diff --git a/demo/abort/main.c b/demo/abort/main.c index f65b93b5..c37ac02d 100644 --- a/demo/abort/main.c +++ b/demo/abort/main.c @@ -1,34 +1,34 @@ /************************************************************************** -* -* Copyright (C) 2016 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2016 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* command line tool that sends a BACnet service */ #include #include #include #include -#include /* for time */ +#include /* for time */ #include #include "bactext.h" #include "iam.h" @@ -54,32 +54,26 @@ static bool Target_Server = true; /* flag for signalling errors */ static bool Error_Detected = false; -void MyAbortHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t abort_reason, - bool server) +void MyAbortHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t abort_reason, bool server) { - (void) src; - (void) invoke_id; - (void) server; + (void)src; + (void)invoke_id; + (void)server; printf("BACnet Abort: %s\n", bactext_abort_reason_name(abort_reason)); Error_Detected = true; } -void MyRejectHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t reject_reason) +void MyRejectHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t reject_reason) { - (void) src; - (void) invoke_id; + (void)src; + (void)invoke_id; printf("BACnet Reject: %s\n", bactext_reject_reason_name(reject_reason)); Error_Detected = true; } -static void Init_Service_Handlers( - void) +static void Init_Service_Handlers(void) { Device_Init(NULL); /* we need to handle who-is @@ -87,11 +81,10 @@ static void Init_Service_Handlers( apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, handler_who_is); /* set the handler for all the services we don't implement It is required to send the proper reject message... */ - apdu_set_unrecognized_service_handler_handler - (handler_unrecognized_service); + apdu_set_unrecognized_service_handler_handler(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 reply (request) coming back */ apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_I_AM, handler_i_am_add); /* handle any errors coming back */ @@ -101,8 +94,7 @@ static void Init_Service_Handlers( static void print_usage(char *filename) { - printf("Usage: %s [abort-reason [invoke-id [server]]]\n", - filename); + printf("Usage: %s [abort-reason [invoke-id [server]]]\n", filename); printf(" [--dnet][--dadr][--mac]\n"); printf(" [--version][--help]\n"); } @@ -110,7 +102,8 @@ static void print_usage(char *filename) static void print_help(char *filename) { printf("Send BACnet Abort message to the network.\n"); - printf("--mac A\n" + printf( + "--mac A\n" "Optional destination BACnet mac address." "Valid ranges are from 00 to FF (hex) for MS/TP or ARCNET,\n" "or an IP string with optional port number like 10.1.2.3:47808\n" @@ -122,12 +115,14 @@ static void print_help(char *filename) "and 65535 is network broadcast.\n" "\n" "--dadr A\n" - "Optional BACnet mac address on the destination BACnet network number.\n" + "Optional BACnet mac address on the destination BACnet network " + "number.\n" "Valid ranges are from 00 to FF (hex) for MS/TP or ARCNET,\n" "or an IP string with optional port number like 10.1.2.3:47808\n" "or an Ethernet MAC in hex like 00:21:70:7e:32:bb\n" "\n"); - printf("abort-reason:\n" + printf( + "abort-reason:\n" " number from 0 to 65535\n" "invoke-id:\n" " number from 1 to 255\n" @@ -138,14 +133,12 @@ static void print_help(char *filename) filename); } -int main( - int argc, - char *argv[]) +int main(int argc, char *argv[]) { long dnet = -1; - BACNET_MAC_ADDRESS mac = { 0 }; - BACNET_MAC_ADDRESS adr = { 0 }; - BACNET_ADDRESS dest = { 0 }; + BACNET_MAC_ADDRESS mac = {0}; + BACNET_MAC_ADDRESS adr = {0}; + BACNET_ADDRESS dest = {0}; bool specific_address = false; int argi = 0; unsigned int target_args = 0; @@ -160,8 +153,10 @@ int main( } if (strcmp(argv[argi], "--version") == 0) { printf("%s %s\n", filename, BACNET_VERSION_TEXT); - printf("Copyright (C) 2016 by Steve Karg and others.\n" - "This is free software; see the source for copying conditions.\n" + printf( + "Copyright (C) 2016 by Steve Karg and others.\n" + "This is free software; see the source for copying " + "conditions.\n" "There is NO warranty; not even for MERCHANTABILITY or\n" "FITNESS FOR A PARTICULAR PURPOSE.\n"); return 0; @@ -239,11 +234,8 @@ int main( dlenv_init(); atexit(datalink_cleanup); /* send the request */ - Send_Abort_To_Network(&Handler_Transmit_Buffer[0], - &dest, - Target_Invoke_ID, - Target_Abort_Reason, - Target_Server); + Send_Abort_To_Network(&Handler_Transmit_Buffer[0], &dest, Target_Invoke_ID, + Target_Abort_Reason, Target_Server); return 0; } diff --git a/demo/dcc/main.c b/demo/dcc/main.c index 2915ee07..31d207ce 100644 --- a/demo/dcc/main.c +++ b/demo/dcc/main.c @@ -1,34 +1,34 @@ /************************************************************************** -* -* Copyright (C) 2006 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2006 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* command line tool demo for BACnet stack */ #include #include #include #include -#include /* for time */ +#include /* for time */ #include #include "bactext.h" #include "iam.h" @@ -53,7 +53,7 @@ #include "dlenv.h" /* buffer used for receive */ -static uint8_t Rx_Buf[MAX_MPDU] = { 0 }; +static uint8_t Rx_Buf[MAX_MPDU] = {0}; /* global variables used in this file */ static uint32_t Target_Device_Object_Instance = BACNET_MAX_INSTANCE; @@ -65,57 +65,48 @@ static char *Communication_Password = NULL; static bool Error_Detected = false; -static void MyErrorHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - BACNET_ERROR_CLASS error_class, - BACNET_ERROR_CODE error_code) +static void MyErrorHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + BACNET_ERROR_CLASS error_class, + BACNET_ERROR_CODE error_code) { /* FIXME: verify src and invoke id */ - (void) src; - (void) invoke_id; + (void)src; + (void)invoke_id; printf("BACnet Error: %s: %s\n", bactext_error_class_name(error_class), - bactext_error_code_name(error_code)); + bactext_error_code_name(error_code)); Error_Detected = true; } -void MyAbortHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t abort_reason, - bool server) +void MyAbortHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t abort_reason, bool server) { /* FIXME: verify src and invoke id */ - (void) src; - (void) invoke_id; - (void) server; + (void)src; + (void)invoke_id; + (void)server; printf("BACnet Abort: %s\n", bactext_abort_reason_name(abort_reason)); Error_Detected = true; } -void MyRejectHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t reject_reason) +void MyRejectHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t reject_reason) { /* FIXME: verify src and invoke id */ - (void) src; - (void) invoke_id; + (void)src; + (void)invoke_id; printf("BACnet Reject: %s\n", bactext_reject_reason_name(reject_reason)); Error_Detected = true; } -void MyDeviceCommunicationControlSimpleAckHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id) +void MyDeviceCommunicationControlSimpleAckHandler(BACNET_ADDRESS *src, + uint8_t invoke_id) { - (void) src; - (void) invoke_id; + (void)src; + (void)invoke_id; printf("DeviceCommunicationControl Acknowledged!\n"); } -static void Init_Service_Handlers( - void) +static void Init_Service_Handlers(void) { Device_Init(NULL); /* we need to handle who-is @@ -125,21 +116,20 @@ static void Init_Service_Handlers( apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_I_AM, handler_i_am_bind); /* set the handler for all the services we don't implement It is required to send the proper reject message... */ - apdu_set_unrecognized_service_handler_handler - (handler_unrecognized_service); + apdu_set_unrecognized_service_handler_handler(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 communication so we can shutup when asked */ apdu_set_confirmed_handler(SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL, - handler_device_communication_control); + handler_device_communication_control); /* handle the ack coming back */ - apdu_set_confirmed_simple_ack_handler - (SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL, + apdu_set_confirmed_simple_ack_handler( + SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL, MyDeviceCommunicationControlSimpleAckHandler); /* handle any errors coming back */ apdu_set_error_handler(SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL, - MyErrorHandler); + MyErrorHandler); apdu_set_abort_handler(MyAbortHandler); apdu_set_reject_handler(MyRejectHandler); } @@ -152,11 +142,16 @@ static void print_usage(char *filename) static void print_help(char *filename) { - printf("Send BACnet DeviceCommunicationControl service to device.\n" - "\n" "The device-instance can be 0 to %lu.\n" - "Possible state values:\n" " 0=enable\n" " 1=disable\n" + printf( + "Send BACnet DeviceCommunicationControl service to device.\n" + "\n" + "The device-instance can be 0 to %lu.\n" + "Possible state values:\n" + " 0=enable\n" + " 1=disable\n" " 2=disable-initiation\n" - "The timeout can be 0 for infinite, or a value in minutes for disable.\n" + "The timeout can be 0 for infinite, or a value in minutes for " + "disable.\n" "The optional password is a character string of 1 to 20 characters.\n" "\nExample:\n" "If you want disable Device Communications in Device 123\n" @@ -165,15 +160,11 @@ static void print_help(char *filename) (unsigned long)(BACNET_MAX_INSTANCE - 1), filename); } -int main( - int argc, - char *argv[]) +int main(int argc, char *argv[]) { - BACNET_ADDRESS src = { - 0 - }; /* address where message came from */ + BACNET_ADDRESS src = {0}; /* address where message came from */ uint16_t pdu_len = 0; - unsigned timeout = 100; /* milliseconds */ + unsigned timeout = 100; /* milliseconds */ unsigned max_apdu = 0; time_t elapsed_seconds = 0; time_t last_seconds = 0; @@ -193,8 +184,10 @@ int main( } if (strcmp(argv[argi], "--version") == 0) { printf("%s %s\n", filename, BACNET_VERSION_TEXT); - printf("Copyright (C) 2014 by Steve Karg and others.\n" - "This is free software; see the source for copying conditions.\n" + printf( + "Copyright (C) 2014 by Steve Karg and others.\n" + "This is free software; see the source for copying " + "conditions.\n" "There is NO warranty; not even for MERCHANTABILITY or\n" "FITNESS FOR A PARTICULAR PURPOSE.\n"); return 0; @@ -206,10 +199,10 @@ int main( } /* decode the command line parameters */ Target_Device_Object_Instance = strtol(argv[1], NULL, 0); - Communication_State = (uint16_t) strtol(argv[2], NULL, 0); + Communication_State = (uint16_t)strtol(argv[2], NULL, 0); /* optional timeout, required if password is included */ if (argc > 3) { - Communication_Timeout_Minutes = (uint16_t) strtol(argv[3], NULL, 0); + Communication_Timeout_Minutes = (uint16_t)strtol(argv[3], NULL, 0); } /* optional password */ if (argc > 4) { @@ -217,7 +210,7 @@ int main( } if (Target_Device_Object_Instance >= BACNET_MAX_INSTANCE) { fprintf(stderr, "device-instance=%u - it must be less than %u\n", - Target_Device_Object_Instance, BACNET_MAX_INSTANCE); + Target_Device_Object_Instance, BACNET_MAX_INSTANCE); return 1; } /* setup my info */ @@ -230,12 +223,11 @@ int main( last_seconds = time(NULL); timeout_seconds = (apdu_timeout() / 1000) * apdu_retries(); /* try to bind with the device */ - found = - address_bind_request(Target_Device_Object_Instance, &max_apdu, - &Target_Address); + found = address_bind_request(Target_Device_Object_Instance, &max_apdu, + &Target_Address); if (!found) { Send_WhoIs(Target_Device_Object_Instance, - Target_Device_Object_Instance); + Target_Device_Object_Instance); } /* loop forever */ for (;;) { @@ -251,21 +243,19 @@ int main( } /* at least one second has passed */ if (current_seconds != last_seconds) - tsm_timer_milliseconds((uint16_t) ((current_seconds - - last_seconds) * 1000)); + tsm_timer_milliseconds( + (uint16_t)((current_seconds - last_seconds) * 1000)); if (Error_Detected) break; /* wait until the device is bound, or timeout and quit */ if (!found) { - found = - address_bind_request(Target_Device_Object_Instance, &max_apdu, - &Target_Address); + found = address_bind_request(Target_Device_Object_Instance, + &max_apdu, &Target_Address); } if (found) { if (invoke_id == 0) { - invoke_id = - Send_Device_Communication_Control_Request - (Target_Device_Object_Instance, + invoke_id = Send_Device_Communication_Control_Request( + Target_Device_Object_Instance, Communication_Timeout_Minutes, Communication_State, Communication_Password); } else if (tsm_invoke_id_free(invoke_id)) diff --git a/demo/epics/main.c b/demo/epics/main.c index 7aa797d7..a0b185e9 100644 --- a/demo/epics/main.c +++ b/demo/epics/main.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2006 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2006 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /** @file epics/main.c Command line tool to build a full VTS3 EPICS file, * including the heading information. */ @@ -30,7 +30,7 @@ #include #include #include -#include /* for time */ +#include /* for time */ #include #include #include "config.h" @@ -58,7 +58,6 @@ #include "keylist.h" #include "bacepics.h" - /* (Doxygen note: The next two lines pull all the following Javadoc * into the BACEPICS module.) */ /** @addtogroup BACEPICS @@ -72,7 +71,7 @@ */ /* buffer used for receive */ -static uint8_t Rx_Buf[MAX_MPDU] = { 0 }; +static uint8_t Rx_Buf[MAX_MPDU] = {0}; /* target information converted from command line */ static uint32_t Target_Device_Object_Instance = BACNET_MAX_INSTANCE; @@ -123,7 +122,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 128 /* Supersized so it always is big enough. */ +#define MAX_PROPS 128 /* 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]; @@ -139,11 +138,9 @@ static struct property_value_list_t Property_Value_List[] = { {PROP_PROTOCOL_SERVICES_SUPPORTED, NULL}, {PROP_PROTOCOL_OBJECT_TYPES_SUPPORTED, NULL}, {PROP_DESCRIPTION, NULL}, - {-1, NULL} -}; + {-1, NULL}}; -static BACNET_APPLICATION_DATA_VALUE *object_property_value( - int32_t property_id) +static BACNET_APPLICATION_DATA_VALUE *object_property_value(int32_t property_id) { BACNET_APPLICATION_DATA_VALUE *value = NULL; int32_t index = 0; @@ -180,19 +177,17 @@ static bool Optional_Properties = false; #define PRINT_ERRORS 1 #endif -static void MyErrorHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - BACNET_ERROR_CLASS error_class, - BACNET_ERROR_CODE error_code) +static void MyErrorHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + BACNET_ERROR_CLASS error_class, + BACNET_ERROR_CODE error_code) { if (address_match(&Target_Address, src) && (invoke_id == Request_Invoke_ID)) { #if PRINT_ERRORS if (ShowValues) { fprintf(stderr, "-- BACnet Error: %s: %s\n", - bactext_error_class_name(error_class), - bactext_error_code_name(error_code)); + bactext_error_class_name(error_class), + bactext_error_code_name(error_code)); } #endif Error_Detected = true; @@ -201,20 +196,17 @@ static void MyErrorHandler( } } -void MyAbortHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t abort_reason, - bool server) +void MyAbortHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t abort_reason, bool server) { - (void) server; + (void)server; if (address_match(&Target_Address, src) && (invoke_id == Request_Invoke_ID)) { #if PRINT_ERRORS /* It is normal for this to fail, so don't print. */ if ((myState != GET_ALL_RESPONSE) && !IsLongArray && ShowValues) { fprintf(stderr, "-- BACnet Abort: %s \n", - bactext_abort_reason_name(abort_reason)); + bactext_abort_reason_name(abort_reason)); } #endif Error_Detected = true; @@ -227,17 +219,15 @@ void MyAbortHandler( } } -void MyRejectHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t reject_reason) +void MyRejectHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t reject_reason) { if (address_match(&Target_Address, src) && (invoke_id == Request_Invoke_ID)) { #if PRINT_ERRORS if (ShowValues) { fprintf(stderr, "BACnet Reject: %s\n", - bactext_reject_reason_name(reject_reason)); + bactext_reject_reason_name(reject_reason)); } #endif Error_Detected = true; @@ -250,11 +240,9 @@ void MyRejectHandler( } } -void MyReadPropertyAckHandler( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src, - BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data) +void MyReadPropertyAckHandler(uint8_t *service_request, uint16_t service_len, + BACNET_ADDRESS *src, + BACNET_CONFIRMED_SERVICE_ACK_DATA *service_data) { int len = 0; BACNET_READ_ACCESS_DATA *rp_data; @@ -263,17 +251,16 @@ void MyReadPropertyAckHandler( (service_data->invoke_id == Request_Invoke_ID)) { rp_data = calloc(1, sizeof(BACNET_READ_ACCESS_DATA)); if (rp_data) { - len = - rp_ack_fully_decode_service_request(service_request, - service_len, rp_data); + len = rp_ack_fully_decode_service_request(service_request, + service_len, 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 */ + if (len < 0) /* Eg, failed due to no segmentation */ Error_Detected = true; free(rp_data); } @@ -281,10 +268,8 @@ void MyReadPropertyAckHandler( } void MyReadPropertyMultipleAckHandler( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src, - BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data) + uint8_t *service_request, uint16_t service_len, BACNET_ADDRESS *src, + BACNET_CONFIRMED_SERVICE_ACK_DATA *service_data) { int len = 0; BACNET_READ_ACCESS_DATA *rpm_data; @@ -293,26 +278,24 @@ void MyReadPropertyMultipleAckHandler( (service_data->invoke_id == Request_Invoke_ID)) { rpm_data = calloc(1, sizeof(BACNET_READ_ACCESS_DATA)); if (rpm_data) { - len = - rpm_ack_decode_service_request(service_request, service_len, - rpm_data); + len = rpm_ack_decode_service_request(service_request, service_len, + 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 */ + if (len < 0) /* Eg, failed due to no segmentation */ Error_Detected = true; free(rpm_data); } } } -static void Init_Service_Handlers( - void) +static void Init_Service_Handlers(void) { Device_Init(NULL); @@ -332,23 +315,21 @@ static void Init_Service_Handlers( apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_I_AM, handler_i_am_bind); /* set the handler for all the services we don't implement It is required to send the proper reject message... */ - apdu_set_unrecognized_service_handler_handler - (handler_unrecognized_service); + apdu_set_unrecognized_service_handler_handler(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); apdu_set_reject_handler(MyRejectHandler); } - /** Determine if this is a writable property, and, if so, * note that in the EPICS output. * This function may need a lot of customization for different implementations. @@ -358,10 +339,9 @@ static void Init_Service_Handlers( * @param rpm_property [in] Points to structure holding the Property, * Value, and Error information. */ -void CheckIsWritableProperty( - BACNET_OBJECT_TYPE object_type, - /* uint32_t object_instance, */ - BACNET_PROPERTY_REFERENCE * rpm_property) +void CheckIsWritableProperty(BACNET_OBJECT_TYPE object_type, + /* uint32_t object_instance, */ + BACNET_PROPERTY_REFERENCE *rpm_property) { bool bIsWritable = false; if ((object_type == OBJECT_ANALOG_OUTPUT) || @@ -383,7 +363,7 @@ void CheckIsWritableProperty( bIsWritable = true; } } else if ((object_type == OBJECT_LIFE_SAFETY_POINT) || - (object_type == OBJECT_LIFE_SAFETY_ZONE)) { + (object_type == OBJECT_LIFE_SAFETY_ZONE)) { if (rpm_property->propertyIdentifier == PROP_MODE) { bIsWritable = true; } @@ -396,8 +376,8 @@ void CheckIsWritableProperty( bIsWritable = true; } } else if ((object_type == OBJECT_TRENDLOG) || - (object_type == OBJECT_EVENT_LOG) || - (object_type == OBJECT_TREND_LOG_MULTIPLE)) { + (object_type == OBJECT_EVENT_LOG) || + (object_type == OBJECT_TREND_LOG_MULTIPLE)) { if ((rpm_property->propertyIdentifier == PROP_ENABLE) || (rpm_property->propertyIdentifier == PROP_RECORD_COUNT)) { bIsWritable = true; @@ -411,17 +391,17 @@ void CheckIsWritableProperty( bIsWritable = true; } } else if ((object_type == OBJECT_ACCESS_ZONE) || - (object_type == OBJECT_ACCESS_USER) || - (object_type == OBJECT_ACCESS_RIGHTS) || - (object_type == OBJECT_ACCESS_CREDENTIAL)) { + (object_type == OBJECT_ACCESS_USER) || + (object_type == OBJECT_ACCESS_RIGHTS) || + (object_type == OBJECT_ACCESS_CREDENTIAL)) { if (rpm_property->propertyIdentifier == PROP_GLOBAL_IDENTIFIER) { bIsWritable = true; } } else if (object_type == OBJECT_NETWORK_SECURITY) { if ((rpm_property->propertyIdentifier == - PROP_BASE_DEVICE_SECURITY_POLICY) || + PROP_BASE_DEVICE_SECURITY_POLICY) || (rpm_property->propertyIdentifier == - PROP_NETWORK_ACCESS_SECURITY_POLICIES) || + PROP_NETWORK_ACCESS_SECURITY_POLICIES) || (rpm_property->propertyIdentifier == PROP_SECURITY_TIME_WINDOW) || (rpm_property->propertyIdentifier == PROP_PACKET_REORDER_TIME) || (rpm_property->propertyIdentifier == PROP_LAST_KEY_SERVER) || @@ -439,9 +419,7 @@ void CheckIsWritableProperty( fprintf(stdout, " Writable"); } - -static const char *protocol_services_supported_text( - size_t bit_index) +static const char *protocol_services_supported_text(size_t bit_index) { bool is_confirmed = false; size_t text_index = 0; @@ -475,9 +453,8 @@ static const char *protocol_services_supported_text( * @return True if success. Or otherwise. */ -bool PrettyPrintPropertyValue( - FILE * stream, - BACNET_OBJECT_PROPERTY_VALUE * object_value) +bool PrettyPrintPropertyValue(FILE *stream, + BACNET_OBJECT_PROPERTY_VALUE *object_value) { BACNET_APPLICATION_DATA_VALUE *value = NULL; bool status = true; /*return value */ @@ -489,31 +466,33 @@ bool PrettyPrintPropertyValue( property = object_value->object_property; if ((value != NULL) && (value->tag == BACNET_APPLICATION_TAG_BIT_STRING) && ((property == PROP_PROTOCOL_OBJECT_TYPES_SUPPORTED) || - (property == PROP_PROTOCOL_SERVICES_SUPPORTED))) { + (property == PROP_PROTOCOL_SERVICES_SUPPORTED))) { len = bitstring_bits_used(&value->type.Bit_String); fprintf(stream, "( \n "); for (i = 0; i < len; i++) { - fprintf(stream, "%s", bitstring_bit(&value->type.Bit_String, - (uint8_t) i) ? "T" : "F"); + 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 "--" */ + /* 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 "--" */ /* 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 (bitstring_bit(&value->type.Bit_String, (uint8_t)j)) { if (property == PROP_PROTOCOL_OBJECT_TYPES_SUPPORTED) { fprintf(stream, " %s,", - bactext_object_type_name(j)); + bactext_object_type_name(j)); } else { /* PROP_PROTOCOL_SERVICES_SUPPORTED */ fprintf(stream, " %s,", - protocol_services_supported_text(j)); + protocol_services_supported_text(j)); } - } else /* not supported */ + } else /* not supported */ fprintf(stream, ","); } fprintf(stream, "\n "); @@ -526,11 +505,11 @@ bool PrettyPrintPropertyValue( * clearer, international form. */ strncpy(short_month, bactext_month_name(value->type.Date.month), 3); short_month[3] = 0; - fprintf(stream, "(%u-%3s-%u, %u)", (unsigned) value->type.Date.day, - short_month, (unsigned) value->type.Date.year, - (unsigned) value->type.Date.wday); + fprintf(stream, "(%u-%3s-%u, %u)", (unsigned)value->type.Date.day, + short_month, (unsigned)value->type.Date.year, + (unsigned)value->type.Date.wday); } else if (value != NULL) { - assert(false); /* How did I get here? Fix your code. */ + assert(false); /* How did I get here? Fix your code. */ /* Meanwhile, a fallback plan */ status = bacapp_print_value(stdout, object_value); } else @@ -539,7 +518,6 @@ bool PrettyPrintPropertyValue( return status; } - /** Print out the value(s) for one Property. * This function may be called repeatedly for one property if we are walking * through a list (Using_Walked_List is True) to show just one value of the @@ -550,16 +528,15 @@ bool PrettyPrintPropertyValue( * @param rpm_property [in] Points to structure holding the Property, * Value, and Error information. */ -void PrintReadPropertyData( - BACNET_OBJECT_TYPE object_type, - uint32_t object_instance, - BACNET_PROPERTY_REFERENCE * rpm_property) +void PrintReadPropertyData(BACNET_OBJECT_TYPE object_type, + uint32_t object_instance, + BACNET_PROPERTY_REFERENCE *rpm_property) { - BACNET_OBJECT_PROPERTY_VALUE object_value; /* for bacapp printing */ + BACNET_OBJECT_PROPERTY_VALUE object_value; /* for bacapp printing */ 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 \n"); @@ -569,15 +546,16 @@ void PrintReadPropertyData( if (value == NULL) { /* Then we print the error information */ fprintf(stdout, "? -- BACnet Error: %s: %s\n", - bactext_error_class_name((int) rpm_property->error.error_class), - bactext_error_code_name((int) rpm_property->error.error_code)); + bactext_error_class_name((int)rpm_property->error.error_class), + bactext_error_code_name((int)rpm_property->error.error_code)); return; } object_value.object_type = object_type; object_value.object_instance = object_instance; if ((value != NULL) && (value->next != NULL)) { /* Then this is an array of values. - * But are we showing Values? We (VTS3) want ? instead of {?,?} to show up. */ + * But are we showing Values? We (VTS3) want ? instead of {?,?} to show + * up. */ switch (rpm_property->propertyIdentifier) { /* Screen the Properties that can be arrays or Sequences */ case PROP_PRESENT_VALUE: @@ -593,18 +571,18 @@ void PrintReadPropertyData( break; } if (object_type == OBJECT_DATETIME_VALUE) - break; /* A special case - no braces for this pair */ + break; /* A special case - no braces for this pair */ /* Else, fall through to normal processing. */ default: /* Normal array: open brace */ fprintf(stdout, "{ "); - print_brace = true; /* remember to close it */ + print_brace = true; /* remember to close it */ break; } } if (!Using_Walked_List) - Walked_List_Index = Walked_List_Length = 0; /* In case we need this. */ + Walked_List_Index = Walked_List_Length = 0; /* In case we need this. */ /* value(s) loop until there is no "next" ... */ while (value != NULL) { object_value.object_property = rpm_property->propertyIdentifier; @@ -620,25 +598,28 @@ void PrintReadPropertyData( 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! */ + /* 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 == (uint32_t) - rpm_property->propertyArrayIndex); + assert(Walked_List_Index == + (uint32_t)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 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) { /* If the array is empty (nothing for this first entry), - * Make it VTS3-friendly and don't show "Null" as a value. */ + * Make it VTS3-friendly and don't show "Null" as a value. + */ if (value->tag == BACNET_APPLICATION_TAG_NULL) { fprintf(stdout, "?\n "); break; @@ -655,41 +636,50 @@ void PrintReadPropertyData( if (rpm_property->propertyIdentifier == PROP_OBJECT_LIST) { if (value->tag != BACNET_APPLICATION_TAG_OBJECT_ID) { - assert(value->tag == BACNET_APPLICATION_TAG_OBJECT_ID); /* Something not right here */ + assert( + value->tag == + BACNET_APPLICATION_TAG_OBJECT_ID); /* 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); + 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. */ + } 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[iLast15idx], + 15); value->type.Character_String.value[31] = 0; value->type.Character_String.length = 31; } } else if (rpm_property->propertyIdentifier == - PROP_SUBORDINATE_LIST) { + PROP_SUBORDINATE_LIST) { if (value->tag != BACNET_APPLICATION_TAG_OBJECT_ID) { - assert(value->tag == BACNET_APPLICATION_TAG_OBJECT_ID); /* Something not right here */ + assert( + value->tag == + BACNET_APPLICATION_TAG_OBJECT_ID); /* 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 the object is a Sequence, it needs its own bracketing + * braces */ if (isSequence) fprintf(stdout, "{"); bacapp_print_value(stdout, &object_value); @@ -738,7 +728,7 @@ void PrintReadPropertyData( /* Else, fall through for normal processing. */ case PROP_DAYLIGHT_SAVINGS_STATUS: case PROP_LOCAL_TIME: - case PROP_LOCAL_DATE: /* Only if !ShowValues */ + case PROP_LOCAL_DATE: /* Only if !ShowValues */ case PROP_PRESENT_VALUE: case PROP_PRIORITY_ARRAY: case PROP_RELIABILITY: @@ -762,26 +752,24 @@ void PrintReadPropertyData( /* Closing brace for this multi-valued array */ fprintf(stdout, " }"); } - CheckIsWritableProperty(object_type, /* object_instance, */ - rpm_property); + CheckIsWritableProperty(object_type, /* object_instance, */ + rpm_property); fprintf(stdout, "\n"); } break; } old_value = value; - value = value->next; /* next or NULL */ + value = value->next; /* next or NULL */ free(old_value); - } /* End while loop */ - + } /* End while loop */ } /** Print the property identifier name to stdout, * handling the proprietary property numbers. * @param propertyIdentifier [in] The property identifier number. */ -static void Print_Property_Identifier( - unsigned propertyIdentifier) +static void Print_Property_Identifier(unsigned propertyIdentifier) { if (propertyIdentifier < 512) { fprintf(stdout, "%s", bactext_property_name(propertyIdentifier)); @@ -791,8 +779,7 @@ static void Print_Property_Identifier( } /* Build a list of device properties to request with RPM. */ -static void BuildPropRequest( - BACNET_READ_ACCESS_DATA * rpm_object) +static void BuildPropRequest(BACNET_READ_ACCESS_DATA *rpm_object) { int i; /* To start with, StartNextObject() has prepopulated one propEntry, @@ -824,9 +811,8 @@ static void BuildPropRequest( * @return The invokeID of the message sent, or 0 if reached the end * of the property list. */ -static uint8_t Read_Properties( - uint32_t device_instance, - BACNET_OBJECT_ID * pMyObject) +static uint8_t Read_Properties(uint32_t device_instance, + BACNET_OBJECT_ID *pMyObject) { uint8_t invoke_id = 0; struct special_property_list_t PropertyListStruct; @@ -841,9 +827,8 @@ static uint8_t Read_Properties( */ property_list_special(pMyObject->type, &PropertyListStruct); if (Optional_Properties) { - Property_List_Length = - PropertyListStruct.Required.count + - PropertyListStruct.Optional.count; + Property_List_Length = PropertyListStruct.Required.count + + PropertyListStruct.Optional.count; } else { Property_List_Length = PropertyListStruct.Required.count; } @@ -879,7 +864,8 @@ static uint8_t Read_Properties( array_index = BACNET_ARRAY_ALL; switch (prop) { - /* These are all potentially long arrays, so they may abort */ + /* These are all potentially long arrays, so they may abort + */ case PROP_OBJECT_LIST: case PROP_STATE_TEXT: case PROP_STRUCTURED_OBJECT_LIST: @@ -891,8 +877,7 @@ static uint8_t Read_Properties( } invoke_id = Send_Read_Property_Request(device_instance, pMyObject->type, - pMyObject->instance, prop, array_index); - + pMyObject->instance, prop, array_index); } return invoke_id; @@ -909,9 +894,8 @@ static uint8_t Read_Properties( * if the RPM got good data, or GET_PROPERTY_REQUEST if we have to * singly process the list of Properties. */ -EPICS_STATES ProcessRPMData( - BACNET_READ_ACCESS_DATA * rpm_data, - EPICS_STATES myState) +EPICS_STATES ProcessRPMData(BACNET_READ_ACCESS_DATA *rpm_data, + EPICS_STATES myState) { BACNET_READ_ACCESS_DATA *old_rpm_data; BACNET_PROPERTY_REFERENCE *rpm_property; @@ -919,7 +903,7 @@ 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; @@ -934,7 +918,7 @@ EPICS_STATES ProcessRPMData( if (myState == GET_LIST_OF_ALL_RESPONSE) { switch (rpm_property->propertyIdentifier) { case PROP_OBJECT_LIST: - bHasObjectList = true; /* Will append below */ + bHasObjectList = true; /* Will append below */ break; case PROP_STRUCTURED_OBJECT_LIST: bHasStructuredViewList = true; @@ -963,7 +947,7 @@ EPICS_STATES ProcessRPMData( Print_Property_Identifier(rpm_property->propertyIdentifier); fprintf(stdout, ": "); PrintReadPropertyData(rpm_data->object_type, - rpm_data->object_instance, rpm_property); + rpm_data->object_instance, rpm_property); } old_rpm_property = rpm_property; rpm_property = rpm_property->next; @@ -980,7 +964,7 @@ EPICS_STATES ProcessRPMData( /* press ahead with or without the data */ else if (bSuccess && (myState == GET_ALL_RESPONSE)) nextState = NEXT_OBJECT; - else if (bSuccess) { /* and GET_LIST_OF_ALL_RESPONSE */ + 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; @@ -995,7 +979,7 @@ EPICS_STATES ProcessRPMData( /* 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 */ + Property_List_Index = 0; /* Will start at top of the list */ nextState = GET_PROPERTY_REQUEST; } return nextState; @@ -1003,15 +987,18 @@ EPICS_STATES ProcessRPMData( static void print_usage(char *filename) { - printf("Usage: %s [-v] [-d] [-p sport] [-t target_mac [-n dnet]]" - " device-instance\n", filename); + printf( + "Usage: %s [-v] [-d] [-p sport] [-t target_mac [-n dnet]]" + " device-instance\n", + filename); printf(" [--version][--help]\n"); } static void print_help(char *filename) { printf("Generates Full EPICS file, including Object and Property List\n"); - printf("device-instance:\n" + printf( + "device-instance:\n" "BACnet Device Object Instance number that you are\n" "trying to communicate to. This number will be used\n" "to try and bind with the device using Who-Is and\n" @@ -1031,9 +1018,7 @@ static void print_help(char *filename) printf("e.g., bacepics 2701876 > epics-2701876.tpi \n"); } -int CheckCommandLineArgs( - int argc, - char *argv[]) +int CheckCommandLineArgs(int argc, char *argv[]) { int i; bool bFoundTarget = false; @@ -1049,8 +1034,10 @@ int CheckCommandLineArgs( } if (strcmp(argv[argi], "--version") == 0) { printf("%s %s\n", filename, BACNET_VERSION_TEXT); - printf("Copyright (C) 2014 by Steve Karg and others.\n" - "This is free software; see the source for copying conditions.\n" + printf( + "Copyright (C) 2014 by Steve Karg and others.\n" + "This is free software; see the source for copying " + "conditions.\n" "There is NO warranty; not even for MERCHANTABILITY or\n" "FITNESS FOR A PARTICULAR PURPOSE.\n"); exit(0); @@ -1076,7 +1063,7 @@ int CheckCommandLineArgs( case 'p': if (++i < argc) { #if defined(BACDL_BIP) - My_BIP_Port = (uint16_t) strtol(argv[i], NULL, 0); + My_BIP_Port = (uint16_t)strtol(argv[i], NULL, 0); /* Used strtol so sport can be either 0xBAC0 or 47808 */ #endif } @@ -1085,10 +1072,9 @@ int CheckCommandLineArgs( /* Destination Network Number */ if (Target_Address.mac_len == 0) fprintf(stderr, - "Must provide a Target MAC before DNET \n"); + "Must provide a Target MAC before DNET \n"); if (++i < argc) - Target_Address.net = - (uint16_t) strtol(argv[i], NULL, 0); + Target_Address.net = (uint16_t)strtol(argv[i], NULL, 0); /* Used strtol so dest.net can be either 0x1234 or 4660 */ break; case 't': @@ -1101,19 +1087,18 @@ int CheckCommandLineArgs( unsigned j; count = sscanf(argv[i], "%2x:%2x:%2x:%2x:%2x:%2x", &mac[0], - &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]); - if (count == 6) { /* success */ + &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]); + if (count == 6) { /* success */ Target_Address.mac_len = count; for (j = 0; j < 6; j++) { - Target_Address.mac[j] = (uint8_t) mac[j]; + Target_Address.mac[j] = (uint8_t)mac[j]; } Target_Address.net = 0; - Target_Address.len = 0; /* No src address */ + Target_Address.len = 0; /* No src address */ Provided_Targ_MAC = true; break; } else - printf("ERROR: invalid Target MAC %s \n", - argv[i]); + printf("ERROR: invalid Target MAC %s \n", argv[i]); /* And fall through to print_usage */ } /* Either break or fall through, as above */ @@ -1128,8 +1113,8 @@ int CheckCommandLineArgs( Target_Device_Object_Instance = strtol(anArg, NULL, 0); if (Target_Device_Object_Instance > BACNET_MAX_INSTANCE) { fprintf(stdout, - "Error: device-instance=%u - it must be less than %u\n", - Target_Device_Object_Instance, BACNET_MAX_INSTANCE + 1); + "Error: device-instance=%u - it must be less than %u\n", + Target_Device_Object_Instance, BACNET_MAX_INSTANCE + 1); print_usage(filename); exit(0); } @@ -1142,11 +1127,10 @@ int CheckCommandLineArgs( exit(0); } - return 0; /* All OK if we reach here */ + return 0; /* All OK if we reach here */ } -void PrintHeading( - ) +void PrintHeading() { BACNET_APPLICATION_DATA_VALUE *value = NULL; BACNET_OBJECT_PROPERTY_VALUE property_value; @@ -1163,7 +1147,7 @@ void PrintHeading( if ((value != NULL) && (value->tag == BACNET_APPLICATION_TAG_CHARACTER_STRING)) { printf("Vendor Name: \"%s\"\n", - characterstring_value(&value->type.Character_String)); + characterstring_value(&value->type.Character_String)); } else { printf("Vendor Name: \"your vendor name here\"\n"); } @@ -1173,9 +1157,9 @@ void PrintHeading( if ((value != NULL) && (value->tag == BACNET_APPLICATION_TAG_CHARACTER_STRING)) { printf("Product Name: \"%s\"\n", - characterstring_value(&value->type.Character_String)); + characterstring_value(&value->type.Character_String)); printf("Product Model Number: \"%s\"\n", - characterstring_value(&value->type.Character_String)); + characterstring_value(&value->type.Character_String)); } else { printf("Product Name: \"your product name here\"\n"); printf("Product Model Number: \"your model number here\"\n"); @@ -1185,9 +1169,10 @@ void PrintHeading( if ((value != NULL) && (value->tag == BACNET_APPLICATION_TAG_CHARACTER_STRING)) { printf("Product Description: \"%s\"\n\n", - characterstring_value(&value->type.Character_String)); + characterstring_value(&value->type.Character_String)); } else { - printf("Product Description: " + printf( + "Product Description: " "\"your product description here\"\n\n"); } printf("BIBBs Supported:\n"); @@ -1217,14 +1202,14 @@ void PrintHeading( printf("BACnet Standard Application Services Supported:\n"); printf("{\n"); value = object_property_value(PROP_PROTOCOL_SERVICES_SUPPORTED); - /* We have to process this bit string and determine which Object Types we have, - * and show them + /* We have to process this bit string and determine which Object Types we + * have, and show them */ if ((value != NULL) && (value->tag == BACNET_APPLICATION_TAG_BIT_STRING)) { int i, len = bitstring_bits_used(&value->type.Bit_String); printf("-- services reported by this device\n"); for (i = 0; i < len; i++) { - if (bitstring_bit(&value->type.Bit_String, (uint8_t) i)) + if (bitstring_bit(&value->type.Bit_String, (uint8_t)i)) printf(" %s\n", protocol_services_supported_text(i)); } } else { @@ -1251,8 +1236,7 @@ void PrintHeading( printf("-- SubscribeCOVProperty Initiate Execute\n"); #ifdef BAC_ROUTING if (Target_Address.net == 0) { - printf - ("-- Note: The following Routing Services are Supported:\n"); + printf("-- Note: The following Routing Services are Supported:\n"); printf("-- Who-Is-Router-To-Network Initiate Execute\n"); printf("-- I-Am-Router-To-Network Initiate Execute\n"); printf("-- Initialize-Routing-Table Execute\n"); @@ -1265,14 +1249,14 @@ void PrintHeading( printf("Standard Object-Types Supported:\n"); printf("{\n"); value = object_property_value(PROP_PROTOCOL_OBJECT_TYPES_SUPPORTED); - /* We have to process this bit string and determine which Object Types we have, - * and show them + /* We have to process this bit string and determine which Object Types we + * have, and show them */ if ((value != NULL) && (value->tag == BACNET_APPLICATION_TAG_BIT_STRING)) { int i, len = bitstring_bits_used(&value->type.Bit_String); printf("-- objects reported by this device\n"); for (i = 0; i < len; i++) { - if (bitstring_bit(&value->type.Bit_String, (uint8_t) i)) + if (bitstring_bit(&value->type.Bit_String, (uint8_t)i)) printf(" %s\n", bactext_object_type_name(i)); } } else { @@ -1360,8 +1344,12 @@ void PrintHeading( printf("{\n"); printf(" unsigned-integer: \n"); printf(" signed-integer: \n"); - printf(" real: \n"); - printf(" double: \n"); + printf( + " real: \n"); + printf( + " double: \n"); printf(" date: \n"); printf(" octet-string: \n"); printf(" character-string: \n"); @@ -1386,14 +1374,12 @@ void Print_Device_Heading(void) printf("List of Objects in Test Device:\n"); /* Print Opening brace, then kick off the Device Object */ printf("{\n"); - printf(" {\n"); /* And opening brace for the first object */ + printf(" {\n"); /* And opening brace for the first object */ } - /* Initialize fields for a new Object */ -void StartNextObject( - BACNET_READ_ACCESS_DATA * rpm_object, - BACNET_OBJECT_ID * pNewObject) +void StartNextObject(BACNET_READ_ACCESS_DATA *rpm_object, + BACNET_OBJECT_ID *pNewObject) { BACNET_PROPERTY_REFERENCE *rpm_property; Error_Detected = false; @@ -1417,16 +1403,15 @@ void StartNextObject( * * * @param argc [in] Arg count. - * @param argv [in] Takes one to four arguments, processed in CheckCommandLineArgs(). + * @param argv [in] Takes one to four arguments, processed in + * CheckCommandLineArgs(). * @return 0 on success. */ -int main( - int argc, - char *argv[]) +int main(int argc, char *argv[]) { BACNET_ADDRESS src; /* address where message came from */ uint16_t pdu_len = 0; - unsigned timeout = 100; /* milliseconds */ + unsigned timeout = 100; /* milliseconds */ unsigned max_apdu = 0; time_t elapsed_seconds = 0; time_t last_seconds = 0; @@ -1434,11 +1419,11 @@ int main( time_t timeout_seconds = 0; bool found = false; BACNET_OBJECT_ID myObject; - uint8_t buffer[MAX_PDU] = { 0 }; + uint8_t buffer[MAX_PDU] = {0}; BACNET_READ_ACCESS_DATA *rpm_object = NULL; KEY nextKey; - CheckCommandLineArgs(argc, argv); /* Won't return if there is an issue. */ + CheckCommandLineArgs(argc, argv); /* Won't return if there is an issue. */ memset(&src, 0, sizeof(BACNET_ADDRESS)); /* setup my info */ @@ -1464,32 +1449,31 @@ int main( #if defined(BACDL_BIP) if (My_BIP_Port > 0) { - bip_set_port(htons(0xBAC0)); /* Set back to std BACnet/IP port */ + bip_set_port(htons(0xBAC0)); /* Set back to std BACnet/IP port */ } #endif /* try to bind with the target device */ - found = - address_bind_request(Target_Device_Object_Instance, &max_apdu, - &Target_Address); + found = address_bind_request(Target_Device_Object_Instance, &max_apdu, + &Target_Address); if (!found) { if (Provided_Targ_MAC) { if (Target_Address.net > 0) { /* We specified a DNET; call Who-Is to find the full * routed path to this Device */ Send_WhoIs_Remote(&Target_Address, - Target_Device_Object_Instance, - Target_Device_Object_Instance); + Target_Device_Object_Instance, + Target_Device_Object_Instance); } else { /* Update by adding the MAC address */ if (max_apdu == 0) - max_apdu = MAX_APDU; /* Whatever set for this datalink. */ + max_apdu = MAX_APDU; /* Whatever set for this datalink. */ address_add_binding(Target_Device_Object_Instance, max_apdu, - &Target_Address); + &Target_Address); } } else { Send_WhoIs(Target_Device_Object_Instance, - Target_Device_Object_Instance); + Target_Device_Object_Instance); } } myObject.type = OBJECT_DEVICE; @@ -1501,34 +1485,32 @@ int main( current_seconds = time(NULL); /* Has at least one second passed ? */ if (current_seconds != last_seconds) { - tsm_timer_milliseconds((uint16_t) ((current_seconds - - last_seconds) * 1000)); + tsm_timer_milliseconds( + (uint16_t)((current_seconds - last_seconds) * 1000)); } /* OK to proceed; see what we are up to now */ switch (myState) { case INITIAL_BINDING: /* returns 0 bytes on timeout */ - pdu_len = - datalink_receive(&src, &Rx_Buf[0], MAX_MPDU, 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); + 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) { fprintf(stderr, - "\rError: Unable to bind to %u" - " after waiting %ld seconds.\n", - Target_Device_Object_Instance, - (long int) elapsed_seconds); + "\rError: Unable to bind to %u" + " after waiting %ld seconds.\n", + Target_Device_Object_Instance, + (long int)elapsed_seconds); break; } /* else, loop back and try again */ @@ -1545,9 +1527,8 @@ int main( last_seconds = current_seconds; StartNextObject(rpm_object, &myObject); BuildPropRequest(rpm_object); - Request_Invoke_ID = - Send_Read_Property_Multiple_Request(buffer, MAX_PDU, - Target_Device_Object_Instance, rpm_object); + Request_Invoke_ID = Send_Read_Property_Multiple_Request( + buffer, MAX_PDU, Target_Device_Object_Instance, rpm_object); if (Request_Invoke_ID > 0) { elapsed_seconds = 0; } else { @@ -1575,9 +1556,8 @@ int main( last_seconds = current_seconds; StartNextObject(rpm_object, &myObject); - Request_Invoke_ID = - Send_Read_Property_Multiple_Request(buffer, MAX_PDU, - Target_Device_Object_Instance, rpm_object); + Request_Invoke_ID = Send_Read_Property_Multiple_Request( + buffer, MAX_PDU, Target_Device_Object_Instance, rpm_object); if (Request_Invoke_ID > 0) { elapsed_seconds = 0; if (myState == GET_LIST_OF_ALL_REQUEST) @@ -1591,8 +1571,7 @@ int main( 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); + pdu_len = datalink_receive(&src, &Rx_Buf[0], MAX_MPDU, timeout); /* process */ if (pdu_len) { @@ -1601,15 +1580,14 @@ int main( if ((Read_Property_Multiple_Data.new_data) && (Request_Invoke_ID == - Read_Property_Multiple_Data.service_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); + myState = ProcessRPMData( + Read_Property_Multiple_Data.rpm_data, myState); if (tsm_invoke_id_free(Request_Invoke_ID)) { Request_Invoke_ID = 0; } else { - assert(false); /* How can this be? */ + assert(false); /* How can this be? */ Request_Invoke_ID = 0; } elapsed_seconds = 0; @@ -1626,7 +1604,8 @@ int main( /* Was it because the Device can't do RPM? */ Has_RPM = false; myState = GET_PROPERTY_REQUEST; - } else if (Last_Error_Code == + } else if ( + Last_Error_Code == ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED) { myState = GET_PROPERTY_REQUEST; StartNextObject(rpm_object, &myObject); @@ -1639,7 +1618,7 @@ int main( StartNextObject(rpm_object, &myObject); } } else if (Has_RPM) - myState = GET_ALL_REQUEST; /* Let's try again */ + myState = GET_ALL_REQUEST; /* Let's try again */ else myState = GET_PROPERTY_REQUEST; } else if (tsm_invoke_id_failed(Request_Invoke_ID)) { @@ -1651,7 +1630,7 @@ int main( myState = PRINT_HEADING; /* just press ahead without the data */ else - myState = GET_ALL_REQUEST; /* Let's try again */ + myState = GET_ALL_REQUEST; /* Let's try again */ } else if (Error_Detected) { /* Don't think we'll ever actually reach this point. */ elapsed_seconds = 0; @@ -1660,7 +1639,8 @@ int main( myState = PRINT_HEADING; /* just press ahead without the data */ else - myState = NEXT_OBJECT; /* Give up and move on to the next. */ + myState = + NEXT_OBJECT; /* Give up and move on to the next. */ Error_Count++; } break; @@ -1676,15 +1656,14 @@ int main( Read_Properties(Target_Device_Object_Instance, &myObject); if (Request_Invoke_ID == 0) { /* Reached the end of the list. */ - myState = NEXT_OBJECT; /* Move on to the next. */ + 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); + pdu_len = datalink_receive(&src, &Rx_Buf[0], MAX_MPDU, timeout); /* process */ if (pdu_len) { @@ -1693,17 +1672,16 @@ int main( if ((Read_Property_Multiple_Data.new_data) && (Request_Invoke_ID == - Read_Property_Multiple_Data.service_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->object_type, + PrintReadPropertyData( + Read_Property_Multiple_Data.rpm_data->object_type, Read_Property_Multiple_Data.rpm_data->object_instance, - Read_Property_Multiple_Data.rpm_data-> - listOfProperties); + Read_Property_Multiple_Data.rpm_data->listOfProperties); if (tsm_invoke_id_free(Request_Invoke_ID)) { Request_Invoke_ID = 0; } else { - assert(false); /* How can this be? */ + assert(false); /* How can this be? */ Request_Invoke_ID = 0; } elapsed_seconds = 0; @@ -1718,7 +1696,7 @@ int main( } else { Property_List_Index++; } - myState = GET_PROPERTY_REQUEST; /* Go fetch next Property */ + myState = GET_PROPERTY_REQUEST; /* Go fetch next Property */ } else if (tsm_invoke_id_free(Request_Invoke_ID)) { Request_Invoke_ID = 0; elapsed_seconds = 0; @@ -1727,14 +1705,16 @@ int main( if ((Last_Error_Class != ERROR_CLASS_PROPERTY) && (Last_Error_Code != ERROR_CODE_UNKNOWN_PROPERTY)) { if (IsLongArray) { - /* Change to using a Walked List and retry this property */ + /* 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. */ + /* OK, skip this one and try the next property. + */ fprintf(stdout, " -- Failed to get "); - Print_Property_Identifier(Property_List - [Property_List_Index]); + Print_Property_Identifier( + Property_List[Property_List_Index]); fprintf(stdout, " \n"); Error_Count++; Property_List_Index++; @@ -1759,12 +1739,13 @@ int main( tsm_free_invoke_id(Request_Invoke_ID); elapsed_seconds = 0; Request_Invoke_ID = 0; - myState = 3; /* Let's try again, same Property */ + myState = 3; /* Let's try again, same Property */ } else if (Error_Detected) { /* Don't think we'll ever actually reach this point. */ elapsed_seconds = 0; Request_Invoke_ID = 0; - myState = NEXT_OBJECT; /* Give up and move on to the next. */ + myState = + NEXT_OBJECT; /* Give up and move on to the next. */ Error_Count++; } break; @@ -1772,17 +1753,19 @@ int main( case NEXT_OBJECT: if (myObject.type == OBJECT_DEVICE) { printf(" -- Found %d Objects \n", - Keylist_Count(Object_List)); - Object_List_Index = -1; /* start over (will be incr to 0) */ + Keylist_Count(Object_List)); + Object_List_Index = -1; /* start over (will be incr to 0) */ if (ShowDeviceObjectOnly) { /* Closing brace for the Device Object */ printf(" }, \n"); - /* done with all Objects, signal end of this while loop */ + /* done with all Objects, signal end of this while loop + */ myObject.type = MAX_BACNET_OBJECT_TYPE; break; } } - /* Advance to the next object, as long as it's not the Device object */ + /* Advance to the next object, as long as it's not the Device + * object */ do { Object_List_Index++; if (Object_List_Index < Keylist_Count(Object_List)) { @@ -1798,12 +1781,14 @@ int main( printf(" { \n"); /* Test code: if ( myObject.type == OBJECT_STRUCTURED_VIEW ) - printf( " -- Structured View %d \n", myObject.instance ); + printf( " -- Structured View %d \n", + myObject.instance ); */ } else { /* Closing brace for the last Object */ printf(" } \n"); - /* done with all Objects, signal end of this while loop */ + /* done with all Objects, signal end of this while loop + */ myObject.type = MAX_BACNET_OBJECT_TYPE; } if (Has_RPM) @@ -1814,11 +1799,12 @@ int main( } } while (myObject.type == OBJECT_DEVICE); - /* Else, don't re-do the Device Object; move to the next object. */ + /* Else, don't re-do the Device Object; move to the next object. + */ break; default: - assert(false); /* program error; fix this */ + assert(false); /* program error; fix this */ break; } @@ -1828,7 +1814,7 @@ int main( elapsed_seconds += (current_seconds - last_seconds); if (elapsed_seconds > timeout_seconds) { fprintf(stderr, "\rError: APDU Timeout! (%lds)\n", - (long int) elapsed_seconds); + (long int)elapsed_seconds); break; } } @@ -1841,8 +1827,7 @@ int main( /* Closing brace for all Objects, if we got any, and closing footer */ if (myState != INITIAL_BINDING) { printf("} \n"); - printf - ("End of BACnet Protocol Implementation Conformance Statement\n"); + printf("End of BACnet Protocol Implementation Conformance Statement\n"); printf("\n"); } diff --git a/demo/error/main.c b/demo/error/main.c index 048e5789..1d8d1709 100644 --- a/demo/error/main.c +++ b/demo/error/main.c @@ -1,34 +1,34 @@ /************************************************************************** -* -* Copyright (C) 2016 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2016 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* command line tool that sends a BACnet service */ #include #include #include #include -#include /* for time */ +#include /* for time */ #include #include "bactext.h" #include "iam.h" @@ -55,32 +55,26 @@ static uint16_t Target_Service = SERVICE_CONFIRMED_READ_PROPERTY; /* flag for signalling errors */ static bool Error_Detected = false; -void MyAbortHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t abort_reason, - bool server) +void MyAbortHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t abort_reason, bool server) { - (void) src; - (void) invoke_id; - (void) server; + (void)src; + (void)invoke_id; + (void)server; printf("BACnet Abort: %s\n", bactext_abort_reason_name(abort_reason)); Error_Detected = true; } -void MyRejectHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t reject_reason) +void MyRejectHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t reject_reason) { - (void) src; - (void) invoke_id; + (void)src; + (void)invoke_id; printf("BACnet Reject: %s\n", bactext_reject_reason_name(reject_reason)); Error_Detected = true; } -static void Init_Service_Handlers( - void) +static void Init_Service_Handlers(void) { Device_Init(NULL); /* we need to handle who-is @@ -88,11 +82,10 @@ static void Init_Service_Handlers( apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, handler_who_is); /* set the handler for all the services we don't implement It is required to send the proper reject message... */ - apdu_set_unrecognized_service_handler_handler - (handler_unrecognized_service); + apdu_set_unrecognized_service_handler_handler(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 reply (request) coming back */ apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_I_AM, handler_i_am_add); /* handle any errors coming back */ @@ -103,7 +96,7 @@ static void Init_Service_Handlers( static void print_usage(char *filename) { printf("Usage: %s [error-class error-code service-number invoke-id]\n", - filename); + filename); printf(" [--dnet][--dadr][--mac]\n"); printf(" [--version][--help]\n"); } @@ -111,7 +104,8 @@ static void print_usage(char *filename) static void print_help(char *filename) { printf("Send BACnet Error message to the network.\n"); - printf("--mac A\n" + printf( + "--mac A\n" "Optional destination BACnet mac address." "Valid ranges are from 00 to FF (hex) for MS/TP or ARCNET,\n" "or an IP string with optional port number like 10.1.2.3:47808\n" @@ -123,12 +117,14 @@ static void print_help(char *filename) "and 65535 is network broadcast.\n" "\n" "--dadr A\n" - "Optional BACnet mac address on the destination BACnet network number.\n" + "Optional BACnet mac address on the destination BACnet network " + "number.\n" "Valid ranges are from 00 to FF (hex) for MS/TP or ARCNET,\n" "or an IP string with optional port number like 10.1.2.3:47808\n" "or an Ethernet MAC in hex like 00:21:70:7e:32:bb\n" "\n"); - printf("error-class:\n" + printf( + "error-class:\n" " number from 0 to 65535\n" "error-code:\n" " number from 0 to 65535\n" @@ -141,14 +137,12 @@ static void print_help(char *filename) filename); } -int main( - int argc, - char *argv[]) +int main(int argc, char *argv[]) { long dnet = -1; - BACNET_MAC_ADDRESS mac = { 0 }; - BACNET_MAC_ADDRESS adr = { 0 }; - BACNET_ADDRESS dest = { 0 }; + BACNET_MAC_ADDRESS mac = {0}; + BACNET_MAC_ADDRESS adr = {0}; + BACNET_ADDRESS dest = {0}; bool specific_address = false; int argi = 0; unsigned int target_args = 0; @@ -163,8 +157,10 @@ int main( } if (strcmp(argv[argi], "--version") == 0) { printf("%s %s\n", filename, BACNET_VERSION_TEXT); - printf("Copyright (C) 2016 by Steve Karg and others.\n" - "This is free software; see the source for copying conditions.\n" + printf( + "Copyright (C) 2016 by Steve Karg and others.\n" + "This is free software; see the source for copying " + "conditions.\n" "There is NO warranty; not even for MERCHANTABILITY or\n" "FITNESS FOR A PARTICULAR PURPOSE.\n"); return 0; @@ -245,12 +241,9 @@ int main( dlenv_init(); atexit(datalink_cleanup); /* send the request */ - Send_Error_To_Network(&Handler_Transmit_Buffer[0], - &dest, - Target_Invoke_ID, - Target_Service, - Target_Error_Class, - Target_Error_Code); + Send_Error_To_Network(&Handler_Transmit_Buffer[0], &dest, Target_Invoke_ID, + Target_Service, Target_Error_Class, + Target_Error_Code); return 0; } diff --git a/demo/gateway/main.c b/demo/gateway/main.c index b5f4c26d..3354bcbc 100644 --- a/demo/gateway/main.c +++ b/demo/gateway/main.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2006 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2006 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /** * Code for this project began with code from the demo/server project and * Paul Chapman's vmac project. @@ -60,7 +60,8 @@ #include "vmac.h" #endif -/** @file gateway/main.c Example virtual gateway application using the BACnet Stack. */ +/** @file gateway/main.c Example virtual gateway application using the BACnet + * Stack. */ /* Prototypes */ @@ -70,23 +71,20 @@ /*@{*/ /** Buffer used for receiving */ -static uint8_t Rx_Buf[MAX_MPDU] = { 0 }; +static uint8_t Rx_Buf[MAX_MPDU] = {0}; /** The list of DNETs that our router can reach. * Only one entry since we don't support downstream routers. */ int DNET_list[2] = { - VIRTUAL_DNET, -1 /* Need -1 terminator */ + VIRTUAL_DNET, -1 /* Need -1 terminator */ }; - - /** Initialize the Device Objects and each of the child Object instances. * @param first_object_instance Set the first (gateway) Device to this instance number, and subsequent devices to incremented values. */ -static void Devices_Init( - uint32_t first_object_instance) +static void Devices_Init(uint32_t first_object_instance) { int i; char nameText[MAX_DEV_NAME_LEN]; @@ -95,8 +93,7 @@ static void Devices_Init( /* Gateway Device has already been initialized. * But give it a better Description. */ - Routed_Device_Set_Description(DEV_DESCR_GATEWAY, - strlen(DEV_DESCR_GATEWAY)); + Routed_Device_Set_Description(DEV_DESCR_GATEWAY, strlen(DEV_DESCR_GATEWAY)); /* Now initialize the remote Device objects. */ for (i = 1; i < MAX_NUM_DEVICES; i++) { @@ -111,15 +108,12 @@ static void Devices_Init( Add_Routed_Device((first_object_instance + i), &name_string, descText); } - } - /** Initialize the handlers we will utilize. * @see Device_Init, apdu_set_unconfirmed_handler, apdu_set_confirmed_handler */ -static void Init_Service_Handlers( - uint32_t first_object_instance) +static void Init_Service_Handlers(uint32_t first_object_instance) { Device_Init(NULL); Routing_Device_Init(first_object_instance); @@ -131,41 +125,40 @@ static void Init_Service_Handlers( * each device in turn. */ apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, - handler_who_is_unicast); + handler_who_is_unicast); apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_HAS, handler_who_has); /* set the handler for all the services we don't implement */ /* It is required to send the proper reject message... */ - apdu_set_unrecognized_service_handler_handler - (handler_unrecognized_service); + apdu_set_unrecognized_service_handler_handler(handler_unrecognized_service); /* 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, - handler_read_property); + handler_read_property); apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROP_MULTIPLE, - handler_read_property_multiple); + handler_read_property_multiple); apdu_set_confirmed_handler(SERVICE_CONFIRMED_WRITE_PROPERTY, - handler_write_property); + handler_write_property); apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_RANGE, - handler_read_range); + handler_read_range); #if defined(BACFILE) apdu_set_confirmed_handler(SERVICE_CONFIRMED_ATOMIC_READ_FILE, - handler_atomic_read_file); + handler_atomic_read_file); apdu_set_confirmed_handler(SERVICE_CONFIRMED_ATOMIC_WRITE_FILE, - handler_atomic_write_file); + handler_atomic_write_file); #endif apdu_set_confirmed_handler(SERVICE_CONFIRMED_REINITIALIZE_DEVICE, - handler_reinitialize_device); + handler_reinitialize_device); apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_UTC_TIME_SYNCHRONIZATION, - handler_timesync_utc); + handler_timesync_utc); apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION, - handler_timesync); + handler_timesync); apdu_set_confirmed_handler(SERVICE_CONFIRMED_SUBSCRIBE_COV, - handler_cov_subscribe); + handler_cov_subscribe); apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_COV_NOTIFICATION, - handler_ucov_notification); + handler_ucov_notification); /* handle communication so we can shutup when asked */ apdu_set_confirmed_handler(SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL, - handler_device_communication_control); + handler_device_communication_control); } /** Initialize the BACnet Device Addresses for each Device object. @@ -176,20 +169,19 @@ static void Init_Service_Handlers( * device.) This is sure to be unique! The port number stays the same. * - For MS/TP, [Steve inserts a good idea here] */ -static void Initialize_Device_Addresses( - ) +static void Initialize_Device_Addresses() { - int i = 0; /* First entry is Gateway Device */ + int i = 0; /* First entry is Gateway Device */ uint32_t virtual_mac = 0; DEVICE_OBJECT_DATA *pDev = NULL; /* Setup info for the main gateway device first */ pDev = Get_Routed_Device_Object(i); #if defined(BACDL_BIP) uint16_t myPort; - struct in_addr *netPtr; /* Lets us cast to this type */ + struct in_addr *netPtr; /* Lets us cast to this type */ uint8_t *gatewayMac = NULL; uint32_t myAddr = bip_get_addr(); - gatewayMac = pDev->bacDevAddr.mac; /* Keep pointer to the main MAC */ + gatewayMac = pDev->bacDevAddr.mac; /* Keep pointer to the main MAC */ memcpy(pDev->bacDevAddr.mac, &myAddr, 4); myPort = bip_get_port(); memcpy(&pDev->bacDevAddr.mac[4], &myPort, 2); @@ -209,7 +201,7 @@ static void Initialize_Device_Addresses( continue; #if defined(BACDL_BIP) virtual_mac = i; - netPtr = (struct in_addr *) pDev->bacDevAddr.mac; + netPtr = (struct in_addr *)pDev->bacDevAddr.mac; #if (MAX_NUM_DEVICES > 0xFFFFFF) pDev->bacDevAddr.mac[0] = ((virtual_mac & 0xff000000) >> 24); #else @@ -232,14 +224,13 @@ static void Initialize_Device_Addresses( memcpy(&pDev->bacDevAddr.adr[0], &pDev->bacDevAddr.mac[0], 6); pDev->bacDevAddr.len = 6; printf(" - Routed device [%d] ID %u at %s \n", i, - pDev->bacObj.Object_Instance_Number, inet_ntoa(*netPtr)); + pDev->bacObj.Object_Instance_Number, inet_ntoa(*netPtr)); #elif defined(BACDL_MSTP) /* Todo: set MS/TP net and port #s */ pDev->bacDevAddr.mac_len = 2; #endif /* broadcast an I-Am for each routed Device now */ Send_I_Am(&Handler_Transmit_Buffer[0]); - } } @@ -255,15 +246,11 @@ static void Initialize_Device_Addresses( * @param argv [in] Takes one argument: the Device Instance #. * @return 0 on success. */ -int main( - int argc, - char *argv[]) +int main(int argc, char *argv[]) { - BACNET_ADDRESS src = { - 0 - }; /* address where message came from */ + BACNET_ADDRESS src = {0}; /* address where message came from */ uint16_t pdu_len = 0; - unsigned timeout = 1000; /* milliseconds */ + unsigned timeout = 1000; /* milliseconds */ time_t last_seconds = 0; time_t current_seconds = 0; uint32_t elapsed_seconds = 0; @@ -282,13 +269,16 @@ int main( (first_object_instance >= BACNET_MAX_INSTANCE)) { printf("Error: Invalid Object Instance %s \n", argv[1]); printf("Provide a number from 1 to %ul \n", - BACNET_MAX_INSTANCE - 1); + BACNET_MAX_INSTANCE - 1); exit(1); } } - printf("BACnet Router Demo\n" "BACnet Stack Version %s\n" - "BACnet Device ID: %u\n" "Max APDU: %d\n", BACnet_Version, - first_object_instance, MAX_APDU); + printf( + "BACnet Router Demo\n" + "BACnet Stack Version %s\n" + "BACnet Device ID: %u\n" + "Max APDU: %d\n", + BACnet_Version, first_object_instance, MAX_APDU); Init_Service_Handlers(first_object_instance); dlenv_init(); atexit(datalink_cleanup); diff --git a/demo/getevent/main.c b/demo/getevent/main.c index 2f7f724a..28e986eb 100755 --- a/demo/getevent/main.c +++ b/demo/getevent/main.c @@ -1,26 +1,26 @@ /************************************************************************* -* Copyright (C) 2015 B Weitsch -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * Copyright (C) 2015 B Weitsch + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* command line tool that sends a BACnet service, and displays the reply */ #include @@ -73,45 +73,38 @@ static bool Recieved_Ack = false; static bool More_Events = false; static BACNET_OBJECT_ID LastReceivedObjectIdentifier; -static void MyErrorHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - BACNET_ERROR_CLASS error_class, - BACNET_ERROR_CODE error_code) +static void MyErrorHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + BACNET_ERROR_CLASS error_class, + BACNET_ERROR_CODE error_code) { if (address_match(&Target_Address, src) && (invoke_id == Request_Invoke_ID)) { printf("BACnet Error: %s: %s\r\n", - bactext_error_class_name((int) error_class), - bactext_error_code_name((int) error_code)); + bactext_error_class_name((int)error_class), + bactext_error_code_name((int)error_code)); Error_Detected = true; } } -void MyAbortHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t abort_reason, - bool server) +void MyAbortHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t abort_reason, bool server) { - (void) server; + (void)server; if (address_match(&Target_Address, src) && (invoke_id == Request_Invoke_ID)) { printf("BACnet Abort: %s\r\n", - bactext_abort_reason_name((int) abort_reason)); + bactext_abort_reason_name((int)abort_reason)); Error_Detected = true; } } -void MyRejectHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t reject_reason) +void MyRejectHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t reject_reason) { if (address_match(&Target_Address, src) && (invoke_id == Request_Invoke_ID)) { printf("BACnet Reject: %s\r\n", - bactext_reject_reason_name((int) reject_reason)); + bactext_reject_reason_name((int)reject_reason)); Error_Detected = true; } } @@ -126,32 +119,31 @@ void MyRejectHandler( * @param service_data [in] The BACNET_CONFIRMED_SERVICE_DATA information * decoded from the APDU header of this message. */ -void My_Get_Event_Ack_Handler( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src, - BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data) +void My_Get_Event_Ack_Handler(uint8_t *service_request, uint16_t service_len, + BACNET_ADDRESS *src, + BACNET_CONFIRMED_SERVICE_ACK_DATA *service_data) { int len = 0; int i; BACNET_GET_EVENT_INFORMATION_DATA data[MAX_OBJ_IDS_IN_GE_ACK]; for (i = 0; i < MAX_OBJ_IDS_IN_GE_ACK - 1; i++) - data[i].next = &data[i+1]; + data[i].next = &data[i + 1]; - printf("Recieved Ack. Saved invoke ID was %i, service returned %i\n", Request_Invoke_ID, service_data->invoke_id); + printf("Recieved Ack. Saved invoke ID was %i, service returned %i\n", + Request_Invoke_ID, service_data->invoke_id); if (service_data->invoke_id == Request_Invoke_ID) { - len = getevent_ack_decode_service_request(service_request, - service_len, - &data[0], - &More_Events); - printf("Decode of Ack returned length %i. MoreEvents flag was %i \n", len, More_Events); + len = getevent_ack_decode_service_request(service_request, service_len, + &data[0], &More_Events); + printf("Decode of Ack returned length %i. MoreEvents flag was %i \n", + len, More_Events); if (len > 0) { ge_ack_print_data(&(data[0]), Target_Device_Object_Instance); if (More_Events) { - BACNET_GET_EVENT_INFORMATION_DATA * lastData = &(data[0]); - while (lastData->next) lastData = lastData->next; - LastReceivedObjectIdentifier = lastData->objectIdentifier; + BACNET_GET_EVENT_INFORMATION_DATA *lastData = &(data[0]); + while (lastData->next) + lastData = lastData->next; + LastReceivedObjectIdentifier = lastData->objectIdentifier; } } } @@ -181,18 +173,25 @@ static void Init_Service_Handlers(void) apdu_set_reject_handler(MyRejectHandler); } -static int print_help(char *exe_name){ - printf("Usage:\n" "\n" "%s device-instance [--help]\n" "\n" - " Send BACnet GetEventInformation service retruequest to given device, and wait\n" - " for responses.\n\n", exe_name); +static int print_help(char *exe_name) +{ + printf( + "Usage:\n" + "\n" + "%s device-instance [--help]\n" + "\n" + " Send BACnet GetEventInformation service retruequest to given " + "device, and wait\n" + " for responses.\n\n", + exe_name); return 1; } int main(int argc, char *argv[]) { - BACNET_ADDRESS src = {0}; /* address where message came from */ + BACNET_ADDRESS src = {0}; /* address where message came from */ uint16_t pdu_len = 0; - unsigned timeout = 100; /* milliseconds */ + unsigned timeout = 100; /* milliseconds */ unsigned max_apdu = 0; time_t elapsed_seconds = 0; time_t last_seconds = 0; @@ -205,7 +204,7 @@ int main(int argc, char *argv[]) if (argc <= 1) { printf("Usage: %s device-instance\r\n", filename_remove_path(argv[0])); return 0; - } else if(strcmp(argv[1], "--help") == 0) { + } else if (strcmp(argv[1], "--help") == 0) { print_help(filename_remove_path(argv[0])); return 0; } @@ -221,11 +220,11 @@ int main(int argc, char *argv[]) last_seconds = time(NULL); timeout_seconds = (apdu_timeout() / 1000) * apdu_retries(); /* try to bind with the device */ - found = address_bind_request(Target_Device_Object_Instance, - &max_apdu, - &Target_Address); + found = address_bind_request(Target_Device_Object_Instance, &max_apdu, + &Target_Address); if (!found) { - Send_WhoIs(Target_Device_Object_Instance, Target_Device_Object_Instance); + Send_WhoIs(Target_Device_Object_Instance, + Target_Device_Object_Instance); } /* loop forever */ for (;;) { @@ -234,14 +233,16 @@ int main(int argc, char *argv[]) /* at least one second has passed */ if (current_seconds != last_seconds) - tsm_timer_milliseconds((uint16_t) ((current_seconds - last_seconds) * 1000)); + tsm_timer_milliseconds( + (uint16_t)((current_seconds - last_seconds) * 1000)); - if (Error_Detected){break;} + if (Error_Detected) { + break; + } /* wait until the device is bound, or timeout and quit */ if (!found) { found = address_bind_request(Target_Device_Object_Instance, - &max_apdu, - &Target_Address); + &max_apdu, &Target_Address); } if (found) { if (Request_Invoke_ID == 0) { @@ -249,8 +250,8 @@ int main(int argc, char *argv[]) Request_Invoke_ID = Send_GetEvent(&Target_Address, NULL); } else if (More_Events) { printf("\nSending another GetEventInformation request ...\n"); - Request_Invoke_ID = Send_GetEvent(&Target_Address, - &LastReceivedObjectIdentifier); + Request_Invoke_ID = Send_GetEvent( + &Target_Address, &LastReceivedObjectIdentifier); More_Events = false; } else if (tsm_invoke_id_free(Request_Invoke_ID)) { if (Recieved_Ack) { diff --git a/demo/handler/dlenv.c b/demo/handler/dlenv.c index 4cf77af5..f82a603b 100644 --- a/demo/handler/dlenv.c +++ b/demo/handler/dlenv.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2009 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2009 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* environment variables used for the command line tools */ #include @@ -52,7 +52,6 @@ static long bbmd_mask = 0xFFFFFFFF; static int bbmd_result = 0; static BBMD_TABLE_ENTRY BBMD_Table_Entry; - /* Simple setters for BBMD registration variables. */ /** Sets the IPv4 address for BBMD registration. @@ -61,8 +60,7 @@ static BBMD_TABLE_ENTRY BBMD_Table_Entry; * @param address - IPv4 address (long) of BBMD to register with, * in network byte order. */ -void dlenv_bbmd_address_set( - long address) +void dlenv_bbmd_address_set(long address) { bbmd_address = address; } @@ -71,8 +69,7 @@ void dlenv_bbmd_address_set( * Default if not set is 0xBAC0. * @param port - The port number (provided in network byte order). */ -void dlenv_bbmd_port_set( - int port) +void dlenv_bbmd_port_set(int port) { bbmd_port = port; } @@ -81,8 +78,7 @@ void dlenv_bbmd_port_set( * Default if not set is 60000 (1000 minutes). * @param ttl_secs - The Lease Time, in seconds. */ -void dlenv_bbmd_ttl_set( - int ttl_secs) +void dlenv_bbmd_ttl_set(int ttl_secs) { bbmd_timetolive_seconds = ttl_secs; } @@ -95,8 +91,7 @@ void dlenv_bbmd_ttl_set( * 0 if no registration request was made, or * -1 if registration attempt failed. */ -int dlenv_bbmd_result( - void) +int dlenv_bbmd_result(void) { if ((bbmd_result > 0) && (bvlc_get_last_result() == BVLC_RESULT_REGISTER_FOREIGN_DEVICE_NAK)) @@ -120,8 +115,7 @@ int dlenv_bbmd_result( * 0 if no registration request is sent, or * -1 if registration fails. */ -int dlenv_register_as_foreign_device( - void) +int dlenv_register_as_foreign_device(void) { int retval = 0; #if defined(BACDL_BIP) @@ -153,17 +147,17 @@ int dlenv_register_as_foreign_device( struct in_addr addr; addr.s_addr = bbmd_address; fprintf(stderr, "Registering with BBMD at %s:%ld for %ld seconds\n", - inet_ntoa(addr), bbmd_port, bbmd_timetolive_seconds); + inet_ntoa(addr), bbmd_port, bbmd_timetolive_seconds); retval = - bvlc_register_with_bbmd(bbmd_address, htons((uint16_t) bbmd_port), - (uint16_t) bbmd_timetolive_seconds); + bvlc_register_with_bbmd(bbmd_address, htons((uint16_t)bbmd_port), + (uint16_t)bbmd_timetolive_seconds); if (retval < 0) fprintf(stderr, "FAILED to Register with BBMD at %s \n", - inet_ntoa(addr)); - BBMD_Timer_Seconds = (uint16_t) bbmd_timetolive_seconds; + inet_ntoa(addr)); + BBMD_Timer_Seconds = (uint16_t)bbmd_timetolive_seconds; } else { for (entry_number = 1; entry_number <= 128; entry_number++) { - sprintf(bbmd_env,"BACNET_BDT_ADDR_%u", entry_number); + sprintf(bbmd_env, "BACNET_BDT_ADDR_%u", entry_number); pEnv = getenv(bbmd_env); if (pEnv) { bbmd_address = bip_getaddrbyname(pEnv); @@ -173,7 +167,7 @@ int dlenv_register_as_foreign_device( } if (bbmd_address) { bbmd_port = 0xBAC0; - sprintf(bbmd_env,"BACNET_BDT_PORT_%u", entry_number); + sprintf(bbmd_env, "BACNET_BDT_PORT_%u", entry_number); pEnv = getenv(bbmd_env); if (pEnv) { bbmd_port = strtol(pEnv, NULL, 0); @@ -185,15 +179,15 @@ int dlenv_register_as_foreign_device( bbmd_port = bip_get_port(); } bbmd_mask = 0xFFFFFFFF; - sprintf(bbmd_env,"BACNET_BDT_MASK_%u", entry_number); + sprintf(bbmd_env, "BACNET_BDT_MASK_%u", entry_number); pEnv = getenv(bbmd_env); if (pEnv) { - c = sscanf(pEnv, "%3u.%3u.%3u.%3u", - &a[0],&a[1],&a[2],&a[3]); + c = sscanf(pEnv, "%3u.%3u.%3u.%3u", &a[0], &a[1], &a[2], + &a[3]); if (c == 4) { - bbmd_mask = - ((a[0]&0xFF)<<24)|((a[1]&0xFF)<<16)| - ((a[2]&0xFF)<<8)|(a[3]&0xFF); + bbmd_mask = ((a[0] & 0xFF) << 24) | + ((a[1] & 0xFF) << 16) | + ((a[2] & 0xFF) << 8) | (a[3] & 0xFF); } } BBMD_Table_Entry.valid = true; @@ -222,7 +216,7 @@ static void dlenv_network_port_init(void) uint32_t test_broadcast = 0; uint32_t mask = 0; uint16_t port = 0; - uint8_t mac[4+2] = {0}; + uint8_t mac[4 + 2] = {0}; uint8_t prefix = 0; Network_Port_Object_Instance_Number_Set(0, instance); @@ -331,8 +325,7 @@ static void dlenv_network_port_init(void) * Call this function to renew our Foreign Device Registration * @param elapsed_seconds Number of seconds that have elapsed since last called. */ -void dlenv_maintenance_timer( - uint16_t elapsed_seconds) +void dlenv_maintenance_timer(uint16_t elapsed_seconds) { #if defined(BACDL_BIP) if (BBMD_Timer_Seconds) { @@ -342,11 +335,11 @@ void dlenv_maintenance_timer( BBMD_Timer_Seconds -= elapsed_seconds; } if (BBMD_Timer_Seconds == 0) { - (void) dlenv_register_as_foreign_device(); + (void)dlenv_register_as_foreign_device(); /* If that failed (negative), maybe just a network issue. * If nothing happened (0), may be un/misconfigured. * Set up to try again later in all cases. */ - BBMD_Timer_Seconds = (uint16_t) bbmd_timetolive_seconds; + BBMD_Timer_Seconds = (uint16_t)bbmd_timetolive_seconds; } } #endif @@ -402,8 +395,7 @@ void dlenv_maintenance_timer( * communications. Default is 47808 (0xBAC0). * - BACNET_BIP6_BROADCAST - FF05::BAC0 or FF02::BAC0 or ... */ -void dlenv_init( - void) +void dlenv_init(void) { char *pEnv = NULL; @@ -419,19 +411,17 @@ void dlenv_init( BACNET_IP6_ADDRESS addr; pEnv = getenv("BACNET_BIP6_BROADCAST"); if (pEnv) { - bvlc6_address_set(&addr, - (uint16_t) strtol(pEnv, NULL, 0), 0, 0, 0, 0, 0, 0, - BIP6_MULTICAST_GROUP_ID); + bvlc6_address_set(&addr, (uint16_t)strtol(pEnv, NULL, 0), 0, 0, 0, 0, 0, + 0, BIP6_MULTICAST_GROUP_ID); bip6_set_broadcast_addr(&addr); } else { - bvlc6_address_set(&addr, - BIP6_MULTICAST_SITE_LOCAL, 0, 0, 0, 0, 0, 0, - BIP6_MULTICAST_GROUP_ID); + bvlc6_address_set(&addr, BIP6_MULTICAST_SITE_LOCAL, 0, 0, 0, 0, 0, 0, + BIP6_MULTICAST_GROUP_ID); bip6_set_broadcast_addr(&addr); } pEnv = getenv("BACNET_BIP6_PORT"); if (pEnv) { - bip6_set_port((uint16_t) strtol(pEnv, NULL, 0)); + bip6_set_port((uint16_t)strtol(pEnv, NULL, 0)); } else { bip6_set_port(0xBAC0); } @@ -442,7 +432,7 @@ void dlenv_init( #endif pEnv = getenv("BACNET_IP_PORT"); if (pEnv) { - bip_set_port(htons((uint16_t) strtol(pEnv, NULL, 0))); + bip_set_port(htons((uint16_t)strtol(pEnv, NULL, 0))); } else { /* BIP_Port is statically initialized to 0xBAC0, * so if it is different, then it was programmatically altered, @@ -489,7 +479,7 @@ void dlenv_init( #endif pEnv = getenv("BACNET_APDU_TIMEOUT"); if (pEnv) { - apdu_timeout_set((uint16_t) strtol(pEnv, NULL, 0)); + apdu_timeout_set((uint16_t)strtol(pEnv, NULL, 0)); } else { #if defined(BACDL_MSTP) apdu_timeout_set(60000); @@ -497,7 +487,7 @@ void dlenv_init( } pEnv = getenv("BACNET_APDU_RETRIES"); if (pEnv) { - apdu_retries_set((uint8_t) strtol(pEnv, NULL, 0)); + apdu_retries_set((uint8_t)strtol(pEnv, NULL, 0)); } /* === Initialize the Datalink Here === */ if (!datalink_init(getenv("BACNET_IFACE"))) { @@ -506,7 +496,7 @@ void dlenv_init( #if (MAX_TSM_TRANSACTIONS) pEnv = getenv("BACNET_INVOKE_ID"); if (pEnv) { - tsm_invokeID_set((uint8_t) strtol(pEnv, NULL, 0)); + tsm_invokeID_set((uint8_t)strtol(pEnv, NULL, 0)); } #endif dlenv_network_port_init(); diff --git a/demo/handler/h_alarm_ack.c b/demo/handler/h_alarm_ack.c index 33c5e49a..6f96a696 100644 --- a/demo/handler/h_alarm_ack.c +++ b/demo/handler/h_alarm_ack.c @@ -1,28 +1,28 @@ /************************************************************************** -* -* Copyright (C) 2005 Steve Karg -* Copyright (C) 2011 Krzysztof Malorny -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2005 Steve Karg + * Copyright (C) 2011 Krzysztof Malorny + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -42,14 +42,12 @@ #include "handlers.h" #include "device.h" - /** @file h_alarm_ack.c Handles Alarm Acknowledgment. */ static alarm_ack_function Alarm_Ack[MAX_BACNET_OBJECT_TYPE]; -void handler_alarm_ack_set( - BACNET_OBJECT_TYPE object_type, - alarm_ack_function pFunction) +void handler_alarm_ack_set(BACNET_OBJECT_TYPE object_type, + alarm_ack_function pFunction) { if (object_type < MAX_BACNET_OBJECT_TYPE) { Alarm_Ack[object_type] = pFunction; @@ -72,11 +70,9 @@ void handler_alarm_ack_set( * @param service_data [in] The BACNET_CONFIRMED_SERVICE_DATA information * decoded from the APDU header of this message. */ -void handler_alarm_ack( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src, - BACNET_CONFIRMED_SERVICE_DATA * service_data) +void handler_alarm_ack(uint8_t* service_request, uint16_t service_len, + BACNET_ADDRESS* src, + BACNET_CONFIRMED_SERVICE_DATA* service_data) { int len = 0; int pdu_len = 0; @@ -90,32 +86,29 @@ void handler_alarm_ack( /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); - pdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address, - &npdu_data); + pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address, + &npdu_data); if (service_data->segmented_message) { /* we don't support segmentation - send an abort */ - len = - abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, - true); + len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], + service_data->invoke_id, + ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); #if PRINT_ENABLED fprintf(stderr, "Alarm Ack: Segmented message. Sending Abort!\n"); #endif goto AA_ABORT; } - len = - alarm_ack_decode_service_request(service_request, service_len, &data); + len = alarm_ack_decode_service_request(service_request, service_len, &data); #if PRINT_ENABLED if (len <= 0) fprintf(stderr, "Alarm Ack: Unable to decode Request!\n"); #endif if (len < 0) { /* bad decoding - send an abort */ - len = - abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, ABORT_REASON_OTHER, true); + len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], + service_data->invoke_id, ABORT_REASON_OTHER, + true); #if PRINT_ENABLED fprintf(stderr, "Alarm Ack: Bad Encoding. Sending Abort!\n"); #endif @@ -123,82 +116,81 @@ void handler_alarm_ack( } #if PRINT_ENABLED fprintf(stderr, - "Alarm Ack Operation: Received acknowledge for object id (%d, %lu) from %s for process id %lu \n", - data.eventObjectIdentifier.type, - (unsigned long) data.eventObjectIdentifier.instance, - data.ackSource.value, (unsigned long) data.ackProcessIdentifier); + "Alarm Ack Operation: Received acknowledge for object id (%d, %lu) " + "from %s for process id %lu \n", + data.eventObjectIdentifier.type, + (unsigned long)data.eventObjectIdentifier.instance, + data.ackSource.value, (unsigned long)data.ackProcessIdentifier); #endif - /* BACnet Testing Observed Incident oi00105 - ACK of a non-existent object returned the incorrect error code - Revealed by BACnet Test Client v1.8.16 ( www.bac-test.com/bacnet-test-client-download ) - BC 135.1: 9.1.3.3-A - Any discussions can be directed to edward@bac-test.com */ - if (!Device_Valid_Object_Id(data.eventObjectIdentifier.type, data.eventObjectIdentifier.instance)) - { - len = - bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, - SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM, ERROR_CLASS_OBJECT, ERROR_CODE_UNKNOWN_OBJECT); - } - else if (Alarm_Ack[data.eventObjectIdentifier.type]) { - + /* BACnet Testing Observed Incident oi00105 + ACK of a non-existent object returned the incorrect error code + Revealed by BACnet Test Client v1.8.16 ( + www.bac-test.com/bacnet-test-client-download ) BC 135.1: 9.1.3.3-A Any + discussions can be directed to edward@bac-test.com */ + if (!Device_Valid_Object_Id(data.eventObjectIdentifier.type, + data.eventObjectIdentifier.instance)) { + len = bacerror_encode_apdu( + &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, + SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM, ERROR_CLASS_OBJECT, + ERROR_CODE_UNKNOWN_OBJECT); + } else if (Alarm_Ack[data.eventObjectIdentifier.type]) { ack_result = - Alarm_Ack[data.eventObjectIdentifier.type] (&data, &error_code); + Alarm_Ack[data.eventObjectIdentifier.type](&data, &error_code); switch (ack_result) { case 1: - len = - encode_simple_ack(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, - SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM); + len = encode_simple_ack(&Handler_Transmit_Buffer[pdu_len], + service_data->invoke_id, + SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM); #if PRINT_ENABLED - fprintf(stderr, "Alarm Acknowledge: " "Sending Simple Ack!\n"); + fprintf(stderr, + "Alarm Acknowledge: " + "Sending Simple Ack!\n"); #endif break; case -1: - len = - bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, - SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM, ERROR_CLASS_OBJECT, - error_code); + len = bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], + service_data->invoke_id, + SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM, + ERROR_CLASS_OBJECT, error_code); #if PRINT_ENABLED fprintf(stderr, "Alarm Acknowledge: error %s!\n", - bactext_error_code_name(error_code)); + bactext_error_code_name(error_code)); #endif break; default: - len = - abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, ABORT_REASON_OTHER, true); + len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], + service_data->invoke_id, + ABORT_REASON_OTHER, true); #if PRINT_ENABLED fprintf(stderr, "Alarm Acknowledge: abort other!\n"); #endif break; } } else { - len = - bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM, - ERROR_CLASS_OBJECT, ERROR_CODE_NO_ALARM_CONFIGURED); + len = bacerror_encode_apdu( + &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, + SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM, ERROR_CLASS_OBJECT, + ERROR_CODE_NO_ALARM_CONFIGURED); #if PRINT_ENABLED fprintf(stderr, "Alarm Acknowledge: error %s!\n", - bactext_error_code_name(ERROR_CODE_NO_ALARM_CONFIGURED)); + bactext_error_code_name(ERROR_CODE_NO_ALARM_CONFIGURED)); #endif } - - AA_ABORT: +AA_ABORT: pdu_len += len; - bytes_sent = - datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], - pdu_len); + bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], + pdu_len); #if PRINT_ENABLED if (bytes_sent <= 0) - fprintf(stderr, "Alarm Acknowledge: " "Failed to send PDU (%s)!\n", - strerror(errno)); + fprintf(stderr, + "Alarm Acknowledge: " + "Failed to send PDU (%s)!\n", + strerror(errno)); #endif return; diff --git a/demo/handler/h_arf.c b/demo/handler/h_arf.c index 54f8d012..65830ba6 100644 --- a/demo/handler/h_arf.c +++ b/demo/handler/h_arf.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2005 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2005 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -96,11 +96,9 @@ shall be TRUE, otherwise FALSE. */ #if defined(BACFILE) -void handler_atomic_read_file( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src, - BACNET_CONFIRMED_SERVICE_DATA * service_data) +void handler_atomic_read_file(uint8_t* service_request, uint16_t service_len, + BACNET_ADDRESS* src, + BACNET_CONFIRMED_SERVICE_DATA* service_data) { BACNET_ATOMIC_READ_FILE_DATA data; int len = 0; @@ -118,14 +116,12 @@ void handler_atomic_read_file( /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); - pdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address, - &npdu_data); + pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address, + &npdu_data); if (service_data->segmented_message) { - len = - abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, - true); + len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], + service_data->invoke_id, + ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); #if PRINT_ENABLED fprintf(stderr, "ARF: Segmented Message. Sending Abort!\n"); #endif @@ -134,9 +130,9 @@ void handler_atomic_read_file( len = arf_decode_service_request(service_request, service_len, &data); /* bad decoding - send an abort */ if (len < 0) { - len = - abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, ABORT_REASON_OTHER, true); + len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], + service_data->invoke_id, ABORT_REASON_OTHER, + true); #if PRINT_ENABLED fprintf(stderr, "Bad Encoding. Sending Abort!\n"); #endif @@ -150,22 +146,20 @@ void handler_atomic_read_file( octetstring_capacity(&data.fileData[0])) { bacfile_read_stream_data(&data); #if PRINT_ENABLED - fprintf(stderr, "ARF: Stream offset %d, %d octets.\n", - data.type.stream.fileStartPosition, - data.type.stream.requestedOctetCount); + fprintf(stderr, "ARF: Stream offset %d, %d octets.\n", + data.type.stream.fileStartPosition, + data.type.stream.requestedOctetCount); #endif - len = - arf_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, &data); + len = arf_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len], + service_data->invoke_id, &data); } else { - len = - abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, + len = abort_encode_apdu( + &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); #if PRINT_ENABLED fprintf(stderr, "Too Big To Send (%d >= %d). Sending Abort!\n", - data.type.stream.requestedOctetCount, - (int)octetstring_capacity(&data.fileData[0])); + data.type.stream.requestedOctetCount, + (int)octetstring_capacity(&data.fileData[0])); #endif } } else if (data.access == FILE_RECORD_ACCESS) { @@ -177,12 +171,11 @@ void handler_atomic_read_file( } else if (bacfile_read_stream_data(&data)) { #if PRINT_ENABLED fprintf(stderr, "ARF: fileStartRecord %d, %u RecordCount.\n", - data.type.record.fileStartRecord, - data.type.record.RecordCount); + data.type.record.fileStartRecord, + data.type.record.RecordCount); #endif - len = - arf_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, &data); + len = arf_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len], + service_data->invoke_id, &data); } else { error = true; error_class = ERROR_CLASS_OBJECT; @@ -202,16 +195,14 @@ void handler_atomic_read_file( error_code = ERROR_CODE_INCONSISTENT_OBJECT_TYPE; } if (error) { - len = - bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, SERVICE_CONFIRMED_ATOMIC_READ_FILE, - error_class, error_code); + len = bacerror_encode_apdu( + &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, + SERVICE_CONFIRMED_ATOMIC_READ_FILE, error_class, error_code); } - ARF_ABORT: +ARF_ABORT: pdu_len += len; - bytes_sent = - datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], - pdu_len); + bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], + pdu_len); #if PRINT_ENABLED if (bytes_sent <= 0) { fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno)); diff --git a/demo/handler/h_arf_a.c b/demo/handler/h_arf_a.c index bfcebf25..d1cd77ad 100644 --- a/demo/handler/h_arf_a.c +++ b/demo/handler/h_arf_a.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2005 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2005 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include "config.h" @@ -51,16 +51,14 @@ /* use the description as the file name. */ #if defined(BACFILE) void handler_atomic_read_file_ack( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src, - BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data) + uint8_t* service_request, uint16_t service_len, BACNET_ADDRESS* src, + BACNET_CONFIRMED_SERVICE_ACK_DATA* service_data) { int len = 0; BACNET_ATOMIC_READ_FILE_DATA data; uint32_t instance = 0; - (void) src; + (void)src; /* get the file instance from the tsm data before freeing it */ instance = bacfile_instance_from_tsm(service_data->invoke_id); len = arf_ack_decode_service_request(service_request, service_len, &data); diff --git a/demo/handler/h_awf.c b/demo/handler/h_awf.c index 1985d8d0..bfa88891 100644 --- a/demo/handler/h_awf.c +++ b/demo/handler/h_awf.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2007 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2007 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -76,11 +76,9 @@ standard. */ #if defined(BACFILE) -void handler_atomic_write_file( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src, - BACNET_CONFIRMED_SERVICE_DATA * service_data) +void handler_atomic_write_file(uint8_t* service_request, uint16_t service_len, + BACNET_ADDRESS* src, + BACNET_CONFIRMED_SERVICE_DATA* service_data) { BACNET_ATOMIC_WRITE_FILE_DATA data; int len = 0; @@ -98,14 +96,12 @@ void handler_atomic_write_file( /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); - pdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address, - &npdu_data); + pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address, + &npdu_data); if (service_data->segmented_message) { - len = - abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, - true); + len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], + service_data->invoke_id, + ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); #if PRINT_ENABLED fprintf(stderr, "Segmented Message. Sending Abort!\n"); #endif @@ -114,9 +110,9 @@ void handler_atomic_write_file( len = awf_decode_service_request(service_request, service_len, &data); /* bad decoding - send an abort */ if (len < 0) { - len = - abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, ABORT_REASON_OTHER, true); + len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], + service_data->invoke_id, ABORT_REASON_OTHER, + true); #if PRINT_ENABLED fprintf(stderr, "Bad Encoding. Sending Abort!\n"); #endif @@ -129,12 +125,11 @@ void handler_atomic_write_file( if (bacfile_write_stream_data(&data)) { #if PRINT_ENABLED fprintf(stderr, "AWF: Stream offset %d, %d bytes\n", - data.type.stream.fileStartPosition, - (int)octetstring_length(&data.fileData[0])); + data.type.stream.fileStartPosition, + (int)octetstring_length(&data.fileData[0])); #endif - len = - awf_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, &data); + len = awf_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len], + service_data->invoke_id, &data); } else { error = true; error_class = ERROR_CLASS_OBJECT; @@ -144,12 +139,11 @@ void handler_atomic_write_file( if (bacfile_write_record_data(&data)) { #if PRINT_ENABLED fprintf(stderr, "AWF: StartRecord %d, RecordCount %u\n", - data.type.record.fileStartRecord, - data.type.record.returnedRecordCount); + data.type.record.fileStartRecord, + data.type.record.returnedRecordCount); #endif - len = - awf_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, &data); + len = awf_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len], + service_data->invoke_id, &data); } else { error = true; error_class = ERROR_CLASS_OBJECT; @@ -169,16 +163,14 @@ void handler_atomic_write_file( error_code = ERROR_CODE_INCONSISTENT_OBJECT_TYPE; } if (error) { - len = - bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, SERVICE_CONFIRMED_ATOMIC_WRITE_FILE, - error_class, error_code); + len = bacerror_encode_apdu( + &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, + SERVICE_CONFIRMED_ATOMIC_WRITE_FILE, error_class, error_code); } - AWF_ABORT: +AWF_ABORT: pdu_len += len; - bytes_sent = - datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], - pdu_len); + bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], + pdu_len); #if PRINT_ENABLED if (bytes_sent <= 0) { fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno)); diff --git a/demo/handler/h_bbmd6.c b/demo/handler/h_bbmd6.c index e929f0ce..3790b522 100644 --- a/demo/handler/h_bbmd6.c +++ b/demo/handler/h_bbmd6.c @@ -32,10 +32,10 @@ ------------------------------------------- ####COPYRIGHTEND####*/ -#include /* for standard i/o, like printing */ -#include /* for standard integer types uint8_t etc. */ -#include /* for the standard bool type. */ -#include /* for memcpy */ +#include /* for standard i/o, like printing */ +#include /* for standard integer types uint8_t etc. */ +#include /* for the standard bool type. */ +#include /* for memcpy */ #include "bacdcode.h" #include "bip6.h" #include "bvlc6.h" @@ -61,7 +61,8 @@ static uint16_t BVLC6_Buffer_Len; #ifndef MAX_BBMD6_ENTRIES #define MAX_BBMD6_ENTRIES 128 #endif -static BACNET_IP6_BROADCAST_DISTRIBUTION_TABLE_ENTRY BBMD_Table[MAX_BBMD6_ENTRIES]; +static BACNET_IP6_BROADCAST_DISTRIBUTION_TABLE_ENTRY + BBMD_Table[MAX_BBMD6_ENTRIES]; /* Foreign Device Table */ #ifndef MAX_FD6_ENTRIES #define MAX_FD6_ENTRIES 128 @@ -74,8 +75,7 @@ static BACNET_IP6_FOREIGN_DEVICE_TABLE_ENTRY FD_Table[MAX_FD6_ENTRIES]; * * @param seconds - number of elapsed seconds since the last call */ -void bbmd6_maintenance_timer( - time_t seconds) +void bbmd6_maintenance_timer(time_t seconds) { unsigned i = 0; @@ -104,9 +104,8 @@ void bbmd6_maintenance_timer( * * @return true if the address was set */ -static bool bbmd6_address_from_vmac( - BACNET_IP6_ADDRESS *addr, - struct vmac_data *vmac) +static bool bbmd6_address_from_vmac(BACNET_IP6_ADDRESS *addr, + struct vmac_data *vmac) { bool status = false; unsigned int i = 0; @@ -130,9 +129,8 @@ static bool bbmd6_address_from_vmac( * * @return true if the address was set */ -static bool bbmd6_address_to_vmac( - struct vmac_data *vmac, - BACNET_IP6_ADDRESS *addr) +static bool bbmd6_address_to_vmac(struct vmac_data *vmac, + BACNET_IP6_ADDRESS *addr) { bool status = false; unsigned int i = 0; @@ -157,9 +155,7 @@ static bool bbmd6_address_to_vmac( * * @return true if the VMAC address was added */ -static bool bbmd6_add_vmac( - uint32_t device_id, - BACNET_IP6_ADDRESS *addr) +static bool bbmd6_add_vmac(uint32_t device_id, BACNET_IP6_ADDRESS *addr) { bool status = false; struct vmac_data *vmac; @@ -186,8 +182,7 @@ static bool bbmd6_add_vmac( * * @return true if the IPv6 from sin match me */ -static bool bbmd6_address_match_self( - BACNET_IP6_ADDRESS *addr) +static bool bbmd6_address_match_self(BACNET_IP6_ADDRESS *addr) { BACNET_IP6_ADDRESS my_addr = {{0}}; bool status = false; @@ -211,10 +206,9 @@ static bool bbmd6_address_match_self( * * @return true if the address was in the VMAC table */ -static bool bbmd6_address_from_bacnet_address( - BACNET_IP6_ADDRESS * addr, - uint32_t * vmac_src, - BACNET_ADDRESS * baddr) +static bool bbmd6_address_from_bacnet_address(BACNET_IP6_ADDRESS *addr, + uint32_t *vmac_src, + BACNET_ADDRESS *baddr) { struct vmac_data *vmac; bool status = false; @@ -226,8 +220,7 @@ static bool bbmd6_address_from_bacnet_address( vmac = VMAC_Find_By_Key(device_id); if (vmac) { debug_printf("BVLC6: Found VMAC %lu (len=%u).\n", - (unsigned long)device_id, - (unsigned)vmac->mac_len); + (unsigned long)device_id, (unsigned)vmac->mac_len); status = bbmd6_address_from_vmac(addr, vmac); if (vmac_src) { *vmac_src = device_id; @@ -239,8 +232,6 @@ static bool bbmd6_address_from_bacnet_address( return status; } - - /** * The common send function for BACnet/IPv6 application layer * @@ -253,20 +244,17 @@ static bool bbmd6_address_from_bacnet_address( * @return Upon successful completion, returns the number of bytes sent. * Otherwise, -1 shall be returned and errno set to indicate the error. */ -int bip6_send_pdu( - BACNET_ADDRESS * dest, - BACNET_NPDU_DATA * npdu_data, - uint8_t * pdu, - unsigned pdu_len) +int bip6_send_pdu(BACNET_ADDRESS *dest, BACNET_NPDU_DATA *npdu_data, + uint8_t *pdu, unsigned pdu_len) { BACNET_IP6_ADDRESS bvlc_dest = {{0}}; - uint8_t mtu[MAX_MPDU] = { 0 }; + uint8_t mtu[MAX_MPDU] = {0}; uint16_t mtu_len = 0; uint32_t vmac_src = 0; uint32_t vmac_dst = 0; /* this datalink doesn't need to know the npdu data */ - (void) npdu_data; + (void)npdu_data; /* handle various broadcasts: */ if ((dest->net == BACNET_BROADCAST_NETWORK) || (dest->mac_len == 0)) { /* mac_len = 0 is a broadcast address */ @@ -281,8 +269,8 @@ int bip6_send_pdu( } else { bip6_get_broadcast_addr(&bvlc_dest); vmac_src = Device_Object_Instance_Number(); - mtu_len = bvlc6_encode_original_broadcast( - mtu, sizeof(mtu), vmac_src, pdu, pdu_len); + mtu_len = bvlc6_encode_original_broadcast(mtu, sizeof(mtu), + vmac_src, pdu, pdu_len); debug_printf("BVLC6: Sent Original-Broadcast-NPDU.\n"); } } else if ((dest->net > 0) && (dest->len == 0)) { @@ -294,16 +282,16 @@ int bip6_send_pdu( bip6_get_broadcast_addr(&bvlc_dest); } vmac_src = Device_Object_Instance_Number(); - mtu_len = bvlc6_encode_original_broadcast( - mtu, sizeof(mtu), vmac_src, pdu, pdu_len); + mtu_len = bvlc6_encode_original_broadcast(mtu, sizeof(mtu), vmac_src, + pdu, pdu_len); debug_printf("BVLC6: Sent Original-Broadcast-NPDU.\n"); } else if (dest->mac_len == 3) { /* valid unicast */ bbmd6_address_from_bacnet_address(&bvlc_dest, &vmac_dst, dest); debug_printf("BVLC6: Sending to VMAC %lu.\n", (unsigned long)vmac_dst); vmac_src = Device_Object_Instance_Number(); - mtu_len = bvlc6_encode_original_unicast( - mtu, sizeof(mtu), vmac_src, vmac_dst, pdu, pdu_len); + mtu_len = bvlc6_encode_original_unicast(mtu, sizeof(mtu), vmac_src, + vmac_dst, pdu, pdu_len); debug_printf("BVLC6: Sent Original-Unicast-NPDU.\n"); } else { debug_printf("BVLC6: Send failure. Invalid Address.\n"); @@ -323,19 +311,17 @@ int bip6_send_pdu( * @param npdu - the bytes of NPDU+APDU data to send * @param npdu_len - the number of bytes of NPDU+APDU data to send */ -static void bbmd6_send_pdu_bdt( - uint8_t * mtu, - unsigned int mtu_len) +static void bbmd6_send_pdu_bdt(uint8_t *mtu, unsigned int mtu_len) { BACNET_IP6_ADDRESS my_addr = {{0}}; - unsigned i = 0; /* loop counter */ + unsigned i = 0; /* loop counter */ if (mtu) { bip6_get_addr(&my_addr); for (i = 0; i < MAX_BBMD_ENTRIES; i++) { if (BBMD_Table[i].valid) { if (bvlc6_address_different(&my_addr, - &BBMD_Table[i].bip6_address)) { + &BBMD_Table[i].bip6_address)) { bip6_send_mpdu(&BBMD_Table[i].bip6_address, mtu, mtu_len); } } @@ -352,19 +338,17 @@ static void bbmd6_send_pdu_bdt( * @param npdu - the bytes of NPDU+APDU data to send * @param npdu_len - the number of bytes of NPDU+APDU data to send */ -static void bbmd6_send_pdu_fdt( - uint8_t * mtu, - unsigned int mtu_len) +static void bbmd6_send_pdu_fdt(uint8_t *mtu, unsigned int mtu_len) { BACNET_IP6_ADDRESS my_addr = {{0}}; - unsigned i = 0; /* loop counter */ + unsigned i = 0; /* loop counter */ if (mtu) { bip6_get_addr(&my_addr); for (i = 0; i < MAX_FD_ENTRIES; i++) { if (FD_Table[i].valid) { if (bvlc6_address_different(&my_addr, - &FD_Table[i].bip6_address)) { + &FD_Table[i].bip6_address)) { bip6_send_mpdu(&FD_Table[i].bip6_address, mtu, mtu_len); } } @@ -381,15 +365,13 @@ static void bbmd6_send_pdu_fdt( * @param npdu - the bytes of NPDU+APDU data to send * @param npdu_len - the number of bytes of NPDU+APDU data to send */ -static void bbmd6_send_forward_npdu( - BACNET_IP6_ADDRESS *address, - uint32_t vmac_src, - uint8_t * npdu, - unsigned int npdu_len) +static void bbmd6_send_forward_npdu(BACNET_IP6_ADDRESS *address, + uint32_t vmac_src, uint8_t *npdu, + unsigned int npdu_len) { - uint8_t mtu[MAX_MPDU] = { 0 }; + uint8_t mtu[MAX_MPDU] = {0}; uint16_t mtu_len = 0; - unsigned i = 0; /* loop counter */ + unsigned i = 0; /* loop counter */ for (i = 0; i < MAX_BBMD_ENTRIES; i++) { if (BBMD_Table[i].valid) { @@ -424,12 +406,10 @@ static void bbmd6_send_forward_npdu( * @return Upon successful completion, returns the number of bytes sent. * Otherwise, -1 shall be returned and errno set to indicate the error. */ -static int bvlc6_send_result( - BACNET_IP6_ADDRESS *dest_addr, - uint32_t vmac_src, - uint16_t result_code) +static int bvlc6_send_result(BACNET_IP6_ADDRESS *dest_addr, uint32_t vmac_src, + uint16_t result_code) { - uint8_t mtu[MAX_MPDU] = { 0 }; + uint8_t mtu[MAX_MPDU] = {0}; uint16_t mtu_len = 0; mtu_len = bvlc6_encode_result(&mtu[0], sizeof(mtu), vmac_src, result_code); @@ -448,17 +428,15 @@ static int bvlc6_send_result( * @return Upon successful completion, returns the number of bytes sent. * Otherwise, -1 shall be returned and errno set to indicate the error. */ -static int bvlc6_send_address_resolution_ack( - BACNET_IP6_ADDRESS *dest_addr, - uint32_t vmac_src, - uint32_t vmac_dst) +static int bvlc6_send_address_resolution_ack(BACNET_IP6_ADDRESS *dest_addr, + uint32_t vmac_src, + uint32_t vmac_dst) { - uint8_t mtu[MAX_MPDU] = { 0 }; + uint8_t mtu[MAX_MPDU] = {0}; uint16_t mtu_len = 0; - mtu_len = bvlc6_encode_address_resolution_ack( - &mtu[0], sizeof(mtu), - vmac_src, vmac_dst); + mtu_len = bvlc6_encode_address_resolution_ack(&mtu[0], sizeof(mtu), + vmac_src, vmac_dst); return bip6_send_mpdu(dest_addr, mtu, mtu_len); } @@ -476,16 +454,13 @@ static int bvlc6_send_address_resolution_ack( * Otherwise, -1 shall be returned and errno set to indicate the error. */ static int bvlc6_send_virtual_address_resolution_ack( - BACNET_IP6_ADDRESS *dest_addr, - uint32_t vmac_src, - uint32_t vmac_dst) + BACNET_IP6_ADDRESS *dest_addr, uint32_t vmac_src, uint32_t vmac_dst) { - uint8_t mtu[MAX_MPDU] = { 0 }; + uint8_t mtu[MAX_MPDU] = {0}; uint16_t mtu_len = 0; - mtu_len = bvlc6_encode_virtual_address_resolution_ack( - &mtu[0], sizeof(mtu), - vmac_src, vmac_dst); + mtu_len = bvlc6_encode_virtual_address_resolution_ack(&mtu[0], sizeof(mtu), + vmac_src, vmac_dst); return bip6_send_mpdu(dest_addr, mtu, mtu_len); } @@ -497,10 +472,9 @@ static int bvlc6_send_virtual_address_resolution_ack( * @param pdu - The received NPDU+APDU buffer. * @param pdu_len - How many bytes in NPDU+APDU buffer. */ -static void bbmd6_virtual_address_resolution_handler( - BACNET_IP6_ADDRESS *addr, - uint8_t * pdu, - uint16_t pdu_len) +static void bbmd6_virtual_address_resolution_handler(BACNET_IP6_ADDRESS *addr, + uint8_t *pdu, + uint16_t pdu_len) { int function_len = 0; uint32_t vmac_src = 0; @@ -511,17 +485,16 @@ static void bbmd6_virtual_address_resolution_handler( if (bbmd6_address_match_self(addr)) { /* ignore messages from my IPv6 address */ } else { - function_len = bvlc6_decode_virtual_address_resolution( - pdu, pdu_len, - &vmac_src); + function_len = bvlc6_decode_virtual_address_resolution(pdu, pdu_len, + &vmac_src); if (function_len) { bbmd6_add_vmac(vmac_src, addr); /* The Address-Resolution-ACK message is unicast to the B/IPv6 node that originally initiated the Address-Resolution message. */ vmac_me = Device_Object_Instance_Number(); - bvlc6_send_virtual_address_resolution_ack( - addr, vmac_me, vmac_src); + bvlc6_send_virtual_address_resolution_ack(addr, vmac_me, + vmac_src); } } } @@ -535,9 +508,7 @@ static void bbmd6_virtual_address_resolution_handler( * @param pdu_len - How many bytes in NPDU+APDU buffer. */ static void bbmd6_virtual_address_resolution_ack_handler( - BACNET_IP6_ADDRESS *addr, - uint8_t * pdu, - uint16_t pdu_len) + BACNET_IP6_ADDRESS *addr, uint8_t *pdu, uint16_t pdu_len) { int function_len = 0; uint32_t vmac_src = 0; @@ -549,8 +520,7 @@ static void bbmd6_virtual_address_resolution_ack_handler( /* ignore messages from my IPv6 address */ } else { function_len = bvlc6_decode_virtual_address_resolution_ack( - pdu, pdu_len, - &vmac_src, &vmac_dst); + pdu, pdu_len, &vmac_src, &vmac_dst); if (function_len) { bbmd6_add_vmac(vmac_src, addr); } @@ -565,10 +535,8 @@ static void bbmd6_virtual_address_resolution_ack_handler( * @param pdu - The received NPDU+APDU buffer. * @param pdu_len - How many bytes in NPDU+APDU buffer. */ -static void bbmd6_address_resolution_handler( - BACNET_IP6_ADDRESS *addr, - uint8_t * pdu, - uint16_t pdu_len) +static void bbmd6_address_resolution_handler(BACNET_IP6_ADDRESS *addr, + uint8_t *pdu, uint16_t pdu_len) { int function_len = 0; uint32_t vmac_src = 0; @@ -581,8 +549,7 @@ static void bbmd6_address_resolution_handler( /* ignore messages from my IPv6 address */ } else { function_len = bvlc6_decode_address_resolution( - pdu, pdu_len, - &vmac_src, &vmac_target); + pdu, pdu_len, &vmac_src, &vmac_target); if (function_len) { bbmd6_add_vmac(vmac_src, addr); vmac_me = Device_Object_Instance_Number(); @@ -590,8 +557,7 @@ static void bbmd6_address_resolution_handler( /* The Address-Resolution-ACK message is unicast to the B/IPv6 node that originally initiated the Address-Resolution message. */ - bvlc6_send_address_resolution_ack( - addr, vmac_me, vmac_src); + bvlc6_send_address_resolution_ack(addr, vmac_me, vmac_src); } } } @@ -605,10 +571,8 @@ static void bbmd6_address_resolution_handler( * @param pdu - The received NPDU+APDU buffer. * @param pdu_len - How many bytes in NPDU+APDU buffer. */ -static void bbmd6_address_resolution_ack_handler( - BACNET_IP6_ADDRESS *addr, - uint8_t * pdu, - uint16_t pdu_len) +static void bbmd6_address_resolution_ack_handler(BACNET_IP6_ADDRESS *addr, + uint8_t *pdu, uint16_t pdu_len) { int function_len = 0; uint32_t vmac_src = 0; @@ -620,8 +584,7 @@ static void bbmd6_address_resolution_ack_handler( /* ignore messages from my IPv6 address */ } else { function_len = bvlc6_decode_address_resolution_ack( - pdu, pdu_len, - &vmac_src, &vmac_dst); + pdu, pdu_len, &vmac_src, &vmac_dst); if (function_len) { bbmd6_add_vmac(vmac_src, addr); } @@ -640,11 +603,9 @@ static void bbmd6_address_resolution_ack_handler( * * @return number of bytes offset into the NPDU for APDU, or 0 if handled */ -static int handler_bbmd6_for_non_bbmd( - BACNET_IP6_ADDRESS *addr, - BACNET_ADDRESS * src, - uint8_t * mtu, - uint16_t mtu_len) +static int handler_bbmd6_for_non_bbmd(BACNET_IP6_ADDRESS *addr, + BACNET_ADDRESS *src, uint8_t *mtu, + uint16_t mtu_len) { uint16_t result_code = BVLC6_RESULT_SUCCESSFUL_COMPLETION; uint32_t vmac_src = 0; @@ -653,23 +614,23 @@ static int handler_bbmd6_for_non_bbmd( uint16_t message_length = 0; int header_len = 0; int function_len = 0; - uint8_t * pdu = NULL; + uint8_t *pdu = NULL; uint16_t pdu_len = 0; uint16_t npdu_len = 0; bool send_result = false; uint16_t offset = 0; BACNET_IP6_ADDRESS fwd_address = {{0}}; - header_len = bvlc6_decode_header(mtu, mtu_len, &message_type, - &message_length); + header_len = + bvlc6_decode_header(mtu, mtu_len, &message_type, &message_length); if (header_len == 4) { BVLC6_Function_Code = message_type; pdu = &mtu[header_len]; pdu_len = mtu_len - header_len; switch (BVLC6_Function_Code) { case BVLC6_RESULT: - function_len = bvlc6_decode_result(pdu, pdu_len, &vmac_src, - &result_code); + function_len = + bvlc6_decode_result(pdu, pdu_len, &vmac_src, &result_code); if (function_len) { BVLC6_Result_Code = result_code; /* The Virtual MAC address table shall be updated @@ -678,7 +639,7 @@ static int handler_bbmd6_for_non_bbmd( bbmd6_add_vmac(vmac_src, addr); bvlc6_vmac_address_set(src, vmac_src); debug_printf("BIP6: Received Result Code=%d\n", - BVLC6_Result_Code); + BVLC6_Result_Code); } break; case BVLC6_REGISTER_FOREIGN_DEVICE: @@ -702,9 +663,7 @@ static int handler_bbmd6_for_non_bbmd( debug_printf("BIP6: Original-Unicast-NPDU is me!.\n"); } else { function_len = bvlc6_decode_original_unicast( - pdu, pdu_len, - &vmac_src, &vmac_dst, - NULL, 0, &npdu_len); + pdu, pdu_len, &vmac_src, &vmac_dst, NULL, 0, &npdu_len); if (function_len) { if (vmac_dst == Device_Object_Instance_Number()) { /* The Virtual MAC address table shall be updated @@ -731,9 +690,7 @@ static int handler_bbmd6_for_non_bbmd( debug_printf("BIP6: Original-Broadcast-NPDU is me!\n"); } else { function_len = bvlc6_decode_original_broadcast( - pdu, pdu_len, - &vmac_src, - NULL, 0, &npdu_len); + pdu, pdu_len, &vmac_src, NULL, 0, &npdu_len); if (function_len) { /* The Virtual MAC address table shall be updated using the respective parameter values of the @@ -743,7 +700,8 @@ static int handler_bbmd6_for_non_bbmd( offset = header_len + (function_len - npdu_len); } else { debug_printf( - "BIP6: Original-Broadcast-NPDU: Unable to decode!\n"); + "BIP6: Original-Broadcast-NPDU: Unable to " + "decode!\n"); } } break; @@ -754,9 +712,8 @@ static int handler_bbmd6_for_non_bbmd( debug_printf("BIP6: Forwarded-NPDU is me!\n"); } else { function_len = bvlc6_decode_forwarded_npdu( - pdu, pdu_len, - &vmac_src, &fwd_address, - NULL, 0, &npdu_len); + pdu, pdu_len, &vmac_src, &fwd_address, NULL, 0, + &npdu_len); if (function_len) { /* The Virtual MAC address table shall be updated using the respective parameter values of the @@ -784,7 +741,8 @@ static int handler_bbmd6_for_non_bbmd( bbmd6_virtual_address_resolution_handler(addr, pdu, pdu_len); break; case BVLC6_VIRTUAL_ADDRESS_RESOLUTION_ACK: - bbmd6_virtual_address_resolution_ack_handler(addr, pdu, pdu_len); + bbmd6_virtual_address_resolution_ack_handler(addr, pdu, + pdu_len); break; case BVLC6_SECURE_BVLL: break; @@ -814,11 +772,8 @@ static int handler_bbmd6_for_non_bbmd( * * @return number of bytes offset into the NPDU for APDU, or 0 if handled */ -static int handler_bbmd6_for_bbmd( - BACNET_IP6_ADDRESS *addr, - BACNET_ADDRESS * src, - uint8_t * mtu, - uint16_t mtu_len) +static int handler_bbmd6_for_bbmd(BACNET_IP6_ADDRESS *addr, BACNET_ADDRESS *src, + uint8_t *mtu, uint16_t mtu_len) { uint16_t result_code = BVLC6_RESULT_SUCCESSFUL_COMPLETION; uint32_t vmac_me = 0; @@ -829,24 +784,24 @@ static int handler_bbmd6_for_bbmd( uint16_t message_length = 0; int header_len = 0; int function_len = 0; - uint8_t * pdu = NULL; + uint8_t *pdu = NULL; uint16_t pdu_len = 0; - uint8_t * npdu = NULL; + uint8_t *npdu = NULL; uint16_t npdu_len = 0; bool send_result = false; uint16_t offset = 0; BACNET_IP6_ADDRESS fwd_address = {{0}}; - header_len = bvlc6_decode_header(mtu, mtu_len, &message_type, - &message_length); + header_len = + bvlc6_decode_header(mtu, mtu_len, &message_type, &message_length); if (header_len == 4) { BVLC6_Function_Code = message_type; pdu = &mtu[header_len]; pdu_len = mtu_len - header_len; switch (BVLC6_Function_Code) { case BVLC6_RESULT: - function_len = bvlc6_decode_result(pdu, pdu_len, &vmac_src, - &result_code); + function_len = + bvlc6_decode_result(pdu, pdu_len, &vmac_src, &result_code); if (function_len) { BVLC6_Result_Code = result_code; /* The Virtual MAC address table shall be updated @@ -855,7 +810,7 @@ static int handler_bbmd6_for_bbmd( bbmd6_add_vmac(vmac_src, addr); bvlc6_vmac_address_set(src, vmac_src); debug_printf("BIP6: Received Result Code=%d\n", - BVLC6_Result_Code); + BVLC6_Result_Code); } break; case BVLC6_REGISTER_FOREIGN_DEVICE: @@ -880,9 +835,7 @@ static int handler_bbmd6_for_bbmd( offset = 0; } else { function_len = bvlc6_decode_original_unicast( - pdu, pdu_len, - &vmac_src, &vmac_dst, - NULL, 0, &npdu_len); + pdu, pdu_len, &vmac_src, &vmac_dst, NULL, 0, &npdu_len); if (function_len) { if (vmac_dst == Device_Object_Instance_Number()) { /* The Virtual MAC address table shall be updated @@ -898,9 +851,7 @@ static int handler_bbmd6_for_bbmd( case BVLC6_ORIGINAL_BROADCAST_NPDU: debug_printf("BIP6: Received Original-Broadcast-NPDU.\n"); function_len = bvlc6_decode_original_broadcast( - pdu, pdu_len, - &vmac_src, - NULL, 0, &npdu_len); + pdu, pdu_len, &vmac_src, NULL, 0, &npdu_len); if (function_len) { offset = header_len + (function_len - npdu_len); npdu = &mtu[offset]; @@ -912,8 +863,7 @@ static int handler_bbmd6_for_bbmd( be unicast to each foreign device currently in the BBMD's FDT */ BVLC6_Buffer_Len = bvlc6_encode_forwarded_npdu( - &BVLC6_Buffer[0], sizeof(BVLC6_Buffer), - vmac_src, addr, + &BVLC6_Buffer[0], sizeof(BVLC6_Buffer), vmac_src, addr, npdu, npdu_len); bbmd6_send_pdu_bdt(&BVLC6_Buffer[0], BVLC6_Buffer_Len); bbmd6_send_pdu_fdt(&BVLC6_Buffer[0], BVLC6_Buffer_Len); @@ -929,9 +879,7 @@ static int handler_bbmd6_for_bbmd( case BVLC6_FORWARDED_NPDU: debug_printf("BIP6: Received Forwarded-NPDU.\n"); function_len = bvlc6_decode_forwarded_npdu( - pdu, pdu_len, - &vmac_src, &fwd_address, - NULL, 0, &npdu_len); + pdu, pdu_len, &vmac_src, &fwd_address, NULL, 0, &npdu_len); if (function_len) { offset = header_len + (function_len - npdu_len); npdu = &mtu[offset]; @@ -941,11 +889,11 @@ static int handler_bbmd6_for_bbmd( transmit it via multicast to B/IPv6 devices in the local multicast domain. */ BVLC6_Buffer_Len = bvlc6_encode_forwarded_npdu( - &BVLC6_Buffer[0], sizeof(BVLC6_Buffer), - vmac_src, addr, + &BVLC6_Buffer[0], sizeof(BVLC6_Buffer), vmac_src, addr, npdu, npdu_len); bip6_get_broadcast_addr(&bvlc_dest); - bip6_send_mpdu(&bvlc_dest, &BVLC6_Buffer[0], BVLC6_Buffer_Len); + bip6_send_mpdu(&bvlc_dest, &BVLC6_Buffer[0], + BVLC6_Buffer_Len); /* In addition, the constructed BVLL Forwarded-NPDU message shall be unicast to each foreign device in the BBMD's FDT. If the BBMD is unable to transmit @@ -977,7 +925,8 @@ static int handler_bbmd6_for_bbmd( bbmd6_virtual_address_resolution_handler(addr, pdu, pdu_len); break; case BVLC6_VIRTUAL_ADDRESS_RESOLUTION_ACK: - bbmd6_virtual_address_resolution_ack_handler(addr, pdu, pdu_len); + bbmd6_virtual_address_resolution_ack_handler(addr, pdu, + pdu_len); break; case BVLC6_SECURE_BVLL: break; @@ -1005,11 +954,8 @@ static int handler_bbmd6_for_bbmd( * * @return number of bytes offset into the NPDU for APDU, or 0 if handled */ -int bvlc6_handler( - BACNET_IP6_ADDRESS *addr, - BACNET_ADDRESS * src, - uint8_t * npdu, - uint16_t npdu_len) +int bvlc6_handler(BACNET_IP6_ADDRESS *addr, BACNET_ADDRESS *src, uint8_t *npdu, + uint16_t npdu_len) { #if defined(BACDL_BIP6) && BBMD6_ENABLED return handler_bbmd6_for_bbmd(addr, src, npdu, npdu_len); @@ -1027,12 +973,10 @@ int bvlc6_handler( * 0 if no registration request is sent, or * -1 if registration fails. */ -int bvlc6_register_with_bbmd( - BACNET_IP6_ADDRESS *bbmd_addr, - uint32_t vmac_src, - uint16_t time_to_live_seconds) +int bvlc6_register_with_bbmd(BACNET_IP6_ADDRESS *bbmd_addr, uint32_t vmac_src, + uint16_t time_to_live_seconds) { - uint8_t mtu[MAX_MPDU] = { 0 }; + uint8_t mtu[MAX_MPDU] = {0}; uint16_t mtu_len = 0; mtu_len = bvlc6_encode_register_foreign_device( @@ -1049,8 +993,7 @@ int bvlc6_register_with_bbmd( * BVLC6_RESULT_REGISTER_FOREIGN_DEVICE_NAK if registration failed, * or one of the other codes (if we are a BBMD). */ -uint16_t bvlc6_get_last_result( - void) +uint16_t bvlc6_get_last_result(void) { return BVLC6_Result_Code; } @@ -1062,8 +1005,7 @@ uint16_t bvlc6_get_last_result( * * @return A BVLC6_ code, such as BVLC6_ORIGINAL_UNICAST_NPDU. */ -uint8_t bvlc6_get_function_code( - void) +uint8_t bvlc6_get_function_code(void) { return BVLC6_Function_Code; } @@ -1095,11 +1037,8 @@ static uint8_t BIP6_MTU_Buffer[MAX_MPDU]; * * @return Number of bytes received, or 0 if none or timeout. */ -uint16_t bip6_receive( - BACNET_ADDRESS * src, - uint8_t * npdu, - uint16_t max_npdu, - unsigned timeout) +uint16_t bip6_receive(BACNET_ADDRESS *src, uint8_t *npdu, uint16_t max_npdu, + unsigned timeout) { return 0; } @@ -1115,10 +1054,7 @@ uint16_t bip6_receive( * @return Upon successful completion, returns the number of bytes sent. * Otherwise, -1 shall be returned and errno set to indicate the error. */ -int bip6_send_mpdu( - BACNET_IP6_ADDRESS *dest, - uint8_t * mtu, - uint16_t mtu_len) +int bip6_send_mpdu(BACNET_IP6_ADDRESS *dest, uint8_t *mtu, uint16_t mtu_len) { return 0; } @@ -1129,8 +1065,7 @@ int bip6_send_mpdu( * * @return The Instance number used in the BACNET_OBJECT_ID for the Device. */ -uint32_t Device_Object_Instance_Number( - void) +uint32_t Device_Object_Instance_Number(void) { return Device_ID; } @@ -1140,8 +1075,7 @@ uint32_t Device_Object_Instance_Number( * * @return BACnet/IP address */ -bool bip6_get_addr( - BACNET_IP6_ADDRESS *addr) +bool bip6_get_addr(BACNET_IP6_ADDRESS *addr) { return bvlc6_address_copy(addr, &BIP6_Addr); } @@ -1151,14 +1085,12 @@ bool bip6_get_addr( * * @return BACnet/IP address */ -bool bip6_get_broadcast_addr( - BACNET_IP6_ADDRESS *addr) +bool bip6_get_broadcast_addr(BACNET_IP6_ADDRESS *addr) { return bvlc6_address_copy(addr, &BIP6_Broadcast_Addr); } -static void test_BBMD_Result( - Test * pTest) +static void test_BBMD_Result(Test *pTest) { int result = 0; uint32_t vmac_src = 0x1234; @@ -1168,24 +1100,22 @@ static void test_BBMD_Result( BVLC6_RESULT_VIRTUAL_ADDRESS_RESOLUTION_NAK, BVLC6_RESULT_REGISTER_FOREIGN_DEVICE_NAK, BVLC6_RESULT_DELETE_FOREIGN_DEVICE_NAK, - BVLC6_RESULT_DISTRIBUTE_BROADCAST_TO_NETWORK_NAK - }; + BVLC6_RESULT_DISTRIBUTE_BROADCAST_TO_NETWORK_NAK}; uint16_t test_result_code = 0; uint8_t test_function_code = 0; BACNET_IP6_ADDRESS addr; BACNET_ADDRESS src; unsigned int i = 0; - uint8_t mtu[MAX_MPDU] = { 0 }; + uint8_t mtu[MAX_MPDU] = {0}; uint16_t mtu_len = 0; - bvlc6_address_set(&addr, - BIP6_MULTICAST_LINK_LOCAL, 0, 0, 0, 0, 0, 0, - BIP6_MULTICAST_GROUP_ID); + bvlc6_address_set(&addr, BIP6_MULTICAST_LINK_LOCAL, 0, 0, 0, 0, 0, 0, + BIP6_MULTICAST_GROUP_ID); addr.port = 0xBAC0; bvlc6_vmac_address_set(&src, vmac_src); for (i = 0; i < 6; i++) { - mtu_len = bvlc6_encode_result(&mtu[0], sizeof(mtu), - vmac_src, result_code[i]); + mtu_len = + bvlc6_encode_result(&mtu[0], sizeof(mtu), vmac_src, result_code[i]); result = handler_bbmd6_for_non_bbmd(&addr, &src, &mtu[0], mtu_len); /* validate that the result is handled (0) */ ct_test(pTest, result == 0); @@ -1196,8 +1126,7 @@ static void test_BBMD_Result( } } -static void test_BBMD6( - Test * pTest) +static void test_BBMD6(Test *pTest) { bool rc; @@ -1207,8 +1136,7 @@ static void test_BBMD6( } #ifdef TEST_BBMD6 -int main( - void) +int main(void) { Test *pTest; @@ -1217,12 +1145,10 @@ int main( /* configure output */ ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; } #endif #endif - - diff --git a/demo/handler/h_ccov.c b/demo/handler/h_ccov.c index d7ca09f4..14a6c133 100644 --- a/demo/handler/h_ccov.c +++ b/demo/handler/h_ccov.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2011 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2011 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -59,11 +59,9 @@ * @param service_data [in] The BACNET_CONFIRMED_SERVICE_DATA information * decoded from the APDU header of this message. */ -void handler_ccov_notification( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src, - BACNET_CONFIRMED_SERVICE_DATA * service_data) +void handler_ccov_notification(uint8_t *service_request, uint16_t service_len, + BACNET_ADDRESS *src, + BACNET_CONFIRMED_SERVICE_DATA *service_data) { BACNET_NPDU_DATA npdu_data; BACNET_COV_DATA cov_data; @@ -81,31 +79,29 @@ void handler_ccov_notification( /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); - pdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address, - &npdu_data); + pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address, + &npdu_data); #if PRINT_ENABLED fprintf(stderr, "CCOV: Received Notification!\n"); #endif if (service_data->segmented_message) { - len = - abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, - true); + len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], + service_data->invoke_id, + ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); #if PRINT_ENABLED fprintf(stderr, "CCOV: Segmented message. Sending Abort!\n"); #endif goto CCOV_ABORT; } /* decode the service request only */ - len = - cov_notify_decode_service_request(service_request, service_len, - &cov_data); + len = cov_notify_decode_service_request(service_request, service_len, + &cov_data); #if PRINT_ENABLED if (len > 0) { fprintf(stderr, "CCOV: PID=%u ", cov_data.subscriberProcessIdentifier); fprintf(stderr, "instance=%u ", cov_data.initiatingDeviceIdentifier); - fprintf(stderr, "%s %u ", + fprintf( + stderr, "%s %u ", bactext_object_type_name(cov_data.monitoredObjectIdentifier.type), cov_data.monitoredObjectIdentifier.instance); fprintf(stderr, "time remaining=%u seconds ", cov_data.timeRemaining); @@ -114,12 +110,12 @@ void handler_ccov_notification( while (pProperty_value) { fprintf(stderr, "CCOV: "); if (pProperty_value->propertyIdentifier < 512) { - fprintf(stderr, "%s ", - bactext_property_name - (pProperty_value->propertyIdentifier)); + fprintf( + stderr, "%s ", + bactext_property_name(pProperty_value->propertyIdentifier)); } else { fprintf(stderr, "proprietary %u ", - pProperty_value->propertyIdentifier); + pProperty_value->propertyIdentifier); } if (pProperty_value->propertyArrayIndex != BACNET_ARRAY_ALL) { fprintf(stderr, "%u ", pProperty_value->propertyArrayIndex); @@ -131,26 +127,25 @@ void handler_ccov_notification( #endif /* bad decoding or something we didn't understand - send an abort */ if (len <= 0) { - len = - abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, ABORT_REASON_OTHER, true); + len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], + service_data->invoke_id, ABORT_REASON_OTHER, + true); #if PRINT_ENABLED fprintf(stderr, "CCOV: Bad Encoding. Sending Abort!\n"); #endif goto CCOV_ABORT; } else { - len = - encode_simple_ack(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, SERVICE_CONFIRMED_COV_NOTIFICATION); + len = encode_simple_ack(&Handler_Transmit_Buffer[pdu_len], + service_data->invoke_id, + SERVICE_CONFIRMED_COV_NOTIFICATION); #if PRINT_ENABLED fprintf(stderr, "CCOV: Sending Simple Ack!\n"); #endif } - CCOV_ABORT: +CCOV_ABORT: pdu_len += len; - bytes_sent = - datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], - pdu_len); + bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], + pdu_len); #if PRINT_ENABLED if (bytes_sent <= 0) { fprintf(stderr, "CCOV: Failed to send PDU (%s)!\n", strerror(errno)); diff --git a/demo/handler/h_cov.c b/demo/handler/h_cov.c index 48346a19..76e7b7bd 100644 --- a/demo/handler/h_cov.c +++ b/demo/handler/h_cov.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2007-2008 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2007-2008 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -54,24 +54,24 @@ /** @file h_cov.c Handles Change of Value (COV) services. */ typedef struct BACnet_COV_Address { - bool valid:1; + bool valid : 1; BACNET_ADDRESS dest; } BACNET_COV_ADDRESS; /* note: This COV service only monitors the properties of an object that have been specified in the standard. */ typedef struct BACnet_COV_Subscription_Flags { - bool valid:1; - bool issueConfirmedNotifications:1; /* optional */ - bool send_requested:1; + bool valid : 1; + bool issueConfirmedNotifications : 1; /* optional */ + bool send_requested : 1; } BACNET_COV_SUBSCRIPTION_FLAGS; typedef struct BACnet_COV_Subscription { BACNET_COV_SUBSCRIPTION_FLAGS flag; uint8_t dest_index; - uint8_t invokeID; /* for confirmed COV */ + uint8_t invokeID; /* for confirmed COV */ uint32_t subscriberProcessIdentifier; - uint32_t lifetime; /* optional */ + uint32_t lifetime; /* optional */ BACNET_OBJECT_ID monitoredObjectIdentifier; } BACNET_COV_SUBSCRIPTION; @@ -85,15 +85,14 @@ static BACNET_COV_SUBSCRIPTION COV_Subscriptions[MAX_COV_SUBCRIPTIONS]; static BACNET_COV_ADDRESS COV_Addresses[MAX_COV_ADDRESSES]; /** -* Gets the address from the list of COV addresses -* -* @param index - offset into COV address list where address is stored -* @param dest - address to be filled when found -* -* @return true if valid address, false if not valid or not found -*/ -static BACNET_ADDRESS *cov_address_get( - int index) + * Gets the address from the list of COV addresses + * + * @param index - offset into COV address list where address is stored + * @param dest - address to be filled when found + * + * @return true if valid address, false if not valid or not found + */ +static BACNET_ADDRESS *cov_address_get(int index) { BACNET_ADDRESS *cov_dest = NULL; @@ -110,8 +109,7 @@ static BACNET_ADDRESS *cov_address_get( * Removes the address from the list of COV addresses, if it is not * used by other COV subscriptions */ -static void cov_address_remove_unused( - void) +static void cov_address_remove_unused(void) { unsigned index = 0; unsigned cov_index = 0; @@ -135,14 +133,13 @@ static void cov_address_remove_unused( } /** -* Adds the address to the list of COV addresses -* -* @param dest - address to be added if there is room in the list -* -* @return index number 0..N, or -1 if unable to add -*/ -static int cov_address_add( - BACNET_ADDRESS * dest) + * Adds the address to the list of COV addresses + * + * @param dest - address to be added if there is room in the list + * + * @return index number 0..N, or -1 if unable to add + */ +static int cov_address_add(BACNET_ADDRESS *dest) { int index = -1; unsigned i = 0; @@ -207,17 +204,14 @@ TimeRemaining [3] Unsigned, COVIncrement [4] REAL OPTIONAL */ -static int cov_encode_subscription( - uint8_t * apdu, - int max_apdu, - BACNET_COV_SUBSCRIPTION * cov_subscription) +static int cov_encode_subscription(uint8_t *apdu, int max_apdu, + BACNET_COV_SUBSCRIPTION *cov_subscription) { int len = 0; int apdu_len = 0; BACNET_OCTET_STRING octet_string; BACNET_ADDRESS *dest = NULL; - /* FIXME: unused parameter */ max_apdu = max_apdu; if (!cov_subscription) { @@ -256,9 +250,8 @@ static int cov_encode_subscription( len = encode_closing_tag(&apdu[apdu_len], 0); apdu_len += len; /* processIdentifier [1] Unsigned32 */ - len = - encode_context_unsigned(&apdu[apdu_len], 1, - cov_subscription->subscriberProcessIdentifier); + len = encode_context_unsigned( + &apdu[apdu_len], 1, cov_subscription->subscriberProcessIdentifier); apdu_len += len; /* Recipient [0] BACnetRecipientProcess - closing */ len = encode_closing_tag(&apdu[apdu_len], 0); @@ -267,9 +260,8 @@ static int cov_encode_subscription( len = encode_opening_tag(&apdu[apdu_len], 1); apdu_len += len; /* objectIdentifier [0] */ - len = - encode_context_object_id(&apdu[apdu_len], 0, - cov_subscription->monitoredObjectIdentifier.type, + len = encode_context_object_id( + &apdu[apdu_len], 0, cov_subscription->monitoredObjectIdentifier.type, cov_subscription->monitoredObjectIdentifier.instance); apdu_len += len; /* propertyIdentifier [1] */ @@ -280,14 +272,12 @@ static int cov_encode_subscription( len = encode_closing_tag(&apdu[apdu_len], 1); apdu_len += len; /* IssueConfirmedNotifications [2] BOOLEAN, */ - len = - encode_context_boolean(&apdu[apdu_len], 2, - cov_subscription->flag.issueConfirmedNotifications); + len = encode_context_boolean( + &apdu[apdu_len], 2, cov_subscription->flag.issueConfirmedNotifications); apdu_len += len; /* TimeRemaining [3] Unsigned, */ len = - encode_context_unsigned(&apdu[apdu_len], 3, - cov_subscription->lifetime); + encode_context_unsigned(&apdu[apdu_len], 3, cov_subscription->lifetime); apdu_len += len; return apdu_len; @@ -295,18 +285,16 @@ static int cov_encode_subscription( /** Handle a request to list all the COV subscriptions. * @ingroup DSCOV - * Invoked by a request to read the Device object's PROP_ACTIVE_COV_SUBSCRIPTIONS. - * Loops through the list of COV Subscriptions, and, for each valid one, - * adds its description to the APDU. + * Invoked by a request to read the Device object's + * PROP_ACTIVE_COV_SUBSCRIPTIONS. Loops through the list of COV Subscriptions, + * and, for each valid one, adds its description to the APDU. * @note This function needs some work to better handle buffer overruns. * @param apdu [out] Buffer in which the APDU contents are built. * @param max_apdu [in] Max length of the APDU buffer. * @return How many bytes were encoded in the buffer, or -2 if the response * would not fit within the buffer. */ -int handler_cov_encode_subscriptions( - uint8_t * apdu, - int max_apdu) +int handler_cov_encode_subscriptions(uint8_t *apdu, int max_apdu) { int len = 0; int apdu_len = 0; @@ -315,9 +303,9 @@ int handler_cov_encode_subscriptions( if (apdu) { for (index = 0; index < MAX_COV_SUBCRIPTIONS; index++) { if (COV_Subscriptions[index].flag.valid) { - len = - cov_encode_subscription(&apdu[apdu_len], - max_apdu - apdu_len, &COV_Subscriptions[index]); + len = cov_encode_subscription(&apdu[apdu_len], + max_apdu - apdu_len, + &COV_Subscriptions[index]); apdu_len += len; /* TODO: too late here to notice that we overran the buffer */ if (apdu_len > max_apdu) { @@ -333,8 +321,7 @@ int handler_cov_encode_subscriptions( /** Handler to initialize the COV list, clearing and disabling each entry. * @ingroup DSCOV */ -void handler_cov_init( - void) +void handler_cov_init(void) { unsigned index = 0; @@ -355,11 +342,10 @@ void handler_cov_init( } } -static bool cov_list_subscribe( - BACNET_ADDRESS * src, - BACNET_SUBSCRIBE_COV_DATA * cov_data, - BACNET_ERROR_CLASS * error_class, - BACNET_ERROR_CODE * error_code) +static bool cov_list_subscribe(BACNET_ADDRESS *src, + BACNET_SUBSCRIBE_COV_DATA *cov_data, + BACNET_ERROR_CLASS *error_class, + BACNET_ERROR_CODE *error_code) { bool existing_entry = false; int index; @@ -382,11 +368,12 @@ static bool cov_list_subscribe( address_match = true; } if ((COV_Subscriptions[index].monitoredObjectIdentifier.type == - cov_data->monitoredObjectIdentifier.type) && + cov_data->monitoredObjectIdentifier.type) && (COV_Subscriptions[index].monitoredObjectIdentifier.instance == - cov_data->monitoredObjectIdentifier.instance) && + cov_data->monitoredObjectIdentifier.instance) && (COV_Subscriptions[index].subscriberProcessIdentifier == - cov_data->subscriberProcessIdentifier) && address_match) { + cov_data->subscriberProcessIdentifier) && + address_match) { existing_entry = true; if (cov_data->cancellationRequest) { COV_Subscriptions[index].flag.valid = false; @@ -447,9 +434,8 @@ static bool cov_list_subscribe( return found; } -static bool cov_send_request( - BACNET_COV_SUBSCRIPTION * cov_subscription, - BACNET_PROPERTY_VALUE * value_list) +static bool cov_send_request(BACNET_COV_SUBSCRIPTION *cov_subscription, + BACNET_PROPERTY_VALUE *value_list) { int len = 0; int pdu_len = 0; @@ -457,7 +443,7 @@ static bool cov_send_request( BACNET_ADDRESS my_address; int bytes_sent = 0; uint8_t invoke_id = 0; - bool status = false; /* return value */ + bool status = false; /* return value */ BACNET_COV_DATA cov_data; BACNET_ADDRESS *dest = NULL; @@ -479,9 +465,8 @@ static bool cov_send_request( } datalink_get_my_address(&my_address); npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); - pdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], dest, &my_address, - &npdu_data); + pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], dest, &my_address, + &npdu_data); /* load the COV data structure for outgoing message */ cov_data.subscriberProcessIdentifier = cov_subscription->subscriberProcessIdentifier; @@ -497,25 +482,26 @@ static bool cov_send_request( invoke_id = tsm_next_free_invokeID(); if (invoke_id) { cov_subscription->invokeID = invoke_id; - len = - ccov_notify_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - sizeof(Handler_Transmit_Buffer) - pdu_len, invoke_id, &cov_data); + len = ccov_notify_encode_apdu( + &Handler_Transmit_Buffer[pdu_len], + sizeof(Handler_Transmit_Buffer) - pdu_len, invoke_id, + &cov_data); } else { goto COV_FAILED; } } else { - len = - ucov_notify_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - sizeof(Handler_Transmit_Buffer) - pdu_len, &cov_data); + len = ucov_notify_encode_apdu(&Handler_Transmit_Buffer[pdu_len], + sizeof(Handler_Transmit_Buffer) - pdu_len, + &cov_data); } pdu_len += len; if (cov_subscription->flag.issueConfirmedNotifications) { tsm_set_confirmed_unsegmented_transaction(invoke_id, dest, &npdu_data, - &Handler_Transmit_Buffer[0], (uint16_t) pdu_len); + &Handler_Transmit_Buffer[0], + (uint16_t)pdu_len); } - bytes_sent = - datalink_send_pdu(dest, &npdu_data, &Handler_Transmit_Buffer[0], - pdu_len); + bytes_sent = datalink_send_pdu(dest, &npdu_data, + &Handler_Transmit_Buffer[0], pdu_len); if (bytes_sent > 0) { status = true; #if PRINT_ENABLED @@ -523,15 +509,14 @@ static bool cov_send_request( #endif } - COV_FAILED: +COV_FAILED: return status; } -static void cov_lifetime_expiration_handler( - unsigned index, - uint32_t elapsed_seconds, - uint32_t lifetime_seconds) +static void cov_lifetime_expiration_handler(unsigned index, + uint32_t elapsed_seconds, + uint32_t lifetime_seconds) { if (index < MAX_COV_SUBCRIPTIONS) { /* handle lifetime expiration */ @@ -548,13 +533,14 @@ static void cov_lifetime_expiration_handler( /* expire the subscription */ #if PRINT_ENABLED fprintf(stderr, "COVtimer: PID=%u ", - COV_Subscriptions[index].subscriberProcessIdentifier); - fprintf(stderr, "%s %u ", - bactext_object_type_name(COV_Subscriptions[index]. - monitoredObjectIdentifier.type), + COV_Subscriptions[index].subscriberProcessIdentifier); + fprintf( + stderr, "%s %u ", + bactext_object_type_name( + COV_Subscriptions[index].monitoredObjectIdentifier.type), COV_Subscriptions[index].monitoredObjectIdentifier.instance); fprintf(stderr, "time remaining=%u seconds ", - COV_Subscriptions[index].lifetime); + COV_Subscriptions[index].lifetime); fprintf(stderr, "\n"); #endif COV_Subscriptions[index].flag.valid = false; @@ -591,8 +577,7 @@ static void cov_lifetime_expiration_handler( * * @param elapsed_seconds [in] How many seconds have elapsed since last called. */ -void handler_cov_timer_seconds( - uint32_t elapsed_seconds) +void handler_cov_timer_seconds(uint32_t elapsed_seconds) { unsigned index = 0; uint32_t lifetime_seconds = 0; @@ -605,15 +590,14 @@ void handler_cov_timer_seconds( if (lifetime_seconds) { /* only expire COV with definite lifetimes */ cov_lifetime_expiration_handler(index, elapsed_seconds, - lifetime_seconds); + lifetime_seconds); } } } } } -bool handler_cov_fsm( - void) +bool handler_cov_fsm(void) { static int index = 0; BACNET_OBJECT_TYPE object_type = MAX_BACNET_OBJECT_TYPE; @@ -638,11 +622,10 @@ bool handler_cov_fsm( case COV_STATE_MARK: /* mark any subscriptions where the value has changed */ if (COV_Subscriptions[index].flag.valid) { - object_type = (BACNET_OBJECT_TYPE) - COV_Subscriptions[index].monitoredObjectIdentifier.type; + object_type = (BACNET_OBJECT_TYPE)COV_Subscriptions[index] + .monitoredObjectIdentifier.type; object_instance = - COV_Subscriptions[index]. - monitoredObjectIdentifier.instance; + COV_Subscriptions[index].monitoredObjectIdentifier.instance; status = Device_COV(object_type, object_instance); if (status) { COV_Subscriptions[index].flag.send_requested = true; @@ -661,11 +644,10 @@ bool handler_cov_fsm( /* clear the COV flag after checking all subscriptions */ if ((COV_Subscriptions[index].flag.valid) && (COV_Subscriptions[index].flag.send_requested)) { - object_type = (BACNET_OBJECT_TYPE) - COV_Subscriptions[index].monitoredObjectIdentifier.type; + object_type = (BACNET_OBJECT_TYPE)COV_Subscriptions[index] + .monitoredObjectIdentifier.type; object_instance = - COV_Subscriptions[index]. - monitoredObjectIdentifier.instance; + COV_Subscriptions[index].monitoredObjectIdentifier.instance; Device_COV_Clear(object_type, object_instance); } index++; @@ -681,9 +663,8 @@ bool handler_cov_fsm( (COV_Subscriptions[index].invokeID)) { if (tsm_invoke_id_free(COV_Subscriptions[index].invokeID)) { COV_Subscriptions[index].invokeID = 0; - } else - if (tsm_invoke_id_failed(COV_Subscriptions - [index].invokeID)) { + } else if (tsm_invoke_id_failed( + COV_Subscriptions[index].invokeID)) { tsm_free_invoke_id(COV_Subscriptions[index].invokeID); COV_Subscriptions[index].invokeID = 0; } @@ -710,24 +691,21 @@ bool handler_cov_fsm( } } if (send) { - object_type = (BACNET_OBJECT_TYPE) - COV_Subscriptions[index]. - monitoredObjectIdentifier.type; - object_instance = - COV_Subscriptions[index]. - monitoredObjectIdentifier.instance; + object_type = (BACNET_OBJECT_TYPE)COV_Subscriptions[index] + .monitoredObjectIdentifier.type; + object_instance = COV_Subscriptions[index] + .monitoredObjectIdentifier.instance; #if PRINT_ENABLED fprintf(stderr, "COVtask: Sending...\n"); #endif /* configure the linked list for the two properties */ bacapp_property_value_list_init(&value_list[0], - MAX_COV_PROPERTIES); - status = Device_Encode_Value_List(object_type, - object_instance, &value_list[0]); + MAX_COV_PROPERTIES); + status = Device_Encode_Value_List( + object_type, object_instance, &value_list[0]); if (status) { - status = - cov_send_request(&COV_Subscriptions[index], - &value_list[0]); + status = cov_send_request(&COV_Subscriptions[index], + &value_list[0]); } if (status) { COV_Subscriptions[index].flag.send_requested = false; @@ -748,31 +726,27 @@ bool handler_cov_fsm( return (cov_task_state == COV_STATE_IDLE); } -void handler_cov_task( - void) +void handler_cov_task(void) { handler_cov_fsm(); } -static bool cov_subscribe( - BACNET_ADDRESS * src, - BACNET_SUBSCRIBE_COV_DATA * cov_data, - BACNET_ERROR_CLASS * error_class, - BACNET_ERROR_CODE * error_code) +static bool cov_subscribe(BACNET_ADDRESS *src, + BACNET_SUBSCRIBE_COV_DATA *cov_data, + BACNET_ERROR_CLASS *error_class, + BACNET_ERROR_CODE *error_code) { - bool status = false; /* return value */ + bool status = false; /* return value */ BACNET_OBJECT_TYPE object_type = MAX_BACNET_OBJECT_TYPE; uint32_t object_instance = 0; - object_type = - (BACNET_OBJECT_TYPE) cov_data->monitoredObjectIdentifier.type; + object_type = (BACNET_OBJECT_TYPE)cov_data->monitoredObjectIdentifier.type; object_instance = cov_data->monitoredObjectIdentifier.instance; status = Device_Valid_Object_Id(object_type, object_instance); if (status) { status = Device_Value_List_Supported(object_type); if (status) { - status = - cov_list_subscribe(src, cov_data, error_class, error_code); + status = cov_list_subscribe(src, cov_data, error_class, error_code); } else { *error_class = ERROR_CLASS_OBJECT; *error_code = ERROR_CODE_OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED; @@ -802,11 +776,9 @@ static bool cov_subscribe( * @param service_data [in] The BACNET_CONFIRMED_SERVICE_DATA information * decoded from the APDU header of this message. */ -void handler_cov_subscribe( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src, - BACNET_CONFIRMED_SERVICE_DATA * service_data) +void handler_cov_subscribe(uint8_t *service_request, uint16_t service_len, + BACNET_ADDRESS *src, + BACNET_CONFIRMED_SERVICE_DATA *service_data) { BACNET_SUBSCRIBE_COV_DATA cov_data; int len = 0; @@ -824,9 +796,8 @@ void handler_cov_subscribe( /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); - npdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address, - &npdu_data); + npdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address, + &npdu_data); if (service_data->segmented_message) { /* we don't support segmentation - send an abort */ len = BACNET_STATUS_ABORT; @@ -836,9 +807,8 @@ void handler_cov_subscribe( error = true; goto COV_ABORT; } - len = - cov_subscribe_decode_service_request(service_request, service_len, - &cov_data); + len = cov_subscribe_decode_service_request(service_request, service_len, + &cov_data); #if PRINT_ENABLED if (len <= 0) fprintf(stderr, "SubscribeCOV: Unable to decode Request!\n"); @@ -849,13 +819,12 @@ void handler_cov_subscribe( } cov_data.error_class = ERROR_CLASS_OBJECT; cov_data.error_code = ERROR_CODE_UNKNOWN_OBJECT; - success = - cov_subscribe(src, &cov_data, &cov_data.error_class, - &cov_data.error_code); + success = cov_subscribe(src, &cov_data, &cov_data.error_class, + &cov_data.error_code); if (success) { - apdu_len = - encode_simple_ack(&Handler_Transmit_Buffer[npdu_len], - service_data->invoke_id, SERVICE_CONFIRMED_SUBSCRIBE_COV); + apdu_len = encode_simple_ack(&Handler_Transmit_Buffer[npdu_len], + service_data->invoke_id, + SERVICE_CONFIRMED_SUBSCRIBE_COV); #if PRINT_ENABLED fprintf(stderr, "SubscribeCOV: Sending Simple Ack!\n"); #endif @@ -866,28 +835,26 @@ void handler_cov_subscribe( fprintf(stderr, "SubscribeCOV: Sending Error!\n"); #endif } - COV_ABORT: +COV_ABORT: if (error) { if (len == BACNET_STATUS_ABORT) { - apdu_len = - abort_encode_apdu(&Handler_Transmit_Buffer[npdu_len], - service_data->invoke_id, + apdu_len = abort_encode_apdu( + &Handler_Transmit_Buffer[npdu_len], service_data->invoke_id, abort_convert_error_code(cov_data.error_code), true); #if PRINT_ENABLED fprintf(stderr, "SubscribeCOV: Sending Abort!\n"); #endif } else if (len == BACNET_STATUS_ERROR) { - apdu_len = - bacerror_encode_apdu(&Handler_Transmit_Buffer[npdu_len], - service_data->invoke_id, SERVICE_CONFIRMED_SUBSCRIBE_COV, - cov_data.error_class, cov_data.error_code); + apdu_len = bacerror_encode_apdu( + &Handler_Transmit_Buffer[npdu_len], service_data->invoke_id, + SERVICE_CONFIRMED_SUBSCRIBE_COV, cov_data.error_class, + cov_data.error_code); #if PRINT_ENABLED fprintf(stderr, "SubscribeCOV: Sending Error!\n"); #endif } else if (len == BACNET_STATUS_REJECT) { - apdu_len = - reject_encode_apdu(&Handler_Transmit_Buffer[npdu_len], - service_data->invoke_id, + apdu_len = reject_encode_apdu( + &Handler_Transmit_Buffer[npdu_len], service_data->invoke_id, reject_convert_error_code(cov_data.error_code)); #if PRINT_ENABLED fprintf(stderr, "SubscribeCOV: Sending Reject!\n"); @@ -895,16 +862,14 @@ void handler_cov_subscribe( } } pdu_len = npdu_len + apdu_len; - bytes_sent = - datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], - pdu_len); + bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], + pdu_len); if (bytes_sent <= 0) { #if PRINT_ENABLED fprintf(stderr, "SubscribeCOV: Failed to send PDU (%s)!\n", - strerror(errno)); + strerror(errno)); #endif } - return; } diff --git a/demo/handler/h_dcc.c b/demo/handler/h_dcc.c index ce1c2e96..80db3325 100644 --- a/demo/handler/h_dcc.c +++ b/demo/handler/h_dcc.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2006 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2006 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -47,10 +47,9 @@ static char My_Password[32] = "filister"; /** Sets (non-volatile hold) the password to be used for DCC requests. * @param new_password [in] The new DCC password, of up to 31 characters. */ -void handler_dcc_password_set( - char *new_password) +void handler_dcc_password_set(char *new_password) { - size_t i = 0; /* loop counter */ + size_t i = 0; /* loop counter */ if (new_password) { for (i = 0; i < (sizeof(My_Password) - 1); i++) { @@ -95,10 +94,8 @@ char *handler_dcc_password(void) * decoded from the APDU header of this message. */ void handler_device_communication_control( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src, - BACNET_CONFIRMED_SERVICE_DATA * service_data) + uint8_t *service_request, uint16_t service_len, BACNET_ADDRESS *src, + BACNET_CONFIRMED_SERVICE_DATA *service_data) { uint16_t timeDuration = 0; BACNET_COMMUNICATION_ENABLE_DISABLE state = COMMUNICATION_ENABLE; @@ -111,100 +108,96 @@ void handler_device_communication_control( /* encode the NPDU portion of the reply packet */ datalink_get_my_address(&my_address); npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); - pdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address, - &npdu_data); + pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address, + &npdu_data); #if PRINT_ENABLED fprintf(stderr, "DeviceCommunicationControl!\n"); #endif if (service_data->segmented_message) { - len = - abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, - true); + len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], + service_data->invoke_id, + ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); #if PRINT_ENABLED fprintf(stderr, - "DeviceCommunicationControl: " - "Sending Abort - segmented message.\n"); + "DeviceCommunicationControl: " + "Sending Abort - segmented message.\n"); #endif goto DCC_ABORT; } /* decode the service request only */ - len = - dcc_decode_service_request(service_request, service_len, &timeDuration, - &state, &password); + len = dcc_decode_service_request(service_request, service_len, + &timeDuration, &state, &password); #if PRINT_ENABLED if (len > 0) fprintf(stderr, - "DeviceCommunicationControl: " "timeout=%u state=%u password=%s\n", - (unsigned) timeDuration, (unsigned) state, - characterstring_value(&password)); + "DeviceCommunicationControl: " + "timeout=%u state=%u password=%s\n", + (unsigned)timeDuration, (unsigned)state, + characterstring_value(&password)); #endif /* bad decoding or something we didn't understand - send an abort */ if (len < 0) { - len = - abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, ABORT_REASON_OTHER, true); + len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], + service_data->invoke_id, ABORT_REASON_OTHER, + true); #if PRINT_ENABLED fprintf(stderr, - "DeviceCommunicationControl: " - "Sending Abort - could not decode.\n"); + "DeviceCommunicationControl: " + "Sending Abort - could not decode.\n"); #endif goto DCC_ABORT; } if (state >= MAX_BACNET_COMMUNICATION_ENABLE_DISABLE) { - len = - reject_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, REJECT_REASON_UNDEFINED_ENUMERATION); + len = reject_encode_apdu(&Handler_Transmit_Buffer[pdu_len], + service_data->invoke_id, + REJECT_REASON_UNDEFINED_ENUMERATION); #if PRINT_ENABLED fprintf(stderr, - "DeviceCommunicationControl: " - "Sending Reject - undefined enumeration\n"); + "DeviceCommunicationControl: " + "Sending Reject - undefined enumeration\n"); #endif } else { #if BAC_ROUTING /* Check to see if the current Device supports this service. */ - len = - Routed_Device_Service_Approval - (SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL, (int) state, + len = Routed_Device_Service_Approval( + SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL, (int)state, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id); if (len > 0) goto DCC_ABORT; #endif if (characterstring_ansi_same(&password, My_Password)) { - len = - encode_simple_ack(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, + len = encode_simple_ack( + &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL); #if PRINT_ENABLED fprintf(stderr, - "DeviceCommunicationControl: " "Sending Simple Ack!\n"); + "DeviceCommunicationControl: " + "Sending Simple Ack!\n"); #endif dcc_set_status_duration(state, timeDuration); } else { - len = - bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, + len = bacerror_encode_apdu( + &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL, ERROR_CLASS_SECURITY, ERROR_CODE_PASSWORD_FAILURE); #if PRINT_ENABLED fprintf(stderr, - "DeviceCommunicationControl: " - "Sending Error - password failure.\n"); + "DeviceCommunicationControl: " + "Sending Error - password failure.\n"); #endif } } - DCC_ABORT: +DCC_ABORT: pdu_len += len; - len = - datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], - pdu_len); + len = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], + pdu_len); if (len <= 0) { #if PRINT_ENABLED fprintf(stderr, - "DeviceCommunicationControl: " "Failed to send PDU (%s)!\n", - strerror(errno)); + "DeviceCommunicationControl: " + "Failed to send PDU (%s)!\n", + strerror(errno)); #endif } diff --git a/demo/handler/h_gas_a.c b/demo/handler/h_gas_a.c index 0073cd31..df6e3b76 100644 --- a/demo/handler/h_gas_a.c +++ b/demo/handler/h_gas_a.c @@ -1,39 +1,39 @@ /** -* @file -* @author Daniel Blazevic -* @date 2013 -* @brief GetAlarmSummary ACK service handling -* -* @section LICENSE -* -* Copyright (C) 2013 Daniel Blazevic -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -* @section DESCRIPTION -* -* The GetAlarmSummary ACK service handler is used by a client BACnet-user to -* obtain a summary of "active alarms." The term "active alarm" refers to -* BACnet standard objects that have an Event_State property whose value is -* not equal to NORMAL and a Notify_Type property whose value is ALARM. -*/ + * @file + * @author Daniel Blazevic + * @date 2013 + * @brief GetAlarmSummary ACK service handling + * + * @section LICENSE + * + * Copyright (C) 2013 Daniel Blazevic + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * @section DESCRIPTION + * + * The GetAlarmSummary ACK service handler is used by a client BACnet-user to + * obtain a summary of "active alarms." The term "active alarm" refers to + * BACnet standard objects that have an Event_State property whose value is + * not equal to NORMAL and a Notify_Type property whose value is ALARM. + */ #include #include "config.h" #include "txbuf.h" @@ -46,7 +46,6 @@ #include "handlers.h" #include "get_alarm_sum.h" - /** Example function to handle a GetAlarmSummary ACK. * * @param service_request [in] The contents of the service request. @@ -56,19 +55,16 @@ * decoded from the APDU header of this message. */ void get_alarm_summary_ack_handler( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src, - BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data) + uint8_t* service_request, uint16_t service_len, BACNET_ADDRESS* src, + BACNET_CONFIRMED_SERVICE_ACK_DATA* service_data) { uint16_t apdu_len = 0; uint16_t len = 0; BACNET_GET_ALARM_SUMMARY_DATA data; while (service_len - len) { - apdu_len = - get_alarm_summary_ack_decode_apdu_data(&service_request[len], - service_len - len, &data); + apdu_len = get_alarm_summary_ack_decode_apdu_data( + &service_request[len], service_len - len, &data); len += apdu_len; diff --git a/demo/handler/h_get_alarm_sum.c b/demo/handler/h_get_alarm_sum.c index 7ef4de10..aec7b245 100644 --- a/demo/handler/h_get_alarm_sum.c +++ b/demo/handler/h_get_alarm_sum.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2011 Krzysztof Malorny -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2011 Krzysztof Malorny + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -41,20 +41,17 @@ static get_alarm_summary_function Get_Alarm_Summary[MAX_BACNET_OBJECT_TYPE]; -void handler_get_alarm_summary_set( - BACNET_OBJECT_TYPE object_type, - get_alarm_summary_function pFunction) +void handler_get_alarm_summary_set(BACNET_OBJECT_TYPE object_type, + get_alarm_summary_function pFunction) { if (object_type < MAX_BACNET_OBJECT_TYPE) { Get_Alarm_Summary[object_type] = pFunction; } } -void handler_get_alarm_summary( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src, - BACNET_CONFIRMED_SERVICE_DATA * service_data) +void handler_get_alarm_summary(uint8_t* service_request, uint16_t service_len, + BACNET_ADDRESS* src, + BACNET_CONFIRMED_SERVICE_DATA* service_data) { int len = 0; int pdu_len = 0; @@ -68,41 +65,33 @@ void handler_get_alarm_summary( BACNET_NPDU_DATA npdu_data; BACNET_GET_ALARM_SUMMARY_DATA getalarm_data; - - /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); - pdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address, - &npdu_data); + pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address, + &npdu_data); if (service_data->segmented_message) { /* we don't support segmentation - send an abort */ - apdu_len = - abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, - true); + apdu_len = abort_encode_apdu( + &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, + ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); #if PRINT_ENABLED - fprintf(stderr, - "GetAlarmSummary: Segmented message. Sending Abort!\n"); + fprintf(stderr, "GetAlarmSummary: Segmented message. Sending Abort!\n"); #endif goto GET_ALARM_SUMMARY_ABORT; } /* init header */ - apdu_len = - get_alarm_summary_ack_encode_apdu_init(&Handler_Transmit_Buffer - [pdu_len], service_data->invoke_id); - + apdu_len = get_alarm_summary_ack_encode_apdu_init( + &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id); for (i = 0; i < MAX_BACNET_OBJECT_TYPE; i++) { if (Get_Alarm_Summary[i]) { for (j = 0; j < 0xffff; j++) { - alarm_value = Get_Alarm_Summary[i] (j, &getalarm_data); + alarm_value = Get_Alarm_Summary[i](j, &getalarm_data); if (alarm_value > 0) { - len = - get_alarm_summary_ack_encode_apdu_data - (&Handler_Transmit_Buffer[pdu_len + apdu_len], + len = get_alarm_summary_ack_encode_apdu_data( + &Handler_Transmit_Buffer[pdu_len + apdu_len], service_data->max_resp - apdu_len, &getalarm_data); if (len <= 0) { error = true; @@ -116,40 +105,36 @@ void handler_get_alarm_summary( } } - #if PRINT_ENABLED fprintf(stderr, "GetAlarmSummary: Sending response!\n"); #endif - GET_ALARM_SUMMARY_ERROR: +GET_ALARM_SUMMARY_ERROR: if (error) { if (len == BACNET_STATUS_ABORT) { /* BACnet APDU too small to fit data, so proper response is Abort */ - apdu_len = - abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, + apdu_len = abort_encode_apdu( + &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); #if PRINT_ENABLED fprintf(stderr, - "GetAlarmSummary: Reply too big to fit into APDU!\n"); + "GetAlarmSummary: Reply too big to fit into APDU!\n"); #endif } else { - apdu_len = - bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, SERVICE_CONFIRMED_GET_ALARM_SUMMARY, - ERROR_CLASS_PROPERTY, ERROR_CODE_OTHER); + apdu_len = bacerror_encode_apdu( + &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, + SERVICE_CONFIRMED_GET_ALARM_SUMMARY, ERROR_CLASS_PROPERTY, + ERROR_CODE_OTHER); #if PRINT_ENABLED fprintf(stderr, "GetAlarmSummary: Sending Error!\n"); #endif } } - - GET_ALARM_SUMMARY_ABORT: +GET_ALARM_SUMMARY_ABORT: pdu_len += apdu_len; - bytes_sent = - datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], - pdu_len); + bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], + pdu_len); #if PRINT_ENABLED if (bytes_sent <= 0) { /*fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno)); */ diff --git a/demo/handler/h_getevent.c b/demo/handler/h_getevent.c index cbc54c2e..f1ee582f 100644 --- a/demo/handler/h_getevent.c +++ b/demo/handler/h_getevent.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2009 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2009 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -43,45 +43,37 @@ static get_event_info_function Get_Event_Info[MAX_BACNET_OBJECT_TYPE]; - /** print eventState */ -void ge_ack_print_data( - BACNET_GET_EVENT_INFORMATION_DATA * data, - uint32_t device_id) +void ge_ack_print_data(BACNET_GET_EVENT_INFORMATION_DATA* data, + uint32_t device_id) { - BACNET_GET_EVENT_INFORMATION_DATA *act_data = data; + BACNET_GET_EVENT_INFORMATION_DATA* act_data = data; const char* state_strs[] = {"NO", "FA", "ON", "HL", "LL"}; - printf("DeviceID\tType\tInstance\teventState\n"); - printf("--------------- ------- --------------- ---------------\n"); - int count = 0; - while (act_data) { - printf("%u\t\t%u\t%u\t\t%s\n", - device_id, - act_data->objectIdentifier.type, - act_data->objectIdentifier.instance, - state_strs[data->eventState] - ); - act_data = act_data->next; - count++; - } - printf("\n%u\t Total\n",count); + printf("DeviceID\tType\tInstance\teventState\n"); + printf("--------------- ------- --------------- ---------------\n"); + int count = 0; + while (act_data) { + printf( + "%u\t\t%u\t%u\t\t%s\n", device_id, act_data->objectIdentifier.type, + act_data->objectIdentifier.instance, state_strs[data->eventState]); + act_data = act_data->next; + count++; + } + printf("\n%u\t Total\n", count); } -void handler_get_event_information_set( - BACNET_OBJECT_TYPE object_type, - get_event_info_function pFunction) +void handler_get_event_information_set(BACNET_OBJECT_TYPE object_type, + get_event_info_function pFunction) { if (object_type < MAX_BACNET_OBJECT_TYPE) { Get_Event_Info[object_type] = pFunction; } } -void handler_get_event_information( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src, - BACNET_CONFIRMED_SERVICE_DATA * service_data) +void handler_get_event_information(uint8_t* service_request, + uint16_t service_len, BACNET_ADDRESS* src, + BACNET_CONFIRMED_SERVICE_DATA* service_data) { int len = 0; int pdu_len = 0; @@ -94,7 +86,7 @@ void handler_get_event_information( BACNET_ERROR_CODE error_code = ERROR_CODE_UNKNOWN_OBJECT; BACNET_ADDRESS my_address; BACNET_OBJECT_ID object_id; - unsigned i = 0, j = 0; /* counter */ + unsigned i = 0, j = 0; /* counter */ BACNET_GET_EVENT_INFORMATION_DATA getevent_data; int valid_event = 0; @@ -104,38 +96,35 @@ void handler_get_event_information( /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); - pdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address, - &npdu_data); + pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address, + &npdu_data); if (service_data->segmented_message) { /* we don't support segmentation - send an abort */ - len = - abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, - true); + len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], + service_data->invoke_id, + ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); #if PRINT_ENABLED fprintf(stderr, - "GetEventInformation: " "Segmented message. Sending Abort!\n"); + "GetEventInformation: " + "Segmented message. Sending Abort!\n"); #endif goto GET_EVENT_ABORT; } - len = - getevent_decode_service_request(service_request, service_len, - &object_id); + len = getevent_decode_service_request(service_request, service_len, + &object_id); if (len < 0) { /* bad decoding - send an abort */ - len = - abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, ABORT_REASON_OTHER, true); + len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], + service_data->invoke_id, ABORT_REASON_OTHER, + true); #if PRINT_ENABLED - fprintf(stderr, - "GetEventInformation: Bad Encoding. Sending Abort!\n"); + fprintf(stderr, "GetEventInformation: Bad Encoding. Sending Abort!\n"); #endif goto GET_EVENT_ABORT; } - len = - getevent_ack_encode_apdu_init(&Handler_Transmit_Buffer[pdu_len], + len = getevent_ack_encode_apdu_init( + &Handler_Transmit_Buffer[pdu_len], sizeof(Handler_Transmit_Buffer) - pdu_len, service_data->invoke_id); if (len <= 0) { error = true; @@ -146,14 +135,15 @@ void handler_get_event_information( for (i = 0; i < MAX_BACNET_OBJECT_TYPE; i++) { if (Get_Event_Info[i]) { for (j = 0; j < 0xffff; j++) { - valid_event = Get_Event_Info[i] (j, &getevent_data); + valid_event = Get_Event_Info[i](j, &getevent_data); if (valid_event > 0) { - /* encode GetEvent_data only when type of object_id has max value */ + /* encode GetEvent_data only when type of object_id has max + * value */ if (object_id.type != MAX_BACNET_OBJECT_TYPE) { if ((object_id.type == - getevent_data.objectIdentifier.type) && + getevent_data.objectIdentifier.type) && (object_id.instance == - getevent_data.objectIdentifier.instance)) { + getevent_data.objectIdentifier.instance)) { /* found 'Last Received Object Identifier' so should set type of object_id to max value */ object_id.type = MAX_BACNET_OBJECT_TYPE; @@ -162,16 +152,16 @@ void handler_get_event_information( } getevent_data.next = NULL; - len = - getevent_ack_encode_apdu_data(&Handler_Transmit_Buffer - [pdu_len], sizeof(Handler_Transmit_Buffer) - pdu_len, + len = getevent_ack_encode_apdu_data( + &Handler_Transmit_Buffer[pdu_len], + sizeof(Handler_Transmit_Buffer) - pdu_len, &getevent_data); if (len <= 0) { error = true; goto GET_EVENT_ERROR; } apdu_len += len; - if ((apdu_len >= service_data->max_resp - 2) || + if ((apdu_len >= service_data->max_resp - 2) || (apdu_len >= MAX_APDU - 2)) { /* Device must be able to fit minimum one event information. @@ -195,8 +185,8 @@ void handler_get_event_information( } } } - len = - getevent_ack_encode_apdu_end(&Handler_Transmit_Buffer[pdu_len], + len = getevent_ack_encode_apdu_end( + &Handler_Transmit_Buffer[pdu_len], sizeof(Handler_Transmit_Buffer) - pdu_len, more_events); if (len <= 0) { error = true; @@ -205,37 +195,34 @@ void handler_get_event_information( #if PRINT_ENABLED fprintf(stderr, "Got a GetEventInformation request: Sending Ack!\n"); #endif - GET_EVENT_ERROR: +GET_EVENT_ERROR: if (error) { - pdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address, - &npdu_data); + pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address, + &npdu_data); if (len == -2) { /* BACnet APDU too small to fit data, so proper response is Abort */ - len = - abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, + len = abort_encode_apdu( + &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); #if PRINT_ENABLED fprintf(stderr, - "GetEventInformation: " "Reply too big to fit into APDU!\n"); + "GetEventInformation: " + "Reply too big to fit into APDU!\n"); #endif } else { - len = - bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, SERVICE_CONFIRMED_READ_PROPERTY, - error_class, error_code); + len = bacerror_encode_apdu( + &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, + SERVICE_CONFIRMED_READ_PROPERTY, error_class, error_code); #if PRINT_ENABLED fprintf(stderr, "GetEventInformation: Sending Error!\n"); #endif } } - GET_EVENT_ABORT: +GET_EVENT_ABORT: pdu_len += len; - bytes_sent = - datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], - pdu_len); + bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], + pdu_len); #if PRINT_ENABLED if (bytes_sent <= 0) fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno)); diff --git a/demo/handler/h_getevent_a.c b/demo/handler/h_getevent_a.c index 8547ab8a..e22c0609 100644 --- a/demo/handler/h_getevent_a.c +++ b/demo/handler/h_getevent_a.c @@ -59,11 +59,9 @@ * @param service_data [in] The BACNET_CONFIRMED_SERVICE_ACK_DATA information * decoded from the APDU header of this message. */ -void get_event_ack_handler( - uint8_t *service_request, - uint16_t service_len, - BACNET_ADDRESS *src, - BACNET_CONFIRMED_SERVICE_ACK_DATA *service_data) +void get_event_ack_handler(uint8_t *service_request, uint16_t service_len, + BACNET_ADDRESS *src, + BACNET_CONFIRMED_SERVICE_ACK_DATA *service_data) { uint8_t i = 0; uint16_t apdu_len = 0; @@ -77,9 +75,8 @@ void get_event_ack_handler( get_event_data[i - 1].next = &get_event_data[i]; } - apdu_len = - getevent_ack_decode_service_request(&service_request[0], - service_len, &get_event_data[0], &more_events); + apdu_len = getevent_ack_decode_service_request( + &service_request[0], service_len, &get_event_data[0], &more_events); if (apdu_len > 0) { /* FIXME: Add code to process get_event_data */ diff --git a/demo/handler/h_iam.c b/demo/handler/h_iam.c index 8387a33a..a1d0190f 100644 --- a/demo/handler/h_iam.c +++ b/demo/handler/h_iam.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2005 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2005 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -42,10 +42,8 @@ * @param service_len [in] Length of the service_request message. * @param src [in] The BACNET_ADDRESS of the message's source. */ -void handler_i_am_add( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src) +void handler_i_am_add(uint8_t* service_request, uint16_t service_len, + BACNET_ADDRESS* src) { int len = 0; uint32_t device_id = 0; @@ -53,18 +51,17 @@ void handler_i_am_add( int segmentation = 0; uint16_t vendor_id = 0; - (void) service_len; - len = - iam_decode_service_request(service_request, &device_id, &max_apdu, - &segmentation, &vendor_id); + (void)service_len; + len = iam_decode_service_request(service_request, &device_id, &max_apdu, + &segmentation, &vendor_id); #if PRINT_ENABLED fprintf(stderr, "Received I-Am Request"); #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]); + (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 { @@ -84,10 +81,8 @@ void handler_i_am_add( * @param service_len [in] Length of the service_request message. * @param src [in] The BACNET_ADDRESS of the message's source. */ -void handler_i_am_bind( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src) +void handler_i_am_bind(uint8_t* service_request, uint16_t service_len, + BACNET_ADDRESS* src) { int len = 0; uint32_t device_id = 0; @@ -95,10 +90,9 @@ void handler_i_am_bind( int segmentation = 0; uint16_t vendor_id = 0; - (void) service_len; - len = - iam_decode_service_request(service_request, &device_id, &max_apdu, - &segmentation, &vendor_id); + (void)service_len; + len = iam_decode_service_request(service_request, &device_id, &max_apdu, + &segmentation, &vendor_id); if (len > 0) { /* only add address if requested to bind */ address_add_binding(device_id, max_apdu, src); diff --git a/demo/handler/h_ihave.c b/demo/handler/h_ihave.c index e5f21aee..fb5db5ef 100644 --- a/demo/handler/h_ihave.c +++ b/demo/handler/h_ihave.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2006 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2006 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -41,24 +41,22 @@ * @param service_len [in] Length of the service_request message. * @param src [in] The BACNET_ADDRESS of the message's source. */ -void handler_i_have( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src) +void handler_i_have(uint8_t* service_request, uint16_t service_len, + BACNET_ADDRESS* src) { int len = 0; BACNET_I_HAVE_DATA data; - (void) service_len; - (void) src; + (void)service_len; + (void)src; len = ihave_decode_service_request(service_request, service_len, &data); if (len != -1) { #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, - bactext_object_type_name(data.device_id.type), - (unsigned long) data.device_id.instance); + bactext_object_type_name(data.object_id.type), + (unsigned long)data.object_id.instance, + bactext_object_type_name(data.device_id.type), + (unsigned long)data.device_id.instance); #endif } else { #if PRINT_ENABLED diff --git a/demo/handler/h_lso.c b/demo/handler/h_lso.c index 196497f3..0638162f 100644 --- a/demo/handler/h_lso.c +++ b/demo/handler/h_lso.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2005 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2005 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -40,11 +40,9 @@ /** @file h_lso.c Handles BACnet Life Safey Operation messages. */ -void handler_lso( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src, - BACNET_CONFIRMED_SERVICE_DATA * service_data) +void handler_lso(uint8_t* service_request, uint16_t service_len, + BACNET_ADDRESS* src, + BACNET_CONFIRMED_SERVICE_DATA* service_data) { BACNET_LSO_DATA data; int len = 0; @@ -56,15 +54,13 @@ void handler_lso( /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); - pdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address, - &npdu_data); + pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address, + &npdu_data); if (service_data->segmented_message) { /* we don't support segmentation - send an abort */ - len = - abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, - true); + len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], + service_data->invoke_id, + ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); #if PRINT_ENABLED fprintf(stderr, "LSO: Segmented message. Sending Abort!\n"); #endif @@ -78,9 +74,9 @@ void handler_lso( #endif if (len < 0) { /* bad decoding - send an abort */ - len = - abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, ABORT_REASON_OTHER, true); + len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], + service_data->invoke_id, ABORT_REASON_OTHER, + true); #if PRINT_ENABLED fprintf(stderr, "LSO: Bad Encoding. Sending Abort!\n"); #endif @@ -92,27 +88,31 @@ 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); + "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); #endif - len = - encode_simple_ack(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, SERVICE_CONFIRMED_LIFE_SAFETY_OPERATION); + len = encode_simple_ack(&Handler_Transmit_Buffer[pdu_len], + service_data->invoke_id, + SERVICE_CONFIRMED_LIFE_SAFETY_OPERATION); #if PRINT_ENABLED - fprintf(stderr, "Life Safety Operation: " "Sending Simple Ack!\n"); + fprintf(stderr, + "Life Safety Operation: " + "Sending Simple Ack!\n"); #endif - LSO_ABORT: +LSO_ABORT: pdu_len += len; - bytes_sent = - datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], - pdu_len); + bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], + pdu_len); #if PRINT_ENABLED if (bytes_sent <= 0) - fprintf(stderr, "Life Safety Operation: " "Failed to send PDU (%s)!\n", - strerror(errno)); + fprintf(stderr, + "Life Safety Operation: " + "Failed to send PDU (%s)!\n", + strerror(errno)); #endif return; diff --git a/demo/handler/h_npdu.c b/demo/handler/h_npdu.c index 973b6061..23281c7a 100644 --- a/demo/handler/h_npdu.c +++ b/demo/handler/h_npdu.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2008 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2008 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include "bacdef.h" @@ -63,14 +63,13 @@ * @param pdu [in] Buffer containing the NPDU and APDU of the received packet. * @param pdu_len [in] The size of the received message in the pdu[] buffer. */ -void npdu_handler( - BACNET_ADDRESS * src, /* source address */ - uint8_t * pdu, /* PDU data */ - uint16_t pdu_len) -{ /* length PDU */ +void npdu_handler(BACNET_ADDRESS* src, /* source address */ + uint8_t* pdu, /* PDU data */ + uint16_t pdu_len) +{ /* length PDU */ int apdu_offset = 0; - BACNET_ADDRESS dest = { 0 }; - BACNET_NPDU_DATA npdu_data = { 0 }; + BACNET_ADDRESS dest = {0}; + BACNET_NPDU_DATA npdu_data = {0}; /* only handle the version that we know how to handle */ if (pdu[0] == BACNET_PROTOCOL_VERSION) { @@ -87,24 +86,24 @@ void npdu_handler( routing information cause they are not for us */ if ((dest.net == BACNET_BROADCAST_NETWORK) && ((pdu[apdu_offset] & 0xF0) == - PDU_TYPE_CONFIRMED_SERVICE_REQUEST)) { + PDU_TYPE_CONFIRMED_SERVICE_REQUEST)) { /* hack for 5.4.5.1 - IDLE */ /* ConfirmedBroadcastReceived */ /* then enter IDLE - ignore the PDU */ } else { apdu_handler(src, &pdu[apdu_offset], - (uint16_t) (pdu_len - apdu_offset)); + (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]); + (unsigned)pdu[0]); #endif } diff --git a/demo/handler/h_pt.c b/demo/handler/h_pt.c index 7658d1e5..6dd61786 100644 --- a/demo/handler/h_pt.c +++ b/demo/handler/h_pt.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2005 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2005 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -50,12 +50,11 @@ DATABLOCK MyData[MYMAXBLOCK]; -uint8_t IOBufferPT[MAX_APDU]; /* Buffer for building response in */ +uint8_t IOBufferPT[MAX_APDU]; /* Buffer for building response in */ -static void ProcessPT( - BACNET_PRIVATE_TRANSFER_DATA * data) +static void ProcessPT(BACNET_PRIVATE_TRANSFER_DATA *data) { - int iLen; /* Index to current location in data */ + int iLen; /* Index to current location in data */ char cBlockNumber; uint32_t ulTemp; int tag_len; @@ -66,9 +65,8 @@ static void ProcessPT( iLen = 0; /* Decode the block number */ - tag_len = - decode_tag_number_and_value(&data->serviceParameters[iLen], - &tag_number, &len_value_type); + tag_len = decode_tag_number_and_value(&data->serviceParameters[iLen], + &tag_number, &len_value_type); iLen += tag_len; if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT) { /* Bail out early if wrong type */ @@ -77,10 +75,9 @@ static void ProcessPT( return; } - iLen += - decode_unsigned(&data->serviceParameters[iLen], len_value_type, - &ulTemp); - cBlockNumber = (char) ulTemp; + iLen += decode_unsigned(&data->serviceParameters[iLen], len_value_type, + &ulTemp); + cBlockNumber = (char)ulTemp; if (cBlockNumber < MY_MAX_BLOCK) { if (data->serviceNumber == MY_SVC_READ) { /* Read Response is an unsigned int with @@ -101,20 +98,16 @@ static void ProcessPT( 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); + iLen += encode_application_real( + &IOBufferPT[iLen], MyData[(int8_t)cBlockNumber].fMyReal); + characterstring_init_ansi( + &bsTemp, (char *)MyData[(int8_t)cBlockNumber].sMyString); iLen += - encode_application_unsigned(&IOBufferPT[iLen], - 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); - iLen += - encode_application_character_string(&IOBufferPT[iLen], - &bsTemp); + encode_application_character_string(&IOBufferPT[iLen], &bsTemp); } else { /* Write operation */ /* Write block consists of the block number @@ -124,59 +117,52 @@ static void ProcessPT( response which is 0 for success and a non 0 error code otherwise. */ - tag_len = - decode_tag_number_and_value(&data->serviceParameters[iLen], - &tag_number, &len_value_type); + tag_len = decode_tag_number_and_value( + &data->serviceParameters[iLen], &tag_number, &len_value_type); iLen += tag_len; if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT) { data->serviceParametersLen = 0; return; } - iLen += - decode_unsigned(&data->serviceParameters[iLen], len_value_type, - &ulTemp); - MyData[(int8_t) cBlockNumber].cMyByte1 = (char) ulTemp; + iLen += decode_unsigned(&data->serviceParameters[iLen], + len_value_type, &ulTemp); + MyData[(int8_t)cBlockNumber].cMyByte1 = (char)ulTemp; - tag_len = - decode_tag_number_and_value(&data->serviceParameters[iLen], - &tag_number, &len_value_type); + tag_len = decode_tag_number_and_value( + &data->serviceParameters[iLen], &tag_number, &len_value_type); iLen += tag_len; if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT) { data->serviceParametersLen = 0; return; } - iLen += - decode_unsigned(&data->serviceParameters[iLen], len_value_type, - &ulTemp); - MyData[(int8_t) cBlockNumber].cMyByte2 = (char) ulTemp; + iLen += decode_unsigned(&data->serviceParameters[iLen], + len_value_type, &ulTemp); + MyData[(int8_t)cBlockNumber].cMyByte2 = (char)ulTemp; - tag_len = - decode_tag_number_and_value(&data->serviceParameters[iLen], - &tag_number, &len_value_type); + tag_len = decode_tag_number_and_value( + &data->serviceParameters[iLen], &tag_number, &len_value_type); iLen += tag_len; if (tag_number != BACNET_APPLICATION_TAG_REAL) { data->serviceParametersLen = 0; return; } - iLen += - decode_real(&data->serviceParameters[iLen], - &MyData[(int8_t) cBlockNumber].fMyReal); + iLen += decode_real(&data->serviceParameters[iLen], + &MyData[(int8_t)cBlockNumber].fMyReal); - tag_len = - decode_tag_number_and_value(&data->serviceParameters[iLen], - &tag_number, &len_value_type); + tag_len = decode_tag_number_and_value( + &data->serviceParameters[iLen], &tag_number, &len_value_type); iLen += tag_len; if (tag_number != BACNET_APPLICATION_TAG_CHARACTER_STRING) { data->serviceParametersLen = 0; return; } decode_character_string(&data->serviceParameters[iLen], - len_value_type, &bsTemp); + 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); } @@ -198,12 +184,9 @@ static void ProcessPT( * */ - -void handler_conf_private_trans( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src, - BACNET_CONFIRMED_SERVICE_DATA * service_data) +void handler_conf_private_trans(uint8_t *service_request, uint16_t service_len, + BACNET_ADDRESS *src, + BACNET_CONFIRMED_SERVICE_DATA *service_data) { BACNET_PRIVATE_TRANSFER_DATA data; int len; @@ -230,28 +213,25 @@ void handler_conf_private_trans( datalink_get_my_address(&my_address); npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); - pdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address, - &npdu_data); + pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address, + &npdu_data); if (service_data->segmented_message) { - len = - abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, - true); + len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], + service_data->invoke_id, + ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); #if PRINT_ENABLED fprintf(stderr, "CPT: Segmented Message. Sending Abort!\n"); #endif goto CPT_ABORT; } - len = - ptransfer_decode_service_request(service_request, service_len, &data); + len = ptransfer_decode_service_request(service_request, service_len, &data); /* bad decoding - send an abort */ if (len < 0) { - len = - abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, ABORT_REASON_OTHER, true); + len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], + service_data->invoke_id, ABORT_REASON_OTHER, + true); #if PRINT_ENABLED fprintf(stderr, "CPT: Bad Encoding. Sending Abort!\n"); #endif @@ -278,10 +258,9 @@ void handler_conf_private_trans( fprintf(stderr, "CPT: Error servicing request!\n"); #endif } - len = - ptransfer_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, &data); - } else { /* Not our vendor ID or bad service parameter */ + len = ptransfer_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len], + service_data->invoke_id, &data); + } else { /* Not our vendor ID or bad service parameter */ error = true; error_class = ERROR_CLASS_SERVICES; @@ -292,15 +271,14 @@ void handler_conf_private_trans( } if (error) { - len = - ptransfer_error_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, error_class, error_code, &data); + len = ptransfer_error_encode_apdu(&Handler_Transmit_Buffer[pdu_len], + service_data->invoke_id, error_class, + error_code, &data); } - CPT_ABORT: +CPT_ABORT: pdu_len += len; - bytes_sent = - datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], - pdu_len); + bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], + pdu_len); #if PRINT_ENABLED if (bytes_sent <= 0) { diff --git a/demo/handler/h_pt_a.c b/demo/handler/h_pt_a.c index dda8eb08..ee41993e 100644 --- a/demo/handler/h_pt_a.c +++ b/demo/handler/h_pt_a.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2005 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2005 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -45,11 +45,10 @@ /** @file h_pt_a.c Handles Confirmed Private Transfer Acknowledgment. */ -extern uint8_t IOBufferPT[300]; /* Somewhere to build the encoded result block for Private Transfers */ +extern uint8_t IOBufferPT[300]; /* Somewhere to build the encoded result block + for Private Transfers */ -static void DecodeBlock( - char cBlockNum, - uint8_t * pData) +static void DecodeBlock(char cBlockNum, uint8_t *pData) { int iLen; uint32_t ulTemp; @@ -65,28 +64,25 @@ static void DecodeBlock( return; tag_len = - decode_tag_number_and_value(&pData[iLen], &tag_number, - &len_value_type); + decode_tag_number_and_value(&pData[iLen], &tag_number, &len_value_type); iLen += tag_len; if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT) return; iLen += decode_unsigned(&pData[iLen], len_value_type, &ulTemp); - Response.cMyByte1 = (char) ulTemp; + Response.cMyByte1 = (char)ulTemp; tag_len = - decode_tag_number_and_value(&pData[iLen], &tag_number, - &len_value_type); + decode_tag_number_and_value(&pData[iLen], &tag_number, &len_value_type); iLen += tag_len; if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT) return; iLen += decode_unsigned(&pData[iLen], len_value_type, &ulTemp); - Response.cMyByte2 = (char) ulTemp; + Response.cMyByte2 = (char)ulTemp; tag_len = - decode_tag_number_and_value(&pData[iLen], &tag_number, - &len_value_type); + decode_tag_number_and_value(&pData[iLen], &tag_number, &len_value_type); iLen += tag_len; if (tag_number != BACNET_APPLICATION_TAG_REAL) return; @@ -94,29 +90,27 @@ static void DecodeBlock( iLen += decode_real(&pData[iLen], &Response.fMyReal); tag_len = - decode_tag_number_and_value(&pData[iLen], &tag_number, - &len_value_type); + decode_tag_number_and_value(&pData[iLen], &tag_number, &len_value_type); iLen += tag_len; if (tag_number != BACNET_APPLICATION_TAG_CHARACTER_STRING) return; iLen += decode_character_string(&pData[iLen], len_value_type, &bsName); - strncpy((char *) Response.sMyString, characterstring_value(&bsName), - MY_MAX_STR); - Response.sMyString[MY_MAX_STR] = '\0'; /* Make sure it is nul terminated */ + 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"); - printf("Data Block: %d\n", (int) cBlockNum); - printf(" First Byte : %d\n", (int) Response.cMyByte1); - printf(" Second Byte : %d\n", (int) Response.cMyByte2); + printf("Data Block: %d\n", (int)cBlockNum); + printf(" First Byte : %d\n", (int)Response.cMyByte1); + printf(" Second Byte : %d\n", (int)Response.cMyByte2); printf(" Real : %f\n", Response.fMyReal); printf(" String : %s\n\n", Response.sMyString); } -static void ProcessPTA( - BACNET_PRIVATE_TRANSFER_DATA * data) +static void ProcessPTA(BACNET_PRIVATE_TRANSFER_DATA *data) { - int iLen; /* Index to current location in data */ + int iLen; /* Index to current location in data */ uint32_t uiErrorCode; char cBlockNumber; uint32_t ulTemp; @@ -128,9 +122,8 @@ static void ProcessPTA( /* Error code is returned for read and write operations */ - tag_len = - decode_tag_number_and_value(&data->serviceParameters[iLen], - &tag_number, &len_value_type); + tag_len = 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 PRINT_ENABLED @@ -138,18 +131,18 @@ static void ProcessPTA( #endif return; } - iLen += - decode_unsigned(&data->serviceParameters[iLen], len_value_type, - &uiErrorCode); + iLen += decode_unsigned(&data->serviceParameters[iLen], len_value_type, + &uiErrorCode); - if (data->serviceNumber == MY_SVC_READ) { /* Read I/O block so should be full block of data or error */ - /* Decode the error type and if necessary block number and then fetch the info */ + if (data->serviceNumber == MY_SVC_READ) { /* Read I/O block so should be + full block of data or error */ + /* Decode the error type and if necessary block number and then fetch + * the info */ if (uiErrorCode == MY_ERR_OK) { /* Block Number */ - tag_len = - decode_tag_number_and_value(&data->serviceParameters[iLen], - &tag_number, &len_value_type); + tag_len = 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 PRINT_ENABLED @@ -158,25 +151,21 @@ static void ProcessPTA( return; } - iLen += - decode_unsigned(&data->serviceParameters[iLen], len_value_type, - &ulTemp); - cBlockNumber = (char) ulTemp; + iLen += decode_unsigned(&data->serviceParameters[iLen], + len_value_type, &ulTemp); + cBlockNumber = (char)ulTemp; DecodeBlock(cBlockNumber, &data->serviceParameters[iLen]); - } else { /* Read error */ - printf - ("Private Transfer read operation returned error code: %lu\n", - (unsigned long) uiErrorCode); + } else { /* Read error */ + 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 */ + } 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); } } - - /* * This is called when we receive a private transfer packet ack. * We parse the response which the remote application generated @@ -184,40 +173,38 @@ static void ProcessPTA( */ void handler_conf_private_trans_ack( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src, - BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data) + uint8_t *service_request, uint16_t service_len, BACNET_ADDRESS *src, + BACNET_CONFIRMED_SERVICE_ACK_DATA *service_data) { BACNET_PRIVATE_TRANSFER_DATA data; int len; -/* - * Note: - * We currently don't look at the source address and service data - * but we probably should to verify that the ack is oneit is what - * we were expecting. But this is just to silence some compiler - * warnings from Borland. - */ + /* + * Note: + * We currently don't look at the source address and service data + * but we probably should to verify that the ack is oneit is what + * we were expecting. But this is just to silence some compiler + * warnings from Borland. + */ src = src; service_data = service_data; len = 0; - - #if PRINT_ENABLED printf("Received Confirmed Private Transfer Ack!\n"); #endif - len = ptransfer_decode_service_request(service_request, service_len, &data); /* Same decode for ack as for service request! */ + len = ptransfer_decode_service_request( + service_request, service_len, + &data); /* Same decode for ack as for service request! */ if (len < 0) { #if PRINT_ENABLED printf("cpta: Bad Encoding!\n"); #endif } - ProcessPTA(&data); /* See what to do with the response */ + ProcessPTA(&data); /* See what to do with the response */ return; } diff --git a/demo/handler/h_rd.c b/demo/handler/h_rd.c index 69fd8498..3207c890 100644 --- a/demo/handler/h_rd.c +++ b/demo/handler/h_rd.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2006 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2006 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -63,11 +63,9 @@ * @param service_data [in] The BACNET_CONFIRMED_SERVICE_DATA information * decoded from the APDU header of this message. */ -void handler_reinitialize_device( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src, - BACNET_CONFIRMED_SERVICE_DATA * service_data) +void handler_reinitialize_device(uint8_t* service_request, uint16_t service_len, + BACNET_ADDRESS* src, + BACNET_CONFIRMED_SERVICE_DATA* service_data) { BACNET_REINITIALIZE_DEVICE_DATA rd_data; int len = 0; @@ -78,94 +76,88 @@ void handler_reinitialize_device( /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); - pdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address, - &npdu_data); + pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address, + &npdu_data); #if PRINT_ENABLED fprintf(stderr, "ReinitializeDevice!\n"); #endif if (service_data->segmented_message) { - len = - abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, - true); + len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], + service_data->invoke_id, + ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); #if PRINT_ENABLED fprintf(stderr, - "ReinitializeDevice: Sending Abort - segmented message.\n"); + "ReinitializeDevice: Sending Abort - segmented message.\n"); #endif goto RD_ABORT; } /* decode the service request only */ - len = - rd_decode_service_request(service_request, service_len, &rd_data.state, - &rd_data.password); + 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, - characterstring_value(&rd_data.password)); + (unsigned)rd_data.state, + characterstring_value(&rd_data.password)); } else { fprintf(stderr, "ReinitializeDevice: Unable to decode request!\n"); } #endif /* bad decoding or something we didn't understand - send an abort */ if (len < 0) { - len = - abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, ABORT_REASON_OTHER, true); + len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], + service_data->invoke_id, ABORT_REASON_OTHER, + true); #if PRINT_ENABLED fprintf(stderr, - "ReinitializeDevice: Sending Abort - could not decode.\n"); + "ReinitializeDevice: Sending Abort - could not decode.\n"); #endif goto RD_ABORT; } /* check the data from the request */ if (rd_data.state >= BACNET_REINIT_MAX) { - len = - reject_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, REJECT_REASON_UNDEFINED_ENUMERATION); + len = reject_encode_apdu(&Handler_Transmit_Buffer[pdu_len], + service_data->invoke_id, + REJECT_REASON_UNDEFINED_ENUMERATION); #if PRINT_ENABLED fprintf(stderr, - "ReinitializeDevice: Sending Reject - undefined enumeration\n"); + "ReinitializeDevice: Sending Reject - undefined enumeration\n"); #endif } else { #if BAC_ROUTING /* Check to see if the current Device supports this service. */ - len = - Routed_Device_Service_Approval - (SERVICE_CONFIRMED_REINITIALIZE_DEVICE, (int) rd_data.state, + len = Routed_Device_Service_Approval( + SERVICE_CONFIRMED_REINITIALIZE_DEVICE, (int)rd_data.state, &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id); if (len > 0) goto RD_ABORT; #endif if (Device_Reinitialize(&rd_data)) { - len = - encode_simple_ack(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, - SERVICE_CONFIRMED_REINITIALIZE_DEVICE); + len = encode_simple_ack(&Handler_Transmit_Buffer[pdu_len], + service_data->invoke_id, + SERVICE_CONFIRMED_REINITIALIZE_DEVICE); #if PRINT_ENABLED fprintf(stderr, "ReinitializeDevice: Sending Simple Ack!\n"); #endif } else { - len = - bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, SERVICE_CONFIRMED_REINITIALIZE_DEVICE, - rd_data.error_class, rd_data.error_code); + len = bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], + 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"); #endif } } - RD_ABORT: +RD_ABORT: pdu_len += len; - len = - datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], - pdu_len); + len = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], + pdu_len); if (len <= 0) { #if PRINT_ENABLED fprintf(stderr, "ReinitializeDevice: Failed to send PDU (%s)!\n", - strerror(errno)); + strerror(errno)); #endif } diff --git a/demo/handler/h_routed_npdu.c b/demo/handler/h_routed_npdu.c index ff3bd267..f3e25d69 100644 --- a/demo/handler/h_routed_npdu.c +++ b/demo/handler/h_routed_npdu.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2010 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2010 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* Acknowledging the contribution of code and ideas used here that * came from Paul Chapman's vmac demo project. */ @@ -47,10 +47,8 @@ #include "bvlc.h" #endif - -/** @file h_routed_npdu.c Handles messages at the NPDU level of the BACnet stack, - * including routing and network control messages. */ - +/** @file h_routed_npdu.c Handles messages at the NPDU level of the BACnet + * stack, including routing and network control messages. */ /** Handler to manage the Network Layer Control Messages received in a packet. * This handler is called if the NCPI bit 7 indicates that this packet is a @@ -61,20 +59,18 @@ * @param src [in] The routing source information, if any. * If src->net and src->len are 0, there is no * routing source information. - * @param DNET_list [in] List of our reachable downstream BACnet Network numbers. - * Normally just one valid entry; terminated with a -1 value. + * @param DNET_list [in] List of our reachable downstream BACnet Network + * numbers. Normally just one valid entry; terminated with a -1 value. * @param npdu_data [in] Contains a filled-out structure with information - * decoded from the NCPI and other NPDU bytes. + * decoded from the NCPI and other NPDU + * bytes. * @param npdu [in] Buffer containing the rest of the NPDU, following the * bytes that have already been decoded. * @param npdu_len [in] The length of the remaining NPDU message in npdu[]. */ -static void network_control_handler( - BACNET_ADDRESS * src, - int *DNET_list, - BACNET_NPDU_DATA * npdu_data, - uint8_t * npdu, - uint16_t npdu_len) +static void network_control_handler(BACNET_ADDRESS *src, int *DNET_list, + BACNET_NPDU_DATA *npdu_data, uint8_t *npdu, + uint16_t npdu_len) { uint16_t npdu_offset = 0; uint16_t dnet = 0; @@ -109,8 +105,8 @@ static void network_control_handler( * later for congestion control - then it could matter. */ debug_printf("%s for Networks: ", - bactext_network_layer_msg_name - (NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK)); + bactext_network_layer_msg_name( + NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK)); while (npdu_len >= 2) { len = decode_unsigned16(&npdu[npdu_offset], &dnet); debug_printf("%hu", dnet); @@ -129,8 +125,8 @@ static void network_control_handler( if (npdu_len >= 3) { decode_unsigned16(&npdu[1], &dnet); debug_printf("Received %s for Network: ", - bactext_network_layer_msg_name - (NETWORK_MESSAGE_I_COULD_BE_ROUTER_TO_NETWORK)); + bactext_network_layer_msg_name( + NETWORK_MESSAGE_I_COULD_BE_ROUTER_TO_NETWORK)); debug_printf("%hu, Reason code: %d \n", dnet, npdu[0]); } break; @@ -168,8 +164,8 @@ static void network_control_handler( break; default: /* An unrecognized message is bad; send an error response. */ - Send_Reject_Message_To_Network(src, - NETWORK_REJECT_UNKNOWN_MESSAGE_TYPE, DNET_list[0]); + Send_Reject_Message_To_Network( + src, NETWORK_REJECT_UNKNOWN_MESSAGE_TYPE, DNET_list[0]); /* Sending our DNET doesn't make a lot of sense, does it? */ break; } @@ -186,19 +182,16 @@ static void network_control_handler( * * @param src [in] The BACNET_ADDRESS of the message's source. * @param dest [in] The BACNET_ADDRESS of the message's destination. - * @param DNET_list [in] List of our reachable downstream BACnet Network numbers. - * Normally just one valid entry; terminated with a -1 value. + * @param DNET_list [in] List of our reachable downstream BACnet Network + * numbers. Normally just one valid entry; terminated with a -1 value. * @param apdu [in] The apdu portion of the request, to be processed. * @param apdu_len [in] The total (remaining) length of the apdu. */ -static void routed_apdu_handler( - BACNET_ADDRESS * src, - BACNET_ADDRESS * dest, - int *DNET_list, - uint8_t * apdu, - uint16_t apdu_len) +static void routed_apdu_handler(BACNET_ADDRESS *src, BACNET_ADDRESS *dest, + int *DNET_list, uint8_t *apdu, + uint16_t apdu_len) { - int cursor = 0; /* Starting hint */ + int cursor = 0; /* Starting hint */ bool bGotOne = false; if (!Routed_Device_Is_Valid_Network(dest->net, DNET_list)) { @@ -220,8 +213,8 @@ static void routed_apdu_handler( */ if (dest->len > 0) { Send_Reject_Message_To_Network(src, NETWORK_REJECT_NO_ROUTE, - dest->net); - } /* else, silently drop it */ + dest->net); + } /* else, silently drop it */ return; } @@ -260,20 +253,17 @@ static void routed_apdu_handler( * think this project's code has any use for the src info * on return from this handler, since the response has * already been sent via the apdu_handler. - * @param DNET_list [in] List of our reachable downstream BACnet Network numbers. - * Normally just one valid entry; terminated with a -1 value. + * @param DNET_list [in] List of our reachable downstream BACnet Network + * numbers. Normally just one valid entry; terminated with a -1 value. * @param pdu [in] Buffer containing the NPDU and APDU of the received packet. * @param pdu_len [in] The size of the received message in the pdu[] buffer. */ -void routing_npdu_handler( - BACNET_ADDRESS * src, - int *DNET_list, - uint8_t * pdu, - uint16_t pdu_len) +void routing_npdu_handler(BACNET_ADDRESS *src, int *DNET_list, uint8_t *pdu, + uint16_t pdu_len) { int apdu_offset = 0; - BACNET_ADDRESS dest = { 0 }; - BACNET_NPDU_DATA npdu_data = { 0 }; + BACNET_ADDRESS dest = {0}; + BACNET_NPDU_DATA npdu_data = {0}; /* only handle the version that we know how to handle */ if (pdu[0] == BACNET_PROTOCOL_VERSION) { @@ -283,7 +273,8 @@ void routing_npdu_handler( } else if (npdu_data.network_layer_message) { if ((dest.net == 0) || (dest.net == BACNET_BROADCAST_NETWORK)) { network_control_handler(src, DNET_list, &npdu_data, - &pdu[apdu_offset], (uint16_t) (pdu_len - apdu_offset)); + &pdu[apdu_offset], + (uint16_t)(pdu_len - apdu_offset)); } else { /* The DNET is set, but we don't support downstream routers, * so we just silently drop this network layer message, @@ -292,14 +283,14 @@ void routing_npdu_handler( } else if (apdu_offset <= pdu_len) { if ((dest.net == 0) || (npdu_data.hop_count > 1)) routed_apdu_handler(src, &dest, DNET_list, &pdu[apdu_offset], - (uint16_t) (pdu_len - apdu_offset)); + (uint16_t)(pdu_len - apdu_offset)); /* Else, hop_count bottomed out and we discard this one. */ } } else { /* Should we send NETWORK_MESSAGE_REJECT_MESSAGE_TO_NETWORK? */ - debug_printf - ("NPDU: Unsupported BACnet Protocol Version=%u. Discarded!\n", - (unsigned) pdu[0]); + debug_printf( + "NPDU: Unsupported BACnet Protocol Version=%u. Discarded!\n", + (unsigned)pdu[0]); } return; diff --git a/demo/handler/h_rp.c b/demo/handler/h_rp.c index d1d27316..0a4ce0b4 100644 --- a/demo/handler/h_rp.c +++ b/demo/handler/h_rp.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2005 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2005 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -44,7 +44,6 @@ /** @file h_rp.c Handles Read Property requests. */ - /** Handler for a ReadProperty Service request. * @ingroup DSRP * This handler will be invoked by apdu_handler() if it has been enabled @@ -64,11 +63,9 @@ * @param service_data [in] The BACNET_CONFIRMED_SERVICE_DATA information * decoded from the APDU header of this message. */ -void handler_read_property( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src, - BACNET_CONFIRMED_SERVICE_DATA * service_data) +void handler_read_property(uint8_t* service_request, uint16_t service_len, + BACNET_ADDRESS* src, + BACNET_CONFIRMED_SERVICE_DATA* service_data) { BACNET_READ_PROPERTY_DATA rpdata; int len = 0; @@ -76,7 +73,7 @@ void handler_read_property( int apdu_len = -1; int npdu_len = -1; BACNET_NPDU_DATA npdu_data; - bool error = true; /* assume that there is an error */ + bool error = true; /* assume that there is an error */ int bytes_sent = 0; BACNET_ADDRESS my_address; @@ -85,9 +82,8 @@ void handler_read_property( /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); - npdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address, - &npdu_data); + npdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address, + &npdu_data); if (service_data->segmented_message) { /* we don't support segmentation - send an abort */ len = BACNET_STATUS_ABORT; @@ -116,9 +112,8 @@ void handler_read_property( rpdata.object_instance = Device_Object_Instance_Number(); } - 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 = @@ -126,9 +121,8 @@ void handler_read_property( 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 @@ -160,28 +154,26 @@ void handler_read_property( #endif } - RP_FAILURE: +RP_FAILURE: if (error) { if (len == BACNET_STATUS_ABORT) { - apdu_len = - abort_encode_apdu(&Handler_Transmit_Buffer[npdu_len], - service_data->invoke_id, + apdu_len = abort_encode_apdu( + &Handler_Transmit_Buffer[npdu_len], service_data->invoke_id, abort_convert_error_code(rpdata.error_code), true); #if PRINT_ENABLED fprintf(stderr, "RP: Sending Abort!\n"); #endif } else if (len == BACNET_STATUS_ERROR) { - apdu_len = - bacerror_encode_apdu(&Handler_Transmit_Buffer[npdu_len], - service_data->invoke_id, SERVICE_CONFIRMED_READ_PROPERTY, - rpdata.error_class, rpdata.error_code); + apdu_len = bacerror_encode_apdu( + &Handler_Transmit_Buffer[npdu_len], service_data->invoke_id, + SERVICE_CONFIRMED_READ_PROPERTY, rpdata.error_class, + rpdata.error_code); #if PRINT_ENABLED fprintf(stderr, "RP: Sending Error!\n"); #endif } else if (len == BACNET_STATUS_REJECT) { - apdu_len = - reject_encode_apdu(&Handler_Transmit_Buffer[npdu_len], - service_data->invoke_id, + apdu_len = reject_encode_apdu( + &Handler_Transmit_Buffer[npdu_len], service_data->invoke_id, reject_convert_error_code(rpdata.error_code)); #if PRINT_ENABLED fprintf(stderr, "RP: Sending Reject!\n"); @@ -190,9 +182,8 @@ void handler_read_property( } pdu_len = npdu_len + apdu_len; - bytes_sent = - datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], - pdu_len); + bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], + pdu_len); if (bytes_sent <= 0) { #if PRINT_ENABLED fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno)); diff --git a/demo/handler/h_rp_a.c b/demo/handler/h_rp_a.c index ee41a133..44dc7050 100644 --- a/demo/handler/h_rp_a.c +++ b/demo/handler/h_rp_a.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2005 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2005 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -46,11 +46,10 @@ /** For debugging... * @param [in] data portion of the ACK */ -void rp_ack_print_data( - BACNET_READ_PROPERTY_DATA * data) +void rp_ack_print_data(BACNET_READ_PROPERTY_DATA *data) { - BACNET_OBJECT_PROPERTY_VALUE object_value; /* for bacapp printing */ - BACNET_APPLICATION_DATA_VALUE value; /* for decode value data */ + BACNET_OBJECT_PROPERTY_VALUE object_value; /* for bacapp printing */ + BACNET_APPLICATION_DATA_VALUE value; /* for decode value data */ int len = 0; uint8_t *application_data; int application_data_len; @@ -63,9 +62,8 @@ void rp_ack_print_data( /* FIXME: what if application_data_len is bigger than 255? */ /* value? need to loop until all of the len is gone... */ for (;;) { - len = - bacapp_decode_application_data(application_data, - (uint8_t) application_data_len, &value); + len = bacapp_decode_application_data( + application_data, (uint8_t)application_data_len, &value); if (first_value && (len < application_data_len)) { first_value = false; #if PRINT_ENABLED @@ -102,7 +100,6 @@ void rp_ack_print_data( } } - /** Handler for a ReadProperty ACK. * @ingroup DSRP * Doesn't actually do anything, except, for debugging, to @@ -114,17 +111,15 @@ void rp_ack_print_data( * @param service_data [in] The BACNET_CONFIRMED_SERVICE_DATA information * decoded from the APDU header of this message. */ -void handler_read_property_ack( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src, - BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data) +void handler_read_property_ack(uint8_t *service_request, uint16_t service_len, + BACNET_ADDRESS *src, + BACNET_CONFIRMED_SERVICE_ACK_DATA *service_data) { int len = 0; BACNET_READ_PROPERTY_DATA data; - (void) src; - (void) service_data; /* we could use these... */ + (void)src; + (void)service_data; /* we could use these... */ len = rp_ack_decode_service_request(service_request, service_len, &data); #if 0 fprintf(stderr, "Received Read-Property Ack!\n"); @@ -148,13 +143,11 @@ void handler_read_property_ack( * or -1 on decoding error. */ int rp_ack_fully_decode_service_request( - uint8_t * apdu, - int apdu_len, - BACNET_READ_ACCESS_DATA * read_access_data) + uint8_t *apdu, int apdu_len, BACNET_READ_ACCESS_DATA *read_access_data) { - int decoded_len = 0; /* return value */ + 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; int vlen, len; @@ -174,7 +167,8 @@ int rp_ack_fully_decode_service_request( } 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? */ + /* Is there no Error case possible here, as there is when decoding RPM? + */ /* rp1_property->error.error_class = ?? */ /* rp_ack_decode_service_request() processing already removed the * Opening and Closing '3' Tags. @@ -187,9 +181,8 @@ int rp_ack_fully_decode_service_request( old_value = value; while (value && vdata && (vlen > 0)) { if (IS_CONTEXT_SPECIFIC(*vdata)) { - len = - bacapp_decode_context_data(vdata, vlen, value, - rp1_property->propertyIdentifier); + len = bacapp_decode_context_data( + vdata, vlen, value, rp1_property->propertyIdentifier); } else { len = bacapp_decode_application_data(vdata, vlen, value); } diff --git a/demo/handler/h_rpm.c b/demo/handler/h_rpm.c index b35f1ac2..249a681e 100644 --- a/demo/handler/h_rpm.c +++ b/demo/handler/h_rpm.c @@ -1,28 +1,28 @@ /************************************************************************** -* -* Copyright (C) 2007 Steve Karg -* Inspired by John Stachler -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2007 Steve Karg + * Inspired by John Stachler + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include @@ -46,14 +46,13 @@ /** @file h_rpm.c Handles Read Property Multiple requests. */ -static uint8_t Temp_Buf[MAX_APDU] = { 0 }; +static uint8_t Temp_Buf[MAX_APDU] = {0}; static BACNET_PROPERTY_ID RPM_Object_Property( struct special_property_list_t *pPropertyList, - BACNET_PROPERTY_ID special_property, - unsigned index) + BACNET_PROPERTY_ID special_property, unsigned index) { - int property = -1; /* return value */ + int property = -1; /* return value */ unsigned required, optional, proprietary; required = pPropertyList->Required.count; @@ -79,7 +78,7 @@ static BACNET_PROPERTY_ID RPM_Object_Property( } } - return (BACNET_PROPERTY_ID) property; + return (BACNET_PROPERTY_ID)property; } static unsigned RPM_Object_Property_Count( @@ -89,9 +88,8 @@ static unsigned RPM_Object_Property_Count( unsigned count = 0; /* return value */ if (special_property == PROP_ALL) { - count = - pPropertyList->Required.count + pPropertyList->Optional.count + - pPropertyList->Proprietary.count; + count = pPropertyList->Required.count + pPropertyList->Optional.count + + pPropertyList->Proprietary.count; } else if (special_property == PROP_REQUIRED) { count = pPropertyList->Required.count; } else if (special_property == PROP_OPTIONAL) { @@ -103,20 +101,16 @@ static unsigned RPM_Object_Property_Count( /** Encode the RPM property returning the length of the encoding, or 0 if there is no room to fit the encoding. */ -static int RPM_Encode_Property( - uint8_t * apdu, - uint16_t offset, - uint16_t max_apdu, - BACNET_RPM_DATA * rpmdata) +static int RPM_Encode_Property(uint8_t *apdu, uint16_t offset, + uint16_t max_apdu, BACNET_RPM_DATA *rpmdata) { int len = 0; size_t copy_len = 0; int apdu_len = 0; BACNET_READ_PROPERTY_DATA rpdata; - len = - rpm_ack_encode_apdu_object_property(&Temp_Buf[0], - rpmdata->object_property, rpmdata->array_index); + len = rpm_ack_encode_apdu_object_property( + &Temp_Buf[0], rpmdata->object_property, rpmdata->array_index); copy_len = memcopy(&apdu[0], &Temp_Buf[0], offset, len, max_apdu); if (copy_len == 0) { rpmdata->error_code = ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED; @@ -140,9 +134,8 @@ static int RPM_Encode_Property( return len; /* Ie, Abort */ } /* error was returned - encode that for the response */ - len = - rpm_ack_encode_apdu_object_property_error(&Temp_Buf[0], - rpdata.error_class, rpdata.error_code); + len = rpm_ack_encode_apdu_object_property_error( + &Temp_Buf[0], rpdata.error_class, rpdata.error_code); copy_len = memcopy(&apdu[0], &Temp_Buf[0], offset + apdu_len, len, max_apdu); @@ -152,9 +145,8 @@ static int RPM_Encode_Property( } } else if ((offset + apdu_len + 1 + len + 1) < max_apdu) { /* enough room to fit the property value and tags */ - len = - rpm_ack_encode_apdu_object_property_value(&apdu[offset + apdu_len], - &Temp_Buf[0], len); + len = rpm_ack_encode_apdu_object_property_value( + &apdu[offset + apdu_len], &Temp_Buf[0], len); } else { /* not enough room - abort! */ rpmdata->error_code = ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED; @@ -175,8 +167,8 @@ static int RPM_Encode_Property( * - if decoding fails * - if the response would be too large * - the result from each included read request, if it succeeds - * - an Error if processing fails for all, or individual errors if only some fail, - * or there isn't enough room in the APDU to fit the data. + * - an Error if processing fails for all, or individual errors if only some + * fail, or there isn't enough room in the APDU to fit the data. * * @param service_request [in] The contents of the service request. * @param service_len [in] The length of the service_request. @@ -184,11 +176,9 @@ static int RPM_Encode_Property( * @param service_data [in] The BACNET_CONFIRMED_SERVICE_DATA information * decoded from the APDU header of this message. */ -void handler_read_property_multiple( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src, - BACNET_CONFIRMED_SERVICE_DATA * service_data) +void handler_read_property_multiple(uint8_t *service_request, + uint16_t service_len, BACNET_ADDRESS *src, + BACNET_CONFIRMED_SERVICE_DATA *service_data) { int len = 0; uint16_t copy_len = 0; @@ -203,13 +193,13 @@ void handler_read_property_multiple( int error = 0; /* jps_debug - see if we are utilizing all the buffer */ - /* memset(&Handler_Transmit_Buffer[0], 0xff, sizeof(Handler_Transmit_Buffer)); */ + /* memset(&Handler_Transmit_Buffer[0], 0xff, + * sizeof(Handler_Transmit_Buffer)); */ /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); - npdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address, - &npdu_data); + npdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address, + &npdu_data); if (service_data->segmented_message) { rpmdata.error_code = ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED; error = BACNET_STATUS_ABORT; @@ -220,14 +210,12 @@ void handler_read_property_multiple( } /* decode apdu request & encode apdu reply encode complex ack, invoke id, service choice */ - apdu_len = - rpm_ack_encode_apdu_init(&Handler_Transmit_Buffer[npdu_len], - service_data->invoke_id); + apdu_len = rpm_ack_encode_apdu_init(&Handler_Transmit_Buffer[npdu_len], + service_data->invoke_id); for (;;) { /* Start by looking for an object ID */ - len = - rpm_decode_object_id(&service_request[decode_len], - service_len - decode_len, &rpmdata); + len = rpm_decode_object_id(&service_request[decode_len], + service_len - decode_len, &rpmdata); if (len >= 0) { /* Got one so skip to next stage */ decode_len += len; @@ -248,9 +236,8 @@ void handler_read_property_multiple( /* Stick this object id into the reply - if it will fit */ len = rpm_ack_encode_apdu_object_begin(&Temp_Buf[0], &rpmdata); - copy_len = - memcopy(&Handler_Transmit_Buffer[npdu_len], &Temp_Buf[0], apdu_len, - len, MAX_APDU); + copy_len = memcopy(&Handler_Transmit_Buffer[npdu_len], &Temp_Buf[0], + apdu_len, len, MAX_APDU); if (copy_len == 0) { #if PRINT_ENABLED fprintf(stderr, "RPM: Response too big!\r\n"); @@ -266,7 +253,7 @@ void handler_read_property_multiple( /* Fetch a property */ len = rpm_decode_object_property(&service_request[decode_len], - service_len - decode_len, &rpmdata); + service_len - decode_len, &rpmdata); if (len < 0) { /* bad encoding - skip to error/reject/abort handling */ #if PRINT_ENABLED @@ -288,16 +275,15 @@ void handler_read_property_multiple( if (rpmdata.array_index != BACNET_ARRAY_ALL) { /* No array index options for this special property. Encode error for this object property response */ - len = - rpm_ack_encode_apdu_object_property(&Temp_Buf[0], - rpmdata.object_property, rpmdata.array_index); - copy_len = - memcopy(&Handler_Transmit_Buffer[npdu_len], - &Temp_Buf[0], apdu_len, len, MAX_APDU); + len = rpm_ack_encode_apdu_object_property( + &Temp_Buf[0], rpmdata.object_property, + rpmdata.array_index); + copy_len = memcopy(&Handler_Transmit_Buffer[npdu_len], + &Temp_Buf[0], apdu_len, len, MAX_APDU); if (copy_len == 0) { #if PRINT_ENABLED fprintf(stderr, - "RPM: Too full to encode property!\r\n"); + "RPM: Too full to encode property!\r\n"); #endif rpmdata.error_code = ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED; @@ -305,13 +291,11 @@ void handler_read_property_multiple( goto RPM_FAILURE; } apdu_len += len; - len = - rpm_ack_encode_apdu_object_property_error(&Temp_Buf[0], - ERROR_CLASS_PROPERTY, + len = rpm_ack_encode_apdu_object_property_error( + &Temp_Buf[0], ERROR_CLASS_PROPERTY, ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY); - copy_len = - memcopy(&Handler_Transmit_Buffer[npdu_len], - &Temp_Buf[0], apdu_len, len, MAX_APDU); + copy_len = memcopy(&Handler_Transmit_Buffer[npdu_len], + &Temp_Buf[0], apdu_len, len, MAX_APDU); if (copy_len == 0) { #if PRINT_ENABLED fprintf(stderr, "RPM: Too full to encode error!\r\n"); @@ -325,10 +309,10 @@ void handler_read_property_multiple( } else { special_object_property = rpmdata.object_property; Device_Objects_Property_List(rpmdata.object_type, - rpmdata.object_instance, &property_list); - property_count = - RPM_Object_Property_Count(&property_list, - special_object_property); + rpmdata.object_instance, + &property_list); + property_count = RPM_Object_Property_Count( + &property_list, special_object_property); if (property_count == 0) { /* this only happens with the OPTIONAL property */ /* 135-2016bl-2. Clarify ReadPropertyMultiple @@ -338,19 +322,17 @@ void handler_read_property_multiple( for the specified property.*/ } else { for (index = 0; index < property_count; index++) { - rpmdata.object_property = - RPM_Object_Property(&property_list, - special_object_property, index); - len = - RPM_Encode_Property(&Handler_Transmit_Buffer - [npdu_len], (uint16_t) apdu_len, MAX_APDU, - &rpmdata); + rpmdata.object_property = RPM_Object_Property( + &property_list, special_object_property, index); + len = RPM_Encode_Property( + &Handler_Transmit_Buffer[npdu_len], + (uint16_t)apdu_len, MAX_APDU, &rpmdata); if (len > 0) { apdu_len += len; } else { #if PRINT_ENABLED fprintf(stderr, - "RPM: Too full for property!\r\n"); + "RPM: Too full for property!\r\n"); #endif error = len; goto RPM_FAILURE; @@ -362,13 +344,13 @@ void handler_read_property_multiple( /* handle an individual property */ len = RPM_Encode_Property(&Handler_Transmit_Buffer[npdu_len], - (uint16_t) apdu_len, MAX_APDU, &rpmdata); + (uint16_t)apdu_len, MAX_APDU, &rpmdata); if (len > 0) { apdu_len += len; } else { #if PRINT_ENABLED fprintf(stderr, - "RPM: Too full for individual property!\r\n"); + "RPM: Too full for individual property!\r\n"); #endif error = len; goto RPM_FAILURE; @@ -378,9 +360,8 @@ void handler_read_property_multiple( /* Reached end of property list so cap the result list */ decode_len++; len = rpm_ack_encode_apdu_object_end(&Temp_Buf[0]); - copy_len = - memcopy(&Handler_Transmit_Buffer[npdu_len], &Temp_Buf[0], - apdu_len, len, MAX_APDU); + copy_len = memcopy(&Handler_Transmit_Buffer[npdu_len], + &Temp_Buf[0], apdu_len, len, MAX_APDU); if (copy_len == 0) { #if PRINT_ENABLED fprintf(stderr, "RPM: Too full to encode object end!\r\n"); @@ -392,7 +373,7 @@ void handler_read_property_multiple( } else { apdu_len += copy_len; } - break; /* finished with this property list */ + break; /* finished with this property list */ } } if (decode_len >= service_len) { @@ -411,28 +392,26 @@ void handler_read_property_multiple( goto RPM_FAILURE; } - RPM_FAILURE: +RPM_FAILURE: if (error) { if (error == BACNET_STATUS_ABORT) { - apdu_len = - abort_encode_apdu(&Handler_Transmit_Buffer[npdu_len], - service_data->invoke_id, + apdu_len = abort_encode_apdu( + &Handler_Transmit_Buffer[npdu_len], service_data->invoke_id, abort_convert_error_code(rpmdata.error_code), true); #if PRINT_ENABLED fprintf(stderr, "RPM: Sending Abort!\n"); #endif } else if (error == BACNET_STATUS_ERROR) { - apdu_len = - bacerror_encode_apdu(&Handler_Transmit_Buffer[npdu_len], - service_data->invoke_id, SERVICE_CONFIRMED_READ_PROP_MULTIPLE, - rpmdata.error_class, rpmdata.error_code); + apdu_len = bacerror_encode_apdu( + &Handler_Transmit_Buffer[npdu_len], service_data->invoke_id, + SERVICE_CONFIRMED_READ_PROP_MULTIPLE, rpmdata.error_class, + rpmdata.error_code); #if PRINT_ENABLED fprintf(stderr, "RPM: Sending Error!\n"); #endif } else if (error == BACNET_STATUS_REJECT) { - apdu_len = - reject_encode_apdu(&Handler_Transmit_Buffer[npdu_len], - service_data->invoke_id, + apdu_len = reject_encode_apdu( + &Handler_Transmit_Buffer[npdu_len], service_data->invoke_id, reject_convert_error_code(rpmdata.error_code)); #if PRINT_ENABLED fprintf(stderr, "RPM: Sending Reject!\n"); @@ -441,9 +420,8 @@ void handler_read_property_multiple( } pdu_len = apdu_len + npdu_len; - bytes_sent = - datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], - pdu_len); + bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], + pdu_len); if (bytes_sent <= 0) { #if PRINT_ENABLED fprintf(stderr, "RPM: Failed to send PDU (%s)!\n", strerror(errno)); diff --git a/demo/handler/h_rpm_a.c b/demo/handler/h_rpm_a.c index 0669c966..36709d9a 100644 --- a/demo/handler/h_rpm_a.c +++ b/demo/handler/h_rpm_a.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2008 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2008 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -53,16 +53,14 @@ * where the RPM data is to be stored. * @return The number of bytes decoded, or -1 on error */ -int rpm_ack_decode_service_request( - uint8_t * apdu, - int apdu_len, - BACNET_READ_ACCESS_DATA * read_access_data) +int rpm_ack_decode_service_request(uint8_t *apdu, int apdu_len, + BACNET_READ_ACCESS_DATA *read_access_data) { - int decoded_len = 0; /* return value */ - uint32_t error_value = 0; /* decoded error value */ - int len = 0; /* number of bytes returned from decoding */ - uint8_t tag_number = 0; /* decoded tag number */ - uint32_t len_value = 0; /* decoded length value */ + int decoded_len = 0; /* return value */ + uint32_t error_value = 0; /* decoded error value */ + int len = 0; /* number of bytes returned from decoding */ + uint8_t tag_number = 0; /* decoded tag number */ + uint32_t len_value = 0; /* decoded length value */ BACNET_READ_ACCESS_DATA *rpm_object; BACNET_READ_ACCESS_DATA *old_rpm_object; BACNET_PROPERTY_REFERENCE *rpm_property; @@ -74,9 +72,8 @@ int rpm_ack_decode_service_request( rpm_object = read_access_data; old_rpm_object = rpm_object; while (rpm_object && apdu_len) { - len = - rpm_ack_decode_object_id(apdu, apdu_len, &rpm_object->object_type, - &rpm_object->object_instance); + len = rpm_ack_decode_object_id(apdu, apdu_len, &rpm_object->object_type, + &rpm_object->object_instance); if (len <= 0) { old_rpm_object->next = NULL; free(rpm_object); @@ -89,9 +86,8 @@ int rpm_ack_decode_service_request( rpm_object->listOfProperties = rpm_property; old_rpm_property = rpm_property; while (rpm_property && apdu_len) { - len = - rpm_ack_decode_object_property(apdu, apdu_len, - &rpm_property->propertyIdentifier, + len = rpm_ack_decode_object_property( + apdu, apdu_len, &rpm_property->propertyIdentifier, &rpm_property->propertyArrayIndex); if (len <= 0) { old_rpm_property->next = NULL; @@ -117,13 +113,12 @@ int rpm_ack_decode_service_request( old_value = value; while (value && (apdu_len > 0)) { if (IS_CONTEXT_SPECIFIC(*apdu)) { - len = - bacapp_decode_context_data(apdu, apdu_len, value, + len = bacapp_decode_context_data( + apdu, apdu_len, value, rpm_property->propertyIdentifier); } else { - len = - bacapp_decode_application_data(apdu, apdu_len, - value); + len = bacapp_decode_application_data(apdu, apdu_len, + value); } /* If len == 0 then it's an empty structure, which is OK. */ if (len < 0) { @@ -201,10 +196,9 @@ int rpm_ack_decode_service_request( } /* for debugging... */ -void rpm_ack_print_data( - BACNET_READ_ACCESS_DATA * rpm_data) +void rpm_ack_print_data(BACNET_READ_ACCESS_DATA *rpm_data) { - BACNET_OBJECT_PROPERTY_VALUE object_value; /* for bacapp printing */ + BACNET_OBJECT_PROPERTY_VALUE object_value; /* for bacapp printing */ BACNET_PROPERTY_REFERENCE *listOfProperties; BACNET_APPLICATION_DATA_VALUE *value; bool array_value = false; @@ -212,8 +206,8 @@ void rpm_ack_print_data( if (rpm_data) { #if PRINT_ENABLED fprintf(stdout, "%s #%lu\r\n", - bactext_object_type_name(rpm_data->object_type), - (unsigned long) rpm_data->object_instance); + bactext_object_type_name(rpm_data->object_type), + (unsigned long)rpm_data->object_instance); fprintf(stdout, "{\r\n"); #endif listOfProperties = rpm_data->listOfProperties; @@ -221,11 +215,11 @@ void rpm_ack_print_data( #if PRINT_ENABLED if (listOfProperties->propertyIdentifier < 512) { fprintf(stdout, " %s: ", - bactext_property_name(listOfProperties-> - propertyIdentifier)); + bactext_property_name( + listOfProperties->propertyIdentifier)); } else { fprintf(stdout, " proprietary %u: ", - (unsigned) listOfProperties->propertyIdentifier); + (unsigned)listOfProperties->propertyIdentifier); } #endif if (listOfProperties->propertyArrayIndex != BACNET_ARRAY_ALL) { @@ -269,10 +263,10 @@ void rpm_ack_print_data( #if PRINT_ENABLED /* AccessError */ fprintf(stdout, "BACnet Error: %s: %s\r\n", - bactext_error_class_name((int) listOfProperties-> - error.error_class), - bactext_error_code_name((int) listOfProperties-> - error.error_code)); + bactext_error_class_name( + (int)listOfProperties->error.error_class), + bactext_error_code_name( + (int)listOfProperties->error.error_code)); #endif } listOfProperties = listOfProperties->next; @@ -295,10 +289,8 @@ void rpm_ack_print_data( * decoded from the APDU header of this message. */ void handler_read_property_multiple_ack( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src, - BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data) + uint8_t *service_request, uint16_t service_len, BACNET_ADDRESS *src, + BACNET_CONFIRMED_SERVICE_ACK_DATA *service_data) { int len = 0; BACNET_READ_ACCESS_DATA *rpm_data; @@ -308,14 +300,13 @@ void handler_read_property_multiple_ack( BACNET_APPLICATION_DATA_VALUE *value; BACNET_APPLICATION_DATA_VALUE *old_value; - (void) src; - (void) service_data; /* we could use these... */ + (void)src; + (void)service_data; /* we could use these... */ rpm_data = calloc(1, sizeof(BACNET_READ_ACCESS_DATA)); if (rpm_data) { - len = - rpm_ack_decode_service_request(service_request, service_len, - rpm_data); + len = rpm_ack_decode_service_request(service_request, service_len, + rpm_data); } #if 1 fprintf(stderr, "Received Read-Property-Multiple Ack!\n"); diff --git a/demo/handler/h_rr.c b/demo/handler/h_rr.c index 45d01311..34eae446 100644 --- a/demo/handler/h_rr.c +++ b/demo/handler/h_rr.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2009 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2009 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -41,13 +41,11 @@ /** @file h_rr.c Handles Read Range requests. */ -static uint8_t Temp_Buf[MAX_APDU] = { 0 }; +static uint8_t Temp_Buf[MAX_APDU] = {0}; /* Encodes the property APDU and returns the length, or sets the error, and returns -1 */ -static int Encode_RR_payload( - uint8_t * apdu, - BACNET_READ_RANGE_DATA * pRequest) +static int Encode_RR_payload(uint8_t* apdu, BACNET_READ_RANGE_DATA* pRequest) { int apdu_len = -1; rr_info_function info_fn_ptr = NULL; @@ -61,37 +59,48 @@ static int Encode_RR_payload( 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 */ + /* 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... */ + 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)) { + (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)) { - /* 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... */ + ((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) { 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 */ + /* 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; } return apdu_len; } -void handler_read_range( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src, - BACNET_CONFIRMED_SERVICE_DATA * service_data) +void handler_read_range(uint8_t* service_request, uint16_t service_len, + BACNET_ADDRESS* src, + BACNET_CONFIRMED_SERVICE_DATA* service_data) { BACNET_READ_RANGE_DATA data; int len = 0; @@ -106,21 +115,19 @@ void handler_read_range( /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); - pdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address, - &npdu_data); + pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address, + &npdu_data); if (service_data->segmented_message) { /* we don't support segmentation - send an abort */ - len = - abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, - true); + len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], + service_data->invoke_id, + ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); #if PRINT_ENABLED fprintf(stderr, "RR: Segmented message. Sending Abort!\n"); #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) @@ -128,9 +135,9 @@ void handler_read_range( #endif if (len < 0) { /* bad decoding - send an abort */ - len = - abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, ABORT_REASON_OTHER, true); + len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], + service_data->invoke_id, ABORT_REASON_OTHER, + true); #if PRINT_ENABLED fprintf(stderr, "RR: Bad Encoding. Sending Abort!\n"); #endif @@ -145,9 +152,8 @@ void handler_read_range( data.application_data = &Temp_Buf[0]; data.application_data_len = len; /* FIXME: probably need a length limitation sent with encode */ - len = - rr_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, &data); + len = rr_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len], + service_data->invoke_id, &data); #if PRINT_ENABLED fprintf(stderr, "RR: Sending Ack!\n"); #endif @@ -156,28 +162,26 @@ void handler_read_range( if (error) { if (len == -2) { /* BACnet APDU too small to fit data, so proper response is Abort */ - len = - abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, + len = abort_encode_apdu( + &Handler_Transmit_Buffer[pdu_len], service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); #if PRINT_ENABLED fprintf(stderr, "RR: Reply too big to fit into APDU!\n"); #endif } else { - len = - bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, SERVICE_CONFIRMED_READ_RANGE, - data.error_class, data.error_code); + len = bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], + service_data->invoke_id, + SERVICE_CONFIRMED_READ_RANGE, + data.error_class, data.error_code); #if PRINT_ENABLED fprintf(stderr, "RR: Sending Error!\n"); #endif } } - RR_ABORT: +RR_ABORT: pdu_len += len; - bytes_sent = - datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], - pdu_len); + bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], + pdu_len); #if PRINT_ENABLED if (bytes_sent <= 0) fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno)); diff --git a/demo/handler/h_rr_a.c b/demo/handler/h_rr_a.c index 17ab4f84..6be06e23 100644 --- a/demo/handler/h_rr_a.c +++ b/demo/handler/h_rr_a.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2009 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2009 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include "config.h" @@ -43,11 +43,10 @@ /** @file h_rr_a.c Handles Read Range Acknowledgments. */ /* for debugging... */ -static void PrintReadRangeData( - BACNET_READ_RANGE_DATA * data) +static void PrintReadRangeData(BACNET_READ_RANGE_DATA *data) { - BACNET_OBJECT_PROPERTY_VALUE object_value; /* for bacapp printing */ - BACNET_APPLICATION_DATA_VALUE value; /* for decode value data */ + BACNET_OBJECT_PROPERTY_VALUE object_value; /* for bacapp printing */ + BACNET_APPLICATION_DATA_VALUE value; /* for decode value data */ int len = 0; uint8_t *application_data; int application_data_len; @@ -60,9 +59,8 @@ static void PrintReadRangeData( /* FIXME: what if application_data_len is bigger than 255? */ /* value? need to loop until all of the len is gone... */ for (;;) { - len = - bacapp_decode_application_data(application_data, - (uint8_t) application_data_len, &value); + len = bacapp_decode_application_data( + application_data, (uint8_t)application_data_len, &value); if (first_value && (len < application_data_len)) { first_value = false; #if PRINT_ENABLED @@ -99,17 +97,15 @@ static void PrintReadRangeData( } } -void handler_read_range_ack( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src, - BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data) +void handler_read_range_ack(uint8_t *service_request, uint16_t service_len, + BACNET_ADDRESS *src, + BACNET_CONFIRMED_SERVICE_ACK_DATA *service_data) { int len = 0; BACNET_READ_RANGE_DATA data; - (void) src; - (void) service_data; /* we could use these... */ + (void)src; + (void)service_data; /* we could use these... */ len = rr_ack_decode_service_request(service_request, service_len, &data); #if PRINT_ENABLED diff --git a/demo/handler/h_ts.c b/demo/handler/h_ts.c index 06ad77ed..47a8d023 100644 --- a/demo/handler/h_ts.c +++ b/demo/handler/h_ts.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2006 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2006 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -49,37 +49,32 @@ static BACNET_DATE_TIME Next_Sync_Time; #endif #if PRINT_ENABLED -static void show_bacnet_date_time( - BACNET_DATE * bdate, - BACNET_TIME * btime) +static void show_bacnet_date_time(BACNET_DATE *bdate, BACNET_TIME *btime) { /* show the date received */ - fprintf(stderr, "%u", (unsigned) bdate->year); - fprintf(stderr, "/%u", (unsigned) bdate->month); - fprintf(stderr, "/%u", (unsigned) bdate->day); + fprintf(stderr, "%u", (unsigned)bdate->year); + fprintf(stderr, "/%u", (unsigned)bdate->month); + fprintf(stderr, "/%u", (unsigned)bdate->day); /* show the time received */ - fprintf(stderr, " %02u", (unsigned) btime->hour); - fprintf(stderr, ":%02u", (unsigned) btime->min); - fprintf(stderr, ":%02u", (unsigned) btime->sec); - fprintf(stderr, ".%02u", (unsigned) btime->hundredths); + fprintf(stderr, " %02u", (unsigned)btime->hour); + fprintf(stderr, ":%02u", (unsigned)btime->min); + fprintf(stderr, ":%02u", (unsigned)btime->sec); + fprintf(stderr, ".%02u", (unsigned)btime->hundredths); fprintf(stderr, "\r\n"); } #endif -void handler_timesync( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src) +void handler_timesync(uint8_t *service_request, uint16_t service_len, + BACNET_ADDRESS *src) { int len = 0; BACNET_DATE bdate = {0}; BACNET_TIME btime = {0}; - (void) src; - (void) service_len; - len = - timesync_decode_service_request(service_request, service_len, &bdate, - &btime); + (void)src; + (void)service_len; + len = timesync_decode_service_request(service_request, service_len, &bdate, + &btime); if (len > 0) { if (datetime_is_valid(&bdate, &btime)) { /* fixme: only set the time if off by some amount */ @@ -96,20 +91,17 @@ void handler_timesync( return; } -void handler_timesync_utc( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src) +void handler_timesync_utc(uint8_t *service_request, uint16_t service_len, + BACNET_ADDRESS *src) { int len = 0; BACNET_DATE bdate; BACNET_TIME btime; - (void) src; - (void) service_len; - len = - timesync_decode_service_request(service_request, service_len, &bdate, - &btime); + (void)src; + (void)service_len; + len = timesync_decode_service_request(service_request, service_len, &bdate, + &btime); if (len > 0) { if (datetime_is_valid(&bdate, &btime)) { #if PRINT_ENABLED @@ -138,18 +130,15 @@ void handler_timesync_utc( * @return How many bytes were encoded in the buffer, or * BACNET_STATUS_ABORT if the response would not fit within the buffer. */ -int handler_timesync_encode_recipients( - uint8_t * apdu, - int max_apdu) +int handler_timesync_encode_recipients(uint8_t *apdu, int max_apdu) { return timesync_encode_timesync_recipients(apdu, max_apdu, - &Time_Sync_Recipients[0]); + &Time_Sync_Recipients[0]); } #endif #if defined(BACNET_TIME_MASTER) -bool handler_timesync_recipient_write( - BACNET_WRITE_PROPERTY_DATA * wp_data) +bool handler_timesync_recipient_write(BACNET_WRITE_PROPERTY_DATA *wp_data) { bool status = false; @@ -162,8 +151,7 @@ bool handler_timesync_recipient_write( #endif #if defined(BACNET_TIME_MASTER) -static void handler_timesync_send( - BACNET_DATE_TIME * current_date_time) +static void handler_timesync_send(BACNET_DATE_TIME *current_date_time) { unsigned index = 0; bool status = false; @@ -171,10 +159,9 @@ static void handler_timesync_send( for (index = 0; index < MAX_TIME_SYNC_RECIPIENTS; index++) { if (Time_Sync_Recipients[index].tag == 1) { if (status) { - Send_TimeSync_Remote( - &Time_Sync_Recipients[index].type.address, - ¤t_date_time->date, - ¤t_date_time->time); + Send_TimeSync_Remote(&Time_Sync_Recipients[index].type.address, + ¤t_date_time->date, + ¤t_date_time->time); } } } @@ -182,9 +169,8 @@ static void handler_timesync_send( #endif #if defined(BACNET_TIME_MASTER) -static void handler_timesync_update( - uint32_t device_interval, - BACNET_DATE_TIME * current_date_time) +static void handler_timesync_update(uint32_t device_interval, + BACNET_DATE_TIME *current_date_time) { uint32_t current_minutes = 0; uint32_t next_minutes = 0; @@ -207,7 +193,7 @@ static void handler_timesync_update( /* Interval_Minutes = 1 2 3 4 5 6 10 12 15 20 30 60 */ /* determine next interval */ current_minutes = Next_Sync_Time.time.min; - interval = current_minutes/device_interval; + interval = current_minutes / device_interval; interval++; next_minutes = interval * device_interval; offset_minutes = interval_offset % device_interval; @@ -223,7 +209,7 @@ static void handler_timesync_update( 144 160 180 240 288 360 480 720 1440 */ current_minutes = datetime_minutes_since_midnight(&Next_Sync_Time.time); - interval = current_minutes/device_interval; + interval = current_minutes / device_interval; interval++; next_minutes = interval * device_interval; offset_minutes = interval_offset % device_interval; @@ -242,17 +228,14 @@ static void handler_timesync_update( #endif #if defined(BACNET_TIME_MASTER) -bool handler_timesync_recipient_address_set( - unsigned index, - BACNET_ADDRESS *address) +bool handler_timesync_recipient_address_set(unsigned index, + BACNET_ADDRESS *address) { bool status = false; if (address && (index < MAX_TIME_SYNC_RECIPIENTS)) { Time_Sync_Recipients[index].tag = 1; - bacnet_address_copy( - &Time_Sync_Recipients[index].type.address, - address); + bacnet_address_copy(&Time_Sync_Recipients[index].type.address, address); status = true; } @@ -261,8 +244,7 @@ bool handler_timesync_recipient_address_set( #endif #if defined(BACNET_TIME_MASTER) -void handler_timesync_task( - BACNET_DATE_TIME * current_date_time) +void handler_timesync_task(BACNET_DATE_TIME *current_date_time) { int compare = 0; uint32_t device_interval = 0; @@ -270,9 +252,9 @@ void handler_timesync_task( device_interval = Device_Time_Sync_Interval(); if (device_interval) { compare = datetime_compare(current_date_time, &Next_Sync_Time); - /* if the date/times are the same, return is 0 - if date1 is before date2, returns negative - if date1 is after date2, returns positive */ + /* if the date/times are the same, return is 0 + if date1 is before date2, returns negative + if date1 is after date2, returns positive */ if (compare >= 0) { handler_timesync_update(device_interval, current_date_time); handler_timesync_send(current_date_time); @@ -287,9 +269,9 @@ void handler_timesync_init(void) unsigned i = 0; /* connect linked list */ - for (; i < (MAX_TIME_SYNC_RECIPIENTS-1); i++) { - Time_Sync_Recipients[i].next = &Time_Sync_Recipients[i+1]; - Time_Sync_Recipients[i+1].next = NULL; + for (; i < (MAX_TIME_SYNC_RECIPIENTS - 1); i++) { + Time_Sync_Recipients[i].next = &Time_Sync_Recipients[i + 1]; + Time_Sync_Recipients[i + 1].next = NULL; } for (i = 0; i < MAX_TIME_SYNC_RECIPIENTS; i++) { Time_Sync_Recipients[i].tag = 0xFF; diff --git a/demo/handler/h_ucov.c b/demo/handler/h_ucov.c index 9515f074..65841bd1 100644 --- a/demo/handler/h_ucov.c +++ b/demo/handler/h_ucov.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2008 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2008 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -57,10 +57,8 @@ * @param service_len [in] The length of the service_request. * @param src [in] BACNET_ADDRESS of the source of the message (unused) */ -void handler_ucov_notification( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src) +void handler_ucov_notification(uint8_t *service_request, uint16_t service_len, + BACNET_ADDRESS *src) { BACNET_COV_DATA cov_data; BACNET_PROPERTY_VALUE property_value[MAX_COV_PROPERTIES]; @@ -77,14 +75,14 @@ void handler_ucov_notification( fprintf(stderr, "UCOV: Received Notification!\n"); #endif /* decode the service request only */ - len = - cov_notify_decode_service_request(service_request, service_len, - &cov_data); + len = cov_notify_decode_service_request(service_request, service_len, + &cov_data); #if PRINT_ENABLED if (len > 0) { fprintf(stderr, "UCOV: PID=%u ", cov_data.subscriberProcessIdentifier); fprintf(stderr, "instance=%u ", cov_data.initiatingDeviceIdentifier); - fprintf(stderr, "%s %u ", + fprintf( + stderr, "%s %u ", bactext_object_type_name(cov_data.monitoredObjectIdentifier.type), cov_data.monitoredObjectIdentifier.instance); fprintf(stderr, "time remaining=%u seconds ", cov_data.timeRemaining); @@ -93,12 +91,12 @@ void handler_ucov_notification( while (pProperty_value) { fprintf(stderr, "UCOV: "); if (pProperty_value->propertyIdentifier < 512) { - fprintf(stderr, "%s ", - bactext_property_name - (pProperty_value->propertyIdentifier)); + fprintf( + stderr, "%s ", + bactext_property_name(pProperty_value->propertyIdentifier)); } else { fprintf(stderr, "proprietary %u ", - pProperty_value->propertyIdentifier); + pProperty_value->propertyIdentifier); } if (pProperty_value->propertyArrayIndex != BACNET_ARRAY_ALL) { fprintf(stderr, "%u ", pProperty_value->propertyArrayIndex); diff --git a/demo/handler/h_upt.c b/demo/handler/h_upt.c index 8630773d..90ede122 100644 --- a/demo/handler/h_upt.c +++ b/demo/handler/h_upt.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2009 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2009 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -39,11 +39,10 @@ /** @file h_upt.c Handles Unconfirmed Private Transfer requests. */ -void private_transfer_print_data( - BACNET_PRIVATE_TRANSFER_DATA *private_data) +void private_transfer_print_data(BACNET_PRIVATE_TRANSFER_DATA *private_data) { - BACNET_OBJECT_PROPERTY_VALUE object_value; /* for bacapp printing */ - BACNET_APPLICATION_DATA_VALUE value; /* for decode value data */ + BACNET_OBJECT_PROPERTY_VALUE object_value; /* for bacapp printing */ + BACNET_APPLICATION_DATA_VALUE value; /* for decode value data */ int len = 0; uint8_t *application_data; int application_data_len; @@ -53,16 +52,15 @@ void private_transfer_print_data( if (private_data) { #if PRINT_ENABLED printf("PrivateTransfer:vendorID=%u\r\n", - (unsigned) private_data->vendorID); + (unsigned)private_data->vendorID); printf("PrivateTransfer:serviceNumber=%lu\r\n", - (unsigned long) private_data->serviceNumber); + (unsigned long)private_data->serviceNumber); #endif application_data = private_data->serviceParameters; application_data_len = private_data->serviceParametersLen; for (;;) { - len = - bacapp_decode_application_data(application_data, - (uint8_t) application_data_len, &value); + len = bacapp_decode_application_data( + application_data, (uint8_t)application_data_len, &value); if (first_value && (len < application_data_len)) { first_value = false; #if PRINT_ENABLED @@ -101,10 +99,9 @@ void private_transfer_print_data( } } -void handler_unconfirmed_private_transfer( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src) +void handler_unconfirmed_private_transfer(uint8_t *service_request, + uint16_t service_len, + BACNET_ADDRESS *src) { BACNET_PRIVATE_TRANSFER_DATA private_data; int len = 0; @@ -112,9 +109,8 @@ void handler_unconfirmed_private_transfer( #if PRINT_ENABLED fprintf(stderr, "Received Unconfirmed Private Transfer Request!\n"); #endif - len = - ptransfer_decode_service_request(service_request, service_len, - &private_data); + len = ptransfer_decode_service_request(service_request, service_len, + &private_data); if (len >= 0) { private_transfer_print_data(&private_data); } diff --git a/demo/handler/h_whohas.c b/demo/handler/h_whohas.c index 91360a87..7b2ab458 100644 --- a/demo/handler/h_whohas.c +++ b/demo/handler/h_whohas.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2006 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2006 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -42,8 +42,7 @@ * or object ID, if the Device has a match. * @param data [in] The decoded who-has payload from the request. */ -static void match_name_or_object( - BACNET_WHO_HAS_DATA * data) +static void match_name_or_object(BACNET_WHO_HAS_DATA* data) { int object_type = 0; uint32_t object_instance = 0; @@ -54,29 +53,26 @@ static void match_name_or_object( note: we should have only 1 of such an object */ if (data->is_object_name) { /* valid name in my device? */ - found = - Device_Valid_Object_Name(&data->object.name, &object_type, - &object_instance); + found = Device_Valid_Object_Name(&data->object.name, &object_type, + &object_instance); if (found) { Send_I_Have(Device_Object_Instance_Number(), - (BACNET_OBJECT_TYPE) object_type, object_instance, - &data->object.name); + (BACNET_OBJECT_TYPE)object_type, object_instance, + &data->object.name); } } else { /* valid object_name copy in my device? */ - found = - Device_Object_Name_Copy((BACNET_OBJECT_TYPE) data-> - object.identifier.type, data->object.identifier.instance, - &object_name); + found = Device_Object_Name_Copy( + (BACNET_OBJECT_TYPE)data->object.identifier.type, + data->object.identifier.instance, &object_name); if (found) { Send_I_Have(Device_Object_Instance_Number(), - (BACNET_OBJECT_TYPE) data->object.identifier.type, - data->object.identifier.instance, &object_name); + (BACNET_OBJECT_TYPE)data->object.identifier.type, + data->object.identifier.instance, &object_name); } } } - /** Handler for Who-Has requests, with broadcast I-Have response. * Will respond if the device Object ID matches, and we have * the Object or Object Name requested. @@ -86,22 +82,21 @@ static void match_name_or_object( * @param service_len [in] Length of the service_request message. * @param src [in] The BACNET_ADDRESS of the message's source. */ -void handler_who_has( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src) +void handler_who_has(uint8_t* service_request, uint16_t service_len, + BACNET_ADDRESS* src) { int len = 0; BACNET_WHO_HAS_DATA data; bool directed_to_me = false; - (void) src; + (void)src; len = whohas_decode_service_request(service_request, service_len, &data); if (len > 0) { if ((data.low_limit == -1) || (data.high_limit == -1)) directed_to_me = true; - else if ((Device_Object_Instance_Number() >= (uint32_t) data.low_limit) - && (Device_Object_Instance_Number() <= (uint32_t) data.high_limit)) + else if ((Device_Object_Instance_Number() >= + (uint32_t)data.low_limit) && + (Device_Object_Instance_Number() <= (uint32_t)data.high_limit)) directed_to_me = true; if (directed_to_me) { match_name_or_object(&data); @@ -109,10 +104,12 @@ void handler_who_has( } } - -#ifdef BAC_ROUTING /* was for BAC_ROUTING - delete in 2/2012 if still unused */ - /* EKH: I restored this to BAC_ROUTING (from DEPRECATED) because I found that the server demo with the built-in - virtual Router did not insert the SADRs of the virtual devices on the virtual network without it */ +#ifdef BAC_ROUTING /* was for BAC_ROUTING - delete in 2/2012 if still unused \ + */ +/* EKH: I restored this to BAC_ROUTING (from DEPRECATED) because I found that + the server demo with the built-in + virtual Router did not insert the SADRs of the virtual devices on the virtual + network without it */ /** Handler for Who-Has requests in the virtual routing setup, * with broadcast I-Have response. @@ -124,29 +121,28 @@ void handler_who_has( * @param service_len [in] Length of the service_request message. * @param src [in] The BACNET_ADDRESS of the message's source (ignored). */ -void handler_who_has_for_routing( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src) +void handler_who_has_for_routing(uint8_t* service_request, uint16_t service_len, + BACNET_ADDRESS* src) { int len = 0; BACNET_WHO_HAS_DATA data; int32_t dev_instance; - int cursor = 0; /* Starting hint */ - int my_list[2] = { 0, -1 }; /* Not really used, so dummy values */ + int cursor = 0; /* Starting hint */ + int my_list[2] = {0, -1}; /* Not really used, so dummy values */ BACNET_ADDRESS bcast_net; - (void) src; + (void)src; len = whohas_decode_service_request(service_request, service_len, &data); if (len > 0) { /* Go through all devices, starting with the root gateway Device */ memset(&bcast_net, 0, sizeof(BACNET_ADDRESS)); - bcast_net.net = BACNET_BROADCAST_NETWORK; /* That's all we have to set */ + bcast_net.net = + BACNET_BROADCAST_NETWORK; /* That's all we have to set */ while (Routed_Device_GetNext(&bcast_net, my_list, &cursor)) { dev_instance = Device_Object_Instance_Number(); if ((data.low_limit == -1) || (data.high_limit == -1) || ((dev_instance >= data.low_limit) && - (dev_instance <= data.high_limit))) + (dev_instance <= data.high_limit))) match_name_or_object(&data); } } diff --git a/demo/handler/h_whois.c b/demo/handler/h_whois.c index a639a1ad..33c56446 100644 --- a/demo/handler/h_whois.c +++ b/demo/handler/h_whois.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2005 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2005 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -47,25 +47,22 @@ * @param service_len [in] Length of the service_request message. * @param src [in] The BACNET_ADDRESS of the message's source (ignored). */ -void handler_who_is( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src) +void handler_who_is(uint8_t* service_request, uint16_t service_len, + BACNET_ADDRESS* src) { int len = 0; int32_t low_limit = 0; int32_t high_limit = 0; - (void) src; - len = - whois_decode_service_request(service_request, service_len, &low_limit, - &high_limit); + (void)src; + len = whois_decode_service_request(service_request, service_len, &low_limit, + &high_limit); if (len == 0) { Send_I_Am(&Handler_Transmit_Buffer[0]); } else if (len != BACNET_STATUS_ERROR) { /* is my device id within the limits? */ - if ((Device_Object_Instance_Number() >= (uint32_t) low_limit) && - (Device_Object_Instance_Number() <= (uint32_t) high_limit)) { + if ((Device_Object_Instance_Number() >= (uint32_t)low_limit) && + (Device_Object_Instance_Number() <= (uint32_t)high_limit)) { Send_I_Am(&Handler_Transmit_Buffer[0]); } } @@ -73,32 +70,30 @@ void handler_who_is( return; } -/** Handler for Who-Is requests, with Unicast I-Am response (per Addendum 135-2004q). +/** Handler for Who-Is requests, with Unicast I-Am response (per Addendum + * 135-2004q). * @ingroup DMDDB * @param service_request [in] The received message to be handled. * @param service_len [in] Length of the service_request message. * @param src [in] The BACNET_ADDRESS of the message's source that the * response will be sent back to. */ -void handler_who_is_unicast( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src) +void handler_who_is_unicast(uint8_t* service_request, uint16_t service_len, + BACNET_ADDRESS* src) { int len = 0; int32_t low_limit = 0; int32_t high_limit = 0; - len = - whois_decode_service_request(service_request, service_len, &low_limit, - &high_limit); + len = whois_decode_service_request(service_request, service_len, &low_limit, + &high_limit); /* If no limits, then always respond */ if (len == 0) { Send_I_Am_Unicast(&Handler_Transmit_Buffer[0], src); } else if (len != BACNET_STATUS_ERROR) { /* is my device id within the limits? */ - if ((Device_Object_Instance_Number() >= (uint32_t) low_limit) && - (Device_Object_Instance_Number() <= (uint32_t) high_limit)) { + if ((Device_Object_Instance_Number() >= (uint32_t)low_limit) && + (Device_Object_Instance_Number() <= (uint32_t)high_limit)) { Send_I_Am_Unicast(&Handler_Transmit_Buffer[0], src); } } @@ -106,11 +101,12 @@ void handler_who_is_unicast( return; } - -#ifdef BAC_ROUTING /* was for BAC_ROUTING - delete in 2/2012 if still unused */ - /* EKH: I restored this to BAC_ROUTING (from DEPRECATED) because I found that the server demo with the built-in - virtual Router did not insert the SADRs of the virtual devices on the virtual network without it */ - +#ifdef BAC_ROUTING /* was for BAC_ROUTING - delete in 2/2012 if still unused \ + */ +/* EKH: I restored this to BAC_ROUTING (from DEPRECATED) because I found that + the server demo with the built-in + virtual Router did not insert the SADRs of the virtual devices on the virtual + network without it */ /** Local function to check Who-Is requests against our Device IDs. * Will check the gateway (root Device) and all virtual routed @@ -120,48 +116,44 @@ void handler_who_is_unicast( * @param service_len [in] Length of the service_request message. * @param src [in] The BACNET_ADDRESS of the message's source. * @param is_unicast [in] True if should send unicast response(s) - * back to the src, else False if should broadcast response(s). + * back to the src, else False if should broadcast + * response(s). */ -static void check_who_is_for_routing( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src, - bool is_unicast) +static void check_who_is_for_routing(uint8_t* service_request, + uint16_t service_len, BACNET_ADDRESS* src, + bool is_unicast) { int len = 0; int32_t low_limit = 0; int32_t high_limit = 0; int32_t dev_instance; - int cursor = 0; /* Starting hint */ - int my_list[2] = { 0, -1 }; /* Not really used, so dummy values */ + int cursor = 0; /* Starting hint */ + int my_list[2] = {0, -1}; /* Not really used, so dummy values */ BACNET_ADDRESS bcast_net; - len = - whois_decode_service_request(service_request, service_len, &low_limit, - &high_limit); + len = whois_decode_service_request(service_request, service_len, &low_limit, + &high_limit); if (len == BACNET_STATUS_ERROR) { /* Invalid; just leave */ return; } /* Go through all devices, starting with the root gateway Device */ memset(&bcast_net, 0, sizeof(BACNET_ADDRESS)); - bcast_net.net = BACNET_BROADCAST_NETWORK; /* That's all we have to set */ + bcast_net.net = BACNET_BROADCAST_NETWORK; /* That's all we have to set */ while (Routed_Device_GetNext(&bcast_net, my_list, &cursor)) { dev_instance = Device_Object_Instance_Number(); /* If len == 0, no limits and always respond */ - if ((len == 0) || ((dev_instance >= low_limit) && - (dev_instance <= high_limit))) { + if ((len == 0) || + ((dev_instance >= low_limit) && (dev_instance <= high_limit))) { if (is_unicast) Send_I_Am_Unicast(&Handler_Transmit_Buffer[0], src); else Send_I_Am(&Handler_Transmit_Buffer[0]); } } - } - /** Handler for Who-Is requests in the virtual routing setup, * with broadcast I-Am response(s). * @ingroup DMDDB @@ -173,15 +165,12 @@ static void check_who_is_for_routing( * @param service_len [in] Length of the service_request message. * @param src [in] The BACNET_ADDRESS of the message's source (ignored). */ -void handler_who_is_bcast_for_routing( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src) +void handler_who_is_bcast_for_routing(uint8_t* service_request, + uint16_t service_len, BACNET_ADDRESS* src) { check_who_is_for_routing(service_request, service_len, src, false); } - /** Handler for Who-Is requests in the virtual routing setup, * with unicast I-Am response(s) returned to the src. * Will check the gateway (root Device) and all virtual routed @@ -193,10 +182,9 @@ void handler_who_is_bcast_for_routing( * @param src [in] The BACNET_ADDRESS of the message's source that the * response will be sent back to. */ -void handler_who_is_unicast_for_routing( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src) +void handler_who_is_unicast_for_routing(uint8_t* service_request, + uint16_t service_len, + BACNET_ADDRESS* src) { check_who_is_for_routing(service_request, service_len, src, true); } diff --git a/demo/handler/h_wp.c b/demo/handler/h_wp.c index 36f7b43f..cd9143b5 100644 --- a/demo/handler/h_wp.c +++ b/demo/handler/h_wp.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2005 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2005 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -42,7 +42,6 @@ /** @file h_wp.c Handles Write Property requests. */ - /** Handler for a WriteProperty Service request. * @ingroup DSWP * This handler will be invoked by apdu_handler() if it has been enabled @@ -61,11 +60,9 @@ * @param service_data [in] The BACNET_CONFIRMED_SERVICE_DATA information * decoded from the APDU header of this message. */ -void handler_write_property( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src, - BACNET_CONFIRMED_SERVICE_DATA * service_data) +void handler_write_property(uint8_t* service_request, uint16_t service_len, + BACNET_ADDRESS* src, + BACNET_CONFIRMED_SERVICE_DATA* service_data) { BACNET_WRITE_PROPERTY_DATA wp_data; int len = 0; @@ -77,65 +74,63 @@ void handler_write_property( /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); - pdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address, - &npdu_data); + pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address, + &npdu_data); #if PRINT_ENABLED fprintf(stderr, "WP: Received Request!\n"); #endif if (service_data->segmented_message) { - len = - abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, - true); + len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], + service_data->invoke_id, + ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true); #if PRINT_ENABLED fprintf(stderr, "WP: Segmented message. Sending Abort!\n"); #endif goto WP_ABORT; - } /* decode the service request only */ + } /* decode the service request only */ len = wp_decode_service_request(service_request, service_len, &wp_data); #if PRINT_ENABLED if (len > 0) - fprintf(stderr, + 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 /* bad decoding or something we didn't understand - send an abort */ if (len <= 0) { - len = - abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, ABORT_REASON_OTHER, true); + len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len], + service_data->invoke_id, ABORT_REASON_OTHER, + true); #if PRINT_ENABLED fprintf(stderr, "WP: Bad Encoding. Sending Abort!\n"); #endif goto WP_ABORT; } if (Device_Write_Property(&wp_data)) { - len = - encode_simple_ack(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY); + len = encode_simple_ack(&Handler_Transmit_Buffer[pdu_len], + service_data->invoke_id, + SERVICE_CONFIRMED_WRITE_PROPERTY); #if PRINT_ENABLED fprintf(stderr, "WP: Sending Simple Ack!\n"); #endif } else { - len = - bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY, - wp_data.error_class, wp_data.error_code); + len = bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len], + service_data->invoke_id, + SERVICE_CONFIRMED_WRITE_PROPERTY, + wp_data.error_class, wp_data.error_code); #if PRINT_ENABLED fprintf(stderr, "WP: Sending Error!\n"); #endif } - WP_ABORT: +WP_ABORT: pdu_len += len; - bytes_sent = - datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], - pdu_len); + bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], + pdu_len); if (bytes_sent <= 0) { #if PRINT_ENABLED fprintf(stderr, "WP: Failed to send PDU (%s)!\n", strerror(errno)); @@ -145,19 +140,15 @@ void handler_write_property( return; } - /** Perform basic validation of Write Property argument based on * the assumption that it is a string. Check for correct data type, * correct encoding (fixed here as ANSI X34),correct length, and * finally if it is allowed to be empty. */ -bool WPValidateString( - BACNET_APPLICATION_DATA_VALUE * pValue, - int iMaxLen, - bool bEmptyAllowed, - BACNET_ERROR_CLASS * pErrorClass, - BACNET_ERROR_CODE * pErrorCode) +bool WPValidateString(BACNET_APPLICATION_DATA_VALUE* pValue, int iMaxLen, + bool bEmptyAllowed, BACNET_ERROR_CLASS* pErrorClass, + BACNET_ERROR_CODE* pErrorCode) { bool bResult; @@ -172,15 +163,15 @@ bool WPValidateString( if (characterstring_encoding(&pValue->type.Character_String) == CHARACTER_ANSI_X34) { if ((bEmptyAllowed == false) && - (characterstring_length(&pValue->type.Character_String) == - 0)) { + (characterstring_length(&pValue->type.Character_String) == 0)) { *pErrorCode = ERROR_CODE_VALUE_OUT_OF_RANGE; } else if ((bEmptyAllowed == false) && - (!characterstring_printable(&pValue->type.Character_String))) { + (!characterstring_printable( + &pValue->type.Character_String))) { /* assumption: non-empty also means must be "printable" */ *pErrorCode = ERROR_CODE_VALUE_OUT_OF_RANGE; } else if (characterstring_length(&pValue->type.Character_String) > - (uint16_t) iMaxLen) { + (uint16_t)iMaxLen) { *pErrorClass = ERROR_CLASS_RESOURCES; *pErrorCode = ERROR_CODE_NO_SPACE_TO_WRITE_PROPERTY; } else @@ -198,11 +189,9 @@ bool WPValidateString( * validation fails. Cuts out reams of repeated code in the object code. */ -bool WPValidateArgType( - BACNET_APPLICATION_DATA_VALUE * pValue, - uint8_t ucExpectedTag, - BACNET_ERROR_CLASS * pErrorClass, - BACNET_ERROR_CODE * pErrorCode) +bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE* pValue, + uint8_t ucExpectedTag, BACNET_ERROR_CLASS* pErrorClass, + BACNET_ERROR_CODE* pErrorCode) { bool bResult; diff --git a/demo/handler/h_wpm.c b/demo/handler/h_wpm.c index 1a7ef92c..7ae635ee 100644 --- a/demo/handler/h_wpm.c +++ b/demo/handler/h_wpm.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2011 Krzysztof Malorny -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2011 Krzysztof Malorny + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -44,7 +44,6 @@ /** @file h_wpm.c Handles Write Property Multiple requests. */ - /** Handler for a WriteProperty Service request. * @ingroup DSWP * This handler will be invoked by apdu_handler() if it has been enabled @@ -63,10 +62,8 @@ * decoded from the APDU header of this message. */ void handler_write_property_multiple( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src, - BACNET_CONFIRMED_SERVICE_DATA * service_data) + uint8_t* service_request, uint16_t service_len, BACNET_ADDRESS* src, + BACNET_CONFIRMED_SERVICE_DATA* service_data) { int len = 0; int apdu_len = 0; @@ -92,32 +89,34 @@ void handler_write_property_multiple( decode_len = 0; do { /* decode Object Identifier */ - len = - wpm_decode_object_id(&service_request[decode_len], - service_len - decode_len, &wp_data); + len = wpm_decode_object_id(&service_request[decode_len], + service_len - decode_len, &wp_data); if (len > 0) { uint8_t tag_number = 0; decode_len += len; /* Opening tag 1 - List of Properties */ if (decode_is_opening_tag_number(&service_request[decode_len++], - 1)) { + 1)) { do { - /* decode a 'Property Identifier'; (3) an optional 'Property Array Index' */ - /* (4) a 'Property Value'; and (5) an optional 'Priority'. */ - len = - wpm_decode_object_property(&service_request - [decode_len], service_len - decode_len, &wp_data); + /* decode a 'Property Identifier'; (3) an optional 'Property + * Array Index' */ + /* (4) a 'Property Value'; and (5) an optional 'Priority'. + */ + len = wpm_decode_object_property( + &service_request[decode_len], service_len - decode_len, + &wp_data); if (len > 0) { decode_len += len; #if PRINT_ENABLED fprintf(stderr, - "WPM: 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); + "WPM: 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); #endif if (Device_Write_Property(&wp_data) == false) { error = true; @@ -133,15 +132,17 @@ void handler_write_property_multiple( } /* Closing tag 1 - List of Properties */ - if (decode_is_closing_tag_number(&service_request - [decode_len], 1)) { + if (decode_is_closing_tag_number( + &service_request[decode_len], 1)) { tag_number = 1; decode_len++; } else - tag_number = 0; /* it was not tag 1, decode next Property Identifier ... */ + tag_number = 0; /* it was not tag 1, decode next + Property Identifier ... */ - } - while (tag_number != 1); /* end decoding List of Properties for "that" object */ + } while ( + tag_number != + 1); /* end decoding List of Properties for "that" object */ if (error) { goto WPM_ABORT; @@ -156,20 +157,18 @@ void handler_write_property_multiple( } } while (decode_len < service_len); - WPM_ABORT: +WPM_ABORT: /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); - npdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address, - &npdu_data); + npdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address, + &npdu_data); apdu_len = 0; /* handle any errors */ if (error) { if (len == BACNET_STATUS_ABORT) { - apdu_len = - abort_encode_apdu(&Handler_Transmit_Buffer[npdu_len], - service_data->invoke_id, + apdu_len = abort_encode_apdu( + &Handler_Transmit_Buffer[npdu_len], service_data->invoke_id, abort_convert_error_code(wp_data.error_code), true); #if PRINT_ENABLED fprintf(stderr, "WPM: Sending Abort!\n"); @@ -177,32 +176,29 @@ void handler_write_property_multiple( } else if (len == BACNET_STATUS_ERROR) { apdu_len = wpm_error_ack_encode_apdu(&Handler_Transmit_Buffer[npdu_len], - service_data->invoke_id, &wp_data); + service_data->invoke_id, &wp_data); #if PRINT_ENABLED fprintf(stderr, "WPM: Sending Error!\n"); #endif } else if (len == BACNET_STATUS_REJECT) { - apdu_len = - reject_encode_apdu(&Handler_Transmit_Buffer[npdu_len], - service_data->invoke_id, + apdu_len = reject_encode_apdu( + &Handler_Transmit_Buffer[npdu_len], service_data->invoke_id, reject_convert_error_code(wp_data.error_code)); #if PRINT_ENABLED fprintf(stderr, "WPM: Sending Reject!\n"); #endif } } else { - apdu_len = - wpm_ack_encode_apdu_init(&Handler_Transmit_Buffer[npdu_len], - service_data->invoke_id); + apdu_len = wpm_ack_encode_apdu_init(&Handler_Transmit_Buffer[npdu_len], + service_data->invoke_id); #if PRINT_ENABLED fprintf(stderr, "WPM: Sending Ack!\n"); #endif } pdu_len = npdu_len + apdu_len; - bytes_sent = - datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], - pdu_len); + bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], + pdu_len); #if PRINT_ENABLED if (bytes_sent <= 0) { fprintf(stderr, "Failed to send PDU (%s)!\n", strerror(errno)); diff --git a/demo/handler/noserv.c b/demo/handler/noserv.c index 5a8faa66..3c75e0d2 100644 --- a/demo/handler/noserv.c +++ b/demo/handler/noserv.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2005 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2005 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -49,11 +49,9 @@ * @param service_data [in] The BACNET_CONFIRMED_SERVICE_DATA information * decoded from the APDU header of this message. */ -void handler_unrecognized_service( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src, - BACNET_CONFIRMED_SERVICE_DATA * service_data) +void handler_unrecognized_service(uint8_t* service_request, + uint16_t service_len, BACNET_ADDRESS* src, + BACNET_CONFIRMED_SERVICE_DATA* service_data) { int len = 0; int pdu_len = 0; @@ -61,24 +59,22 @@ void handler_unrecognized_service( BACNET_NPDU_DATA npdu_data; BACNET_ADDRESS my_address; - (void) service_request; - (void) service_len; + (void)service_request; + (void)service_len; /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); - pdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address, - &npdu_data); + pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address, + &npdu_data); /* encode the APDU portion of the packet */ - len = - reject_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - service_data->invoke_id, REJECT_REASON_UNRECOGNIZED_SERVICE); + len = reject_encode_apdu(&Handler_Transmit_Buffer[pdu_len], + service_data->invoke_id, + REJECT_REASON_UNRECOGNIZED_SERVICE); pdu_len += len; /* send the data */ - bytes_sent = - datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], - pdu_len); + bytes_sent = datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0], + pdu_len); if (bytes_sent > 0) { #if PRINT_ENABLED fprintf(stderr, "Sent Reject!\n"); diff --git a/demo/handler/objects.c b/demo/handler/objects.c index 83247247..3ccc5453 100644 --- a/demo/handler/objects.c +++ b/demo/handler/objects.c @@ -44,36 +44,31 @@ /* list of devices */ static OS_Keylist Device_List = NULL; -void objects_init( - void) +void objects_init(void) { if (!Device_List) Device_List = Keylist_Create(); } -int objects_device_count( - void) +int objects_device_count(void) { objects_init(); return Keylist_Count(Device_List); } -OBJECT_DEVICE_T *objects_device_data( - int index) +OBJECT_DEVICE_T *objects_device_data(int index) { objects_init(); return Keylist_Data_Index(Device_List, index); } -OBJECT_DEVICE_T *objects_device_by_instance( - uint32_t device_instance) +OBJECT_DEVICE_T *objects_device_by_instance(uint32_t device_instance) { objects_init(); return Keylist_Data(Device_List, device_instance); } -OBJECT_DEVICE_T *objects_device_new( - uint32_t device_instance) +OBJECT_DEVICE_T *objects_device_new(uint32_t device_instance) { OBJECT_DEVICE_T *pDevice = NULL; KEY key = device_instance; @@ -93,8 +88,8 @@ OBJECT_DEVICE_T *objects_device_new( Keylist_Data_Add(Device_List, key, pDevice); } else { fprintf(stderr, - "Objects: Unable to allocate device %lu buffer\n", - (unsigned long) device_instance); + "Objects: Unable to allocate device %lu buffer\n", + (unsigned long)device_instance); } } } @@ -102,8 +97,7 @@ OBJECT_DEVICE_T *objects_device_new( return pDevice; } -OBJECT_DEVICE_T *objects_device_delete( - int index) +OBJECT_DEVICE_T *objects_device_delete(int index) { OBJECT_DEVICE_T *pDevice = NULL; BACNET_OBJECT_ID *pObject; @@ -112,7 +106,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 = @@ -137,10 +131,8 @@ OBJECT_DEVICE_T *objects_device_delete( #include "ctest.h" /* test the object creation and deletion */ -void testBACnetObjectsCompare( - Test * pTest, - OBJECT_DEVICE_T * pDevice, - uint32_t device_id) +void testBACnetObjectsCompare(Test *pTest, OBJECT_DEVICE_T *pDevice, + uint32_t device_id) { ct_test(pTest, pDevice != NULL); if (pDevice) { @@ -151,8 +143,7 @@ void testBACnetObjectsCompare( } } -void testBACnetObjects( - Test * pTest) +void testBACnetObjects(Test *pTest) { uint32_t device_id = 0; unsigned test_point = 0; @@ -175,8 +166,8 @@ void testBACnetObjects( for (test_point = 0; test_point < max_test_points; test_point++) { device_id = test_point * (BACNET_MAX_INSTANCE / max_test_points); pDevice = objects_device_data(test_point); - testBACnetObjectsCompare(pTest, pDevice, Keylist_Key(Device_List, - test_point)); + testBACnetObjectsCompare(pTest, pDevice, + Keylist_Key(Device_List, test_point)); } for (test_point = 0; test_point < max_test_points; test_point++) { pDevice = objects_device_delete(0); @@ -184,8 +175,7 @@ void testBACnetObjects( } #ifdef TEST_OBJECT_LIST -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -198,7 +188,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); diff --git a/demo/handler/s_abort.c b/demo/handler/s_abort.c index 71d54cf9..1e4053e2 100644 --- a/demo/handler/s_abort.c +++ b/demo/handler/s_abort.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2016 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2016 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -43,7 +43,6 @@ #include "handlers.h" #include "client.h" - /** Encodes an Abort message * @param buffer The buffer to build the message for sending. * @param dest - Destination address to send the message @@ -55,14 +54,9 @@ * * @return Size of the message sent (bytes), or a negative value on error. */ -int abort_encode_pdu( - uint8_t * buffer, - BACNET_ADDRESS * dest, - BACNET_ADDRESS * src, - BACNET_NPDU_DATA * npdu_data, - uint8_t invoke_id, - BACNET_ABORT_REASON reason, - bool server) +int abort_encode_pdu(uint8_t *buffer, BACNET_ADDRESS *dest, BACNET_ADDRESS *src, + BACNET_NPDU_DATA *npdu_data, uint8_t invoke_id, + BACNET_ABORT_REASON reason, bool server) { int len = 0; int pdu_len = 0; @@ -87,12 +81,9 @@ int abort_encode_pdu( * * @return Size of the message sent (bytes), or a negative value on error. */ -int Send_Abort_To_Network( - uint8_t * buffer, - BACNET_ADDRESS *dest, - uint8_t invoke_id, - BACNET_ABORT_REASON reason, - bool server) +int Send_Abort_To_Network(uint8_t *buffer, BACNET_ADDRESS *dest, + uint8_t invoke_id, BACNET_ABORT_REASON reason, + bool server) { int pdu_len = 0; BACNET_ADDRESS src; @@ -100,8 +91,8 @@ int Send_Abort_To_Network( BACNET_NPDU_DATA npdu_data; datalink_get_my_address(&src); - pdu_len = abort_encode_pdu(buffer, dest, &src, &npdu_data, - invoke_id, reason, server); + pdu_len = abort_encode_pdu(buffer, dest, &src, &npdu_data, invoke_id, + reason, server); bytes_sent = datalink_send_pdu(dest, &npdu_data, &buffer[0], pdu_len); return bytes_sent; diff --git a/demo/handler/s_ack_alarm.c b/demo/handler/s_ack_alarm.c index 2835deff..fc3cfab5 100644 --- a/demo/handler/s_ack_alarm.c +++ b/demo/handler/s_ack_alarm.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2009 John Minack -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2009 John Minack + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -48,10 +48,8 @@ /* returns the invoke ID for confirmed request, or zero on failure */ - -uint8_t Send_Alarm_Acknowledgement( - uint32_t device_id, - BACNET_ALARM_ACK_DATA * data) +uint8_t Send_Alarm_Acknowledgement(uint32_t device_id, + BACNET_ALARM_ACK_DATA* data) { BACNET_ADDRESS dest; BACNET_ADDRESS my_address; @@ -75,36 +73,34 @@ uint8_t Send_Alarm_Acknowledgement( /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL); - pdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address, - &npdu_data); - len = - alarm_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id, - data); + pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, + &my_address, &npdu_data); + len = alarm_ack_encode_apdu(&Handler_Transmit_Buffer[pdu_len], + invoke_id, data); pdu_len += len; /* will it fit in the sender? note: if there is a bottleneck router in between us and the destination, we won't know unless we have a way to check for that and update the max_apdu in the address binding table. */ - if ((unsigned) pdu_len < max_apdu) { - tsm_set_confirmed_unsegmented_transaction(invoke_id, &dest, - &npdu_data, &Handler_Transmit_Buffer[0], (uint16_t) pdu_len); - bytes_sent = - datalink_send_pdu(&dest, &npdu_data, - &Handler_Transmit_Buffer[0], pdu_len); + if ((unsigned)pdu_len < max_apdu) { + tsm_set_confirmed_unsegmented_transaction( + invoke_id, &dest, &npdu_data, &Handler_Transmit_Buffer[0], + (uint16_t)pdu_len); + bytes_sent = datalink_send_pdu( + &dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); #if PRINT_ENABLED if (bytes_sent <= 0) fprintf(stderr, "Failed to Send Alarm Ack Request (%s)!\n", - strerror(errno)); + strerror(errno)); #endif } else { tsm_free_invoke_id(invoke_id); invoke_id = 0; #if PRINT_ENABLED fprintf(stderr, - "Failed to Send Alarm Ack Request " - "(exceeds destination maximum APDU)!\n"); + "Failed to Send Alarm Ack Request " + "(exceeds destination maximum APDU)!\n"); #endif } } diff --git a/demo/handler/s_arfs.c b/demo/handler/s_arfs.c index 15d43971..c471993f 100644 --- a/demo/handler/s_arfs.c +++ b/demo/handler/s_arfs.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2006 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2006 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -45,11 +45,9 @@ /** @file s_arfs.c Send part of an Atomic Read File Stream. */ -uint8_t Send_Atomic_Read_File_Stream( - uint32_t device_id, - uint32_t file_instance, - int fileStartPosition, - unsigned requestedOctetCount) +uint8_t Send_Atomic_Read_File_Stream(uint32_t device_id, uint32_t file_instance, + int fileStartPosition, + unsigned requestedOctetCount) { BACNET_ADDRESS dest; BACNET_ADDRESS my_address; @@ -81,37 +79,34 @@ uint8_t Send_Atomic_Read_File_Stream( /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL); - pdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address, - &npdu_data); - len = - arf_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id, - &data); + pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, + &my_address, &npdu_data); + len = arf_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id, + &data); pdu_len += len; /* will the APDU fit the target device? note: if there is a bottleneck router in between us and the destination, we won't know unless we have a way to check for that and update the max_apdu in the address binding table. */ - if ((unsigned) pdu_len < max_apdu) { - tsm_set_confirmed_unsegmented_transaction(invoke_id, &dest, - &npdu_data, &Handler_Transmit_Buffer[0], (uint16_t) pdu_len); - bytes_sent = - datalink_send_pdu(&dest, &npdu_data, - &Handler_Transmit_Buffer[0], pdu_len); + if ((unsigned)pdu_len < max_apdu) { + tsm_set_confirmed_unsegmented_transaction( + invoke_id, &dest, &npdu_data, &Handler_Transmit_Buffer[0], + (uint16_t)pdu_len); + bytes_sent = datalink_send_pdu( + &dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); #if PRINT_ENABLED if (bytes_sent <= 0) - fprintf(stderr, - "Failed to Send AtomicReadFile Request (%s)!\n", - strerror(errno)); + fprintf(stderr, "Failed to Send AtomicReadFile Request (%s)!\n", + strerror(errno)); #endif } else { tsm_free_invoke_id(invoke_id); invoke_id = 0; #if PRINT_ENABLED fprintf(stderr, - "Failed to Send AtomicReadFile Request " - "(payload exceeds destination maximum APDU)!\n"); + "Failed to Send AtomicReadFile Request " + "(payload exceeds destination maximum APDU)!\n"); #endif } } diff --git a/demo/handler/s_awfs.c b/demo/handler/s_awfs.c index e5aa2802..36eb3b7e 100644 --- a/demo/handler/s_awfs.c +++ b/demo/handler/s_awfs.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2006 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2006 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -45,11 +45,10 @@ /** @file s_awfs.c Send part of an Atomic Write File Stream request. */ -uint8_t Send_Atomic_Write_File_Stream( - uint32_t device_id, - uint32_t file_instance, - int fileStartPosition, - BACNET_OCTET_STRING * fileData) +uint8_t Send_Atomic_Write_File_Stream(uint32_t device_id, + uint32_t file_instance, + int fileStartPosition, + BACNET_OCTET_STRING* fileData) { BACNET_ADDRESS dest; BACNET_ADDRESS my_address; @@ -82,37 +81,35 @@ uint8_t Send_Atomic_Write_File_Stream( /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL); - pdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, - &my_address, &npdu_data); + pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, + &my_address, &npdu_data); /* encode the APDU portion of the packet */ - len = - awf_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id, - &data); + len = awf_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id, + &data); pdu_len += len; /* will the APDU fit the target device? note: if there is a bottleneck router in between us and the destination, we won't know unless we have a way to check for that and update the max_apdu in the address binding table. */ - if ((unsigned) pdu_len <= max_apdu) { - tsm_set_confirmed_unsegmented_transaction(invoke_id, &dest, - &npdu_data, &Handler_Transmit_Buffer[0], - (uint16_t) pdu_len); - bytes_sent = - datalink_send_pdu(&dest, &npdu_data, - &Handler_Transmit_Buffer[0], pdu_len); + if ((unsigned)pdu_len <= max_apdu) { + tsm_set_confirmed_unsegmented_transaction( + invoke_id, &dest, &npdu_data, &Handler_Transmit_Buffer[0], + (uint16_t)pdu_len); + bytes_sent = datalink_send_pdu( + &dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); #if PRINT_ENABLED if (bytes_sent <= 0) fprintf(stderr, - "Failed to Send AtomicWriteFile Request (%s)!\n", - strerror(errno)); + "Failed to Send AtomicWriteFile Request (%s)!\n", + strerror(errno)); #endif } else { tsm_free_invoke_id(invoke_id); invoke_id = 0; #if PRINT_ENABLED - fprintf(stderr, + fprintf( + stderr, "Failed to Send AtomicWriteFile Request " "(payload [%d] exceeds destination maximum APDU [%u])!\n", pdu_len, max_apdu); @@ -123,8 +120,9 @@ uint8_t Send_Atomic_Write_File_Stream( invoke_id = 0; #if PRINT_ENABLED fprintf(stderr, - "Failed to Send AtomicWriteFile Request " - "(payload [%d] exceeds octet string capacity)!\n", pdu_len); + "Failed to Send AtomicWriteFile Request " + "(payload [%d] exceeds octet string capacity)!\n", + pdu_len); #endif } } diff --git a/demo/handler/s_cevent.c b/demo/handler/s_cevent.c index 0607d718..e476bb56 100644 --- a/demo/handler/s_cevent.c +++ b/demo/handler/s_cevent.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2005 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2005 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -47,9 +47,8 @@ * @return invoke id of outgoing message, or 0 if communication is disabled, * or no tsm slot is available. */ -uint8_t Send_CEvent_Notify( - uint32_t device_id, - BACNET_EVENT_NOTIFICATION_DATA * data) +uint8_t Send_CEvent_Notify(uint32_t device_id, + BACNET_EVENT_NOTIFICATION_DATA* data) { int len = 0; int pdu_len = 0; @@ -73,28 +72,27 @@ uint8_t Send_CEvent_Notify( /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL); - pdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address, - &npdu_data); + pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, + &my_address, &npdu_data); /* encode the APDU portion of the packet */ - len = - cevent_notify_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - invoke_id, data); + len = cevent_notify_encode_apdu(&Handler_Transmit_Buffer[pdu_len], + invoke_id, data); pdu_len += len; /* will it fit in the sender? note: if there is a bottleneck router in between us and the destination, we won't know unless we have a way to check for that and update the max_apdu in the address binding table. */ - if ((unsigned) pdu_len < max_apdu) { - tsm_set_confirmed_unsegmented_transaction(invoke_id, &dest, - &npdu_data, &Handler_Transmit_Buffer[0], (uint16_t) pdu_len); - bytes_sent = - datalink_send_pdu(&dest, &npdu_data, - &Handler_Transmit_Buffer[0], pdu_len); + if ((unsigned)pdu_len < max_apdu) { + tsm_set_confirmed_unsegmented_transaction( + invoke_id, &dest, &npdu_data, &Handler_Transmit_Buffer[0], + (uint16_t)pdu_len); + bytes_sent = datalink_send_pdu( + &dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); #if PRINT_ENABLED if (bytes_sent <= 0) { - fprintf(stderr, + fprintf( + stderr, "Failed to Send ConfirmedEventNotification Request (%s)!\n", strerror(errno)); } @@ -104,8 +102,8 @@ uint8_t Send_CEvent_Notify( invoke_id = 0; #if PRINT_ENABLED fprintf(stderr, - "Failed to Send ConfirmedEventNotification Request " - "(exceeds destination maximum APDU)!\n"); + "Failed to Send ConfirmedEventNotification Request " + "(exceeds destination maximum APDU)!\n"); #endif } } diff --git a/demo/handler/s_cov.c b/demo/handler/s_cov.c index ceaae4b8..5081a698 100644 --- a/demo/handler/s_cov.c +++ b/demo/handler/s_cov.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2008 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2008 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -42,7 +42,8 @@ #include "txbuf.h" #include "client.h" -/** @file s_cov.c Send a Change of Value (COV) update or a Subscribe COV request. */ +/** @file s_cov.c Send a Change of Value (COV) update or a Subscribe COV + * request. */ /** Encodes an Unconfirmed COV Notification. * @ingroup DSCOV @@ -54,12 +55,9 @@ * @param cov_data [in] The COV update information to be encoded. * @return Size of the message sent (bytes), or a negative value on error. */ -int ucov_notify_encode_pdu( - uint8_t * buffer, - unsigned buffer_len, - BACNET_ADDRESS * dest, - BACNET_NPDU_DATA * npdu_data, - BACNET_COV_DATA * cov_data) +int ucov_notify_encode_pdu(uint8_t* buffer, unsigned buffer_len, + BACNET_ADDRESS* dest, BACNET_NPDU_DATA* npdu_data, + BACNET_COV_DATA* cov_data) { int len = 0; int pdu_len = 0; @@ -73,8 +71,8 @@ int ucov_notify_encode_pdu( pdu_len = npdu_encode_pdu(&buffer[0], dest, &my_address, npdu_data); /* encode the APDU portion of the packet */ - len = ucov_notify_encode_apdu(&buffer[pdu_len], - buffer_len - pdu_len, cov_data); + len = ucov_notify_encode_apdu(&buffer[pdu_len], buffer_len - pdu_len, + cov_data); if (len) { pdu_len += len; } else { @@ -92,18 +90,16 @@ int ucov_notify_encode_pdu( * @param cov_data [in] The COV update information to be encoded. * @return Size of the message sent (bytes), or a negative value on error. */ -int Send_UCOV_Notify( - uint8_t * buffer, - unsigned buffer_len, - BACNET_COV_DATA * cov_data) +int Send_UCOV_Notify(uint8_t* buffer, unsigned buffer_len, + BACNET_COV_DATA* cov_data) { int pdu_len = 0; BACNET_ADDRESS dest; int bytes_sent = 0; BACNET_NPDU_DATA npdu_data; - pdu_len = ucov_notify_encode_pdu(buffer, buffer_len, &dest, &npdu_data, - cov_data); + pdu_len = + ucov_notify_encode_pdu(buffer, buffer_len, &dest, &npdu_data, cov_data); bytes_sent = datalink_send_pdu(&dest, &npdu_data, &buffer[0], pdu_len); return bytes_sent; @@ -117,9 +113,8 @@ int Send_UCOV_Notify( * @return invoke id of outgoing message, or 0 if communication is disabled or * no slot is available from the tsm for sending. */ -uint8_t Send_COV_Subscribe( - uint32_t device_id, - BACNET_SUBSCRIBE_COV_DATA * cov_data) +uint8_t Send_COV_Subscribe(uint32_t device_id, + BACNET_SUBSCRIBE_COV_DATA* cov_data) { BACNET_ADDRESS dest; BACNET_ADDRESS my_address; @@ -143,29 +138,28 @@ uint8_t Send_COV_Subscribe( /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL); - pdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address, - &npdu_data); + pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, + &my_address, &npdu_data); /* encode the APDU portion of the packet */ - len = - cov_subscribe_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - sizeof(Handler_Transmit_Buffer)-pdu_len, invoke_id, cov_data); + len = cov_subscribe_encode_apdu( + &Handler_Transmit_Buffer[pdu_len], + sizeof(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 us and the destination, we won't know unless we have a way to check for that and update the max_apdu in the address binding table. */ - if ((unsigned) pdu_len < max_apdu) { - tsm_set_confirmed_unsegmented_transaction(invoke_id, &dest, - &npdu_data, &Handler_Transmit_Buffer[0], (uint16_t) pdu_len); - bytes_sent = - datalink_send_pdu(&dest, &npdu_data, - &Handler_Transmit_Buffer[0], pdu_len); + if ((unsigned)pdu_len < max_apdu) { + tsm_set_confirmed_unsegmented_transaction( + invoke_id, &dest, &npdu_data, &Handler_Transmit_Buffer[0], + (uint16_t)pdu_len); + bytes_sent = datalink_send_pdu( + &dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); if (bytes_sent <= 0) { #if PRINT_ENABLED fprintf(stderr, "Failed to Send SubscribeCOV Request (%s)!\n", - strerror(errno)); + strerror(errno)); #endif } } else { @@ -173,8 +167,8 @@ uint8_t Send_COV_Subscribe( invoke_id = 0; #if PRINT_ENABLED fprintf(stderr, - "Failed to Send SubscribeCOV Request " - "(exceeds destination maximum APDU)!\n"); + "Failed to Send SubscribeCOV Request " + "(exceeds destination maximum APDU)!\n"); #endif } } diff --git a/demo/handler/s_dcc.c b/demo/handler/s_dcc.c index 1f4653f7..f743c191 100644 --- a/demo/handler/s_dcc.c +++ b/demo/handler/s_dcc.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2006 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2006 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -56,11 +56,9 @@ */ uint8_t Send_Device_Communication_Control_Request( - uint32_t device_id, - uint16_t timeDuration, /* 0=optional */ - BACNET_COMMUNICATION_ENABLE_DISABLE state, - char *password) -{ /* NULL=optional */ + uint32_t device_id, uint16_t timeDuration, /* 0=optional */ + BACNET_COMMUNICATION_ENABLE_DISABLE state, char *password) +{ /* NULL=optional */ BACNET_ADDRESS dest; BACNET_ADDRESS my_address; unsigned max_apdu = 0; @@ -85,29 +83,29 @@ uint8_t Send_Device_Communication_Control_Request( /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL); - pdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address, - &npdu_data); + pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, + &my_address, &npdu_data); /* encode the APDU portion of the packet */ characterstring_init_ansi(&password_string, password); - len = - dcc_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id, - timeDuration, state, password ? &password_string : NULL); + len = dcc_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id, + timeDuration, state, + password ? &password_string : NULL); pdu_len += len; /* will it fit in the sender? note: if there is a bottleneck router in between us and the destination, we won't know unless we have a way to check for that and update the max_apdu in the address binding table. */ - if ((unsigned) pdu_len < max_apdu) { - tsm_set_confirmed_unsegmented_transaction(invoke_id, &dest, - &npdu_data, &Handler_Transmit_Buffer[0], (uint16_t) pdu_len); - bytes_sent = - datalink_send_pdu(&dest, &npdu_data, - &Handler_Transmit_Buffer[0], pdu_len); + if ((unsigned)pdu_len < max_apdu) { + tsm_set_confirmed_unsegmented_transaction( + invoke_id, &dest, &npdu_data, &Handler_Transmit_Buffer[0], + (uint16_t)pdu_len); + bytes_sent = datalink_send_pdu( + &dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); #if PRINT_ENABLED if (bytes_sent <= 0) - fprintf(stderr, + fprintf( + stderr, "Failed to Send DeviceCommunicationControl Request (%s)!\n", strerror(errno)); #endif @@ -116,8 +114,8 @@ uint8_t Send_Device_Communication_Control_Request( invoke_id = 0; #if PRINT_ENABLED fprintf(stderr, - "Failed to Send DeviceCommunicationControl Request " - "(exceeds destination maximum APDU)!\n"); + "Failed to Send DeviceCommunicationControl Request " + "(exceeds destination maximum APDU)!\n"); #endif } } diff --git a/demo/handler/s_error.c b/demo/handler/s_error.c index 091b98de..21f803d5 100644 --- a/demo/handler/s_error.c +++ b/demo/handler/s_error.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2016 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2016 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -42,7 +42,6 @@ #include "handlers.h" #include "client.h" - /** Encodes an Error message * @param buffer The buffer to build the message for sending. * @param dest - Destination address to send the message @@ -54,15 +53,11 @@ * * @return Size of the message sent (bytes), or a negative value on error. */ -int error_encode_pdu( - uint8_t * buffer, - BACNET_ADDRESS * dest, - BACNET_ADDRESS * src, - BACNET_NPDU_DATA * npdu_data, - uint8_t invoke_id, - BACNET_CONFIRMED_SERVICE service, - BACNET_ERROR_CLASS error_class, - BACNET_ERROR_CODE error_code) +int error_encode_pdu(uint8_t *buffer, BACNET_ADDRESS *dest, BACNET_ADDRESS *src, + BACNET_NPDU_DATA *npdu_data, uint8_t invoke_id, + BACNET_CONFIRMED_SERVICE service, + BACNET_ERROR_CLASS error_class, + BACNET_ERROR_CODE error_code) { int len = 0; int pdu_len = 0; @@ -72,8 +67,8 @@ int error_encode_pdu( pdu_len = npdu_encode_pdu(&buffer[0], dest, src, npdu_data); /* encode the APDU portion of the packet */ - len = bacerror_encode_apdu(&buffer[pdu_len], invoke_id, - service, error_class, error_code); + len = bacerror_encode_apdu(&buffer[pdu_len], invoke_id, service, + error_class, error_code); pdu_len += len; return pdu_len; @@ -88,13 +83,10 @@ int error_encode_pdu( * * @return Size of the message sent (bytes), or a negative value on error. */ -int Send_Error_To_Network( - uint8_t * buffer, - BACNET_ADDRESS *dest, - uint8_t invoke_id, - BACNET_CONFIRMED_SERVICE service, - BACNET_ERROR_CLASS error_class, - BACNET_ERROR_CODE error_code) +int Send_Error_To_Network(uint8_t *buffer, BACNET_ADDRESS *dest, + uint8_t invoke_id, BACNET_CONFIRMED_SERVICE service, + BACNET_ERROR_CLASS error_class, + BACNET_ERROR_CODE error_code) { int pdu_len = 0; BACNET_ADDRESS src; @@ -102,8 +94,8 @@ int Send_Error_To_Network( BACNET_NPDU_DATA npdu_data; datalink_get_my_address(&src); - pdu_len = error_encode_pdu(buffer, dest, &src, &npdu_data, - invoke_id, service, error_class, error_code); + pdu_len = error_encode_pdu(buffer, dest, &src, &npdu_data, invoke_id, + service, error_class, error_code); bytes_sent = datalink_send_pdu(dest, &npdu_data, &buffer[0], pdu_len); return bytes_sent; diff --git a/demo/handler/s_get_alarm_sum.c b/demo/handler/s_get_alarm_sum.c index 1477ea6a..f1042803 100644 --- a/demo/handler/s_get_alarm_sum.c +++ b/demo/handler/s_get_alarm_sum.c @@ -52,9 +52,7 @@ #include "client.h" #include "get_alarm_sum.h" -uint8_t Send_Get_Alarm_Summary_Address( - BACNET_ADDRESS *dest, - uint16_t max_apdu) +uint8_t Send_Get_Alarm_Summary_Address(BACNET_ADDRESS *dest, uint16_t max_apdu) { int len = 0; int pdu_len = 0; @@ -72,36 +70,35 @@ uint8_t Send_Get_Alarm_Summary_Address( /* encode the NPDU portion of the packet */ npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL); - pdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], dest, - &my_address, &npdu_data); + pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], dest, + &my_address, &npdu_data); /* encode the APDU portion of the packet */ len = get_alarm_summary_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - invoke_id); + invoke_id); pdu_len += len; - if ((uint16_t) pdu_len < max_apdu) { - tsm_set_confirmed_unsegmented_transaction(invoke_id, dest, - &npdu_data, &Handler_Transmit_Buffer[0], - (uint16_t) pdu_len); + if ((uint16_t)pdu_len < max_apdu) { + tsm_set_confirmed_unsegmented_transaction( + invoke_id, dest, &npdu_data, &Handler_Transmit_Buffer[0], + (uint16_t)pdu_len); #if PRINT_ENABLED bytes_sent = #endif - datalink_send_pdu(dest, &npdu_data, - &Handler_Transmit_Buffer[0], pdu_len); + datalink_send_pdu(dest, &npdu_data, &Handler_Transmit_Buffer[0], + pdu_len); #if PRINT_ENABLED if (bytes_sent <= 0) fprintf(stderr, - "Failed to Send Get Alarm Summary Request (%s)!\n", - strerror(errno)); + "Failed to Send Get Alarm Summary Request (%s)!\n", + strerror(errno)); #endif } else { tsm_free_invoke_id(invoke_id); invoke_id = 0; #if PRINT_ENABLED fprintf(stderr, - "Failed to Send Get Alarm Summary Request " - "(exceeds destination maximum APDU)!\n"); + "Failed to Send Get Alarm Summary Request " + "(exceeds destination maximum APDU)!\n"); #endif } } @@ -109,8 +106,7 @@ uint8_t Send_Get_Alarm_Summary_Address( return invoke_id; } -uint8_t Send_Get_Alarm_Summary( - uint32_t device_id) +uint8_t Send_Get_Alarm_Summary(uint32_t device_id) { BACNET_ADDRESS dest; unsigned max_apdu = 0; @@ -120,8 +116,7 @@ uint8_t Send_Get_Alarm_Summary( /* is the device bound? */ status = address_get_by_device(device_id, &max_apdu, &dest); if (status) { - invoke_id = Send_Get_Alarm_Summary_Address( - &dest, max_apdu); + invoke_id = Send_Get_Alarm_Summary_Address(&dest, max_apdu); } return invoke_id; diff --git a/demo/handler/s_get_event.c b/demo/handler/s_get_event.c index 5a75225e..ce3cef07 100644 --- a/demo/handler/s_get_event.c +++ b/demo/handler/s_get_event.c @@ -55,9 +55,8 @@ #include "getevent.h" uint8_t Send_Get_Event_Information_Address( - BACNET_ADDRESS *dest, - uint16_t max_apdu, - BACNET_OBJECT_ID * lastReceivedObjectIdentifier) + BACNET_ADDRESS *dest, uint16_t max_apdu, + BACNET_OBJECT_ID *lastReceivedObjectIdentifier) { int len = 0; int pdu_len = 0; @@ -74,34 +73,35 @@ uint8_t Send_Get_Event_Information_Address( datalink_get_my_address(&my_address); /* encode the NPDU portion of the packet */ npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL); - pdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], dest, - &my_address, &npdu_data); + pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], dest, + &my_address, &npdu_data); /* encode the APDU portion of the packet */ - len = getevent_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - invoke_id, lastReceivedObjectIdentifier); + len = getevent_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id, + lastReceivedObjectIdentifier); pdu_len += len; - if ((uint16_t) pdu_len < max_apdu) { - tsm_set_confirmed_unsegmented_transaction(invoke_id, dest, - &npdu_data, &Handler_Transmit_Buffer[0], (uint16_t) pdu_len); + if ((uint16_t)pdu_len < max_apdu) { + tsm_set_confirmed_unsegmented_transaction( + invoke_id, dest, &npdu_data, &Handler_Transmit_Buffer[0], + (uint16_t)pdu_len); #if PRINT_ENABLED bytes_sent = #endif - datalink_send_pdu(dest, &npdu_data, - &Handler_Transmit_Buffer[0], pdu_len); + datalink_send_pdu(dest, &npdu_data, &Handler_Transmit_Buffer[0], + pdu_len); #if PRINT_ENABLED if (bytes_sent <= 0) - fprintf(stderr, "Failed to Send Get Event Information Request (%s)!\n", - strerror(errno)); + fprintf(stderr, + "Failed to Send Get Event Information Request (%s)!\n", + strerror(errno)); #endif } else { tsm_free_invoke_id(invoke_id); invoke_id = 0; #if PRINT_ENABLED fprintf(stderr, - "Failed to Send Get Event Information Request " - "(exceeds destination maximum APDU)!\n"); + "Failed to Send Get Event Information Request " + "(exceeds destination maximum APDU)!\n"); #endif } } @@ -110,8 +110,7 @@ uint8_t Send_Get_Event_Information_Address( } uint8_t Send_Get_Event_Information( - uint32_t device_id, - BACNET_OBJECT_ID * lastReceivedObjectIdentifier) + uint32_t device_id, BACNET_OBJECT_ID *lastReceivedObjectIdentifier) { BACNET_ADDRESS dest = {0}; unsigned max_apdu = 0; diff --git a/demo/handler/s_getevent.c b/demo/handler/s_getevent.c index 1c0a870c..0d967917 100644 --- a/demo/handler/s_getevent.c +++ b/demo/handler/s_getevent.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2015 bowe -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2015 bowe + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -46,13 +46,12 @@ /** @file s_getevent.c Send a GetEventInformation request. */ -/** Send a GetEventInformation request to a remote network for a specific device, a range, - * or any device. +/** Send a GetEventInformation request to a remote network for a specific + * device, a range, or any device. * @param target_address [in] BACnet address of target or broadcast */ -uint8_t Send_GetEvent( - BACNET_ADDRESS * target_address, - BACNET_OBJECT_ID * lastReceivedObjectIdentifier) +uint8_t Send_GetEvent(BACNET_ADDRESS* target_address, + BACNET_OBJECT_ID* lastReceivedObjectIdentifier) { int len = 0; int pdu_len = 0; @@ -65,29 +64,28 @@ uint8_t Send_GetEvent( /* encode the NPDU portion of the packet */ npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); - pdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], target_address, - &my_address, &npdu_data); + pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], target_address, + &my_address, &npdu_data); invoke_id = tsm_next_free_invokeID(); if (invoke_id) { /* encode the APDU portion of the packet */ - len = - getevent_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id, lastReceivedObjectIdentifier); + len = getevent_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id, + lastReceivedObjectIdentifier); pdu_len += len; - bytes_sent = - datalink_send_pdu(target_address, &npdu_data, - &Handler_Transmit_Buffer[0], pdu_len); - #if PRINT_ENABLED - if (bytes_sent <= 0) - fprintf(stderr, "Failed to Send GetEventInformation Request (%s)!\n", - strerror(errno)); - #endif - } else { - tsm_free_invoke_id(invoke_id); - invoke_id = 0; + bytes_sent = datalink_send_pdu(target_address, &npdu_data, + &Handler_Transmit_Buffer[0], pdu_len); #if PRINT_ENABLED + if (bytes_sent <= 0) fprintf(stderr, + "Failed to Send GetEventInformation Request (%s)!\n", + strerror(errno)); +#endif + } else { + tsm_free_invoke_id(invoke_id); + invoke_id = 0; +#if PRINT_ENABLED + fprintf(stderr, "Failed to Send GetEventInformation Request " "(exceeds destination maximum APDU)!\n"); #endif @@ -97,7 +95,7 @@ uint8_t Send_GetEvent( /** Send a global GetEventInformation request. */ -uint8_t Send_GetEvent_Global( void ) +uint8_t Send_GetEvent_Global(void) { BACNET_ADDRESS dest; @@ -108,4 +106,3 @@ uint8_t Send_GetEvent_Global( void ) return Send_GetEvent(&dest, NULL); } - diff --git a/demo/handler/s_iam.c b/demo/handler/s_iam.c index d7ae6f45..10440d22 100644 --- a/demo/handler/s_iam.c +++ b/demo/handler/s_iam.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2008 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2008 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -51,12 +51,9 @@ * @param segmentation [in] #BACNET_SEGMENTATION enumeration * @param vendor_id [in] BACnet vendor ID 0-65535 */ -void Send_I_Am_To_Network( - BACNET_ADDRESS * target_address, - uint32_t device_id, - unsigned int max_apdu, - int segmentation, - uint16_t vendor_id) +void Send_I_Am_To_Network(BACNET_ADDRESS* target_address, uint32_t device_id, + unsigned int max_apdu, int segmentation, + uint16_t vendor_id) { int len = 0; int pdu_len = 0; @@ -68,25 +65,20 @@ void Send_I_Am_To_Network( /* encode the NPDU portion of the packet */ npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); - pdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], target_address, - &my_address, &npdu_data); + pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], target_address, + &my_address, &npdu_data); /* encode the APDU portion of the packet */ /* encode the APDU portion of the packet */ - len = - iam_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - device_id, max_apdu, segmentation, vendor_id); + len = iam_encode_apdu(&Handler_Transmit_Buffer[pdu_len], device_id, + max_apdu, segmentation, vendor_id); pdu_len += len; - bytes_sent = - datalink_send_pdu(target_address, &npdu_data, - &Handler_Transmit_Buffer[0], pdu_len); + bytes_sent = datalink_send_pdu(target_address, &npdu_data, + &Handler_Transmit_Buffer[0], pdu_len); if (bytes_sent <= 0) { #if PRINT_ENABLED - fprintf(stderr, "Failed to Send I-Am Request (%s)!\n", - strerror(errno)); + fprintf(stderr, "Failed to Send I-Am Request (%s)!\n", strerror(errno)); #endif } - } /** Encode an I Am message to be broadcast. @@ -95,10 +87,8 @@ void Send_I_Am_To_Network( * @param npdu_data [out] The NPDU structure describing the message. * @return The length of the message in buffer[]. */ -int iam_encode_pdu( - uint8_t * buffer, - BACNET_ADDRESS * dest, - BACNET_NPDU_DATA * npdu_data) +int iam_encode_pdu(uint8_t* buffer, BACNET_ADDRESS* dest, + BACNET_NPDU_DATA* npdu_data) { int len = 0; int pdu_len = 0; @@ -111,9 +101,9 @@ int iam_encode_pdu( pdu_len = npdu_encode_pdu(&buffer[0], dest, &my_address, npdu_data); /* encode the APDU portion of the packet */ - len = - iam_encode_apdu(&buffer[pdu_len], Device_Object_Instance_Number(), - MAX_APDU, SEGMENTATION_NONE, Device_Vendor_Identifier()); + len = iam_encode_apdu(&buffer[pdu_len], Device_Object_Instance_Number(), + MAX_APDU, SEGMENTATION_NONE, + Device_Vendor_Identifier()); pdu_len += len; return pdu_len; @@ -124,8 +114,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) +void Send_I_Am(uint8_t* buffer) { int pdu_len = 0; BACNET_ADDRESS dest; @@ -165,11 +154,8 @@ void Send_I_Am( * @param npdu_data [out] The NPDU structure describing the message. * @return The length of the message in buffer[]. */ -int iam_unicast_encode_pdu( - uint8_t * buffer, - BACNET_ADDRESS * src, - BACNET_ADDRESS * dest, - BACNET_NPDU_DATA * npdu_data) +int iam_unicast_encode_pdu(uint8_t* buffer, BACNET_ADDRESS* src, + BACNET_ADDRESS* dest, BACNET_NPDU_DATA* npdu_data) { int npdu_len = 0; int apdu_len = 0; @@ -184,9 +170,9 @@ int iam_unicast_encode_pdu( npdu_encode_npdu_data(npdu_data, false, MESSAGE_PRIORITY_NORMAL); 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(), - MAX_APDU, SEGMENTATION_NONE, Device_Vendor_Identifier()); + apdu_len = iam_encode_apdu(&buffer[npdu_len], + Device_Object_Instance_Number(), MAX_APDU, + SEGMENTATION_NONE, Device_Vendor_Identifier()); pdu_len = npdu_len + apdu_len; return pdu_len; @@ -203,9 +189,7 @@ int iam_unicast_encode_pdu( * @param buffer [in] The buffer to use for building and sending the message. * @param src [in] The source address information from service handler. */ -void Send_I_Am_Unicast( - uint8_t * buffer, - BACNET_ADDRESS * src) +void Send_I_Am_Unicast(uint8_t* buffer, BACNET_ADDRESS* src) { int pdu_len = 0; BACNET_ADDRESS dest; diff --git a/demo/handler/s_ihave.c b/demo/handler/s_ihave.c index cbd16ba1..11864ce5 100644 --- a/demo/handler/s_ihave.c +++ b/demo/handler/s_ihave.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2006 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2006 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -53,11 +53,8 @@ * @param object_instance [in] The Object ID that I Have. * @param object_name [in] The Name of the Object I Have. */ -void Send_I_Have( - uint32_t device_id, - BACNET_OBJECT_TYPE object_type, - uint32_t object_instance, - BACNET_CHARACTER_STRING * object_name) +void Send_I_Have(uint32_t device_id, BACNET_OBJECT_TYPE object_type, + uint32_t object_instance, BACNET_CHARACTER_STRING* object_name) { int len = 0; int pdu_len = 0; @@ -75,9 +72,8 @@ void Send_I_Have( 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(&Handler_Transmit_Buffer[0], &dest, &my_address, - &npdu_data); + pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address, + &npdu_data); /* encode the APDU portion of the packet */ data.device_id.type = OBJECT_DEVICE; @@ -88,13 +84,11 @@ void Send_I_Have( len = ihave_encode_apdu(&Handler_Transmit_Buffer[pdu_len], &data); pdu_len += len; /* send the data */ - bytes_sent = - datalink_send_pdu(&dest, &npdu_data, &Handler_Transmit_Buffer[0], - pdu_len); + bytes_sent = datalink_send_pdu(&dest, &npdu_data, + &Handler_Transmit_Buffer[0], pdu_len); if (bytes_sent <= 0) { #if PRINT_ENABLED - fprintf(stderr, "Failed to Send I-Have Reply (%s)!\n", - strerror(errno)); + fprintf(stderr, "Failed to Send I-Have Reply (%s)!\n", strerror(errno)); #endif } } diff --git a/demo/handler/s_lso.c b/demo/handler/s_lso.c index 098041b9..3527d859 100644 --- a/demo/handler/s_lso.c +++ b/demo/handler/s_lso.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2009 John Minack -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2009 John Minack + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -48,10 +48,8 @@ /* returns the invoke ID for confirmed request, or zero on failure */ - -uint8_t Send_Life_Safety_Operation_Data( - uint32_t device_id, - BACNET_LSO_DATA * data) +uint8_t Send_Life_Safety_Operation_Data(uint32_t device_id, + BACNET_LSO_DATA* data) { BACNET_ADDRESS dest; BACNET_ADDRESS my_address; @@ -75,36 +73,34 @@ uint8_t Send_Life_Safety_Operation_Data( /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL); - pdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address, - &npdu_data); + pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, + &my_address, &npdu_data); len = - lso_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id, - data); + lso_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id, data); pdu_len += len; /* will it fit in the sender? note: if there is a bottleneck router in between us and the destination, we won't know unless we have a way to check for that and update the max_apdu in the address binding table. */ - if ((unsigned) pdu_len < max_apdu) { - tsm_set_confirmed_unsegmented_transaction(invoke_id, &dest, - &npdu_data, &Handler_Transmit_Buffer[0], (uint16_t) pdu_len); - bytes_sent = - datalink_send_pdu(&dest, &npdu_data, - &Handler_Transmit_Buffer[0], pdu_len); + if ((unsigned)pdu_len < max_apdu) { + tsm_set_confirmed_unsegmented_transaction( + invoke_id, &dest, &npdu_data, &Handler_Transmit_Buffer[0], + (uint16_t)pdu_len); + bytes_sent = datalink_send_pdu( + &dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); #if PRINT_ENABLED if (bytes_sent <= 0) fprintf(stderr, "Failed to Send Life Safe Op Request (%s)!\n", - strerror(errno)); + strerror(errno)); #endif } else { tsm_free_invoke_id(invoke_id); invoke_id = 0; #if PRINT_ENABLED fprintf(stderr, - "Failed to Send Life Safe Op Request " - "(exceeds destination maximum APDU)!\n"); + "Failed to Send Life Safe Op Request " + "(exceeds destination maximum APDU)!\n"); #endif } } diff --git a/demo/handler/s_ptransfer.c b/demo/handler/s_ptransfer.c index d1663c29..c96c1e13 100644 --- a/demo/handler/s_ptransfer.c +++ b/demo/handler/s_ptransfer.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2006 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2006 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -48,20 +48,14 @@ /** @file s_ptransfer.c Send a Private Transfer request. */ /* This function is exported. Hence this unnecessary prototype. */ -uint8_t Send_Private_Transfer_Request( - uint32_t device_id, - uint16_t vendor_id, - uint32_t service_number, - char block_number, - DATABLOCK * block); +uint8_t Send_Private_Transfer_Request(uint32_t device_id, uint16_t vendor_id, + uint32_t service_number, + char block_number, DATABLOCK *block); -uint8_t Send_Private_Transfer_Request( - uint32_t device_id, - uint16_t vendor_id, - uint32_t service_number, - char block_number, - DATABLOCK * block) -{ /* NULL=optional */ +uint8_t Send_Private_Transfer_Request(uint32_t device_id, uint16_t vendor_id, + uint32_t service_number, + char block_number, DATABLOCK *block) +{ /* NULL=optional */ BACNET_ADDRESS dest; BACNET_ADDRESS my_address; unsigned max_apdu = 0; @@ -71,7 +65,8 @@ uint8_t Send_Private_Transfer_Request( int pdu_len = 0; int bytes_sent = 0; BACNET_NPDU_DATA npdu_data; - static uint8_t pt_req_buffer[300]; /* Somewhere to build the request packet */ + static uint8_t + pt_req_buffer[300]; /* Somewhere to build the request packet */ BACNET_PRIVATE_TRANSFER_DATA pt_block; BACNET_CHARACTER_STRING bsTemp; @@ -88,34 +83,34 @@ uint8_t Send_Private_Transfer_Request( /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL); - pdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address, - &npdu_data); + pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, + &my_address, &npdu_data); /* encode the APDU portion of the packet */ pt_block.vendorID = vendor_id; pt_block.serviceNumber = service_number; if (service_number == MY_SVC_READ) { - len += encode_application_unsigned(&pt_req_buffer[len], block_number); /* The block number we want to retrieve */ + len += encode_application_unsigned( + &pt_req_buffer[len], + block_number); /* The block number we want to retrieve */ } else { - len += encode_application_unsigned(&pt_req_buffer[len], block_number); /* The block number */ - len += encode_application_unsigned(&pt_req_buffer[len], block->cMyByte1); /* And Then the block contents */ - len += - encode_application_unsigned(&pt_req_buffer[len], - block->cMyByte2); - len += - encode_application_real(&pt_req_buffer[len], block->fMyReal); - characterstring_init_ansi(&bsTemp, (char *) block->sMyString); - len += - encode_application_character_string(&pt_req_buffer[len], - &bsTemp); + len += encode_application_unsigned( + &pt_req_buffer[len], block_number); /* The block number */ + len += encode_application_unsigned( + &pt_req_buffer[len], + block->cMyByte1); /* And Then the block contents */ + len += encode_application_unsigned(&pt_req_buffer[len], + block->cMyByte2); + len += encode_application_real(&pt_req_buffer[len], block->fMyReal); + characterstring_init_ansi(&bsTemp, (char *)block->sMyString); + len += encode_application_character_string(&pt_req_buffer[len], + &bsTemp); } pt_block.serviceParameters = &pt_req_buffer[0]; pt_block.serviceParametersLen = len; - len = - ptransfer_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id, - &pt_block); + len = ptransfer_encode_apdu(&Handler_Transmit_Buffer[pdu_len], + invoke_id, &pt_block); pdu_len += len; /* will it fit in the sender? @@ -124,25 +119,25 @@ uint8_t Send_Private_Transfer_Request( we have a way to check for that and update the max_apdu in the address binding table. */ - if ((unsigned) pdu_len < max_apdu) { - tsm_set_confirmed_unsegmented_transaction(invoke_id, &dest, - &npdu_data, &Handler_Transmit_Buffer[0], (uint16_t) pdu_len); - bytes_sent = - datalink_send_pdu(&dest, &npdu_data, - &Handler_Transmit_Buffer[0], pdu_len); + if ((unsigned)pdu_len < max_apdu) { + tsm_set_confirmed_unsegmented_transaction( + invoke_id, &dest, &npdu_data, &Handler_Transmit_Buffer[0], + (uint16_t)pdu_len); + bytes_sent = datalink_send_pdu( + &dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); #if PRINT_ENABLED if (bytes_sent <= 0) fprintf(stderr, - "Failed to Send Private Transfer Request (%s)!\n", - strerror(errno)); + "Failed to Send Private Transfer Request (%s)!\n", + strerror(errno)); #endif } else { tsm_free_invoke_id(invoke_id); invoke_id = 0; #if PRINT_ENABLED fprintf(stderr, - "Failed to Send Private Transfer Request " - "(exceeds destination maximum APDU)!\n"); + "Failed to Send Private Transfer Request " + "(exceeds destination maximum APDU)!\n"); #endif } } diff --git a/demo/handler/s_rd.c b/demo/handler/s_rd.c index f2fdc5b0..08664ca2 100644 --- a/demo/handler/s_rd.c +++ b/demo/handler/s_rd.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2005 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2005 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -49,14 +49,14 @@ * @ingroup DMRD * * @param device_id [in] The index to the device address in our address cache. - * @param state [in] Specifies the desired state of the device after reinitialization. + * @param state [in] Specifies the desired state of the device after + * reinitialization. * @param password [in] Optional password, up to 20 chars. * @return The invokeID of the transmitted message, or 0 on failure. */ -uint8_t Send_Reinitialize_Device_Request( - uint32_t device_id, - BACNET_REINITIALIZED_STATE state, - char *password) +uint8_t Send_Reinitialize_Device_Request(uint32_t device_id, + BACNET_REINITIALIZED_STATE state, + char *password) { BACNET_ADDRESS dest; BACNET_ADDRESS my_address; @@ -82,39 +82,37 @@ uint8_t Send_Reinitialize_Device_Request( /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL); - pdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address, - &npdu_data); + pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, + &my_address, &npdu_data); /* encode the APDU portion of the packet */ characterstring_init_ansi(&password_string, password); - len = - rd_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id, state, - password ? &password_string : NULL); + len = rd_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id, + state, password ? &password_string : NULL); pdu_len += len; /* will it fit in the sender? note: if there is a bottleneck router in between us and the destination, we won't know unless we have a way to check for that and update the max_apdu in the address binding table. */ - if ((unsigned) pdu_len < max_apdu) { - tsm_set_confirmed_unsegmented_transaction(invoke_id, &dest, - &npdu_data, &Handler_Transmit_Buffer[0], (uint16_t) pdu_len); - bytes_sent = - datalink_send_pdu(&dest, &npdu_data, - &Handler_Transmit_Buffer[0], pdu_len); + if ((unsigned)pdu_len < max_apdu) { + tsm_set_confirmed_unsegmented_transaction( + invoke_id, &dest, &npdu_data, &Handler_Transmit_Buffer[0], + (uint16_t)pdu_len); + bytes_sent = datalink_send_pdu( + &dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); #if PRINT_ENABLED if (bytes_sent <= 0) fprintf(stderr, - "Failed to Send ReinitializeDevice Request (%s)!\n", - strerror(errno)); + "Failed to Send ReinitializeDevice Request (%s)!\n", + strerror(errno)); #endif } else { tsm_free_invoke_id(invoke_id); invoke_id = 0; #if PRINT_ENABLED fprintf(stderr, - "Failed to Send ReinitializeDevice Request " - "(exceeds destination maximum APDU)!\n"); + "Failed to Send ReinitializeDevice Request " + "(exceeds destination maximum APDU)!\n"); #endif } } diff --git a/demo/handler/s_readrange.c b/demo/handler/s_readrange.c index e342bb78..efac05a8 100644 --- a/demo/handler/s_readrange.c +++ b/demo/handler/s_readrange.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2008 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2008 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -47,9 +47,8 @@ /** @file s_readrange.c Send a ReadRange request. */ /* returns invoke id of 0 if device is not bound or no tsm available */ -uint8_t Send_ReadRange_Request( - uint32_t device_id, /* destination device */ - BACNET_READ_RANGE_DATA * read_access_data) +uint8_t Send_ReadRange_Request(uint32_t device_id, /* destination device */ + BACNET_READ_RANGE_DATA* read_access_data) { BACNET_ADDRESS dest; BACNET_ADDRESS my_address; @@ -74,14 +73,12 @@ uint8_t Send_ReadRange_Request( /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL); - pdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address, - &npdu_data); + pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, + &my_address, &npdu_data); /* encode the APDU portion of the packet */ - len = - rr_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id, - read_access_data); + len = rr_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id, + read_access_data); if (len <= 0) { return 0; } @@ -92,23 +89,24 @@ uint8_t Send_ReadRange_Request( us and the destination, we won't know unless we have a way to check for that and update the max_apdu in the address binding table. */ - if ((unsigned) pdu_len < max_apdu) { - tsm_set_confirmed_unsegmented_transaction(invoke_id, &dest, - &npdu_data, &Handler_Transmit_Buffer[0], (uint16_t) pdu_len); - bytes_sent = - datalink_send_pdu(&dest, &npdu_data, - &Handler_Transmit_Buffer[0], pdu_len); + if ((unsigned)pdu_len < max_apdu) { + tsm_set_confirmed_unsegmented_transaction( + invoke_id, &dest, &npdu_data, &Handler_Transmit_Buffer[0], + (uint16_t)pdu_len); + bytes_sent = datalink_send_pdu( + &dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); #if PRINT_ENABLED if (bytes_sent <= 0) fprintf(stderr, "Failed to Send ReadRange Request (%s)!\n", - strerror(errno)); + strerror(errno)); #endif } else { tsm_free_invoke_id(invoke_id); invoke_id = 0; #if PRINT_ENABLED fprintf(stderr, - "Failed to Send ReadRange Request (exceeds destination maximum APDU)!\n"); + "Failed to Send ReadRange Request (exceeds destination " + "maximum APDU)!\n"); #endif } } diff --git a/demo/handler/s_router.c b/demo/handler/s_router.c index 3396505f..9e8a6b41 100644 --- a/demo/handler/s_router.c +++ b/demo/handler/s_router.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2005 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2005 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -43,7 +43,8 @@ #include "client.h" #include "debug.h" -/** @file s_router.c Methods to send various BACnet Router Network Layer Messages. */ +/** @file s_router.c Methods to send various BACnet Router Network Layer + * Messages. */ /** Initialize an npdu_data structure with given parameters and good defaults, * and add the Network Layer Message fields. @@ -52,30 +53,29 @@ * APDU instead of a Network Layer Message. * * @param npdu_data [out] Returns a filled-out structure with information - * provided by the other arguments and good defaults. + * provided by the other arguments and + * good defaults. * @param network_message_type [in] The type of Network Layer Message. * @param data_expecting_reply [in] True if message should have a reply. * @param priority [in] One of the 4 priorities defined in section 6.2.2, * like B'11' = Life Safety message */ static void npdu_encode_npdu_network( - BACNET_NPDU_DATA * npdu_data, - BACNET_NETWORK_MESSAGE_TYPE network_message_type, - bool data_expecting_reply, + BACNET_NPDU_DATA *npdu_data, + BACNET_NETWORK_MESSAGE_TYPE network_message_type, bool data_expecting_reply, BACNET_MESSAGE_PRIORITY priority) { if (npdu_data) { npdu_data->data_expecting_reply = data_expecting_reply; npdu_data->protocol_version = BACNET_PROTOCOL_VERSION; - npdu_data->network_layer_message = true; /* false if APDU */ + npdu_data->network_layer_message = true; /* false if APDU */ npdu_data->network_message_type = network_message_type; /* optional */ - npdu_data->vendor_id = 0; /* optional, if net message type is > 0x80 */ + npdu_data->vendor_id = 0; /* optional, if net message type is > 0x80 */ npdu_data->priority = priority; npdu_data->hop_count = HOP_COUNT_DEFAULT; } } - /** Function to encode and send any supported Network Layer Message. * The payload for the message is encoded from information in the iArgs[] array. * The contents of iArgs are are, per message type: @@ -97,21 +97,19 @@ static void npdu_encode_npdu_network( * the type of message. * @return Number of bytes sent, or <=0 if no message was sent. */ -int Send_Network_Layer_Message( - BACNET_NETWORK_MESSAGE_TYPE network_message_type, - BACNET_ADDRESS * dst, - int *iArgs) +int Send_Network_Layer_Message(BACNET_NETWORK_MESSAGE_TYPE network_message_type, + BACNET_ADDRESS *dst, int *iArgs) { int len = 0; int pdu_len = 0; int bytes_sent = 0; - int *pVal = iArgs; /* Start with first value */ + int *pVal = iArgs; /* Start with first value */ bool data_expecting_reply = false; BACNET_NPDU_DATA npdu_data; BACNET_ADDRESS bcastDest; if (iArgs == NULL) - return 0; /* Can't do anything here */ + return 0; /* Can't do anything here */ /* If dst was NULL, get our (local net) broadcast MAC address. */ if (dst == NULL) { @@ -120,9 +118,9 @@ int Send_Network_Layer_Message( } if (network_message_type == NETWORK_MESSAGE_INIT_RT_TABLE) - data_expecting_reply = true; /* DER in this one case */ + data_expecting_reply = true; /* DER in this one case */ npdu_encode_npdu_network(&npdu_data, network_message_type, - data_expecting_reply, MESSAGE_PRIORITY_NORMAL); + data_expecting_reply, MESSAGE_PRIORITY_NORMAL); /* We don't need src information, since a message can't originate from * our downstream BACnet network. @@ -134,9 +132,8 @@ int Send_Network_Layer_Message( switch (network_message_type) { case NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK: if (*pVal >= 0) { - len = - encode_unsigned16(&Handler_Transmit_Buffer[pdu_len], - (uint16_t) * pVal); + len = encode_unsigned16(&Handler_Transmit_Buffer[pdu_len], + (uint16_t)*pVal); pdu_len += len; } /* else, don't encode a DNET */ @@ -146,9 +143,8 @@ int Send_Network_Layer_Message( case NETWORK_MESSAGE_ROUTER_BUSY_TO_NETWORK: case NETWORK_MESSAGE_ROUTER_AVAILABLE_TO_NETWORK: while (*pVal >= 0) { - len = - encode_unsigned16(&Handler_Transmit_Buffer[pdu_len], - (uint16_t) * pVal); + len = encode_unsigned16(&Handler_Transmit_Buffer[pdu_len], + (uint16_t)*pVal); pdu_len += len; pVal++; } @@ -156,40 +152,38 @@ int Send_Network_Layer_Message( case NETWORK_MESSAGE_REJECT_MESSAGE_TO_NETWORK: /* Encode the Reason byte, then the DNET */ - Handler_Transmit_Buffer[pdu_len++] = (uint8_t) * pVal; + Handler_Transmit_Buffer[pdu_len++] = (uint8_t)*pVal; pVal++; - len = - encode_unsigned16(&Handler_Transmit_Buffer[pdu_len], - (uint16_t) * pVal); + len = encode_unsigned16(&Handler_Transmit_Buffer[pdu_len], + (uint16_t)*pVal); pdu_len += len; break; case NETWORK_MESSAGE_INIT_RT_TABLE: case NETWORK_MESSAGE_INIT_RT_TABLE_ACK: /* First, count the number of Ports we will encode */ - len = 0; /* Re-purpose len as our counter here */ + len = 0; /* Re-purpose len as our counter here */ while (*pVal >= 0) { len++; pVal++; } - Handler_Transmit_Buffer[pdu_len++] = (uint8_t) len; + Handler_Transmit_Buffer[pdu_len++] = (uint8_t)len; if (len > 0) { uint8_t portID = 1; - pVal = iArgs; /* Reset to beginning */ + pVal = iArgs; /* Reset to beginning */ /* Now encode each (virtual) BACNET_ROUTER_PORT. * We will simply use a positive index for PortID, * and have no PortInfo. */ while (*pVal >= 0) { - len = - encode_unsigned16(&Handler_Transmit_Buffer[pdu_len], - (uint16_t) * pVal); + len = encode_unsigned16(&Handler_Transmit_Buffer[pdu_len], + (uint16_t)*pVal); pdu_len += len; Handler_Transmit_Buffer[pdu_len++] = portID++; Handler_Transmit_Buffer[pdu_len++] = 0; debug_printf(" Sending Routing Table entry for %u \n", - *pVal); + *pVal); pVal++; } } @@ -197,34 +191,33 @@ int Send_Network_Layer_Message( default: debug_printf("Not sent: %s message unsupported \n", - bactext_network_layer_msg_name(network_message_type)); + bactext_network_layer_msg_name(network_message_type)); return 0; - break; /* Will never reach this line */ + break; /* Will never reach this line */ } if (dst != NULL) debug_printf("Sending %s message to BACnet network %u \n", - bactext_network_layer_msg_name(network_message_type), dst->net); + bactext_network_layer_msg_name(network_message_type), + dst->net); else debug_printf("Sending %s message to local BACnet network \n", - bactext_network_layer_msg_name(network_message_type)); + bactext_network_layer_msg_name(network_message_type)); /* Now send the message */ - bytes_sent = - datalink_send_pdu(dst, &npdu_data, &Handler_Transmit_Buffer[0], - pdu_len); + bytes_sent = datalink_send_pdu(dst, &npdu_data, &Handler_Transmit_Buffer[0], + pdu_len); #if PRINT_ENABLED if (bytes_sent <= 0) { - int wasErrno = errno; /* preserve the errno */ + int wasErrno = errno; /* preserve the errno */ debug_printf("Failed to send %s message (%s)!\n", - bactext_network_layer_msg_name(network_message_type), - strerror(wasErrno)); + bactext_network_layer_msg_name(network_message_type), + strerror(wasErrno)); } #endif return bytes_sent; } - /** Finds a specific router, or all reachable BACnet networks. * The response(s) will come in I-am-router-to-network message(s). * @ingroup NMRC @@ -236,12 +229,10 @@ int Send_Network_Layer_Message( * will be sent and the receiving router(s) will send * their full list of reachable BACnet networks. */ -void Send_Who_Is_Router_To_Network( - BACNET_ADDRESS * dst, - int dnet) +void Send_Who_Is_Router_To_Network(BACNET_ADDRESS *dst, int dnet) { Send_Network_Layer_Message(NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK, dst, - &dnet); + &dnet); } /** Broadcast an I-am-router-to-network message, giving the list of networks @@ -253,12 +244,11 @@ void Send_Who_Is_Router_To_Network( * @param DNET_list [in] List of BACnet network numbers for which I am a router, * terminated with -1 */ -void Send_I_Am_Router_To_Network( - const int DNET_list[]) +void Send_I_Am_Router_To_Network(const int DNET_list[]) { /* Use a NULL dst here since we want a broadcast MAC address. */ Send_Network_Layer_Message(NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK, NULL, - (int *) DNET_list); + (int *)DNET_list); } /** Finds a specific router, or all reachable BACnet networks. @@ -271,20 +261,17 @@ void Send_I_Am_Router_To_Network( * @param reject_reason [in] One of the BACNET_NETWORK_REJECT_REASONS codes. * @param dnet [in] Which BACnet network orginated the message. */ -void Send_Reject_Message_To_Network( - BACNET_ADDRESS * dst, - uint8_t reject_reason, - int dnet) +void Send_Reject_Message_To_Network(BACNET_ADDRESS *dst, uint8_t reject_reason, + int dnet) { int iArgs[2]; iArgs[0] = reject_reason; iArgs[1] = dnet; Send_Network_Layer_Message(NETWORK_MESSAGE_REJECT_MESSAGE_TO_NETWORK, dst, - iArgs); + iArgs); debug_printf(" Reject Reason=%d, DNET=%u\n", reject_reason, dnet); } - /** Send an Initialize Routing Table message, built from an optional DNET[] * array. * There are two cases here: @@ -301,16 +288,13 @@ void Send_Reject_Message_To_Network( * terminated with -1. Will be just -1 when we are * requesting a routing table. */ -void Send_Initialize_Routing_Table( - BACNET_ADDRESS * dst, - const int DNET_list[]) +void Send_Initialize_Routing_Table(BACNET_ADDRESS *dst, const int DNET_list[]) { /* Use a NULL dst here since we want a broadcast MAC address. */ Send_Network_Layer_Message(NETWORK_MESSAGE_INIT_RT_TABLE, dst, - (int *) DNET_list); + (int *)DNET_list); } - /** Sends our Routing Table, built from our DNET[] array, as an ACK. * There are two cases here: * 1) We are responding to a NETWORK_MESSAGE_INIT_RT_TABLE requesting our table. @@ -328,10 +312,9 @@ void Send_Initialize_Routing_Table( * terminated with -1. May be just -1 when no table * should be sent. */ -void Send_Initialize_Routing_Table_Ack( - BACNET_ADDRESS * dst, - const int DNET_list[]) +void Send_Initialize_Routing_Table_Ack(BACNET_ADDRESS *dst, + const int DNET_list[]) { Send_Network_Layer_Message(NETWORK_MESSAGE_INIT_RT_TABLE_ACK, dst, - (int *) DNET_list); + (int *)DNET_list); } diff --git a/demo/handler/s_rp.c b/demo/handler/s_rp.c index b9104bd5..205527ba 100644 --- a/demo/handler/s_rp.c +++ b/demo/handler/s_rp.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2005 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2005 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -52,20 +52,21 @@ * @param max_apdu [in] * @param object_type [in] Type of the object whose property is to be read. * @param object_instance [in] Instance # of the object to be read. - * @param object_property [in] Property to be read, but not ALL, REQUIRED, or OPTIONAL. + * @param object_property [in] Property to be read, but not ALL, REQUIRED, or + * OPTIONAL. * @param array_index [in] Optional: if the Property is an array, * - 0 for the array size * - 1 to n for individual array members * - BACNET_ARRAY_ALL (~0) for the full array to be read. - * @return invoke id of outgoing message, or 0 if device is not bound or no tsm available + * @return invoke id of outgoing message, or 0 if device is not bound or no tsm + * available */ -uint8_t Send_Read_Property_Request_Address( - BACNET_ADDRESS * dest, - uint16_t max_apdu, - BACNET_OBJECT_TYPE object_type, - uint32_t object_instance, - BACNET_PROPERTY_ID object_property, - uint32_t array_index) +uint8_t Send_Read_Property_Request_Address(BACNET_ADDRESS* dest, + uint16_t max_apdu, + BACNET_OBJECT_TYPE object_type, + uint32_t object_instance, + BACNET_PROPERTY_ID object_property, + uint32_t array_index) { BACNET_ADDRESS my_address; uint8_t invoke_id = 0; @@ -87,33 +88,31 @@ uint8_t Send_Read_Property_Request_Address( /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL); - pdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], dest, &my_address, - &npdu_data); + pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], dest, + &my_address, &npdu_data); /* encode the APDU portion of the packet */ data.object_type = object_type; data.object_instance = object_instance; data.object_property = object_property; data.array_index = array_index; len = - rp_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id, - &data); + rp_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id, &data); pdu_len += len; /* will it fit in the sender? note: if there is a bottleneck router in between us and the destination, we won't know unless we have a way to check for that and update the max_apdu in the address binding table. */ - if ((uint16_t) pdu_len < max_apdu) { - tsm_set_confirmed_unsegmented_transaction(invoke_id, dest, - &npdu_data, &Handler_Transmit_Buffer[0], (uint16_t) pdu_len); - bytes_sent = - datalink_send_pdu(dest, &npdu_data, - &Handler_Transmit_Buffer[0], pdu_len); + if ((uint16_t)pdu_len < max_apdu) { + tsm_set_confirmed_unsegmented_transaction( + invoke_id, dest, &npdu_data, &Handler_Transmit_Buffer[0], + (uint16_t)pdu_len); + bytes_sent = datalink_send_pdu( + dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); if (bytes_sent <= 0) { #if PRINT_ENABLED fprintf(stderr, "Failed to Send ReadProperty Request (%s)!\n", - strerror(errno)); + strerror(errno)); #endif } } else { @@ -121,8 +120,8 @@ uint8_t Send_Read_Property_Request_Address( invoke_id = 0; #if PRINT_ENABLED fprintf(stderr, - "Failed to Send ReadProperty Request " - "(exceeds destination maximum APDU)!\n"); + "Failed to Send ReadProperty Request " + "(exceeds destination maximum APDU)!\n"); #endif } } @@ -136,21 +135,22 @@ uint8_t Send_Read_Property_Request_Address( * @param device_id [in] ID of the destination device * @param object_type [in] Type of the object whose property is to be read. * @param object_instance [in] Instance # of the object to be read. - * @param object_property [in] Property to be read, but not ALL, REQUIRED, or OPTIONAL. + * @param object_property [in] Property to be read, but not ALL, REQUIRED, or + * OPTIONAL. * @param array_index [in] Optional: if the Property is an array, * - 0 for the array size * - 1 to n for individual array members * - BACNET_ARRAY_ALL (~0) for the full array to be read. - * @return invoke id of outgoing message, or 0 if device is not bound or no tsm available + * @return invoke id of outgoing message, or 0 if device is not bound or no tsm + * available */ -uint8_t Send_Read_Property_Request( - uint32_t device_id, /* destination device */ - BACNET_OBJECT_TYPE object_type, - uint32_t object_instance, - BACNET_PROPERTY_ID object_property, - uint32_t array_index) +uint8_t Send_Read_Property_Request(uint32_t device_id, /* destination device */ + BACNET_OBJECT_TYPE object_type, + uint32_t object_instance, + BACNET_PROPERTY_ID object_property, + uint32_t array_index) { - BACNET_ADDRESS dest = { 0 }; + BACNET_ADDRESS dest = {0}; unsigned max_apdu = 0; uint8_t invoke_id = 0; bool status = false; @@ -158,9 +158,9 @@ uint8_t Send_Read_Property_Request( /* is the device bound? */ status = address_get_by_device(device_id, &max_apdu, &dest); if (status) { - invoke_id = - Send_Read_Property_Request_Address(&dest, max_apdu, object_type, - object_instance, object_property, array_index); + invoke_id = Send_Read_Property_Request_Address( + &dest, max_apdu, object_type, object_instance, object_property, + array_index); } return invoke_id; diff --git a/demo/handler/s_rpm.c b/demo/handler/s_rpm.c index a3b47a61..f36cc6b6 100644 --- a/demo/handler/s_rpm.c +++ b/demo/handler/s_rpm.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2008 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2008 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -53,13 +53,12 @@ * @param device_id [in] ID of the destination device * @param read_access_data [in] Ptr to structure with the linked list of * properties to be read. - * @return invoke id of outgoing message, or 0 if device is not bound or no tsm available + * @return invoke id of outgoing message, or 0 if device is not bound or no tsm + * available */ uint8_t Send_Read_Property_Multiple_Request( - uint8_t * pdu, - size_t max_pdu, - uint32_t device_id, /* destination device */ - BACNET_READ_ACCESS_DATA * read_access_data) + uint8_t* pdu, size_t max_pdu, uint32_t device_id, /* destination device */ + BACNET_READ_ACCESS_DATA* read_access_data) { BACNET_ADDRESS dest; BACNET_ADDRESS my_address; @@ -85,9 +84,8 @@ uint8_t Send_Read_Property_Multiple_Request( npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL); pdu_len = npdu_encode_pdu(&pdu[0], &dest, &my_address, &npdu_data); /* encode the APDU portion of the packet */ - len = - rpm_encode_apdu(&pdu[pdu_len], max_pdu - pdu_len, invoke_id, - read_access_data); + len = rpm_encode_apdu(&pdu[pdu_len], max_pdu - pdu_len, invoke_id, + read_access_data); if (len <= 0) { return 0; } @@ -97,24 +95,23 @@ uint8_t Send_Read_Property_Multiple_Request( us and the destination, we won't know unless we have a way to check for that and update the max_apdu in the address binding table. */ - if ((unsigned) pdu_len < max_apdu) { - tsm_set_confirmed_unsegmented_transaction(invoke_id, &dest, - &npdu_data, &pdu[0], (uint16_t) pdu_len); - bytes_sent = - datalink_send_pdu(&dest, &npdu_data, &pdu[0], pdu_len); + if ((unsigned)pdu_len < max_apdu) { + tsm_set_confirmed_unsegmented_transaction( + invoke_id, &dest, &npdu_data, &pdu[0], (uint16_t)pdu_len); + bytes_sent = datalink_send_pdu(&dest, &npdu_data, &pdu[0], pdu_len); #if PRINT_ENABLED if (bytes_sent <= 0) fprintf(stderr, - "Failed to Send ReadPropertyMultiple Request (%s)!\n", - strerror(errno)); + "Failed to Send ReadPropertyMultiple Request (%s)!\n", + strerror(errno)); #endif } else { tsm_free_invoke_id(invoke_id); invoke_id = 0; #if PRINT_ENABLED fprintf(stderr, - "Failed to Send ReadPropertyMultiple Request " - "(exceeds destination maximum APDU)!\n"); + "Failed to Send ReadPropertyMultiple Request " + "(exceeds destination maximum APDU)!\n"); #endif } } diff --git a/demo/handler/s_ts.c b/demo/handler/s_ts.c index f9d13af3..d214ac35 100644 --- a/demo/handler/s_ts.c +++ b/demo/handler/s_ts.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2005 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2005 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -52,10 +52,8 @@ * @param bdate - #BACNET_DATE * @param btime - #BACNET_TIME */ -void Send_TimeSync_Remote( - BACNET_ADDRESS * dest, - BACNET_DATE * bdate, - BACNET_TIME * btime) +void Send_TimeSync_Remote(BACNET_ADDRESS* dest, BACNET_DATE* bdate, + BACNET_TIME* btime) { int len = 0; int pdu_len = 0; @@ -69,21 +67,18 @@ void Send_TimeSync_Remote( datalink_get_my_address(&my_address); /* encode the NPDU portion of the packet */ npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); - pdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], dest, &my_address, - &npdu_data); + pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], dest, &my_address, + &npdu_data); /* encode the APDU portion of the packet */ - len = - timesync_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bdate, btime); + len = timesync_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bdate, btime); pdu_len += len; /* send it out the datalink */ - bytes_sent = - datalink_send_pdu(dest, &npdu_data, &Handler_Transmit_Buffer[0], - pdu_len); + bytes_sent = datalink_send_pdu(dest, &npdu_data, + &Handler_Transmit_Buffer[0], pdu_len); #if PRINT_ENABLED if (bytes_sent <= 0) fprintf(stderr, "Failed to Send Time-Synchronization Request (%s)!\n", - strerror(errno)); + strerror(errno)); #endif } @@ -93,9 +88,7 @@ void Send_TimeSync_Remote( * @param bdate - #BACNET_DATE * @param btime - #BACNET_TIME */ -void Send_TimeSync( - BACNET_DATE * bdate, - BACNET_TIME * btime) +void Send_TimeSync(BACNET_DATE* bdate, BACNET_TIME* btime) { BACNET_ADDRESS dest; @@ -110,10 +103,8 @@ void Send_TimeSync( * @param bdate - #BACNET_DATE * @param btime - #BACNET_TIME */ -void Send_TimeSyncUTC_Remote( - BACNET_ADDRESS * dest, - BACNET_DATE * bdate, - BACNET_TIME * btime) +void Send_TimeSyncUTC_Remote(BACNET_ADDRESS* dest, BACNET_DATE* bdate, + BACNET_TIME* btime) { int len = 0; int pdu_len = 0; @@ -127,22 +118,19 @@ void Send_TimeSyncUTC_Remote( datalink_get_my_address(&my_address); /* encode the NPDU portion of the packet */ npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); - pdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], dest, &my_address, - &npdu_data); + pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], dest, &my_address, + &npdu_data); /* encode the APDU portion of the packet */ - len = - timesync_utc_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - bdate, btime); + len = timesync_utc_encode_apdu(&Handler_Transmit_Buffer[pdu_len], bdate, + btime); pdu_len += len; - bytes_sent = - datalink_send_pdu(dest, &npdu_data, &Handler_Transmit_Buffer[0], - pdu_len); + bytes_sent = datalink_send_pdu(dest, &npdu_data, + &Handler_Transmit_Buffer[0], pdu_len); #if PRINT_ENABLED if (bytes_sent <= 0) fprintf(stderr, - "Failed to Send UTC-Time-Synchronization Request (%s)!\n", - strerror(errno)); + "Failed to Send UTC-Time-Synchronization Request (%s)!\n", + strerror(errno)); #endif } @@ -152,9 +140,7 @@ void Send_TimeSyncUTC_Remote( * @param bdate - #BACNET_DATE * @param btime - #BACNET_TIME */ -void Send_TimeSyncUTC( - BACNET_DATE * bdate, - BACNET_TIME * btime) +void Send_TimeSyncUTC(BACNET_DATE* bdate, BACNET_TIME* btime) { BACNET_ADDRESS dest; diff --git a/demo/handler/s_uevent.c b/demo/handler/s_uevent.c index 9ec00a66..6cac8322 100644 --- a/demo/handler/s_uevent.c +++ b/demo/handler/s_uevent.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2008 John Minack -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2008 John Minack + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -40,10 +40,8 @@ * @param dest [in] The destination address information (may be a broadcast). * @return Size of the message sent (bytes), or a negative value on error. */ -int Send_UEvent_Notify( - uint8_t * buffer, - BACNET_EVENT_NOTIFICATION_DATA * data, - BACNET_ADDRESS * dest) +int Send_UEvent_Notify(uint8_t* buffer, BACNET_EVENT_NOTIFICATION_DATA* data, + BACNET_ADDRESS* dest) { int len = 0; int pdu_len = 0; diff --git a/demo/handler/s_upt.c b/demo/handler/s_upt.c index 7b09ccbc..3ee5be81 100644 --- a/demo/handler/s_upt.c +++ b/demo/handler/s_upt.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2009 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2009 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -45,9 +45,8 @@ /** @file s_upt.c Send an Unconfirmed Private Transfer request. */ -int Send_UnconfirmedPrivateTransfer( - BACNET_ADDRESS * dest, - BACNET_PRIVATE_TRANSFER_DATA * private_data) +int Send_UnconfirmedPrivateTransfer(BACNET_ADDRESS* dest, + BACNET_PRIVATE_TRANSFER_DATA* private_data) { int len = 0; int pdu_len = 0; @@ -61,23 +60,20 @@ int Send_UnconfirmedPrivateTransfer( datalink_get_my_address(&my_address); /* encode the NPDU portion of the packet */ npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); - pdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], dest, &my_address, - &npdu_data); + pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], dest, &my_address, + &npdu_data); /* encode the APDU portion of the packet */ len = - uptransfer_encode_apdu(&Handler_Transmit_Buffer[pdu_len], - private_data); + uptransfer_encode_apdu(&Handler_Transmit_Buffer[pdu_len], private_data); pdu_len += len; - bytes_sent = - datalink_send_pdu(dest, &npdu_data, &Handler_Transmit_Buffer[0], - pdu_len); + bytes_sent = datalink_send_pdu(dest, &npdu_data, + &Handler_Transmit_Buffer[0], pdu_len); if (bytes_sent <= 0) { #if PRINT_ENABLED fprintf(stderr, - "Failed to Send UnconfirmedPrivateTransfer Request (%s)!\n", - strerror(errno)); + "Failed to Send UnconfirmedPrivateTransfer Request (%s)!\n", + strerror(errno)); #endif } diff --git a/demo/handler/s_whohas.c b/demo/handler/s_whohas.c index c423365d..a5d5919b 100644 --- a/demo/handler/s_whohas.c +++ b/demo/handler/s_whohas.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2006 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2006 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -47,18 +47,16 @@ /** Send a Who-Has request for a device which has a named Object. * @ingroup DMDOB - * If low_limit and high_limit both are -1, then the device ID range is unlimited. - * If low_limit and high_limit have the same non-negative value, then only - * that device will respond. - * Otherwise, low_limit must be less than high_limit for a range. + * If low_limit and high_limit both are -1, then the device ID range is + * unlimited. If low_limit and high_limit have the same non-negative value, then + * only that device will respond. Otherwise, low_limit must be less than + * high_limit for a range. * @param low_limit [in] Device Instance Low Range, 0 - 4,194,303 or -1 * @param high_limit [in] Device Instance High Range, 0 - 4,194,303 or -1 * @param object_name [in] The Name of the desired Object. */ -void Send_WhoHas_Name( - int32_t low_limit, - int32_t high_limit, - const char *object_name) +void Send_WhoHas_Name(int32_t low_limit, int32_t high_limit, + const char *object_name) { int len = 0; int pdu_len = 0; @@ -76,9 +74,8 @@ void Send_WhoHas_Name( datalink_get_my_address(&my_address); /* encode the NPDU portion of the packet */ npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); - pdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address, - &npdu_data); + pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address, + &npdu_data); /* encode the APDU portion of the packet */ data.low_limit = low_limit; @@ -88,32 +85,29 @@ void Send_WhoHas_Name( len = whohas_encode_apdu(&Handler_Transmit_Buffer[pdu_len], &data); pdu_len += len; /* send the data */ - bytes_sent = - datalink_send_pdu(&dest, &npdu_data, &Handler_Transmit_Buffer[0], - pdu_len); + bytes_sent = datalink_send_pdu(&dest, &npdu_data, + &Handler_Transmit_Buffer[0], pdu_len); #if PRINT_ENABLED if (bytes_sent <= 0) fprintf(stderr, "Failed to Send Who-Has Request (%s)!\n", - strerror(errno)); + strerror(errno)); #endif } /** Send a Who-Has request for a device which has a specific Object type and ID. * @ingroup DMDOB - * If low_limit and high_limit both are -1, then the device ID range is unlimited. - * If low_limit and high_limit have the same non-negative value, then only - * that device will respond. - * Otherwise, low_limit must be less than high_limit for a range. + * If low_limit and high_limit both are -1, then the device ID range is + * unlimited. If low_limit and high_limit have the same non-negative value, then + * only that device will respond. Otherwise, low_limit must be less than + * high_limit for a range. * @param low_limit [in] Device Instance Low Range, 0 - 4,194,303 or -1 * @param high_limit [in] Device Instance High Range, 0 - 4,194,303 or -1 * @param object_type [in] The BACNET_OBJECT_TYPE of the desired Object. * @param object_instance [in] The ID of the desired Object. */ -void Send_WhoHas_Object( - int32_t low_limit, - int32_t high_limit, - BACNET_OBJECT_TYPE object_type, - uint32_t object_instance) +void Send_WhoHas_Object(int32_t low_limit, int32_t high_limit, + BACNET_OBJECT_TYPE object_type, + uint32_t object_instance) { int len = 0; int pdu_len = 0; @@ -131,9 +125,8 @@ void Send_WhoHas_Object( datalink_get_my_address(&my_address); /* encode the NPDU portion of the packet */ npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); - pdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address, - &npdu_data); + pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address, + &npdu_data); /* encode the APDU portion of the packet */ data.low_limit = low_limit; @@ -143,12 +136,11 @@ void Send_WhoHas_Object( data.object.identifier.instance = object_instance; len = whohas_encode_apdu(&Handler_Transmit_Buffer[pdu_len], &data); pdu_len += len; - bytes_sent = - datalink_send_pdu(&dest, &npdu_data, &Handler_Transmit_Buffer[0], - pdu_len); + bytes_sent = datalink_send_pdu(&dest, &npdu_data, + &Handler_Transmit_Buffer[0], pdu_len); #if PRINT_ENABLED if (bytes_sent <= 0) fprintf(stderr, "Failed to Send Who-Has Request (%s)!\n", - strerror(errno)); + strerror(errno)); #endif } diff --git a/demo/handler/s_whois.c b/demo/handler/s_whois.c index aa538013..8d04df84 100644 --- a/demo/handler/s_whois.c +++ b/demo/handler/s_whois.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2005 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2005 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -56,10 +56,8 @@ * @param low_limit [in] Device Instance Low Range, 0 - 4,194,303 or -1 * @param high_limit [in] Device Instance High Range, 0 - 4,194,303 or -1 */ -void Send_WhoIs_To_Network( - BACNET_ADDRESS * target_address, - int32_t low_limit, - int32_t high_limit) +void Send_WhoIs_To_Network(BACNET_ADDRESS* target_address, int32_t low_limit, + int32_t high_limit) { int len = 0; int pdu_len = 0; @@ -71,21 +69,18 @@ void Send_WhoIs_To_Network( /* encode the NPDU portion of the packet */ npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); - pdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], target_address, - &my_address, &npdu_data); + pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], target_address, + &my_address, &npdu_data); /* encode the APDU portion of the packet */ - len = - whois_encode_apdu(&Handler_Transmit_Buffer[pdu_len], low_limit, - high_limit); + len = whois_encode_apdu(&Handler_Transmit_Buffer[pdu_len], low_limit, + high_limit); pdu_len += len; - bytes_sent = - datalink_send_pdu(target_address, &npdu_data, - &Handler_Transmit_Buffer[0], pdu_len); + bytes_sent = datalink_send_pdu(target_address, &npdu_data, + &Handler_Transmit_Buffer[0], pdu_len); #if PRINT_ENABLED if (bytes_sent <= 0) fprintf(stderr, "Failed to Send Who-Is Request (%s)!\n", - strerror(errno)); + strerror(errno)); #endif } @@ -97,9 +92,7 @@ void Send_WhoIs_To_Network( * @param low_limit [in] Device Instance Low Range, 0 - 4,194,303 or -1 * @param high_limit [in] Device Instance High Range, 0 - 4,194,303 or -1 */ -void Send_WhoIs_Global( - int32_t low_limit, - int32_t high_limit) +void Send_WhoIs_Global(int32_t low_limit, int32_t high_limit) { BACNET_ADDRESS dest; @@ -120,9 +113,7 @@ void Send_WhoIs_Global( * @param low_limit [in] Device Instance Low Range, 0 - 4,194,303 or -1 * @param high_limit [in] Device Instance High Range, 0 - 4,194,303 or -1 */ -void Send_WhoIs_Local( - int32_t low_limit, - int32_t high_limit) +void Send_WhoIs_Local(int32_t low_limit, int32_t high_limit) { BACNET_ADDRESS dest; char temp[6]; @@ -138,7 +129,8 @@ void Send_WhoIs_Local( /* I added this to make it a local broadcast */ dest.net = 0; - /* Not sure why this happens but values are backwards so they need to be reversed */ + /* Not sure why this happens but values are backwards so they need to be + * reversed */ temp[0] = dest.mac[3]; temp[1] = dest.mac[2]; @@ -147,7 +139,6 @@ void Send_WhoIs_Local( temp[4] = dest.mac[5]; temp[5] = dest.mac[4]; - for (loop = 0; loop < 6; loop++) { dest.mac[loop] = temp[loop]; } @@ -166,10 +157,8 @@ void Send_WhoIs_Local( * @param low_limit [in] Device Instance Low Range, 0 - 4,194,303 or -1 * @param high_limit [in] Device Instance High Range, 0 - 4,194,303 or -1 */ -void Send_WhoIs_Remote( - BACNET_ADDRESS * target_address, - int32_t low_limit, - int32_t high_limit) +void Send_WhoIs_Remote(BACNET_ADDRESS* target_address, int32_t low_limit, + int32_t high_limit) { if (!dcc_communication_enabled()) return; @@ -189,9 +178,7 @@ void Send_WhoIs_Remote( * @param low_limit [in] Device Instance Low Range, 0 - 4,194,303 or -1 * @param high_limit [in] Device Instance High Range, 0 - 4,194,303 or -1 */ -void Send_WhoIs( - int32_t low_limit, - int32_t high_limit) +void Send_WhoIs(int32_t low_limit, int32_t high_limit) { Send_WhoIs_Global(low_limit, high_limit); } diff --git a/demo/handler/s_wp.c b/demo/handler/s_wp.c index d65d4b57..cadf485c 100644 --- a/demo/handler/s_wp.c +++ b/demo/handler/s_wp.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2005 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2005 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -46,15 +46,13 @@ /** @file s_wp.c Send a Write Property request. */ /** returns the invoke ID for confirmed request, or zero on failure */ -uint8_t Send_Write_Property_Request_Data( - uint32_t device_id, - BACNET_OBJECT_TYPE object_type, - uint32_t object_instance, - BACNET_PROPERTY_ID object_property, - uint8_t * application_data, - int application_data_len, - uint8_t priority, - uint32_t array_index) +uint8_t Send_Write_Property_Request_Data(uint32_t device_id, + BACNET_OBJECT_TYPE object_type, + uint32_t object_instance, + BACNET_PROPERTY_ID object_property, + uint8_t* application_data, + int application_data_len, + uint8_t priority, uint32_t array_index) { BACNET_ADDRESS dest; BACNET_ADDRESS my_address; @@ -79,9 +77,8 @@ uint8_t Send_Write_Property_Request_Data( /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL); - pdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, &my_address, - &npdu_data); + pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &dest, + &my_address, &npdu_data); /* encode the APDU portion of the packet */ data.object_type = object_type; data.object_instance = object_instance; @@ -89,35 +86,34 @@ uint8_t Send_Write_Property_Request_Data( data.array_index = array_index; data.application_data_len = application_data_len; memcpy(&data.application_data[0], &application_data[0], - application_data_len); + application_data_len); data.priority = priority; len = - wp_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id, - &data); + wp_encode_apdu(&Handler_Transmit_Buffer[pdu_len], invoke_id, &data); pdu_len += len; /* will it fit in the sender? note: if there is a bottleneck router in between us and the destination, we won't know unless we have a way to check for that and update the max_apdu in the address binding table. */ - if ((unsigned) pdu_len < max_apdu) { - tsm_set_confirmed_unsegmented_transaction(invoke_id, &dest, - &npdu_data, &Handler_Transmit_Buffer[0], (uint16_t) pdu_len); - bytes_sent = - datalink_send_pdu(&dest, &npdu_data, - &Handler_Transmit_Buffer[0], pdu_len); + if ((unsigned)pdu_len < max_apdu) { + tsm_set_confirmed_unsegmented_transaction( + invoke_id, &dest, &npdu_data, &Handler_Transmit_Buffer[0], + (uint16_t)pdu_len); + bytes_sent = datalink_send_pdu( + &dest, &npdu_data, &Handler_Transmit_Buffer[0], pdu_len); #if PRINT_ENABLED if (bytes_sent <= 0) fprintf(stderr, "Failed to Send WriteProperty Request (%s)!\n", - strerror(errno)); + strerror(errno)); #endif } else { tsm_free_invoke_id(invoke_id); invoke_id = 0; #if PRINT_ENABLED fprintf(stderr, - "Failed to Send WriteProperty Request " - "(exceeds destination maximum APDU)!\n"); + "Failed to Send WriteProperty Request " + "(exceeds destination maximum APDU)!\n"); #endif } } @@ -125,7 +121,6 @@ uint8_t Send_Write_Property_Request_Data( return invoke_id; } - /** Sends a Write Property request. * @ingroup DSWP * @@ -141,25 +136,24 @@ uint8_t Send_Write_Property_Request_Data( * - BACNET_ARRAY_ALL (~0) for the array value to be ignored (not sent) * @return invoke id of outgoing message, or 0 on failure. */ -uint8_t Send_Write_Property_Request( - uint32_t device_id, - BACNET_OBJECT_TYPE object_type, - uint32_t object_instance, - BACNET_PROPERTY_ID object_property, - BACNET_APPLICATION_DATA_VALUE * object_value, - uint8_t priority, - uint32_t array_index) +uint8_t Send_Write_Property_Request(uint32_t device_id, + BACNET_OBJECT_TYPE object_type, + uint32_t object_instance, + BACNET_PROPERTY_ID object_property, + BACNET_APPLICATION_DATA_VALUE* object_value, + uint8_t priority, uint32_t array_index) { - uint8_t application_data[MAX_APDU] = { 0 }; + uint8_t application_data[MAX_APDU] = {0}; int apdu_len = 0, len = 0; while (object_value) { #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)); + 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)); #endif len = bacapp_encode_data(&application_data[apdu_len], object_value); if ((len + apdu_len) < MAX_APDU) { @@ -170,7 +164,7 @@ uint8_t Send_Write_Property_Request( object_value = object_value->next; } - return Send_Write_Property_Request_Data(device_id, object_type, - object_instance, object_property, &application_data[0], apdu_len, - priority, array_index); + return Send_Write_Property_Request_Data( + device_id, object_type, object_instance, object_property, + &application_data[0], apdu_len, priority, array_index); } diff --git a/demo/handler/s_wpm.c b/demo/handler/s_wpm.c index c5cc467a..7270f6f9 100644 --- a/demo/handler/s_wpm.c +++ b/demo/handler/s_wpm.c @@ -1,32 +1,32 @@ /** -* @file -* @author Daniel Blazevic -* @date 2013 -* @brief Send Write Property Multiple request -* -* @section LICENSE -* -* Copyright (C) 2013 Daniel Blazevic -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ + * @file + * @author Daniel Blazevic + * @date 2013 + * @brief Send Write Property Multiple request + * + * @section LICENSE + * + * Copyright (C) 2013 Daniel Blazevic + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ #include #include #include @@ -55,13 +55,12 @@ * @param device_id [in] ID of the destination device * @param write_access_data [in] Ptr to structure with the linked list of * objects and properties to be written. - * @return invoke id of outgoing message, or 0 if device is not bound or no tsm available + * @return invoke id of outgoing message, or 0 if device is not bound or no tsm + * available */ uint8_t Send_Write_Property_Multiple_Request( - uint8_t * pdu, - size_t max_pdu, - uint32_t device_id, - BACNET_WRITE_ACCESS_DATA * write_access_data) + uint8_t* pdu, size_t max_pdu, uint32_t device_id, + BACNET_WRITE_ACCESS_DATA* write_access_data) { BACNET_ADDRESS dest; BACNET_ADDRESS my_address; @@ -87,11 +86,10 @@ uint8_t Send_Write_Property_Multiple_Request( /* encode the NPDU portion of the packet */ datalink_get_my_address(&my_address); npdu_encode_npdu_data(&npdu_data, true, MESSAGE_PRIORITY_NORMAL); - pdu_len = npdu_encode_pdu(&pdu[0], &dest, &my_address,&npdu_data); + pdu_len = npdu_encode_pdu(&pdu[0], &dest, &my_address, &npdu_data); /* encode the APDU portion of the packet */ - len = - wpm_encode_apdu(&pdu[pdu_len], max_pdu - pdu_len, - invoke_id, write_access_data); + len = wpm_encode_apdu(&pdu[pdu_len], max_pdu - pdu_len, invoke_id, + write_access_data); pdu_len += len; /* will it fit in the sender? @@ -99,17 +97,15 @@ uint8_t Send_Write_Property_Multiple_Request( us and the destination, we won't know unless we have a way to check for that and update the max_apdu in the address binding table. */ - if ((unsigned) pdu_len < max_apdu) { - tsm_set_confirmed_unsegmented_transaction(invoke_id, &dest, - &npdu_data, &pdu[0], (uint16_t) pdu_len); - bytes_sent = - datalink_send_pdu(&dest, &npdu_data, - &pdu[0], pdu_len); + if ((unsigned)pdu_len < max_apdu) { + tsm_set_confirmed_unsegmented_transaction( + invoke_id, &dest, &npdu_data, &pdu[0], (uint16_t)pdu_len); + bytes_sent = datalink_send_pdu(&dest, &npdu_data, &pdu[0], pdu_len); #if PRINT_ENABLED if (bytes_sent <= 0) { fprintf(stderr, - "Failed to Send WritePropertyMultiple Request (%s)!\n", - strerror(errno)); + "Failed to Send WritePropertyMultiple Request (%s)!\n", + strerror(errno)); } #endif } else { @@ -117,8 +113,8 @@ uint8_t Send_Write_Property_Multiple_Request( invoke_id = 0; #if PRINT_ENABLED fprintf(stderr, - "Failed to Send WritePropertyMultiple Request " - "(exceeds destination maximum APDU)!\n"); + "Failed to Send WritePropertyMultiple Request " + "(exceeds destination maximum APDU)!\n"); #endif } } diff --git a/demo/handler/txbuf.c b/demo/handler/txbuf.c index af6f47be..7d36eed3 100644 --- a/demo/handler/txbuf.c +++ b/demo/handler/txbuf.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2005 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2005 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include "config.h" @@ -29,4 +29,4 @@ /** @file txbuf.c Declare the global Transmit Buffer for handler functions. */ -uint8_t Handler_Transmit_Buffer[MAX_PDU] = { 0 }; +uint8_t Handler_Transmit_Buffer[MAX_PDU] = {0}; diff --git a/demo/iam/main.c b/demo/iam/main.c index d0275e08..8aac47ed 100644 --- a/demo/iam/main.c +++ b/demo/iam/main.c @@ -1,34 +1,34 @@ /************************************************************************** -* -* Copyright (C) 2016 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2016 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* command line tool that sends a BACnet service */ #include #include #include #include -#include /* for time */ +#include /* for time */ #include #include "bactext.h" #include "iam.h" @@ -55,32 +55,26 @@ static int Target_Segmentation = SEGMENTATION_NONE; /* flag for signalling errors */ static bool Error_Detected = false; -void MyAbortHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t abort_reason, - bool server) +void MyAbortHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t abort_reason, bool server) { - (void) src; - (void) invoke_id; - (void) server; + (void)src; + (void)invoke_id; + (void)server; printf("BACnet Abort: %s\n", bactext_abort_reason_name(abort_reason)); Error_Detected = true; } -void MyRejectHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t reject_reason) +void MyRejectHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t reject_reason) { - (void) src; - (void) invoke_id; + (void)src; + (void)invoke_id; printf("BACnet Reject: %s\n", bactext_reject_reason_name(reject_reason)); Error_Detected = true; } -static void Init_Service_Handlers( - void) +static void Init_Service_Handlers(void) { Device_Init(NULL); /* we need to handle who-is @@ -88,11 +82,10 @@ static void Init_Service_Handlers( apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, handler_who_is); /* set the handler for all the services we don't implement It is required to send the proper reject message... */ - apdu_set_unrecognized_service_handler_handler - (handler_unrecognized_service); + apdu_set_unrecognized_service_handler_handler(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 reply (request) coming back */ apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_I_AM, handler_i_am_add); /* handle any errors coming back */ @@ -103,7 +96,7 @@ static void Init_Service_Handlers( static void print_usage(char *filename) { printf("Usage: %s [device-instance vendor-id max-apdu segmentation]\n", - filename); + filename); printf(" [--dnet][--dadr][--mac]\n"); printf(" [--version][--help]\n"); } @@ -111,7 +104,8 @@ static void print_usage(char *filename) static void print_help(char *filename) { printf("Send BACnet I-Am message for a device.\n"); - printf("--mac A\n" + printf( + "--mac A\n" "Optional BACnet mac address." "Valid ranges are from 00 to FF (hex) for MS/TP or ARCNET,\n" "or an IP string with optional port number like 10.1.2.3:47808\n" @@ -123,12 +117,14 @@ static void print_help(char *filename) "and 65535 is network broadcast.\n" "\n" "--dadr A\n" - "Optional BACnet mac address on the destination BACnet network number.\n" + "Optional BACnet mac address on the destination BACnet network " + "number.\n" "Valid ranges are from 00 to FF (hex) for MS/TP or ARCNET,\n" "or an IP string with optional port number like 10.1.2.3:47808\n" "or an Ethernet MAC in hex like 00:21:70:7e:32:bb\n" "\n"); - printf("device-instance:\n" + printf( + "device-instance:\n" " BACnet device-ID 0..4194303\n" "vendor-id:\n" " Vendor Identifier 0..65535\n" @@ -141,14 +137,12 @@ static void print_help(char *filename) filename); } -int main( - int argc, - char *argv[]) +int main(int argc, char *argv[]) { long dnet = -1; - BACNET_MAC_ADDRESS mac = { 0 }; - BACNET_MAC_ADDRESS adr = { 0 }; - BACNET_ADDRESS dest = { 0 }; + BACNET_MAC_ADDRESS mac = {0}; + BACNET_MAC_ADDRESS adr = {0}; + BACNET_ADDRESS dest = {0}; bool specific_address = false; int argi = 0; unsigned int target_args = 0; @@ -163,8 +157,10 @@ int main( } if (strcmp(argv[argi], "--version") == 0) { printf("%s %s\n", filename, BACNET_VERSION_TEXT); - printf("Copyright (C) 2016 by Steve Karg and others.\n" - "This is free software; see the source for copying conditions.\n" + printf( + "Copyright (C) 2016 by Steve Karg and others.\n" + "This is free software; see the source for copying " + "conditions.\n" "There is NO warranty; not even for MERCHANTABILITY or\n" "FITNESS FOR A PARTICULAR PURPOSE.\n"); return 0; @@ -245,11 +241,8 @@ int main( dlenv_init(); atexit(datalink_cleanup); /* send the request */ - Send_I_Am_To_Network(&dest, - Target_Device_ID, - Target_Max_APDU, - Target_Segmentation, - Target_Vendor_ID); + Send_I_Am_To_Network(&dest, Target_Device_ID, Target_Max_APDU, + Target_Segmentation, Target_Vendor_ID); return 0; } diff --git a/demo/iamrouter/main.c b/demo/iamrouter/main.c index 73a90565..acd030e8 100644 --- a/demo/iamrouter/main.c +++ b/demo/iamrouter/main.c @@ -1,34 +1,34 @@ /************************************************************************** -* -* Copyright (C) 2008 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2008 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* command line tool that sends a BACnet service, and displays the reply */ #include #include #include #include -#include /* for time */ +#include /* for time */ #include #include "bactext.h" #include "iam.h" @@ -49,38 +49,32 @@ /* global variables used in this file */ #define MAX_ROUTER_DNETS 64 -static int Target_Router_Networks[MAX_ROUTER_DNETS] = { -1 }; +static int Target_Router_Networks[MAX_ROUTER_DNETS] = {-1}; static bool Error_Detected = false; -void MyAbortHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t abort_reason, - bool server) +void MyAbortHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t abort_reason, bool server) { /* FIXME: verify src and invoke id */ - (void) src; - (void) invoke_id; - (void) server; + (void)src; + (void)invoke_id; + (void)server; printf("BACnet Abort: %s\n", bactext_abort_reason_name(abort_reason)); Error_Detected = true; } -void MyRejectHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t reject_reason) +void MyRejectHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t reject_reason) { /* FIXME: verify src and invoke id */ - (void) src; - (void) invoke_id; + (void)src; + (void)invoke_id; printf("BACnet Reject: %s\n", bactext_reject_reason_name(reject_reason)); Error_Detected = true; } -static void Init_Service_Handlers( - void) +static void Init_Service_Handlers(void) { Device_Init(NULL); /* we need to handle who-is @@ -88,11 +82,10 @@ static void Init_Service_Handlers( apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, handler_who_is); /* set the handler for all the services we don't implement It is required to send the proper reject message... */ - apdu_set_unrecognized_service_handler_handler - (handler_unrecognized_service); + apdu_set_unrecognized_service_handler_handler(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 reply (request) coming back */ apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_I_AM, handler_i_am_add); /* handle any errors coming back */ @@ -108,19 +101,20 @@ static void print_usage(char *filename) static void print_help(char *filename) { - printf("Send BACnet I-Am-Router-To-Network message for \n" - "one or more networks.\n" "\nDNET:\n" + printf( + "Send BACnet I-Am-Router-To-Network message for \n" + "one or more networks.\n" + "\nDNET:\n" "BACnet destination network number 0-65534\n" "To send a I-Am-Router-To-Network message for DNET 86:\n" "%s 86\n" "To send a I-Am-Router-To-Network message for multiple DNETs\n" - "use the following command:\n" "%s 86 42 24 14\n", + "use the following command:\n" + "%s 86 42 24 14\n", filename, filename); } -int main( - int argc, - char *argv[]) +int main(int argc, char *argv[]) { unsigned arg_count = 0; int argi = 0; @@ -135,8 +129,10 @@ int main( } if (strcmp(argv[argi], "--version") == 0) { printf("%s %s\n", filename, BACNET_VERSION_TEXT); - printf("Copyright (C) 2014 by Steve Karg and others.\n" - "This is free software; see the source for copying conditions.\n" + printf( + "Copyright (C) 2014 by Steve Karg and others.\n" + "This is free software; see the source for copying " + "conditions.\n" "There is NO warranty; not even for MERCHANTABILITY or\n" "FITNESS FOR A PARTICULAR PURPOSE.\n"); exit(0); @@ -151,7 +147,7 @@ int main( for (arg_count = 1; arg_count < argc; arg_count++) { if (arg_count > MAX_ROUTER_DNETS) { fprintf(stderr, "Limited to %u DNETS. Sorry!\n", - MAX_ROUTER_DNETS); + MAX_ROUTER_DNETS); break; } Target_Router_Networks[arg_count - 1] = @@ -161,7 +157,7 @@ int main( /* invalid DNET? */ if (Target_Router_Networks[arg_count - 1] >= 65535) { fprintf(stderr, "DNET=%u - it must be less than %u\n", - Target_Router_Networks[arg_count - 1], 65535); + Target_Router_Networks[arg_count - 1], 65535); return 1; } } diff --git a/demo/initrouter/main.c b/demo/initrouter/main.c index f3161394..5017f29c 100644 --- a/demo/initrouter/main.c +++ b/demo/initrouter/main.c @@ -1,34 +1,34 @@ /************************************************************************** -* -* Copyright (C) 2008 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2008 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* command line tool that sends a BACnet service, and displays the reply */ #include #include #include #include -#include /* for time */ +#include /* for time */ #include #include "bactext.h" #include "iam.h" @@ -52,53 +52,46 @@ #include "dlenv.h" /* buffer used for receive */ -static uint8_t Rx_Buf[MAX_MPDU] = { 0 }; +static uint8_t Rx_Buf[MAX_MPDU] = {0}; /* target address */ static BACNET_ADDRESS Target_Router_Address; /* static BACNET_ROUTER_PORT *Target_Router_Port_List; */ -#define VIRTUAL_DNET 2709 /* your choice of number here */ +#define VIRTUAL_DNET 2709 /* your choice of number here */ /** The list of DNETs that our router can reach. * Only one entry since we don't support downstream routers. */ int DNET_list[2] = { - VIRTUAL_DNET, -1 /* Need -1 terminator */ + VIRTUAL_DNET, -1 /* Need -1 terminator */ }; static bool Error_Detected = false; -static void MyAbortHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t abort_reason, - bool server) +static void MyAbortHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t abort_reason, bool server) { /* FIXME: verify src and invoke id */ - (void) src; - (void) invoke_id; - (void) server; + (void)src; + (void)invoke_id; + (void)server; printf("BACnet Abort: %s\n", bactext_abort_reason_name(abort_reason)); Error_Detected = true; } -static void MyRejectHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t reject_reason) +static void MyRejectHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t reject_reason) { /* FIXME: verify src and invoke id */ - (void) src; - (void) invoke_id; + (void)src; + (void)invoke_id; printf("BACnet Reject: %s\n", bactext_reject_reason_name(reject_reason)); Error_Detected = true; } -static void My_Router_Handler( - BACNET_ADDRESS * src, - BACNET_NPDU_DATA * npdu_data, - uint8_t * npdu, /* PDU data */ - uint16_t npdu_len) +static void My_Router_Handler(BACNET_ADDRESS *src, BACNET_NPDU_DATA *npdu_data, + uint8_t *npdu, /* PDU data */ + uint16_t npdu_len) { uint16_t npdu_offset = 0; uint16_t dnet = 0; @@ -183,20 +176,19 @@ static void My_Router_Handler( } } -static void My_NPDU_Handler( - BACNET_ADDRESS * src, /* source address */ - uint8_t * pdu, /* PDU data */ - uint16_t pdu_len) -{ /* length PDU */ +static void My_NPDU_Handler(BACNET_ADDRESS *src, /* source address */ + uint8_t *pdu, /* PDU data */ + uint16_t pdu_len) +{ /* length PDU */ int apdu_offset = 0; - BACNET_ADDRESS dest = { 0 }; - BACNET_NPDU_DATA npdu_data = { 0 }; + BACNET_ADDRESS dest = {0}; + BACNET_NPDU_DATA npdu_data = {0}; apdu_offset = npdu_decode(&pdu[0], &dest, src, &npdu_data); if (npdu_data.network_layer_message) { if (apdu_offset <= pdu_len) { My_Router_Handler(src, &npdu_data, &pdu[apdu_offset], - (uint16_t) (pdu_len - apdu_offset)); + (uint16_t)(pdu_len - apdu_offset)); } } else if ((apdu_offset > 0) && (apdu_offset <= pdu_len)) { if ((npdu_data.protocol_version == BACNET_PROTOCOL_VERSION) && @@ -205,13 +197,13 @@ static void My_NPDU_Handler( /* and we are not a router, so ignore messages with routing information cause they are not for us */ apdu_handler(src, &pdu[apdu_offset], - (uint16_t) (pdu_len - apdu_offset)); + (uint16_t)(pdu_len - apdu_offset)); } else { if (dest.net) { debug_printf("NPDU: DNET=%d. Discarded!\n", dest.net); } else { debug_printf("NPDU: BACnet Protocol Version=%d. Discarded!\n", - npdu_data.protocol_version); + npdu_data.protocol_version); } } } @@ -219,8 +211,7 @@ static void My_NPDU_Handler( return; } -static void Init_Service_Handlers( - void) +static void Init_Service_Handlers(void) { Device_Init(NULL); /* we need to handle who-is @@ -228,11 +219,10 @@ static void Init_Service_Handlers( apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, handler_who_is); /* set the handler for all the services we don't implement It is required to send the proper reject message... */ - apdu_set_unrecognized_service_handler_handler - (handler_unrecognized_service); + apdu_set_unrecognized_service_handler_handler(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 reply (request) coming back */ apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_I_AM, handler_i_am_add); /* handle any errors coming back */ @@ -248,23 +238,27 @@ static void print_usage(char *filename) static void print_help(char *filename) { - printf("Send BACnet Initialize-Routing-Table message to a network\n" + printf( + "Send BACnet Initialize-Routing-Table message to a network\n" "and wait for responses. Displays their network information.\n" - "\n" "address:\n" + "\n" + "address:\n" "MAC address in xx:xx:xx:xx:xx:xx format or IP x.x.x.x:port\n" - "DNET ID Len Info:\n" "Port-info data:\n" " DNET:\n" - " Destination network number 0-65534\n" " ID:\n" - " Port Identifier number 0-255\n" " Info:\n" + "DNET ID Len Info:\n" + "Port-info data:\n" + " DNET:\n" + " Destination network number 0-65534\n" + " ID:\n" + " Port Identifier number 0-255\n" + " Info:\n" " Octet string of data, up to 255 octets\n" "To query the complete routing table, do not include any port-info.\n" "To query using Initialize-Routing-Table message to 192.168.0.18:\n" - "%s 192.168.0.18:47808\n", filename); + "%s 192.168.0.18:47808\n", + filename); } -static void address_parse( - BACNET_ADDRESS * dst, - int argc, - char *argv[]) +static void address_parse(BACNET_ADDRESS *dst, int argc, char *argv[]) { unsigned mac[6]; unsigned port; @@ -272,9 +266,8 @@ static void address_parse( int index = 0; if (argc > 0) { - count = - sscanf(argv[0], "%u.%u.%u.%u:%u", &mac[0], &mac[1], &mac[2], - &mac[3], &port); + count = sscanf(argv[0], "%u.%u.%u.%u:%u", &mac[0], &mac[1], &mac[2], + &mac[3], &port); if (count == 5) { dst->mac_len = 6; for (index = 0; index < 4; index++) { @@ -282,9 +275,8 @@ static void address_parse( } encode_unsigned16(&dst->mac[4], port); } else { - count = - sscanf(argv[0], "%x:%x:%x:%x:%x:%x", &mac[0], &mac[1], &mac[2], - &mac[3], &mac[4], &mac[5]); + count = sscanf(argv[0], "%x:%x:%x:%x:%x:%x", &mac[0], &mac[1], + &mac[2], &mac[3], &mac[4], &mac[5]); dst->mac_len = count; for (index = 0; index < MAX_MAC_LEN; index++) { if (index < count) { @@ -302,15 +294,11 @@ static void address_parse( } } -int main( - int argc, - char *argv[]) +int main(int argc, char *argv[]) { - BACNET_ADDRESS src = { - 0 - }; /* address where message came from */ + BACNET_ADDRESS src = {0}; /* address where message came from */ uint16_t pdu_len = 0; - unsigned timeout = 100; /* milliseconds */ + unsigned timeout = 100; /* milliseconds */ time_t total_seconds = 0; time_t elapsed_seconds = 0; time_t last_seconds = 0; @@ -328,8 +316,10 @@ int main( } if (strcmp(argv[argi], "--version") == 0) { printf("%s %s\n", filename, BACNET_VERSION_TEXT); - printf("Copyright (C) 2014 by Steve Karg and others.\n" - "This is free software; see the source for copying conditions.\n" + printf( + "Copyright (C) 2014 by Steve Karg and others.\n" + "This is free software; see the source for copying " + "conditions.\n" "There is NO warranty; not even for MERCHANTABILITY or\n" "FITNESS FOR A PARTICULAR PURPOSE.\n"); exit(0); diff --git a/demo/mstpcap/main.c b/demo/mstpcap/main.c index 4b7efe62..6f1fe68a 100644 --- a/demo/mstpcap/main.c +++ b/demo/mstpcap/main.c @@ -54,18 +54,18 @@ #include "iam.h" #ifdef _WIN32 -#define strncasecmp(x,y,z) _strnicmp(x,y,z) +#define strncasecmp(x, y, z) _strnicmp(x, y, z) #endif /* define our Data Link Type for libPCAP */ #define DLT_BACNET_MS_TP 165 /* local min/max macros */ #ifndef max -#define max(a,b) (((a) (b)) ? (a) : (b)) -#define min(a,b) (((a) < (b)) ? (a) : (b)) +#define max(a, b) (((a)(b)) ? (a) : (b)) +#define min(a, b) (((a) < (b)) ? (a) : (b)) #endif -#define MSTP_HEADER_MAX (2+1+1+1+2+1) +#define MSTP_HEADER_MAX (2 + 1 + 1 + 1 + 2 + 1) /* local port data - shared with RS-485 */ static volatile struct mstp_port_struct_t MSTP_Port; @@ -133,27 +133,22 @@ struct mstp_statistics { static struct mstp_statistics MSTP_Statistics[MAX_MSTP_DEVICES]; static uint32_t Invalid_Frame_Count; -static uint32_t timeval_diff_ms( - struct timeval *old, - struct timeval *now) +static uint32_t timeval_diff_ms(struct timeval *old, struct timeval *now) { uint32_t ms = 0; /* convert to milliseconds */ - ms = (now->tv_sec - old->tv_sec) * 1000 + (now->tv_usec - - old->tv_usec) / 1000; + ms = (now->tv_sec - old->tv_sec) * 1000 + + (now->tv_usec - old->tv_usec) / 1000; return ms; } -static void mstp_monitor_i_am( - uint8_t mac, - uint8_t * pdu, - uint16_t pdu_len) +static void mstp_monitor_i_am(uint8_t mac, uint8_t *pdu, uint16_t pdu_len) { - BACNET_ADDRESS src = { 0 }; - BACNET_ADDRESS dest = { 0 }; - BACNET_NPDU_DATA npdu_data = { 0 }; + BACNET_ADDRESS src = {0}; + BACNET_ADDRESS dest = {0}; + BACNET_NPDU_DATA npdu_data = {0}; int apdu_offset = 0; uint16_t apdu_len = 0; uint8_t *apdu = NULL; @@ -176,9 +171,8 @@ static void mstp_monitor_i_am( service_choice = apdu[1]; service_request = &apdu[2]; if (service_choice == SERVICE_UNCONFIRMED_I_AM) { - len = - iam_decode_service_request(service_request, &device_id, - NULL, NULL, NULL); + len = iam_decode_service_request( + service_request, &device_id, NULL, NULL, NULL); if (len != -1) { MSTP_Statistics[mac].device_id = device_id; } @@ -188,11 +182,10 @@ static void mstp_monitor_i_am( } } -static void packet_statistics( - struct timeval *tv, - volatile struct mstp_port_struct_t *mstp_port) +static void packet_statistics(struct timeval *tv, + volatile struct mstp_port_struct_t *mstp_port) { - static struct timeval old_tv = { 0 }; + static struct timeval old_tv = {0}; static uint8_t old_frame = 255; static uint8_t old_src = 255; static uint8_t old_dst = 255; @@ -228,7 +221,7 @@ static void packet_statistics( } } } else if ((old_frame == FRAME_TYPE_POLL_FOR_MASTER) && - (old_src == src)) { + (old_src == src)) { /* Tusage_timeout */ delta = timeval_diff_ms(&old_tv, tv); if (delta > MSTP_Statistics[src].tusage_timeout) { @@ -243,9 +236,8 @@ static void packet_statistics( break; case FRAME_TYPE_POLL_FOR_MASTER: if (MSTP_Statistics[src].last_pfm_tokens) { - npoll = - MSTP_Statistics[src].token_received_count - - MSTP_Statistics[src].last_pfm_tokens; + npoll = MSTP_Statistics[src].token_received_count - + MSTP_Statistics[src].last_pfm_tokens; if (npoll > MSTP_Statistics[src].npoll) { MSTP_Statistics[src].npoll = npoll; } @@ -297,7 +289,7 @@ static void packet_statistics( if ((mstp_port->DataLength <= mstp_port->InputBufferSize) && (mstp_port->DataLength > 0)) { mstp_monitor_i_am(src, &mstp_port->InputBuffer[0], - mstp_port->DataLength); + mstp_port->DataLength); } } break; @@ -324,8 +316,7 @@ static void packet_statistics( old_tv.tv_usec = tv->tv_usec; } -static void packet_statistics_print( - void) +static void packet_statistics_print(void) { unsigned i; /* loop counter */ unsigned node_count = 0; @@ -333,32 +324,32 @@ static void packet_statistics_print( fprintf(stdout, "\n"); fprintf(stdout, "==== MS/TP Frame Counts ====\n"); - fprintf(stdout, "%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-7s", "MAC", - "Device", "Tokens", "PFM", "RPFM", "DER", "Postpd", "DNER", "TestReq", - "TestRsp"); + fprintf(stdout, "%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-7s", "MAC", "Device", + "Tokens", "PFM", "RPFM", "DER", "Postpd", "DNER", "TestReq", + "TestRsp"); fprintf(stdout, "\n"); for (i = 0; i < MAX_MSTP_DEVICES; 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)) { node_count++; fprintf(stdout, "%-8u", i); if (MSTP_Statistics[i].device_id <= 4194303) { fprintf(stdout, "%-8lu", - (long unsigned int) MSTP_Statistics[i].device_id); + (long unsigned int)MSTP_Statistics[i].device_id); } else { fprintf(stdout, "%-8s", "-"); } fprintf(stdout, "%-8lu%-8lu%-8lu%-8lu", - (long unsigned int) MSTP_Statistics[i].token_count, - (long unsigned int) MSTP_Statistics[i].pfm_count, - (long unsigned int) MSTP_Statistics[i].rpfm_count, - (long unsigned int) MSTP_Statistics[i].der_count); + (long unsigned int)MSTP_Statistics[i].token_count, + (long unsigned int)MSTP_Statistics[i].pfm_count, + (long unsigned int)MSTP_Statistics[i].rpfm_count, + (long unsigned int)MSTP_Statistics[i].der_count); fprintf(stdout, "%-8lu%-8lu%-8lu%-7lu", - (long unsigned int) MSTP_Statistics[i].reply_postponed_count, - (long unsigned int) MSTP_Statistics[i].dner_count, - (long unsigned int) MSTP_Statistics[i].test_request_count, - (long unsigned int) MSTP_Statistics[i].test_response_count); + (long unsigned int)MSTP_Statistics[i].reply_postponed_count, + (long unsigned int)MSTP_Statistics[i].dner_count, + (long unsigned int)MSTP_Statistics[i].test_request_count, + (long unsigned int)MSTP_Statistics[i].test_response_count); fprintf(stdout, "\n"); } } @@ -367,38 +358,37 @@ static void packet_statistics_print( fprintf(stdout, "\n"); fprintf(stdout, "==== MS/TP Usage and Timing Maximums ====\n"); fprintf(stdout, "%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-8s%-7s", "MAC", - "MaxMstr", "Retries", "Npoll", "Self/TT", "Treply", "Tusage", "Trpfm", - "Tder", "Tpostpd"); + "MaxMstr", "Retries", "Npoll", "Self/TT", "Treply", "Tusage", + "Trpfm", "Tder", "Tpostpd"); fprintf(stdout, "\n"); for (i = 0; i < MAX_MSTP_DEVICES; 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)) { node_count++; self_or_ooo_count = MSTP_Statistics[i].self_token_count + - MSTP_Statistics[i].ooo_token_count; + MSTP_Statistics[i].ooo_token_count; fprintf(stdout, "%-8u", i); fprintf(stdout, "%-8lu%-8lu%-8lu%-8lu%-8lu", - (long unsigned int) MSTP_Statistics[i].max_master, - (long unsigned int) MSTP_Statistics[i].token_retries, - (long unsigned int) MSTP_Statistics[i].npoll, - self_or_ooo_count, - (long unsigned int) MSTP_Statistics[i].token_reply); + (long unsigned int)MSTP_Statistics[i].max_master, + (long unsigned int)MSTP_Statistics[i].token_retries, + (long unsigned int)MSTP_Statistics[i].npoll, + self_or_ooo_count, + (long unsigned int)MSTP_Statistics[i].token_reply); fprintf(stdout, "%-8lu%-8lu%-8lu%-7lu", - (long unsigned int) MSTP_Statistics[i].tusage_timeout, - (long unsigned int) MSTP_Statistics[i].pfm_reply, - (long unsigned int) MSTP_Statistics[i].der_reply, - (long unsigned int) MSTP_Statistics[i].reply_postponed); + (long unsigned int)MSTP_Statistics[i].tusage_timeout, + (long unsigned int)MSTP_Statistics[i].pfm_reply, + (long unsigned int)MSTP_Statistics[i].der_reply, + (long unsigned int)MSTP_Statistics[i].reply_postponed); fprintf(stdout, "\n"); } } fprintf(stdout, "Node Count: %u\n", node_count); fprintf(stdout, "Invalid Frame Count: %lu\n", - (long unsigned int) Invalid_Frame_Count); + (long unsigned int)Invalid_Frame_Count); } -static void packet_statistics_clear( - void) +static void packet_statistics_clear(void) { unsigned i = 0; @@ -409,76 +399,63 @@ static void packet_statistics_clear( Invalid_Frame_Count = 0; } -static uint32_t Timer_Silence( - void *pArg) +static uint32_t Timer_Silence(void *pArg) { return timer_milliseconds(TIMER_SILENCE); } -static void Timer_Silence_Reset( - void *pArg) +static void Timer_Silence_Reset(void *pArg) { timer_reset(TIMER_SILENCE); } /* functions used by the MS/TP state machine to put or get data */ -uint16_t MSTP_Put_Receive( - volatile struct mstp_port_struct_t *mstp_port) +uint16_t MSTP_Put_Receive(volatile struct mstp_port_struct_t *mstp_port) { - (void) mstp_port; + (void)mstp_port; return 0; } /* for the MS/TP state machine to use for getting data to send */ /* Return: amount of PDU data */ -uint16_t MSTP_Get_Send( - volatile struct mstp_port_struct_t * mstp_port, - unsigned timeout) -{ /* milliseconds to wait for a packet */ - (void) mstp_port; - (void) timeout; +uint16_t MSTP_Get_Send(volatile struct mstp_port_struct_t *mstp_port, + unsigned timeout) +{ /* milliseconds to wait for a packet */ + (void)mstp_port; + (void)timeout; return 0; } -uint16_t MSTP_Get_Reply( - volatile struct mstp_port_struct_t * mstp_port, - unsigned timeout) -{ /* milliseconds to wait for a packet */ - (void) mstp_port; - (void) timeout; +uint16_t MSTP_Get_Reply(volatile struct mstp_port_struct_t *mstp_port, + unsigned timeout) +{ /* milliseconds to wait for a packet */ + (void)mstp_port; + (void)timeout; return 0; } static char Capture_Filename[64] = "mstp_20090123091200.cap"; -static FILE *pFile = NULL; /* stream pointer */ +static FILE *pFile = NULL; /* stream pointer */ #if defined(_WIN32) -static HANDLE hPipe = INVALID_HANDLE_VALUE; /* pipe handle */ -static void named_pipe_create( - char *pipe_name) +static HANDLE hPipe = INVALID_HANDLE_VALUE; /* pipe handle */ +static void named_pipe_create(char *pipe_name) { if (!Wireshark_Capture) { fprintf(stdout, "mstpcap: Creating Named Pipe \"%s\"\n", pipe_name); } /* create the pipe */ - while (hPipe == INVALID_HANDLE_VALUE) - { + while (hPipe == INVALID_HANDLE_VALUE) { /* use CreateFile rather than CreateNamedPipe */ - hPipe = CreateFile( - pipe_name, - GENERIC_READ | - GENERIC_WRITE, - 0, - NULL, - OPEN_EXISTING, - 0, - NULL); + hPipe = CreateFile(pipe_name, GENERIC_READ | GENERIC_WRITE, 0, NULL, + OPEN_EXISTING, 0, NULL); if (hPipe != INVALID_HANDLE_VALUE) { break; } /* if an error occured at handle creation */ if (!WaitNamedPipe(pipe_name, 20000)) { - printf("Could not open pipe: waited for 20sec!\n" + printf( + "Could not open pipe: waited for 20sec!\n" "If this message was issued before the 20sec finished,\n" "then the pipe doesn't exist!\n"); Exit_Requested = true; @@ -488,44 +465,37 @@ static void named_pipe_create( ConnectNamedPipe(hPipe, NULL); } -size_t data_write( - const void *ptr, - size_t size, - size_t nitems) +size_t data_write(const void *ptr, size_t size, size_t nitems) { DWORD cbWritten = 0; if (hPipe != INVALID_HANDLE_VALUE) { - (void) WriteFile(hPipe, /* handle to pipe */ - ptr, /* buffer to write from */ - size * nitems, /* number of bytes to write */ - &cbWritten, /* number of bytes written */ - NULL); /* not overlapped I/O */ + (void)WriteFile(hPipe, /* handle to pipe */ + ptr, /* buffer to write from */ + size * nitems, /* number of bytes to write */ + &cbWritten, /* number of bytes written */ + NULL); /* not overlapped I/O */ } return fwrite(ptr, size, nitems, pFile); } -size_t data_write_header( - const void *ptr, - size_t size, - size_t nitems, - bool pipe_enable) +size_t data_write_header(const void *ptr, size_t size, size_t nitems, + bool pipe_enable) { DWORD cbWritten = 0; if (pipe_enable && (hPipe != INVALID_HANDLE_VALUE)) { - (void) WriteFile(hPipe, /* handle to pipe */ - ptr, /* buffer to write from */ - size * nitems, /* number of bytes to write */ - &cbWritten, /* number of bytes written */ - NULL); /* not overlapped I/O */ + (void)WriteFile(hPipe, /* handle to pipe */ + ptr, /* buffer to write from */ + size * nitems, /* number of bytes to write */ + &cbWritten, /* number of bytes written */ + NULL); /* not overlapped I/O */ } return fwrite(ptr, size, nitems, pFile); } #else static int FD_Pipe = -1; -static void named_pipe_create( - char *name) +static void named_pipe_create(char *name) { int rv = 0; rv = mkfifo(name, 0666); @@ -540,10 +510,7 @@ static void named_pipe_create( } } -size_t data_write( - const void *ptr, - size_t size, - size_t nitems) +size_t data_write(const void *ptr, size_t size, size_t nitems) { ssize_t bytes = 0; if (FD_Pipe != -1) { @@ -553,11 +520,8 @@ size_t data_write( return fwrite(ptr, size, nitems, pFile); } -size_t data_write_header( - const void *ptr, - size_t size, - size_t nitems, - bool pipe_enable) +size_t data_write_header(const void *ptr, size_t size, size_t nitems, + bool pipe_enable) { ssize_t bytes = 0; if (pipe_enable && (FD_Pipe != -1)) { @@ -568,8 +532,7 @@ size_t data_write_header( } #endif -static void filename_create( - char *filename) +static void filename_create(char *filename) { time_t my_time; struct tm *today; @@ -578,60 +541,57 @@ static void filename_create( my_time = time(NULL); today = localtime(&my_time); sprintf(filename, "mstp_%04d%02d%02d%02d%02d%02d.cap", - 1900 + today->tm_year, 1 + today->tm_mon, today->tm_mday, - today->tm_hour, today->tm_min, today->tm_sec); + 1900 + today->tm_year, 1 + today->tm_mon, today->tm_mday, + today->tm_hour, today->tm_min, today->tm_sec); } } /* write packet to file in libpcap format */ -static void write_global_header( - const char *filename) +static void write_global_header(const char *filename) { 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 */ - int32_t thiszone = 0; /* GMT to local correction */ - uint32_t sigfigs = 0; /* accuracy of timestamps */ - uint32_t snaplen = 65535; /* max length of captured packets, in octets */ - uint32_t network = DLT_BACNET_MS_TP; /* data link type - BACNET_MS_TP */ + uint16_t version_major = 2; /* major version number */ + uint16_t version_minor = 4; /* minor version number */ + int32_t thiszone = 0; /* GMT to local correction */ + uint32_t sigfigs = 0; /* accuracy of timestamps */ + uint32_t snaplen = 65535; /* max length of captured packets, in octets */ + uint32_t network = DLT_BACNET_MS_TP; /* data link type - BACNET_MS_TP */ /* 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(&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); - (void) data_write_header(&network, sizeof(network), 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); + (void)data_write_header(&network, sizeof(network), 1, pipe_enable); fflush(pFile); if (!Wireshark_Capture) { fprintf(stdout, "mstpcap: saving capture to %s\n", filename); } } else { fprintf(stderr, "mstpcap[header]: failed to open %s: %s\n", filename, - strerror(errno)); + strerror(errno)); } if (pipe_enable) { pipe_enable = false; } } - -static void write_received_packet( - volatile struct mstp_port_struct_t *mstp_port, - size_t header_len) +static void write_received_packet(volatile struct mstp_port_struct_t *mstp_port, + size_t header_len) { - uint32_t ts_sec = 0; /* timestamp seconds */ - uint32_t ts_usec = 0; /* timestamp microseconds */ - uint32_t incl_len = 0; /* number of octets of packet saved in file */ - uint32_t orig_len = 0; /* actual length of packet */ - uint8_t header[MSTP_HEADER_MAX] = {0}; /* MS/TP header */ + uint32_t ts_sec = 0; /* timestamp seconds */ + uint32_t ts_usec = 0; /* timestamp microseconds */ + uint32_t incl_len = 0; /* number of octets of packet saved in file */ + uint32_t orig_len = 0; /* actual length of packet */ + uint8_t header[MSTP_HEADER_MAX] = {0}; /* MS/TP header */ struct timeval tv; size_t max_data = 0; @@ -643,27 +603,28 @@ static void write_received_packet( (mstp_port->ReceivedValidFrameNotForUs)) { packet_statistics(&tv, mstp_port); } - (void) data_write(&ts_sec, sizeof(ts_sec), 1); - (void) data_write(&ts_usec, sizeof(ts_usec), 1); + (void)data_write(&ts_sec, sizeof(ts_sec), 1); + (void)data_write(&ts_usec, sizeof(ts_usec), 1); if (mstp_port->ReceivedInvalidFrame) { if (mstp_port->Index) { max_data = min(mstp_port->InputBufferSize, mstp_port->Index); - incl_len = orig_len = header_len + max_data + 2/* checksum*/; + incl_len = orig_len = header_len + max_data + 2 /* checksum*/; } else { /* header only */ incl_len = orig_len = header_len; } } else { if (mstp_port->DataLength) { - max_data = min(mstp_port->InputBufferSize, mstp_port->DataLength); - incl_len = orig_len = header_len + max_data + 2/* checksum*/; + max_data = + min(mstp_port->InputBufferSize, mstp_port->DataLength); + incl_len = orig_len = header_len + max_data + 2 /* checksum*/; } else { /* header only - or at least some bytes of the header */ incl_len = orig_len = header_len; } } - (void) data_write(&incl_len, sizeof(incl_len), 1); - (void) data_write(&orig_len, sizeof(orig_len), 1); + (void)data_write(&incl_len, sizeof(incl_len), 1); + (void)data_write(&orig_len, sizeof(orig_len), 1); if (header_len == 1) { header[0] = mstp_port->DataRegister; } else if (header_len == 2) { @@ -679,21 +640,20 @@ static void write_received_packet( header[6] = LO_BYTE(mstp_port->DataLength); header[7] = mstp_port->HeaderCRCActual; } - (void) data_write(header, header_len, 1); + (void)data_write(header, header_len, 1); if (max_data) { - (void) data_write(mstp_port->InputBuffer, max_data, 1); - (void) data_write((char *) &mstp_port->DataCRCActualMSB, 1, 1); - (void) data_write((char *) &mstp_port->DataCRCActualLSB, 1, 1); + (void)data_write(mstp_port->InputBuffer, max_data, 1); + (void)data_write((char *)&mstp_port->DataCRCActualMSB, 1, 1); + (void)data_write((char *)&mstp_port->DataCRCActualLSB, 1, 1); } } else { fprintf(stderr, "mstpcap[packet]: failed to open %s: %s\n", - Capture_Filename, strerror(errno)); + Capture_Filename, strerror(errno)); } } /* read header from file in libpcap format */ -static bool test_global_header( - const char *filename) +static bool test_global_header(const char *filename) { uint32_t magic_number = 0; /* magic number */ uint16_t version_major = 0; /* major version number */ @@ -758,21 +718,20 @@ static bool test_global_header( } } else { fprintf(stderr, "mstpcap[scan]: failed to open %s: %s\n", filename, - strerror(errno)); + strerror(errno)); return false; } return true; } -static bool read_received_packet( - volatile struct mstp_port_struct_t *mstp_port) +static bool read_received_packet(volatile struct mstp_port_struct_t *mstp_port) { - uint32_t ts_sec = 0; /* timestamp seconds */ - uint32_t ts_usec = 0; /* timestamp microseconds */ - uint32_t incl_len = 0; /* number of octets of packet saved in file */ - uint32_t orig_len = 0; /* actual length of packet */ - uint8_t header[8] = { 0 }; /* MS/TP header */ + uint32_t ts_sec = 0; /* timestamp seconds */ + uint32_t ts_usec = 0; /* timestamp microseconds */ + uint32_t incl_len = 0; /* number of octets of packet saved in file */ + uint32_t orig_len = 0; /* actual length of packet */ + uint8_t header[8] = {0}; /* MS/TP header */ struct timeval tv; size_t count = 0; unsigned i = 0; @@ -841,13 +800,13 @@ static bool read_received_packet( pFile = NULL; return false; } - count = fread((char *) &mstp_port->DataCRCActualMSB, 1, 1, pFile); + count = fread((char *)&mstp_port->DataCRCActualMSB, 1, 1, pFile); if (count != 1) { fclose(pFile); pFile = NULL; return false; } - count = fread((char *) &mstp_port->DataCRCActualLSB, 1, 1, pFile); + count = fread((char *)&mstp_port->DataCRCActualLSB, 1, 1, pFile); if (count != 1) { fclose(pFile); pFile = NULL; @@ -855,9 +814,8 @@ static bool read_received_packet( } mstp_port->DataCRC = 0xFFFF; for (i = 0; i < mstp_port->DataLength; i++) { - mstp_port->DataCRC = - CRC_Calc_Data(mstp_port->InputBuffer[i], - mstp_port->DataCRC); + mstp_port->DataCRC = CRC_Calc_Data(mstp_port->InputBuffer[i], + mstp_port->DataCRC); } mstp_port->DataCRC = CRC_Calc_Data(mstp_port->DataCRCActualMSB, mstp_port->DataCRC); @@ -878,7 +836,7 @@ static bool read_received_packet( if (mstp_port->ReceivedInvalidFrame) { Invalid_Frame_Count++; } else if ((mstp_port->ReceivedValidFrame) || - (mstp_port->ReceivedValidFrameNotForUs)) { + (mstp_port->ReceivedValidFrameNotForUs)) { packet_statistics(&tv, mstp_port); } } else { @@ -888,22 +846,20 @@ static bool read_received_packet( return true; } -static void cleanup( - void) +static void cleanup(void) { if (!Wireshark_Capture) { packet_statistics_print(); } if (pFile) { - fflush(pFile); /* stream pointer */ - fclose(pFile); /* stream pointer */ + fflush(pFile); /* stream pointer */ + fclose(pFile); /* stream pointer */ } pFile = NULL; } #if defined(_WIN32) -static BOOL WINAPI CtrlCHandler( - DWORD dwCtrlType) +static BOOL WINAPI CtrlCHandler(DWORD dwCtrlType) { dwCtrlType = dwCtrlType; @@ -923,10 +879,9 @@ static BOOL WINAPI CtrlCHandler( return TRUE; } #else -static void sig_int( - int signo) +static void sig_int(int signo) { - (void) signo; + (void)signo; if (FD_Pipe != -1) { close(FD_Pipe); } @@ -934,8 +889,7 @@ static void sig_int( exit(0); } -void signal_init( - void) +void signal_init(void) { signal(SIGINT, sig_int); signal(SIGHUP, sig_int); @@ -943,8 +897,7 @@ void signal_init( } #endif -void filename_create_new( - void) +void filename_create_new(void) { if (pFile) { fclose(pFile); @@ -954,8 +907,7 @@ void filename_create_new( write_global_header(&Capture_Filename[0]); } -static void print_usage( - char *filename) +static void print_usage(char *filename) { printf("Usage: %s", filename); printf(" [--scan ]\n"); @@ -965,15 +917,19 @@ static void print_usage( printf(" [--version][--help]\n"); } -static void print_help(char *filename) { - printf("%s --scan \n" +static void print_help(char *filename) +{ + printf( + "%s --scan \n" "perform statistic analysis on MS/TP capture file.\n", filename); printf("\n"); - printf("Captures MS/TP packets from a serial interface\n" + printf( + "Captures MS/TP packets from a serial interface\n" "and saves them to a file. Saves packets in a\n" "filename mstp_20090123091200.cap that has data and time.\n" - "After receiving 65535 packets, a new file is created.\n" "\n" + "After receiving 65535 packets, a new file is created.\n" + "\n" "Command line options:\n" "[--extcap-interface port] - serial interface.\n" #if defined(_WIN32) @@ -992,7 +948,8 @@ static void print_help(char *filename) { #endif " Use that name as the interface name in Wireshark.\n"); printf("\n"); - printf("%s [--extcap-interfaces][--extcap-dlts][--extcap-config]\n" + printf( + "%s [--extcap-interfaces][--extcap-dlts][--extcap-config]\n" "[--capture][--baud baud][--fifo pipe]\n" "[--extcap-interface iface]\n" "Usage from Wireshark ExtCap interface\n", @@ -1000,8 +957,7 @@ static void print_help(char *filename) { } /* initialize some of the variables in the MS/TP Receive structure */ -static void mstp_structure_init( - volatile struct mstp_port_struct_t *mstp_port) +static void mstp_structure_init(volatile struct mstp_port_struct_t *mstp_port) { if (mstp_port) { mstp_port->FrameType = FRAME_TYPE_PROPRIETARY_MAX; @@ -1019,9 +975,7 @@ static void mstp_structure_init( } /* simple test to packetize the data and print it */ -int main( - int argc, - char *argv[]) +int main(int argc, char *argv[]) { volatile struct mstp_port_struct_t *mstp_port; long my_baud = 38400; @@ -1053,8 +1007,10 @@ int main( } if (strcmp(argv[argi], "--version") == 0) { printf("mstpcap %s\n", BACNET_VERSION_TEXT); - printf("Copyright (C) 2011-2016 by Steve Karg\n" - "This is free software; see the source for copying conditions.\n" + printf( + "Copyright (C) 2011-2016 by Steve Karg\n" + "This is free software; see the source for copying " + "conditions.\n" "There is NO warranty; not even for MERCHANTABILITY or\n" "FITNESS FOR A PARTICULAR PURPOSE.\n"); return 0; @@ -1070,8 +1026,7 @@ int main( if (test_global_header(argv[argi])) { while (read_received_packet(mstp_port)) { packet_count++; - fprintf(stderr, "\r%u packets", - (unsigned) packet_count); + fprintf(stderr, "\r%u packets", (unsigned)packet_count); } if (packet_count) { packet_statistics_print(); @@ -1092,21 +1047,27 @@ int main( printf("An interface must be provided.\n"); return 0; } - printf("dlt {number=%u}{name=BACnet MS/TP}" + printf( + "dlt {number=%u}{name=BACnet MS/TP}" "{display=BACnet MS/TP}\n", DLT_BACNET_MS_TP); Exit_Requested = true; } if (strcmp(argv[argi], "--extcap-config") == 0) { - printf("arg {number=0}{call=--baud}{display=Baud Rate}" + printf( + "arg {number=0}{call=--baud}{display=Baud Rate}" "{tooltip=Serial port baud rate in bits per second}" "{type=selector}\n"); printf("value {arg=0}{value=9600}{display=9600}{default=false}\n"); - printf("value {arg=0}{value=19200}{display=19200}{default=false}\n"); + printf( + "value {arg=0}{value=19200}{display=19200}{default=false}\n"); printf("value {arg=0}{value=38400}{display=38400}{default=true}\n"); - printf("value {arg=0}{value=57600}{display=57600}{default=false}\n"); - printf("value {arg=0}{value=76800}{display=76800}{default=false}\n"); - printf("value {arg=0}{value=115200}{display=115200}{default=false}\n"); + printf( + "value {arg=0}{value=57600}{display=57600}{default=false}\n"); + printf( + "value {arg=0}{value=76800}{display=76800}{default=false}\n"); + printf( + "value {arg=0}{value=115200}{display=115200}{default=false}\n"); return 0; } if (strcmp(argv[argi], "--capture") == 0) { @@ -1116,7 +1077,8 @@ int main( if (strcmp(argv[argi], "--extcap-interface") == 0) { argi++; if (argi >= argc) { - printf("An interface must be provided or " + printf( + "An interface must be provided or " "the selection must be displayed.\n"); return 0; } @@ -1126,7 +1088,7 @@ int main( if (strncasecmp(argv[argi], "com", 3) == 0) { /* legacy command line options */ RS485_Set_Interface(argv[argi]); - if ((argi+1) < argc) { + if ((argi + 1) < argc) { argi++; my_baud = strtol(argv[argi], NULL, 0); RS485_Set_Baud_Rate(my_baud); @@ -1136,7 +1098,7 @@ int main( if (strncasecmp(argv[argi], "/dev/", 5) == 0) { /* legacy command line options */ RS485_Set_Interface(argv[argi]); - if ((argi+1) < argc) { + if ((argi + 1) < argc) { argi++; my_baud = strtol(argv[argi], NULL, 0); RS485_Set_Baud_Rate(my_baud); @@ -1173,11 +1135,11 @@ int main( timer_init(); if (!Wireshark_Capture) { fprintf(stdout, "mstpcap: Using %s for capture at %ld bps.\n", - RS485_Interface(), (long) RS485_Get_Baud_Rate()); + RS485_Interface(), (long)RS485_Get_Baud_Rate()); } #if defined(_WIN32) SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), ENABLE_PROCESSED_INPUT); - SetConsoleCtrlHandler((PHANDLER_ROUTINE) CtrlCHandler, TRUE); + SetConsoleCtrlHandler((PHANDLER_ROUTINE)CtrlCHandler, TRUE); #else signal_init(); #endif @@ -1228,8 +1190,8 @@ int main( } if (!Wireshark_Capture) { if (!(packet_count % 100)) { - fprintf(stdout, "\r%hu packets, %hu invalid frames", packet_count, - Invalid_Frame_Count); + fprintf(stdout, "\r%hu packets, %hu invalid frames", + packet_count, Invalid_Frame_Count); } if (packet_count >= 65535) { packet_statistics_print(); diff --git a/demo/mstpcrc/main.c b/demo/mstpcrc/main.c index a5589a8f..3338e66f 100644 --- a/demo/mstpcrc/main.c +++ b/demo/mstpcrc/main.c @@ -50,8 +50,8 @@ #include "version.h" #ifndef max -#define max(a,b) (((a) (b)) ? (a) : (b)) -#define min(a,b) (((a) < (b)) ? (a) : (b)) +#define max(a, b) (((a)(b)) ? (a) : (b)) +#define min(a, b) (((a) < (b)) ? (a) : (b)) #endif /* buffer needed by CRC functions */ @@ -65,17 +65,16 @@ static bool MSTP_Cap = false; static bool MSTP_Text_File = false; static char Capture_Filename[64] = "mstp_20090123091200.cap"; static FILE *pFile = NULL; /* stream pointer */ -static FILE *pText_File = NULL; /* stream pointer */ +static FILE *pText_File = NULL; /* stream pointer */ /****************************************************************** -* DESCRIPTION: Takes one of the arguments passed by the main function -* and converts it into a buffer value. -* argi - single argument in string form. -* RETURN: nothing -* NOTES: none -******************************************************************/ -static void Parse_Number( - char *argi) + * DESCRIPTION: Takes one of the arguments passed by the main function + * and converts it into a buffer value. + * argi - single argument in string form. + * RETURN: nothing + * NOTES: none + ******************************************************************/ +static void Parse_Number(char *argi) { long long_value = 0; @@ -84,21 +83,19 @@ static void Parse_Number( } else { long_value = strtol(argi, NULL, 16); } - CRC_Buffer[CRC_Buffer_Len] = (uint8_t) long_value; + CRC_Buffer[CRC_Buffer_Len] = (uint8_t)long_value; CRC_Buffer_Len++; } /****************************************************************** -* DESCRIPTION: Takes one of the arguments passed by the main function -* and sets flags if it matches one of the predefined args. -* PARAMETERS: argc (IN) number of arguments. -* argv (IN) an array of arguments in string form. -* RETURN: number of arguments parsed -* NOTES: none -******************************************************************/ -static void Parse_Arguments( - int argc, - char *argv[]) + * DESCRIPTION: Takes one of the arguments passed by the main function + * and sets flags if it matches one of the predefined args. + * PARAMETERS: argc (IN) number of arguments. + * argv (IN) an array of arguments in string form. + * RETURN: number of arguments parsed + * NOTES: none + ******************************************************************/ +static void Parse_Arguments(int argc, char *argv[]) { int i = 0; long long_value = 0; @@ -156,8 +153,7 @@ static void Parse_Arguments( } } -static void filename_create( - char *filename) +static void filename_create(char *filename) { time_t my_time; struct tm *today; @@ -166,70 +162,65 @@ static void filename_create( my_time = time(NULL); today = localtime(&my_time); sprintf(filename, "mstp_%04d%02d%02d%02d%02d%02d.cap", - 1900 + today->tm_year, 1 + today->tm_mon, today->tm_mday, - today->tm_hour, today->tm_min, today->tm_sec); + 1900 + today->tm_year, 1 + today->tm_mon, today->tm_mday, + today->tm_hour, today->tm_min, today->tm_sec); } } /* write packet to file in libpcap format */ -static void write_global_header( - const char *filename) +static void write_global_header(const char *filename) { uint32_t magic_number = 0xa1b2c3d4; /* magic number */ - uint16_t version_major = 2; /* major version number */ - uint16_t version_minor = 4; /* minor version number */ - int32_t thiszone = 0; /* GMT to local correction */ - uint32_t sigfigs = 0; /* accuracy of timestamps */ - uint32_t snaplen = 65535; /* max length of captured packets, in octets */ - uint32_t network = 165; /* data link type - BACNET_MS_TP */ + uint16_t version_major = 2; /* major version number */ + uint16_t version_minor = 4; /* minor version number */ + int32_t thiszone = 0; /* GMT to local correction */ + uint32_t sigfigs = 0; /* accuracy of timestamps */ + uint32_t snaplen = 65535; /* max length of captured packets, in octets */ + uint32_t network = 165; /* data link type - BACNET_MS_TP */ /* create a new file. */ pFile = fopen(filename, "wb"); if (pFile) { - (void) fwrite(&magic_number, sizeof(magic_number), 1, pFile); - (void) fwrite(&version_major, sizeof(version_major), 1, pFile); - (void) fwrite(&version_minor, sizeof(version_minor), 1, pFile); - (void) fwrite(&thiszone, sizeof(thiszone), 1, pFile); - (void) fwrite(&sigfigs, sizeof(sigfigs), 1, pFile); - (void) fwrite(&snaplen, sizeof(snaplen), 1, pFile); - (void) fwrite(&network, sizeof(network), 1, pFile); + (void)fwrite(&magic_number, sizeof(magic_number), 1, pFile); + (void)fwrite(&version_major, sizeof(version_major), 1, pFile); + (void)fwrite(&version_minor, sizeof(version_minor), 1, pFile); + (void)fwrite(&thiszone, sizeof(thiszone), 1, pFile); + (void)fwrite(&sigfigs, sizeof(sigfigs), 1, pFile); + (void)fwrite(&snaplen, sizeof(snaplen), 1, pFile); + (void)fwrite(&network, sizeof(network), 1, pFile); fflush(pFile); fprintf(stdout, "mstpcap: saving capture to %s\n", filename); } else { fprintf(stderr, "mstpcap[header]: failed to open %s: %s\n", filename, - strerror(errno)); + strerror(errno)); } } -static void write_received_packet( - uint8_t * buffer, - unsigned length) +static void write_received_packet(uint8_t *buffer, unsigned length) { - uint32_t ts_sec; /* timestamp seconds */ - uint32_t ts_usec; /* timestamp microseconds */ - uint32_t incl_len; /* number of octets of packet saved in file */ - uint32_t orig_len; /* actual length of packet */ + uint32_t ts_sec; /* timestamp seconds */ + uint32_t ts_usec; /* timestamp microseconds */ + uint32_t incl_len; /* number of octets of packet saved in file */ + uint32_t orig_len; /* actual length of packet */ struct timeval tv; if (pFile) { gettimeofday(&tv, NULL); ts_sec = tv.tv_sec; ts_usec = tv.tv_usec; - (void) fwrite(&ts_sec, sizeof(ts_sec), 1, pFile); - (void) fwrite(&ts_usec, sizeof(ts_usec), 1, pFile); + (void)fwrite(&ts_sec, sizeof(ts_sec), 1, pFile); + (void)fwrite(&ts_usec, sizeof(ts_usec), 1, pFile); orig_len = incl_len = length; - (void) fwrite(&incl_len, sizeof(incl_len), 1, pFile); - (void) fwrite(&orig_len, sizeof(orig_len), 1, pFile); - (void) fwrite(buffer, length, 1, pFile); + (void)fwrite(&incl_len, sizeof(incl_len), 1, pFile); + (void)fwrite(&orig_len, sizeof(orig_len), 1, pFile); + (void)fwrite(buffer, length, 1, pFile); } else { fprintf(stderr, "mstpcrc[packet]: failed to open %s: %s\n", - Capture_Filename, strerror(errno)); + Capture_Filename, strerror(errno)); } } -static void Write_Pcap( - uint8_t * buffer, - unsigned length) +static void Write_Pcap(uint8_t *buffer, unsigned length) { filename_create(&Capture_Filename[0]); write_global_header(&Capture_Filename[0]); @@ -239,7 +230,7 @@ static void Write_Pcap( } } /* hold 3 ASCII characters per byte of data */ -static char Text_Buffer[1024*3]; +static char Text_Buffer[1024 * 3]; static void Process_Text_File(void) { char *argi = NULL; @@ -269,9 +260,7 @@ static void Process_Text_File(void) } /* simple program to CRC the data and print the CRC */ -int main( - int argc, - char *argv[]) +int main(int argc, char *argv[]) { /* accumulates the crc value */ uint8_t crc8 = 0xff; @@ -280,8 +269,10 @@ int main( /* initialize our interface */ if ((argc > 1) && (strcmp(argv[1], "--help") == 0)) { - printf("mstpcrc [options] <05 03 01 0D...>\r\n" - "perform MS/TP CRC on data bytes.\r\n" "options:\r\n" + printf( + "mstpcrc [options] <05 03 01 0D...>\r\n" + "perform MS/TP CRC on data bytes.\r\n" + "options:\r\n" "[-x] interprete the arguments as ascii hex (default)\r\n" "[-d] interprete the argument as ascii decimal\r\n" "[-m] Write the bytes to Wireshark capture file\r\n" @@ -294,7 +285,8 @@ int main( } if ((argc > 1) && (strcmp(argv[1], "--version") == 0)) { printf("mstpcap %s\r\n", BACNET_VERSION_TEXT); - printf("Copyright (C) 2012 by Steve Karg\r\n" + printf( + "Copyright (C) 2012 by Steve Karg\r\n" "This is free software; see the source for copying conditions.\r\n" "There is NO warranty; not even for MERCHANTABILITY or\r\n" "FITNESS FOR A PARTICULAR PURPOSE.\r\n"); @@ -314,7 +306,7 @@ int main( crc16 = CRC_Calc_Data(CRC_Buffer[i], crc16); } if (ASCII_Decimal) { - printf("%u\r\n", (unsigned) CRC_Buffer[i]); + printf("%u\r\n", (unsigned)CRC_Buffer[i]); } else { printf("0x%02X\r\n", CRC_Buffer[i]); } @@ -322,15 +314,15 @@ int main( if (CRC_Size == 8) { crc8 = ~crc8; if (ASCII_Decimal) { - printf("%u Header CRC\r\n", (unsigned) crc8); + printf("%u Header CRC\r\n", (unsigned)crc8); } else { printf("0x%02X Header CRC\r\n", crc8); } } else if (CRC_Size == 16) { crc16 = ~crc16; if (ASCII_Decimal) { - printf("%u Data CRC\r\n", (unsigned) (crc16 & 0xFF)); - printf("%u Data CRC\r\n", (unsigned) (crc16 >> 8)); + printf("%u Data CRC\r\n", (unsigned)(crc16 & 0xFF)); + printf("%u Data CRC\r\n", (unsigned)(crc16 >> 8)); } else { printf("0x%02X Data CRC\r\n", (crc16 & 0xFF)); printf("0x%02X Data CRC\r\n", (crc16 >> 8)); diff --git a/demo/object/access_credential.c b/demo/object/access_credential.c index ce998ac6..9ea5aa13 100644 --- a/demo/object/access_credential.c +++ b/demo/object/access_credential.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2015 Nikola Jelic -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the credential to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2015 Nikola Jelic + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the credential to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* Access Credential Objects - customize for your use */ @@ -33,7 +33,7 @@ #include "bacdcode.h" #include "bacenum.h" #include "bacapp.h" -#include "config.h" /* the custom stuff */ +#include "config.h" /* the custom stuff */ #include "wp.h" #include "access_credential.h" #include "handlers.h" @@ -43,35 +43,28 @@ static bool Access_Credential_Initialized = false; static ACCESS_CREDENTIAL_DESCR ac_descr[MAX_ACCESS_CREDENTIALS]; /* These three arrays are used by the ReadPropertyMultiple handler */ -static const int Properties_Required[] = { - PROP_OBJECT_IDENTIFIER, - PROP_OBJECT_NAME, - PROP_OBJECT_TYPE, - PROP_GLOBAL_IDENTIFIER, - PROP_STATUS_FLAGS, - PROP_RELIABILITY, - PROP_CREDENTIAL_STATUS, - PROP_REASON_FOR_DISABLE, - PROP_AUTHENTICATION_FACTORS, - PROP_ACTIVATION_TIME, - PROP_EXPIRATION_TIME, - PROP_CREDENTIAL_DISABLE, - PROP_ASSIGNED_ACCESS_RIGHTS, - -1 -}; +static const int Properties_Required[] = {PROP_OBJECT_IDENTIFIER, + PROP_OBJECT_NAME, + PROP_OBJECT_TYPE, + PROP_GLOBAL_IDENTIFIER, + PROP_STATUS_FLAGS, + PROP_RELIABILITY, + PROP_CREDENTIAL_STATUS, + PROP_REASON_FOR_DISABLE, + PROP_AUTHENTICATION_FACTORS, + PROP_ACTIVATION_TIME, + PROP_EXPIRATION_TIME, + PROP_CREDENTIAL_DISABLE, + PROP_ASSIGNED_ACCESS_RIGHTS, + -1}; -static const int Properties_Optional[] = { - -1 -}; +static const int Properties_Optional[] = {-1}; -static const int Properties_Proprietary[] = { - -1 -}; +static const int Properties_Proprietary[] = {-1}; -void Access_Credential_Property_Lists( - const int **pRequired, - const int **pOptional, - const int **pProprietary) +void Access_Credential_Property_Lists(const int **pRequired, + const int **pOptional, + const int **pProprietary) { if (pRequired) *pRequired = Properties_Required; @@ -83,8 +76,7 @@ void Access_Credential_Property_Lists( return; } -void Access_Credential_Init( - void) +void Access_Credential_Init(void) { unsigned i; @@ -92,7 +84,8 @@ void Access_Credential_Init( Access_Credential_Initialized = true; for (i = 0; i < MAX_ACCESS_CREDENTIALS; i++) { - ac_descr[i].global_identifier = 0; /* set to some meaningful value */ + ac_descr[i].global_identifier = + 0; /* set to some meaningful value */ ac_descr[i].reliability = RELIABILITY_NO_FAULT_DETECTED; ac_descr[i].credential_status = false; ac_descr[i].reasons_count = 0; @@ -110,8 +103,7 @@ void Access_Credential_Init( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need validate that the */ /* given instance exists */ -bool Access_Credential_Valid_Instance( - uint32_t object_instance) +bool Access_Credential_Valid_Instance(uint32_t object_instance) { if (object_instance < MAX_ACCESS_CREDENTIALS) return true; @@ -121,8 +113,7 @@ bool Access_Credential_Valid_Instance( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then count how many you have */ -unsigned Access_Credential_Count( - void) +unsigned Access_Credential_Count(void) { return MAX_ACCESS_CREDENTIALS; } @@ -130,8 +121,7 @@ unsigned Access_Credential_Count( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need to return the instance */ /* that correlates to the correct index */ -uint32_t Access_Credential_Index_To_Instance( - unsigned index) +uint32_t Access_Credential_Index_To_Instance(unsigned index) { return index; } @@ -139,8 +129,7 @@ uint32_t Access_Credential_Index_To_Instance( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need to return the index */ /* that correlates to the correct instance number */ -unsigned Access_Credential_Instance_To_Index( - uint32_t object_instance) +unsigned Access_Credential_Instance_To_Index(uint32_t object_instance) { unsigned index = MAX_ACCESS_CREDENTIALS; @@ -151,16 +140,15 @@ unsigned Access_Credential_Instance_To_Index( } /* note: the object name must be unique within this device */ -bool Access_Credential_Object_Name( - uint32_t object_instance, - BACNET_CHARACTER_STRING * object_name) +bool Access_Credential_Object_Name(uint32_t object_instance, + BACNET_CHARACTER_STRING *object_name) { - static char text_string[32] = ""; /* okay for single thread */ + static char text_string[32] = ""; /* okay for single thread */ bool status = false; if (object_instance < MAX_ACCESS_CREDENTIALS) { sprintf(text_string, "ACCESS CREDENTIAL %lu", - (unsigned long) object_instance); + (unsigned long)object_instance); status = characterstring_init_ansi(object_name, text_string); } @@ -168,11 +156,10 @@ bool Access_Credential_Object_Name( } /* return apdu len, or BACNET_STATUS_ERROR on error */ -int Access_Credential_Read_Property( - BACNET_READ_PROPERTY_DATA * rpdata) +int Access_Credential_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata) { int len = 0; - int apdu_len = 0; /* return value */ + int apdu_len = 0; /* return value */ BACNET_BIT_STRING bit_string; BACNET_CHARACTER_STRING char_string; unsigned object_index = 0; @@ -184,29 +171,25 @@ int Access_Credential_Read_Property( return 0; } apdu = rpdata->application_data; - object_index = - Access_Credential_Instance_To_Index(rpdata->object_instance); + object_index = Access_Credential_Instance_To_Index(rpdata->object_instance); switch (rpdata->object_property) { case PROP_OBJECT_IDENTIFIER: - apdu_len = - encode_application_object_id(&apdu[0], - OBJECT_ACCESS_CREDENTIAL, rpdata->object_instance); + apdu_len = encode_application_object_id( + &apdu[0], OBJECT_ACCESS_CREDENTIAL, rpdata->object_instance); break; case PROP_OBJECT_NAME: Access_Credential_Object_Name(rpdata->object_instance, - &char_string); + &char_string); apdu_len = encode_application_character_string(&apdu[0], &char_string); break; case PROP_OBJECT_TYPE: - apdu_len = - encode_application_enumerated(&apdu[0], - OBJECT_ACCESS_CREDENTIAL); + apdu_len = encode_application_enumerated(&apdu[0], + OBJECT_ACCESS_CREDENTIAL); break; case PROP_GLOBAL_IDENTIFIER: - apdu_len = - encode_application_unsigned(&apdu[0], - ac_descr[object_index].global_identifier); + apdu_len = encode_application_unsigned( + &apdu[0], ac_descr[object_index].global_identifier); break; case PROP_STATUS_FLAGS: bitstring_init(&bit_string); @@ -217,20 +200,17 @@ int Access_Credential_Read_Property( apdu_len = encode_application_bitstring(&apdu[0], &bit_string); break; case PROP_RELIABILITY: - apdu_len = - encode_application_enumerated(&apdu[0], - ac_descr[object_index].reliability); + apdu_len = encode_application_enumerated( + &apdu[0], ac_descr[object_index].reliability); break; case PROP_CREDENTIAL_STATUS: - apdu_len = - encode_application_enumerated(&apdu[0], - ac_descr[object_index].credential_status); + apdu_len = encode_application_enumerated( + &apdu[0], ac_descr[object_index].credential_status); break; case PROP_REASON_FOR_DISABLE: for (i = 0; i < ac_descr[object_index].reasons_count; i++) { - len = - encode_application_enumerated(&apdu[0], - ac_descr[object_index].reason_for_disable[i]); + len = encode_application_enumerated( + &apdu[0], ac_descr[object_index].reason_for_disable[i]); if (apdu_len + len < MAX_APDU) apdu_len += len; else { @@ -243,14 +223,13 @@ int Access_Credential_Read_Property( break; case PROP_AUTHENTICATION_FACTORS: if (rpdata->array_index == 0) { - apdu_len = - encode_application_unsigned(&apdu[0], - ac_descr[object_index].auth_factors_count); + apdu_len = encode_application_unsigned( + &apdu[0], ac_descr[object_index].auth_factors_count); } else if (rpdata->array_index == BACNET_ARRAY_ALL) { - for (i = 0; i < ac_descr[object_index].auth_factors_count; i++) { - len = - bacapp_encode_credential_authentication_factor(&apdu - [0], &ac_descr[object_index].auth_factors[i]); + for (i = 0; i < ac_descr[object_index].auth_factors_count; + i++) { + len = bacapp_encode_credential_authentication_factor( + &apdu[0], &ac_descr[object_index].auth_factors[i]); if (apdu_len + len < MAX_APDU) apdu_len += len; else { @@ -263,11 +242,9 @@ int Access_Credential_Read_Property( } else { if (rpdata->array_index <= ac_descr[object_index].auth_factors_count) { - apdu_len = - bacapp_encode_credential_authentication_factor(&apdu - [0], - &ac_descr[object_index]. - auth_factors[rpdata->array_index - 1]); + apdu_len = bacapp_encode_credential_authentication_factor( + &apdu[0], &ac_descr[object_index] + .auth_factors[rpdata->array_index - 1]); } else { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX; @@ -276,31 +253,28 @@ int Access_Credential_Read_Property( } break; case PROP_ACTIVATION_TIME: - apdu_len = - bacapp_encode_datetime(&apdu[0], - &ac_descr[object_index].activation_time); + apdu_len = bacapp_encode_datetime( + &apdu[0], &ac_descr[object_index].activation_time); break; case PROP_EXPIRATION_TIME: - apdu_len = - bacapp_encode_datetime(&apdu[0], - &ac_descr[object_index].expiration_time); + apdu_len = bacapp_encode_datetime( + &apdu[0], &ac_descr[object_index].expiration_time); break; case PROP_CREDENTIAL_DISABLE: - apdu_len = - encode_application_enumerated(&apdu[0], - ac_descr[object_index].credential_disable); + apdu_len = encode_application_enumerated( + &apdu[0], ac_descr[object_index].credential_disable); break; case PROP_ASSIGNED_ACCESS_RIGHTS: if (rpdata->array_index == 0) { - apdu_len = - encode_application_unsigned(&apdu[0], + apdu_len = encode_application_unsigned( + &apdu[0], ac_descr[object_index].assigned_access_rights_count); } else if (rpdata->array_index == BACNET_ARRAY_ALL) { for (i = 0; - i < ac_descr[object_index].assigned_access_rights_count; - i++) { - len = - bacapp_encode_assigned_access_rights(&apdu[0], + i < ac_descr[object_index].assigned_access_rights_count; + i++) { + len = bacapp_encode_assigned_access_rights( + &apdu[0], &ac_descr[object_index].assigned_access_rights[i]); if (apdu_len + len < MAX_APDU) apdu_len += len; @@ -314,10 +288,10 @@ int Access_Credential_Read_Property( } else { if (rpdata->array_index <= ac_descr[object_index].assigned_access_rights_count) { - apdu_len = - bacapp_encode_assigned_access_rights(&apdu[0], - &ac_descr[object_index]. - assigned_access_rights[rpdata->array_index - 1]); + apdu_len = bacapp_encode_assigned_access_rights( + &apdu[0], + &ac_descr[object_index] + .assigned_access_rights[rpdata->array_index - 1]); } else { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX; @@ -333,9 +307,9 @@ int Access_Credential_Read_Property( } /* only array properties can have array options */ if ((apdu_len >= 0) && - (rpdata->object_property != PROP_AUTHENTICATION_FACTORS) - && (rpdata->object_property != PROP_ASSIGNED_ACCESS_RIGHTS) - && (rpdata->array_index != BACNET_ARRAY_ALL)) { + (rpdata->object_property != PROP_AUTHENTICATION_FACTORS) && + (rpdata->object_property != PROP_ASSIGNED_ACCESS_RIGHTS) && + (rpdata->array_index != BACNET_ARRAY_ALL)) { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; apdu_len = BACNET_STATUS_ERROR; @@ -345,18 +319,16 @@ int Access_Credential_Read_Property( } /* returns true if successful */ -bool Access_Credential_Write_Property( - BACNET_WRITE_PROPERTY_DATA * wp_data) +bool Access_Credential_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data) { - bool status = false; /* return value */ + bool status = false; /* return value */ int len = 0; BACNET_APPLICATION_DATA_VALUE value; unsigned object_index = 0; /* decode the some of the request */ - len = - bacapp_decode_application_data(wp_data->application_data, - wp_data->application_data_len, &value); + len = bacapp_decode_application_data(wp_data->application_data, + wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ if (len < 0) { /* error while decoding - a value larger than we can handle */ @@ -365,9 +337,9 @@ bool Access_Credential_Write_Property( return false; } /* only array properties can have array options */ - if ((wp_data->object_property != PROP_AUTHENTICATION_FACTORS) - && (wp_data->object_property != PROP_ASSIGNED_ACCESS_RIGHTS) - && (wp_data->array_index != BACNET_ARRAY_ALL)) { + if ((wp_data->object_property != PROP_AUTHENTICATION_FACTORS) && + (wp_data->object_property != PROP_ASSIGNED_ACCESS_RIGHTS) && + (wp_data->array_index != BACNET_ARRAY_ALL)) { wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; return false; @@ -378,7 +350,7 @@ bool Access_Credential_Write_Property( case PROP_GLOBAL_IDENTIFIER: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { ac_descr[object_index].global_identifier = value.type.Unsigned_Int; @@ -408,17 +380,14 @@ bool Access_Credential_Write_Property( return status; } - #ifdef TEST #include #include #include "ctest.h" -bool WPValidateArgType( - BACNET_APPLICATION_DATA_VALUE * pValue, - uint8_t ucExpectedTag, - BACNET_ERROR_CLASS * pErrorClass, - BACNET_ERROR_CODE * pErrorCode) +bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue, + uint8_t ucExpectedTag, BACNET_ERROR_CLASS *pErrorClass, + BACNET_ERROR_CODE *pErrorCode) { pValue = pValue; ucExpectedTag = ucExpectedTag; @@ -428,10 +397,9 @@ bool WPValidateArgType( return false; } -void testAccessCredential( - Test * pTest) +void testAccessCredential(Test *pTest) { - uint8_t apdu[MAX_APDU] = { 0 }; + uint8_t apdu[MAX_APDU] = {0}; int len = 0; uint32_t len_value = 0; uint8_t tag_number = 0; @@ -458,8 +426,7 @@ void testAccessCredential( } #ifdef TEST_ACCESS_CREDENTIAL -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -471,7 +438,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/demo/object/access_door.c b/demo/object/access_door.c index 56c52c53..87f99920 100644 --- a/demo/object/access_door.c +++ b/demo/object/access_door.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2015 Nikola Jelic -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2015 Nikola Jelic + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* Access Door Objects - customize for your use */ @@ -32,7 +32,7 @@ #include "bacdcode.h" #include "bacenum.h" #include "bacapp.h" -#include "config.h" /* the custom stuff */ +#include "config.h" /* the custom stuff */ #include "wp.h" #include "access_door.h" #include "handlers.h" @@ -42,40 +42,30 @@ static bool Access_Door_Initialized = false; static ACCESS_DOOR_DESCR ad_descr[MAX_ACCESS_DOORS]; /* These three arrays are used by the ReadPropertyMultiple handler */ -static const int Properties_Required[] = { - PROP_OBJECT_IDENTIFIER, - PROP_OBJECT_NAME, - PROP_OBJECT_TYPE, - PROP_PRESENT_VALUE, - PROP_STATUS_FLAGS, - PROP_EVENT_STATE, - PROP_RELIABILITY, - PROP_OUT_OF_SERVICE, - PROP_PRIORITY_ARRAY, - PROP_RELINQUISH_DEFAULT, - PROP_DOOR_PULSE_TIME, - PROP_DOOR_EXTENDED_PULSE_TIME, - PROP_DOOR_OPEN_TOO_LONG_TIME, - -1 -}; +static const int Properties_Required[] = {PROP_OBJECT_IDENTIFIER, + PROP_OBJECT_NAME, + PROP_OBJECT_TYPE, + PROP_PRESENT_VALUE, + PROP_STATUS_FLAGS, + PROP_EVENT_STATE, + PROP_RELIABILITY, + PROP_OUT_OF_SERVICE, + PROP_PRIORITY_ARRAY, + PROP_RELINQUISH_DEFAULT, + PROP_DOOR_PULSE_TIME, + PROP_DOOR_EXTENDED_PULSE_TIME, + PROP_DOOR_OPEN_TOO_LONG_TIME, + -1}; static const int Properties_Optional[] = { - PROP_DOOR_STATUS, - PROP_LOCK_STATUS, - PROP_SECURED_STATUS, - PROP_DOOR_UNLOCK_DELAY_TIME, - PROP_DOOR_ALARM_STATE, - -1 -}; + PROP_DOOR_STATUS, PROP_LOCK_STATUS, + PROP_SECURED_STATUS, PROP_DOOR_UNLOCK_DELAY_TIME, + PROP_DOOR_ALARM_STATE, -1}; -static const int Properties_Proprietary[] = { - -1 -}; +static const int Properties_Proprietary[] = {-1}; -void Access_Door_Property_Lists( - const int **pRequired, - const int **pOptional, - const int **pProprietary) +void Access_Door_Property_Lists(const int **pRequired, const int **pOptional, + const int **pProprietary) { if (pRequired) *pRequired = Properties_Required; @@ -87,8 +77,7 @@ void Access_Door_Property_Lists( return; } -void Access_Door_Init( - void) +void Access_Door_Init(void) { unsigned i, j; @@ -104,10 +93,10 @@ void Access_Door_Init( ad_descr[i].door_status = DOOR_STATUS_CLOSED; ad_descr[i].lock_status = LOCK_STATUS_LOCKED; ad_descr[i].secured_status = DOOR_SECURED_STATUS_SECURED; - ad_descr[i].door_pulse_time = 30; /* 3s */ - ad_descr[i].door_extended_pulse_time = 50; /* 5s */ - ad_descr[i].door_unlock_delay_time = 0; /* 0s */ - ad_descr[i].door_open_too_long_time = 300; /* 30s */ + ad_descr[i].door_pulse_time = 30; /* 3s */ + ad_descr[i].door_extended_pulse_time = 50; /* 5s */ + ad_descr[i].door_unlock_delay_time = 0; /* 0s */ + ad_descr[i].door_open_too_long_time = 300; /* 30s */ ad_descr[i].door_alarm_state = DOOR_ALARM_STATE_NORMAL; for (j = 0; j < BACNET_MAX_PRIORITY; j++) { ad_descr[i].value_active[j] = false; @@ -123,8 +112,7 @@ void Access_Door_Init( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need validate that the */ /* given instance exists */ -bool Access_Door_Valid_Instance( - uint32_t object_instance) +bool Access_Door_Valid_Instance(uint32_t object_instance) { if (object_instance < MAX_ACCESS_DOORS) return true; @@ -134,8 +122,7 @@ bool Access_Door_Valid_Instance( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then count how many you have */ -unsigned Access_Door_Count( - void) +unsigned Access_Door_Count(void) { return MAX_ACCESS_DOORS; } @@ -143,8 +130,7 @@ unsigned Access_Door_Count( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need to return the instance */ /* that correlates to the correct index */ -uint32_t Access_Door_Index_To_Instance( - unsigned index) +uint32_t Access_Door_Index_To_Instance(unsigned index) { return index; } @@ -152,8 +138,7 @@ uint32_t Access_Door_Index_To_Instance( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need to return the index */ /* that correlates to the correct instance number */ -unsigned Access_Door_Instance_To_Index( - uint32_t object_instance) +unsigned Access_Door_Instance_To_Index(uint32_t object_instance) { unsigned index = MAX_ACCESS_DOORS; @@ -163,8 +148,7 @@ unsigned Access_Door_Instance_To_Index( return index; } -BACNET_DOOR_VALUE Access_Door_Present_Value( - uint32_t object_instance) +BACNET_DOOR_VALUE Access_Door_Present_Value(uint32_t object_instance) { unsigned index = 0; unsigned i = 0; @@ -183,12 +167,11 @@ BACNET_DOOR_VALUE Access_Door_Present_Value( return value; } -unsigned Access_Door_Present_Value_Priority( - uint32_t object_instance) +unsigned Access_Door_Present_Value_Priority(uint32_t object_instance) { - unsigned index = 0; /* instance to index conversion */ - unsigned i = 0; /* loop counter */ - unsigned priority = 0; /* return value */ + unsigned index = 0; /* instance to index conversion */ + unsigned i = 0; /* loop counter */ + unsigned priority = 0; /* return value */ index = Access_Door_Instance_To_Index(object_instance); if (index < MAX_ACCESS_DOORS) { @@ -203,10 +186,8 @@ unsigned Access_Door_Present_Value_Priority( return priority; } -bool Access_Door_Present_Value_Set( - uint32_t object_instance, - BACNET_DOOR_VALUE value, - unsigned priority) +bool Access_Door_Present_Value_Set(uint32_t object_instance, + BACNET_DOOR_VALUE value, unsigned priority) { unsigned index = 0; bool status = false; @@ -214,8 +195,7 @@ bool Access_Door_Present_Value_Set( index = Access_Door_Instance_To_Index(object_instance); if (index < MAX_ACCESS_DOORS) { if (priority && (priority <= BACNET_MAX_PRIORITY) && - (priority != 6 /* reserved */ ) && - (value >= DOOR_VALUE_LOCK) && + (priority != 6 /* reserved */) && (value >= DOOR_VALUE_LOCK) && (value <= DOOR_VALUE_EXTENDED_PULSE_UNLOCK)) { ad_descr[index].value_active[priority - 1] = true; ad_descr[index].priority_array[priority - 1] = value; @@ -232,9 +212,8 @@ bool Access_Door_Present_Value_Set( return status; } -bool Access_Door_Present_Value_Relinquish( - uint32_t object_instance, - unsigned priority) +bool Access_Door_Present_Value_Relinquish(uint32_t object_instance, + unsigned priority) { unsigned index = 0; bool status = false; @@ -242,7 +221,7 @@ bool Access_Door_Present_Value_Relinquish( index = Access_Door_Instance_To_Index(object_instance); if (index < MAX_ACCESS_DOORS) { if (priority && (priority <= BACNET_MAX_PRIORITY) && - (priority != 6 /* reserved */ )) { + (priority != 6 /* reserved */)) { ad_descr[index].value_active[priority - 1] = false; /* Note: you could set the physical output here to the next highest priority, or to the relinquish default if no @@ -257,8 +236,7 @@ bool Access_Door_Present_Value_Relinquish( return status; } -BACNET_DOOR_VALUE Access_Door_Relinquish_Default( - uint32_t object_instance) +BACNET_DOOR_VALUE Access_Door_Relinquish_Default(uint32_t object_instance) { BACNET_DOOR_VALUE status = -1; unsigned index = 0; @@ -271,24 +249,21 @@ BACNET_DOOR_VALUE Access_Door_Relinquish_Default( } /* note: the object name must be unique within this device */ -bool Access_Door_Object_Name( - uint32_t object_instance, - BACNET_CHARACTER_STRING * object_name) +bool Access_Door_Object_Name(uint32_t object_instance, + BACNET_CHARACTER_STRING *object_name) { - static char text_string[32] = ""; /* okay for single thread */ + static char text_string[32] = ""; /* okay for single thread */ bool status = false; if (object_instance < MAX_ACCESS_DOORS) { - sprintf(text_string, "ACCESS DOOR %lu", - (unsigned long) object_instance); + sprintf(text_string, "ACCESS DOOR %lu", (unsigned long)object_instance); status = characterstring_init_ansi(object_name, text_string); } return status; } -bool Access_Door_Out_Of_Service( - uint32_t instance) +bool Access_Door_Out_Of_Service(uint32_t instance) { unsigned index = 0; bool oos_flag = false; @@ -301,9 +276,7 @@ bool Access_Door_Out_Of_Service( return oos_flag; } -void Access_Door_Out_Of_Service_Set( - uint32_t instance, - bool oos_flag) +void Access_Door_Out_Of_Service_Set(uint32_t instance, bool oos_flag) { unsigned index = 0; @@ -314,11 +287,10 @@ void Access_Door_Out_Of_Service_Set( } /* return apdu len, or BACNET_STATUS_ERROR on error */ -int Access_Door_Read_Property( - BACNET_READ_PROPERTY_DATA * rpdata) +int Access_Door_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata) { int len = 0; - int apdu_len = 0; /* return value */ + int apdu_len = 0; /* return value */ BACNET_BIT_STRING bit_string; BACNET_CHARACTER_STRING char_string; unsigned object_index = 0; @@ -334,9 +306,8 @@ int Access_Door_Read_Property( object_index = Access_Door_Instance_To_Index(rpdata->object_instance); switch (rpdata->object_property) { case PROP_OBJECT_IDENTIFIER: - apdu_len = - encode_application_object_id(&apdu[0], OBJECT_ACCESS_DOOR, - rpdata->object_instance); + apdu_len = encode_application_object_id( + &apdu[0], OBJECT_ACCESS_DOOR, rpdata->object_instance); break; case PROP_OBJECT_NAME: Access_Door_Object_Name(rpdata->object_instance, &char_string); @@ -348,9 +319,8 @@ int Access_Door_Read_Property( encode_application_enumerated(&apdu[0], OBJECT_ACCESS_DOOR); break; case PROP_PRESENT_VALUE: - apdu_len = - encode_application_enumerated(&apdu[0], - Access_Door_Present_Value(rpdata->object_instance)); + apdu_len = encode_application_enumerated( + &apdu[0], Access_Door_Present_Value(rpdata->object_instance)); break; case PROP_STATUS_FLAGS: bitstring_init(&bit_string); @@ -362,14 +332,12 @@ int Access_Door_Read_Property( apdu_len = encode_application_bitstring(&apdu[0], &bit_string); break; case PROP_EVENT_STATE: - apdu_len = - encode_application_enumerated(&apdu[0], - ad_descr[object_index].event_state); + apdu_len = encode_application_enumerated( + &apdu[0], ad_descr[object_index].event_state); break; case PROP_RELIABILITY: - apdu_len = - encode_application_enumerated(&apdu[0], - ad_descr[object_index].reliability); + apdu_len = encode_application_enumerated( + &apdu[0], ad_descr[object_index].reliability); break; case PROP_OUT_OF_SERVICE: state = Access_Door_Out_Of_Service(rpdata->object_instance); @@ -388,8 +356,8 @@ int Access_Door_Read_Property( if (ad_descr[object_index].value_active[i]) len = encode_application_null(&apdu[apdu_len]); else - len = - encode_application_enumerated(&apdu[apdu_len], + len = encode_application_enumerated( + &apdu[apdu_len], ad_descr[object_index].priority_array[i]); /* add it if we have room */ if ((apdu_len + len) < MAX_APDU) @@ -406,8 +374,8 @@ int Access_Door_Read_Property( if (ad_descr[object_index].value_active[i]) apdu_len = encode_application_null(&apdu[0]); else { - apdu_len = - encode_application_enumerated(&apdu[apdu_len], + apdu_len = encode_application_enumerated( + &apdu[apdu_len], ad_descr[object_index].priority_array[i]); } } else { @@ -418,49 +386,41 @@ int Access_Door_Read_Property( } break; case PROP_RELINQUISH_DEFAULT: - apdu_len = - encode_application_enumerated(&apdu[0], + apdu_len = encode_application_enumerated( + &apdu[0], Access_Door_Relinquish_Default(rpdata->object_instance)); break; case PROP_DOOR_STATUS: - apdu_len = - encode_application_enumerated(&apdu[0], - ad_descr[object_index].door_status); + apdu_len = encode_application_enumerated( + &apdu[0], ad_descr[object_index].door_status); break; case PROP_LOCK_STATUS: - apdu_len = - encode_application_enumerated(&apdu[0], - ad_descr[object_index].lock_status); + apdu_len = encode_application_enumerated( + &apdu[0], ad_descr[object_index].lock_status); break; case PROP_SECURED_STATUS: - apdu_len = - encode_application_enumerated(&apdu[0], - ad_descr[object_index].secured_status); + apdu_len = encode_application_enumerated( + &apdu[0], ad_descr[object_index].secured_status); break; case PROP_DOOR_PULSE_TIME: - apdu_len = - encode_application_unsigned(&apdu[0], - ad_descr[object_index].door_pulse_time); + apdu_len = encode_application_unsigned( + &apdu[0], ad_descr[object_index].door_pulse_time); break; case PROP_DOOR_EXTENDED_PULSE_TIME: - apdu_len = - encode_application_unsigned(&apdu[0], - ad_descr[object_index].door_extended_pulse_time); + apdu_len = encode_application_unsigned( + &apdu[0], ad_descr[object_index].door_extended_pulse_time); break; case PROP_DOOR_UNLOCK_DELAY_TIME: - apdu_len = - encode_application_unsigned(&apdu[0], - ad_descr[object_index].door_unlock_delay_time); + apdu_len = encode_application_unsigned( + &apdu[0], ad_descr[object_index].door_unlock_delay_time); break; case PROP_DOOR_OPEN_TOO_LONG_TIME: - apdu_len = - encode_application_unsigned(&apdu[0], - ad_descr[object_index].door_open_too_long_time); + apdu_len = encode_application_unsigned( + &apdu[0], ad_descr[object_index].door_open_too_long_time); break; case PROP_DOOR_ALARM_STATE: - apdu_len = - encode_application_enumerated(&apdu[0], - ad_descr[object_index].door_alarm_state); + apdu_len = encode_application_enumerated( + &apdu[0], ad_descr[object_index].door_alarm_state); break; default: rpdata->error_class = ERROR_CLASS_PROPERTY; @@ -480,18 +440,16 @@ int Access_Door_Read_Property( } /* returns true if successful */ -bool Access_Door_Write_Property( - BACNET_WRITE_PROPERTY_DATA * wp_data) +bool Access_Door_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data) { - bool status = false; /* return value */ + bool status = false; /* return value */ int len = 0; BACNET_APPLICATION_DATA_VALUE value; unsigned object_index = 0; /* decode the some of the request */ - len = - bacapp_decode_application_data(wp_data->application_data, - wp_data->application_data_len, &value); + len = bacapp_decode_application_data(wp_data->application_data, + wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ if (len < 0) { /* error while decoding - a value larger than we can handle */ @@ -513,9 +471,9 @@ bool Access_Door_Write_Property( /* Command priority 6 is reserved for use by Minimum On/Off algorithm and may not be used for other purposes in any object. */ - status = - Access_Door_Present_Value_Set(wp_data->object_instance, - value.type.Enumerated, wp_data->priority); + status = Access_Door_Present_Value_Set(wp_data->object_instance, + value.type.Enumerated, + 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 @@ -527,13 +485,12 @@ bool Access_Door_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) { - status = - Access_Door_Present_Value_Relinquish - (wp_data->object_instance, wp_data->priority); + status = Access_Door_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; @@ -544,18 +501,17 @@ bool Access_Door_Write_Property( case PROP_OUT_OF_SERVICE: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { Access_Door_Out_Of_Service_Set(wp_data->object_instance, - value.type.Boolean); + value.type.Boolean); } break; case PROP_DOOR_STATUS: if (Access_Door_Out_Of_Service(wp_data->object_instance)) { - 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) { ad_descr[object_index].door_status = value.type.Enumerated; } @@ -566,10 +522,9 @@ bool Access_Door_Write_Property( break; case PROP_LOCK_STATUS: if (Access_Door_Out_Of_Service(wp_data->object_instance)) { - 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) { ad_descr[object_index].lock_status = value.type.Enumerated; } @@ -580,10 +535,9 @@ bool Access_Door_Write_Property( break; case PROP_DOOR_ALARM_STATE: if (Access_Door_Out_Of_Service(wp_data->object_instance)) { - 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) { ad_descr[object_index].door_alarm_state = value.type.Enumerated; @@ -618,17 +572,14 @@ bool Access_Door_Write_Property( return status; } - #ifdef TEST #include #include #include "ctest.h" -bool WPValidateArgType( - BACNET_APPLICATION_DATA_VALUE * pValue, - uint8_t ucExpectedTag, - BACNET_ERROR_CLASS * pErrorClass, - BACNET_ERROR_CODE * pErrorCode) +bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue, + uint8_t ucExpectedTag, BACNET_ERROR_CLASS *pErrorClass, + BACNET_ERROR_CODE *pErrorCode) { pValue = pValue; ucExpectedTag = ucExpectedTag; @@ -638,10 +589,9 @@ bool WPValidateArgType( return false; } -void testAccessDoor( - Test * pTest) +void testAccessDoor(Test *pTest) { - uint8_t apdu[MAX_APDU] = { 0 }; + uint8_t apdu[MAX_APDU] = {0}; int len = 0; uint32_t len_value = 0; uint8_t tag_number = 0; @@ -668,8 +618,7 @@ void testAccessDoor( } #ifdef TEST_ACCESS_DOOR -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -681,7 +630,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/demo/object/access_point.c b/demo/object/access_point.c index 65a2944c..c8f1102c 100644 --- a/demo/object/access_point.c +++ b/demo/object/access_point.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2015 Nikola Jelic -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2015 Nikola Jelic + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* Access Point Objects - customize for your use */ @@ -32,7 +32,7 @@ #include "bacdcode.h" #include "bacenum.h" #include "bacapp.h" -#include "config.h" /* the custom stuff */ +#include "config.h" /* the custom stuff */ #include "wp.h" #include "access_point.h" #include "handlers.h" @@ -60,21 +60,14 @@ static const int Properties_Required[] = { PROP_ACCESS_EVENT_CREDENTIAL, PROP_ACCESS_DOORS, PROP_PRIORITY_FOR_WRITING, - -1 -}; + -1}; -static const int Properties_Optional[] = { - -1 -}; +static const int Properties_Optional[] = {-1}; -static const int Properties_Proprietary[] = { - -1 -}; +static const int Properties_Proprietary[] = {-1}; -void Access_Point_Property_Lists( - const int **pRequired, - const int **pOptional, - const int **pProprietary) +void Access_Point_Property_Lists(const int **pRequired, const int **pOptional, + const int **pProprietary) { if (pRequired) *pRequired = Properties_Required; @@ -86,8 +79,7 @@ void Access_Point_Property_Lists( return; } -void Access_Point_Init( - void) +void Access_Point_Init(void) { unsigned i; @@ -98,8 +90,7 @@ void Access_Point_Init( ap_descr[i].event_state = EVENT_STATE_NORMAL; ap_descr[i].reliability = RELIABILITY_NO_FAULT_DETECTED; ap_descr[i].out_of_service = false; - ap_descr[i].authentication_status = - AUTHENTICATION_STATUS_NOT_READY; + ap_descr[i].authentication_status = AUTHENTICATION_STATUS_NOT_READY; ap_descr[i].active_authentication_policy = 0; ap_descr[i].number_of_authentication_policies = 0; ap_descr[i].authorization_mode = AUTHORIZATION_MODE_AUTHORIZE; @@ -108,7 +99,7 @@ void Access_Point_Init( /* access_event_credential should be set to some meaningful value */ ap_descr[i].num_doors = 0; /* fill in the access doors with proper ids */ - ap_descr[i].priority_for_writing = 16; /* lowest possible for now */ + ap_descr[i].priority_for_writing = 16; /* lowest possible for now */ } } @@ -118,8 +109,7 @@ void Access_Point_Init( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need validate that the */ /* given instance exists */ -bool Access_Point_Valid_Instance( - uint32_t object_instance) +bool Access_Point_Valid_Instance(uint32_t object_instance) { if (object_instance < MAX_ACCESS_POINTS) return true; @@ -129,8 +119,7 @@ bool Access_Point_Valid_Instance( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then count how many you have */ -unsigned Access_Point_Count( - void) +unsigned Access_Point_Count(void) { return MAX_ACCESS_POINTS; } @@ -138,8 +127,7 @@ unsigned Access_Point_Count( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need to return the instance */ /* that correlates to the correct index */ -uint32_t Access_Point_Index_To_Instance( - unsigned index) +uint32_t Access_Point_Index_To_Instance(unsigned index) { return index; } @@ -147,8 +135,7 @@ uint32_t Access_Point_Index_To_Instance( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need to return the index */ /* that correlates to the correct instance number */ -unsigned Access_Point_Instance_To_Index( - uint32_t object_instance) +unsigned Access_Point_Instance_To_Index(uint32_t object_instance) { unsigned index = MAX_ACCESS_POINTS; @@ -159,24 +146,22 @@ unsigned Access_Point_Instance_To_Index( } /* note: the object name must be unique within this device */ -bool Access_Point_Object_Name( - uint32_t object_instance, - BACNET_CHARACTER_STRING * object_name) +bool Access_Point_Object_Name(uint32_t object_instance, + BACNET_CHARACTER_STRING *object_name) { - static char text_string[32] = ""; /* okay for single thread */ + static char text_string[32] = ""; /* okay for single thread */ bool status = false; if (object_instance < MAX_ACCESS_POINTS) { sprintf(text_string, "ACCESS POINT %lu", - (unsigned long) object_instance); + (unsigned long)object_instance); status = characterstring_init_ansi(object_name, text_string); } return status; } -bool Access_Point_Out_Of_Service( - uint32_t instance) +bool Access_Point_Out_Of_Service(uint32_t instance) { unsigned index = 0; bool oos_flag = false; @@ -189,9 +174,7 @@ bool Access_Point_Out_Of_Service( return oos_flag; } -void Access_Point_Out_Of_Service_Set( - uint32_t instance, - bool oos_flag) +void Access_Point_Out_Of_Service_Set(uint32_t instance, bool oos_flag) { unsigned index = 0; @@ -202,11 +185,10 @@ void Access_Point_Out_Of_Service_Set( } /* return apdu len, or BACNET_STATUS_ERROR on error */ -int Access_Point_Read_Property( - BACNET_READ_PROPERTY_DATA * rpdata) +int Access_Point_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata) { int len = 0; - int apdu_len = 0; /* return value */ + int apdu_len = 0; /* return value */ BACNET_BIT_STRING bit_string; BACNET_CHARACTER_STRING char_string; unsigned object_index = 0; @@ -222,9 +204,8 @@ int Access_Point_Read_Property( object_index = Access_Point_Instance_To_Index(rpdata->object_instance); switch (rpdata->object_property) { case PROP_OBJECT_IDENTIFIER: - apdu_len = - encode_application_object_id(&apdu[0], OBJECT_ACCESS_POINT, - rpdata->object_instance); + apdu_len = encode_application_object_id( + &apdu[0], OBJECT_ACCESS_POINT, rpdata->object_instance); break; case PROP_OBJECT_NAME: Access_Point_Object_Name(rpdata->object_instance, &char_string); @@ -245,69 +226,58 @@ int Access_Point_Read_Property( apdu_len = encode_application_bitstring(&apdu[0], &bit_string); break; case PROP_EVENT_STATE: - apdu_len = - encode_application_enumerated(&apdu[0], - ap_descr[object_index].event_state); + apdu_len = encode_application_enumerated( + &apdu[0], ap_descr[object_index].event_state); break; case PROP_RELIABILITY: - apdu_len = - encode_application_enumerated(&apdu[0], - ap_descr[object_index].reliability); + apdu_len = encode_application_enumerated( + &apdu[0], ap_descr[object_index].reliability); break; case PROP_OUT_OF_SERVICE: state = Access_Point_Out_Of_Service(rpdata->object_instance); apdu_len = encode_application_boolean(&apdu[0], state); break; case PROP_AUTHENTICATION_STATUS: - apdu_len = - encode_application_enumerated(&apdu[0], - ap_descr[object_index].authentication_status); + apdu_len = encode_application_enumerated( + &apdu[0], ap_descr[object_index].authentication_status); break; case PROP_ACTIVE_AUTHENTICATION_POLICY: - apdu_len = - encode_application_unsigned(&apdu[0], - ap_descr[object_index].active_authentication_policy); + apdu_len = encode_application_unsigned( + &apdu[0], ap_descr[object_index].active_authentication_policy); break; case PROP_NUMBER_OF_AUTHENTICATION_POLICIES: - apdu_len = - encode_application_unsigned(&apdu[0], + apdu_len = encode_application_unsigned( + &apdu[0], ap_descr[object_index].number_of_authentication_policies); break; case PROP_AUTHORIZATION_MODE: - apdu_len = - encode_application_enumerated(&apdu[0], - ap_descr[object_index].authorization_mode); + apdu_len = encode_application_enumerated( + &apdu[0], ap_descr[object_index].authorization_mode); break; case PROP_ACCESS_EVENT: - apdu_len = - encode_application_enumerated(&apdu[0], - ap_descr[object_index].access_event); + apdu_len = encode_application_enumerated( + &apdu[0], ap_descr[object_index].access_event); break; case PROP_ACCESS_EVENT_TAG: - apdu_len = - encode_application_unsigned(&apdu[0], - ap_descr[object_index].access_event_tag); + apdu_len = encode_application_unsigned( + &apdu[0], ap_descr[object_index].access_event_tag); break; case PROP_ACCESS_EVENT_TIME: - apdu_len = - bacapp_encode_timestamp(&apdu[0], - &ap_descr[object_index].access_event_time); + apdu_len = bacapp_encode_timestamp( + &apdu[0], &ap_descr[object_index].access_event_time); break; case PROP_ACCESS_EVENT_CREDENTIAL: - apdu_len = - bacapp_encode_device_obj_ref(&apdu[0], - &ap_descr[object_index].access_event_credential); + apdu_len = bacapp_encode_device_obj_ref( + &apdu[0], &ap_descr[object_index].access_event_credential); break; case PROP_ACCESS_DOORS: if (rpdata->array_index == 0) { - apdu_len = - encode_application_unsigned(&apdu[0], - ap_descr[object_index].num_doors); + apdu_len = encode_application_unsigned( + &apdu[0], ap_descr[object_index].num_doors); } else if (rpdata->array_index == BACNET_ARRAY_ALL) { for (i = 0; i < ap_descr[object_index].num_doors; i++) { - len = - bacapp_encode_device_obj_ref(&apdu[0], - &ap_descr[object_index].access_doors[i]); + len = bacapp_encode_device_obj_ref( + &apdu[0], &ap_descr[object_index].access_doors[i]); if (apdu_len + len < MAX_APDU) apdu_len += len; else { @@ -319,10 +289,9 @@ int Access_Point_Read_Property( } } else { if (rpdata->array_index <= ap_descr[object_index].num_doors) { - apdu_len = - bacapp_encode_device_obj_ref(&apdu[0], - &ap_descr[object_index].access_doors[rpdata-> - array_index - 1]); + apdu_len = bacapp_encode_device_obj_ref( + &apdu[0], &ap_descr[object_index] + .access_doors[rpdata->array_index - 1]); } else { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX; @@ -348,17 +317,15 @@ int Access_Point_Read_Property( } /* returns true if successful */ -bool Access_Point_Write_Property( - BACNET_WRITE_PROPERTY_DATA * wp_data) +bool Access_Point_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data) { - bool status = false; /* return value */ + bool status = false; /* return value */ int len = 0; BACNET_APPLICATION_DATA_VALUE value; /* decode the some of the request */ - len = - bacapp_decode_application_data(wp_data->application_data, - wp_data->application_data_len, &value); + len = bacapp_decode_application_data(wp_data->application_data, + wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ if (len < 0) { /* error while decoding - a value larger than we can handle */ @@ -404,17 +371,14 @@ bool Access_Point_Write_Property( return status; } - #ifdef TEST #include #include #include "ctest.h" -bool WPValidateArgType( - BACNET_APPLICATION_DATA_VALUE * pValue, - uint8_t ucExpectedTag, - BACNET_ERROR_CLASS * pErrorClass, - BACNET_ERROR_CODE * pErrorCode) +bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue, + uint8_t ucExpectedTag, BACNET_ERROR_CLASS *pErrorClass, + BACNET_ERROR_CODE *pErrorCode) { pValue = pValue; ucExpectedTag = ucExpectedTag; @@ -424,10 +388,9 @@ bool WPValidateArgType( return false; } -void testAccessPoint( - Test * pTest) +void testAccessPoint(Test *pTest) { - uint8_t apdu[MAX_APDU] = { 0 }; + uint8_t apdu[MAX_APDU] = {0}; int len = 0; uint32_t len_value = 0; uint8_t tag_number = 0; @@ -454,8 +417,7 @@ void testAccessPoint( } #ifdef TEST_ACCESS_POINT -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -467,7 +429,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/demo/object/access_rights.c b/demo/object/access_rights.c index 6972d6ca..f2e82439 100644 --- a/demo/object/access_rights.c +++ b/demo/object/access_rights.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2015 Nikola Jelic -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2015 Nikola Jelic + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* Access Rights Objects - customize for your use */ @@ -32,7 +32,7 @@ #include "bacdcode.h" #include "bacenum.h" #include "bacapp.h" -#include "config.h" /* the custom stuff */ +#include "config.h" /* the custom stuff */ #include "wp.h" #include "access_rights.h" #include "handlers.h" @@ -42,31 +42,23 @@ static bool Access_Rights_Initialized = false; static ACCESS_RIGHTS_DESCR ar_descr[MAX_ACCESS_RIGHTSS]; /* These three arrays are used by the ReadPropertyMultiple handler */ -static const int Properties_Required[] = { - PROP_OBJECT_IDENTIFIER, - PROP_OBJECT_NAME, - PROP_OBJECT_TYPE, - PROP_GLOBAL_IDENTIFIER, - PROP_STATUS_FLAGS, - PROP_RELIABILITY, - PROP_ENABLE, - PROP_NEGATIVE_ACCESS_RULES, - PROP_POSITIVE_ACCESS_RULES, - -1 -}; +static const int Properties_Required[] = {PROP_OBJECT_IDENTIFIER, + PROP_OBJECT_NAME, + PROP_OBJECT_TYPE, + PROP_GLOBAL_IDENTIFIER, + PROP_STATUS_FLAGS, + PROP_RELIABILITY, + PROP_ENABLE, + PROP_NEGATIVE_ACCESS_RULES, + PROP_POSITIVE_ACCESS_RULES, + -1}; -static const int Properties_Optional[] = { - -1 -}; +static const int Properties_Optional[] = {-1}; -static const int Properties_Proprietary[] = { - -1 -}; +static const int Properties_Proprietary[] = {-1}; -void Access_Rights_Property_Lists( - const int **pRequired, - const int **pOptional, - const int **pProprietary) +void Access_Rights_Property_Lists(const int **pRequired, const int **pOptional, + const int **pProprietary) { if (pRequired) *pRequired = Properties_Required; @@ -78,8 +70,7 @@ void Access_Rights_Property_Lists( return; } -void Access_Rights_Init( - void) +void Access_Rights_Init(void) { unsigned i; @@ -87,7 +78,8 @@ void Access_Rights_Init( Access_Rights_Initialized = true; for (i = 0; i < MAX_ACCESS_RIGHTSS; i++) { - ar_descr[i].global_identifier = 0; /* set to some meaningful value */ + ar_descr[i].global_identifier = + 0; /* set to some meaningful value */ ar_descr[i].reliability = RELIABILITY_NO_FAULT_DETECTED; ar_descr[i].enable = false; ar_descr[i].negative_access_rules_count = 0; @@ -102,8 +94,7 @@ void Access_Rights_Init( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need validate that the */ /* given instance exists */ -bool Access_Rights_Valid_Instance( - uint32_t object_instance) +bool Access_Rights_Valid_Instance(uint32_t object_instance) { if (object_instance < MAX_ACCESS_RIGHTSS) return true; @@ -113,8 +104,7 @@ bool Access_Rights_Valid_Instance( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then count how many you have */ -unsigned Access_Rights_Count( - void) +unsigned Access_Rights_Count(void) { return MAX_ACCESS_RIGHTSS; } @@ -122,8 +112,7 @@ unsigned Access_Rights_Count( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need to return the instance */ /* that correlates to the correct index */ -uint32_t Access_Rights_Index_To_Instance( - unsigned index) +uint32_t Access_Rights_Index_To_Instance(unsigned index) { return index; } @@ -131,8 +120,7 @@ uint32_t Access_Rights_Index_To_Instance( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need to return the index */ /* that correlates to the correct instance number */ -unsigned Access_Rights_Instance_To_Index( - uint32_t object_instance) +unsigned Access_Rights_Instance_To_Index(uint32_t object_instance) { unsigned index = MAX_ACCESS_RIGHTSS; @@ -143,16 +131,15 @@ unsigned Access_Rights_Instance_To_Index( } /* note: the object name must be unique within this device */ -bool Access_Rights_Object_Name( - uint32_t object_instance, - BACNET_CHARACTER_STRING * object_name) +bool Access_Rights_Object_Name(uint32_t object_instance, + BACNET_CHARACTER_STRING *object_name) { - static char text_string[32] = ""; /* okay for single thread */ + static char text_string[32] = ""; /* okay for single thread */ bool status = false; if (object_instance < MAX_ACCESS_RIGHTSS) { sprintf(text_string, "ACCESS RIGHTS %lu", - (unsigned long) object_instance); + (unsigned long)object_instance); status = characterstring_init_ansi(object_name, text_string); } @@ -160,11 +147,10 @@ bool Access_Rights_Object_Name( } /* return apdu len, or BACNET_STATUS_ERROR on error */ -int Access_Rights_Read_Property( - BACNET_READ_PROPERTY_DATA * rpdata) +int Access_Rights_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata) { int len = 0; - int apdu_len = 0; /* return value */ + int apdu_len = 0; /* return value */ BACNET_BIT_STRING bit_string; BACNET_CHARACTER_STRING char_string; unsigned object_index = 0; @@ -179,9 +165,8 @@ int Access_Rights_Read_Property( object_index = Access_Rights_Instance_To_Index(rpdata->object_instance); switch (rpdata->object_property) { case PROP_OBJECT_IDENTIFIER: - apdu_len = - encode_application_object_id(&apdu[0], OBJECT_ACCESS_RIGHTS, - rpdata->object_instance); + apdu_len = encode_application_object_id( + &apdu[0], OBJECT_ACCESS_RIGHTS, rpdata->object_instance); break; case PROP_OBJECT_NAME: Access_Rights_Object_Name(rpdata->object_instance, &char_string); @@ -193,9 +178,8 @@ int Access_Rights_Read_Property( encode_application_enumerated(&apdu[0], OBJECT_ACCESS_RIGHTS); break; case PROP_GLOBAL_IDENTIFIER: - apdu_len = - encode_application_unsigned(&apdu[0], - ar_descr[object_index].global_identifier); + apdu_len = encode_application_unsigned( + &apdu[0], ar_descr[object_index].global_identifier); break; case PROP_STATUS_FLAGS: bitstring_init(&bit_string); @@ -206,26 +190,24 @@ int Access_Rights_Read_Property( apdu_len = encode_application_bitstring(&apdu[0], &bit_string); break; case PROP_RELIABILITY: - apdu_len = - encode_application_enumerated(&apdu[0], - ar_descr[object_index].reliability); + apdu_len = encode_application_enumerated( + &apdu[0], ar_descr[object_index].reliability); break; case PROP_ENABLE: - apdu_len = - encode_application_boolean(&apdu[0], - ar_descr[object_index].enable); + apdu_len = encode_application_boolean( + &apdu[0], ar_descr[object_index].enable); break; case PROP_NEGATIVE_ACCESS_RULES: if (rpdata->array_index == 0) { - apdu_len = - encode_application_unsigned(&apdu[0], + apdu_len = encode_application_unsigned( + &apdu[0], ar_descr[object_index].negative_access_rules_count); } else if (rpdata->array_index == BACNET_ARRAY_ALL) { for (i = 0; - i < ar_descr[object_index].negative_access_rules_count; - i++) { - len = - bacapp_encode_access_rule(&apdu[0], + i < ar_descr[object_index].negative_access_rules_count; + i++) { + len = bacapp_encode_access_rule( + &apdu[0], &ar_descr[object_index].negative_access_rules[i]); if (apdu_len + len < MAX_APDU) apdu_len += len; @@ -239,10 +221,10 @@ int Access_Rights_Read_Property( } else { if (rpdata->array_index <= ar_descr[object_index].negative_access_rules_count) { - apdu_len = - bacapp_encode_access_rule(&apdu[0], - &ar_descr[object_index]. - negative_access_rules[rpdata->array_index - 1]); + apdu_len = bacapp_encode_access_rule( + &apdu[0], + &ar_descr[object_index] + .negative_access_rules[rpdata->array_index - 1]); } else { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX; @@ -252,15 +234,15 @@ int Access_Rights_Read_Property( break; case PROP_POSITIVE_ACCESS_RULES: if (rpdata->array_index == 0) { - apdu_len = - encode_application_unsigned(&apdu[0], + apdu_len = encode_application_unsigned( + &apdu[0], ar_descr[object_index].positive_access_rules_count); } else if (rpdata->array_index == BACNET_ARRAY_ALL) { for (i = 0; - i < ar_descr[object_index].positive_access_rules_count; - i++) { - len = - bacapp_encode_access_rule(&apdu[0], + i < ar_descr[object_index].positive_access_rules_count; + i++) { + len = bacapp_encode_access_rule( + &apdu[0], &ar_descr[object_index].positive_access_rules[i]); if (apdu_len + len < MAX_APDU) apdu_len += len; @@ -274,10 +256,10 @@ int Access_Rights_Read_Property( } else { if (rpdata->array_index <= ar_descr[object_index].positive_access_rules_count) { - apdu_len = - bacapp_encode_access_rule(&apdu[0], - &ar_descr[object_index]. - positive_access_rules[rpdata->array_index - 1]); + apdu_len = bacapp_encode_access_rule( + &apdu[0], + &ar_descr[object_index] + .positive_access_rules[rpdata->array_index - 1]); } else { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX; @@ -293,9 +275,9 @@ int Access_Rights_Read_Property( } /* only array properties can have array options */ if ((apdu_len >= 0) && - (rpdata->object_property != PROP_NEGATIVE_ACCESS_RULES) - && (rpdata->object_property != PROP_POSITIVE_ACCESS_RULES) - && (rpdata->array_index != BACNET_ARRAY_ALL)) { + (rpdata->object_property != PROP_NEGATIVE_ACCESS_RULES) && + (rpdata->object_property != PROP_POSITIVE_ACCESS_RULES) && + (rpdata->array_index != BACNET_ARRAY_ALL)) { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; apdu_len = BACNET_STATUS_ERROR; @@ -305,18 +287,16 @@ int Access_Rights_Read_Property( } /* returns true if successful */ -bool Access_Rights_Write_Property( - BACNET_WRITE_PROPERTY_DATA * wp_data) +bool Access_Rights_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data) { - bool status = false; /* return value */ + bool status = false; /* return value */ int len = 0; BACNET_APPLICATION_DATA_VALUE value; unsigned object_index = 0; /* decode the some of the request */ - len = - bacapp_decode_application_data(wp_data->application_data, - wp_data->application_data_len, &value); + len = bacapp_decode_application_data(wp_data->application_data, + wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ if (len < 0) { /* error while decoding - a value larger than we can handle */ @@ -325,9 +305,9 @@ bool Access_Rights_Write_Property( return false; } /* only array properties can have array options */ - if ((wp_data->object_property != PROP_NEGATIVE_ACCESS_RULES) - && (wp_data->object_property != PROP_POSITIVE_ACCESS_RULES) - && (wp_data->array_index != BACNET_ARRAY_ALL)) { + if ((wp_data->object_property != PROP_NEGATIVE_ACCESS_RULES) && + (wp_data->object_property != PROP_POSITIVE_ACCESS_RULES) && + (wp_data->array_index != BACNET_ARRAY_ALL)) { wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; return false; @@ -337,7 +317,7 @@ bool Access_Rights_Write_Property( case PROP_GLOBAL_IDENTIFIER: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { ar_descr[object_index].global_identifier = value.type.Unsigned_Int; @@ -363,17 +343,14 @@ bool Access_Rights_Write_Property( return status; } - #ifdef TEST #include #include #include "ctest.h" -bool WPValidateArgType( - BACNET_APPLICATION_DATA_VALUE * pValue, - uint8_t ucExpectedTag, - BACNET_ERROR_CLASS * pErrorClass, - BACNET_ERROR_CODE * pErrorCode) +bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue, + uint8_t ucExpectedTag, BACNET_ERROR_CLASS *pErrorClass, + BACNET_ERROR_CODE *pErrorCode) { pValue = pValue; ucExpectedTag = ucExpectedTag; @@ -383,10 +360,9 @@ bool WPValidateArgType( return false; } -void testAccessRights( - Test * pTest) +void testAccessRights(Test *pTest) { - uint8_t apdu[MAX_APDU] = { 0 }; + uint8_t apdu[MAX_APDU] = {0}; int len = 0; uint32_t len_value = 0; uint8_t tag_number = 0; @@ -413,8 +389,7 @@ void testAccessRights( } #ifdef TEST_ACCESS_RIGHTS -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -426,7 +401,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/demo/object/access_user.c b/demo/object/access_user.c index 2d0f1ab7..b0f8012d 100644 --- a/demo/object/access_user.c +++ b/demo/object/access_user.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2015 Nikola Jelic -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2015 Nikola Jelic + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* Access User Objects - customize for your use */ @@ -32,7 +32,7 @@ #include "bacdcode.h" #include "bacenum.h" #include "bacapp.h" -#include "config.h" /* the custom stuff */ +#include "config.h" /* the custom stuff */ #include "wp.h" #include "access_user.h" #include "handlers.h" @@ -43,29 +43,16 @@ static ACCESS_USER_DESCR au_descr[MAX_ACCESS_USERS]; /* These three arrays are used by the ReadPropertyMultiple handler */ static const int Properties_Required[] = { - PROP_OBJECT_IDENTIFIER, - PROP_OBJECT_NAME, - PROP_OBJECT_TYPE, - PROP_GLOBAL_IDENTIFIER, - PROP_STATUS_FLAGS, - PROP_RELIABILITY, - PROP_USER_TYPE, - PROP_CREDENTIALS, - -1 -}; + PROP_OBJECT_IDENTIFIER, PROP_OBJECT_NAME, PROP_OBJECT_TYPE, + PROP_GLOBAL_IDENTIFIER, PROP_STATUS_FLAGS, PROP_RELIABILITY, + PROP_USER_TYPE, PROP_CREDENTIALS, -1}; -static const int Properties_Optional[] = { - -1 -}; +static const int Properties_Optional[] = {-1}; -static const int Properties_Proprietary[] = { - -1 -}; +static const int Properties_Proprietary[] = {-1}; -void Access_User_Property_Lists( - const int **pRequired, - const int **pOptional, - const int **pProprietary) +void Access_User_Property_Lists(const int **pRequired, const int **pOptional, + const int **pProprietary) { if (pRequired) *pRequired = Properties_Required; @@ -77,8 +64,7 @@ void Access_User_Property_Lists( return; } -void Access_User_Init( - void) +void Access_User_Init(void) { unsigned i; @@ -86,7 +72,8 @@ void Access_User_Init( Access_User_Initialized = true; for (i = 0; i < MAX_ACCESS_USERS; i++) { - au_descr[i].global_identifier = 0; /* set to some meaningful value */ + au_descr[i].global_identifier = + 0; /* set to some meaningful value */ au_descr[i].reliability = RELIABILITY_NO_FAULT_DETECTED; au_descr[i].user_type = ACCESS_USER_TYPE_PERSON; au_descr[i].credentials_count = 0; @@ -100,8 +87,7 @@ void Access_User_Init( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need validate that the */ /* given instance exists */ -bool Access_User_Valid_Instance( - uint32_t object_instance) +bool Access_User_Valid_Instance(uint32_t object_instance) { if (object_instance < MAX_ACCESS_USERS) return true; @@ -111,8 +97,7 @@ bool Access_User_Valid_Instance( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then count how many you have */ -unsigned Access_User_Count( - void) +unsigned Access_User_Count(void) { return MAX_ACCESS_USERS; } @@ -120,8 +105,7 @@ unsigned Access_User_Count( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need to return the instance */ /* that correlates to the correct index */ -uint32_t Access_User_Index_To_Instance( - unsigned index) +uint32_t Access_User_Index_To_Instance(unsigned index) { return index; } @@ -129,8 +113,7 @@ uint32_t Access_User_Index_To_Instance( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need to return the index */ /* that correlates to the correct instance number */ -unsigned Access_User_Instance_To_Index( - uint32_t object_instance) +unsigned Access_User_Instance_To_Index(uint32_t object_instance) { unsigned index = MAX_ACCESS_USERS; @@ -141,16 +124,14 @@ unsigned Access_User_Instance_To_Index( } /* note: the object name must be unique within this device */ -bool Access_User_Object_Name( - uint32_t object_instance, - BACNET_CHARACTER_STRING * object_name) +bool Access_User_Object_Name(uint32_t object_instance, + BACNET_CHARACTER_STRING *object_name) { - static char text_string[32] = ""; /* okay for single thread */ + static char text_string[32] = ""; /* okay for single thread */ bool status = false; if (object_instance < MAX_ACCESS_USERS) { - sprintf(text_string, "ACCESS USER %lu", - (unsigned long) object_instance); + sprintf(text_string, "ACCESS USER %lu", (unsigned long)object_instance); status = characterstring_init_ansi(object_name, text_string); } @@ -158,11 +139,10 @@ bool Access_User_Object_Name( } /* return apdu len, or BACNET_STATUS_ERROR on error */ -int Access_User_Read_Property( - BACNET_READ_PROPERTY_DATA * rpdata) +int Access_User_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata) { int len = 0; - int apdu_len = 0; /* return value */ + int apdu_len = 0; /* return value */ BACNET_BIT_STRING bit_string; BACNET_CHARACTER_STRING char_string; unsigned object_index = 0; @@ -177,9 +157,8 @@ int Access_User_Read_Property( object_index = Access_User_Instance_To_Index(rpdata->object_instance); switch (rpdata->object_property) { case PROP_OBJECT_IDENTIFIER: - apdu_len = - encode_application_object_id(&apdu[0], OBJECT_ACCESS_USER, - rpdata->object_instance); + apdu_len = encode_application_object_id( + &apdu[0], OBJECT_ACCESS_USER, rpdata->object_instance); break; case PROP_OBJECT_NAME: Access_User_Object_Name(rpdata->object_instance, &char_string); @@ -191,9 +170,8 @@ int Access_User_Read_Property( encode_application_enumerated(&apdu[0], OBJECT_ACCESS_USER); break; case PROP_GLOBAL_IDENTIFIER: - apdu_len = - encode_application_unsigned(&apdu[0], - au_descr[object_index].global_identifier); + apdu_len = encode_application_unsigned( + &apdu[0], au_descr[object_index].global_identifier); break; case PROP_STATUS_FLAGS: bitstring_init(&bit_string); @@ -204,20 +182,17 @@ int Access_User_Read_Property( apdu_len = encode_application_bitstring(&apdu[0], &bit_string); break; case PROP_RELIABILITY: - apdu_len = - encode_application_enumerated(&apdu[0], - au_descr[object_index].reliability); + apdu_len = encode_application_enumerated( + &apdu[0], au_descr[object_index].reliability); break; case PROP_USER_TYPE: - apdu_len = - encode_application_enumerated(&apdu[0], - au_descr[object_index].user_type); + apdu_len = encode_application_enumerated( + &apdu[0], au_descr[object_index].user_type); break; case PROP_CREDENTIALS: for (i = 0; i < au_descr[object_index].credentials_count; i++) { - len = - bacapp_encode_device_obj_ref(&apdu[0], - &au_descr[object_index].credentials[i]); + len = bacapp_encode_device_obj_ref( + &apdu[0], &au_descr[object_index].credentials[i]); if (apdu_len + len < MAX_APDU) apdu_len += len; else { @@ -245,18 +220,16 @@ int Access_User_Read_Property( } /* returns true if successful */ -bool Access_User_Write_Property( - BACNET_WRITE_PROPERTY_DATA * wp_data) +bool Access_User_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data) { - bool status = false; /* return value */ + bool status = false; /* return value */ int len = 0; BACNET_APPLICATION_DATA_VALUE value; unsigned object_index = 0; /* decode the some of the request */ - len = - bacapp_decode_application_data(wp_data->application_data, - wp_data->application_data_len, &value); + len = bacapp_decode_application_data(wp_data->application_data, + wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ if (len < 0) { /* error while decoding - a value larger than we can handle */ @@ -275,7 +248,7 @@ bool Access_User_Write_Property( case PROP_GLOBAL_IDENTIFIER: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { au_descr[object_index].global_identifier = value.type.Unsigned_Int; @@ -301,17 +274,14 @@ bool Access_User_Write_Property( return status; } - #ifdef TEST #include #include #include "ctest.h" -bool WPValidateArgType( - BACNET_APPLICATION_DATA_VALUE * pValue, - uint8_t ucExpectedTag, - BACNET_ERROR_CLASS * pErrorClass, - BACNET_ERROR_CODE * pErrorCode) +bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue, + uint8_t ucExpectedTag, BACNET_ERROR_CLASS *pErrorClass, + BACNET_ERROR_CODE *pErrorCode) { pValue = pValue; ucExpectedTag = ucExpectedTag; @@ -321,10 +291,9 @@ bool WPValidateArgType( return false; } -void testAccessUser( - Test * pTest) +void testAccessUser(Test *pTest) { - uint8_t apdu[MAX_APDU] = { 0 }; + uint8_t apdu[MAX_APDU] = {0}; int len = 0; uint32_t len_value = 0; uint8_t tag_number = 0; @@ -351,8 +320,7 @@ void testAccessUser( } #ifdef TEST_ACCESS_USER -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -364,7 +332,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/demo/object/access_zone.c b/demo/object/access_zone.c index 4add09e7..6a4ab832 100644 --- a/demo/object/access_zone.c +++ b/demo/object/access_zone.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2015 Nikola Jelic -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2015 Nikola Jelic + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* Access Zone Objects - customize for your use */ @@ -32,7 +32,7 @@ #include "bacdcode.h" #include "bacenum.h" #include "bacapp.h" -#include "config.h" /* the custom stuff */ +#include "config.h" /* the custom stuff */ #include "wp.h" #include "access_zone.h" #include "handlers.h" @@ -43,32 +43,17 @@ static ACCESS_ZONE_DESCR az_descr[MAX_ACCESS_ZONES]; /* These three arrays are used by the ReadPropertyMultiple handler */ static const int Properties_Required[] = { - PROP_OBJECT_IDENTIFIER, - PROP_OBJECT_NAME, - PROP_OBJECT_TYPE, - PROP_GLOBAL_IDENTIFIER, - PROP_OCCUPANCY_STATE, - PROP_STATUS_FLAGS, - PROP_EVENT_STATE, - PROP_RELIABILITY, - PROP_OUT_OF_SERVICE, - PROP_ENTRY_POINTS, - PROP_EXIT_POINTS, - -1 -}; + PROP_OBJECT_IDENTIFIER, PROP_OBJECT_NAME, PROP_OBJECT_TYPE, + PROP_GLOBAL_IDENTIFIER, PROP_OCCUPANCY_STATE, PROP_STATUS_FLAGS, + PROP_EVENT_STATE, PROP_RELIABILITY, PROP_OUT_OF_SERVICE, + PROP_ENTRY_POINTS, PROP_EXIT_POINTS, -1}; -static const int Properties_Optional[] = { - -1 -}; +static const int Properties_Optional[] = {-1}; -static const int Properties_Proprietary[] = { - -1 -}; +static const int Properties_Proprietary[] = {-1}; -void Access_Zone_Property_Lists( - const int **pRequired, - const int **pOptional, - const int **pProprietary) +void Access_Zone_Property_Lists(const int **pRequired, const int **pOptional, + const int **pProprietary) { if (pRequired) *pRequired = Properties_Required; @@ -80,8 +65,7 @@ void Access_Zone_Property_Lists( return; } -void Access_Zone_Init( - void) +void Access_Zone_Init(void) { unsigned i; @@ -89,7 +73,8 @@ void Access_Zone_Init( Access_Zone_Initialized = true; for (i = 0; i < MAX_ACCESS_ZONES; i++) { - az_descr[i].global_identifier = 0; /* set to some meaningful value */ + az_descr[i].global_identifier = + 0; /* set to some meaningful value */ az_descr[i].occupancy_state = ACCESS_ZONE_OCCUPANCY_STATE_DISABLED; az_descr[i].event_state = EVENT_STATE_NORMAL; az_descr[i].reliability = RELIABILITY_NO_FAULT_DETECTED; @@ -106,8 +91,7 @@ void Access_Zone_Init( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need validate that the */ /* given instance exists */ -bool Access_Zone_Valid_Instance( - uint32_t object_instance) +bool Access_Zone_Valid_Instance(uint32_t object_instance) { if (object_instance < MAX_ACCESS_ZONES) return true; @@ -117,8 +101,7 @@ bool Access_Zone_Valid_Instance( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then count how many you have */ -unsigned Access_Zone_Count( - void) +unsigned Access_Zone_Count(void) { return MAX_ACCESS_ZONES; } @@ -126,8 +109,7 @@ unsigned Access_Zone_Count( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need to return the instance */ /* that correlates to the correct index */ -uint32_t Access_Zone_Index_To_Instance( - unsigned index) +uint32_t Access_Zone_Index_To_Instance(unsigned index) { return index; } @@ -135,8 +117,7 @@ uint32_t Access_Zone_Index_To_Instance( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need to return the index */ /* that correlates to the correct instance number */ -unsigned Access_Zone_Instance_To_Index( - uint32_t object_instance) +unsigned Access_Zone_Instance_To_Index(uint32_t object_instance) { unsigned index = MAX_ACCESS_ZONES; @@ -147,24 +128,21 @@ unsigned Access_Zone_Instance_To_Index( } /* note: the object name must be unique within this device */ -bool Access_Zone_Object_Name( - uint32_t object_instance, - BACNET_CHARACTER_STRING * object_name) +bool Access_Zone_Object_Name(uint32_t object_instance, + BACNET_CHARACTER_STRING *object_name) { - static char text_string[32] = ""; /* okay for single thread */ + static char text_string[32] = ""; /* okay for single thread */ bool status = false; if (object_instance < MAX_ACCESS_ZONES) { - sprintf(text_string, "ACCESS ZONE %lu", - (unsigned long) object_instance); + sprintf(text_string, "ACCESS ZONE %lu", (unsigned long)object_instance); status = characterstring_init_ansi(object_name, text_string); } return status; } -bool Access_Zone_Out_Of_Service( - uint32_t instance) +bool Access_Zone_Out_Of_Service(uint32_t instance) { unsigned index = 0; bool oos_flag = false; @@ -177,9 +155,7 @@ bool Access_Zone_Out_Of_Service( return oos_flag; } -void Access_Zone_Out_Of_Service_Set( - uint32_t instance, - bool oos_flag) +void Access_Zone_Out_Of_Service_Set(uint32_t instance, bool oos_flag) { unsigned index = 0; @@ -190,11 +166,10 @@ void Access_Zone_Out_Of_Service_Set( } /* return apdu len, or BACNET_STATUS_ERROR on error */ -int Access_Zone_Read_Property( - BACNET_READ_PROPERTY_DATA * rpdata) +int Access_Zone_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata) { int len = 0; - int apdu_len = 0; /* return value */ + int apdu_len = 0; /* return value */ BACNET_BIT_STRING bit_string; BACNET_CHARACTER_STRING char_string; unsigned object_index = 0; @@ -210,9 +185,8 @@ int Access_Zone_Read_Property( object_index = Access_Zone_Instance_To_Index(rpdata->object_instance); switch (rpdata->object_property) { case PROP_OBJECT_IDENTIFIER: - apdu_len = - encode_application_object_id(&apdu[0], OBJECT_ACCESS_ZONE, - rpdata->object_instance); + apdu_len = encode_application_object_id( + &apdu[0], OBJECT_ACCESS_ZONE, rpdata->object_instance); break; case PROP_OBJECT_NAME: Access_Zone_Object_Name(rpdata->object_instance, &char_string); @@ -224,14 +198,12 @@ int Access_Zone_Read_Property( encode_application_enumerated(&apdu[0], OBJECT_ACCESS_ZONE); break; case PROP_GLOBAL_IDENTIFIER: - apdu_len = - encode_application_unsigned(&apdu[0], - az_descr[object_index].global_identifier); + apdu_len = encode_application_unsigned( + &apdu[0], az_descr[object_index].global_identifier); break; case PROP_OCCUPANCY_STATE: - apdu_len = - encode_application_enumerated(&apdu[0], - az_descr[object_index].occupancy_state); + apdu_len = encode_application_enumerated( + &apdu[0], az_descr[object_index].occupancy_state); break; case PROP_STATUS_FLAGS: bitstring_init(&bit_string); @@ -243,14 +215,12 @@ int Access_Zone_Read_Property( apdu_len = encode_application_bitstring(&apdu[0], &bit_string); break; case PROP_EVENT_STATE: - apdu_len = - encode_application_enumerated(&apdu[0], - az_descr[object_index].event_state); + apdu_len = encode_application_enumerated( + &apdu[0], az_descr[object_index].event_state); break; case PROP_RELIABILITY: - apdu_len = - encode_application_enumerated(&apdu[0], - az_descr[object_index].reliability); + apdu_len = encode_application_enumerated( + &apdu[0], az_descr[object_index].reliability); break; case PROP_OUT_OF_SERVICE: state = Access_Zone_Out_Of_Service(rpdata->object_instance); @@ -258,9 +228,8 @@ int Access_Zone_Read_Property( break; case PROP_ENTRY_POINTS: for (i = 0; i < az_descr[object_index].entry_points_count; i++) { - len = - bacapp_encode_device_obj_ref(&apdu[0], - &az_descr[object_index].entry_points[i]); + len = bacapp_encode_device_obj_ref( + &apdu[0], &az_descr[object_index].entry_points[i]); if (apdu_len + len < MAX_APDU) apdu_len += len; else { @@ -273,9 +242,8 @@ int Access_Zone_Read_Property( break; case PROP_EXIT_POINTS: for (i = 0; i < az_descr[object_index].exit_points_count; i++) { - len = - bacapp_encode_device_obj_ref(&apdu[0], - &az_descr[object_index].exit_points[i]); + len = bacapp_encode_device_obj_ref( + &apdu[0], &az_descr[object_index].exit_points[i]); if (apdu_len + len < MAX_APDU) apdu_len += len; else { @@ -303,18 +271,16 @@ int Access_Zone_Read_Property( } /* returns true if successful */ -bool Access_Zone_Write_Property( - BACNET_WRITE_PROPERTY_DATA * wp_data) +bool Access_Zone_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data) { - bool status = false; /* return value */ + bool status = false; /* return value */ int len = 0; BACNET_APPLICATION_DATA_VALUE value; unsigned object_index = 0; /* decode the some of the request */ - len = - bacapp_decode_application_data(wp_data->application_data, - wp_data->application_data_len, &value); + len = bacapp_decode_application_data(wp_data->application_data, + wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ if (len < 0) { /* error while decoding - a value larger than we can handle */ @@ -333,7 +299,7 @@ bool Access_Zone_Write_Property( case PROP_GLOBAL_IDENTIFIER: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { az_descr[object_index].global_identifier = value.type.Unsigned_Int; @@ -341,10 +307,9 @@ bool Access_Zone_Write_Property( break; case PROP_RELIABILITY: if (Access_Zone_Out_Of_Service(wp_data->object_instance)) { - 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) { az_descr[object_index].reliability = value.type.Enumerated; } @@ -374,17 +339,14 @@ bool Access_Zone_Write_Property( return status; } - #ifdef TEST #include #include #include "ctest.h" -bool WPValidateArgType( - BACNET_APPLICATION_DATA_VALUE * pValue, - uint8_t ucExpectedTag, - BACNET_ERROR_CLASS * pErrorClass, - BACNET_ERROR_CODE * pErrorCode) +bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue, + uint8_t ucExpectedTag, BACNET_ERROR_CLASS *pErrorClass, + BACNET_ERROR_CODE *pErrorCode) { pValue = pValue; ucExpectedTag = ucExpectedTag; @@ -394,10 +356,9 @@ bool WPValidateArgType( return false; } -void testAccessZone( - Test * pTest) +void testAccessZone(Test *pTest) { - uint8_t apdu[MAX_APDU] = { 0 }; + uint8_t apdu[MAX_APDU] = {0}; int len = 0; uint32_t len_value = 0; uint8_t tag_number = 0; @@ -424,8 +385,7 @@ void testAccessZone( } #ifdef TEST_ACCESS_ZONE -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -437,7 +397,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/demo/object/ai.c b/demo/object/ai.c index 96f2b1f4..15059743 100644 --- a/demo/object/ai.c +++ b/demo/object/ai.c @@ -1,28 +1,28 @@ /************************************************************************** -* -* Copyright (C) 2005 Steve Karg -* Copyright (C) 2011 Krzysztof Malorny -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2005 Steve Karg + * Copyright (C) 2011 Krzysztof Malorny + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* Analog Input Objects customize for your use */ @@ -34,64 +34,46 @@ #include "bacdcode.h" #include "bacenum.h" #include "bactext.h" -#include "config.h" /* the custom stuff */ +#include "config.h" /* the custom stuff */ #include "device.h" #include "handlers.h" #include "proplist.h" #include "timestamp.h" #include "ai.h" - #ifndef MAX_ANALOG_INPUTS #define MAX_ANALOG_INPUTS 4 #endif - ANALOG_INPUT_DESCR AI_Descr[MAX_ANALOG_INPUTS]; /* These three arrays are used by the ReadPropertyMultiple handler */ static const int Properties_Required[] = { - PROP_OBJECT_IDENTIFIER, - PROP_OBJECT_NAME, - PROP_OBJECT_TYPE, - PROP_PRESENT_VALUE, - PROP_STATUS_FLAGS, - PROP_EVENT_STATE, - PROP_OUT_OF_SERVICE, - PROP_UNITS, - -1 -}; + PROP_OBJECT_IDENTIFIER, PROP_OBJECT_NAME, PROP_OBJECT_TYPE, + PROP_PRESENT_VALUE, PROP_STATUS_FLAGS, PROP_EVENT_STATE, + PROP_OUT_OF_SERVICE, PROP_UNITS, -1}; -static const int Properties_Optional[] = { - PROP_DESCRIPTION, - PROP_RELIABILITY, - PROP_COV_INCREMENT, +static const int Properties_Optional[] = {PROP_DESCRIPTION, + PROP_RELIABILITY, + PROP_COV_INCREMENT, #if defined(INTRINSIC_REPORTING) - PROP_TIME_DELAY, - PROP_NOTIFICATION_CLASS, - PROP_HIGH_LIMIT, - PROP_LOW_LIMIT, - PROP_DEADBAND, - PROP_LIMIT_ENABLE, - PROP_EVENT_ENABLE, - PROP_ACKED_TRANSITIONS, - PROP_NOTIFY_TYPE, - PROP_EVENT_TIME_STAMPS, + PROP_TIME_DELAY, + PROP_NOTIFICATION_CLASS, + PROP_HIGH_LIMIT, + PROP_LOW_LIMIT, + PROP_DEADBAND, + PROP_LIMIT_ENABLE, + PROP_EVENT_ENABLE, + PROP_ACKED_TRANSITIONS, + PROP_NOTIFY_TYPE, + PROP_EVENT_TIME_STAMPS, #endif - -1 -}; + -1}; -static const int Properties_Proprietary[] = { - 9997, - 9998, - 9999, - -1 -}; +static const int Properties_Proprietary[] = {9997, 9998, 9999, -1}; -void Analog_Input_Property_Lists( - const int **pRequired, - const int **pOptional, - const int **pProprietary) +void Analog_Input_Property_Lists(const int **pRequired, const int **pOptional, + const int **pProprietary) { if (pRequired) *pRequired = Properties_Required; @@ -103,9 +85,7 @@ void Analog_Input_Property_Lists( return; } - -void Analog_Input_Init( - void) +void Analog_Input_Init(void) { unsigned i; #if defined(INTRINSIC_REPORTING) @@ -133,12 +113,12 @@ void Analog_Input_Init( /* Set handler for GetEventInformation function */ handler_get_event_information_set(OBJECT_ANALOG_INPUT, - Analog_Input_Event_Information); + Analog_Input_Event_Information); /* Set handler for AcknowledgeAlarm function */ handler_alarm_ack_set(OBJECT_ANALOG_INPUT, Analog_Input_Alarm_Ack); /* Set handler for GetAlarmSummary Service */ handler_get_alarm_summary_set(OBJECT_ANALOG_INPUT, - Analog_Input_Alarm_Summary); + Analog_Input_Alarm_Summary); #endif } } @@ -146,8 +126,7 @@ void Analog_Input_Init( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need validate that the */ /* given instance exists */ -bool Analog_Input_Valid_Instance( - uint32_t object_instance) +bool Analog_Input_Valid_Instance(uint32_t object_instance) { unsigned int index; @@ -160,8 +139,7 @@ bool Analog_Input_Valid_Instance( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then count how many you have */ -unsigned Analog_Input_Count( - void) +unsigned Analog_Input_Count(void) { return MAX_ANALOG_INPUTS; } @@ -169,8 +147,7 @@ unsigned Analog_Input_Count( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need to return the instance */ /* that correlates to the correct index */ -uint32_t Analog_Input_Index_To_Instance( - unsigned index) +uint32_t Analog_Input_Index_To_Instance(unsigned index) { return index; } @@ -178,8 +155,7 @@ uint32_t Analog_Input_Index_To_Instance( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need to return the index */ /* that correlates to the correct instance number */ -unsigned Analog_Input_Instance_To_Index( - uint32_t object_instance) +unsigned Analog_Input_Instance_To_Index(uint32_t object_instance) { unsigned index = MAX_ANALOG_INPUTS; @@ -189,8 +165,7 @@ unsigned Analog_Input_Instance_To_Index( return index; } -float Analog_Input_Present_Value( - uint32_t object_instance) +float Analog_Input_Present_Value(uint32_t object_instance) { float value = 0.0; unsigned int index; @@ -203,8 +178,7 @@ float Analog_Input_Present_Value( return value; } -static void Analog_Input_COV_Detect(unsigned int index, - float value) +static void Analog_Input_COV_Detect(unsigned int index, float value) { float prior_value = 0.0; float cov_increment = 0.0; @@ -225,9 +199,7 @@ static void Analog_Input_COV_Detect(unsigned int index, } } -void Analog_Input_Present_Value_Set( - uint32_t object_instance, - float value) +void Analog_Input_Present_Value_Set(uint32_t object_instance, float value) { unsigned int index = 0; @@ -238,25 +210,23 @@ void Analog_Input_Present_Value_Set( } } -bool Analog_Input_Object_Name( - uint32_t object_instance, - BACNET_CHARACTER_STRING * object_name) +bool Analog_Input_Object_Name(uint32_t object_instance, + BACNET_CHARACTER_STRING *object_name) { - static char text_string[32] = ""; /* okay for single thread */ + static char text_string[32] = ""; /* okay for single thread */ unsigned int index; bool status = false; 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); status = characterstring_init_ansi(object_name, text_string); } return status; } -bool Analog_Input_Change_Of_Value( - uint32_t object_instance) +bool Analog_Input_Change_Of_Value(uint32_t object_instance) { unsigned index = 0; bool changed = false; @@ -269,8 +239,7 @@ bool Analog_Input_Change_Of_Value( return changed; } -void Analog_Input_Change_Of_Value_Clear( - uint32_t object_instance) +void Analog_Input_Change_Of_Value_Clear(uint32_t object_instance) { unsigned index = 0; @@ -288,9 +257,8 @@ void Analog_Input_Change_Of_Value_Clear( * * @return true if the value list is encoded */ -bool Analog_Input_Encode_Value_List( - uint32_t object_instance, - BACNET_PROPERTY_VALUE * value_list) +bool Analog_Input_Encode_Value_List(uint32_t object_instance, + BACNET_PROPERTY_VALUE *value_list) { bool status = false; @@ -312,17 +280,17 @@ bool Analog_Input_Encode_Value_List( value_list->value.tag = BACNET_APPLICATION_TAG_BIT_STRING; bitstring_init(&value_list->value.type.Bit_String); bitstring_set_bit(&value_list->value.type.Bit_String, - STATUS_FLAG_IN_ALARM, false); + STATUS_FLAG_IN_ALARM, false); + bitstring_set_bit(&value_list->value.type.Bit_String, STATUS_FLAG_FAULT, + false); bitstring_set_bit(&value_list->value.type.Bit_String, - STATUS_FLAG_FAULT, false); - bitstring_set_bit(&value_list->value.type.Bit_String, - STATUS_FLAG_OVERRIDDEN, false); + STATUS_FLAG_OVERRIDDEN, false); if (Analog_Input_Out_Of_Service(object_instance)) { bitstring_set_bit(&value_list->value.type.Bit_String, - STATUS_FLAG_OUT_OF_SERVICE, true); + STATUS_FLAG_OUT_OF_SERVICE, true); } else { bitstring_set_bit(&value_list->value.type.Bit_String, - STATUS_FLAG_OUT_OF_SERVICE, false); + STATUS_FLAG_OUT_OF_SERVICE, false); } value_list->value.next = NULL; value_list->priority = BACNET_NO_PRIORITY; @@ -333,8 +301,7 @@ bool Analog_Input_Encode_Value_List( return status; } -float Analog_Input_COV_Increment( - uint32_t object_instance) +float Analog_Input_COV_Increment(uint32_t object_instance) { unsigned index = 0; float value = 0; @@ -347,9 +314,7 @@ float Analog_Input_COV_Increment( return value; } -void Analog_Input_COV_Increment_Set( - uint32_t object_instance, - float value) +void Analog_Input_COV_Increment_Set(uint32_t object_instance, float value) { unsigned index = 0; @@ -360,8 +325,7 @@ void Analog_Input_COV_Increment_Set( } } -bool Analog_Input_Out_Of_Service( - uint32_t object_instance) +bool Analog_Input_Out_Of_Service(uint32_t object_instance) { unsigned index = 0; bool value = false; @@ -374,22 +338,20 @@ bool Analog_Input_Out_Of_Service( return value; } -void Analog_Input_Out_Of_Service_Set( - uint32_t object_instance, - bool value) +void Analog_Input_Out_Of_Service_Set(uint32_t object_instance, bool value) { unsigned index = 0; index = Analog_Input_Instance_To_Index(object_instance); if (index < MAX_ANALOG_INPUTS) { - /* BACnet Testing Observed Incident oi00104 - The Changed flag was not being set when a client wrote to the Out-of-Service bit. - Revealed by BACnet Test Client v1.8.16 ( www.bac-test.com/bacnet-test-client-download ) - BC 135.1: 8.2.1-A - BC 135.1: 8.2.2-A - Any discussions can be directed to edward@bac-test.com - Please feel free to remove this comment when my changes accepted after suitable time for - review by all interested parties. Say 6 months -> September 2016 */ + /* BACnet Testing Observed Incident oi00104 + The Changed flag was not being set when a client wrote to the + Out-of-Service bit. Revealed by BACnet Test Client v1.8.16 ( + www.bac-test.com/bacnet-test-client-download ) BC 135.1: 8.2.1-A BC + 135.1: 8.2.2-A Any discussions can be directed to edward@bac-test.com + Please feel free to remove this comment when my changes accepted after + suitable time for review by all interested parties. Say 6 months -> + September 2016 */ if (AI_Descr[index].Out_Of_Service != value) { AI_Descr[index].Changed = true; } @@ -399,10 +361,9 @@ void Analog_Input_Out_Of_Service_Set( /* return apdu length, or BACNET_STATUS_ERROR on error */ /* assumption - object already exists */ -int Analog_Input_Read_Property( - BACNET_READ_PROPERTY_DATA * rpdata) +int Analog_Input_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata) { - int apdu_len = 0; /* return value */ + int apdu_len = 0; /* return value */ BACNET_BIT_STRING bit_string; BACNET_CHARACTER_STRING char_string; ANALOG_INPUT_DESCR *CurrentAI; @@ -425,11 +386,10 @@ int Analog_Input_Read_Property( return BACNET_STATUS_ERROR; apdu = rpdata->application_data; - switch ((int) rpdata->object_property) { + switch ((int)rpdata->object_property) { case PROP_OBJECT_IDENTIFIER: - apdu_len = - encode_application_object_id(&apdu[0], OBJECT_ANALOG_INPUT, - rpdata->object_instance); + apdu_len = encode_application_object_id( + &apdu[0], OBJECT_ANALOG_INPUT, rpdata->object_instance); break; case PROP_OBJECT_NAME: @@ -445,23 +405,22 @@ int Analog_Input_Read_Property( break; case PROP_PRESENT_VALUE: - apdu_len = - encode_application_real(&apdu[0], - Analog_Input_Present_Value(rpdata->object_instance)); + apdu_len = encode_application_real( + &apdu[0], Analog_Input_Present_Value(rpdata->object_instance)); break; case PROP_STATUS_FLAGS: bitstring_init(&bit_string); #if defined(INTRINSIC_REPORTING) bitstring_set_bit(&bit_string, STATUS_FLAG_IN_ALARM, - CurrentAI->Event_State ? true : false); + CurrentAI->Event_State ? true : false); #else bitstring_set_bit(&bit_string, STATUS_FLAG_IN_ALARM, false); #endif bitstring_set_bit(&bit_string, STATUS_FLAG_FAULT, false); bitstring_set_bit(&bit_string, STATUS_FLAG_OVERRIDDEN, false); bitstring_set_bit(&bit_string, STATUS_FLAG_OUT_OF_SERVICE, - CurrentAI->Out_Of_Service); + CurrentAI->Out_Of_Service); apdu_len = encode_application_bitstring(&apdu[0], &bit_string); break; @@ -469,8 +428,7 @@ int Analog_Input_Read_Property( case PROP_EVENT_STATE: #if defined(INTRINSIC_REPORTING) apdu_len = - encode_application_enumerated(&apdu[0], - CurrentAI->Event_State); + encode_application_enumerated(&apdu[0], CurrentAI->Event_State); #else apdu_len = encode_application_enumerated(&apdu[0], EVENT_STATE_NORMAL); @@ -479,14 +437,12 @@ int Analog_Input_Read_Property( case PROP_RELIABILITY: apdu_len = - encode_application_enumerated(&apdu[0], - CurrentAI->Reliability); + encode_application_enumerated(&apdu[0], CurrentAI->Reliability); break; case PROP_OUT_OF_SERVICE: apdu_len = - encode_application_boolean(&apdu[0], - CurrentAI->Out_Of_Service); + encode_application_boolean(&apdu[0], CurrentAI->Out_Of_Service); break; case PROP_UNITS: @@ -495,8 +451,8 @@ int Analog_Input_Read_Property( break; case PROP_COV_INCREMENT: - apdu_len = encode_application_real(&apdu[0], - CurrentAI->COV_Increment); + apdu_len = + encode_application_real(&apdu[0], CurrentAI->COV_Increment); break; #if defined(INTRINSIC_REPORTING) @@ -506,14 +462,12 @@ int Analog_Input_Read_Property( break; case PROP_NOTIFICATION_CLASS: - apdu_len = - encode_application_unsigned(&apdu[0], - CurrentAI->Notification_Class); + apdu_len = encode_application_unsigned( + &apdu[0], CurrentAI->Notification_Class); break; case PROP_HIGH_LIMIT: - apdu_len = - encode_application_real(&apdu[0], CurrentAI->High_Limit); + apdu_len = encode_application_real(&apdu[0], CurrentAI->High_Limit); break; case PROP_LOW_LIMIT: @@ -527,71 +481,74 @@ int Analog_Input_Read_Property( case PROP_LIMIT_ENABLE: bitstring_init(&bit_string); bitstring_set_bit(&bit_string, 0, - (CurrentAI-> - Limit_Enable & EVENT_LOW_LIMIT_ENABLE) ? true : false); - bitstring_set_bit(&bit_string, 1, - (CurrentAI-> - Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) ? true : false); + (CurrentAI->Limit_Enable & EVENT_LOW_LIMIT_ENABLE) + ? true + : false); + bitstring_set_bit( + &bit_string, 1, + (CurrentAI->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) ? true + : false); apdu_len = encode_application_bitstring(&apdu[0], &bit_string); break; case PROP_EVENT_ENABLE: bitstring_init(&bit_string); - bitstring_set_bit(&bit_string, TRANSITION_TO_OFFNORMAL, - (CurrentAI-> - Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ? true : false); + bitstring_set_bit( + &bit_string, TRANSITION_TO_OFFNORMAL, + (CurrentAI->Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ? true + : false); bitstring_set_bit(&bit_string, TRANSITION_TO_FAULT, - (CurrentAI-> - Event_Enable & EVENT_ENABLE_TO_FAULT) ? true : false); + (CurrentAI->Event_Enable & EVENT_ENABLE_TO_FAULT) + ? true + : false); bitstring_set_bit(&bit_string, TRANSITION_TO_NORMAL, - (CurrentAI-> - Event_Enable & EVENT_ENABLE_TO_NORMAL) ? true : false); + (CurrentAI->Event_Enable & EVENT_ENABLE_TO_NORMAL) + ? true + : false); apdu_len = encode_application_bitstring(&apdu[0], &bit_string); break; case PROP_ACKED_TRANSITIONS: bitstring_init(&bit_string); - bitstring_set_bit(&bit_string, TRANSITION_TO_OFFNORMAL, - CurrentAI->Acked_Transitions[TRANSITION_TO_OFFNORMAL]. - bIsAcked); - bitstring_set_bit(&bit_string, TRANSITION_TO_FAULT, + bitstring_set_bit( + &bit_string, TRANSITION_TO_OFFNORMAL, + CurrentAI->Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked); + bitstring_set_bit( + &bit_string, TRANSITION_TO_FAULT, CurrentAI->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked); - bitstring_set_bit(&bit_string, TRANSITION_TO_NORMAL, + bitstring_set_bit( + &bit_string, TRANSITION_TO_NORMAL, CurrentAI->Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked); apdu_len = encode_application_bitstring(&apdu[0], &bit_string); break; case PROP_NOTIFY_TYPE: - apdu_len = - encode_application_enumerated(&apdu[0], - CurrentAI->Notify_Type ? NOTIFY_EVENT : NOTIFY_ALARM); + apdu_len = encode_application_enumerated( + &apdu[0], CurrentAI->Notify_Type ? NOTIFY_EVENT : NOTIFY_ALARM); break; case PROP_EVENT_TIME_STAMPS: /* Array element zero is the number of elements in the array */ if (rpdata->array_index == 0) - apdu_len = - encode_application_unsigned(&apdu[0], - MAX_BACNET_EVENT_TRANSITION); + apdu_len = encode_application_unsigned( + &apdu[0], MAX_BACNET_EVENT_TRANSITION); /* if no index was specified, then try to encode the entire list */ /* into one packet. */ else if (rpdata->array_index == BACNET_ARRAY_ALL) { for (i = 0; i < MAX_BACNET_EVENT_TRANSITION; i++) { - len = - encode_opening_tag(&apdu[apdu_len], - TIME_STAMP_DATETIME); - len += - encode_application_date(&apdu[apdu_len + len], + len = encode_opening_tag(&apdu[apdu_len], + TIME_STAMP_DATETIME); + len += encode_application_date( + &apdu[apdu_len + len], &CurrentAI->Event_Time_Stamps[i].date); - len += - encode_application_time(&apdu[apdu_len + len], + len += encode_application_time( + &apdu[apdu_len + len], &CurrentAI->Event_Time_Stamps[i].time); - len += - encode_closing_tag(&apdu[apdu_len + len], - TIME_STAMP_DATETIME); + len += encode_closing_tag(&apdu[apdu_len + len], + TIME_STAMP_DATETIME); /* add it if we have room */ if ((apdu_len + len) < MAX_APDU) @@ -606,11 +563,11 @@ int Analog_Input_Read_Property( } else if (rpdata->array_index <= MAX_BACNET_EVENT_TRANSITION) { apdu_len = encode_opening_tag(&apdu[apdu_len], TIME_STAMP_DATETIME); - apdu_len += - encode_application_date(&apdu[apdu_len], + apdu_len += encode_application_date( + &apdu[apdu_len], &CurrentAI->Event_Time_Stamps[rpdata->array_index].date); - apdu_len += - encode_application_time(&apdu[apdu_len], + apdu_len += encode_application_time( + &apdu[apdu_len], &CurrentAI->Event_Time_Stamps[rpdata->array_index].time); apdu_len += encode_closing_tag(&apdu[apdu_len], TIME_STAMP_DATETIME); @@ -626,11 +583,13 @@ int Analog_Input_Read_Property( apdu_len = encode_application_real(&apdu[0], 90.510F); break; case 9998: - /* test case for unsigned encoding-decoding unsigned value correctly */ + /* test case for unsigned encoding-decoding unsigned value correctly + */ apdu_len = encode_application_unsigned(&apdu[0], 90); break; case 9999: - /* test case for signed encoding-decoding negative value correctly */ + /* test case for signed encoding-decoding negative value correctly + */ apdu_len = encode_application_signed(&apdu[0], -200); break; default: @@ -640,8 +599,9 @@ int Analog_Input_Read_Property( break; } /* only array properties can have array options */ - if ((apdu_len >= 0) && (rpdata->object_property != PROP_EVENT_TIME_STAMPS) - && (rpdata->array_index != BACNET_ARRAY_ALL)) { + if ((apdu_len >= 0) && + (rpdata->object_property != PROP_EVENT_TIME_STAMPS) && + (rpdata->array_index != BACNET_ARRAY_ALL)) { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; apdu_len = BACNET_STATUS_ERROR; @@ -651,19 +611,17 @@ int Analog_Input_Read_Property( } /* returns true if successful */ -bool Analog_Input_Write_Property( - BACNET_WRITE_PROPERTY_DATA * wp_data) +bool Analog_Input_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data) { - bool status = false; /* return value */ + bool status = false; /* return value */ unsigned int object_index = 0; int len = 0; BACNET_APPLICATION_DATA_VALUE value; ANALOG_INPUT_DESCR *CurrentAI; /* decode the some of the request */ - len = - bacapp_decode_application_data(wp_data->application_data, - wp_data->application_data_len, &value); + len = bacapp_decode_application_data(wp_data->application_data, + wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ if (len < 0) { /* error while decoding - a value larger than we can handle */ @@ -685,16 +643,16 @@ bool Analog_Input_Write_Property( return false; } - switch ((int) wp_data->object_property) { + switch ((int)wp_data->object_property) { case PROP_PRESENT_VALUE: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_REAL, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { if (CurrentAI->Out_Of_Service == true) { Analog_Input_Present_Value_Set(wp_data->object_instance, - value.type.Real); + value.type.Real); } else { wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED; @@ -706,18 +664,17 @@ bool Analog_Input_Write_Property( case PROP_OUT_OF_SERVICE: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { - Analog_Input_Out_Of_Service_Set( - wp_data->object_instance, - value.type.Boolean); + Analog_Input_Out_Of_Service_Set(wp_data->object_instance, + value.type.Boolean); } break; case PROP_UNITS: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_ENUMERATED, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { CurrentAI->Units = value.type.Enumerated; } @@ -726,12 +683,11 @@ bool Analog_Input_Write_Property( case PROP_COV_INCREMENT: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_REAL, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { if (value.type.Real >= 0.0) { - Analog_Input_COV_Increment_Set( - wp_data->object_instance, - value.type.Real); + Analog_Input_COV_Increment_Set(wp_data->object_instance, + value.type.Real); } else { status = false; wp_data->error_class = ERROR_CLASS_PROPERTY; @@ -744,7 +700,7 @@ bool Analog_Input_Write_Property( case PROP_TIME_DELAY: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { CurrentAI->Time_Delay = value.type.Unsigned_Int; @@ -755,7 +711,7 @@ bool Analog_Input_Write_Property( case PROP_NOTIFICATION_CLASS: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { CurrentAI->Notification_Class = value.type.Unsigned_Int; @@ -765,7 +721,7 @@ bool Analog_Input_Write_Property( case PROP_HIGH_LIMIT: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_REAL, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { CurrentAI->High_Limit = value.type.Real; @@ -775,7 +731,7 @@ bool Analog_Input_Write_Property( case PROP_LOW_LIMIT: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_REAL, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { CurrentAI->Low_Limit = value.type.Real; @@ -785,7 +741,7 @@ bool Analog_Input_Write_Property( case PROP_DEADBAND: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_REAL, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { CurrentAI->Deadband = value.type.Real; @@ -795,7 +751,7 @@ bool Analog_Input_Write_Property( case PROP_LIMIT_ENABLE: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_BIT_STRING, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { if (value.type.Bit_String.bits_used == 2) { @@ -811,7 +767,7 @@ bool Analog_Input_Write_Property( case PROP_EVENT_ENABLE: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_BIT_STRING, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { if (value.type.Bit_String.bits_used == 3) { @@ -827,10 +783,10 @@ bool Analog_Input_Write_Property( case PROP_NOTIFY_TYPE: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_ENUMERATED, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { - switch ((BACNET_NOTIFY_TYPE) value.type.Enumerated) { + switch ((BACNET_NOTIFY_TYPE)value.type.Enumerated) { case NOTIFY_EVENT: CurrentAI->Notify_Type = 1; break; @@ -872,9 +828,7 @@ bool Analog_Input_Write_Property( return status; } - -void Analog_Input_Intrinsic_Reporting( - uint32_t object_instance) +void Analog_Input_Intrinsic_Reporting(uint32_t object_instance) { #if defined(INTRINSIC_REPORTING) BACNET_EVENT_NOTIFICATION_DATA event_data; @@ -887,7 +841,6 @@ void Analog_Input_Intrinsic_Reporting( float PresentVal = 0.0f; bool SendNotify = false; - object_index = Analog_Input_Instance_To_Index(object_instance); if (object_index < MAX_ANALOG_INPUTS) CurrentAI = &AI_Descr[object_index]; @@ -898,7 +851,6 @@ void Analog_Input_Intrinsic_Reporting( if (!CurrentAI->Limit_Enable) return; /* limits are not configured */ - if (CurrentAI->Ack_notify_data.bSendAckNotify) { /* clean bSendAckNotify flag */ CurrentAI->Ack_notify_data.bSendAckNotify = false; @@ -907,7 +859,7 @@ void Analog_Input_Intrinsic_Reporting( #if PRINT_ENABLED fprintf(stderr, "Send Acknotification for (%s,%d).\n", - bactext_object_type_name(OBJECT_ANALOG_INPUT), object_instance); + bactext_object_type_name(OBJECT_ANALOG_INPUT), object_instance); #endif /* PRINT_ENABLED */ characterstring_init_ansi(&msgText, "AckNotification"); @@ -924,15 +876,17 @@ void Analog_Input_Intrinsic_Reporting( switch (CurrentAI->Event_State) { case EVENT_STATE_NORMAL: /* A TO-OFFNORMAL event is generated under these conditions: - (a) the Present_Value must exceed the High_Limit for a minimum - period of time, specified in the Time_Delay property, and - (b) the HighLimitEnable flag must be set in the Limit_Enable property, and - (c) the TO-OFFNORMAL flag must be set in the Event_Enable property. */ + (a) the Present_Value must exceed the High_Limit for a + minimum period of time, specified in the Time_Delay property, + and (b) the HighLimitEnable flag must be set in the + Limit_Enable property, and + (c) the TO-OFFNORMAL flag must be set in the Event_Enable + property. */ if ((PresentVal > CurrentAI->High_Limit) && ((CurrentAI->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) == - EVENT_HIGH_LIMIT_ENABLE) && + EVENT_HIGH_LIMIT_ENABLE) && ((CurrentAI->Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) == - EVENT_ENABLE_TO_OFFNORMAL)) { + EVENT_ENABLE_TO_OFFNORMAL)) { if (!CurrentAI->Remaining_Time_Delay) CurrentAI->Event_State = EVENT_STATE_HIGH_LIMIT; else @@ -941,15 +895,17 @@ void Analog_Input_Intrinsic_Reporting( } /* A TO-OFFNORMAL event is generated under these conditions: - (a) the Present_Value must exceed the Low_Limit plus the Deadband - for a minimum period of time, specified in the Time_Delay property, and - (b) the LowLimitEnable flag must be set in the Limit_Enable property, and - (c) the TO-NORMAL flag must be set in the Event_Enable property. */ + (a) the Present_Value must exceed the Low_Limit plus the + Deadband for a minimum period of time, specified in the + Time_Delay property, and (b) the LowLimitEnable flag must be + set in the Limit_Enable property, and + (c) the TO-NORMAL flag must be set in the Event_Enable + property. */ if ((PresentVal < CurrentAI->Low_Limit) && ((CurrentAI->Limit_Enable & EVENT_LOW_LIMIT_ENABLE) == - EVENT_LOW_LIMIT_ENABLE) && + EVENT_LOW_LIMIT_ENABLE) && ((CurrentAI->Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) == - EVENT_ENABLE_TO_OFFNORMAL)) { + EVENT_ENABLE_TO_OFFNORMAL)) { if (!CurrentAI->Remaining_Time_Delay) CurrentAI->Event_State = EVENT_STATE_LOW_LIMIT; else @@ -961,17 +917,20 @@ void Analog_Input_Intrinsic_Reporting( break; case EVENT_STATE_HIGH_LIMIT: - /* Once exceeded, the Present_Value must fall below the High_Limit minus - the Deadband before a TO-NORMAL event is generated under these conditions: - (a) the Present_Value must fall below the High_Limit minus the Deadband - for a minimum period of time, specified in the Time_Delay property, and - (b) the HighLimitEnable flag must be set in the Limit_Enable property, and - (c) the TO-NORMAL flag must be set in the Event_Enable property. */ - if ((PresentVal < CurrentAI->High_Limit - CurrentAI->Deadband) - && ((CurrentAI->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) == - EVENT_HIGH_LIMIT_ENABLE) && + /* Once exceeded, the Present_Value must fall below the + High_Limit minus the Deadband before a TO-NORMAL event is + generated under these conditions: (a) the Present_Value must + fall below the High_Limit minus the Deadband for a minimum + period of time, specified in the Time_Delay property, and (b) + the HighLimitEnable flag must be set in the Limit_Enable + property, and (c) the TO-NORMAL flag must be set in the + Event_Enable property. */ + if ((PresentVal < + CurrentAI->High_Limit - CurrentAI->Deadband) && + ((CurrentAI->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) == + EVENT_HIGH_LIMIT_ENABLE) && ((CurrentAI->Event_Enable & EVENT_ENABLE_TO_NORMAL) == - EVENT_ENABLE_TO_NORMAL)) { + EVENT_ENABLE_TO_NORMAL)) { if (!CurrentAI->Remaining_Time_Delay) CurrentAI->Event_State = EVENT_STATE_NORMAL; else @@ -986,15 +945,17 @@ void Analog_Input_Intrinsic_Reporting( /* Once the Present_Value has fallen below the Low_Limit, the Present_Value must exceed the Low_Limit plus the Deadband before a TO-NORMAL event is generated under these conditions: - (a) the Present_Value must exceed the Low_Limit plus the Deadband - for a minimum period of time, specified in the Time_Delay property, and - (b) the LowLimitEnable flag must be set in the Limit_Enable property, and - (c) the TO-NORMAL flag must be set in the Event_Enable property. */ - if ((PresentVal > CurrentAI->Low_Limit + CurrentAI->Deadband) - && ((CurrentAI->Limit_Enable & EVENT_LOW_LIMIT_ENABLE) == - EVENT_LOW_LIMIT_ENABLE) && + (a) the Present_Value must exceed the Low_Limit plus the + Deadband for a minimum period of time, specified in the + Time_Delay property, and (b) the LowLimitEnable flag must be + set in the Limit_Enable property, and + (c) the TO-NORMAL flag must be set in the Event_Enable + property. */ + if ((PresentVal > CurrentAI->Low_Limit + CurrentAI->Deadband) && + ((CurrentAI->Limit_Enable & EVENT_LOW_LIMIT_ENABLE) == + EVENT_LOW_LIMIT_ENABLE) && ((CurrentAI->Event_Enable & EVENT_ENABLE_TO_NORMAL) == - EVENT_ENABLE_TO_NORMAL)) { + EVENT_ENABLE_TO_NORMAL)) { if (!CurrentAI->Remaining_Time_Delay) CurrentAI->Event_State = EVENT_STATE_NORMAL; else @@ -1007,7 +968,7 @@ void Analog_Input_Intrinsic_Reporting( default: return; /* shouldn't happen */ - } /* switch (FromState) */ + } /* switch (FromState) */ ToState = CurrentAI->Event_State; @@ -1030,25 +991,25 @@ void Analog_Input_Intrinsic_Reporting( case EVENT_STATE_NORMAL: if (FromState == EVENT_STATE_HIGH_LIMIT) { ExceededLimit = CurrentAI->High_Limit; - characterstring_init_ansi(&msgText, - "Back to normal state from high limit"); + characterstring_init_ansi( + &msgText, "Back to normal state from high limit"); } else { ExceededLimit = CurrentAI->Low_Limit; - characterstring_init_ansi(&msgText, - "Back to normal state from low limit"); + characterstring_init_ansi( + &msgText, "Back to normal state from low limit"); } break; default: ExceededLimit = 0; break; - } /* switch (ToState) */ + } /* switch (ToState) */ #if PRINT_ENABLED fprintf(stderr, "Event_State for (%s,%d) goes from %s to %s.\n", - bactext_object_type_name(OBJECT_ANALOG_INPUT), object_instance, - bactext_event_state_name(FromState), - bactext_event_state_name(ToState)); + bactext_object_type_name(OBJECT_ANALOG_INPUT), + object_instance, bactext_event_state_name(FromState), + bactext_event_state_name(ToState)); #endif /* PRINT_ENABLED */ /* Notify Type */ @@ -1059,7 +1020,6 @@ void Analog_Input_Intrinsic_Reporting( } } - if (SendNotify) { /* Event Object Identifier */ event_data.eventObjectIdentifier.type = OBJECT_ANALOG_INPUT; @@ -1115,18 +1075,20 @@ void Analog_Input_Intrinsic_Reporting( event_data.notificationParams.outOfRange.exceedingValue = PresentVal; /* Status_Flags of the referenced object. */ - bitstring_init(&event_data.notificationParams.outOfRange. - statusFlags); - bitstring_set_bit(&event_data.notificationParams.outOfRange. - statusFlags, STATUS_FLAG_IN_ALARM, - CurrentAI->Event_State ? true : false); - bitstring_set_bit(&event_data.notificationParams.outOfRange. - statusFlags, STATUS_FLAG_FAULT, false); - bitstring_set_bit(&event_data.notificationParams.outOfRange. - statusFlags, STATUS_FLAG_OVERRIDDEN, false); - bitstring_set_bit(&event_data.notificationParams.outOfRange. - statusFlags, STATUS_FLAG_OUT_OF_SERVICE, - CurrentAI->Out_Of_Service); + bitstring_init( + &event_data.notificationParams.outOfRange.statusFlags); + bitstring_set_bit( + &event_data.notificationParams.outOfRange.statusFlags, + STATUS_FLAG_IN_ALARM, CurrentAI->Event_State ? true : false); + bitstring_set_bit( + &event_data.notificationParams.outOfRange.statusFlags, + STATUS_FLAG_FAULT, false); + bitstring_set_bit( + &event_data.notificationParams.outOfRange.statusFlags, + STATUS_FLAG_OVERRIDDEN, false); + bitstring_set_bit( + &event_data.notificationParams.outOfRange.statusFlags, + STATUS_FLAG_OUT_OF_SERVICE, CurrentAI->Out_Of_Service); /* Deadband used for limit checking. */ event_data.notificationParams.outOfRange.deadband = CurrentAI->Deadband; @@ -1145,24 +1107,24 @@ void Analog_Input_Intrinsic_Reporting( case EVENT_STATE_OFFNORMAL: case EVENT_STATE_HIGH_LIMIT: case EVENT_STATE_LOW_LIMIT: - CurrentAI->Acked_Transitions[TRANSITION_TO_OFFNORMAL]. - bIsAcked = false; - CurrentAI->Acked_Transitions[TRANSITION_TO_OFFNORMAL]. - Time_Stamp = event_data.timeStamp.value.dateTime; + CurrentAI->Acked_Transitions[TRANSITION_TO_OFFNORMAL] + .bIsAcked = false; + CurrentAI->Acked_Transitions[TRANSITION_TO_OFFNORMAL] + .Time_Stamp = event_data.timeStamp.value.dateTime; break; case EVENT_STATE_FAULT: - CurrentAI->Acked_Transitions[TRANSITION_TO_FAULT]. - bIsAcked = false; - CurrentAI->Acked_Transitions[TRANSITION_TO_FAULT]. - Time_Stamp = event_data.timeStamp.value.dateTime; + CurrentAI->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked = + false; + CurrentAI->Acked_Transitions[TRANSITION_TO_FAULT] + .Time_Stamp = event_data.timeStamp.value.dateTime; break; case EVENT_STATE_NORMAL: - CurrentAI->Acked_Transitions[TRANSITION_TO_NORMAL]. - bIsAcked = false; - CurrentAI->Acked_Transitions[TRANSITION_TO_NORMAL]. - Time_Stamp = event_data.timeStamp.value.dateTime; + CurrentAI->Acked_Transitions[TRANSITION_TO_NORMAL] + .bIsAcked = false; + CurrentAI->Acked_Transitions[TRANSITION_TO_NORMAL] + .Time_Stamp = event_data.timeStamp.value.dateTime; break; } } @@ -1170,17 +1132,14 @@ void Analog_Input_Intrinsic_Reporting( #endif /* defined(INTRINSIC_REPORTING) */ } - #if defined(INTRINSIC_REPORTING) int Analog_Input_Event_Information( - unsigned index, - BACNET_GET_EVENT_INFORMATION_DATA * getevent_data) + unsigned index, BACNET_GET_EVENT_INFORMATION_DATA *getevent_data) { bool IsNotAckedTransitions; bool IsActiveEvent; int i; - /* check index */ if (index < MAX_ANALOG_INPUTS) { /* Event_State not equal to NORMAL */ @@ -1189,14 +1148,15 @@ int Analog_Input_Event_Information( /* Acked_Transitions property, which has at least one of the bits (TO-OFFNORMAL, TO-FAULT, TONORMAL) set to FALSE. */ IsNotAckedTransitions = - (AI_Descr[index].Acked_Transitions[TRANSITION_TO_OFFNORMAL]. - bIsAcked == - false) | (AI_Descr[index].Acked_Transitions[TRANSITION_TO_FAULT]. - bIsAcked == - false) | (AI_Descr[index].Acked_Transitions[TRANSITION_TO_NORMAL]. - bIsAcked == false); + (AI_Descr[index] + .Acked_Transitions[TRANSITION_TO_OFFNORMAL] + .bIsAcked == false) | + (AI_Descr[index].Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked == + false) | + (AI_Descr[index].Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked == + false); } else - return -1; /* end of list */ + return -1; /* end of list */ if ((IsActiveEvent) || (IsNotAckedTransitions)) { /* Object Identifier */ @@ -1208,14 +1168,15 @@ int Analog_Input_Event_Information( /* Acknowledged Transitions */ bitstring_init(&getevent_data->acknowledgedTransitions); bitstring_set_bit(&getevent_data->acknowledgedTransitions, - TRANSITION_TO_OFFNORMAL, - AI_Descr[index].Acked_Transitions[TRANSITION_TO_OFFNORMAL]. - bIsAcked); - bitstring_set_bit(&getevent_data->acknowledgedTransitions, - TRANSITION_TO_FAULT, + TRANSITION_TO_OFFNORMAL, + AI_Descr[index] + .Acked_Transitions[TRANSITION_TO_OFFNORMAL] + .bIsAcked); + bitstring_set_bit( + &getevent_data->acknowledgedTransitions, TRANSITION_TO_FAULT, AI_Descr[index].Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked); - bitstring_set_bit(&getevent_data->acknowledgedTransitions, - TRANSITION_TO_NORMAL, + bitstring_set_bit( + &getevent_data->acknowledgedTransitions, TRANSITION_TO_NORMAL, AI_Descr[index].Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked); /* Event Time Stamps */ for (i = 0; i < 3; i++) { @@ -1227,36 +1188,35 @@ int Analog_Input_Event_Information( getevent_data->notifyType = AI_Descr[index].Notify_Type; /* Event Enable */ bitstring_init(&getevent_data->eventEnable); - bitstring_set_bit(&getevent_data->eventEnable, TRANSITION_TO_OFFNORMAL, - (AI_Descr[index]. - Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ? true : false); + bitstring_set_bit( + &getevent_data->eventEnable, TRANSITION_TO_OFFNORMAL, + (AI_Descr[index].Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ? true + : false); bitstring_set_bit(&getevent_data->eventEnable, TRANSITION_TO_FAULT, - (AI_Descr[index]. - Event_Enable & EVENT_ENABLE_TO_FAULT) ? true : false); - bitstring_set_bit(&getevent_data->eventEnable, TRANSITION_TO_NORMAL, - (AI_Descr[index]. - Event_Enable & EVENT_ENABLE_TO_NORMAL) ? true : false); + (AI_Descr[index].Event_Enable & EVENT_ENABLE_TO_FAULT) + ? true + : false); + bitstring_set_bit( + &getevent_data->eventEnable, TRANSITION_TO_NORMAL, + (AI_Descr[index].Event_Enable & EVENT_ENABLE_TO_NORMAL) ? true + : false); /* Event Priorities */ Notification_Class_Get_Priorities(AI_Descr[index].Notification_Class, - getevent_data->eventPriorities); + getevent_data->eventPriorities); - return 1; /* active event */ + return 1; /* active event */ } else - return 0; /* no active event at this index */ + return 0; /* no active event at this index */ } - -int Analog_Input_Alarm_Ack( - BACNET_ALARM_ACK_DATA * alarmack_data, - BACNET_ERROR_CODE * error_code) +int Analog_Input_Alarm_Ack(BACNET_ALARM_ACK_DATA *alarmack_data, + BACNET_ERROR_CODE *error_code) { ANALOG_INPUT_DESCR *CurrentAI; unsigned int object_index; - - object_index = - Analog_Input_Instance_To_Index(alarmack_data->eventObjectIdentifier. - instance); + object_index = Analog_Input_Instance_To_Index( + alarmack_data->eventObjectIdentifier.instance); if (object_index < MAX_ANALOG_INPUTS) CurrentAI = &AI_Descr[object_index]; @@ -1269,22 +1229,23 @@ int Analog_Input_Alarm_Ack( case EVENT_STATE_OFFNORMAL: case EVENT_STATE_HIGH_LIMIT: case EVENT_STATE_LOW_LIMIT: - if (CurrentAI->Acked_Transitions[TRANSITION_TO_OFFNORMAL]. - bIsAcked == false) { + if (CurrentAI->Acked_Transitions[TRANSITION_TO_OFFNORMAL] + .bIsAcked == false) { if (alarmack_data->eventTimeStamp.tag != TIME_STAMP_DATETIME) { *error_code = ERROR_CODE_INVALID_TIME_STAMP; return -1; } - if (datetime_compare(&CurrentAI-> - Acked_Transitions[TRANSITION_TO_OFFNORMAL].Time_Stamp, + if (datetime_compare( + &CurrentAI->Acked_Transitions[TRANSITION_TO_OFFNORMAL] + .Time_Stamp, &alarmack_data->eventTimeStamp.value.dateTime) > 0) { *error_code = ERROR_CODE_INVALID_TIME_STAMP; return -1; } /* FIXME: Send ack notification */ - CurrentAI->Acked_Transitions[TRANSITION_TO_OFFNORMAL]. - bIsAcked = true; + CurrentAI->Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked = + true; } else { *error_code = ERROR_CODE_INVALID_EVENT_STATE; return -1; @@ -1298,8 +1259,9 @@ int Analog_Input_Alarm_Ack( *error_code = ERROR_CODE_INVALID_TIME_STAMP; return -1; } - if (datetime_compare(&CurrentAI-> - Acked_Transitions[TRANSITION_TO_FAULT].Time_Stamp, + if (datetime_compare( + &CurrentAI->Acked_Transitions[TRANSITION_TO_FAULT] + .Time_Stamp, &alarmack_data->eventTimeStamp.value.dateTime) > 0) { *error_code = ERROR_CODE_INVALID_TIME_STAMP; return -1; @@ -1321,8 +1283,9 @@ int Analog_Input_Alarm_Ack( *error_code = ERROR_CODE_INVALID_TIME_STAMP; return -1; } - if (datetime_compare(&CurrentAI-> - Acked_Transitions[TRANSITION_TO_NORMAL].Time_Stamp, + if (datetime_compare( + &CurrentAI->Acked_Transitions[TRANSITION_TO_NORMAL] + .Time_Stamp, &alarmack_data->eventTimeStamp.value.dateTime) > 0) { *error_code = ERROR_CODE_INVALID_TIME_STAMP; return -1; @@ -1346,11 +1309,9 @@ int Analog_Input_Alarm_Ack( return 1; } -int Analog_Input_Alarm_Summary( - unsigned index, - BACNET_GET_ALARM_SUMMARY_DATA * getalarm_data) +int Analog_Input_Alarm_Summary(unsigned index, + BACNET_GET_ALARM_SUMMARY_DATA *getalarm_data) { - /* check index */ if (index < MAX_ANALOG_INPUTS) { /* Event_State is not equal to NORMAL and @@ -1366,37 +1327,37 @@ int Analog_Input_Alarm_Summary( /* Acknowledged Transitions */ bitstring_init(&getalarm_data->acknowledgedTransitions); bitstring_set_bit(&getalarm_data->acknowledgedTransitions, - TRANSITION_TO_OFFNORMAL, - AI_Descr[index].Acked_Transitions[TRANSITION_TO_OFFNORMAL]. - bIsAcked); + TRANSITION_TO_OFFNORMAL, + AI_Descr[index] + .Acked_Transitions[TRANSITION_TO_OFFNORMAL] + .bIsAcked); bitstring_set_bit(&getalarm_data->acknowledgedTransitions, - TRANSITION_TO_FAULT, - AI_Descr[index]. - Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked); + TRANSITION_TO_FAULT, + AI_Descr[index] + .Acked_Transitions[TRANSITION_TO_FAULT] + .bIsAcked); bitstring_set_bit(&getalarm_data->acknowledgedTransitions, - TRANSITION_TO_NORMAL, - AI_Descr[index]. - Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked); + TRANSITION_TO_NORMAL, + AI_Descr[index] + .Acked_Transitions[TRANSITION_TO_NORMAL] + .bIsAcked); - return 1; /* active alarm */ + return 1; /* active alarm */ } else - return 0; /* no active alarm at this index */ + return 0; /* no active alarm at this index */ } else - return -1; /* end of list */ + return -1; /* end of list */ } #endif /* defined(INTRINSIC_REPORTING) */ - #ifdef TEST #include #include #include "ctest.h" -bool WPValidateArgType( - BACNET_APPLICATION_DATA_VALUE * pValue, - uint8_t ucExpectedTag, - BACNET_ERROR_CLASS * pErrorClass, - BACNET_ERROR_CODE * pErrorCode) +bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue, + uint8_t ucExpectedTag, BACNET_ERROR_CLASS *pErrorClass, + BACNET_ERROR_CODE *pErrorCode) { bool bResult; @@ -1414,10 +1375,9 @@ bool WPValidateArgType( return (bResult); } -void testAnalogInput( - Test * pTest) +void testAnalogInput(Test *pTest) { - uint8_t apdu[MAX_APDU] = { 0 }; + uint8_t apdu[MAX_APDU] = {0}; int len = 0; uint32_t len_value = 0; uint8_t tag_number = 0; @@ -1444,8 +1404,7 @@ void testAnalogInput( } #ifdef TEST_ANALOG_INPUT -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -1457,7 +1416,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/demo/object/ao.c b/demo/object/ao.c index f8022465..f377fe77 100644 --- a/demo/object/ao.c +++ b/demo/object/ao.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2005 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2005 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* Analog Output Objects - customize for your use */ @@ -32,7 +32,7 @@ #include "bacdcode.h" #include "bacenum.h" #include "bacapp.h" -#include "config.h" /* the custom stuff */ +#include "config.h" /* the custom stuff */ #include "wp.h" #include "ao.h" #include "handlers.h" @@ -60,32 +60,24 @@ static bool Out_Of_Service[MAX_ANALOG_OUTPUTS]; static bool Analog_Output_Initialized = false; /* These three arrays are used by the ReadPropertyMultiple handler */ -static const int Properties_Required[] = { - PROP_OBJECT_IDENTIFIER, - PROP_OBJECT_NAME, - PROP_OBJECT_TYPE, - PROP_PRESENT_VALUE, - PROP_STATUS_FLAGS, - PROP_EVENT_STATE, - PROP_OUT_OF_SERVICE, - PROP_UNITS, - PROP_PRIORITY_ARRAY, - PROP_RELINQUISH_DEFAULT, - -1 -}; +static const int Properties_Required[] = {PROP_OBJECT_IDENTIFIER, + PROP_OBJECT_NAME, + PROP_OBJECT_TYPE, + PROP_PRESENT_VALUE, + PROP_STATUS_FLAGS, + PROP_EVENT_STATE, + PROP_OUT_OF_SERVICE, + PROP_UNITS, + PROP_PRIORITY_ARRAY, + PROP_RELINQUISH_DEFAULT, + -1}; -static const int Properties_Optional[] = { - -1 -}; +static const int Properties_Optional[] = {-1}; -static const int Properties_Proprietary[] = { - -1 -}; +static const int Properties_Proprietary[] = {-1}; -void Analog_Output_Property_Lists( - const int **pRequired, - const int **pOptional, - const int **pProprietary) +void Analog_Output_Property_Lists(const int **pRequired, const int **pOptional, + const int **pProprietary) { if (pRequired) *pRequired = Properties_Required; @@ -97,8 +89,7 @@ void Analog_Output_Property_Lists( return; } -void Analog_Output_Init( - void) +void Analog_Output_Init(void) { unsigned i, j; @@ -119,8 +110,7 @@ void Analog_Output_Init( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need validate that the */ /* given instance exists */ -bool Analog_Output_Valid_Instance( - uint32_t object_instance) +bool Analog_Output_Valid_Instance(uint32_t object_instance) { if (object_instance < MAX_ANALOG_OUTPUTS) return true; @@ -130,8 +120,7 @@ bool Analog_Output_Valid_Instance( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then count how many you have */ -unsigned Analog_Output_Count( - void) +unsigned Analog_Output_Count(void) { return MAX_ANALOG_OUTPUTS; } @@ -139,8 +128,7 @@ unsigned Analog_Output_Count( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need to return the instance */ /* that correlates to the correct index */ -uint32_t Analog_Output_Index_To_Instance( - unsigned index) +uint32_t Analog_Output_Index_To_Instance(unsigned index) { return index; } @@ -148,8 +136,7 @@ uint32_t Analog_Output_Index_To_Instance( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need to return the index */ /* that correlates to the correct instance number */ -unsigned Analog_Output_Instance_To_Index( - uint32_t object_instance) +unsigned Analog_Output_Instance_To_Index(uint32_t object_instance) { unsigned index = MAX_ANALOG_OUTPUTS; @@ -159,8 +146,7 @@ unsigned Analog_Output_Instance_To_Index( return index; } -float Analog_Output_Present_Value( - uint32_t object_instance) +float Analog_Output_Present_Value(uint32_t object_instance) { float value = AO_RELINQUISH_DEFAULT; unsigned index = 0; @@ -179,12 +165,11 @@ float Analog_Output_Present_Value( return value; } -unsigned Analog_Output_Present_Value_Priority( - uint32_t object_instance) +unsigned Analog_Output_Present_Value_Priority(uint32_t object_instance) { - unsigned index = 0; /* instance to index conversion */ - unsigned i = 0; /* loop counter */ - unsigned priority = 0; /* return value */ + unsigned index = 0; /* instance to index conversion */ + unsigned i = 0; /* loop counter */ + unsigned priority = 0; /* return value */ index = Analog_Output_Instance_To_Index(object_instance); if (index < MAX_ANALOG_OUTPUTS) { @@ -199,10 +184,8 @@ unsigned Analog_Output_Present_Value_Priority( return priority; } -bool Analog_Output_Present_Value_Set( - uint32_t object_instance, - float value, - unsigned priority) +bool Analog_Output_Present_Value_Set(uint32_t object_instance, float value, + unsigned priority) { unsigned index = 0; bool status = false; @@ -210,9 +193,9 @@ bool Analog_Output_Present_Value_Set( index = Analog_Output_Instance_To_Index(object_instance); if (index < MAX_ANALOG_OUTPUTS) { if (priority && (priority <= BACNET_MAX_PRIORITY) && - (priority != 6 /* reserved */ ) && - (value >= 0.0) && (value <= 100.0)) { - Analog_Output_Level[index][priority - 1] = (uint8_t) value; + (priority != 6 /* reserved */) && (value >= 0.0) && + (value <= 100.0)) { + Analog_Output_Level[index][priority - 1] = (uint8_t)value; /* Note: you could set the physical output here to the next highest priority, or to the relinquish default if no priorities are set. @@ -226,9 +209,8 @@ bool Analog_Output_Present_Value_Set( return status; } -bool Analog_Output_Present_Value_Relinquish( - uint32_t object_instance, - unsigned priority) +bool Analog_Output_Present_Value_Relinquish(uint32_t object_instance, + unsigned priority) { unsigned index = 0; bool status = false; @@ -236,7 +218,7 @@ bool Analog_Output_Present_Value_Relinquish( index = Analog_Output_Instance_To_Index(object_instance); if (index < MAX_ANALOG_OUTPUTS) { if (priority && (priority <= BACNET_MAX_PRIORITY) && - (priority != 6 /* reserved */ )) { + (priority != 6 /* reserved */)) { Analog_Output_Level[index][priority - 1] = AO_LEVEL_NULL; /* Note: you could set the physical output here to the next highest priority, or to the relinquish default if no @@ -252,24 +234,22 @@ bool Analog_Output_Present_Value_Relinquish( } /* note: the object name must be unique within this device */ -bool Analog_Output_Object_Name( - uint32_t object_instance, - BACNET_CHARACTER_STRING * object_name) +bool Analog_Output_Object_Name(uint32_t object_instance, + BACNET_CHARACTER_STRING *object_name) { - static char text_string[32] = ""; /* okay for single thread */ + static char text_string[32] = ""; /* okay for single thread */ bool status = false; if (object_instance < MAX_ANALOG_OUTPUTS) { sprintf(text_string, "ANALOG OUTPUT %lu", - (unsigned long) object_instance); + (unsigned long)object_instance); status = characterstring_init_ansi(object_name, text_string); } return status; } -bool Analog_Output_Out_Of_Service( - uint32_t instance) +bool Analog_Output_Out_Of_Service(uint32_t instance) { unsigned index = 0; bool oos_flag = false; @@ -282,9 +262,7 @@ bool Analog_Output_Out_Of_Service( return oos_flag; } -void Analog_Output_Out_Of_Service_Set( - uint32_t instance, - bool oos_flag) +void Analog_Output_Out_Of_Service_Set(uint32_t instance, bool oos_flag) { unsigned index = 0; @@ -295,14 +273,13 @@ void Analog_Output_Out_Of_Service_Set( } /* return apdu len, or BACNET_STATUS_ERROR on error */ -int Analog_Output_Read_Property( - BACNET_READ_PROPERTY_DATA * rpdata) +int Analog_Output_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata) { int len = 0; - int apdu_len = 0; /* return value */ + int apdu_len = 0; /* return value */ BACNET_BIT_STRING bit_string; BACNET_CHARACTER_STRING char_string; - float real_value = (float) 1.414; + float real_value = (float)1.414; unsigned object_index = 0; unsigned i = 0; bool state = false; @@ -315,9 +292,8 @@ int Analog_Output_Read_Property( apdu = rpdata->application_data; switch (rpdata->object_property) { case PROP_OBJECT_IDENTIFIER: - apdu_len = - encode_application_object_id(&apdu[0], OBJECT_ANALOG_OUTPUT, - rpdata->object_instance); + apdu_len = encode_application_object_id( + &apdu[0], OBJECT_ANALOG_OUTPUT, rpdata->object_instance); break; case PROP_OBJECT_NAME: Analog_Output_Object_Name(rpdata->object_instance, &char_string); @@ -368,9 +344,8 @@ int Analog_Output_Read_Property( len = encode_application_null(&apdu[apdu_len]); else { real_value = Analog_Output_Level[object_index][i]; - len = - encode_application_real(&apdu[apdu_len], - real_value); + len = encode_application_real(&apdu[apdu_len], + real_value); } /* add it if we have room */ if ((apdu_len + len) < MAX_APDU) @@ -387,11 +362,12 @@ int Analog_Output_Read_Property( 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) + 1] == AO_LEVEL_NULL) apdu_len = encode_application_null(&apdu[0]); else { - real_value = Analog_Output_Level[object_index] - [rpdata->array_index - 1]; + real_value = + Analog_Output_Level[object_index] + [rpdata->array_index - 1]; apdu_len = encode_application_real(&apdu[0], real_value); } @@ -424,17 +400,15 @@ int Analog_Output_Read_Property( } /* returns true if successful */ -bool Analog_Output_Write_Property( - BACNET_WRITE_PROPERTY_DATA * wp_data) +bool Analog_Output_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data) { - bool status = false; /* return value */ + bool status = false; /* return value */ int len = 0; BACNET_APPLICATION_DATA_VALUE value; /* decode the some of the request */ - len = - bacapp_decode_application_data(wp_data->application_data, - wp_data->application_data_len, &value); + len = bacapp_decode_application_data(wp_data->application_data, + wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ if (len < 0) { /* error while decoding - a value larger than we can handle */ @@ -455,9 +429,9 @@ bool Analog_Output_Write_Property( /* Command priority 6 is reserved for use by Minimum On/Off algorithm and may not be used for other purposes in any object. */ - status = - Analog_Output_Present_Value_Set(wp_data->object_instance, - value.type.Real, wp_data->priority); + status = Analog_Output_Present_Value_Set( + wp_data->object_instance, value.type.Real, + 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 @@ -469,13 +443,12 @@ 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) { - status = - Analog_Output_Present_Value_Relinquish - (wp_data->object_instance, wp_data->priority); + status = 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; @@ -486,10 +459,10 @@ bool Analog_Output_Write_Property( case PROP_OUT_OF_SERVICE: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { Analog_Output_Out_Of_Service_Set(wp_data->object_instance, - value.type.Boolean); + value.type.Boolean); } break; case PROP_OBJECT_IDENTIFIER: @@ -512,38 +485,34 @@ bool Analog_Output_Write_Property( return status; } - #ifdef TEST #include #include #include "ctest.h" -bool WPValidateArgType( - BACNET_APPLICATION_DATA_VALUE * pValue, - uint8_t ucExpectedTag, - BACNET_ERROR_CLASS * pErrorClass, - BACNET_ERROR_CODE * pErrorCode) +bool WPValidateArgType(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) { - bResult = false; + /* + * start out assuming success and only set up error + * response if validation fails. + */ + bResult = true; + if (pValue->tag != ucExpectedTag) { + bResult = false; *pErrorClass = ERROR_CLASS_PROPERTY; *pErrorCode = ERROR_CODE_INVALID_DATA_TYPE; - } + } - return (bResult); + return (bResult); } -void testAnalogOutput( - Test * pTest) +void testAnalogOutput(Test *pTest) { - uint8_t apdu[MAX_APDU] = { 0 }; + uint8_t apdu[MAX_APDU] = {0}; int len = 0; uint32_t len_value = 0; uint8_t tag_number = 0; @@ -570,8 +539,7 @@ void testAnalogOutput( } #ifdef TEST_ANALOG_OUTPUT -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -583,7 +551,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/demo/object/av.c b/demo/object/av.c index 149b6352..091b12b9 100644 --- a/demo/object/av.c +++ b/demo/object/av.c @@ -1,28 +1,28 @@ /************************************************************************** -* -* Copyright (C) 2006 Steve Karg -* Copyright (C) 2011 Krzysztof Malorny -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2006 Steve Karg + * Copyright (C) 2011 Krzysztof Malorny + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* Analog Value Objects - customize for your use */ @@ -36,12 +36,11 @@ #include "bacenum.h" #include "bacapp.h" #include "bactext.h" -#include "config.h" /* the custom stuff */ +#include "config.h" /* the custom stuff */ #include "device.h" #include "handlers.h" #include "av.h" - #ifndef MAX_ANALOG_VALUES #define MAX_ANALOG_VALUES 4 #endif @@ -50,43 +49,30 @@ ANALOG_VALUE_DESCR AV_Descr[MAX_ANALOG_VALUES]; /* These three arrays are used by the ReadPropertyMultiple handler */ static const int Analog_Value_Properties_Required[] = { - PROP_OBJECT_IDENTIFIER, - PROP_OBJECT_NAME, - PROP_OBJECT_TYPE, - PROP_PRESENT_VALUE, - PROP_STATUS_FLAGS, - PROP_EVENT_STATE, - PROP_OUT_OF_SERVICE, - PROP_UNITS, - -1 -}; + PROP_OBJECT_IDENTIFIER, PROP_OBJECT_NAME, PROP_OBJECT_TYPE, + PROP_PRESENT_VALUE, PROP_STATUS_FLAGS, PROP_EVENT_STATE, + PROP_OUT_OF_SERVICE, PROP_UNITS, -1}; -static const int Analog_Value_Properties_Optional[] = { - PROP_DESCRIPTION, - PROP_COV_INCREMENT, +static const int Analog_Value_Properties_Optional[] = {PROP_DESCRIPTION, + PROP_COV_INCREMENT, #if defined(INTRINSIC_REPORTING) - PROP_TIME_DELAY, - PROP_NOTIFICATION_CLASS, - PROP_HIGH_LIMIT, - PROP_LOW_LIMIT, - PROP_DEADBAND, - PROP_LIMIT_ENABLE, - PROP_EVENT_ENABLE, - PROP_ACKED_TRANSITIONS, - PROP_NOTIFY_TYPE, - PROP_EVENT_TIME_STAMPS, + PROP_TIME_DELAY, + PROP_NOTIFICATION_CLASS, + PROP_HIGH_LIMIT, + PROP_LOW_LIMIT, + PROP_DEADBAND, + PROP_LIMIT_ENABLE, + PROP_EVENT_ENABLE, + PROP_ACKED_TRANSITIONS, + PROP_NOTIFY_TYPE, + PROP_EVENT_TIME_STAMPS, #endif - -1 -}; + -1}; -static const int Analog_Value_Properties_Proprietary[] = { - -1 -}; +static const int Analog_Value_Properties_Proprietary[] = {-1}; -void Analog_Value_Property_Lists( - const int **pRequired, - const int **pOptional, - const int **pProprietary) +void Analog_Value_Property_Lists(const int **pRequired, const int **pOptional, + const int **pProprietary) { if (pRequired) *pRequired = Analog_Value_Properties_Required; @@ -98,12 +84,11 @@ void Analog_Value_Property_Lists( return; } -void Analog_Value_Init( - void) +void Analog_Value_Init(void) { - unsigned i; + unsigned i; #if defined(INTRINSIC_REPORTING) - unsigned j; + unsigned j; #endif for (i = 0; i < MAX_ANALOG_VALUES; i++) { @@ -126,12 +111,12 @@ void Analog_Value_Init( /* Set handler for GetEventInformation function */ handler_get_event_information_set(OBJECT_ANALOG_VALUE, - Analog_Value_Event_Information); + Analog_Value_Event_Information); /* Set handler for AcknowledgeAlarm function */ handler_alarm_ack_set(OBJECT_ANALOG_VALUE, Analog_Value_Alarm_Ack); /* Set handler for GetAlarmSummary Service */ handler_get_alarm_summary_set(OBJECT_ANALOG_VALUE, - Analog_Value_Alarm_Summary); + Analog_Value_Alarm_Summary); #endif } } @@ -139,8 +124,7 @@ void Analog_Value_Init( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need validate that the */ /* given instance exists */ -bool Analog_Value_Valid_Instance( - uint32_t object_instance) +bool Analog_Value_Valid_Instance(uint32_t object_instance) { if (object_instance < MAX_ANALOG_VALUES) return true; @@ -150,8 +134,7 @@ bool Analog_Value_Valid_Instance( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then count how many you have */ -unsigned Analog_Value_Count( - void) +unsigned Analog_Value_Count(void) { return MAX_ANALOG_VALUES; } @@ -159,8 +142,7 @@ unsigned Analog_Value_Count( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need to return the instance */ /* that correlates to the correct index */ -uint32_t Analog_Value_Index_To_Instance( - unsigned index) +uint32_t Analog_Value_Index_To_Instance(unsigned index) { return index; } @@ -168,8 +150,7 @@ uint32_t Analog_Value_Index_To_Instance( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need to return the index */ /* that correlates to the correct instance number */ -unsigned Analog_Value_Instance_To_Index( - uint32_t object_instance) +unsigned Analog_Value_Instance_To_Index(uint32_t object_instance) { unsigned index = MAX_ANALOG_VALUES; @@ -179,8 +160,7 @@ unsigned Analog_Value_Instance_To_Index( return index; } -static void Analog_Value_COV_Detect(unsigned int index, - float value) +static void Analog_Value_COV_Detect(unsigned int index, float value) { float prior_value = 0.0; float cov_increment = 0.0; @@ -211,10 +191,8 @@ static void Analog_Value_COV_Detect(unsigned int index, * * @return true if values are within range and present-value is set. */ -bool Analog_Value_Present_Value_Set( - uint32_t object_instance, - float value, - uint8_t priority) +bool Analog_Value_Present_Value_Set(uint32_t object_instance, float value, + uint8_t priority) { unsigned index = 0; bool status = false; @@ -228,8 +206,7 @@ bool Analog_Value_Present_Value_Set( return status; } -float Analog_Value_Present_Value( - uint32_t object_instance) +float Analog_Value_Present_Value(uint32_t object_instance) { float value = 0; unsigned index = 0; @@ -243,23 +220,22 @@ float Analog_Value_Present_Value( } /* note: the object name must be unique within this device */ -bool Analog_Value_Object_Name( - uint32_t object_instance, - BACNET_CHARACTER_STRING * object_name) +bool Analog_Value_Object_Name(uint32_t object_instance, + BACNET_CHARACTER_STRING *object_name) { - static char text_string[32] = ""; /* okay for single thread */ + static char text_string[32] = ""; /* okay for single thread */ bool status = false; if (object_instance < MAX_ANALOG_VALUES) { sprintf(text_string, "ANALOG VALUE %lu", - (unsigned long) object_instance); + (unsigned long)object_instance); status = characterstring_init_ansi(object_name, text_string); } return status; } - /** +/** * For a given object instance-number, determines if the COV flag * has been triggered. * @@ -303,9 +279,8 @@ void Analog_Value_Change_Of_Value_Clear(uint32_t object_instance) * * @return true if the value list is encoded */ -bool Analog_Value_Encode_Value_List( - uint32_t object_instance, - BACNET_PROPERTY_VALUE * value_list) +bool Analog_Value_Encode_Value_List(uint32_t object_instance, + BACNET_PROPERTY_VALUE *value_list) { bool status = false; @@ -327,17 +302,17 @@ bool Analog_Value_Encode_Value_List( value_list->value.tag = BACNET_APPLICATION_TAG_BIT_STRING; bitstring_init(&value_list->value.type.Bit_String); bitstring_set_bit(&value_list->value.type.Bit_String, - STATUS_FLAG_IN_ALARM, false); + STATUS_FLAG_IN_ALARM, false); + bitstring_set_bit(&value_list->value.type.Bit_String, STATUS_FLAG_FAULT, + false); bitstring_set_bit(&value_list->value.type.Bit_String, - STATUS_FLAG_FAULT, false); - bitstring_set_bit(&value_list->value.type.Bit_String, - STATUS_FLAG_OVERRIDDEN, false); + STATUS_FLAG_OVERRIDDEN, false); if (Analog_Value_Out_Of_Service(object_instance)) { bitstring_set_bit(&value_list->value.type.Bit_String, - STATUS_FLAG_OUT_OF_SERVICE, true); + STATUS_FLAG_OUT_OF_SERVICE, true); } else { bitstring_set_bit(&value_list->value.type.Bit_String, - STATUS_FLAG_OUT_OF_SERVICE, false); + STATUS_FLAG_OUT_OF_SERVICE, false); } value_list->value.next = NULL; value_list->priority = BACNET_NO_PRIORITY; @@ -348,8 +323,7 @@ bool Analog_Value_Encode_Value_List( return status; } -float Analog_Value_COV_Increment( - uint32_t object_instance) +float Analog_Value_COV_Increment(uint32_t object_instance) { unsigned index = 0; float value = 0; @@ -362,9 +336,7 @@ float Analog_Value_COV_Increment( return value; } -void Analog_Value_COV_Increment_Set( - uint32_t object_instance, - float value) +void Analog_Value_COV_Increment_Set(uint32_t object_instance, float value) { unsigned index = 0; @@ -375,8 +347,7 @@ void Analog_Value_COV_Increment_Set( } } -bool Analog_Value_Out_Of_Service( - uint32_t object_instance) +bool Analog_Value_Out_Of_Service(uint32_t object_instance) { unsigned index = 0; bool value = false; @@ -389,9 +360,7 @@ bool Analog_Value_Out_Of_Service( return value; } -void Analog_Value_Out_Of_Service_Set( - uint32_t object_instance, - bool value) +void Analog_Value_Out_Of_Service_Set(uint32_t object_instance, bool value) { unsigned index = 0; @@ -405,13 +374,12 @@ void Analog_Value_Out_Of_Service_Set( } /* return apdu len, or BACNET_STATUS_ERROR on error */ -int Analog_Value_Read_Property( - BACNET_READ_PROPERTY_DATA * rpdata) +int Analog_Value_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata) { - int apdu_len = 0; /* return value */ + int apdu_len = 0; /* return value */ BACNET_BIT_STRING bit_string; BACNET_CHARACTER_STRING char_string; - float real_value = (float) 1.414; + float real_value = (float)1.414; unsigned object_index = 0; bool state = false; uint8_t *apdu = NULL; @@ -436,9 +404,8 @@ int Analog_Value_Read_Property( switch (rpdata->object_property) { case PROP_OBJECT_IDENTIFIER: - apdu_len = - encode_application_object_id(&apdu[0], OBJECT_ANALOG_VALUE, - rpdata->object_instance); + apdu_len = encode_application_object_id( + &apdu[0], OBJECT_ANALOG_VALUE, rpdata->object_instance); break; case PROP_OBJECT_NAME: @@ -462,14 +429,14 @@ int Analog_Value_Read_Property( bitstring_init(&bit_string); #if defined(INTRINSIC_REPORTING) bitstring_set_bit(&bit_string, STATUS_FLAG_IN_ALARM, - CurrentAV->Event_State ? true : false); + CurrentAV->Event_State ? true : false); #else bitstring_set_bit(&bit_string, STATUS_FLAG_IN_ALARM, false); #endif bitstring_set_bit(&bit_string, STATUS_FLAG_FAULT, false); bitstring_set_bit(&bit_string, STATUS_FLAG_OVERRIDDEN, false); bitstring_set_bit(&bit_string, STATUS_FLAG_OUT_OF_SERVICE, - CurrentAV->Out_Of_Service); + CurrentAV->Out_Of_Service); apdu_len = encode_application_bitstring(&apdu[0], &bit_string); break; @@ -477,8 +444,7 @@ int Analog_Value_Read_Property( case PROP_EVENT_STATE: #if defined(INTRINSIC_REPORTING) apdu_len = - encode_application_enumerated(&apdu[0], - CurrentAV->Event_State); + encode_application_enumerated(&apdu[0], CurrentAV->Event_State); #else apdu_len = encode_application_enumerated(&apdu[0], EVENT_STATE_NORMAL); @@ -496,8 +462,8 @@ int Analog_Value_Read_Property( break; case PROP_COV_INCREMENT: - apdu_len = encode_application_real(&apdu[0], - CurrentAV->COV_Increment); + apdu_len = + encode_application_real(&apdu[0], CurrentAV->COV_Increment); break; #if defined(INTRINSIC_REPORTING) @@ -507,14 +473,12 @@ int Analog_Value_Read_Property( break; case PROP_NOTIFICATION_CLASS: - apdu_len = - encode_application_unsigned(&apdu[0], - CurrentAV->Notification_Class); + apdu_len = encode_application_unsigned( + &apdu[0], CurrentAV->Notification_Class); break; case PROP_HIGH_LIMIT: - apdu_len = - encode_application_real(&apdu[0], CurrentAV->High_Limit); + apdu_len = encode_application_real(&apdu[0], CurrentAV->High_Limit); break; case PROP_LOW_LIMIT: @@ -528,71 +492,74 @@ int Analog_Value_Read_Property( case PROP_LIMIT_ENABLE: bitstring_init(&bit_string); bitstring_set_bit(&bit_string, 0, - (CurrentAV-> - Limit_Enable & EVENT_LOW_LIMIT_ENABLE) ? true : false); - bitstring_set_bit(&bit_string, 1, - (CurrentAV-> - Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) ? true : false); + (CurrentAV->Limit_Enable & EVENT_LOW_LIMIT_ENABLE) + ? true + : false); + bitstring_set_bit( + &bit_string, 1, + (CurrentAV->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) ? true + : false); apdu_len = encode_application_bitstring(&apdu[0], &bit_string); break; case PROP_EVENT_ENABLE: bitstring_init(&bit_string); - bitstring_set_bit(&bit_string, TRANSITION_TO_OFFNORMAL, - (CurrentAV-> - Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ? true : false); + bitstring_set_bit( + &bit_string, TRANSITION_TO_OFFNORMAL, + (CurrentAV->Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ? true + : false); bitstring_set_bit(&bit_string, TRANSITION_TO_FAULT, - (CurrentAV-> - Event_Enable & EVENT_ENABLE_TO_FAULT) ? true : false); + (CurrentAV->Event_Enable & EVENT_ENABLE_TO_FAULT) + ? true + : false); bitstring_set_bit(&bit_string, TRANSITION_TO_NORMAL, - (CurrentAV-> - Event_Enable & EVENT_ENABLE_TO_NORMAL) ? true : false); + (CurrentAV->Event_Enable & EVENT_ENABLE_TO_NORMAL) + ? true + : false); apdu_len = encode_application_bitstring(&apdu[0], &bit_string); break; case PROP_ACKED_TRANSITIONS: bitstring_init(&bit_string); - bitstring_set_bit(&bit_string, TRANSITION_TO_OFFNORMAL, - CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL]. - bIsAcked); - bitstring_set_bit(&bit_string, TRANSITION_TO_FAULT, + bitstring_set_bit( + &bit_string, TRANSITION_TO_OFFNORMAL, + CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked); + bitstring_set_bit( + &bit_string, TRANSITION_TO_FAULT, CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked); - bitstring_set_bit(&bit_string, TRANSITION_TO_NORMAL, + bitstring_set_bit( + &bit_string, TRANSITION_TO_NORMAL, CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked); apdu_len = encode_application_bitstring(&apdu[0], &bit_string); break; case PROP_NOTIFY_TYPE: - apdu_len = - encode_application_enumerated(&apdu[0], - CurrentAV->Notify_Type ? NOTIFY_EVENT : NOTIFY_ALARM); + apdu_len = encode_application_enumerated( + &apdu[0], CurrentAV->Notify_Type ? NOTIFY_EVENT : NOTIFY_ALARM); break; case PROP_EVENT_TIME_STAMPS: /* Array element zero is the number of elements in the array */ if (rpdata->array_index == 0) - apdu_len = - encode_application_unsigned(&apdu[0], - MAX_BACNET_EVENT_TRANSITION); + apdu_len = encode_application_unsigned( + &apdu[0], MAX_BACNET_EVENT_TRANSITION); /* if no index was specified, then try to encode the entire list */ /* into one packet. */ else if (rpdata->array_index == BACNET_ARRAY_ALL) { for (i = 0; i < MAX_BACNET_EVENT_TRANSITION; i++) { - len = - encode_opening_tag(&apdu[apdu_len], - TIME_STAMP_DATETIME); - len += - encode_application_date(&apdu[apdu_len + len], + len = encode_opening_tag(&apdu[apdu_len], + TIME_STAMP_DATETIME); + len += encode_application_date( + &apdu[apdu_len + len], &CurrentAV->Event_Time_Stamps[i].date); - len += - encode_application_time(&apdu[apdu_len + len], + len += encode_application_time( + &apdu[apdu_len + len], &CurrentAV->Event_Time_Stamps[i].time); - len += - encode_closing_tag(&apdu[apdu_len + len], - TIME_STAMP_DATETIME); + len += encode_closing_tag(&apdu[apdu_len + len], + TIME_STAMP_DATETIME); /* add it if we have room */ if ((apdu_len + len) < MAX_APDU) @@ -607,11 +574,11 @@ int Analog_Value_Read_Property( } else if (rpdata->array_index <= MAX_BACNET_EVENT_TRANSITION) { apdu_len = encode_opening_tag(&apdu[apdu_len], TIME_STAMP_DATETIME); - apdu_len += - encode_application_date(&apdu[apdu_len], + apdu_len += encode_application_date( + &apdu[apdu_len], &CurrentAV->Event_Time_Stamps[rpdata->array_index].date); - apdu_len += - encode_application_time(&apdu[apdu_len], + apdu_len += encode_application_time( + &apdu[apdu_len], &CurrentAV->Event_Time_Stamps[rpdata->array_index].time); apdu_len += encode_closing_tag(&apdu[apdu_len], TIME_STAMP_DATETIME); @@ -642,19 +609,17 @@ int Analog_Value_Read_Property( } /* returns true if successful */ -bool Analog_Value_Write_Property( - BACNET_WRITE_PROPERTY_DATA * wp_data) +bool Analog_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data) { - bool status = false; /* return value */ + bool status = false; /* return value */ unsigned int object_index = 0; int len = 0; BACNET_APPLICATION_DATA_VALUE value; ANALOG_VALUE_DESCR *CurrentAV; /* decode the some of the request */ - len = - bacapp_decode_application_data(wp_data->application_data, - wp_data->application_data_len, &value); + len = bacapp_decode_application_data(wp_data->application_data, + wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ if (len < 0) { /* error while decoding - a value larger than we can handle */ @@ -683,7 +648,8 @@ bool Analog_Value_Write_Property( algorithm and may not be used for other purposes in any object. */ if (Analog_Value_Present_Value_Set(wp_data->object_instance, - value.type.Real, wp_data->priority)) { + value.type.Real, + wp_data->priority)) { status = true; } else if (wp_data->priority == 6) { /* Command priority 6 is reserved for use by Minimum On/Off @@ -705,7 +671,7 @@ bool Analog_Value_Write_Property( case PROP_OUT_OF_SERVICE: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { CurrentAV->Out_Of_Service = value.type.Boolean; } @@ -714,7 +680,7 @@ bool Analog_Value_Write_Property( case PROP_UNITS: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_ENUMERATED, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { CurrentAV->Units = value.type.Enumerated; } @@ -723,12 +689,11 @@ bool Analog_Value_Write_Property( case PROP_COV_INCREMENT: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_REAL, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { if (value.type.Real >= 0.0) { - Analog_Value_COV_Increment_Set( - wp_data->object_instance, - value.type.Real); + Analog_Value_COV_Increment_Set(wp_data->object_instance, + value.type.Real); } else { status = false; wp_data->error_class = ERROR_CLASS_PROPERTY; @@ -741,7 +706,7 @@ bool Analog_Value_Write_Property( case PROP_TIME_DELAY: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { CurrentAV->Time_Delay = value.type.Unsigned_Int; @@ -752,7 +717,7 @@ bool Analog_Value_Write_Property( case PROP_NOTIFICATION_CLASS: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { CurrentAV->Notification_Class = value.type.Unsigned_Int; @@ -762,7 +727,7 @@ bool Analog_Value_Write_Property( case PROP_HIGH_LIMIT: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_REAL, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { CurrentAV->High_Limit = value.type.Real; @@ -772,7 +737,7 @@ bool Analog_Value_Write_Property( case PROP_LOW_LIMIT: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_REAL, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { CurrentAV->Low_Limit = value.type.Real; @@ -782,7 +747,7 @@ bool Analog_Value_Write_Property( case PROP_DEADBAND: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_REAL, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { CurrentAV->Deadband = value.type.Real; @@ -792,7 +757,7 @@ bool Analog_Value_Write_Property( case PROP_LIMIT_ENABLE: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_BIT_STRING, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { if (value.type.Bit_String.bits_used == 2) { @@ -808,7 +773,7 @@ bool Analog_Value_Write_Property( case PROP_EVENT_ENABLE: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_BIT_STRING, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { if (value.type.Bit_String.bits_used == 3) { @@ -824,10 +789,10 @@ bool Analog_Value_Write_Property( case PROP_NOTIFY_TYPE: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_ENUMERATED, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { - switch ((BACNET_NOTIFY_TYPE) value.type.Enumerated) { + switch ((BACNET_NOTIFY_TYPE)value.type.Enumerated) { case NOTIFY_EVENT: CurrentAV->Notify_Type = 1; break; @@ -867,9 +832,7 @@ bool Analog_Value_Write_Property( return status; } - -void Analog_Value_Intrinsic_Reporting( - uint32_t object_instance) +void Analog_Value_Intrinsic_Reporting(uint32_t object_instance) { #if defined(INTRINSIC_REPORTING) BACNET_EVENT_NOTIFICATION_DATA event_data; @@ -882,7 +845,6 @@ void Analog_Value_Intrinsic_Reporting( float PresentVal = 0.0f; bool SendNotify = false; - object_index = Analog_Value_Instance_To_Index(object_instance); if (object_index < MAX_ANALOG_VALUES) CurrentAV = &AV_Descr[object_index]; @@ -893,7 +855,6 @@ void Analog_Value_Intrinsic_Reporting( if (!CurrentAV->Limit_Enable) return; /* limits are not configured */ - if (CurrentAV->Ack_notify_data.bSendAckNotify) { /* clean bSendAckNotify flag */ CurrentAV->Ack_notify_data.bSendAckNotify = false; @@ -902,7 +863,7 @@ void Analog_Value_Intrinsic_Reporting( #if PRINT_ENABLED fprintf(stderr, "Send Acknotification for (%s,%d).\n", - bactext_object_type_name(OBJECT_ANALOG_VALUE), object_instance); + bactext_object_type_name(OBJECT_ANALOG_VALUE), object_instance); #endif /* PRINT_ENABLED */ characterstring_init_ansi(&msgText, "AckNotification"); @@ -919,15 +880,17 @@ void Analog_Value_Intrinsic_Reporting( switch (CurrentAV->Event_State) { case EVENT_STATE_NORMAL: /* A TO-OFFNORMAL event is generated under these conditions: - (a) the Present_Value must exceed the High_Limit for a minimum - period of time, specified in the Time_Delay property, and - (b) the HighLimitEnable flag must be set in the Limit_Enable property, and - (c) the TO-OFFNORMAL flag must be set in the Event_Enable property. */ + (a) the Present_Value must exceed the High_Limit for a + minimum period of time, specified in the Time_Delay property, + and (b) the HighLimitEnable flag must be set in the + Limit_Enable property, and + (c) the TO-OFFNORMAL flag must be set in the Event_Enable + property. */ if ((PresentVal > CurrentAV->High_Limit) && ((CurrentAV->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) == - EVENT_HIGH_LIMIT_ENABLE) && + EVENT_HIGH_LIMIT_ENABLE) && ((CurrentAV->Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) == - EVENT_ENABLE_TO_OFFNORMAL)) { + EVENT_ENABLE_TO_OFFNORMAL)) { if (!CurrentAV->Remaining_Time_Delay) CurrentAV->Event_State = EVENT_STATE_HIGH_LIMIT; else @@ -936,15 +899,17 @@ void Analog_Value_Intrinsic_Reporting( } /* A TO-OFFNORMAL event is generated under these conditions: - (a) the Present_Value must exceed the Low_Limit plus the Deadband - for a minimum period of time, specified in the Time_Delay property, and - (b) the LowLimitEnable flag must be set in the Limit_Enable property, and - (c) the TO-NORMAL flag must be set in the Event_Enable property. */ + (a) the Present_Value must exceed the Low_Limit plus the + Deadband for a minimum period of time, specified in the + Time_Delay property, and (b) the LowLimitEnable flag must be + set in the Limit_Enable property, and + (c) the TO-NORMAL flag must be set in the Event_Enable + property. */ if ((PresentVal < CurrentAV->Low_Limit) && ((CurrentAV->Limit_Enable & EVENT_LOW_LIMIT_ENABLE) == - EVENT_LOW_LIMIT_ENABLE) && + EVENT_LOW_LIMIT_ENABLE) && ((CurrentAV->Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) == - EVENT_ENABLE_TO_OFFNORMAL)) { + EVENT_ENABLE_TO_OFFNORMAL)) { if (!CurrentAV->Remaining_Time_Delay) CurrentAV->Event_State = EVENT_STATE_LOW_LIMIT; else @@ -956,17 +921,20 @@ void Analog_Value_Intrinsic_Reporting( break; case EVENT_STATE_HIGH_LIMIT: - /* Once exceeded, the Present_Value must fall below the High_Limit minus - the Deadband before a TO-NORMAL event is generated under these conditions: - (a) the Present_Value must fall below the High_Limit minus the Deadband - for a minimum period of time, specified in the Time_Delay property, and - (b) the HighLimitEnable flag must be set in the Limit_Enable property, and - (c) the TO-NORMAL flag must be set in the Event_Enable property. */ - if ((PresentVal < CurrentAV->High_Limit - CurrentAV->Deadband) - && ((CurrentAV->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) == - EVENT_HIGH_LIMIT_ENABLE) && + /* Once exceeded, the Present_Value must fall below the + High_Limit minus the Deadband before a TO-NORMAL event is + generated under these conditions: (a) the Present_Value must + fall below the High_Limit minus the Deadband for a minimum + period of time, specified in the Time_Delay property, and (b) + the HighLimitEnable flag must be set in the Limit_Enable + property, and (c) the TO-NORMAL flag must be set in the + Event_Enable property. */ + if ((PresentVal < + CurrentAV->High_Limit - CurrentAV->Deadband) && + ((CurrentAV->Limit_Enable & EVENT_HIGH_LIMIT_ENABLE) == + EVENT_HIGH_LIMIT_ENABLE) && ((CurrentAV->Event_Enable & EVENT_ENABLE_TO_NORMAL) == - EVENT_ENABLE_TO_NORMAL)) { + EVENT_ENABLE_TO_NORMAL)) { if (!CurrentAV->Remaining_Time_Delay) CurrentAV->Event_State = EVENT_STATE_NORMAL; else @@ -981,15 +949,17 @@ void Analog_Value_Intrinsic_Reporting( /* Once the Present_Value has fallen below the Low_Limit, the Present_Value must exceed the Low_Limit plus the Deadband before a TO-NORMAL event is generated under these conditions: - (a) the Present_Value must exceed the Low_Limit plus the Deadband - for a minimum period of time, specified in the Time_Delay property, and - (b) the LowLimitEnable flag must be set in the Limit_Enable property, and - (c) the TO-NORMAL flag must be set in the Event_Enable property. */ - if ((PresentVal > CurrentAV->Low_Limit + CurrentAV->Deadband) - && ((CurrentAV->Limit_Enable & EVENT_LOW_LIMIT_ENABLE) == - EVENT_LOW_LIMIT_ENABLE) && + (a) the Present_Value must exceed the Low_Limit plus the + Deadband for a minimum period of time, specified in the + Time_Delay property, and (b) the LowLimitEnable flag must be + set in the Limit_Enable property, and + (c) the TO-NORMAL flag must be set in the Event_Enable + property. */ + if ((PresentVal > CurrentAV->Low_Limit + CurrentAV->Deadband) && + ((CurrentAV->Limit_Enable & EVENT_LOW_LIMIT_ENABLE) == + EVENT_LOW_LIMIT_ENABLE) && ((CurrentAV->Event_Enable & EVENT_ENABLE_TO_NORMAL) == - EVENT_ENABLE_TO_NORMAL)) { + EVENT_ENABLE_TO_NORMAL)) { if (!CurrentAV->Remaining_Time_Delay) CurrentAV->Event_State = EVENT_STATE_NORMAL; else @@ -1002,7 +972,7 @@ void Analog_Value_Intrinsic_Reporting( default: return; /* shouldn't happen */ - } /* switch (FromState) */ + } /* switch (FromState) */ ToState = CurrentAV->Event_State; @@ -1025,25 +995,25 @@ void Analog_Value_Intrinsic_Reporting( case EVENT_STATE_NORMAL: if (FromState == EVENT_STATE_HIGH_LIMIT) { ExceededLimit = CurrentAV->High_Limit; - characterstring_init_ansi(&msgText, - "Back to normal state from high limit"); + characterstring_init_ansi( + &msgText, "Back to normal state from high limit"); } else { ExceededLimit = CurrentAV->Low_Limit; - characterstring_init_ansi(&msgText, - "Back to normal state from low limit"); + characterstring_init_ansi( + &msgText, "Back to normal state from low limit"); } break; default: ExceededLimit = 0; break; - } /* switch (ToState) */ + } /* switch (ToState) */ #if PRINT_ENABLED fprintf(stderr, "Event_State for (%s,%d) goes from %s to %s.\n", - bactext_object_type_name(OBJECT_ANALOG_VALUE), object_instance, - bactext_event_state_name(FromState), - bactext_event_state_name(ToState)); + bactext_object_type_name(OBJECT_ANALOG_VALUE), + object_instance, bactext_event_state_name(FromState), + bactext_event_state_name(ToState)); #endif /* PRINT_ENABLED */ /* Notify Type */ @@ -1054,7 +1024,6 @@ void Analog_Value_Intrinsic_Reporting( } } - if (SendNotify) { /* Event Object Identifier */ event_data.eventObjectIdentifier.type = OBJECT_ANALOG_VALUE; @@ -1110,18 +1079,20 @@ void Analog_Value_Intrinsic_Reporting( event_data.notificationParams.outOfRange.exceedingValue = PresentVal; /* Status_Flags of the referenced object. */ - bitstring_init(&event_data.notificationParams.outOfRange. - statusFlags); - bitstring_set_bit(&event_data.notificationParams.outOfRange. - statusFlags, STATUS_FLAG_IN_ALARM, - CurrentAV->Event_State ? true : false); - bitstring_set_bit(&event_data.notificationParams.outOfRange. - statusFlags, STATUS_FLAG_FAULT, false); - bitstring_set_bit(&event_data.notificationParams.outOfRange. - statusFlags, STATUS_FLAG_OVERRIDDEN, false); - bitstring_set_bit(&event_data.notificationParams.outOfRange. - statusFlags, STATUS_FLAG_OUT_OF_SERVICE, - CurrentAV->Out_Of_Service); + bitstring_init( + &event_data.notificationParams.outOfRange.statusFlags); + bitstring_set_bit( + &event_data.notificationParams.outOfRange.statusFlags, + STATUS_FLAG_IN_ALARM, CurrentAV->Event_State ? true : false); + bitstring_set_bit( + &event_data.notificationParams.outOfRange.statusFlags, + STATUS_FLAG_FAULT, false); + bitstring_set_bit( + &event_data.notificationParams.outOfRange.statusFlags, + STATUS_FLAG_OVERRIDDEN, false); + bitstring_set_bit( + &event_data.notificationParams.outOfRange.statusFlags, + STATUS_FLAG_OUT_OF_SERVICE, CurrentAV->Out_Of_Service); /* Deadband used for limit checking. */ event_data.notificationParams.outOfRange.deadband = CurrentAV->Deadband; @@ -1140,24 +1111,24 @@ void Analog_Value_Intrinsic_Reporting( case EVENT_STATE_OFFNORMAL: case EVENT_STATE_HIGH_LIMIT: case EVENT_STATE_LOW_LIMIT: - CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL]. - bIsAcked = false; - CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL]. - Time_Stamp = event_data.timeStamp.value.dateTime; + CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL] + .bIsAcked = false; + CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL] + .Time_Stamp = event_data.timeStamp.value.dateTime; break; case EVENT_STATE_FAULT: - CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT]. - bIsAcked = false; - CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT]. - Time_Stamp = event_data.timeStamp.value.dateTime; + CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked = + false; + CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT] + .Time_Stamp = event_data.timeStamp.value.dateTime; break; case EVENT_STATE_NORMAL: - CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL]. - bIsAcked = false; - CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL]. - Time_Stamp = event_data.timeStamp.value.dateTime; + CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL] + .bIsAcked = false; + CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL] + .Time_Stamp = event_data.timeStamp.value.dateTime; break; } } @@ -1165,17 +1136,14 @@ void Analog_Value_Intrinsic_Reporting( #endif /* defined(INTRINSIC_REPORTING) */ } - #if defined(INTRINSIC_REPORTING) int Analog_Value_Event_Information( - unsigned index, - BACNET_GET_EVENT_INFORMATION_DATA * getevent_data) + unsigned index, BACNET_GET_EVENT_INFORMATION_DATA *getevent_data) { bool IsNotAckedTransitions; bool IsActiveEvent; int i; - /* check index */ if (index < MAX_ANALOG_VALUES) { /* Event_State not equal to NORMAL */ @@ -1184,14 +1152,15 @@ int Analog_Value_Event_Information( /* Acked_Transitions property, which has at least one of the bits (TO-OFFNORMAL, TO-FAULT, TONORMAL) set to FALSE. */ IsNotAckedTransitions = - (AV_Descr[index].Acked_Transitions[TRANSITION_TO_OFFNORMAL]. - bIsAcked == - false) | (AV_Descr[index].Acked_Transitions[TRANSITION_TO_FAULT]. - bIsAcked == - false) | (AV_Descr[index].Acked_Transitions[TRANSITION_TO_NORMAL]. - bIsAcked == false); + (AV_Descr[index] + .Acked_Transitions[TRANSITION_TO_OFFNORMAL] + .bIsAcked == false) | + (AV_Descr[index].Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked == + false) | + (AV_Descr[index].Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked == + false); } else - return -1; /* end of list */ + return -1; /* end of list */ if ((IsActiveEvent) || (IsNotAckedTransitions)) { /* Object Identifier */ @@ -1203,14 +1172,15 @@ int Analog_Value_Event_Information( /* Acknowledged Transitions */ bitstring_init(&getevent_data->acknowledgedTransitions); bitstring_set_bit(&getevent_data->acknowledgedTransitions, - TRANSITION_TO_OFFNORMAL, - AV_Descr[index].Acked_Transitions[TRANSITION_TO_OFFNORMAL]. - bIsAcked); - bitstring_set_bit(&getevent_data->acknowledgedTransitions, - TRANSITION_TO_FAULT, + TRANSITION_TO_OFFNORMAL, + AV_Descr[index] + .Acked_Transitions[TRANSITION_TO_OFFNORMAL] + .bIsAcked); + bitstring_set_bit( + &getevent_data->acknowledgedTransitions, TRANSITION_TO_FAULT, AV_Descr[index].Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked); - bitstring_set_bit(&getevent_data->acknowledgedTransitions, - TRANSITION_TO_NORMAL, + bitstring_set_bit( + &getevent_data->acknowledgedTransitions, TRANSITION_TO_NORMAL, AV_Descr[index].Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked); /* Event Time Stamps */ for (i = 0; i < 3; i++) { @@ -1222,35 +1192,35 @@ int Analog_Value_Event_Information( getevent_data->notifyType = AV_Descr[index].Notify_Type; /* Event Enable */ bitstring_init(&getevent_data->eventEnable); - bitstring_set_bit(&getevent_data->eventEnable, TRANSITION_TO_OFFNORMAL, - (AV_Descr[index]. - Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ? true : false); + bitstring_set_bit( + &getevent_data->eventEnable, TRANSITION_TO_OFFNORMAL, + (AV_Descr[index].Event_Enable & EVENT_ENABLE_TO_OFFNORMAL) ? true + : false); bitstring_set_bit(&getevent_data->eventEnable, TRANSITION_TO_FAULT, - (AV_Descr[index]. - Event_Enable & EVENT_ENABLE_TO_FAULT) ? true : false); - bitstring_set_bit(&getevent_data->eventEnable, TRANSITION_TO_NORMAL, - (AV_Descr[index]. - Event_Enable & EVENT_ENABLE_TO_NORMAL) ? true : false); + (AV_Descr[index].Event_Enable & EVENT_ENABLE_TO_FAULT) + ? true + : false); + bitstring_set_bit( + &getevent_data->eventEnable, TRANSITION_TO_NORMAL, + (AV_Descr[index].Event_Enable & EVENT_ENABLE_TO_NORMAL) ? true + : false); /* Event Priorities */ Notification_Class_Get_Priorities(AV_Descr[index].Notification_Class, - getevent_data->eventPriorities); + getevent_data->eventPriorities); - return 1; /* active event */ + return 1; /* active event */ } else - return 0; /* no active event at this index */ + return 0; /* no active event at this index */ } -int Analog_Value_Alarm_Ack( - BACNET_ALARM_ACK_DATA * alarmack_data, - BACNET_ERROR_CODE * error_code) +int Analog_Value_Alarm_Ack(BACNET_ALARM_ACK_DATA *alarmack_data, + BACNET_ERROR_CODE *error_code) { ANALOG_VALUE_DESCR *CurrentAV; unsigned int object_index; - - object_index = - Analog_Value_Instance_To_Index(alarmack_data->eventObjectIdentifier. - instance); + object_index = Analog_Value_Instance_To_Index( + alarmack_data->eventObjectIdentifier.instance); if (object_index < MAX_ANALOG_VALUES) CurrentAV = &AV_Descr[object_index]; @@ -1263,22 +1233,23 @@ int Analog_Value_Alarm_Ack( case EVENT_STATE_OFFNORMAL: case EVENT_STATE_HIGH_LIMIT: case EVENT_STATE_LOW_LIMIT: - if (CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL]. - bIsAcked == false) { + if (CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL] + .bIsAcked == false) { if (alarmack_data->eventTimeStamp.tag != TIME_STAMP_DATETIME) { *error_code = ERROR_CODE_INVALID_TIME_STAMP; return -1; } - if (datetime_compare(&CurrentAV-> - Acked_Transitions[TRANSITION_TO_OFFNORMAL].Time_Stamp, + if (datetime_compare( + &CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL] + .Time_Stamp, &alarmack_data->eventTimeStamp.value.dateTime) > 0) { *error_code = ERROR_CODE_INVALID_TIME_STAMP; return -1; } /* Clean transitions flag. */ - CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL]. - bIsAcked = true; + CurrentAV->Acked_Transitions[TRANSITION_TO_OFFNORMAL].bIsAcked = + true; } else { *error_code = ERROR_CODE_INVALID_EVENT_STATE; return -1; @@ -1292,8 +1263,9 @@ int Analog_Value_Alarm_Ack( *error_code = ERROR_CODE_INVALID_TIME_STAMP; return -1; } - if (datetime_compare(&CurrentAV-> - Acked_Transitions[TRANSITION_TO_NORMAL].Time_Stamp, + if (datetime_compare( + &CurrentAV->Acked_Transitions[TRANSITION_TO_NORMAL] + .Time_Stamp, &alarmack_data->eventTimeStamp.value.dateTime) > 0) { *error_code = ERROR_CODE_INVALID_TIME_STAMP; return -1; @@ -1315,8 +1287,9 @@ int Analog_Value_Alarm_Ack( *error_code = ERROR_CODE_INVALID_TIME_STAMP; return -1; } - if (datetime_compare(&CurrentAV-> - Acked_Transitions[TRANSITION_TO_FAULT].Time_Stamp, + if (datetime_compare( + &CurrentAV->Acked_Transitions[TRANSITION_TO_FAULT] + .Time_Stamp, &alarmack_data->eventTimeStamp.value.dateTime) > 0) { *error_code = ERROR_CODE_INVALID_TIME_STAMP; return -1; @@ -1343,11 +1316,9 @@ int Analog_Value_Alarm_Ack( return 1; } -int Analog_Value_Alarm_Summary( - unsigned index, - BACNET_GET_ALARM_SUMMARY_DATA * getalarm_data) +int Analog_Value_Alarm_Summary(unsigned index, + BACNET_GET_ALARM_SUMMARY_DATA *getalarm_data) { - /* check index */ if (index < MAX_ANALOG_VALUES) { /* Event_State is not equal to NORMAL and @@ -1363,37 +1334,37 @@ int Analog_Value_Alarm_Summary( /* Acknowledged Transitions */ bitstring_init(&getalarm_data->acknowledgedTransitions); bitstring_set_bit(&getalarm_data->acknowledgedTransitions, - TRANSITION_TO_OFFNORMAL, - AV_Descr[index].Acked_Transitions[TRANSITION_TO_OFFNORMAL]. - bIsAcked); + TRANSITION_TO_OFFNORMAL, + AV_Descr[index] + .Acked_Transitions[TRANSITION_TO_OFFNORMAL] + .bIsAcked); bitstring_set_bit(&getalarm_data->acknowledgedTransitions, - TRANSITION_TO_FAULT, - AV_Descr[index]. - Acked_Transitions[TRANSITION_TO_FAULT].bIsAcked); + TRANSITION_TO_FAULT, + AV_Descr[index] + .Acked_Transitions[TRANSITION_TO_FAULT] + .bIsAcked); bitstring_set_bit(&getalarm_data->acknowledgedTransitions, - TRANSITION_TO_NORMAL, - AV_Descr[index]. - Acked_Transitions[TRANSITION_TO_NORMAL].bIsAcked); + TRANSITION_TO_NORMAL, + AV_Descr[index] + .Acked_Transitions[TRANSITION_TO_NORMAL] + .bIsAcked); - return 1; /* active alarm */ + return 1; /* active alarm */ } else - return 0; /* no active alarm at this index */ + return 0; /* no active alarm at this index */ } else - return -1; /* end of list */ + return -1; /* end of list */ } #endif /* defined(INTRINSIC_REPORTING) */ - #ifdef TEST #include #include #include "ctest.h" -bool WPValidateArgType( - BACNET_APPLICATION_DATA_VALUE * pValue, - uint8_t ucExpectedTag, - BACNET_ERROR_CLASS * pErrorClass, - BACNET_ERROR_CODE * pErrorCode) +bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue, + uint8_t ucExpectedTag, BACNET_ERROR_CLASS *pErrorClass, + BACNET_ERROR_CODE *pErrorCode) { pValue = pValue; ucExpectedTag = ucExpectedTag; @@ -1403,11 +1374,10 @@ bool WPValidateArgType( return false; } -void testAnalog_Value( - Test * pTest) +void testAnalog_Value(Test *pTest) { BACNET_READ_PROPERTY_DATA rpdata; - uint8_t apdu[MAX_APDU] = { 0 }; + uint8_t apdu[MAX_APDU] = {0}; int len = 0; uint32_t len_value = 0; uint8_t tag_number = 0; @@ -1433,8 +1403,7 @@ void testAnalog_Value( } #ifdef TEST_ANALOG_VALUE -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -1446,7 +1415,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/demo/object/bacfile.c b/demo/object/bacfile.c index 002a281f..8255677a 100644 --- a/demo/object/bacfile.c +++ b/demo/object/bacfile.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2005 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2005 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -57,36 +57,27 @@ static BACNET_FILE_LISTING BACnet_File_Listing[] = { {0, "temp_0.txt"}, {1, "temp_1.txt"}, {2, "temp_2.txt"}, - {0, NULL} /* last file indication */ + {0, NULL} /* last file indication */ }; /* These three arrays are used by the ReadPropertyMultiple handler */ -static const int bacfile_Properties_Required[] = { - PROP_OBJECT_IDENTIFIER, - PROP_OBJECT_NAME, - PROP_OBJECT_TYPE, - PROP_FILE_TYPE, - PROP_FILE_SIZE, - PROP_MODIFICATION_DATE, - PROP_ARCHIVE, - PROP_READ_ONLY, - PROP_FILE_ACCESS_METHOD, - -1 -}; +static const int bacfile_Properties_Required[] = {PROP_OBJECT_IDENTIFIER, + PROP_OBJECT_NAME, + PROP_OBJECT_TYPE, + PROP_FILE_TYPE, + PROP_FILE_SIZE, + PROP_MODIFICATION_DATE, + PROP_ARCHIVE, + PROP_READ_ONLY, + PROP_FILE_ACCESS_METHOD, + -1}; -static const int bacfile_Properties_Optional[] = { - PROP_DESCRIPTION, - -1 -}; +static const int bacfile_Properties_Optional[] = {PROP_DESCRIPTION, -1}; -static const int bacfile_Properties_Proprietary[] = { - -1 -}; +static const int bacfile_Properties_Proprietary[] = {-1}; -void BACfile_Property_Lists( - const int **pRequired, - const int **pOptional, - const int **pProprietary) +void BACfile_Property_Lists(const int **pRequired, const int **pOptional, + const int **pProprietary) { if (pRequired) *pRequired = bacfile_Properties_Required; @@ -98,8 +89,7 @@ void BACfile_Property_Lists( return; } -static char *bacfile_name( - uint32_t instance) +static char *bacfile_name(uint32_t instance) { uint32_t index = 0; char *filename = NULL; @@ -116,9 +106,8 @@ static char *bacfile_name( return filename; } -bool bacfile_object_name( - uint32_t instance, - BACNET_CHARACTER_STRING * object_name) +bool bacfile_object_name(uint32_t instance, + BACNET_CHARACTER_STRING *object_name) { bool status = false; char *filename = NULL; @@ -131,14 +120,12 @@ bool bacfile_object_name( return status; } -bool bacfile_valid_instance( - uint32_t object_instance) +bool bacfile_valid_instance(uint32_t object_instance) { return bacfile_name(object_instance) ? true : false; } -uint32_t bacfile_count( - void) +uint32_t bacfile_count(void) { uint32_t index = 0; @@ -150,8 +137,7 @@ uint32_t bacfile_count( return index; } -uint32_t bacfile_index_to_instance( - unsigned find_index) +uint32_t bacfile_index_to_instance(unsigned find_index) { uint32_t instance = BACNET_MAX_INSTANCE + 1; uint32_t index = 0; @@ -168,8 +154,7 @@ uint32_t bacfile_index_to_instance( return instance; } -static long fsize( - FILE * pFile) +static long fsize(FILE *pFile) { long size = 0; long origin = 0; @@ -183,8 +168,7 @@ static long fsize( return (size); } -unsigned bacfile_file_size( - uint32_t object_instance) +unsigned bacfile_file_size(uint32_t object_instance) { char *pFilename = NULL; FILE *pFile = NULL; @@ -203,11 +187,10 @@ unsigned bacfile_file_size( } /* return the number of bytes used, or -1 on error */ -int bacfile_read_property( - BACNET_READ_PROPERTY_DATA * rpdata) +int bacfile_read_property(BACNET_READ_PROPERTY_DATA *rpdata) { - int apdu_len = 0; /* return value */ - char text_string[32] = { "" }; + int apdu_len = 0; /* return value */ + char text_string[32] = {""}; BACNET_CHARACTER_STRING char_string; BACNET_DATE bdate; BACNET_TIME btime; @@ -220,13 +203,12 @@ int bacfile_read_property( apdu = rpdata->application_data; switch (rpdata->object_property) { case PROP_OBJECT_IDENTIFIER: - apdu_len = - encode_application_object_id(&apdu[0], OBJECT_FILE, - rpdata->object_instance); + apdu_len = encode_application_object_id(&apdu[0], OBJECT_FILE, + rpdata->object_instance); break; case PROP_OBJECT_NAME: sprintf(text_string, "FILE %lu", - (unsigned long) rpdata->object_instance); + (unsigned long)rpdata->object_instance); characterstring_init_ansi(&char_string, text_string); apdu_len = encode_application_character_string(&apdu[0], &char_string); @@ -236,7 +218,7 @@ int bacfile_read_property( break; case PROP_DESCRIPTION: characterstring_init_ansi(&char_string, - bacfile_name(rpdata->object_instance)); + bacfile_name(rpdata->object_instance)); apdu_len = encode_application_character_string(&apdu[0], &char_string); break; @@ -246,16 +228,15 @@ int bacfile_read_property( encode_application_character_string(&apdu[0], &char_string); break; case PROP_FILE_SIZE: - apdu_len = - encode_application_unsigned(&apdu[0], - bacfile_file_size(rpdata->object_instance)); + apdu_len = encode_application_unsigned( + &apdu[0], bacfile_file_size(rpdata->object_instance)); break; case PROP_MODIFICATION_DATE: /* FIXME: get the actual value instead of April Fool's Day */ - bdate.year = 2006; /* AD */ - bdate.month = 4; /* 1=Jan */ - bdate.day = 1; /* 1..31 */ - bdate.wday = 6; /* 1=Monday */ + bdate.year = 2006; /* AD */ + bdate.month = 4; /* 1=Jan */ + bdate.day = 1; /* 1..31 */ + bdate.wday = 6; /* 1=Monday */ apdu_len = encode_application_date(&apdu[0], &bdate); /* FIXME: get the actual value */ btime.hour = 7; @@ -280,9 +261,8 @@ int bacfile_read_property( apdu_len = encode_application_boolean(&apdu[0], true); break; case PROP_FILE_ACCESS_METHOD: - apdu_len = - encode_application_enumerated(&apdu[0], - FILE_RECORD_AND_STREAM_ACCESS); + apdu_len = encode_application_enumerated( + &apdu[0], FILE_RECORD_AND_STREAM_ACCESS); break; default: rpdata->error_class = ERROR_CLASS_PROPERTY; @@ -295,10 +275,9 @@ int bacfile_read_property( } /* returns true if successful */ -bool bacfile_write_property( - BACNET_WRITE_PROPERTY_DATA * wp_data) +bool bacfile_write_property(BACNET_WRITE_PROPERTY_DATA *wp_data) { - bool status = false; /* return value */ + bool status = false; /* return value */ int len = 0; BACNET_APPLICATION_DATA_VALUE value; @@ -314,9 +293,8 @@ bool bacfile_write_property( return false; } /* decode the some of the request */ - len = - bacapp_decode_application_data(wp_data->application_data, - wp_data->application_data_len, &value); + len = bacapp_decode_application_data(wp_data->application_data, + wp_data->application_data_len, &value); if (len < 0) { /* error while decoding - a value larger than we can handle */ wp_data->error_class = ERROR_CLASS_PROPERTY; @@ -334,7 +312,7 @@ bool bacfile_write_property( 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); + &wp_data->error_class, &wp_data->error_code); if (status) { if (value.type.Boolean) { /* FIXME: do something to wp_data->object_instance */ @@ -349,7 +327,7 @@ bool bacfile_write_property( shall be writable. */ status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { /* FIXME: do something with value.type.Unsigned to wp_data->object_instance */ @@ -375,8 +353,7 @@ bool bacfile_write_property( return status; } -uint32_t bacfile_instance( - char *filename) +uint32_t bacfile_instance(char *filename) { uint32_t index = 0; uint32_t instance = BACNET_MAX_INSTANCE + 1; @@ -399,36 +376,33 @@ uint32_t bacfile_instance( /* Another way would be to store the */ /* invokeID and file instance in a list or table */ /* when the request was sent */ -uint32_t bacfile_instance_from_tsm( - uint8_t invokeID) +uint32_t bacfile_instance_from_tsm(uint8_t invokeID) { - BACNET_NPDU_DATA npdu_data = { 0 }; /* dummy for getting npdu length */ - BACNET_CONFIRMED_SERVICE_DATA service_data = { 0 }; + BACNET_NPDU_DATA npdu_data = {0}; /* dummy for getting npdu length */ + BACNET_CONFIRMED_SERVICE_DATA service_data = {0}; uint8_t service_choice = 0; uint8_t *service_request = NULL; uint16_t service_request_len = 0; - BACNET_ADDRESS dest; /* where the original packet was destined */ - uint8_t apdu[MAX_PDU] = { 0 }; /* original APDU packet */ - uint16_t apdu_len = 0; /* original APDU packet length */ - int len = 0; /* apdu header length */ - BACNET_ATOMIC_READ_FILE_DATA data = { 0 }; + BACNET_ADDRESS dest; /* where the original packet was destined */ + uint8_t apdu[MAX_PDU] = {0}; /* original APDU packet */ + uint16_t apdu_len = 0; /* original APDU packet length */ + int len = 0; /* apdu header length */ + BACNET_ATOMIC_READ_FILE_DATA data = {0}; uint32_t object_instance = BACNET_MAX_INSTANCE + 1; /* return value */ bool found = false; - found = - tsm_get_transaction_pdu(invokeID, &dest, &npdu_data, &apdu[0], - &apdu_len); + found = tsm_get_transaction_pdu(invokeID, &dest, &npdu_data, &apdu[0], + &apdu_len); if (found) { - if (!npdu_data.network_layer_message && npdu_data.data_expecting_reply - && (apdu[0] == PDU_TYPE_CONFIRMED_SERVICE_REQUEST)) { - len = - apdu_decode_confirmed_service_request(&apdu[0], apdu_len, - &service_data, &service_choice, &service_request, - &service_request_len); + if (!npdu_data.network_layer_message && + npdu_data.data_expecting_reply && + (apdu[0] == PDU_TYPE_CONFIRMED_SERVICE_REQUEST)) { + len = apdu_decode_confirmed_service_request( + &apdu[0], apdu_len, &service_data, &service_choice, + &service_request, &service_request_len); if (service_choice == SERVICE_CONFIRMED_ATOMIC_READ_FILE) { - len = - arf_decode_service_request(service_request, - service_request_len, &data); + len = arf_decode_service_request(service_request, + service_request_len, &data); if (len > 0) { if (data.object_type == OBJECT_FILE) object_instance = data.object_instance; @@ -441,8 +415,7 @@ uint32_t bacfile_instance_from_tsm( } #endif -bool bacfile_read_stream_data( - BACNET_ATOMIC_READ_FILE_DATA * data) +bool bacfile_read_stream_data(BACNET_ATOMIC_READ_FILE_DATA *data) { char *pFilename = NULL; bool found = false; @@ -454,10 +427,9 @@ bool bacfile_read_stream_data( found = true; pFile = fopen(pFilename, "rb"); if (pFile) { - (void) fseek(pFile, data->type.stream.fileStartPosition, SEEK_SET); - len = - fread(octetstring_value(&data->fileData[0]), 1, - data->type.stream.requestedOctetCount, pFile); + (void)fseek(pFile, data->type.stream.fileStartPosition, SEEK_SET); + len = fread(octetstring_value(&data->fileData[0]), 1, + data->type.stream.requestedOctetCount, pFile); if (len < data->type.stream.requestedOctetCount) data->endOfFile = true; else @@ -476,8 +448,7 @@ bool bacfile_read_stream_data( return found; } -bool bacfile_write_stream_data( - BACNET_ATOMIC_WRITE_FILE_DATA * data) +bool bacfile_write_stream_data(BACNET_ATOMIC_WRITE_FILE_DATA *data) { char *pFilename = NULL; bool found = false; @@ -500,11 +471,11 @@ bool bacfile_write_stream_data( } if (pFile) { if (data->type.stream.fileStartPosition != -1) { - (void) fseek(pFile, data->type.stream.fileStartPosition, - SEEK_SET); + (void)fseek(pFile, data->type.stream.fileStartPosition, + SEEK_SET); } if (fwrite(octetstring_value(&data->fileData[0]), - octetstring_length(&data->fileData[0]), 1, pFile) != 1) { + octetstring_length(&data->fileData[0]), 1, pFile) != 1) { /* do something if it fails? */ } fclose(pFile); @@ -514,8 +485,7 @@ bool bacfile_write_stream_data( return found; } -bool bacfile_write_record_data( - BACNET_ATOMIC_WRITE_FILE_DATA * data) +bool bacfile_write_record_data(BACNET_ATOMIC_WRITE_FILE_DATA *data) { char *pFilename = NULL; bool found = false; @@ -542,7 +512,8 @@ bool bacfile_write_record_data( if (pFile) { if ((data->type.record.fileStartRecord != -1) && (data->type.record.fileStartRecord > 0)) { - for (i = 0; i < (uint32_t)data->type.record.fileStartRecord; i++) { + for (i = 0; i < (uint32_t)data->type.record.fileStartRecord; + i++) { pData = fgets(&dummy_data[0], sizeof(dummy_data), pFile); if ((pData == NULL) || feof(pFile)) { break; @@ -551,8 +522,8 @@ bool bacfile_write_record_data( } for (i = 0; i < data->type.record.returnedRecordCount; i++) { if (fwrite(octetstring_value(&data->fileData[i]), - octetstring_length(&data->fileData[i]), 1, - pFile) != 1) { + octetstring_length(&data->fileData[i]), 1, + pFile) != 1) { /* do something if it fails? */ } } @@ -563,9 +534,8 @@ bool bacfile_write_record_data( return found; } -bool bacfile_read_ack_stream_data( - uint32_t instance, - BACNET_ATOMIC_READ_FILE_DATA * data) +bool bacfile_read_ack_stream_data(uint32_t instance, + BACNET_ATOMIC_READ_FILE_DATA *data) { bool found = false; FILE *pFile = NULL; @@ -576,12 +546,12 @@ bool bacfile_read_ack_stream_data( found = true; pFile = fopen(pFilename, "rb"); if (pFile) { - (void) fseek(pFile, data->type.stream.fileStartPosition, SEEK_SET); + (void)fseek(pFile, data->type.stream.fileStartPosition, SEEK_SET); if (fwrite(octetstring_value(&data->fileData[0]), - octetstring_length(&data->fileData[0]), 1, pFile) != 1) { + octetstring_length(&data->fileData[0]), 1, pFile) != 1) { #if PRINT_ENABLED fprintf(stderr, "Failed to write to %s (%lu)!\n", pFilename, - (unsigned long) instance); + (unsigned long)instance); #endif } fclose(pFile); @@ -591,15 +561,14 @@ bool bacfile_read_ack_stream_data( return found; } -bool bacfile_read_ack_record_data( - uint32_t instance, - BACNET_ATOMIC_READ_FILE_DATA * data) +bool bacfile_read_ack_record_data(uint32_t instance, + BACNET_ATOMIC_READ_FILE_DATA *data) { bool found = false; FILE *pFile = NULL; char *pFilename = NULL; uint32_t i = 0; - char dummy_data[MAX_OCTET_STRING_BYTES] = { 0 }; + char dummy_data[MAX_OCTET_STRING_BYTES] = {0}; char *pData = NULL; pFilename = bacfile_name(instance); @@ -608,7 +577,8 @@ bool bacfile_read_ack_record_data( pFile = fopen(pFilename, "rb"); if (pFile) { if (data->type.record.fileStartRecord > 0) { - for (i = 0; i < (uint32_t)data->type.record.fileStartRecord; i++) { + for (i = 0; i < (uint32_t)data->type.record.fileStartRecord; + i++) { pData = fgets(&dummy_data[0], sizeof(dummy_data), pFile); if ((pData == NULL) || feof(pFile)) { break; @@ -617,11 +587,11 @@ bool bacfile_read_ack_record_data( } for (i = 0; i < data->type.record.RecordCount; i++) { if (fwrite(octetstring_value(&data->fileData[i]), - octetstring_length(&data->fileData[i]), 1, - pFile) != 1) { + octetstring_length(&data->fileData[i]), 1, + pFile) != 1) { #if PRINT_ENABLED - fprintf(stderr, "Failed to write to %s (%lu)!\n", - pFilename, (unsigned long) instance); + fprintf(stderr, "Failed to write to %s (%lu)!\n", pFilename, + (unsigned long)instance); #endif } } @@ -632,7 +602,6 @@ bool bacfile_read_ack_record_data( return found; } -void bacfile_init( - void) +void bacfile_init(void) { } diff --git a/demo/object/bi.c b/demo/object/bi.c index abe43906..b2f1a259 100644 --- a/demo/object/bi.c +++ b/demo/object/bi.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2006 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2006 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* Binary Input Objects customize for your use */ @@ -35,7 +35,7 @@ #include "rp.h" #include "wp.h" #include "cov.h" -#include "config.h" /* the custom stuff */ +#include "config.h" /* the custom stuff */ #include "bi.h" #include "handlers.h" @@ -54,30 +54,16 @@ static BACNET_POLARITY Polarity[MAX_BINARY_INPUTS]; /* These three arrays are used by the ReadPropertyMultiple handler */ static const int Binary_Input_Properties_Required[] = { - PROP_OBJECT_IDENTIFIER, - PROP_OBJECT_NAME, - PROP_OBJECT_TYPE, - PROP_PRESENT_VALUE, - PROP_STATUS_FLAGS, - PROP_EVENT_STATE, - PROP_OUT_OF_SERVICE, - PROP_POLARITY, - -1 -}; + PROP_OBJECT_IDENTIFIER, PROP_OBJECT_NAME, PROP_OBJECT_TYPE, + PROP_PRESENT_VALUE, PROP_STATUS_FLAGS, PROP_EVENT_STATE, + PROP_OUT_OF_SERVICE, PROP_POLARITY, -1}; -static const int Binary_Input_Properties_Optional[] = { - PROP_DESCRIPTION, - -1 -}; +static const int Binary_Input_Properties_Optional[] = {PROP_DESCRIPTION, -1}; -static const int Binary_Input_Properties_Proprietary[] = { - -1 -}; +static const int Binary_Input_Properties_Proprietary[] = {-1}; -void Binary_Input_Property_Lists( - const int **pRequired, - const int **pOptional, - const int **pProprietary) +void Binary_Input_Property_Lists(const int **pRequired, const int **pOptional, + const int **pProprietary) { if (pRequired) { *pRequired = Binary_Input_Properties_Required; @@ -95,8 +81,7 @@ void Binary_Input_Property_Lists( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need validate that the */ /* given instance exists */ -bool Binary_Input_Valid_Instance( - uint32_t object_instance) +bool Binary_Input_Valid_Instance(uint32_t object_instance) { if (object_instance < MAX_BINARY_INPUTS) { return true; @@ -107,8 +92,7 @@ bool Binary_Input_Valid_Instance( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then count how many you have */ -unsigned Binary_Input_Count( - void) +unsigned Binary_Input_Count(void) { return MAX_BINARY_INPUTS; } @@ -116,14 +100,12 @@ unsigned Binary_Input_Count( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need to return the instance */ /* that correlates to the correct index */ -uint32_t Binary_Input_Index_To_Instance( - unsigned index) +uint32_t Binary_Input_Index_To_Instance(unsigned index) { return index; } -void Binary_Input_Init( - void) +void Binary_Input_Init(void) { static bool initialized = false; unsigned i; @@ -143,8 +125,7 @@ void Binary_Input_Init( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need to return the index */ /* that correlates to the correct instance number */ -unsigned Binary_Input_Instance_To_Index( - uint32_t object_instance) +unsigned Binary_Input_Instance_To_Index(uint32_t object_instance) { unsigned index = MAX_BINARY_INPUTS; @@ -155,8 +136,7 @@ unsigned Binary_Input_Instance_To_Index( return index; } -BACNET_BINARY_PV Binary_Input_Present_Value( - uint32_t object_instance) +BACNET_BINARY_PV Binary_Input_Present_Value(uint32_t object_instance) { BACNET_BINARY_PV value = BINARY_INACTIVE; unsigned index = 0; @@ -176,8 +156,7 @@ BACNET_BINARY_PV Binary_Input_Present_Value( return value; } -bool Binary_Input_Out_Of_Service( - uint32_t object_instance) +bool Binary_Input_Out_Of_Service(uint32_t object_instance) { bool value = false; unsigned index = 0; @@ -190,8 +169,7 @@ bool Binary_Input_Out_Of_Service( return value; } -bool Binary_Input_Change_Of_Value( - uint32_t object_instance) +bool Binary_Input_Change_Of_Value(uint32_t object_instance) { bool status = false; unsigned index; @@ -204,8 +182,7 @@ bool Binary_Input_Change_Of_Value( return status; } -void Binary_Input_Change_Of_Value_Clear( - uint32_t object_instance) +void Binary_Input_Change_Of_Value_Clear(uint32_t object_instance) { unsigned index; @@ -225,9 +202,8 @@ void Binary_Input_Change_Of_Value_Clear( * * @return true if the value list is encoded */ -bool Binary_Input_Encode_Value_List( - uint32_t object_instance, - BACNET_PROPERTY_VALUE * value_list) +bool Binary_Input_Encode_Value_List(uint32_t object_instance, + BACNET_PROPERTY_VALUE *value_list) { bool status = false; @@ -250,17 +226,17 @@ bool Binary_Input_Encode_Value_List( value_list->value.next = NULL; bitstring_init(&value_list->value.type.Bit_String); bitstring_set_bit(&value_list->value.type.Bit_String, - STATUS_FLAG_IN_ALARM, false); + STATUS_FLAG_IN_ALARM, false); + bitstring_set_bit(&value_list->value.type.Bit_String, STATUS_FLAG_FAULT, + false); bitstring_set_bit(&value_list->value.type.Bit_String, - STATUS_FLAG_FAULT, false); - bitstring_set_bit(&value_list->value.type.Bit_String, - STATUS_FLAG_OVERRIDDEN, false); + STATUS_FLAG_OVERRIDDEN, false); if (Binary_Input_Out_Of_Service(object_instance)) { bitstring_set_bit(&value_list->value.type.Bit_String, - STATUS_FLAG_OUT_OF_SERVICE, true); + STATUS_FLAG_OUT_OF_SERVICE, true); } else { bitstring_set_bit(&value_list->value.type.Bit_String, - STATUS_FLAG_OUT_OF_SERVICE, false); + STATUS_FLAG_OUT_OF_SERVICE, false); } value_list->priority = BACNET_NO_PRIORITY; value_list->next = NULL; @@ -270,9 +246,8 @@ bool Binary_Input_Encode_Value_List( return status; } -bool Binary_Input_Present_Value_Set( - uint32_t object_instance, - BACNET_BINARY_PV value) +bool Binary_Input_Present_Value_Set(uint32_t object_instance, + BACNET_BINARY_PV value) { unsigned index = 0; bool status = false; @@ -296,9 +271,7 @@ bool Binary_Input_Present_Value_Set( return status; } -void Binary_Input_Out_Of_Service_Set( - uint32_t object_instance, - bool value) +void Binary_Input_Out_Of_Service_Set(uint32_t object_instance, bool value) { unsigned index = 0; @@ -313,26 +286,24 @@ void Binary_Input_Out_Of_Service_Set( return; } -bool Binary_Input_Object_Name( - uint32_t object_instance, - BACNET_CHARACTER_STRING * object_name) +bool Binary_Input_Object_Name(uint32_t object_instance, + BACNET_CHARACTER_STRING *object_name) { - static char text_string[32] = ""; /* okay for single thread */ + static char text_string[32] = ""; /* okay for single thread */ bool status = false; unsigned index = 0; index = Binary_Input_Instance_To_Index(object_instance); if (index < MAX_BINARY_INPUTS) { sprintf(text_string, "BINARY INPUT %lu", - (unsigned long) object_instance); + (unsigned long)object_instance); status = characterstring_init_ansi(object_name, text_string); } return status; } -BACNET_POLARITY Binary_Input_Polarity( - uint32_t object_instance) +BACNET_POLARITY Binary_Input_Polarity(uint32_t object_instance) { BACNET_POLARITY polarity = POLARITY_NORMAL; unsigned index = 0; @@ -345,9 +316,8 @@ BACNET_POLARITY Binary_Input_Polarity( return polarity; } -bool Binary_Input_Polarity_Set( - uint32_t object_instance, - BACNET_POLARITY polarity) +bool Binary_Input_Polarity_Set(uint32_t object_instance, + BACNET_POLARITY polarity) { bool status = false; unsigned index = 0; @@ -362,10 +332,9 @@ bool Binary_Input_Polarity_Set( /* return apdu length, or BACNET_STATUS_ERROR on error */ /* assumption - object already exists, and has been bounds checked */ -int Binary_Input_Read_Property( - BACNET_READ_PROPERTY_DATA * rpdata) +int Binary_Input_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata) { - int apdu_len = 0; /* return value */ + int apdu_len = 0; /* return value */ BACNET_BIT_STRING bit_string; BACNET_CHARACTER_STRING char_string; uint8_t *apdu = NULL; @@ -378,9 +347,8 @@ int Binary_Input_Read_Property( apdu = rpdata->application_data; switch (rpdata->object_property) { case PROP_OBJECT_IDENTIFIER: - apdu_len = - encode_application_object_id(&apdu[0], OBJECT_BINARY_INPUT, - rpdata->object_instance); + apdu_len = encode_application_object_id( + &apdu[0], OBJECT_BINARY_INPUT, rpdata->object_instance); break; case PROP_OBJECT_NAME: case PROP_DESCRIPTION: @@ -395,9 +363,8 @@ int Binary_Input_Read_Property( break; case PROP_PRESENT_VALUE: /* note: you need to look up the actual value */ - apdu_len = - encode_application_enumerated(&apdu[0], - Binary_Input_Present_Value(rpdata->object_instance)); + apdu_len = encode_application_enumerated( + &apdu[0], Binary_Input_Present_Value(rpdata->object_instance)); break; case PROP_STATUS_FLAGS: /* note: see the details in the standard on how to use these */ @@ -419,9 +386,8 @@ int Binary_Input_Read_Property( apdu_len = encode_application_boolean(&apdu[0], state); break; case PROP_POLARITY: - apdu_len = - encode_application_enumerated(&apdu[0], - Binary_Input_Polarity(rpdata->object_instance)); + apdu_len = encode_application_enumerated( + &apdu[0], Binary_Input_Polarity(rpdata->object_instance)); break; default: rpdata->error_class = ERROR_CLASS_PROPERTY; @@ -440,17 +406,15 @@ int Binary_Input_Read_Property( } /* returns true if successful */ -bool Binary_Input_Write_Property( - BACNET_WRITE_PROPERTY_DATA * wp_data) +bool Binary_Input_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data) { - bool status = false; /* return value */ + bool status = false; /* return value */ int len = 0; BACNET_APPLICATION_DATA_VALUE value; /* decode the some of the request */ - len = - bacapp_decode_application_data(wp_data->application_data, - wp_data->application_data_len, &value); + len = bacapp_decode_application_data(wp_data->application_data, + wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ if (len < 0) { /* error while decoding - a value larger than we can handle */ @@ -468,11 +432,12 @@ bool Binary_Input_Write_Property( case PROP_PRESENT_VALUE: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_ENUMERATED, - &wp_data->error_class, &wp_data->error_code); + &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, - (BACNET_BINARY_PV) value.type.Enumerated); + Binary_Input_Present_Value_Set( + wp_data->object_instance, + (BACNET_BINARY_PV)value.type.Enumerated); } else { status = false; wp_data->error_class = ERROR_CLASS_PROPERTY; @@ -483,20 +448,21 @@ bool Binary_Input_Write_Property( case PROP_OUT_OF_SERVICE: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { Binary_Input_Out_Of_Service_Set(wp_data->object_instance, - value.type.Boolean); + value.type.Boolean); } break; case PROP_POLARITY: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_ENUMERATED, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { if (value.type.Enumerated < MAX_POLARITY) { - Binary_Input_Polarity_Set(wp_data->object_instance, - (BACNET_POLARITY) value.type.Enumerated); + Binary_Input_Polarity_Set( + wp_data->object_instance, + (BACNET_POLARITY)value.type.Enumerated); } else { status = false; wp_data->error_class = ERROR_CLASS_PROPERTY; @@ -527,11 +493,9 @@ bool Binary_Input_Write_Property( #include #include "ctest.h" -bool WPValidateArgType( - BACNET_APPLICATION_DATA_VALUE * pValue, - uint8_t ucExpectedTag, - BACNET_ERROR_CLASS * pErrorClass, - BACNET_ERROR_CODE * pErrorCode) +bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue, + uint8_t ucExpectedTag, BACNET_ERROR_CLASS *pErrorClass, + BACNET_ERROR_CODE *pErrorCode) { pValue = pValue; ucExpectedTag = ucExpectedTag; @@ -541,11 +505,10 @@ bool WPValidateArgType( return false; } -void testBinaryInput( - Test * pTest) +void testBinaryInput(Test *pTest) { BACNET_READ_PROPERTY_DATA rpdata; - uint8_t apdu[MAX_APDU] = { 0 }; + uint8_t apdu[MAX_APDU] = {0}; int len = 0; uint32_t len_value = 0; uint8_t tag_number = 0; @@ -571,8 +534,7 @@ void testBinaryInput( } #ifdef TEST_BINARY_INPUT -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -584,7 +546,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/demo/object/bo.c b/demo/object/bo.c index 3e842b68..17cda406 100644 --- a/demo/object/bo.c +++ b/demo/object/bo.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2005 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2005 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* Binary Output Objects - customize for your use */ @@ -32,7 +32,7 @@ #include "bacdcode.h" #include "bacenum.h" #include "bacapp.h" -#include "config.h" /* the custom stuff */ +#include "config.h" /* the custom stuff */ #include "rp.h" #include "wp.h" #include "bo.h" @@ -46,42 +46,32 @@ /* the Relinquish Default value */ #define RELINQUISH_DEFAULT BINARY_INACTIVE /* Here is our Priority Array.*/ -static BACNET_BINARY_PV - Binary_Output_Level[MAX_BINARY_OUTPUTS][BACNET_MAX_PRIORITY]; +static BACNET_BINARY_PV Binary_Output_Level[MAX_BINARY_OUTPUTS] + [BACNET_MAX_PRIORITY]; /* Writable out-of-service allows others to play with our Present Value */ /* without changing the physical output */ static bool Out_Of_Service[MAX_BINARY_OUTPUTS]; /* These three arrays are used by the ReadPropertyMultiple handler */ -static const int Binary_Output_Properties_Required[] = { - PROP_OBJECT_IDENTIFIER, - PROP_OBJECT_NAME, - PROP_OBJECT_TYPE, - PROP_PRESENT_VALUE, - PROP_STATUS_FLAGS, - PROP_EVENT_STATE, - PROP_OUT_OF_SERVICE, - PROP_POLARITY, - PROP_PRIORITY_ARRAY, - PROP_RELINQUISH_DEFAULT, - -1 -}; +static const int Binary_Output_Properties_Required[] = {PROP_OBJECT_IDENTIFIER, + PROP_OBJECT_NAME, + PROP_OBJECT_TYPE, + PROP_PRESENT_VALUE, + PROP_STATUS_FLAGS, + PROP_EVENT_STATE, + PROP_OUT_OF_SERVICE, + PROP_POLARITY, + PROP_PRIORITY_ARRAY, + PROP_RELINQUISH_DEFAULT, + -1}; static const int Binary_Output_Properties_Optional[] = { - PROP_DESCRIPTION, - PROP_ACTIVE_TEXT, - PROP_INACTIVE_TEXT, - -1 -}; + PROP_DESCRIPTION, PROP_ACTIVE_TEXT, PROP_INACTIVE_TEXT, -1}; -static const int Binary_Output_Properties_Proprietary[] = { - -1 -}; +static const int Binary_Output_Properties_Proprietary[] = {-1}; -void Binary_Output_Property_Lists( - const int **pRequired, - const int **pOptional, - const int **pProprietary) +void Binary_Output_Property_Lists(const int **pRequired, const int **pOptional, + const int **pProprietary) { if (pRequired) *pRequired = Binary_Output_Properties_Required; @@ -93,8 +83,7 @@ void Binary_Output_Property_Lists( return; } -void Binary_Output_Init( - void) +void Binary_Output_Init(void) { unsigned i, j; static bool initialized = false; @@ -116,8 +105,7 @@ void Binary_Output_Init( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need validate that the */ /* given instance exists */ -bool Binary_Output_Valid_Instance( - uint32_t object_instance) +bool Binary_Output_Valid_Instance(uint32_t object_instance) { if (object_instance < MAX_BINARY_OUTPUTS) return true; @@ -127,8 +115,7 @@ bool Binary_Output_Valid_Instance( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then count how many you have */ -unsigned Binary_Output_Count( - void) +unsigned Binary_Output_Count(void) { return MAX_BINARY_OUTPUTS; } @@ -136,8 +123,7 @@ unsigned Binary_Output_Count( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need to return the instance */ /* that correlates to the correct index */ -uint32_t Binary_Output_Index_To_Instance( - unsigned index) +uint32_t Binary_Output_Index_To_Instance(unsigned index) { return index; } @@ -145,8 +131,7 @@ uint32_t Binary_Output_Index_To_Instance( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need to return the index */ /* that correlates to the correct instance number */ -unsigned Binary_Output_Instance_To_Index( - uint32_t object_instance) +unsigned Binary_Output_Instance_To_Index(uint32_t object_instance) { unsigned index = MAX_BINARY_OUTPUTS; @@ -156,8 +141,7 @@ unsigned Binary_Output_Instance_To_Index( return index; } -BACNET_BINARY_PV Binary_Output_Present_Value( - uint32_t object_instance) +BACNET_BINARY_PV Binary_Output_Present_Value(uint32_t object_instance) { BACNET_BINARY_PV value = RELINQUISH_DEFAULT; unsigned index = 0; @@ -176,8 +160,7 @@ BACNET_BINARY_PV Binary_Output_Present_Value( return value; } -bool Binary_Output_Out_Of_Service( - uint32_t object_instance) +bool Binary_Output_Out_Of_Service(uint32_t object_instance) { bool value = false; unsigned index = 0; @@ -191,16 +174,15 @@ bool Binary_Output_Out_Of_Service( } /* note: the object name must be unique within this device */ -bool Binary_Output_Object_Name( - uint32_t object_instance, - BACNET_CHARACTER_STRING * object_name) +bool Binary_Output_Object_Name(uint32_t object_instance, + BACNET_CHARACTER_STRING *object_name) { - static char text_string[32] = ""; /* okay for single thread */ + static char text_string[32] = ""; /* okay for single thread */ bool status = false; if (object_instance < MAX_BINARY_OUTPUTS) { sprintf(text_string, "BINARY OUTPUT %lu", - (unsigned long) object_instance); + (unsigned long)object_instance); status = characterstring_init_ansi(object_name, text_string); } @@ -208,11 +190,10 @@ bool Binary_Output_Object_Name( } /* return apdu len, or BACNET_STATUS_ERROR on error */ -int Binary_Output_Read_Property( - BACNET_READ_PROPERTY_DATA * rpdata) +int Binary_Output_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata) { int len = 0; - int apdu_len = 0; /* return value */ + int apdu_len = 0; /* return value */ BACNET_BIT_STRING bit_string; BACNET_CHARACTER_STRING char_string; BACNET_BINARY_PV present_value = BINARY_INACTIVE; @@ -229,9 +210,8 @@ int Binary_Output_Read_Property( apdu = rpdata->application_data; switch (rpdata->object_property) { case PROP_OBJECT_IDENTIFIER: - apdu_len = - encode_application_object_id(&apdu[0], OBJECT_BINARY_OUTPUT, - rpdata->object_instance); + apdu_len = encode_application_object_id( + &apdu[0], OBJECT_BINARY_OUTPUT, rpdata->object_instance); break; /* note: Name and Description don't have to be the same. You could make Description writable and different */ @@ -289,9 +269,8 @@ int Binary_Output_Read_Property( len = encode_application_null(&apdu[apdu_len]); else { present_value = Binary_Output_Level[object_index][i]; - len = - encode_application_enumerated(&apdu[apdu_len], - present_value); + len = encode_application_enumerated(&apdu[apdu_len], + present_value); } /* add it if we have room */ if ((apdu_len + len) < MAX_APDU) @@ -308,14 +287,14 @@ int Binary_Output_Read_Property( 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) + 1] == BINARY_NULL) apdu_len = encode_application_null(&apdu[apdu_len]); else { - present_value = Binary_Output_Level[object_index] - [rpdata->array_index - 1]; - apdu_len = - encode_application_enumerated(&apdu[apdu_len], - present_value); + present_value = + Binary_Output_Level[object_index] + [rpdata->array_index - 1]; + apdu_len = encode_application_enumerated( + &apdu[apdu_len], present_value); } } else { rpdata->error_class = ERROR_CLASS_PROPERTY; @@ -357,10 +336,9 @@ int Binary_Output_Read_Property( } /* returns true if successful */ -bool Binary_Output_Write_Property( - BACNET_WRITE_PROPERTY_DATA * wp_data) +bool Binary_Output_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data) { - bool status = false; /* return value */ + bool status = false; /* return value */ unsigned int object_index = 0; unsigned int priority = 0; BACNET_BINARY_PV level = BINARY_NULL; @@ -368,9 +346,8 @@ bool Binary_Output_Write_Property( BACNET_APPLICATION_DATA_VALUE value; /* decode the some of the request */ - len = - bacapp_decode_application_data(wp_data->application_data, - wp_data->application_data_len, &value); + len = bacapp_decode_application_data(wp_data->application_data, + wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ if (len < 0) { /* error while decoding - a value larger than we can handle */ @@ -393,19 +370,19 @@ bool Binary_Output_Write_Property( algorithm and may not be used for other purposes in any object. */ if (priority && (priority <= BACNET_MAX_PRIORITY) && - (priority != 6 /* reserved */ ) && + (priority != 6 /* reserved */) && (value.type.Enumerated <= MAX_BINARY_PV)) { - level = (BACNET_BINARY_PV) value.type.Enumerated; - object_index = - Binary_Output_Instance_To_Index - (wp_data->object_instance); + level = (BACNET_BINARY_PV)value.type.Enumerated; + object_index = 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 are the highest priority. However, if Out of Service is TRUE, then don't set the physical output. This comment may apply to the - main loop (i.e. check out of service before changing output) */ + main loop (i.e. check out of service before changing + output) */ status = true; } else if (priority == 6) { /* Command priority 6 is reserved for use by Minimum On/Off @@ -418,24 +395,24 @@ 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); + object_index = Binary_Output_Instance_To_Index( + wp_data->object_instance); priority = wp_data->priority; if (priority && (priority <= BACNET_MAX_PRIORITY)) { priority--; Binary_Output_Level[object_index][priority] = level; - /* Note: you could set the physical output here to the next - highest priority, or to the relinquish default if no - priorities are set. - However, if Out of Service is TRUE, then don't set the - physical output. This comment may apply to the - main loop (i.e. check out of service before changing output) */ + /* Note: you could set the physical output here to the + next highest priority, or to the relinquish default + if no priorities are set. However, if Out of Service + is TRUE, then don't set the physical output. This + comment may apply to the + main loop (i.e. check out of service before changing + output) */ } else { status = false; wp_data->error_class = ERROR_CLASS_PROPERTY; @@ -447,12 +424,11 @@ bool Binary_Output_Write_Property( case PROP_OUT_OF_SERVICE: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { object_index = Binary_Output_Instance_To_Index(wp_data->object_instance); - Out_Of_Service[object_index] = - value.type.Boolean; + Out_Of_Service[object_index] = value.type.Boolean; } break; case PROP_OBJECT_IDENTIFIER: @@ -478,17 +454,14 @@ bool Binary_Output_Write_Property( return status; } - #ifdef TEST #include #include #include "ctest.h" -bool WPValidateArgType( - BACNET_APPLICATION_DATA_VALUE * pValue, - uint8_t ucExpectedTag, - BACNET_ERROR_CLASS * pErrorClass, - BACNET_ERROR_CODE * pErrorCode) +bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue, + uint8_t ucExpectedTag, BACNET_ERROR_CLASS *pErrorClass, + BACNET_ERROR_CODE *pErrorCode) { pValue = pValue; ucExpectedTag = ucExpectedTag; @@ -498,10 +471,9 @@ bool WPValidateArgType( return false; } -void testBinaryOutput( - Test * pTest) +void testBinaryOutput(Test *pTest) { - uint8_t apdu[MAX_APDU] = { 0 }; + uint8_t apdu[MAX_APDU] = {0}; int len = 0; uint32_t len_value = 0; uint8_t tag_number = 0; @@ -528,8 +500,7 @@ void testBinaryOutput( } #ifdef TEST_BINARY_OUTPUT -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -541,7 +512,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/demo/object/bv.c b/demo/object/bv.c index d91deabc..40ad3fd3 100644 --- a/demo/object/bv.c +++ b/demo/object/bv.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2006 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2006 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* Binary Output Objects - customize for your use */ @@ -32,7 +32,7 @@ #include "bacdcode.h" #include "bacenum.h" #include "bacapp.h" -#include "config.h" /* the custom stuff */ +#include "config.h" /* the custom stuff */ #include "wp.h" #include "rp.h" #include "bv.h" @@ -46,39 +46,26 @@ /* the Relinquish Default value */ #define RELINQUISH_DEFAULT BINARY_INACTIVE /* Here is our Priority Array.*/ -static BACNET_BINARY_PV - Binary_Value_Level[MAX_BINARY_VALUES][BACNET_MAX_PRIORITY]; +static BACNET_BINARY_PV Binary_Value_Level[MAX_BINARY_VALUES] + [BACNET_MAX_PRIORITY]; /* Writable out-of-service allows others to play with our Present Value */ /* without changing the physical output */ static bool Out_Of_Service[MAX_BINARY_VALUES]; /* These three arrays are used by the ReadPropertyMultiple handler */ static const int Binary_Value_Properties_Required[] = { - PROP_OBJECT_IDENTIFIER, - PROP_OBJECT_NAME, - PROP_OBJECT_TYPE, - PROP_PRESENT_VALUE, - PROP_STATUS_FLAGS, - PROP_EVENT_STATE, - PROP_OUT_OF_SERVICE, - -1 -}; + PROP_OBJECT_IDENTIFIER, PROP_OBJECT_NAME, + PROP_OBJECT_TYPE, PROP_PRESENT_VALUE, + PROP_STATUS_FLAGS, PROP_EVENT_STATE, + PROP_OUT_OF_SERVICE, -1}; static const int Binary_Value_Properties_Optional[] = { - PROP_DESCRIPTION, - PROP_PRIORITY_ARRAY, - PROP_RELINQUISH_DEFAULT, - -1 -}; + PROP_DESCRIPTION, PROP_PRIORITY_ARRAY, PROP_RELINQUISH_DEFAULT, -1}; -static const int Binary_Value_Properties_Proprietary[] = { - -1 -}; +static const int Binary_Value_Properties_Proprietary[] = {-1}; -void Binary_Value_Property_Lists( - const int **pRequired, - const int **pOptional, - const int **pProprietary) +void Binary_Value_Property_Lists(const int **pRequired, const int **pOptional, + const int **pProprietary) { if (pRequired) *pRequired = Binary_Value_Properties_Required; @@ -90,8 +77,7 @@ void Binary_Value_Property_Lists( return; } -void Binary_Value_Init( - void) +void Binary_Value_Init(void) { unsigned i, j; static bool initialized = false; @@ -113,8 +99,7 @@ void Binary_Value_Init( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need validate that the */ /* given instance exists */ -bool Binary_Value_Valid_Instance( - uint32_t object_instance) +bool Binary_Value_Valid_Instance(uint32_t object_instance) { if (object_instance < MAX_BINARY_VALUES) return true; @@ -124,8 +109,7 @@ bool Binary_Value_Valid_Instance( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then count how many you have */ -unsigned Binary_Value_Count( - void) +unsigned Binary_Value_Count(void) { return MAX_BINARY_VALUES; } @@ -133,8 +117,7 @@ unsigned Binary_Value_Count( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need to return the instance */ /* that correlates to the correct index */ -uint32_t Binary_Value_Index_To_Instance( - unsigned index) +uint32_t Binary_Value_Index_To_Instance(unsigned index) { return index; } @@ -142,8 +125,7 @@ uint32_t Binary_Value_Index_To_Instance( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need to return the index */ /* that correlates to the correct instance number */ -unsigned Binary_Value_Instance_To_Index( - uint32_t object_instance) +unsigned Binary_Value_Instance_To_Index(uint32_t object_instance) { unsigned index = MAX_BINARY_VALUES; @@ -153,8 +135,7 @@ unsigned Binary_Value_Instance_To_Index( return index; } -BACNET_BINARY_PV Binary_Value_Present_Value( - uint32_t object_instance) +BACNET_BINARY_PV Binary_Value_Present_Value(uint32_t object_instance) { BACNET_BINARY_PV value = RELINQUISH_DEFAULT; unsigned index = 0; @@ -174,24 +155,22 @@ BACNET_BINARY_PV Binary_Value_Present_Value( } /* note: the object name must be unique within this device */ -bool Binary_Value_Object_Name( - uint32_t object_instance, - BACNET_CHARACTER_STRING * object_name) +bool Binary_Value_Object_Name(uint32_t object_instance, + BACNET_CHARACTER_STRING *object_name) { - static char text_string[32] = ""; /* okay for single thread */ + static char text_string[32] = ""; /* okay for single thread */ bool status = false; if (object_instance < MAX_BINARY_VALUES) { sprintf(text_string, "BINARY VALUE %lu", - (unsigned long) object_instance); + (unsigned long)object_instance); status = characterstring_init_ansi(object_name, text_string); } return status; } -bool Binary_Value_Out_Of_Service( - uint32_t instance) +bool Binary_Value_Out_Of_Service(uint32_t instance) { unsigned index = 0; bool oos_flag = false; @@ -204,9 +183,7 @@ bool Binary_Value_Out_Of_Service( return oos_flag; } -void Binary_Value_Out_Of_Service_Set( - uint32_t instance, - bool oos_flag) +void Binary_Value_Out_Of_Service_Set(uint32_t instance, bool oos_flag) { unsigned index = 0; @@ -217,11 +194,10 @@ void Binary_Value_Out_Of_Service_Set( } /* return apdu len, or BACNET_STATUS_ERROR on error */ -int Binary_Value_Read_Property( - BACNET_READ_PROPERTY_DATA * rpdata) +int Binary_Value_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata) { int len = 0; - int apdu_len = 0; /* return value */ + int apdu_len = 0; /* return value */ BACNET_BIT_STRING bit_string; BACNET_CHARACTER_STRING char_string; BACNET_BINARY_PV present_value = BINARY_INACTIVE; @@ -237,9 +213,8 @@ int Binary_Value_Read_Property( apdu = rpdata->application_data; switch (rpdata->object_property) { case PROP_OBJECT_IDENTIFIER: - apdu_len = - encode_application_object_id(&apdu[0], OBJECT_BINARY_VALUE, - rpdata->object_instance); + apdu_len = encode_application_object_id( + &apdu[0], OBJECT_BINARY_VALUE, rpdata->object_instance); break; /* note: Name and Description don't have to be the same. You could make Description writable and different */ @@ -254,8 +229,7 @@ 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: @@ -293,9 +267,8 @@ int Binary_Value_Read_Property( len = encode_application_null(&apdu[apdu_len]); else { present_value = Binary_Value_Level[object_index][i]; - len = - encode_application_enumerated(&apdu[apdu_len], - present_value); + len = encode_application_enumerated(&apdu[apdu_len], + present_value); } /* add it if we have room */ if ((apdu_len + len) < MAX_APDU) @@ -311,15 +284,14 @@ int Binary_Value_Read_Property( 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]; - apdu_len = - encode_application_enumerated(&apdu[apdu_len], - present_value); + [rpdata->array_index]; + apdu_len = encode_application_enumerated( + &apdu[apdu_len], present_value); } } else { rpdata->error_class = ERROR_CLASS_PROPERTY; @@ -350,10 +322,9 @@ int Binary_Value_Read_Property( } /* returns true if successful */ -bool Binary_Value_Write_Property( - BACNET_WRITE_PROPERTY_DATA * wp_data) +bool Binary_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data) { - bool status = false; /* return value */ + bool status = false; /* return value */ unsigned int object_index = 0; unsigned int priority = 0; BACNET_BINARY_PV level = BINARY_NULL; @@ -361,9 +332,8 @@ bool Binary_Value_Write_Property( BACNET_APPLICATION_DATA_VALUE value; /* decode the some of the request */ - len = - bacapp_decode_application_data(wp_data->application_data, - wp_data->application_data_len, &value); + len = bacapp_decode_application_data(wp_data->application_data, + wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ if (len < 0) { /* error while decoding - a value larger than we can handle */ @@ -386,19 +356,19 @@ bool Binary_Value_Write_Property( algorithm and may not be used for other purposes in any object. */ if (priority && (priority <= BACNET_MAX_PRIORITY) && - (priority != 6 /* reserved */ ) && + (priority != 6 /* reserved */) && (value.type.Enumerated <= MAX_BINARY_PV)) { - level = (BACNET_BINARY_PV) value.type.Enumerated; - object_index = - Binary_Value_Instance_To_Index - (wp_data->object_instance); + level = (BACNET_BINARY_PV)value.type.Enumerated; + object_index = 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 are the highest priority. However, if Out of Service is TRUE, then don't set the physical output. This comment may apply to the - main loop (i.e. check out of service before changing output) */ + main loop (i.e. check out of service before changing + output) */ status = true; } else if (priority == 6) { /* Command priority 6 is reserved for use by Minimum On/Off @@ -411,24 +381,24 @@ 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); + object_index = Binary_Value_Instance_To_Index( + wp_data->object_instance); priority = wp_data->priority; if (priority && (priority <= BACNET_MAX_PRIORITY)) { priority--; Binary_Value_Level[object_index][priority] = level; - /* Note: you could set the physical output here to the next - highest priority, or to the relinquish default if no - priorities are set. - However, if Out of Service is TRUE, then don't set the - physical output. This comment may apply to the - main loop (i.e. check out of service before changing output) */ + /* Note: you could set the physical output here to the + next highest priority, or to the relinquish default + if no priorities are set. However, if Out of Service + is TRUE, then don't set the physical output. This + comment may apply to the + main loop (i.e. check out of service before changing + output) */ } else { status = false; wp_data->error_class = ERROR_CLASS_PROPERTY; @@ -440,10 +410,10 @@ bool Binary_Value_Write_Property( case PROP_OUT_OF_SERVICE: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { Binary_Value_Out_Of_Service_Set(wp_data->object_instance, - value.type.Boolean); + value.type.Boolean); } break; case PROP_OBJECT_IDENTIFIER: @@ -466,17 +436,14 @@ bool Binary_Value_Write_Property( return status; } - #ifdef TEST #include #include #include "ctest.h" -bool WPValidateArgType( - BACNET_APPLICATION_DATA_VALUE * pValue, - uint8_t ucExpectedTag, - BACNET_ERROR_CLASS * pErrorClass, - BACNET_ERROR_CODE * pErrorCode) +bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue, + uint8_t ucExpectedTag, BACNET_ERROR_CLASS *pErrorClass, + BACNET_ERROR_CODE *pErrorCode) { pValue = pValue; ucExpectedTag = ucExpectedTag; @@ -486,10 +453,9 @@ bool WPValidateArgType( return false; } -void testBinary_Value( - Test * pTest) +void testBinary_Value(Test *pTest) { - uint8_t apdu[MAX_APDU] = { 0 }; + uint8_t apdu[MAX_APDU] = {0}; int len = 0; uint32_t len_value = 0; uint8_t tag_number = 0; @@ -516,8 +482,7 @@ void testBinary_Value( } #ifdef TEST_BINARY_VALUE -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -529,7 +494,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/demo/object/channel.c b/demo/object/channel.c index 8369b4bf..7e27ae7c 100644 --- a/demo/object/channel.c +++ b/demo/object/channel.c @@ -7,8 +7,8 @@ * @section DESCRIPTION * * The Channel object is a command object without a priority array, and the - * present-value property uses a priority array and a single precision floating point - * data type. + * present-value property uses a priority array and a single precision floating + * point data type. * * @section LICENSE * @@ -39,13 +39,13 @@ #include "bacdcode.h" #include "bacenum.h" #include "bacapp.h" -#include "config.h" /* the custom stuff */ +#include "config.h" /* the custom stuff */ #include "wp.h" #include "handlers.h" #include "proplist.h" #include "lighting.h" #include "device.h" -#if defined (CHANNEL_LIGHTING_COMMAND) || defined (BACAPP_LIGHTING_COMMAND) +#if defined(CHANNEL_LIGHTING_COMMAND) || defined(BACAPP_LIGHTING_COMMAND) #include "lo.h" #endif /* me! */ @@ -64,7 +64,7 @@ #endif struct bacnet_channel_object { - bool Out_Of_Service:1; + bool Out_Of_Service : 1; BACNET_CHANNEL_VALUE Present_Value; unsigned Last_Priority; BACNET_WRITE_STATUS Write_Status; @@ -89,16 +89,11 @@ static const int Channel_Properties_Required[] = { PROP_LIST_OF_OBJECT_PROPERTY_REFERENCES, PROP_CHANNEL_NUMBER, PROP_CONTROL_GROUPS, - -1 -}; + -1}; -static const int Channel_Properties_Optional[] = { - -1 -}; +static const int Channel_Properties_Optional[] = {-1}; -static const int Channel_Properties_Proprietary[] = { - -1 -}; +static const int Channel_Properties_Proprietary[] = {-1}; /** * Returns the list of required, optional, and proprietary properties. @@ -111,9 +106,8 @@ static const int Channel_Properties_Proprietary[] = { * @param pProprietary - pointer to list of int terminated by -1, of * BACnet proprietary properties for this object. */ -void Channel_Property_Lists(const int **pRequired, - const int **pOptional, - const int **pProprietary) +void Channel_Property_Lists(const int **pRequired, const int **pOptional, + const int **pProprietary) { if (pRequired) *pRequired = Channel_Properties_Required; @@ -200,7 +194,7 @@ unsigned Channel_Instance_To_Index(uint32_t object_instance) * @param object_instance - object-instance number of the object * @return pointer to the BACNET_CHANNEL_VALUE present-value */ -BACNET_CHANNEL_VALUE * Channel_Present_Value(uint32_t object_instance) +BACNET_CHANNEL_VALUE *Channel_Present_Value(uint32_t object_instance) { unsigned index = 0; BACNET_CHANNEL_VALUE *cvalue = NULL; @@ -352,9 +346,8 @@ unsigned Channel_Reference_List_Member_Count(uint32_t object_instance) * * @return pointer to member element or NULL if not found */ -BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE * -Channel_Reference_List_Member_Element(uint32_t object_instance, - unsigned array_index) +BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE *Channel_Reference_List_Member_Element( + uint32_t object_instance, unsigned array_index) { BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE *pMember = NULL; unsigned count = 0; @@ -385,8 +378,8 @@ Channel_Reference_List_Member_Element(uint32_t object_instance, * * @return pointer to member element or NULL if not found */ -bool Channel_Reference_List_Member_Element_Set(uint32_t object_instance, - unsigned array_index, +bool Channel_Reference_List_Member_Element_Set( + uint32_t object_instance, unsigned array_index, BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE *pMemberSrc) { BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE *pMember = NULL; @@ -403,7 +396,7 @@ bool Channel_Reference_List_Member_Element_Set(uint32_t object_instance, count++; if (count == array_index) { memcpy(pMember, pMemberSrc, - sizeof(BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE)); + sizeof(BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE)); status = true; break; } @@ -423,7 +416,8 @@ bool Channel_Reference_List_Member_Element_Set(uint32_t object_instance, * @return array_index - 1-based array index value for added element, or * zero if not added */ -unsigned Channel_Reference_List_Member_Element_Add(uint32_t object_instance, +unsigned Channel_Reference_List_Member_Element_Add( + uint32_t object_instance, BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE *pMemberSrc) { BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE *pMember = NULL; @@ -441,7 +435,7 @@ unsigned Channel_Reference_List_Member_Element_Add(uint32_t object_instance, /* first empty slot */ count++; memcpy(pMember, pMemberSrc, - sizeof(BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE)); + sizeof(BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE)); break; } } @@ -463,11 +457,8 @@ unsigned Channel_Reference_List_Member_Element_Add(uint32_t object_instance, * zero if not added */ unsigned Channel_Reference_List_Member_Local_Add( - uint32_t object_instance, - uint16_t type, - uint32_t instance, - BACNET_PROPERTY_ID propertyIdentifier, - uint32_t arrayIndex) + uint32_t object_instance, uint16_t type, uint32_t instance, + BACNET_PROPERTY_ID propertyIdentifier, uint32_t arrayIndex) { BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE member = {{0}}; @@ -478,9 +469,7 @@ unsigned Channel_Reference_List_Member_Local_Add( member.deviceIdentifier.type = OBJECT_DEVICE; member.deviceIdentifier.instance = Device_Object_Instance_Number(); - return Channel_Reference_List_Member_Element_Add( - object_instance, - &member); + return Channel_Reference_List_Member_Element_Add(object_instance, &member); } /** @@ -491,16 +480,14 @@ unsigned Channel_Reference_List_Member_Local_Add( * * @return group number in the array */ -uint16_t Channel_Control_Groups_Element( - uint32_t object_instance, - int32_t array_index) +uint16_t Channel_Control_Groups_Element(uint32_t object_instance, + int32_t array_index) { unsigned index = 0; uint16_t value = 0; index = Channel_Instance_To_Index(object_instance); - if ((index < BACNET_CHANNELS_MAX) && - (array_index > 0) && + if ((index < BACNET_CHANNELS_MAX) && (array_index > 0) && (array_index <= CONTROL_GROUPS_MAX)) { array_index--; value = Channel[index].Control_Groups[array_index]; @@ -518,17 +505,14 @@ uint16_t Channel_Control_Groups_Element( * * @return true if parameters are value and control group is set */ -bool Channel_Control_Groups_Element_Set( - uint32_t object_instance, - int32_t array_index, - uint16_t value) +bool Channel_Control_Groups_Element_Set(uint32_t object_instance, + int32_t array_index, uint16_t value) { bool status = false; unsigned index = 0; index = Channel_Instance_To_Index(object_instance); - if ((index < BACNET_CHANNELS_MAX) && - (array_index > 0) && + if ((index < BACNET_CHANNELS_MAX) && (array_index > 0) && (array_index <= CONTROL_GROUPS_MAX)) { array_index--; Channel[index].Control_Groups[array_index] = value; @@ -546,8 +530,8 @@ bool Channel_Control_Groups_Element_Set( * * @return true if values are able to be copied */ -bool Channel_Value_Copy(BACNET_CHANNEL_VALUE * cvalue, - BACNET_APPLICATION_DATA_VALUE * value) +bool Channel_Value_Copy(BACNET_CHANNEL_VALUE *cvalue, + BACNET_APPLICATION_DATA_VALUE *value) { bool status = false; @@ -555,100 +539,92 @@ bool Channel_Value_Copy(BACNET_CHANNEL_VALUE * cvalue, return false; } switch (value->tag) { -#if defined (BACAPP_NULL) +#if defined(BACAPP_NULL) case BACNET_APPLICATION_TAG_NULL: cvalue->tag = value->tag; status = true; break; #endif -#if defined (BACAPP_BOOLEAN) && defined (CHANNEL_BOOLEAN) +#if defined(BACAPP_BOOLEAN) && defined(CHANNEL_BOOLEAN) case BACNET_APPLICATION_TAG_BOOLEAN: cvalue->tag = value->tag; cvalue->type.Boolean = value->type.Boolean; status = true; break; #endif -#if defined (BACAPP_UNSIGNED) && defined (CHANNEL_UNSIGNED) +#if defined(BACAPP_UNSIGNED) && defined(CHANNEL_UNSIGNED) case BACNET_APPLICATION_TAG_UNSIGNED_INT: cvalue->tag = value->tag; cvalue->type.Unsigned_Int = value->type.Unsigned_Int; status = true; break; #endif -#if defined (BACAPP_SIGNED) && defined (CHANNEL_SIGNED) +#if defined(BACAPP_SIGNED) && defined(CHANNEL_SIGNED) case BACNET_APPLICATION_TAG_SIGNED_INT: cvalue->tag = value->tag; cvalue->type.Signed_Int = value->type.Signed_Int; status = true; break; #endif -#if defined (BACAPP_REAL) && defined (CHANNEL_REAL) +#if defined(BACAPP_REAL) && defined(CHANNEL_REAL) case BACNET_APPLICATION_TAG_REAL: cvalue->tag = value->tag; cvalue->type.Real = value->type.Real; status = true; break; #endif -#if defined (BACAPP_DOUBLE) && defined (CHANNEL_DOUBLE) +#if defined(BACAPP_DOUBLE) && defined(CHANNEL_DOUBLE) case BACNET_APPLICATION_TAG_DOUBLE: cvalue->tag = value->tag; cvalue->type.Double = value->type.Double; status = true; break; #endif -#if defined (BACAPP_OCTET_STRING) && defined (CHANNEL_OCTET_STRING) +#if defined(BACAPP_OCTET_STRING) && defined(CHANNEL_OCTET_STRING) case BACNET_APPLICATION_TAG_OCTET_STRING: cvalue->tag = value->tag; - octetstring_copy( - &cvalue->type.Octet_String, - &value->type.Octet_String); + octetstring_copy(&cvalue->type.Octet_String, + &value->type.Octet_String); status = true; break; #endif -#if defined (BACAPP_CHARACTER_STRING) && defined (CHANNEL_CHARACTER_STRING) +#if defined(BACAPP_CHARACTER_STRING) && defined(CHANNEL_CHARACTER_STRING) case BACNET_APPLICATION_TAG_CHARACTER_STRING: cvalue->tag = value->tag; - characterstring_copy( - &cvalue->type.Character_String, - &value->type.Character_String); + characterstring_copy(&cvalue->type.Character_String, + &value->type.Character_String); status = true; break; #endif -#if defined (BACAPP_BIT_STRING) && defined (CHANNEL_BIT_STRING) +#if defined(BACAPP_BIT_STRING) && defined(CHANNEL_BIT_STRING) case BACNET_APPLICATION_TAG_BIT_STRING: cvalue->tag = value->tag; - bitstring_copy( - &cvalue->type.Bit_String, - &value->type.Bit_String); + bitstring_copy(&cvalue->type.Bit_String, &value->type.Bit_String); status = true; break; #endif -#if defined (BACAPP_ENUMERATED) && defined (CHANNEL_ENUMERATED) +#if defined(BACAPP_ENUMERATED) && defined(CHANNEL_ENUMERATED) case BACNET_APPLICATION_TAG_ENUMERATED: cvalue->tag = value->tag; cvalue->type.Enumerated = value->type.Enumerated; status = true; break; #endif -#if defined (BACAPP_DATE) && defined (CHANNEL_DATE) +#if defined(BACAPP_DATE) && defined(CHANNEL_DATE) case BACNET_APPLICATION_TAG_DATE: cvalue->tag = value->tag; - datetime_date_copy( - &cvalue->type.Date, - &value->type.Date); + datetime_date_copy(&cvalue->type.Date, &value->type.Date); apdu_len = encode_application_date(&apdu[0], &value->type.Date); status = true; break; #endif -#if defined (BACAPP_TIME) && defined (CHANNEL_TIME) +#if defined(BACAPP_TIME) && defined(CHANNEL_TIME) case BACNET_APPLICATION_TAG_TIME: cvalue->tag = value->tag; - datetime_time_copy( - &cvalue->type.Time, - &value->type.Time); + datetime_time_copy(&cvalue->type.Time, &value->type.Time); break; #endif -#if defined (BACAPP_OBJECT_ID) && defined (CHANNEL_OBJECT_ID) +#if defined(BACAPP_OBJECT_ID) && defined(CHANNEL_OBJECT_ID) case BACNET_APPLICATION_TAG_OBJECT_ID: cvalue->tag = value->tag; cvalue->type.Object_Id.type = value->type.Object_Id.type; @@ -656,12 +632,11 @@ bool Channel_Value_Copy(BACNET_CHANNEL_VALUE * cvalue, status = true; break; #endif -#if defined (BACAPP_LIGHTING_COMMAND) && defined (CHANNEL_LIGHTING_COMMAND) +#if defined(BACAPP_LIGHTING_COMMAND) && defined(CHANNEL_LIGHTING_COMMAND) case BACNET_APPLICATION_TAG_LIGHTING_COMMAND: cvalue->tag = value->tag; - lighting_command_copy( - &cvalue->type.Lighting_Command, - &value->type.Lighting_Command); + lighting_command_copy(&cvalue->type.Lighting_Command, + &value->type.Lighting_Command); status = true; break; #endif @@ -682,7 +657,7 @@ bool Channel_Value_Copy(BACNET_CHANNEL_VALUE * cvalue, * @return number of bytes in the APDU, or BACNET_STATUS_ERROR */ int Channel_Value_Encode(uint8_t *apdu, int apdu_max, - BACNET_CHANNEL_VALUE * value) + BACNET_CHANNEL_VALUE *value) { int apdu_len = BACNET_STATUS_ERROR; @@ -693,90 +668,79 @@ int Channel_Value_Encode(uint8_t *apdu, int apdu_max, case BACNET_APPLICATION_TAG_NULL: apdu_len = encode_application_null(&apdu[0]); break; -#if defined (CHANNEL_BOOLEAN) +#if defined(CHANNEL_BOOLEAN) case BACNET_APPLICATION_TAG_BOOLEAN: - apdu_len = encode_application_boolean(&apdu[0], - value->type.Boolean); + apdu_len = + encode_application_boolean(&apdu[0], value->type.Boolean); break; #endif -#if defined (CHANNEL_UNSIGNED) +#if defined(CHANNEL_UNSIGNED) case BACNET_APPLICATION_TAG_UNSIGNED_INT: apdu_len = - encode_application_unsigned(&apdu[0], - value->type.Unsigned_Int); + encode_application_unsigned(&apdu[0], value->type.Unsigned_Int); break; #endif -#if defined (CHANNEL_SIGNED) +#if defined(CHANNEL_SIGNED) case BACNET_APPLICATION_TAG_SIGNED_INT: apdu_len = - encode_application_signed(&apdu[0], - value->type.Signed_Int); + encode_application_signed(&apdu[0], value->type.Signed_Int); break; #endif -#if defined (CHANNEL_REAL) +#if defined(CHANNEL_REAL) case BACNET_APPLICATION_TAG_REAL: apdu_len = encode_application_real(&apdu[0], value->type.Real); break; #endif -#if defined (CHANNEL_DOUBLE) +#if defined(CHANNEL_DOUBLE) case BACNET_APPLICATION_TAG_DOUBLE: - apdu_len = - encode_application_double(&apdu[0], value->type.Double); + apdu_len = encode_application_double(&apdu[0], value->type.Double); break; #endif -#if defined (CHANNEL_OCTET_STRING) +#if defined(CHANNEL_OCTET_STRING) case BACNET_APPLICATION_TAG_OCTET_STRING: - apdu_len = - encode_application_octet_string(&apdu[0], - &value->type.Octet_String); + apdu_len = encode_application_octet_string( + &apdu[0], &value->type.Octet_String); break; #endif -#if defined (CHANNEL_CHARACTER_STRING) +#if defined(CHANNEL_CHARACTER_STRING) case BACNET_APPLICATION_TAG_CHARACTER_STRING: - apdu_len = - encode_application_character_string(&apdu[0], - &value->type.Character_String); + apdu_len = encode_application_character_string( + &apdu[0], &value->type.Character_String); break; #endif -#if defined (CHANNEL_BIT_STRING) +#if defined(CHANNEL_BIT_STRING) case BACNET_APPLICATION_TAG_BIT_STRING: apdu_len = - encode_application_bitstring(&apdu[0], - &value->type.Bit_String); + encode_application_bitstring(&apdu[0], &value->type.Bit_String); break; #endif -#if defined (CHANNEL_ENUMERATED) +#if defined(CHANNEL_ENUMERATED) case BACNET_APPLICATION_TAG_ENUMERATED: apdu_len = - encode_application_enumerated(&apdu[0], - value->type.Enumerated); + encode_application_enumerated(&apdu[0], value->type.Enumerated); break; #endif -#if defined (CHANNEL_DATE) +#if defined(CHANNEL_DATE) case BACNET_APPLICATION_TAG_DATE: - apdu_len = - encode_application_date(&apdu[0], &value->type.Date); + apdu_len = encode_application_date(&apdu[0], &value->type.Date); break; #endif -#if defined (CHANNEL_TIME) +#if defined(CHANNEL_TIME) case BACNET_APPLICATION_TAG_TIME: - apdu_len = - encode_application_time(&apdu[0], &value->type.Time); + apdu_len = encode_application_time(&apdu[0], &value->type.Time); break; #endif -#if defined (CHANNEL_OBJECT_ID) +#if defined(CHANNEL_OBJECT_ID) case BACNET_APPLICATION_TAG_OBJECT_ID: - apdu_len = - encode_application_object_id(&apdu[0], - (int) value->type.Object_Id.type, + apdu_len = encode_application_object_id( + &apdu[0], (int)value->type.Object_Id.type, value->type.Object_Id.instance); break; #endif -#if defined (CHANNEL_LIGHTING_COMMAND) +#if defined(CHANNEL_LIGHTING_COMMAND) case BACNET_APPLICATION_TAG_LIGHTING_COMMAND: - apdu_len = - lighting_command_encode(&apdu[0], - &value->type.Lighting_Command); + apdu_len = lighting_command_encode(&apdu[0], + &value->type.Lighting_Command); break; #endif default: @@ -796,13 +760,11 @@ int Channel_Value_Encode(uint8_t *apdu, int apdu_max, * * @return number of bytes in the APDU, or BACNET_STATUS_ERROR if error. */ -int Channel_Coerce_Data_Encode( - uint8_t * apdu, - unsigned max_apdu, - BACNET_APPLICATION_DATA_VALUE * value, - BACNET_APPLICATION_TAG tag) +int Channel_Coerce_Data_Encode(uint8_t *apdu, unsigned max_apdu, + BACNET_APPLICATION_DATA_VALUE *value, + BACNET_APPLICATION_TAG tag) { - int apdu_len = 0; /* total length of the apdu, return value */ + int apdu_len = 0; /* total length of the apdu, return value */ float float_value = 0.0; double double_value = 0.0; uint32_t unsigned_value = 0; @@ -812,7 +774,7 @@ int Channel_Coerce_Data_Encode( (void)max_apdu; if (apdu && value) { switch (value->tag) { -#if defined (BACAPP_NULL) +#if defined(BACAPP_NULL) case BACNET_APPLICATION_TAG_NULL: if (tag == BACNET_APPLICATION_TAG_LIGHTING_COMMAND) { apdu_len = BACNET_STATUS_ERROR; @@ -823,21 +785,23 @@ int Channel_Coerce_Data_Encode( } break; #endif -#if defined (BACAPP_BOOLEAN) +#if defined(BACAPP_BOOLEAN) case BACNET_APPLICATION_TAG_BOOLEAN: if (tag == BACNET_APPLICATION_TAG_BOOLEAN) { - apdu_len = - encode_application_boolean(&apdu[0], value->type.Boolean); + apdu_len = encode_application_boolean(&apdu[0], + value->type.Boolean); } else if (tag == BACNET_APPLICATION_TAG_UNSIGNED_INT) { if (value->type.Boolean) { unsigned_value = 1; } - apdu_len = encode_application_unsigned(&apdu[0], unsigned_value); + apdu_len = + encode_application_unsigned(&apdu[0], unsigned_value); } else if (tag == BACNET_APPLICATION_TAG_SIGNED_INT) { if (value->type.Boolean) { signed_value = 1; } - apdu_len = encode_application_signed(&apdu[0], signed_value); + apdu_len = + encode_application_signed(&apdu[0], signed_value); } else if (tag == BACNET_APPLICATION_TAG_REAL) { if (value->type.Boolean) { float_value = 1; @@ -847,7 +811,8 @@ int Channel_Coerce_Data_Encode( if (value->type.Boolean) { double_value = 1; } - apdu_len = encode_application_double(&apdu[0], double_value); + apdu_len = + encode_application_double(&apdu[0], double_value); } else if (tag == BACNET_APPLICATION_TAG_ENUMERATED) { if (value->type.Boolean) { unsigned_value = 1; @@ -859,7 +824,7 @@ int Channel_Coerce_Data_Encode( } break; #endif -#if defined (BACAPP_UNSIGNED) +#if defined(BACAPP_UNSIGNED) case BACNET_APPLICATION_TAG_UNSIGNED_INT: if (tag == BACNET_APPLICATION_TAG_BOOLEAN) { if (value->type.Unsigned_Int) { @@ -869,38 +834,38 @@ int Channel_Coerce_Data_Encode( encode_application_boolean(&apdu[0], boolean_value); } else if (tag == BACNET_APPLICATION_TAG_UNSIGNED_INT) { unsigned_value = value->type.Unsigned_Int; - apdu_len = encode_application_unsigned(&apdu[0], - unsigned_value); + apdu_len = + encode_application_unsigned(&apdu[0], unsigned_value); } else if (tag == BACNET_APPLICATION_TAG_SIGNED_INT) { if (value->type.Unsigned_Int <= 2147483647) { signed_value = value->type.Unsigned_Int; - apdu_len = encode_application_signed(&apdu[0], - signed_value); + apdu_len = + encode_application_signed(&apdu[0], signed_value); } else { apdu_len = BACNET_STATUS_ERROR; } } else if (tag == BACNET_APPLICATION_TAG_REAL) { if (value->type.Unsigned_Int <= 9999999) { float_value = (float)value->type.Unsigned_Int; - apdu_len = encode_application_real(&apdu[0], - float_value); + apdu_len = + encode_application_real(&apdu[0], float_value); } else { apdu_len = BACNET_STATUS_ERROR; } } else if (tag == BACNET_APPLICATION_TAG_DOUBLE) { double_value = value->type.Unsigned_Int; - apdu_len = encode_application_double(&apdu[0], - double_value); + apdu_len = + encode_application_double(&apdu[0], double_value); } else if (tag == BACNET_APPLICATION_TAG_ENUMERATED) { unsigned_value = value->type.Unsigned_Int; - apdu_len = encode_application_enumerated(&apdu[0], - unsigned_value); + apdu_len = + encode_application_enumerated(&apdu[0], unsigned_value); } else { apdu_len = BACNET_STATUS_ERROR; } break; #endif -#if defined (BACAPP_SIGNED) +#if defined(BACAPP_SIGNED) case BACNET_APPLICATION_TAG_SIGNED_INT: if (tag == BACNET_APPLICATION_TAG_BOOLEAN) { if (value->type.Signed_Int) { @@ -913,36 +878,36 @@ int Channel_Coerce_Data_Encode( (value->type.Signed_Int <= 2147483647)) { unsigned_value = value->type.Signed_Int; apdu_len = encode_application_unsigned(&apdu[0], - unsigned_value); + unsigned_value); } else { apdu_len = BACNET_STATUS_ERROR; } } else if (tag == BACNET_APPLICATION_TAG_SIGNED_INT) { signed_value = value->type.Signed_Int; - apdu_len = encode_application_signed(&apdu[0], - signed_value); + apdu_len = + encode_application_signed(&apdu[0], signed_value); } else if (tag == BACNET_APPLICATION_TAG_REAL) { if (value->type.Signed_Int <= 9999999) { float_value = (float)value->type.Signed_Int; - apdu_len = encode_application_real(&apdu[0], - float_value); + apdu_len = + encode_application_real(&apdu[0], float_value); } else { apdu_len = BACNET_STATUS_ERROR; } } else if (tag == BACNET_APPLICATION_TAG_DOUBLE) { double_value = value->type.Signed_Int; - apdu_len = encode_application_double(&apdu[0], - double_value); + apdu_len = + encode_application_double(&apdu[0], double_value); } else if (tag == BACNET_APPLICATION_TAG_ENUMERATED) { unsigned_value = value->type.Signed_Int; - apdu_len = encode_application_enumerated(&apdu[0], - unsigned_value); + apdu_len = + encode_application_enumerated(&apdu[0], unsigned_value); } else { apdu_len = BACNET_STATUS_ERROR; } break; #endif -#if defined (BACAPP_REAL) +#if defined(BACAPP_REAL) case BACNET_APPLICATION_TAG_REAL: if (tag == BACNET_APPLICATION_TAG_BOOLEAN) { if (value->type.Real) { @@ -955,7 +920,7 @@ int Channel_Coerce_Data_Encode( (value->type.Real <= 2147483000.0)) { unsigned_value = (uint32_t)value->type.Real; apdu_len = encode_application_unsigned(&apdu[0], - unsigned_value); + unsigned_value); } else { apdu_len = BACNET_STATUS_ERROR; } @@ -963,25 +928,24 @@ int Channel_Coerce_Data_Encode( if ((value->type.Real >= -2147483000.0) && (value->type.Real <= 214783000.0)) { signed_value = (int32_t)value->type.Real; - apdu_len = encode_application_signed(&apdu[0], - signed_value); + apdu_len = + encode_application_signed(&apdu[0], signed_value); } else { apdu_len = BACNET_STATUS_ERROR; } } else if (tag == BACNET_APPLICATION_TAG_REAL) { float_value = value->type.Real; - apdu_len = encode_application_real(&apdu[0], - float_value); + apdu_len = encode_application_real(&apdu[0], float_value); } else if (tag == BACNET_APPLICATION_TAG_DOUBLE) { double_value = value->type.Real; - apdu_len = encode_application_double(&apdu[0], - double_value); + apdu_len = + encode_application_double(&apdu[0], double_value); } else if (tag == BACNET_APPLICATION_TAG_ENUMERATED) { if ((value->type.Real >= 0.0) && (value->type.Real <= 2147483000.0)) { unsigned_value = (uint32_t)value->type.Real; - apdu_len = encode_application_enumerated(&apdu[0], - unsigned_value); + apdu_len = encode_application_enumerated( + &apdu[0], unsigned_value); } else { apdu_len = BACNET_STATUS_ERROR; } @@ -990,7 +954,7 @@ int Channel_Coerce_Data_Encode( } break; #endif -#if defined (BACAPP_DOUBLE) +#if defined(BACAPP_DOUBLE) case BACNET_APPLICATION_TAG_DOUBLE: if (tag == BACNET_APPLICATION_TAG_BOOLEAN) { if (value->type.Double) { @@ -1003,7 +967,7 @@ int Channel_Coerce_Data_Encode( (value->type.Double <= 2147483000.0)) { unsigned_value = (uint32_t)value->type.Double; apdu_len = encode_application_unsigned(&apdu[0], - unsigned_value); + unsigned_value); } else { apdu_len = BACNET_STATUS_ERROR; } @@ -1011,8 +975,8 @@ int Channel_Coerce_Data_Encode( if ((value->type.Double >= -2147483000.0) && (value->type.Double <= 214783000.0)) { signed_value = (int32_t)value->type.Double; - apdu_len = encode_application_signed(&apdu[0], - signed_value); + apdu_len = + encode_application_signed(&apdu[0], signed_value); } else { apdu_len = BACNET_STATUS_ERROR; } @@ -1020,21 +984,21 @@ int Channel_Coerce_Data_Encode( if ((value->type.Double >= 3.4E-38) && (value->type.Double <= 3.4E+38)) { float_value = (float)value->type.Double; - apdu_len = encode_application_real(&apdu[0], - float_value); + apdu_len = + encode_application_real(&apdu[0], float_value); } else { apdu_len = BACNET_STATUS_ERROR; } } else if (tag == BACNET_APPLICATION_TAG_DOUBLE) { double_value = value->type.Double; - apdu_len = encode_application_double(&apdu[0], - double_value); + apdu_len = + encode_application_double(&apdu[0], double_value); } else if (tag == BACNET_APPLICATION_TAG_ENUMERATED) { if ((value->type.Double >= 0.0) && (value->type.Double <= 2147483000.0)) { unsigned_value = (uint32_t)value->type.Double; - apdu_len = encode_application_enumerated(&apdu[0], - unsigned_value); + apdu_len = encode_application_enumerated( + &apdu[0], unsigned_value); } else { apdu_len = BACNET_STATUS_ERROR; } @@ -1043,7 +1007,7 @@ int Channel_Coerce_Data_Encode( } break; #endif -#if defined (BACAPP_ENUMERATED) +#if defined(BACAPP_ENUMERATED) case BACNET_APPLICATION_TAG_ENUMERATED: if (tag == BACNET_APPLICATION_TAG_BOOLEAN) { if (value->type.Enumerated) { @@ -1053,47 +1017,46 @@ int Channel_Coerce_Data_Encode( encode_application_boolean(&apdu[0], boolean_value); } else if (tag == BACNET_APPLICATION_TAG_UNSIGNED_INT) { unsigned_value = value->type.Enumerated; - apdu_len = encode_application_unsigned(&apdu[0], - unsigned_value); + apdu_len = + encode_application_unsigned(&apdu[0], unsigned_value); } else if (tag == BACNET_APPLICATION_TAG_SIGNED_INT) { if (value->type.Enumerated <= 2147483647) { signed_value = value->type.Enumerated; - apdu_len = encode_application_signed(&apdu[0], - signed_value); + apdu_len = + encode_application_signed(&apdu[0], signed_value); } else { apdu_len = BACNET_STATUS_ERROR; } } else if (tag == BACNET_APPLICATION_TAG_REAL) { if (value->type.Enumerated <= 9999999) { float_value = (float)value->type.Enumerated; - apdu_len = encode_application_real(&apdu[0], - float_value); + apdu_len = + encode_application_real(&apdu[0], float_value); } else { apdu_len = BACNET_STATUS_ERROR; } } else if (tag == BACNET_APPLICATION_TAG_DOUBLE) { double_value = value->type.Enumerated; - apdu_len = encode_application_double(&apdu[0], - double_value); + apdu_len = + encode_application_double(&apdu[0], double_value); } else if (tag == BACNET_APPLICATION_TAG_ENUMERATED) { unsigned_value = value->type.Enumerated; - apdu_len = encode_application_enumerated(&apdu[0], - unsigned_value); + apdu_len = + encode_application_enumerated(&apdu[0], unsigned_value); } else { apdu_len = BACNET_STATUS_ERROR; } break; #endif -#if defined (BACAPP_LIGHTING_COMMAND) - case BACNET_APPLICATION_TAG_LIGHTING_COMMAND: - if (tag == BACNET_APPLICATION_TAG_LIGHTING_COMMAND) { - apdu_len = - lighting_command_encode(&apdu[0], - &value->type.Lighting_Command); - } else { - apdu_len = BACNET_STATUS_ERROR; - } - break; +#if defined(BACAPP_LIGHTING_COMMAND) + case BACNET_APPLICATION_TAG_LIGHTING_COMMAND: + if (tag == BACNET_APPLICATION_TAG_LIGHTING_COMMAND) { + apdu_len = lighting_command_encode( + &apdu[0], &value->type.Lighting_Command); + } else { + apdu_len = BACNET_STATUS_ERROR; + } + break; #endif default: apdu_len = BACNET_STATUS_ERROR; @@ -1112,51 +1075,44 @@ int Channel_Coerce_Data_Encode( * * @return true if values are within range and present-value is sent. */ -bool Channel_Write_Member_Value( - BACNET_WRITE_PROPERTY_DATA * wp_data, - BACNET_APPLICATION_DATA_VALUE * value) +bool Channel_Write_Member_Value(BACNET_WRITE_PROPERTY_DATA *wp_data, + BACNET_APPLICATION_DATA_VALUE *value) { bool status = false; int apdu_len = 0; if (wp_data && value) { if (((wp_data->object_type == OBJECT_ANALOG_INPUT) || - (wp_data->object_type == OBJECT_ANALOG_OUTPUT) || - (wp_data->object_type == OBJECT_ANALOG_VALUE)) && + (wp_data->object_type == OBJECT_ANALOG_OUTPUT) || + (wp_data->object_type == OBJECT_ANALOG_VALUE)) && (wp_data->object_property == PROP_PRESENT_VALUE) && (wp_data->array_index == BACNET_ARRAY_ALL)) { apdu_len = Channel_Coerce_Data_Encode( - wp_data->application_data, - wp_data->application_data_len, - value, + wp_data->application_data, wp_data->application_data_len, value, BACNET_APPLICATION_TAG_REAL); if (apdu_len != BACNET_STATUS_ERROR) { wp_data->application_data_len = apdu_len; status = true; } } else if (((wp_data->object_type == OBJECT_BINARY_INPUT) || - (wp_data->object_type == OBJECT_BINARY_OUTPUT) || - (wp_data->object_type == OBJECT_BINARY_VALUE)) && - (wp_data->object_property == PROP_PRESENT_VALUE) && - (wp_data->array_index == BACNET_ARRAY_ALL)) { + (wp_data->object_type == OBJECT_BINARY_OUTPUT) || + (wp_data->object_type == OBJECT_BINARY_VALUE)) && + (wp_data->object_property == PROP_PRESENT_VALUE) && + (wp_data->array_index == BACNET_ARRAY_ALL)) { apdu_len = Channel_Coerce_Data_Encode( - wp_data->application_data, - wp_data->application_data_len, - value, + wp_data->application_data, wp_data->application_data_len, value, BACNET_APPLICATION_TAG_ENUMERATED); if (apdu_len != BACNET_STATUS_ERROR) { wp_data->application_data_len = apdu_len; status = true; } } else if (((wp_data->object_type == OBJECT_MULTI_STATE_INPUT) || - (wp_data->object_type == OBJECT_MULTI_STATE_OUTPUT) || - (wp_data->object_type == OBJECT_MULTI_STATE_VALUE)) && - (wp_data->object_property == PROP_PRESENT_VALUE) && - (wp_data->array_index == BACNET_ARRAY_ALL)) { + (wp_data->object_type == OBJECT_MULTI_STATE_OUTPUT) || + (wp_data->object_type == OBJECT_MULTI_STATE_VALUE)) && + (wp_data->object_property == PROP_PRESENT_VALUE) && + (wp_data->array_index == BACNET_ARRAY_ALL)) { apdu_len = Channel_Coerce_Data_Encode( - wp_data->application_data, - wp_data->application_data_len, - value, + wp_data->application_data, wp_data->application_data_len, value, BACNET_APPLICATION_TAG_UNSIGNED_INT); if (apdu_len != BACNET_STATUS_ERROR) { wp_data->application_data_len = apdu_len; @@ -1166,21 +1122,17 @@ bool Channel_Write_Member_Value( if ((wp_data->object_property == PROP_PRESENT_VALUE) && (wp_data->array_index == BACNET_ARRAY_ALL)) { apdu_len = Channel_Coerce_Data_Encode( - wp_data->application_data, - wp_data->application_data_len, - value, - BACNET_APPLICATION_TAG_REAL); + wp_data->application_data, wp_data->application_data_len, + value, BACNET_APPLICATION_TAG_REAL); if (apdu_len != BACNET_STATUS_ERROR) { wp_data->application_data_len = apdu_len; status = true; } } else if ((wp_data->object_property == PROP_LIGHTING_COMMAND) && - (wp_data->array_index == BACNET_ARRAY_ALL)) { + (wp_data->array_index == BACNET_ARRAY_ALL)) { apdu_len = Channel_Coerce_Data_Encode( - wp_data->application_data, - wp_data->application_data_len, - value, - BACNET_APPLICATION_TAG_LIGHTING_COMMAND); + wp_data->application_data, wp_data->application_data_len, + value, BACNET_APPLICATION_TAG_LIGHTING_COMMAND); if (apdu_len != BACNET_STATUS_ERROR) { wp_data->application_data_len = apdu_len; status = true; @@ -1200,10 +1152,9 @@ bool Channel_Write_Member_Value( * * @return true if values are within range and present-value is sent. */ -static bool Channel_Write_Members( - struct bacnet_channel_object * pChannel, - BACNET_APPLICATION_DATA_VALUE * value, - uint8_t priority) +static bool Channel_Write_Members(struct bacnet_channel_object *pChannel, + BACNET_APPLICATION_DATA_VALUE *value, + uint8_t priority) { BACNET_WRITE_PROPERTY_DATA wp_data = {0}; bool status = false; @@ -1227,8 +1178,7 @@ static bool Channel_Write_Members( wp_data.object_property = pMember->propertyIdentifier; wp_data.array_index = pMember->arrayIndex; wp_data.priority = priority; - wp_data.application_data_len = - sizeof(wp_data.application_data); + wp_data.application_data_len = sizeof(wp_data.application_data); status = Channel_Write_Member_Value(&wp_data, value); if (status) { status = Device_Write_Property(&wp_data); @@ -1253,9 +1203,8 @@ static bool Channel_Write_Members( * * @return true if values are within range and present-value is sent. */ -bool Channel_Present_Value_Set( - BACNET_WRITE_PROPERTY_DATA * wp_data, - BACNET_APPLICATION_DATA_VALUE * value) +bool Channel_Present_Value_Set(BACNET_WRITE_PROPERTY_DATA *wp_data, + BACNET_APPLICATION_DATA_VALUE *value) { unsigned index = 0; bool status = false; @@ -1264,11 +1213,11 @@ bool Channel_Present_Value_Set( if (index < BACNET_CHANNELS_MAX) { if ((wp_data->priority > 0) && (wp_data->priority <= BACNET_MAX_PRIORITY)) { - if (wp_data->priority != 6 /* reserved */ ) { - status = Channel_Value_Copy(&Channel[index].Present_Value, - value); + if (wp_data->priority != 6 /* reserved */) { + status = + Channel_Value_Copy(&Channel[index].Present_Value, value); status = Channel_Write_Members(&Channel[index], value, - wp_data->priority); + wp_data->priority); status = true; } else { /* Command priority 6 is reserved for use by Minimum On/Off @@ -1297,7 +1246,7 @@ bool Channel_Present_Value_Set( * @return true if object-name was retrieved */ bool Channel_Object_Name(uint32_t object_instance, - BACNET_CHARACTER_STRING * object_name) + BACNET_CHARACTER_STRING *object_name) { char text_string[32] = ""; bool status = false; @@ -1305,8 +1254,7 @@ bool Channel_Object_Name(uint32_t object_instance, index = Channel_Instance_To_Index(object_instance); if (index < BACNET_CHANNELS_MAX) { - sprintf(text_string, "CHANNEL %lu", - (unsigned long) object_instance); + sprintf(text_string, "CHANNEL %lu", (unsigned long)object_instance); status = characterstring_init_ansi(object_name, text_string); } @@ -1342,8 +1290,7 @@ bool Channel_Out_Of_Service(uint32_t instance) * * @return true if the out-of-service property value was set */ -void Channel_Out_Of_Service_Set(uint32_t instance, - bool value) +void Channel_Out_Of_Service_Set(uint32_t instance, bool value) { unsigned int index = 0; @@ -1363,13 +1310,13 @@ void Channel_Out_Of_Service_Set(uint32_t instance, * @return number of APDU bytes in the response, or * BACNET_STATUS_ERROR on error. */ -int Channel_Read_Property(BACNET_READ_PROPERTY_DATA * rpdata) +int Channel_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata) { int len = 0; - int apdu_len = 0; /* return value */ + int apdu_len = 0; /* return value */ BACNET_BIT_STRING bit_string; BACNET_CHARACTER_STRING char_string; - BACNET_CHANNEL_VALUE * cvalue = NULL; + BACNET_CHANNEL_VALUE *cvalue = NULL; uint32_t unsigned_value = 0; unsigned i = 0; unsigned count = 0; @@ -1384,9 +1331,8 @@ int Channel_Read_Property(BACNET_READ_PROPERTY_DATA * rpdata) apdu = rpdata->application_data; switch (rpdata->object_property) { case PROP_OBJECT_IDENTIFIER: - apdu_len = - encode_application_object_id(&apdu[0], OBJECT_CHANNEL, - rpdata->object_instance); + apdu_len = encode_application_object_id(&apdu[0], OBJECT_CHANNEL, + rpdata->object_instance); break; case PROP_OBJECT_NAME: Channel_Object_Name(rpdata->object_instance, &char_string); @@ -1394,8 +1340,7 @@ int Channel_Read_Property(BACNET_READ_PROPERTY_DATA * rpdata) encode_application_character_string(&apdu[0], &char_string); break; case PROP_OBJECT_TYPE: - apdu_len = - encode_application_enumerated(&apdu[0], OBJECT_CHANNEL); + apdu_len = encode_application_enumerated(&apdu[0], OBJECT_CHANNEL); break; case PROP_PRESENT_VALUE: cvalue = Channel_Present_Value(rpdata->object_instance); @@ -1406,15 +1351,12 @@ int Channel_Read_Property(BACNET_READ_PROPERTY_DATA * rpdata) break; case PROP_LAST_PRIORITY: unsigned_value = Channel_Last_Priority(rpdata->object_instance); - apdu_len = - encode_application_unsigned(&apdu[0], unsigned_value); + apdu_len = encode_application_unsigned(&apdu[0], unsigned_value); break; case PROP_WRITE_STATUS: - unsigned_value = - (BACNET_WRITE_STATUS)Channel_Write_Status( + unsigned_value = (BACNET_WRITE_STATUS)Channel_Write_Status( rpdata->object_instance); - apdu_len = - encode_application_enumerated(&apdu[0], unsigned_value); + apdu_len = encode_application_enumerated(&apdu[0], unsigned_value); break; case PROP_STATUS_FLAGS: bitstring_init(&bit_string); @@ -1432,18 +1374,20 @@ int Channel_Read_Property(BACNET_READ_PROPERTY_DATA * rpdata) case PROP_LIST_OF_OBJECT_PROPERTY_REFERENCES: if (rpdata->array_index == 0) { /* Array element zero is the number of elements in the array */ - count = Channel_Reference_List_Member_Count(rpdata->object_instance); + count = Channel_Reference_List_Member_Count( + rpdata->object_instance); apdu_len = encode_application_unsigned(&apdu[0], count); } else if (rpdata->array_index == BACNET_ARRAY_ALL) { - /* if no index was specified, then try to encode the entire list */ + /* if no index was specified, then try to encode the entire list + */ /* into one packet. */ - count = Channel_Reference_List_Member_Count(rpdata->object_instance); + count = Channel_Reference_List_Member_Count( + rpdata->object_instance); for (i = 1; i <= count; i++) { pMember = Channel_Reference_List_Member_Element( rpdata->object_instance, i); - len = - bacapp_encode_device_obj_property_ref(&apdu[apdu_len], - pMember); + len = bacapp_encode_device_obj_property_ref(&apdu[apdu_len], + pMember); /* add it if we have room */ if ((apdu_len + len) < MAX_APDU) { apdu_len += len; @@ -1456,13 +1400,13 @@ int Channel_Read_Property(BACNET_READ_PROPERTY_DATA * rpdata) } } else { /* a specific element was requested */ - count = Channel_Reference_List_Member_Count(rpdata->object_instance); + count = Channel_Reference_List_Member_Count( + rpdata->object_instance); if (rpdata->array_index <= count) { pMember = Channel_Reference_List_Member_Element( rpdata->object_instance, rpdata->array_index); - apdu_len += - bacapp_encode_device_obj_property_ref(&apdu[0], - pMember); + apdu_len += bacapp_encode_device_obj_property_ref(&apdu[0], + pMember); } else { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX; @@ -1472,23 +1416,22 @@ int Channel_Read_Property(BACNET_READ_PROPERTY_DATA * rpdata) break; case PROP_CHANNEL_NUMBER: unsigned_value = Channel_Number(rpdata->object_instance); - apdu_len = - encode_application_unsigned(&apdu[0], unsigned_value); + apdu_len = encode_application_unsigned(&apdu[0], unsigned_value); break; case PROP_CONTROL_GROUPS: if (rpdata->array_index == 0) { /* Array element zero is the number of elements in the array */ - apdu_len = encode_application_unsigned(&apdu[0], - CONTROL_GROUPS_MAX); + apdu_len = + encode_application_unsigned(&apdu[0], CONTROL_GROUPS_MAX); } else if (rpdata->array_index == BACNET_ARRAY_ALL) { - /* if no index was specified, then try to encode the entire list */ + /* if no index was specified, then try to encode the entire list + */ /* into one packet. */ for (i = 1; i <= CONTROL_GROUPS_MAX; i++) { unsigned_value = Channel_Control_Groups_Element( rpdata->object_instance, i); - len = - encode_application_unsigned(&apdu[apdu_len], - unsigned_value); + len = encode_application_unsigned(&apdu[apdu_len], + unsigned_value); /* add it if we have room */ if ((apdu_len + len) < MAX_APDU) { apdu_len += len; @@ -1504,9 +1447,8 @@ int Channel_Read_Property(BACNET_READ_PROPERTY_DATA * rpdata) if (rpdata->array_index <= CONTROL_GROUPS_MAX) { unsigned_value = Channel_Control_Groups_Element( rpdata->object_instance, rpdata->array_index); - apdu_len = - encode_application_unsigned(&apdu[apdu_len], - unsigned_value); + apdu_len = encode_application_unsigned(&apdu[apdu_len], + unsigned_value); } else { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX; @@ -1521,10 +1463,9 @@ int Channel_Read_Property(BACNET_READ_PROPERTY_DATA * rpdata) break; } /* only array properties can have array options */ - if ((apdu_len >= 0) - && (rpdata->object_property != PROP_PRIORITY_ARRAY) - && (rpdata->object_property != PROP_LIST_OF_OBJECT_PROPERTY_REFERENCES) - && (rpdata->array_index != BACNET_ARRAY_ALL)) { + if ((apdu_len >= 0) && (rpdata->object_property != PROP_PRIORITY_ARRAY) && + (rpdata->object_property != PROP_LIST_OF_OBJECT_PROPERTY_REFERENCES) && + (rpdata->array_index != BACNET_ARRAY_ALL)) { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; apdu_len = BACNET_STATUS_ERROR; @@ -1542,9 +1483,9 @@ int Channel_Read_Property(BACNET_READ_PROPERTY_DATA * rpdata) * * @return false if an error is loaded, true if no errors */ -bool Channel_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data) +bool Channel_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data) { - bool status = false; /* return value */ + bool status = false; /* return value */ int len = 0; BACNET_APPLICATION_DATA_VALUE value; int element_len = 0; @@ -1552,9 +1493,8 @@ bool Channel_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data) uint32_t array_index = 0; /* decode the some of the request */ - len = - bacapp_decode_application_data(wp_data->application_data, - wp_data->application_data_len, &value); + len = bacapp_decode_application_data(wp_data->application_data, + wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ if (len < 0) { /* error while decoding - a value larger than we can handle */ @@ -1576,33 +1516,36 @@ bool Channel_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data) case PROP_OUT_OF_SERVICE: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { Channel_Out_Of_Service_Set(wp_data->object_instance, - value.type.Boolean); + value.type.Boolean); } break; case PROP_LIST_OF_OBJECT_PROPERTY_REFERENCES: -// FIXME: add property handling -// status = Channel_List_Of_Object_Property_References_Set( -// wp_data, -// &value); + // FIXME: add property handling + // status = + // Channel_List_Of_Object_Property_References_Set( + // wp_data, + // &value); 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_CHANNEL_NUMBER: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { Channel_Number_Set(wp_data->object_instance, - value.type.Unsigned_Int); + value.type.Unsigned_Int); } break; case PROP_CONTROL_GROUPS: if (value.tag == BACNET_APPLICATION_TAG_UNSIGNED_INT) { if (wp_data->array_index == 0) { - /* Array element zero is the number of elements in the array */ + /* Array element zero is the number of elements in the array + */ wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED; } else if (wp_data->array_index == BACNET_ARRAY_ALL) { @@ -1612,7 +1555,8 @@ bool Channel_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data) element_len = len; do { if ((element_len > 0) && - (value.tag == BACNET_APPLICATION_TAG_UNSIGNED_INT)) { + (value.tag == + BACNET_APPLICATION_TAG_UNSIGNED_INT)) { if ((wp_data->array_index <= CONTROL_GROUPS_MAX) && (value.type.Unsigned_Int <= 65535)) { status = Channel_Control_Groups_Element_Set( @@ -1622,7 +1566,8 @@ bool Channel_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data) } if (!status) { wp_data->error_class = ERROR_CLASS_PROPERTY; - wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; + wp_data->error_code = + ERROR_CODE_VALUE_OUT_OF_RANGE; break; } } @@ -1631,11 +1576,11 @@ bool Channel_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data) if (count) { element_len = bacapp_decode_application_data( &wp_data->application_data[len], - wp_data->application_data_len-len, - &value); + wp_data->application_data_len - len, &value); if (element_len < 0) { wp_data->error_class = ERROR_CLASS_PROPERTY; - wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; + wp_data->error_code = + ERROR_CODE_VALUE_OUT_OF_RANGE; break; } len += element_len; @@ -1645,8 +1590,7 @@ bool Channel_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data) if ((wp_data->array_index <= CONTROL_GROUPS_MAX) && (value.type.Unsigned_Int <= 65535)) { status = Channel_Control_Groups_Element_Set( - wp_data->object_instance, - wp_data->array_index, + wp_data->object_instance, wp_data->array_index, value.type.Unsigned_Int); } if (!status) { @@ -1692,11 +1636,10 @@ void Channel_Init(void) for (m = 0; m < CHANNEL_MEMBERS_MAX; m++) { Channel[i].Members[m].objectIdentifier.type = OBJECT_LIGHTING_OUTPUT; - Channel[i].Members[m].objectIdentifier.instance = i+1; + Channel[i].Members[m].objectIdentifier.instance = i + 1; Channel[i].Members[m].propertyIdentifier = PROP_LIGHTING_COMMAND; Channel[i].Members[m].arrayIndex = BACNET_ARRAY_ALL; - Channel[i].Members[m].deviceIdentifier.type = - OBJECT_DEVICE; + Channel[i].Members[m].deviceIdentifier.type = OBJECT_DEVICE; Channel[i].Members[m].deviceIdentifier.instance = 0; } Channel[i].Number = 0; diff --git a/demo/object/command.c b/demo/object/command.c index 674959f0..30ce1c2d 100644 --- a/demo/object/command.c +++ b/demo/object/command.c @@ -47,87 +47,78 @@ #include "bacdcode.h" #include "bacenum.h" #include "bactext.h" -#include "config.h" /* the custom stuff */ +#include "config.h" /* the custom stuff */ #include "device.h" #include "handlers.h" #include "proplist.h" #include "timestamp.h" #include "command.h" - /*BACnetActionCommand ::= SEQUENCE { - deviceIdentifier [0] BACnetObjectIdentifier OPTIONAL, - objectIdentifier [1] BACnetObjectIdentifier, - propertyIdentifier [2] BACnetPropertyIdentifier, - propertyArrayIndex [3] Unsigned OPTIONAL, --used only with array datatype - propertyValue [4] ABSTRACT-SYNTAX.&Type, - priority [5] Unsigned (1..16) OPTIONAL, --used only when property is commandable - postDelay [6] Unsigned OPTIONAL, - quitOnFailure [7] BOOLEAN, - writeSuccessful [8] BOOLEAN - }*/ +/*BACnetActionCommand ::= SEQUENCE { +deviceIdentifier [0] BACnetObjectIdentifier OPTIONAL, +objectIdentifier [1] BACnetObjectIdentifier, +propertyIdentifier [2] BACnetPropertyIdentifier, +propertyArrayIndex [3] Unsigned OPTIONAL, --used only with array datatype +propertyValue [4] ABSTRACT-SYNTAX.&Type, +priority [5] Unsigned (1..16) OPTIONAL, --used only when property is commandable +postDelay [6] Unsigned OPTIONAL, +quitOnFailure [7] BOOLEAN, +writeSuccessful [8] BOOLEAN +}*/ - -int cl_encode_apdu( - uint8_t * apdu, - BACNET_ACTION_LIST * bcl) +int cl_encode_apdu(uint8_t *apdu, BACNET_ACTION_LIST *bcl) { int len = 0; int apdu_len = 0; if (bcl->Device_Id.instance >= 0 && bcl->Device_Id.instance <= BACNET_MAX_INSTANCE) { - len = - encode_context_object_id(&apdu[apdu_len], 0, bcl->Device_Id.type, - bcl->Device_Id.instance); + len = encode_context_object_id(&apdu[apdu_len], 0, bcl->Device_Id.type, + bcl->Device_Id.instance); if (len < 0) return BACNET_STATUS_REJECT; apdu_len += len; } /* TODO: Check for object type and instance limits */ - len = - encode_context_object_id(&apdu[apdu_len], 1, bcl->Object_Id.type, - bcl->Object_Id.instance); + len = encode_context_object_id(&apdu[apdu_len], 1, bcl->Object_Id.type, + bcl->Object_Id.instance); if (len < 0) return BACNET_STATUS_REJECT; apdu_len += len; len = - encode_context_enumerated(&apdu[apdu_len], 2, - bcl->Property_Identifier); + encode_context_enumerated(&apdu[apdu_len], 2, bcl->Property_Identifier); if (len < 0) return BACNET_STATUS_REJECT; apdu_len += len; if (bcl->Property_Array_Index != BACNET_ARRAY_ALL) { - len = - encode_context_unsigned(&apdu[apdu_len], 3, - bcl->Property_Array_Index); + len = encode_context_unsigned(&apdu[apdu_len], 3, + bcl->Property_Array_Index); if (len < 0) return BACNET_STATUS_REJECT; apdu_len += len; } - /* BACnet Testing Observed Incident oi00108 - Command Action not correctly formatted - Revealed by BACnet Test Client v1.8.16 ( www.bac-test.com/bacnet-test-client-download ) - BITS: BIT00031 - BC 135.1: 9.20.1.7 - BC 135.1: 9.20.1.9 - Any discussions can be directed to edward@bac-test.com - Please feel free to remove this comment when my changes have been reviewed - by all interested parties. Say 6 months -> September 2016 */ - - len = encode_opening_tag(&apdu[apdu_len], 4); - if (len < 0) - return BACNET_STATUS_REJECT; - apdu_len += len; - len = bacapp_encode_application_data(&apdu[apdu_len], &bcl->Value); + /* BACnet Testing Observed Incident oi00108 + Command Action not correctly formatted + Revealed by BACnet Test Client v1.8.16 ( + www.bac-test.com/bacnet-test-client-download ) BITS: BIT00031 BC + 135.1: 9.20.1.7 BC 135.1: 9.20.1.9 Any discussions can be directed to + edward@bac-test.com Please feel free to remove this comment when my + changes have been reviewed by all interested parties. Say 6 months -> + September 2016 */ + + len = encode_opening_tag(&apdu[apdu_len], 4); + if (len < 0) + return BACNET_STATUS_REJECT; + apdu_len += len; + len = bacapp_encode_application_data(&apdu[apdu_len], &bcl->Value); + if (len < 0) + return BACNET_STATUS_REJECT; + apdu_len += len; + len = encode_closing_tag(&apdu[apdu_len], 4); if (len < 0) return BACNET_STATUS_REJECT; apdu_len += len; - len = encode_closing_tag(&apdu[apdu_len], 4); - if (len < 0) - return BACNET_STATUS_REJECT; - apdu_len += len; - if (bcl->Priority != BACNET_NO_PRIORITY) { len = encode_context_unsigned(&apdu[apdu_len], 5, bcl->Priority); @@ -153,11 +144,8 @@ int cl_encode_apdu( return apdu_len; } -int cl_decode_apdu( - uint8_t * apdu, - unsigned apdu_len, - BACNET_APPLICATION_TAG tag, - BACNET_ACTION_LIST * bcl) +int cl_decode_apdu(uint8_t *apdu, unsigned apdu_len, BACNET_APPLICATION_TAG tag, + BACNET_ACTION_LIST *bcl) { int len = 0; int dec_len = 0; @@ -167,43 +155,37 @@ int cl_decode_apdu( if (decode_is_context_tag(&apdu[dec_len], 0)) { /* Tag 0: Device ID */ dec_len++; - len = - decode_object_id(&apdu[dec_len], &bcl->Device_Id.type, - &bcl->Device_Id.instance); + len = decode_object_id(&apdu[dec_len], &bcl->Device_Id.type, + &bcl->Device_Id.instance); if (len < 0) return BACNET_STATUS_REJECT; dec_len += len; } if (!decode_is_context_tag(&apdu[dec_len++], 1)) return BACNET_STATUS_REJECT; - len = - decode_object_id(&apdu[dec_len], &bcl->Object_Id.type, - &bcl->Object_Id.instance); + len = decode_object_id(&apdu[dec_len], &bcl->Object_Id.type, + &bcl->Object_Id.instance); if (len < 0) return BACNET_STATUS_REJECT; dec_len += len; - len = - decode_tag_number_and_value(&apdu[dec_len], &tag_number, - &len_value_type); + len = decode_tag_number_and_value(&apdu[dec_len], &tag_number, + &len_value_type); if (len < 0) return BACNET_STATUS_REJECT; dec_len += len; if (tag_number != 2) return BACNET_STATUS_REJECT; - len = - decode_enumerated(&apdu[dec_len], len_value_type, - &bcl->Property_Identifier); + len = decode_enumerated(&apdu[dec_len], len_value_type, + &bcl->Property_Identifier); if (len < 0) return BACNET_STATUS_REJECT; dec_len += len; if (decode_is_context_tag(&apdu[dec_len], 3)) { - len = - decode_tag_number_and_value(&apdu[dec_len], &tag_number, - &len_value_type); + len = decode_tag_number_and_value(&apdu[dec_len], &tag_number, + &len_value_type); dec_len += len; - len = - decode_unsigned(&apdu[dec_len], len_value_type, - &bcl->Property_Array_Index); + len = decode_unsigned(&apdu[dec_len], len_value_type, + &bcl->Property_Array_Index); if (len < 0) return BACNET_STATUS_REJECT; dec_len += len; @@ -220,68 +202,55 @@ int cl_decode_apdu( len = 1; break; case BACNET_APPLICATION_TAG_BOOLEAN: - len = - decode_context_boolean2(&apdu[dec_len], 4, - &bcl->Value.type.Boolean); + len = decode_context_boolean2(&apdu[dec_len], 4, + &bcl->Value.type.Boolean); break; case BACNET_APPLICATION_TAG_UNSIGNED_INT: - len = - decode_context_unsigned(&apdu[dec_len], 4, - &bcl->Value.type.Unsigned_Int); + len = decode_context_unsigned(&apdu[dec_len], 4, + &bcl->Value.type.Unsigned_Int); break; case BACNET_APPLICATION_TAG_SIGNED_INT: - len = - decode_context_signed(&apdu[dec_len], 4, - &bcl->Value.type.Signed_Int); + len = decode_context_signed(&apdu[dec_len], 4, + &bcl->Value.type.Signed_Int); break; case BACNET_APPLICATION_TAG_REAL: - len = - decode_context_real(&apdu[dec_len], 4, &bcl->Value.type.Real); + len = decode_context_real(&apdu[dec_len], 4, &bcl->Value.type.Real); break; case BACNET_APPLICATION_TAG_DOUBLE: - len = - decode_context_double(&apdu[dec_len], 4, - &bcl->Value.type.Double); + len = decode_context_double(&apdu[dec_len], 4, + &bcl->Value.type.Double); break; case BACNET_APPLICATION_TAG_OCTET_STRING: - len = - decode_context_octet_string(&apdu[dec_len], 4, - &bcl->Value.type.Octet_String); + len = decode_context_octet_string(&apdu[dec_len], 4, + &bcl->Value.type.Octet_String); break; case BACNET_APPLICATION_TAG_CHARACTER_STRING: - len = - decode_context_character_string(&apdu[dec_len], 4, - &bcl->Value.type.Character_String); + len = decode_context_character_string( + &apdu[dec_len], 4, &bcl->Value.type.Character_String); break; case BACNET_APPLICATION_TAG_BIT_STRING: - len = - decode_context_bitstring(&apdu[dec_len], 4, - &bcl->Value.type.Bit_String); + len = decode_context_bitstring(&apdu[dec_len], 4, + &bcl->Value.type.Bit_String); break; case BACNET_APPLICATION_TAG_ENUMERATED: - len = - decode_context_enumerated(&apdu[dec_len], 4, - &bcl->Value.type.Enumerated); + len = decode_context_enumerated(&apdu[dec_len], 4, + &bcl->Value.type.Enumerated); break; case BACNET_APPLICATION_TAG_DATE: - len = - decode_context_date(&apdu[dec_len], 4, &bcl->Value.type.Date); + len = decode_context_date(&apdu[dec_len], 4, &bcl->Value.type.Date); break; case BACNET_APPLICATION_TAG_TIME: - len = - decode_context_bacnet_time(&apdu[dec_len], 4, - &bcl->Value.type.Time); + len = decode_context_bacnet_time(&apdu[dec_len], 4, + &bcl->Value.type.Time); break; case BACNET_APPLICATION_TAG_OBJECT_ID: - len = - decode_context_object_id(&apdu[dec_len], 4, - &bcl->Value.type.Object_Id.type, - &bcl->Value.type.Object_Id.instance); + len = decode_context_object_id(&apdu[dec_len], 4, + &bcl->Value.type.Object_Id.type, + &bcl->Value.type.Object_Id.instance); break; case BACNET_APPLICATION_TAG_LIGHTING_COMMAND: - len = - lighting_command_decode(&apdu[dec_len], apdu_len - dec_len, - &bcl->Value.type.Lighting_Command); + len = lighting_command_decode(&apdu[dec_len], apdu_len - dec_len, + &bcl->Value.type.Lighting_Command); break; default: return BACNET_STATUS_REJECT; @@ -291,25 +260,22 @@ int cl_decode_apdu( dec_len += len; if (decode_is_context_tag(&apdu[dec_len], 5)) { uint32_t priority_dec; - len = - decode_tag_number_and_value(&apdu[dec_len], &tag_number, - &len_value_type); + len = decode_tag_number_and_value(&apdu[dec_len], &tag_number, + &len_value_type); dec_len += len; len = decode_unsigned(&apdu[dec_len], len_value_type, &priority_dec); if (len < 0) return BACNET_STATUS_REJECT; - bcl->Priority = (uint8_t) priority_dec; + bcl->Priority = (uint8_t)priority_dec; dec_len += len; } else { bcl->Priority = BACNET_NO_PRIORITY; } if (decode_is_context_tag(&apdu[dec_len], 6)) { - len = - decode_tag_number_and_value(&apdu[dec_len], &tag_number, - &len_value_type); + len = decode_tag_number_and_value(&apdu[dec_len], &tag_number, + &len_value_type); dec_len += len; - len = - decode_unsigned(&apdu[dec_len], len_value_type, &bcl->Post_Delay); + len = decode_unsigned(&apdu[dec_len], len_value_type, &bcl->Post_Delay); if (len < 0) return BACNET_STATUS_REJECT; dec_len += len; @@ -340,25 +306,18 @@ int cl_decode_apdu( COMMAND_DESCR Command_Descr[MAX_COMMANDS]; /* These arrays are used by the ReadPropertyMultiple handler */ -static const int Command_Properties_Required[] = { - PROP_OBJECT_IDENTIFIER, - PROP_OBJECT_NAME, - PROP_OBJECT_TYPE, - PROP_PRESENT_VALUE, - PROP_IN_PROCESS, - PROP_ALL_WRITES_SUCCESSFUL, - PROP_ACTION, - -1 -}; +static const int Command_Properties_Required[] = {PROP_OBJECT_IDENTIFIER, + PROP_OBJECT_NAME, + PROP_OBJECT_TYPE, + PROP_PRESENT_VALUE, + PROP_IN_PROCESS, + PROP_ALL_WRITES_SUCCESSFUL, + PROP_ACTION, + -1}; -static const int Command_Properties_Optional[] = { - PROP_DESCRIPTION, - -1 -}; +static const int Command_Properties_Optional[] = {PROP_DESCRIPTION, -1}; -static const int Command_Properties_Proprietary[] = { - -1 -}; +static const int Command_Properties_Proprietary[] = {-1}; /** * Returns the list of required, optional, and proprietary properties. @@ -371,10 +330,8 @@ static const int Command_Properties_Proprietary[] = { * @param pProprietary - pointer to list of int terminated by -1, of * BACnet proprietary properties for this object. */ -void Command_Property_Lists( - const int **pRequired, - const int **pOptional, - const int **pProprietary) +void Command_Property_Lists(const int **pRequired, const int **pOptional, + const int **pProprietary) { if (pRequired) *pRequired = Command_Properties_Required; @@ -386,18 +343,16 @@ void Command_Property_Lists( return; } - /** * Initializes the Command object data */ -void Command_Init( - void) +void Command_Init(void) { unsigned i; for (i = 0; i < MAX_COMMANDS; i++) { Command_Descr[i].Present_Value = 0; Command_Descr[i].In_Process = false; - Command_Descr[i].All_Writes_Successful = true; /* Optimistic default */ + Command_Descr[i].All_Writes_Successful = true; /* Optimistic default */ } } @@ -408,8 +363,7 @@ void Command_Init( * * @return true if the instance is valid, and false if not */ -bool Command_Valid_Instance( - uint32_t object_instance) +bool Command_Valid_Instance(uint32_t object_instance) { unsigned int index; @@ -425,8 +379,7 @@ bool Command_Valid_Instance( * * @return Number of objects */ -unsigned Command_Count( - void) +unsigned Command_Count(void) { return MAX_COMMANDS; } @@ -439,8 +392,7 @@ unsigned Command_Count( * * @return object instance-number for the given index */ -uint32_t Command_Index_To_Instance( - unsigned index) +uint32_t Command_Index_To_Instance(unsigned index) { return index; } @@ -454,8 +406,7 @@ uint32_t Command_Index_To_Instance( * @return index for the given instance-number, or * the total number of this object instances if not valid. */ -unsigned Command_Instance_To_Index( - uint32_t object_instance) +unsigned Command_Instance_To_Index(uint32_t object_instance) { unsigned index = MAX_COMMANDS; @@ -472,8 +423,7 @@ unsigned Command_Instance_To_Index( * * @return present-value of the object */ -uint32_t Command_Present_Value( - uint32_t object_instance) +uint32_t Command_Present_Value(uint32_t object_instance) { uint32_t value = 0; unsigned int index; @@ -494,9 +444,7 @@ uint32_t Command_Present_Value( * * @return true if values are within range and present-value is set. */ -bool Command_Present_Value_Set( - uint32_t object_instance, - uint32_t value) +bool Command_Present_Value_Set(uint32_t object_instance, uint32_t value) { bool status = false; unsigned int index; @@ -521,8 +469,7 @@ bool Command_Present_Value_Set( * * @return true if this object-instance is in-process. */ -bool Command_In_Process( - uint32_t object_instance) +bool Command_In_Process(uint32_t object_instance) { bool value = false; unsigned int index; @@ -543,9 +490,7 @@ bool Command_In_Process( * * @return true if values are within range and in-process flag is set. */ -bool Command_In_Process_Set( - uint32_t object_instance, - bool value) +bool Command_In_Process_Set(uint32_t object_instance, bool value) { bool status = false; unsigned int index; @@ -568,8 +513,7 @@ bool Command_In_Process_Set( * * @return true if all writes were successful for this object-instance */ -bool Command_All_Writes_Successful( - uint32_t object_instance) +bool Command_All_Writes_Successful(uint32_t object_instance) { bool value = false; unsigned int index; @@ -590,9 +534,7 @@ bool Command_All_Writes_Successful( * * @return true if values are within range and all-writes-succcessful is set. */ -bool Command_All_Writes_Successful_Set( - uint32_t object_instance, - bool value) +bool Command_All_Writes_Successful_Set(uint32_t object_instance, bool value) { bool status = false; unsigned int index; @@ -615,17 +557,16 @@ bool Command_All_Writes_Successful_Set( * * @return true if object-name was retrieved */ -bool Command_Object_Name( - uint32_t object_instance, - BACNET_CHARACTER_STRING * object_name) +bool Command_Object_Name(uint32_t object_instance, + BACNET_CHARACTER_STRING *object_name) { - static char text_string[32] = ""; /* okay for single thread */ + static char text_string[32] = ""; /* okay for single thread */ unsigned int index; bool status = false; index = Command_Instance_To_Index(object_instance); if (index < MAX_COMMANDS) { - sprintf(text_string, "COMMAND %lu", (unsigned long) index); + sprintf(text_string, "COMMAND %lu", (unsigned long)index); status = characterstring_init_ansi(object_name, text_string); } @@ -642,10 +583,9 @@ bool Command_Object_Name( * @return number of APDU bytes in the response, or * BACNET_STATUS_ERROR on error. */ -int Command_Read_Property( - BACNET_READ_PROPERTY_DATA * rpdata) +int Command_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata) { - int apdu_len = 0; /* return value */ + int apdu_len = 0; /* return value */ int len = 0; BACNET_CHARACTER_STRING char_string; unsigned object_index = 0; @@ -666,11 +606,10 @@ int Command_Read_Property( } apdu = rpdata->application_data; - switch ((int) rpdata->object_property) { + switch ((int)rpdata->object_property) { case PROP_OBJECT_IDENTIFIER: - apdu_len = - encode_application_object_id(&apdu[0], OBJECT_COMMAND, - rpdata->object_instance); + apdu_len = encode_application_object_id(&apdu[0], OBJECT_COMMAND, + rpdata->object_instance); break; case PROP_OBJECT_NAME: @@ -685,24 +624,23 @@ int Command_Read_Property( break; case PROP_PRESENT_VALUE: - apdu_len = - encode_application_unsigned(&apdu[0], - Command_Present_Value(rpdata->object_instance)); + apdu_len = encode_application_unsigned( + &apdu[0], Command_Present_Value(rpdata->object_instance)); break; case PROP_IN_PROCESS: - apdu_len = - encode_application_boolean(&apdu[0], - Command_In_Process(rpdata->object_instance)); + apdu_len = encode_application_boolean( + &apdu[0], Command_In_Process(rpdata->object_instance)); break; case PROP_ALL_WRITES_SUCCESSFUL: - apdu_len = - encode_application_boolean(&apdu[0], + apdu_len = encode_application_boolean( + &apdu[0], Command_All_Writes_Successful(rpdata->object_instance)); break; case PROP_ACTION: /* TODO */ if (rpdata->array_index == 0) - apdu_len = encode_application_unsigned(&apdu[0], MAX_COMMAND_ACTIONS); + apdu_len = + encode_application_unsigned(&apdu[0], MAX_COMMAND_ACTIONS); else if (rpdata->array_index == BACNET_ARRAY_ALL) { int i; for (i = 0; i < MAX_COMMAND_ACTIONS; i++) { @@ -710,12 +648,12 @@ int Command_Read_Property( &CurrentCommand->Action[0]; /* another loop, for aditional actions in the list */ for (; Curr_CL_Member != NULL; - Curr_CL_Member = Curr_CL_Member->next) { - len = - cl_encode_apdu(&apdu[apdu_len], - &CurrentCommand->Action[0]); + Curr_CL_Member = Curr_CL_Member->next) { + len = cl_encode_apdu(&apdu[apdu_len], + &CurrentCommand->Action[0]); apdu_len += len; - /* assume the next one is of the same length, which need not be the case */ + /* assume the next one is of the same length, which need + * not be the case */ if ((i != MAX_COMMAND_ACTIONS - 1) && (apdu_len + len) >= apdu_max) { rpdata->error_code = @@ -731,12 +669,12 @@ int Command_Read_Property( &CurrentCommand->Action[rpdata->array_index]; /* another loop, for aditional actions in the list */ for (; Curr_CL_Member != NULL; - Curr_CL_Member = Curr_CL_Member->next) { - len = - cl_encode_apdu(&apdu[apdu_len], - &CurrentCommand->Action[0]); + Curr_CL_Member = Curr_CL_Member->next) { + len = cl_encode_apdu(&apdu[apdu_len], + &CurrentCommand->Action[0]); apdu_len += len; - /* assume the next one is of the same length, which need not be the case */ + /* assume the next one is of the same length, which need + * not be the case */ if ((apdu_len + len) >= apdu_max) { rpdata->error_code = ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED; @@ -758,8 +696,8 @@ int Command_Read_Property( break; } /* only array properties can have array options */ - if ((apdu_len >= 0) && (rpdata->object_property != PROP_ACTION) - && (rpdata->array_index != BACNET_ARRAY_ALL)) { + if ((apdu_len >= 0) && (rpdata->object_property != PROP_ACTION) && + (rpdata->array_index != BACNET_ARRAY_ALL)) { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; apdu_len = BACNET_STATUS_ERROR; @@ -777,17 +715,15 @@ int Command_Read_Property( * * @return false if an error is loaded, true if no errors */ -bool Command_Write_Property( - BACNET_WRITE_PROPERTY_DATA * wp_data) +bool Command_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data) { - bool status = false; /* return value */ + bool status = false; /* return value */ unsigned int object_index = 0; int len = 0; BACNET_APPLICATION_DATA_VALUE value; /* decode the some of the request */ - len = - bacapp_decode_application_data(wp_data->application_data, - wp_data->application_data_len, &value); + len = bacapp_decode_application_data(wp_data->application_data, + wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ if (len < 0) { /* error while decoding - a value larger than we can handle */ @@ -807,11 +743,11 @@ bool Command_Write_Property( return false; } - switch ((int) wp_data->object_property) { + switch ((int)wp_data->object_property) { case PROP_PRESENT_VALUE: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { if (value.type.Unsigned_Int >= MAX_COMMAND_ACTIONS) { wp_data->error_class = ERROR_CLASS_PROPERTY; @@ -819,7 +755,7 @@ bool Command_Write_Property( return false; } Command_Present_Value_Set(wp_data->object_instance, - value.type.Unsigned_Int); + value.type.Unsigned_Int); } else { wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED; @@ -846,8 +782,7 @@ bool Command_Write_Property( return status; } -void Command_Intrinsic_Reporting( - uint32_t object_instance) +void Command_Intrinsic_Reporting(uint32_t object_instance) { } @@ -856,11 +791,9 @@ void Command_Intrinsic_Reporting( #include #include "ctest.h" -bool WPValidateArgType( - BACNET_APPLICATION_DATA_VALUE * pValue, - uint8_t ucExpectedTag, - BACNET_ERROR_CLASS * pErrorClass, - BACNET_ERROR_CODE * pErrorCode) +bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue, + uint8_t ucExpectedTag, BACNET_ERROR_CLASS *pErrorClass, + BACNET_ERROR_CODE *pErrorCode) { bool bResult; @@ -878,10 +811,9 @@ bool WPValidateArgType( return (bResult); } -void testCommand( - Test * pTest) +void testCommand(Test *pTest) { - uint8_t apdu[MAX_APDU] = { 0 }; + uint8_t apdu[MAX_APDU] = {0}; int len = 0; uint32_t len_value = 0; uint8_t tag_number = 0; @@ -926,10 +858,9 @@ void testCommand( ct_test(pTest, clist.Device_Id.instance == clist_test.Device_Id.instance); ct_test(pTest, clist.Object_Id.type == clist_test.Object_Id.type); ct_test(pTest, clist.Object_Id.instance == clist_test.Object_Id.instance); + ct_test(pTest, clist.Property_Identifier == clist_test.Property_Identifier); ct_test(pTest, - clist.Property_Identifier == clist_test.Property_Identifier); - ct_test(pTest, - clist.Property_Array_Index == clist_test.Property_Array_Index); + clist.Property_Array_Index == clist_test.Property_Array_Index); ct_test(pTest, clist.Value.tag == clist_test.Value.tag); ct_test(pTest, clist.Value.type.Real == clist_test.Value.type.Real); ct_test(pTest, clist.Priority == clist_test.Priority); @@ -940,8 +871,7 @@ void testCommand( } #ifdef TEST_COMMAND -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -953,7 +883,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/demo/object/credential_data_input.c b/demo/object/credential_data_input.c index 2b2c14a0..85ff8289 100644 --- a/demo/object/credential_data_input.c +++ b/demo/object/credential_data_input.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2015 Nikola Jelic -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2015 Nikola Jelic + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* Credential Data Input Objects - customize for your use */ @@ -33,7 +33,7 @@ #include "bacdcode.h" #include "bacenum.h" #include "bacapp.h" -#include "config.h" /* the custom stuff */ +#include "config.h" /* the custom stuff */ #include "wp.h" #include "credential_data_input.h" #include "handlers.h" @@ -44,30 +44,19 @@ static CREDENTIAL_DATA_INPUT_DESCR cdi_descr[MAX_CREDENTIAL_DATA_INPUTS]; /* These three arrays are used by the ReadPropertyMultiple handler */ static const int Properties_Required[] = { - PROP_OBJECT_IDENTIFIER, - PROP_OBJECT_NAME, - PROP_OBJECT_TYPE, - PROP_PRESENT_VALUE, - PROP_STATUS_FLAGS, - PROP_RELIABILITY, - PROP_OUT_OF_SERVICE, - PROP_SUPPORTED_FORMATS, - PROP_UPDATE_TIME, - -1 -}; + PROP_OBJECT_IDENTIFIER, PROP_OBJECT_NAME, + PROP_OBJECT_TYPE, PROP_PRESENT_VALUE, + PROP_STATUS_FLAGS, PROP_RELIABILITY, + PROP_OUT_OF_SERVICE, PROP_SUPPORTED_FORMATS, + PROP_UPDATE_TIME, -1}; -static const int Properties_Optional[] = { - -1 -}; +static const int Properties_Optional[] = {-1}; -static const int Properties_Proprietary[] = { - -1 -}; +static const int Properties_Proprietary[] = {-1}; -void Credential_Data_Input_Property_Lists( - const int **pRequired, - const int **pOptional, - const int **pProprietary) +void Credential_Data_Input_Property_Lists(const int **pRequired, + const int **pOptional, + const int **pProprietary) { if (pRequired) *pRequired = Properties_Required; @@ -79,8 +68,7 @@ void Credential_Data_Input_Property_Lists( return; } -void Credential_Data_Input_Init( - void) +void Credential_Data_Input_Init(void) { unsigned i; @@ -107,8 +95,7 @@ void Credential_Data_Input_Init( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need validate that the */ /* given instance exists */ -bool Credential_Data_Input_Valid_Instance( - uint32_t object_instance) +bool Credential_Data_Input_Valid_Instance(uint32_t object_instance) { if (object_instance < MAX_CREDENTIAL_DATA_INPUTS) return true; @@ -118,8 +105,7 @@ bool Credential_Data_Input_Valid_Instance( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then count how many you have */ -unsigned Credential_Data_Input_Count( - void) +unsigned Credential_Data_Input_Count(void) { return MAX_CREDENTIAL_DATA_INPUTS; } @@ -127,8 +113,7 @@ unsigned Credential_Data_Input_Count( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need to return the instance */ /* that correlates to the correct index */ -uint32_t Credential_Data_Input_Index_To_Instance( - unsigned index) +uint32_t Credential_Data_Input_Index_To_Instance(unsigned index) { return index; } @@ -136,8 +121,7 @@ uint32_t Credential_Data_Input_Index_To_Instance( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need to return the index */ /* that correlates to the correct instance number */ -unsigned Credential_Data_Input_Instance_To_Index( - uint32_t object_instance) +unsigned Credential_Data_Input_Instance_To_Index(uint32_t object_instance) { unsigned index = MAX_CREDENTIAL_DATA_INPUTS; @@ -148,24 +132,22 @@ unsigned Credential_Data_Input_Instance_To_Index( } /* note: the object name must be unique within this device */ -bool Credential_Data_Input_Object_Name( - uint32_t object_instance, - BACNET_CHARACTER_STRING * object_name) +bool Credential_Data_Input_Object_Name(uint32_t object_instance, + BACNET_CHARACTER_STRING *object_name) { - static char text_string[32] = ""; /* okay for single thread */ + static char text_string[32] = ""; /* okay for single thread */ bool status = false; if (object_instance < MAX_CREDENTIAL_DATA_INPUTS) { sprintf(text_string, "CREDENTIAL DATA INPUT %lu", - (unsigned long) object_instance); + (unsigned long)object_instance); status = characterstring_init_ansi(object_name, text_string); } return status; } -bool Credential_Data_Input_Out_Of_Service( - uint32_t instance) +bool Credential_Data_Input_Out_Of_Service(uint32_t instance) { unsigned index = 0; bool oos_flag = false; @@ -178,9 +160,7 @@ bool Credential_Data_Input_Out_Of_Service( return oos_flag; } -void Credential_Data_Input_Out_Of_Service_Set( - uint32_t instance, - bool oos_flag) +void Credential_Data_Input_Out_Of_Service_Set(uint32_t instance, bool oos_flag) { unsigned index = 0; @@ -191,11 +171,10 @@ void Credential_Data_Input_Out_Of_Service_Set( } /* return apdu len, or BACNET_STATUS_ERROR on error */ -int Credential_Data_Input_Read_Property( - BACNET_READ_PROPERTY_DATA * rpdata) +int Credential_Data_Input_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata) { int len = 0; - int apdu_len = 0; /* return value */ + int apdu_len = 0; /* return value */ BACNET_BIT_STRING bit_string; BACNET_CHARACTER_STRING char_string; unsigned object_index = 0; @@ -212,25 +191,23 @@ int Credential_Data_Input_Read_Property( Credential_Data_Input_Instance_To_Index(rpdata->object_instance); switch (rpdata->object_property) { case PROP_OBJECT_IDENTIFIER: - apdu_len = - encode_application_object_id(&apdu[0], - OBJECT_CREDENTIAL_DATA_INPUT, rpdata->object_instance); + apdu_len = encode_application_object_id( + &apdu[0], OBJECT_CREDENTIAL_DATA_INPUT, + rpdata->object_instance); break; case PROP_OBJECT_NAME: Credential_Data_Input_Object_Name(rpdata->object_instance, - &char_string); + &char_string); apdu_len = encode_application_character_string(&apdu[0], &char_string); break; case PROP_OBJECT_TYPE: - apdu_len = - encode_application_enumerated(&apdu[0], - OBJECT_CREDENTIAL_DATA_INPUT); + apdu_len = encode_application_enumerated( + &apdu[0], OBJECT_CREDENTIAL_DATA_INPUT); break; case PROP_PRESENT_VALUE: - apdu_len = - bacapp_encode_authentication_factor(&apdu[apdu_len], - &cdi_descr[object_index].present_value); + apdu_len = bacapp_encode_authentication_factor( + &apdu[apdu_len], &cdi_descr[object_index].present_value); break; case PROP_STATUS_FLAGS: bitstring_init(&bit_string); @@ -243,9 +220,8 @@ int Credential_Data_Input_Read_Property( apdu_len = encode_application_bitstring(&apdu[0], &bit_string); break; case PROP_RELIABILITY: - apdu_len = - encode_application_enumerated(&apdu[0], - cdi_descr[object_index].reliability); + apdu_len = encode_application_enumerated( + &apdu[0], cdi_descr[object_index].reliability); break; case PROP_OUT_OF_SERVICE: state = @@ -254,14 +230,13 @@ int Credential_Data_Input_Read_Property( break; case PROP_SUPPORTED_FORMATS: if (rpdata->array_index == 0) { - apdu_len = - encode_application_unsigned(&apdu[0], - cdi_descr[object_index].supported_formats_count); + apdu_len = encode_application_unsigned( + &apdu[0], cdi_descr[object_index].supported_formats_count); } else if (rpdata->array_index == BACNET_ARRAY_ALL) { for (i = 0; i < cdi_descr[object_index].supported_formats_count; - i++) { - len = - bacapp_encode_authentication_factor_format(&apdu[0], + i++) { + len = bacapp_encode_authentication_factor_format( + &apdu[0], &cdi_descr[object_index].supported_formats[i]); if (apdu_len + len < MAX_APDU) apdu_len += len; @@ -275,10 +250,10 @@ int Credential_Data_Input_Read_Property( } else { if (rpdata->array_index <= cdi_descr[object_index].supported_formats_count) { - apdu_len = - bacapp_encode_authentication_factor_format(&apdu[0], - &cdi_descr[object_index]. - supported_formats[rpdata->array_index - 1]); + apdu_len = bacapp_encode_authentication_factor_format( + &apdu[0], + &cdi_descr[object_index] + .supported_formats[rpdata->array_index - 1]); } else { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX; @@ -288,9 +263,8 @@ int Credential_Data_Input_Read_Property( break; case PROP_UPDATE_TIME: - apdu_len = - bacapp_encode_timestamp(&apdu[0], - &cdi_descr[object_index].timestamp); + apdu_len = bacapp_encode_timestamp( + &apdu[0], &cdi_descr[object_index].timestamp); break; default: rpdata->error_class = ERROR_CLASS_PROPERTY; @@ -299,8 +273,9 @@ int Credential_Data_Input_Read_Property( break; } /* only array properties can have array options */ - if ((apdu_len >= 0) && (rpdata->object_property != PROP_SUPPORTED_FORMATS) - && (rpdata->array_index != BACNET_ARRAY_ALL)) { + if ((apdu_len >= 0) && + (rpdata->object_property != PROP_SUPPORTED_FORMATS) && + (rpdata->array_index != BACNET_ARRAY_ALL)) { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; apdu_len = BACNET_STATUS_ERROR; @@ -310,18 +285,16 @@ int Credential_Data_Input_Read_Property( } /* returns true if successful */ -bool Credential_Data_Input_Write_Property( - BACNET_WRITE_PROPERTY_DATA * wp_data) +bool Credential_Data_Input_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data) { - bool status = false; /* return value */ + bool status = false; /* return value */ int len = 0; BACNET_APPLICATION_DATA_VALUE value; unsigned object_index = 0; /* decode the some of the request */ - len = - bacapp_decode_application_data(wp_data->application_data, - wp_data->application_data_len, &value); + len = bacapp_decode_application_data(wp_data->application_data, + wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ if (len < 0) { /* error while decoding - a value larger than we can handle */ @@ -336,17 +309,18 @@ bool Credential_Data_Input_Write_Property( wp_data->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; return false; } - object_index = Credential_Data_Input_Instance_To_Index(wp_data->object_instance); + object_index = + Credential_Data_Input_Instance_To_Index(wp_data->object_instance); switch (wp_data->object_property) { case PROP_PRESENT_VALUE: - if (Credential_Data_Input_Out_Of_Service(wp_data->object_instance)) { + if (Credential_Data_Input_Out_Of_Service( + wp_data->object_instance)) { BACNET_AUTHENTICATION_FACTOR tmp; - len = - bacapp_decode_authentication_factor(wp_data-> - application_data, &tmp); + len = bacapp_decode_authentication_factor( + wp_data->application_data, &tmp); if (len > 0) { memcpy(&cdi_descr[object_index].present_value, &tmp, - sizeof(BACNET_AUTHENTICATION_FACTOR)); + sizeof(BACNET_AUTHENTICATION_FACTOR)); } else { wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; @@ -357,14 +331,13 @@ bool Credential_Data_Input_Write_Property( } break; case PROP_RELIABILITY: - if (Credential_Data_Input_Out_Of_Service(wp_data->object_instance)) { - status = - WPValidateArgType(&value, - BACNET_APPLICATION_TAG_ENUMERATED, &wp_data->error_class, - &wp_data->error_code); + if (Credential_Data_Input_Out_Of_Service( + wp_data->object_instance)) { + status = WPValidateArgType( + &value, BACNET_APPLICATION_TAG_ENUMERATED, + &wp_data->error_class, &wp_data->error_code); if (status) { - cdi_descr[object_index].reliability = - value.type.Enumerated; + cdi_descr[object_index].reliability = value.type.Enumerated; } } else { wp_data->error_class = ERROR_CLASS_PROPERTY; @@ -390,17 +363,14 @@ bool Credential_Data_Input_Write_Property( return status; } - #ifdef TEST #include #include #include "ctest.h" -bool WPValidateArgType( - BACNET_APPLICATION_DATA_VALUE * pValue, - uint8_t ucExpectedTag, - BACNET_ERROR_CLASS * pErrorClass, - BACNET_ERROR_CODE * pErrorCode) +bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue, + uint8_t ucExpectedTag, BACNET_ERROR_CLASS *pErrorClass, + BACNET_ERROR_CODE *pErrorCode) { pValue = pValue; ucExpectedTag = ucExpectedTag; @@ -410,10 +380,9 @@ bool WPValidateArgType( return false; } -void testCredentialDataInput( - Test * pTest) +void testCredentialDataInput(Test *pTest) { - uint8_t apdu[MAX_APDU] = { 0 }; + uint8_t apdu[MAX_APDU] = {0}; int len = 0; uint32_t len_value = 0; uint8_t tag_number = 0; @@ -440,8 +409,7 @@ void testCredentialDataInput( } #ifdef TEST_CREDENTIAL_DATA_INPUT -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -453,7 +421,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/demo/object/csv.c b/demo/object/csv.c index 730b5baa..404303cc 100644 --- a/demo/object/csv.c +++ b/demo/object/csv.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2012 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2012 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* CharacterString Value Objects */ @@ -32,7 +32,7 @@ #include "bacdcode.h" #include "bacenum.h" #include "bacapp.h" -#include "config.h" /* the custom stuff */ +#include "config.h" /* the custom stuff */ #include "rp.h" #include "wp.h" #include "csv.h" @@ -52,29 +52,17 @@ static char Object_Description[MAX_CHARACTERSTRING_VALUES][64]; /* These three arrays are used by the ReadPropertyMultiple handler */ static const int Properties_Required[] = { - PROP_OBJECT_IDENTIFIER, - PROP_OBJECT_NAME, - PROP_OBJECT_TYPE, - PROP_PRESENT_VALUE, - PROP_STATUS_FLAGS, - -1 -}; + PROP_OBJECT_IDENTIFIER, PROP_OBJECT_NAME, PROP_OBJECT_TYPE, + PROP_PRESENT_VALUE, PROP_STATUS_FLAGS, -1}; -static const int Properties_Optional[] = { - PROP_EVENT_STATE, - PROP_OUT_OF_SERVICE, - PROP_DESCRIPTION, - -1 -}; +static const int Properties_Optional[] = {PROP_EVENT_STATE, PROP_OUT_OF_SERVICE, + PROP_DESCRIPTION, -1}; -static const int Properties_Proprietary[] = { - -1 -}; +static const int Properties_Proprietary[] = {-1}; -void CharacterString_Value_Property_Lists( - const int **pRequired, - const int **pOptional, - const int **pProprietary) +void CharacterString_Value_Property_Lists(const int **pRequired, + const int **pOptional, + const int **pProprietary) { if (pRequired) *pRequired = Properties_Required; @@ -86,17 +74,16 @@ void CharacterString_Value_Property_Lists( return; } -void CharacterString_Value_Init( - void) +void CharacterString_Value_Init(void) { unsigned i; /* initialize all Present Values */ for (i = 0; i < MAX_CHARACTERSTRING_VALUES; i++) { snprintf(&Object_Name[i][0], sizeof(Object_Name[i]), - "CHARACTER STRING VALUE %u", i+1); + "CHARACTER STRING VALUE %u", i + 1); snprintf(&Object_Description[i][0], sizeof(Object_Description[i]), - "A Character String Value Example"); + "A Character String Value Example"); characterstring_init_ansi(&Present_Value[i], ""); } @@ -106,8 +93,7 @@ void CharacterString_Value_Init( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need to return the index */ /* that correlates to the correct instance number */ -unsigned CharacterString_Value_Instance_To_Index( - uint32_t object_instance) +unsigned CharacterString_Value_Instance_To_Index(uint32_t object_instance) { unsigned index = MAX_CHARACTERSTRING_VALUES; @@ -121,22 +107,19 @@ unsigned CharacterString_Value_Instance_To_Index( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need to return the instance */ /* that correlates to the correct index */ -uint32_t CharacterString_Value_Index_To_Instance( - unsigned index) +uint32_t CharacterString_Value_Index_To_Instance(unsigned index) { return index; } /* we simply have 0-n object instances. Yours might be */ /* more complex, and then count how many you have */ -unsigned CharacterString_Value_Count( - void) +unsigned CharacterString_Value_Count(void) { return MAX_CHARACTERSTRING_VALUES; } -bool CharacterString_Value_Valid_Instance( - uint32_t object_instance) +bool CharacterString_Value_Valid_Instance(uint32_t object_instance) { unsigned index = 0; /* offset from instance lookup */ @@ -148,9 +131,8 @@ bool CharacterString_Value_Valid_Instance( return false; } -bool CharacterString_Value_Present_Value( - uint32_t object_instance, - BACNET_CHARACTER_STRING * object_name) +bool CharacterString_Value_Present_Value(uint32_t object_instance, + BACNET_CHARACTER_STRING *object_name) { bool status = false; unsigned index = 0; /* offset from instance lookup */ @@ -164,8 +146,7 @@ bool CharacterString_Value_Present_Value( } bool CharacterString_Value_Present_Value_Set( - uint32_t object_instance, - BACNET_CHARACTER_STRING * object_name) + uint32_t object_instance, BACNET_CHARACTER_STRING *object_name) { bool status = false; unsigned index = 0; /* offset from instance lookup */ @@ -178,8 +159,7 @@ bool CharacterString_Value_Present_Value_Set( return status; } -bool CharacterString_Value_Out_Of_Service( - uint32_t object_instance) +bool CharacterString_Value_Out_Of_Service(uint32_t object_instance) { bool value = false; unsigned index = 0; @@ -192,9 +172,8 @@ bool CharacterString_Value_Out_Of_Service( return value; } -static void CharacterString_Value_Out_Of_Service_Set( - uint32_t object_instance, - bool value) +static void CharacterString_Value_Out_Of_Service_Set(uint32_t object_instance, + bool value) { unsigned index = 0; @@ -206,8 +185,7 @@ static void CharacterString_Value_Out_Of_Service_Set( return; } -static char *CharacterString_Value_Description( - uint32_t object_instance) +static char *CharacterString_Value_Description(uint32_t object_instance) { unsigned index = 0; /* offset from instance lookup */ char *pName = NULL; /* return value */ @@ -220,13 +198,12 @@ static char *CharacterString_Value_Description( return pName; } -bool CharacterString_Value_Description_Set( - uint32_t object_instance, - char *new_name) +bool CharacterString_Value_Description_Set(uint32_t object_instance, + char *new_name) { - unsigned index = 0; /* offset from instance lookup */ - size_t i = 0; /* loop counter */ - bool status = false; /* return value */ + unsigned index = 0; /* offset from instance lookup */ + size_t i = 0; /* loop counter */ + bool status = false; /* return value */ index = CharacterString_Value_Instance_To_Index(object_instance); if (index < MAX_CHARACTERSTRING_VALUES) { @@ -248,9 +225,8 @@ bool CharacterString_Value_Description_Set( return status; } -bool CharacterString_Value_Object_Name( - uint32_t object_instance, - BACNET_CHARACTER_STRING * object_name) +bool CharacterString_Value_Object_Name(uint32_t object_instance, + BACNET_CHARACTER_STRING *object_name) { unsigned index = 0; /* offset from instance lookup */ bool status = false; @@ -264,13 +240,11 @@ bool CharacterString_Value_Object_Name( } /* note: the object name must be unique within this device */ -bool CharacterString_Value_Name_Set( - uint32_t object_instance, - char *new_name) +bool CharacterString_Value_Name_Set(uint32_t object_instance, char *new_name) { - unsigned index = 0; /* offset from instance lookup */ - size_t i = 0; /* loop counter */ - bool status = false; /* return value */ + unsigned index = 0; /* offset from instance lookup */ + size_t i = 0; /* loop counter */ + bool status = false; /* return value */ index = CharacterString_Value_Instance_To_Index(object_instance); if (index < MAX_CHARACTERSTRING_VALUES) { @@ -294,10 +268,9 @@ bool CharacterString_Value_Name_Set( } /* return apdu len, or BACNET_STATUS_ERROR on error */ -int CharacterString_Value_Read_Property( - BACNET_READ_PROPERTY_DATA * rpdata) +int CharacterString_Value_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata) { - int apdu_len = 0; /* return value */ + int apdu_len = 0; /* return value */ BACNET_BIT_STRING bit_string; BACNET_CHARACTER_STRING char_string; unsigned object_index = 0; @@ -311,32 +284,32 @@ int CharacterString_Value_Read_Property( apdu = rpdata->application_data; switch (rpdata->object_property) { case PROP_OBJECT_IDENTIFIER: - apdu_len = - encode_application_object_id(&apdu[0], - OBJECT_CHARACTERSTRING_VALUE, rpdata->object_instance); + apdu_len = encode_application_object_id( + &apdu[0], OBJECT_CHARACTERSTRING_VALUE, + rpdata->object_instance); break; /* note: Name and Description don't have to be the same. You could make Description writable and different */ case PROP_OBJECT_NAME: CharacterString_Value_Object_Name(rpdata->object_instance, - &char_string); + &char_string); apdu_len = encode_application_character_string(&apdu[0], &char_string); break; case PROP_DESCRIPTION: - characterstring_init_ansi(&char_string, + characterstring_init_ansi( + &char_string, CharacterString_Value_Description(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_CHARACTERSTRING_VALUE); + apdu_len = encode_application_enumerated( + &apdu[0], OBJECT_CHARACTERSTRING_VALUE); break; case PROP_PRESENT_VALUE: CharacterString_Value_Present_Value(rpdata->object_instance, - &char_string); + &char_string); apdu_len = encode_application_character_string(&apdu[0], &char_string); break; @@ -348,10 +321,10 @@ int CharacterString_Value_Read_Property( bitstring_set_bit(&bit_string, STATUS_FLAG_OVERRIDDEN, false); if (CharacterString_Value_Out_Of_Service(rpdata->object_instance)) { bitstring_set_bit(&bit_string, STATUS_FLAG_OUT_OF_SERVICE, - true); + true); } else { bitstring_set_bit(&bit_string, STATUS_FLAG_OUT_OF_SERVICE, - false); + false); } apdu_len = encode_application_bitstring(&apdu[0], &bit_string); break; @@ -361,9 +334,8 @@ int CharacterString_Value_Read_Property( encode_application_enumerated(&apdu[0], EVENT_STATE_NORMAL); break; case PROP_OUT_OF_SERVICE: - object_index = - CharacterString_Value_Instance_To_Index - (rpdata->object_instance); + object_index = CharacterString_Value_Instance_To_Index( + rpdata->object_instance); state = Out_Of_Service[object_index]; apdu_len = encode_application_boolean(&apdu[0], state); break; @@ -385,17 +357,15 @@ int CharacterString_Value_Read_Property( } /* returns true if successful */ -bool CharacterString_Value_Write_Property( - BACNET_WRITE_PROPERTY_DATA * wp_data) +bool CharacterString_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data) { - bool status = false; /* return value */ + bool status = false; /* return value */ int len = 0; BACNET_APPLICATION_DATA_VALUE value; /* decode the some of the request */ - len = - bacapp_decode_application_data(wp_data->application_data, - wp_data->application_data_len, &value); + len = bacapp_decode_application_data(wp_data->application_data, + wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ if (len < 0) { /* error while decoding - a value larger than we can handle */ @@ -405,14 +375,12 @@ bool CharacterString_Value_Write_Property( } switch (wp_data->object_property) { case PROP_PRESENT_VALUE: - status = - WPValidateArgType(&value, - BACNET_APPLICATION_TAG_CHARACTER_STRING, &wp_data->error_class, - &wp_data->error_code); + status = WPValidateArgType( + &value, BACNET_APPLICATION_TAG_CHARACTER_STRING, + &wp_data->error_class, &wp_data->error_code); if (status) { - status = - CharacterString_Value_Present_Value_Set - (wp_data->object_instance, &value.type.Character_String); + status = CharacterString_Value_Present_Value_Set( + wp_data->object_instance, &value.type.Character_String); if (!status) { wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; @@ -422,10 +390,10 @@ bool CharacterString_Value_Write_Property( case PROP_OUT_OF_SERVICE: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { - CharacterString_Value_Out_Of_Service_Set - (wp_data->object_instance, value.type.Boolean); + CharacterString_Value_Out_Of_Service_Set( + wp_data->object_instance, value.type.Boolean); } break; case PROP_OBJECT_IDENTIFIER: @@ -446,17 +414,14 @@ bool CharacterString_Value_Write_Property( return status; } - #ifdef TEST #include #include #include "ctest.h" -bool WPValidateArgType( - BACNET_APPLICATION_DATA_VALUE * pValue, - uint8_t ucExpectedTag, - BACNET_ERROR_CLASS * pErrorClass, - BACNET_ERROR_CODE * pErrorCode) +bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue, + uint8_t ucExpectedTag, BACNET_ERROR_CLASS *pErrorClass, + BACNET_ERROR_CODE *pErrorCode) { pValue = pValue; ucExpectedTag = ucExpectedTag; @@ -466,10 +431,9 @@ bool WPValidateArgType( return false; } -void testCharacterStringValue( - Test * pTest) +void testCharacterStringValue(Test *pTest) { - uint8_t apdu[MAX_APDU] = { 0 }; + uint8_t apdu[MAX_APDU] = {0}; int len = 0; uint32_t len_value = 0; uint8_t tag_number = 0; @@ -496,8 +460,7 @@ void testCharacterStringValue( } #ifdef TEST_CHARACTERSTRING_VALUE -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -509,7 +472,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/demo/object/device-client.c b/demo/object/device-client.c index 90727ab9..dc2916c2 100644 --- a/demo/object/device-client.c +++ b/demo/object/device-client.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2011 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2011 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /** @file device-client.c Lightweight base "class" for handling all * BACnet objects belonging to a BACnet device, as well as @@ -30,8 +30,8 @@ #include #include -#include /* for memmove */ -#include /* for timezone, localtime */ +#include /* for memmove */ +#include /* for timezone, localtime */ /* OS specific include*/ #include "net.h" #include "timer.h" @@ -40,7 +40,7 @@ #include "bacdcode.h" #include "bacenum.h" #include "bacapp.h" -#include "config.h" /* the custom stuff */ +#include "config.h" /* the custom stuff */ #include "apdu.h" #include "rp.h" /* ReadProperty handling */ #include "version.h" @@ -51,7 +51,7 @@ #include "netport.h" #endif /* include the device object */ -#include "device.h" /* me */ +#include "device.h" /* me */ #if defined(__BORLANDC__) || defined(_WIN32) /* seems to not be defined in time.h as specified by The Open Group */ @@ -82,14 +82,14 @@ static char *Description = "command line client"; /* 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. BACnet UTC offset is expressed in minutes. */ static int32_t UTC_Offset = 5 * 60; -static bool Daylight_Savings_Status = false; /* rely on OS */ +static bool Daylight_Savings_Status = false; /* rely on OS */ #if defined(BACNET_TIME_MASTER) static bool Align_Intervals; static uint32_t Interval_Minutes; @@ -112,68 +112,40 @@ static uint32_t Database_Revision = 0; /* Profile_Name */ /* local forward (semi-private) and external prototypes */ -int Device_Read_Property_Local( - BACNET_READ_PROPERTY_DATA * rpdata); -extern int Routed_Device_Read_Property_Local( - BACNET_READ_PROPERTY_DATA * rpdata); +int Device_Read_Property_Local(BACNET_READ_PROPERTY_DATA *rpdata); +extern int Routed_Device_Read_Property_Local(BACNET_READ_PROPERTY_DATA *rpdata); extern bool Routed_Device_Write_Property_Local( - BACNET_WRITE_PROPERTY_DATA * wp_data); + BACNET_WRITE_PROPERTY_DATA *wp_data); /* All included BACnet objects */ static object_functions_t Object_Table[] = { - {OBJECT_DEVICE, - NULL /* Init - don't init Device or it will recourse! */ , - Device_Count, - Device_Index_To_Instance, - Device_Valid_Object_Instance_Number, - Device_Object_Name, - Device_Read_Property_Local, - NULL /* Write_Property */ , - NULL /* Property_Lists */ , - NULL /* ReadRangeInfo */ , - NULL /* Iterator */ , - NULL /* Value_Lists */ , - NULL /* COV */ , - NULL /* COV Clear */ , - NULL /* Intrinsic Reporting */ }, + {OBJECT_DEVICE, NULL /* Init - don't init Device or it will recourse! */, + Device_Count, Device_Index_To_Instance, + Device_Valid_Object_Instance_Number, Device_Object_Name, + Device_Read_Property_Local, NULL /* Write_Property */, + NULL /* Property_Lists */, NULL /* ReadRangeInfo */, NULL /* Iterator */, + NULL /* Value_Lists */, NULL /* COV */, NULL /* COV Clear */, + NULL /* Intrinsic Reporting */}, #if (BACNET_PROTOCOL_REVISION >= 17) - {OBJECT_NETWORK_PORT, - Network_Port_Init, - Network_Port_Count, - Network_Port_Index_To_Instance, - Network_Port_Valid_Instance, - Network_Port_Object_Name, - Network_Port_Read_Property, - Network_Port_Write_Property, - Network_Port_Property_Lists, - NULL /* ReadRangeInfo */ , - NULL /* Iterator */ , - NULL /* Value_Lists */ , - NULL /* COV */ , - NULL /* COV Clear */ , - NULL /* Intrinsic Reporting */ }, + {OBJECT_NETWORK_PORT, Network_Port_Init, Network_Port_Count, + Network_Port_Index_To_Instance, Network_Port_Valid_Instance, + Network_Port_Object_Name, Network_Port_Read_Property, + Network_Port_Write_Property, Network_Port_Property_Lists, + NULL /* ReadRangeInfo */, NULL /* Iterator */, NULL /* Value_Lists */, + NULL /* COV */, NULL /* COV Clear */, NULL /* Intrinsic Reporting */}, #endif - {MAX_BACNET_OBJECT_TYPE, - NULL /* Init */ , - NULL /* Count */ , - NULL /* Index_To_Instance */ , - NULL /* Valid_Instance */ , - NULL /* Object_Name */ , - NULL /* Read_Property */ , - NULL /* Write_Property */ , - NULL /* Property_Lists */ , - NULL /* ReadRangeInfo */ , - NULL /* Iterator */ , - NULL /* Value_Lists */ , - NULL /* COV */ , - NULL /* COV Clear */ , - NULL /* Intrinsic Reporting */ } -}; + {MAX_BACNET_OBJECT_TYPE, NULL /* Init */, NULL /* Count */, + NULL /* Index_To_Instance */, NULL /* Valid_Instance */, + NULL /* Object_Name */, NULL /* Read_Property */, + NULL /* Write_Property */, NULL /* Property_Lists */, + NULL /* ReadRangeInfo */, NULL /* Iterator */, NULL /* Value_Lists */, + NULL /* COV */, NULL /* COV Clear */, NULL /* Intrinsic Reporting */}}; /** Glue function to let the Device object, when called by a handler, * lookup which Object type needs to be invoked. * @ingroup ObjHelpers - * @param Object_Type [in] The type of BACnet Object the handler wants to access. + * @param Object_Type [in] The type of BACnet Object the handler wants to + * access. * @return Pointer to the group of object helper functions that implement this * type of Object. */ @@ -195,14 +167,12 @@ static struct object_functions *Device_Objects_Find_Functions( return (NULL); } -unsigned Device_Count( - void) +unsigned Device_Count(void) { return 1; } -uint32_t Device_Index_To_Instance( - unsigned index) +uint32_t Device_Index_To_Instance(unsigned index) { index = index; return Object_Instance_Number; @@ -216,8 +186,7 @@ uint32_t Device_Index_To_Instance( * @ingroup ObjIntf * @return The Instance number used in the BACNET_OBJECT_ID for the Device. */ -uint32_t Device_Object_Instance_Number( - void) +uint32_t Device_Object_Instance_Number(void) { #ifdef BAC_ROUTING return Routed_Device_Object_Instance_Number(); @@ -226,8 +195,7 @@ uint32_t Device_Object_Instance_Number( #endif } -bool Device_Set_Object_Instance_Number( - uint32_t object_id) +bool Device_Set_Object_Instance_Number(uint32_t object_id) { bool status = true; /* return value */ @@ -241,15 +209,13 @@ bool Device_Set_Object_Instance_Number( return status; } -bool Device_Valid_Object_Instance_Number( - uint32_t object_id) +bool Device_Valid_Object_Instance_Number(uint32_t object_id) { return (Object_Instance_Number == object_id); } -bool Device_Object_Name( - uint32_t object_instance, - BACNET_CHARACTER_STRING * object_name) +bool Device_Object_Name(uint32_t object_instance, + BACNET_CHARACTER_STRING *object_name) { bool status = false; @@ -260,10 +226,9 @@ bool Device_Object_Name( return status; } -bool Device_Set_Object_Name( - BACNET_CHARACTER_STRING * object_name) +bool Device_Set_Object_Name(BACNET_CHARACTER_STRING *object_name) { - bool status = false; /*return value */ + bool status = false; /*return value */ if (!characterstring_same(&My_Object_Name, object_name)) { /* Make the change and update the database revision */ @@ -274,17 +239,14 @@ bool Device_Set_Object_Name( return status; } -BACNET_DEVICE_STATUS Device_System_Status( - void) +BACNET_DEVICE_STATUS Device_System_Status(void) { return System_Status; } -int Device_Set_System_Status( - BACNET_DEVICE_STATUS status, - bool local) +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. */ @@ -345,39 +307,34 @@ int Device_Set_System_Status( return (result); } -const char *Device_Vendor_Name( - void) +const char *Device_Vendor_Name(void) { return Vendor_Name; } /** Returns the Vendor ID for this Device. - * See the assignments at http://www.bacnet.org/VendorID/BACnet%20Vendor%20IDs.htm + * See the assignments at + * http://www.bacnet.org/VendorID/BACnet%20Vendor%20IDs.htm * @return The Vendor ID of this Device. */ -uint16_t Device_Vendor_Identifier( - void) +uint16_t Device_Vendor_Identifier(void) { return Vendor_Identifier; } -void Device_Set_Vendor_Identifier( - uint16_t vendor_id) +void Device_Set_Vendor_Identifier(uint16_t vendor_id) { Vendor_Identifier = vendor_id; } -const char *Device_Model_Name( - void) +const char *Device_Model_Name(void) { return Model_Name; } -bool Device_Set_Model_Name( - const char *name, - size_t length) +bool Device_Set_Model_Name(const char *name, size_t length) { - bool status = false; /*return value */ + bool status = false; /*return value */ if (length < sizeof(Model_Name)) { memmove(Model_Name, name, length); @@ -388,23 +345,19 @@ bool Device_Set_Model_Name( return status; } -const char *Device_Firmware_Revision( - void) +const char *Device_Firmware_Revision(void) { return BACnet_Version; } -const char *Device_Application_Software_Version( - void) +const char *Device_Application_Software_Version(void) { return Application_Software_Version; } -bool Device_Set_Application_Software_Version( - const char *name, - size_t length) +bool Device_Set_Application_Software_Version(const char *name, size_t length) { - bool status = false; /*return value */ + bool status = false; /*return value */ if (length < sizeof(Application_Software_Version)) { memmove(Application_Software_Version, name, length); @@ -415,17 +368,14 @@ bool Device_Set_Application_Software_Version( return status; } -const char *Device_Description( - void) +const char *Device_Description(void) { return Description; } -bool Device_Set_Description( - const char *name, - size_t length) +bool Device_Set_Description(const char *name, size_t length) { - bool status = false; /*return value */ + bool status = false; /*return value */ if (length < sizeof(Description)) { memmove(Description, name, length); @@ -436,17 +386,14 @@ bool Device_Set_Description( return status; } -const char *Device_Location( - void) +const char *Device_Location(void) { return Location; } -bool Device_Set_Location( - const char *name, - size_t length) +bool Device_Set_Location(const char *name, size_t length) { - bool status = false; /*return value */ + bool status = false; /*return value */ if (length < sizeof(Location)) { memmove(Location, name, length); @@ -457,32 +404,27 @@ bool Device_Set_Location( return status; } -uint8_t Device_Protocol_Version( - void) +uint8_t Device_Protocol_Version(void) { return BACNET_PROTOCOL_VERSION; } -uint8_t Device_Protocol_Revision( - void) +uint8_t Device_Protocol_Revision(void) { return BACNET_PROTOCOL_REVISION; } -BACNET_SEGMENTATION Device_Segmentation_Supported( - void) +BACNET_SEGMENTATION Device_Segmentation_Supported(void) { return SEGMENTATION_NONE; } -uint32_t Device_Database_Revision( - void) +uint32_t Device_Database_Revision(void) { return Database_Revision; } -void Device_Set_Database_Revision( - uint32_t revision) +void Device_Set_Database_Revision(uint32_t revision) { Database_Revision = revision; } @@ -492,8 +434,7 @@ void Device_Set_Database_Revision( * the most common operation if changing object names and ids is * implemented. */ -void Device_Inc_Database_Revision( - void) +void Device_Inc_Database_Revision(void) { Database_Revision++; } @@ -503,8 +444,7 @@ void Device_Inc_Database_Revision( * for discovery, it must be consistent! * @return The count of objects, for all supported Object types. */ -unsigned Device_Object_List_Count( - void) +unsigned Device_Object_List_Count(void) { unsigned count = 0; /* number of objects */ struct object_functions *pObject = NULL; @@ -531,10 +471,8 @@ unsigned Device_Object_List_Count( * @param instance [out] The object's instance number, if found. * @return True if found, else false. */ -bool Device_Object_List_Identifier( - uint32_t array_index, - int *object_type, - uint32_t * instance) +bool Device_Object_List_Identifier(uint32_t array_index, int *object_type, + uint32_t *instance) { bool status = false; unsigned count = 0; @@ -558,19 +496,19 @@ bool Device_Object_List_Identifier( * look for the index to instance to get the ID */ if (pObject->Object_Iterator) { /* First find the first object */ - temp_index = pObject->Object_Iterator(~(unsigned) 0); + temp_index = pObject->Object_Iterator(~(unsigned)0); /* Then step through the objects to find the nth */ while (object_index != 0) { temp_index = pObject->Object_Iterator(temp_index); object_index--; } - /* set the object_index up before falling through to next bit */ + /* 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); + *instance = pObject->Object_Index_To_Instance(object_index); status = true; break; } @@ -587,13 +525,12 @@ bool Device_Object_List_Identifier( * and the lookup succeeds, they will be given the resulting values. * @param object_name [in] The desired Object Name to look for. * @param object_type [out] The BACNET_OBJECT_TYPE of the matching Object. - * @param object_instance [out] The object instance number of the matching Object. + * @param object_instance [out] The object instance number of the matching + * Object. * @return True on success or else False if not found. */ -bool Device_Valid_Object_Name( - BACNET_CHARACTER_STRING * object_name1, - int *object_type, - uint32_t * object_instance) +bool Device_Valid_Object_Name(BACNET_CHARACTER_STRING *object_name1, + int *object_type, uint32_t *object_instance) { bool found = false; int type = 0; @@ -610,7 +547,7 @@ bool Device_Valid_Object_Name( pObject = Device_Objects_Find_Functions(type); if ((pObject != NULL) && (pObject->Object_Name != NULL) && (pObject->Object_Name(instance, &object_name2) && - characterstring_same(object_name1, &object_name2))) { + characterstring_same(object_name1, &object_name2))) { found = true; if (object_type) { *object_type = type; @@ -631,11 +568,9 @@ bool Device_Valid_Object_Name( * @param object_instance [in] The object instance number to be looked up. * @return True if found, else False if no such Object in this device. */ -bool Device_Valid_Object_Id( - int object_type, - uint32_t object_instance) +bool Device_Valid_Object_Id(int object_type, uint32_t object_instance) { - bool status = false; /* return value */ + bool status = false; /* return value */ struct object_functions *pObject = NULL; pObject = Device_Objects_Find_Functions(object_type); @@ -652,10 +587,9 @@ bool Device_Valid_Object_Id( * @param object_name [out] The Object Name found for this child Object. * @return True on success or else False if not found. */ -bool Device_Object_Name_Copy( - BACNET_OBJECT_TYPE object_type, - uint32_t object_instance, - BACNET_CHARACTER_STRING * object_name) +bool Device_Object_Name_Copy(BACNET_OBJECT_TYPE object_type, + uint32_t object_instance, + BACNET_CHARACTER_STRING *object_name) { struct object_functions *pObject = NULL; bool found = false; @@ -668,8 +602,7 @@ bool Device_Object_Name_Copy( return found; } -static void Update_Current_Time( - void) +static void Update_Current_Time(void) { struct tm *tblock = NULL; #if defined(_MSC_VER) @@ -700,15 +633,16 @@ int tm_isdst Daylight Savings flag. #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); + 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)); + 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); + 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; @@ -724,8 +658,7 @@ int tm_isdst Daylight Savings flag. } } -void Device_getCurrentDateTime( - BACNET_DATE_TIME * DateTime) +void Device_getCurrentDateTime(BACNET_DATE_TIME *DateTime) { Update_Current_Time(); @@ -821,11 +754,10 @@ uint32_t Device_Interval_Offset(void) /* return the length of the apdu encoded or BACNET_STATUS_ERROR for error or BACNET_STATUS_ABORT for abort message */ -int Device_Read_Property_Local( - BACNET_READ_PROPERTY_DATA * rpdata) +int Device_Read_Property_Local(BACNET_READ_PROPERTY_DATA *rpdata) { - int apdu_len = 0; /* return value */ - int len = 0; /* apdu len intermediate value */ + int apdu_len = 0; /* return value */ + int len = 0; /* apdu len intermediate value */ BACNET_BIT_STRING bit_string; BACNET_CHARACTER_STRING char_string; uint32_t i = 0; @@ -843,9 +775,8 @@ int Device_Read_Property_Local( apdu = rpdata->application_data; switch (rpdata->object_property) { case PROP_OBJECT_IDENTIFIER: - apdu_len = - encode_application_object_id(&apdu[0], OBJECT_DEVICE, - Object_Instance_Number); + apdu_len = encode_application_object_id(&apdu[0], OBJECT_DEVICE, + Object_Instance_Number); break; case PROP_OBJECT_NAME: apdu_len = @@ -868,8 +799,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], Vendor_Identifier); + apdu_len = encode_application_unsigned(&apdu[0], Vendor_Identifier); break; case PROP_MODEL_NAME: characterstring_init_ansi(&char_string, Model_Name); @@ -883,7 +813,7 @@ int Device_Read_Property_Local( break; case PROP_APPLICATION_SOFTWARE_VERSION: characterstring_init_ansi(&char_string, - Application_Software_Version); + Application_Software_Version); apdu_len = encode_application_character_string(&apdu[0], &char_string); break; @@ -893,22 +823,21 @@ 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], - Device_Protocol_Version()); + apdu_len = encode_application_unsigned(&apdu[0], + Device_Protocol_Version()); break; case PROP_PROTOCOL_REVISION: - apdu_len = - encode_application_unsigned(&apdu[0], - Device_Protocol_Revision()); + apdu_len = encode_application_unsigned(&apdu[0], + Device_Protocol_Revision()); break; case PROP_PROTOCOL_SERVICES_SUPPORTED: /* Note: list of services that are executed, not initiated. */ bitstring_init(&bit_string); for (i = 0; i < MAX_BACNET_SERVICES_SUPPORTED; i++) { /* automatic lookup based on handlers set */ - bitstring_set_bit(&bit_string, (uint8_t) i, - apdu_service_supported((BACNET_SERVICES_SUPPORTED) i)); + bitstring_set_bit( + &bit_string, (uint8_t)i, + apdu_service_supported((BACNET_SERVICES_SUPPORTED)i)); } apdu_len = encode_application_bitstring(&apdu[0], &bit_string); break; @@ -918,7 +847,7 @@ int Device_Read_Property_Local( bitstring_init(&bit_string); for (i = 0; i < MAX_ASHRAE_OBJECT_TYPE; i++) { /* initialize all the object types to not-supported */ - bitstring_set_bit(&bit_string, (uint8_t) i, false); + bitstring_set_bit(&bit_string, (uint8_t)i, false); } /* set the object types with objects to supported */ @@ -942,16 +871,15 @@ 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], - object_type, instance); + len = encode_application_object_id( + &apdu[apdu_len], object_type, instance); apdu_len += len; /* assume next one is the same size as this one */ - /* can we all fit into the APDU? Don't check for last entry */ + /* can we all fit into the APDU? Don't check for last + * entry */ if ((i != count) && (apdu_len + len) >= MAX_APDU) { /* Abort response */ rpdata->error_code = @@ -968,13 +896,11 @@ 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, - instance); + apdu_len = encode_application_object_id( + &apdu[0], object_type, instance); } else { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX; @@ -986,9 +912,8 @@ int Device_Read_Property_Local( apdu_len = encode_application_unsigned(&apdu[0], MAX_APDU); break; case PROP_SEGMENTATION_SUPPORTED: - apdu_len = - encode_application_enumerated(&apdu[0], - Device_Segmentation_Supported()); + apdu_len = encode_application_enumerated( + &apdu[0], Device_Segmentation_Supported()); break; case PROP_APDU_TIMEOUT: apdu_len = encode_application_unsigned(&apdu[0], apdu_timeout()); @@ -997,18 +922,17 @@ int Device_Read_Property_Local( apdu_len = encode_application_unsigned(&apdu[0], apdu_retries()); break; case PROP_DEVICE_ADDRESS_BINDING: - /* FIXME: the real max apdu remaining should be passed into function */ + /* FIXME: the real max apdu remaining should be passed into function + */ apdu_len = address_list_encode(&apdu[0], MAX_APDU); break; case PROP_DATABASE_REVISION: - apdu_len = - encode_application_unsigned(&apdu[0], Database_Revision); + apdu_len = encode_application_unsigned(&apdu[0], Database_Revision); break; #if defined(BACDL_MSTP) case PROP_MAX_INFO_FRAMES: apdu_len = - encode_application_unsigned(&apdu[0], - dlmstp_max_info_frames()); + encode_application_unsigned(&apdu[0], dlmstp_max_info_frames()); break; case PROP_MAX_MASTER: apdu_len = @@ -1034,7 +958,8 @@ int Device_Read_Property_Local( return apdu_len; } -/** Looks up the requested Object and Property, and encodes its Value in an APDU. +/** Looks up the requested Object and Property, and encodes its Value in an + * APDU. * @ingroup ObjIntf * If the Object or Property can't be found, sets the error class and code. * @@ -1042,8 +967,7 @@ int Device_Read_Property_Local( * on entry, and APDU message on return. * @return The length of the APDU on success, else BACNET_STATUS_ERROR */ -int Device_Read_Property( - BACNET_READ_PROPERTY_DATA * rpdata) +int Device_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata) { int apdu_len = BACNET_STATUS_ERROR; struct object_functions *pObject = NULL; @@ -1078,14 +1002,13 @@ int Device_Read_Property( * Each Child Object must provide some implementation of each of these * functions in order to properly support the default handlers. */ -void Device_Init( - object_functions_t * object_table) +void Device_Init(object_functions_t *object_table) { struct object_functions *pObject = NULL; characterstring_init_ansi(&My_Object_Name, "SimpleClient"); /* we don't use the object table passed in */ - (void) object_table; + (void)object_table; pObject = &Object_Table[0]; while (pObject->Object_Type < MAX_BACNET_OBJECT_TYPE) { if (pObject->Object_Init) { diff --git a/demo/object/device.c b/demo/object/device.c index 9ebb73ca..1d5993ad 100644 --- a/demo/object/device.c +++ b/demo/object/device.c @@ -1,46 +1,46 @@ /************************************************************************** -* -* Copyright (C) 2005,2006,2009 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2005,2006,2009 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /** @file device.c Base "class" for handling all BACnet objects belonging * to a BACnet device, as well as Device-specific properties. */ #include #include -#include /* for memmove */ -#include /* for timezone, localtime */ +#include /* for memmove */ +#include /* for timezone, localtime */ #include "bacdef.h" #include "bacdcode.h" #include "bacenum.h" #include "bacapp.h" -#include "config.h" /* the custom stuff */ +#include "config.h" /* the custom stuff */ #include "apdu.h" -#include "wp.h" /* WriteProperty handling */ -#include "rp.h" /* ReadProperty handling */ -#include "dcc.h" /* DeviceCommunicationControl handling */ +#include "wp.h" /* WriteProperty handling */ +#include "rp.h" /* ReadProperty handling */ +#include "dcc.h" /* DeviceCommunicationControl handling */ #include "version.h" -#include "device.h" /* me */ +#include "device.h" /* me */ #include "handlers.h" #include "datalink.h" #include "address.h" @@ -80,7 +80,6 @@ #include "ucix.h" #endif /* defined(BAC_UCI) */ - #if defined(__BORLANDC__) || defined(_WIN32) /* Not included in time.h as specified by The Open Group */ /* Difference from UTC and local standard time */ @@ -88,408 +87,184 @@ long int timezone; #endif /* local forward (semi-private) and external prototypes */ -int Device_Read_Property_Local( - BACNET_READ_PROPERTY_DATA * rpdata); -bool Device_Write_Property_Local( - BACNET_WRITE_PROPERTY_DATA * wp_data); -extern int Routed_Device_Read_Property_Local( - BACNET_READ_PROPERTY_DATA * rpdata); +int Device_Read_Property_Local(BACNET_READ_PROPERTY_DATA *rpdata); +bool Device_Write_Property_Local(BACNET_WRITE_PROPERTY_DATA *wp_data); +extern int Routed_Device_Read_Property_Local(BACNET_READ_PROPERTY_DATA *rpdata); extern bool Routed_Device_Write_Property_Local( - BACNET_WRITE_PROPERTY_DATA * wp_data); + BACNET_WRITE_PROPERTY_DATA *wp_data); /* may be overridden by outside table */ static object_functions_t *Object_Table; static object_functions_t My_Object_Table[] = { - {OBJECT_DEVICE, - NULL /* Init - don't init Device or it will recourse! */ , - Device_Count, - Device_Index_To_Instance, - Device_Valid_Object_Instance_Number, - Device_Object_Name, - Device_Read_Property_Local, - Device_Write_Property_Local, - Device_Property_Lists, - DeviceGetRRInfo, - NULL /* Iterator */ , - NULL /* Value_Lists */ , - NULL /* COV */ , - NULL /* COV Clear */ , - NULL /* Intrinsic Reporting */ }, + {OBJECT_DEVICE, NULL /* Init - don't init Device or it will recourse! */, + Device_Count, Device_Index_To_Instance, + Device_Valid_Object_Instance_Number, Device_Object_Name, + Device_Read_Property_Local, Device_Write_Property_Local, + Device_Property_Lists, DeviceGetRRInfo, NULL /* Iterator */, + NULL /* Value_Lists */, NULL /* COV */, NULL /* COV Clear */, + NULL /* Intrinsic Reporting */}, #if (BACNET_PROTOCOL_REVISION >= 17) - {OBJECT_NETWORK_PORT, - Network_Port_Init, - Network_Port_Count, - Network_Port_Index_To_Instance, - Network_Port_Valid_Instance, - Network_Port_Object_Name, - Network_Port_Read_Property, - Network_Port_Write_Property, - Network_Port_Property_Lists, - NULL /* ReadRangeInfo */ , - NULL /* Iterator */ , - NULL /* Value_Lists */ , - NULL /* COV */ , - NULL /* COV Clear */ , - NULL /* Intrinsic Reporting */ }, + {OBJECT_NETWORK_PORT, Network_Port_Init, Network_Port_Count, + Network_Port_Index_To_Instance, Network_Port_Valid_Instance, + Network_Port_Object_Name, Network_Port_Read_Property, + Network_Port_Write_Property, Network_Port_Property_Lists, + NULL /* ReadRangeInfo */, NULL /* Iterator */, NULL /* Value_Lists */, + NULL /* COV */, NULL /* COV Clear */, NULL /* Intrinsic Reporting */}, #endif - {OBJECT_ANALOG_INPUT, - Analog_Input_Init, - Analog_Input_Count, - Analog_Input_Index_To_Instance, - Analog_Input_Valid_Instance, - Analog_Input_Object_Name, - Analog_Input_Read_Property, - Analog_Input_Write_Property, - Analog_Input_Property_Lists, - NULL /* ReadRangeInfo */ , - NULL /* Iterator */ , - Analog_Input_Encode_Value_List, - Analog_Input_Change_Of_Value, - Analog_Input_Change_Of_Value_Clear, - Analog_Input_Intrinsic_Reporting}, - {OBJECT_ANALOG_OUTPUT, - Analog_Output_Init, - Analog_Output_Count, - Analog_Output_Index_To_Instance, - Analog_Output_Valid_Instance, - Analog_Output_Object_Name, - Analog_Output_Read_Property, - Analog_Output_Write_Property, - Analog_Output_Property_Lists, - NULL /* ReadRangeInfo */ , - NULL /* Iterator */ , - NULL /* Value_Lists */ , - NULL /* COV */ , - NULL /* COV Clear */ , - NULL /* Intrinsic Reporting */ }, - {OBJECT_ANALOG_VALUE, - Analog_Value_Init, - Analog_Value_Count, - Analog_Value_Index_To_Instance, - Analog_Value_Valid_Instance, - Analog_Value_Object_Name, - Analog_Value_Read_Property, - Analog_Value_Write_Property, - Analog_Value_Property_Lists, - NULL /* ReadRangeInfo */ , - NULL /* Iterator */ , - Analog_Value_Encode_Value_List, - Analog_Value_Change_Of_Value, - Analog_Value_Change_Of_Value_Clear, - Analog_Value_Intrinsic_Reporting}, - {OBJECT_BINARY_INPUT, - Binary_Input_Init, - Binary_Input_Count, - Binary_Input_Index_To_Instance, - Binary_Input_Valid_Instance, - Binary_Input_Object_Name, - Binary_Input_Read_Property, - Binary_Input_Write_Property, - Binary_Input_Property_Lists, - NULL /* ReadRangeInfo */ , - NULL /* Iterator */ , - Binary_Input_Encode_Value_List, - Binary_Input_Change_Of_Value, - Binary_Input_Change_Of_Value_Clear, - NULL /* Intrinsic Reporting */ }, - {OBJECT_BINARY_OUTPUT, - Binary_Output_Init, - Binary_Output_Count, - Binary_Output_Index_To_Instance, - Binary_Output_Valid_Instance, - Binary_Output_Object_Name, - Binary_Output_Read_Property, - Binary_Output_Write_Property, - Binary_Output_Property_Lists, - NULL /* ReadRangeInfo */ , - NULL /* Iterator */ , - NULL /* Value_Lists */ , - NULL /* COV */ , - NULL /* COV Clear */ , - NULL /* Intrinsic Reporting */ }, - {OBJECT_BINARY_VALUE, - Binary_Value_Init, - Binary_Value_Count, - Binary_Value_Index_To_Instance, - Binary_Value_Valid_Instance, - Binary_Value_Object_Name, - Binary_Value_Read_Property, - Binary_Value_Write_Property, - Binary_Value_Property_Lists, - NULL /* ReadRangeInfo */ , - NULL /* Iterator */ , - NULL /* Value_Lists */ , - NULL /* COV */ , - NULL /* COV Clear */ , - NULL /* Intrinsic Reporting */ }, - {OBJECT_CHARACTERSTRING_VALUE, - CharacterString_Value_Init, - CharacterString_Value_Count, - CharacterString_Value_Index_To_Instance, - CharacterString_Value_Valid_Instance, - CharacterString_Value_Object_Name, - CharacterString_Value_Read_Property, - CharacterString_Value_Write_Property, - CharacterString_Value_Property_Lists, - NULL /* ReadRangeInfo */ , - NULL /* Iterator */ , - NULL /* Value_Lists */ , - NULL /* COV */ , - NULL /* COV Clear */ , - NULL /* Intrinsic Reporting */ }, - {OBJECT_COMMAND, - Command_Init, - Command_Count, - Command_Index_To_Instance, - Command_Valid_Instance, - Command_Object_Name, - Command_Read_Property, - Command_Write_Property, - Command_Property_Lists, - NULL /* ReadRangeInfo */ , - NULL /* Iterator */ , - NULL /* Value_Lists */ , - NULL /* COV */ , - NULL /* COV Clear */ , - NULL /* Intrinsic Reporting */ }, - {OBJECT_INTEGER_VALUE, - Integer_Value_Init, - Integer_Value_Count, - Integer_Value_Index_To_Instance, - Integer_Value_Valid_Instance, - Integer_Value_Object_Name, - Integer_Value_Read_Property, - Integer_Value_Write_Property, - Integer_Value_Property_Lists, - NULL /* ReadRangeInfo */ , - NULL /* Iterator */ , - NULL /* Value_Lists */ , - NULL /* COV */ , - NULL /* COV Clear */ , - NULL /* Intrinsic Reporting */ }, + {OBJECT_ANALOG_INPUT, Analog_Input_Init, Analog_Input_Count, + Analog_Input_Index_To_Instance, Analog_Input_Valid_Instance, + Analog_Input_Object_Name, Analog_Input_Read_Property, + Analog_Input_Write_Property, Analog_Input_Property_Lists, + NULL /* ReadRangeInfo */, NULL /* Iterator */, + Analog_Input_Encode_Value_List, Analog_Input_Change_Of_Value, + Analog_Input_Change_Of_Value_Clear, Analog_Input_Intrinsic_Reporting}, + {OBJECT_ANALOG_OUTPUT, Analog_Output_Init, Analog_Output_Count, + Analog_Output_Index_To_Instance, Analog_Output_Valid_Instance, + Analog_Output_Object_Name, Analog_Output_Read_Property, + Analog_Output_Write_Property, Analog_Output_Property_Lists, + NULL /* ReadRangeInfo */, NULL /* Iterator */, NULL /* Value_Lists */, + NULL /* COV */, NULL /* COV Clear */, NULL /* Intrinsic Reporting */}, + {OBJECT_ANALOG_VALUE, Analog_Value_Init, Analog_Value_Count, + Analog_Value_Index_To_Instance, Analog_Value_Valid_Instance, + Analog_Value_Object_Name, Analog_Value_Read_Property, + Analog_Value_Write_Property, Analog_Value_Property_Lists, + NULL /* ReadRangeInfo */, NULL /* Iterator */, + Analog_Value_Encode_Value_List, Analog_Value_Change_Of_Value, + Analog_Value_Change_Of_Value_Clear, Analog_Value_Intrinsic_Reporting}, + {OBJECT_BINARY_INPUT, Binary_Input_Init, Binary_Input_Count, + Binary_Input_Index_To_Instance, Binary_Input_Valid_Instance, + Binary_Input_Object_Name, Binary_Input_Read_Property, + Binary_Input_Write_Property, Binary_Input_Property_Lists, + NULL /* ReadRangeInfo */, NULL /* Iterator */, + Binary_Input_Encode_Value_List, Binary_Input_Change_Of_Value, + Binary_Input_Change_Of_Value_Clear, NULL /* Intrinsic Reporting */}, + {OBJECT_BINARY_OUTPUT, Binary_Output_Init, Binary_Output_Count, + Binary_Output_Index_To_Instance, Binary_Output_Valid_Instance, + Binary_Output_Object_Name, Binary_Output_Read_Property, + Binary_Output_Write_Property, Binary_Output_Property_Lists, + NULL /* ReadRangeInfo */, NULL /* Iterator */, NULL /* Value_Lists */, + NULL /* COV */, NULL /* COV Clear */, NULL /* Intrinsic Reporting */}, + {OBJECT_BINARY_VALUE, Binary_Value_Init, Binary_Value_Count, + Binary_Value_Index_To_Instance, Binary_Value_Valid_Instance, + Binary_Value_Object_Name, Binary_Value_Read_Property, + Binary_Value_Write_Property, Binary_Value_Property_Lists, + NULL /* ReadRangeInfo */, NULL /* Iterator */, NULL /* Value_Lists */, + NULL /* COV */, NULL /* COV Clear */, NULL /* Intrinsic Reporting */}, + {OBJECT_CHARACTERSTRING_VALUE, CharacterString_Value_Init, + CharacterString_Value_Count, CharacterString_Value_Index_To_Instance, + CharacterString_Value_Valid_Instance, CharacterString_Value_Object_Name, + CharacterString_Value_Read_Property, CharacterString_Value_Write_Property, + CharacterString_Value_Property_Lists, NULL /* ReadRangeInfo */, + NULL /* Iterator */, NULL /* Value_Lists */, NULL /* COV */, + NULL /* COV Clear */, NULL /* Intrinsic Reporting */}, + {OBJECT_COMMAND, Command_Init, Command_Count, Command_Index_To_Instance, + Command_Valid_Instance, Command_Object_Name, Command_Read_Property, + Command_Write_Property, Command_Property_Lists, NULL /* ReadRangeInfo */, + NULL /* Iterator */, NULL /* Value_Lists */, NULL /* COV */, + NULL /* COV Clear */, NULL /* Intrinsic Reporting */}, + {OBJECT_INTEGER_VALUE, Integer_Value_Init, Integer_Value_Count, + Integer_Value_Index_To_Instance, Integer_Value_Valid_Instance, + Integer_Value_Object_Name, Integer_Value_Read_Property, + Integer_Value_Write_Property, Integer_Value_Property_Lists, + NULL /* ReadRangeInfo */, NULL /* Iterator */, NULL /* Value_Lists */, + NULL /* COV */, NULL /* COV Clear */, NULL /* Intrinsic Reporting */}, #if defined(INTRINSIC_REPORTING) - {OBJECT_NOTIFICATION_CLASS, - Notification_Class_Init, - Notification_Class_Count, - Notification_Class_Index_To_Instance, - Notification_Class_Valid_Instance, - Notification_Class_Object_Name, - Notification_Class_Read_Property, - Notification_Class_Write_Property, - Notification_Class_Property_Lists, - NULL /* ReadRangeInfo */ , - NULL /* Iterator */ , - NULL /* Value_Lists */ , - NULL /* COV */ , - NULL /* COV Clear */ , - NULL /* Intrinsic Reporting */ }, + {OBJECT_NOTIFICATION_CLASS, Notification_Class_Init, + Notification_Class_Count, Notification_Class_Index_To_Instance, + Notification_Class_Valid_Instance, Notification_Class_Object_Name, + Notification_Class_Read_Property, Notification_Class_Write_Property, + Notification_Class_Property_Lists, NULL /* ReadRangeInfo */, + NULL /* Iterator */, NULL /* Value_Lists */, NULL /* COV */, + NULL /* COV Clear */, NULL /* Intrinsic Reporting */}, #endif - {OBJECT_LIFE_SAFETY_POINT, - Life_Safety_Point_Init, - Life_Safety_Point_Count, - Life_Safety_Point_Index_To_Instance, - Life_Safety_Point_Valid_Instance, - Life_Safety_Point_Object_Name, - Life_Safety_Point_Read_Property, - Life_Safety_Point_Write_Property, - Life_Safety_Point_Property_Lists, - NULL /* ReadRangeInfo */ , - NULL /* Iterator */ , - NULL /* Value_Lists */ , - NULL /* COV */ , - NULL /* COV Clear */ , - NULL /* Intrinsic Reporting */ }, - {OBJECT_LOAD_CONTROL, - Load_Control_Init, - Load_Control_Count, - Load_Control_Index_To_Instance, - Load_Control_Valid_Instance, - Load_Control_Object_Name, - Load_Control_Read_Property, - Load_Control_Write_Property, - Load_Control_Property_Lists, - NULL /* ReadRangeInfo */ , - NULL /* Iterator */ , - NULL /* Value_Lists */ , - NULL /* COV */ , - NULL /* COV Clear */ , - NULL /* Intrinsic Reporting */ }, - {OBJECT_MULTI_STATE_INPUT, - Multistate_Input_Init, - Multistate_Input_Count, - Multistate_Input_Index_To_Instance, - Multistate_Input_Valid_Instance, - Multistate_Input_Object_Name, - Multistate_Input_Read_Property, - Multistate_Input_Write_Property, - Multistate_Input_Property_Lists, - NULL /* ReadRangeInfo */ , - NULL /* Iterator */ , - NULL /* Value_Lists */ , - NULL /* COV */ , - NULL /* COV Clear */ , - NULL /* Intrinsic Reporting */ }, - {OBJECT_MULTI_STATE_OUTPUT, - Multistate_Output_Init, - Multistate_Output_Count, - Multistate_Output_Index_To_Instance, - Multistate_Output_Valid_Instance, - Multistate_Output_Object_Name, - Multistate_Output_Read_Property, - Multistate_Output_Write_Property, - Multistate_Output_Property_Lists, - NULL /* ReadRangeInfo */ , - NULL /* Iterator */ , - NULL /* Value_Lists */ , - NULL /* COV */ , - NULL /* COV Clear */ , - NULL /* Intrinsic Reporting */ }, - {OBJECT_MULTI_STATE_VALUE, - Multistate_Value_Init, - Multistate_Value_Count, - Multistate_Value_Index_To_Instance, - Multistate_Value_Valid_Instance, - Multistate_Value_Object_Name, - Multistate_Value_Read_Property, - Multistate_Value_Write_Property, - Multistate_Value_Property_Lists, - NULL /* ReadRangeInfo */ , - NULL /* Iterator */ , - Multistate_Value_Encode_Value_List, - Multistate_Value_Change_Of_Value, - Multistate_Value_Change_Of_Value_Clear, - NULL /* Intrinsic Reporting */ }, - {OBJECT_TRENDLOG, - Trend_Log_Init, - Trend_Log_Count, - Trend_Log_Index_To_Instance, - Trend_Log_Valid_Instance, - Trend_Log_Object_Name, - Trend_Log_Read_Property, - Trend_Log_Write_Property, - Trend_Log_Property_Lists, - TrendLogGetRRInfo, - NULL /* Iterator */ , - NULL /* Value_Lists */ , - NULL /* COV */ , - NULL /* COV Clear */ , - NULL /* Intrinsic Reporting */ }, + {OBJECT_LIFE_SAFETY_POINT, Life_Safety_Point_Init, Life_Safety_Point_Count, + Life_Safety_Point_Index_To_Instance, Life_Safety_Point_Valid_Instance, + Life_Safety_Point_Object_Name, Life_Safety_Point_Read_Property, + Life_Safety_Point_Write_Property, Life_Safety_Point_Property_Lists, + NULL /* ReadRangeInfo */, NULL /* Iterator */, NULL /* Value_Lists */, + NULL /* COV */, NULL /* COV Clear */, NULL /* Intrinsic Reporting */}, + {OBJECT_LOAD_CONTROL, Load_Control_Init, Load_Control_Count, + Load_Control_Index_To_Instance, Load_Control_Valid_Instance, + Load_Control_Object_Name, Load_Control_Read_Property, + Load_Control_Write_Property, Load_Control_Property_Lists, + NULL /* ReadRangeInfo */, NULL /* Iterator */, NULL /* Value_Lists */, + NULL /* COV */, NULL /* COV Clear */, NULL /* Intrinsic Reporting */}, + {OBJECT_MULTI_STATE_INPUT, Multistate_Input_Init, Multistate_Input_Count, + Multistate_Input_Index_To_Instance, Multistate_Input_Valid_Instance, + Multistate_Input_Object_Name, Multistate_Input_Read_Property, + Multistate_Input_Write_Property, Multistate_Input_Property_Lists, + NULL /* ReadRangeInfo */, NULL /* Iterator */, NULL /* Value_Lists */, + NULL /* COV */, NULL /* COV Clear */, NULL /* Intrinsic Reporting */}, + {OBJECT_MULTI_STATE_OUTPUT, Multistate_Output_Init, Multistate_Output_Count, + Multistate_Output_Index_To_Instance, Multistate_Output_Valid_Instance, + Multistate_Output_Object_Name, Multistate_Output_Read_Property, + Multistate_Output_Write_Property, Multistate_Output_Property_Lists, + NULL /* ReadRangeInfo */, NULL /* Iterator */, NULL /* Value_Lists */, + NULL /* COV */, NULL /* COV Clear */, NULL /* Intrinsic Reporting */}, + {OBJECT_MULTI_STATE_VALUE, Multistate_Value_Init, Multistate_Value_Count, + Multistate_Value_Index_To_Instance, Multistate_Value_Valid_Instance, + Multistate_Value_Object_Name, Multistate_Value_Read_Property, + Multistate_Value_Write_Property, Multistate_Value_Property_Lists, + NULL /* ReadRangeInfo */, NULL /* Iterator */, + Multistate_Value_Encode_Value_List, Multistate_Value_Change_Of_Value, + Multistate_Value_Change_Of_Value_Clear, NULL /* Intrinsic Reporting */}, + {OBJECT_TRENDLOG, Trend_Log_Init, Trend_Log_Count, + Trend_Log_Index_To_Instance, Trend_Log_Valid_Instance, + Trend_Log_Object_Name, Trend_Log_Read_Property, Trend_Log_Write_Property, + Trend_Log_Property_Lists, TrendLogGetRRInfo, NULL /* Iterator */, + NULL /* Value_Lists */, NULL /* COV */, NULL /* COV Clear */, + NULL /* Intrinsic Reporting */}, #if (BACNET_PROTOCOL_REVISION >= 14) - {OBJECT_LIGHTING_OUTPUT, - Lighting_Output_Init, - Lighting_Output_Count, - Lighting_Output_Index_To_Instance, - Lighting_Output_Valid_Instance, - Lighting_Output_Object_Name, - Lighting_Output_Read_Property, - Lighting_Output_Write_Property, - Lighting_Output_Property_Lists, - NULL /* ReadRangeInfo */ , - NULL /* Iterator */ , - NULL /* Value_Lists */ , - NULL /* COV */ , - NULL /* COV Clear */ , - NULL /* Intrinsic Reporting */ }, - {OBJECT_CHANNEL, - Channel_Init, - Channel_Count, - Channel_Index_To_Instance, - Channel_Valid_Instance, - Channel_Object_Name, - Channel_Read_Property, - Channel_Write_Property, - Channel_Property_Lists, - NULL /* ReadRangeInfo */ , - NULL /* Iterator */ , - NULL /* Value_Lists */ , - NULL /* COV */ , - NULL /* COV Clear */ , - NULL /* Intrinsic Reporting */ }, + {OBJECT_LIGHTING_OUTPUT, Lighting_Output_Init, Lighting_Output_Count, + Lighting_Output_Index_To_Instance, Lighting_Output_Valid_Instance, + Lighting_Output_Object_Name, Lighting_Output_Read_Property, + Lighting_Output_Write_Property, Lighting_Output_Property_Lists, + NULL /* ReadRangeInfo */, NULL /* Iterator */, NULL /* Value_Lists */, + NULL /* COV */, NULL /* COV Clear */, NULL /* Intrinsic Reporting */}, + {OBJECT_CHANNEL, Channel_Init, Channel_Count, Channel_Index_To_Instance, + Channel_Valid_Instance, Channel_Object_Name, Channel_Read_Property, + Channel_Write_Property, Channel_Property_Lists, NULL /* ReadRangeInfo */, + NULL /* Iterator */, NULL /* Value_Lists */, NULL /* COV */, + NULL /* COV Clear */, NULL /* Intrinsic Reporting */}, #endif #if defined(BACFILE) - {OBJECT_FILE, - bacfile_init, - bacfile_count, - bacfile_index_to_instance, - bacfile_valid_instance, - bacfile_object_name, - bacfile_read_property, - bacfile_write_property, - BACfile_Property_Lists, - NULL /* ReadRangeInfo */ , - NULL /* Iterator */ , - NULL /* Value_Lists */ , - NULL /* COV */ , - NULL /* COV Clear */ , - NULL /* Intrinsic Reporting */ }, + {OBJECT_FILE, bacfile_init, bacfile_count, bacfile_index_to_instance, + bacfile_valid_instance, bacfile_object_name, bacfile_read_property, + bacfile_write_property, BACfile_Property_Lists, NULL /* ReadRangeInfo */, + NULL /* Iterator */, NULL /* Value_Lists */, NULL /* COV */, + NULL /* COV Clear */, NULL /* Intrinsic Reporting */}, #endif - {OBJECT_OCTETSTRING_VALUE, - OctetString_Value_Init, - OctetString_Value_Count, - OctetString_Value_Index_To_Instance, - OctetString_Value_Valid_Instance, - OctetString_Value_Object_Name, - OctetString_Value_Read_Property, - OctetString_Value_Write_Property, - OctetString_Value_Property_Lists, - NULL /* ReadRangeInfo */ , - NULL /* Iterator */ , - NULL /* Value_Lists */ , - NULL /* COV */ , - NULL /* COV Clear */ , - NULL /* Intrinsic Reporting */ }, - {OBJECT_POSITIVE_INTEGER_VALUE, - PositiveInteger_Value_Init, - PositiveInteger_Value_Count, - PositiveInteger_Value_Index_To_Instance, - PositiveInteger_Value_Valid_Instance, - PositiveInteger_Value_Object_Name, - PositiveInteger_Value_Read_Property, - PositiveInteger_Value_Write_Property, - PositiveInteger_Value_Property_Lists, - NULL /* ReadRangeInfo */ , - NULL /* Iterator */ , - NULL /* Value_Lists */ , - NULL /* COV */ , - NULL /* COV Clear */ , - NULL /* Intrinsic Reporting */ }, - {OBJECT_SCHEDULE, - Schedule_Init, - Schedule_Count, - Schedule_Index_To_Instance, - Schedule_Valid_Instance, - Schedule_Object_Name, - Schedule_Read_Property, - Schedule_Write_Property, - Schedule_Property_Lists, - NULL /* ReadRangeInfo */ , - NULL /* Iterator */ , - NULL /* Value_Lists */ , - NULL /* COV */ , - NULL /* COV Clear */ , - NULL /* Intrinsic Reporting */ }, - {MAX_BACNET_OBJECT_TYPE, - NULL /* Init */ , - NULL /* Count */ , - NULL /* Index_To_Instance */ , - NULL /* Valid_Instance */ , - NULL /* Object_Name */ , - NULL /* Read_Property */ , - NULL /* Write_Property */ , - NULL /* Property_Lists */ , - NULL /* ReadRangeInfo */ , - NULL /* Iterator */ , - NULL /* Value_Lists */ , - NULL /* COV */ , - NULL /* COV Clear */ , - NULL /* Intrinsic Reporting */ } -}; + {OBJECT_OCTETSTRING_VALUE, OctetString_Value_Init, OctetString_Value_Count, + OctetString_Value_Index_To_Instance, OctetString_Value_Valid_Instance, + OctetString_Value_Object_Name, OctetString_Value_Read_Property, + OctetString_Value_Write_Property, OctetString_Value_Property_Lists, + NULL /* ReadRangeInfo */, NULL /* Iterator */, NULL /* Value_Lists */, + NULL /* COV */, NULL /* COV Clear */, NULL /* Intrinsic Reporting */}, + {OBJECT_POSITIVE_INTEGER_VALUE, PositiveInteger_Value_Init, + PositiveInteger_Value_Count, PositiveInteger_Value_Index_To_Instance, + PositiveInteger_Value_Valid_Instance, PositiveInteger_Value_Object_Name, + PositiveInteger_Value_Read_Property, PositiveInteger_Value_Write_Property, + PositiveInteger_Value_Property_Lists, NULL /* ReadRangeInfo */, + NULL /* Iterator */, NULL /* Value_Lists */, NULL /* COV */, + NULL /* COV Clear */, NULL /* Intrinsic Reporting */}, + {OBJECT_SCHEDULE, Schedule_Init, Schedule_Count, Schedule_Index_To_Instance, + Schedule_Valid_Instance, Schedule_Object_Name, Schedule_Read_Property, + Schedule_Write_Property, Schedule_Property_Lists, NULL /* ReadRangeInfo */, + NULL /* Iterator */, NULL /* Value_Lists */, NULL /* COV */, + NULL /* COV Clear */, NULL /* Intrinsic Reporting */}, + {MAX_BACNET_OBJECT_TYPE, NULL /* Init */, NULL /* Count */, + NULL /* Index_To_Instance */, NULL /* Valid_Instance */, + NULL /* Object_Name */, NULL /* Read_Property */, + NULL /* Write_Property */, NULL /* Property_Lists */, + NULL /* ReadRangeInfo */, NULL /* Iterator */, NULL /* Value_Lists */, + NULL /* COV */, NULL /* COV Clear */, NULL /* Intrinsic Reporting */}}; /** Glue function to let the Device object, when called by a handler, * lookup which Object type needs to be invoked. * @ingroup ObjHelpers - * @param Object_Type [in] The type of BACnet Object the handler wants to access. + * @param Object_Type [in] The type of BACnet Object the handler wants to + * access. * @return Pointer to the group of object helper functions that implement this * type of Object. */ @@ -510,17 +285,18 @@ static struct object_functions *Device_Objects_Find_Functions( return (NULL); } -/** Try to find a rr_info_function helper function for the requested object type. +/** Try to find a rr_info_function helper function for the requested object + * type. * @ingroup ObjIntf * - * @param object_type [in] The type of BACnet Object the handler wants to access. + * @param object_type [in] The type of BACnet Object the handler wants to + * access. * @return Pointer to the object helper function that implements the * ReadRangeInfo function, Object_RR_Info, for this type of Object on * success, else a NULL pointer if the type of Object isn't supported * or doesn't have a ReadRangeInfo function. */ -rr_info_function Device_Objects_RR_Info( - BACNET_OBJECT_TYPE object_type) +rr_info_function Device_Objects_RR_Info(BACNET_OBJECT_TYPE object_type) { struct object_functions *pObject = NULL; @@ -539,10 +315,9 @@ rr_info_function Device_Objects_RR_Info( * list, separately, the Required, Optional, and Proprietary object * properties with their counts. */ -void Device_Objects_Property_List( - BACNET_OBJECT_TYPE object_type, - uint32_t object_instance, - struct special_property_list_t *pPropertyList) +void Device_Objects_Property_List(BACNET_OBJECT_TYPE object_type, + uint32_t object_instance, + struct special_property_list_t *pPropertyList) { struct object_functions *pObject = NULL; @@ -559,21 +334,25 @@ 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); + &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.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.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.pList == NULL + ? 0 + : property_list_count(pPropertyList->Proprietary.pList); return; } @@ -600,8 +379,7 @@ static const int Device_Properties_Required[] = { PROP_NUMBER_OF_APDU_RETRIES, PROP_DEVICE_ADDRESS_BINDING, PROP_DATABASE_REVISION, - -1 -}; + -1}; static const int Device_Properties_Optional[] = { #if defined(BACDL_MSTP) @@ -621,17 +399,12 @@ static const int Device_Properties_Optional[] = { PROP_ALIGN_INTERVALS, PROP_INTERVAL_OFFSET, #endif - -1 -}; + -1}; -static const int Device_Properties_Proprietary[] = { - -1 -}; +static const int Device_Properties_Proprietary[] = {-1}; -void Device_Property_Lists( - const int **pRequired, - const int **pOptional, - const int **pProprietary) +void Device_Property_Lists(const int **pRequired, const int **pOptional, + const int **pProprietary) { if (pRequired) *pRequired = Device_Properties_Required; @@ -666,14 +439,14 @@ 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. BACnet UTC offset is expressed in minutes. */ static int32_t UTC_Offset = 5 * 60; -static bool Daylight_Savings_Status = false; /* rely on OS */ +static bool Daylight_Savings_Status = false; /* rely on OS */ #if defined(BACNET_TIME_MASTER) static bool Align_Intervals; static uint32_t Interval_Minutes; @@ -710,8 +483,7 @@ static const char *Reinit_Password = "filister"; * 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; @@ -754,20 +526,17 @@ bool Device_Reinitialize( return status; } -BACNET_REINITIALIZED_STATE Device_Reinitialized_State( - void) +BACNET_REINITIALIZED_STATE Device_Reinitialized_State(void) { return Reinitialize_State; } -unsigned Device_Count( - void) +unsigned Device_Count(void) { return 1; } -uint32_t Device_Index_To_Instance( - unsigned index) +uint32_t Device_Index_To_Instance(unsigned index) { index = index; return Object_Instance_Number; @@ -781,8 +550,7 @@ uint32_t Device_Index_To_Instance( * @ingroup ObjIntf * @return The Instance number used in the BACNET_OBJECT_ID for the Device. */ -uint32_t Device_Object_Instance_Number( - void) +uint32_t Device_Object_Instance_Number(void) { #ifdef BAC_ROUTING return Routed_Device_Object_Instance_Number(); @@ -791,8 +559,7 @@ uint32_t Device_Object_Instance_Number( #endif } -bool Device_Set_Object_Instance_Number( - uint32_t object_id) +bool Device_Set_Object_Instance_Number(uint32_t object_id) { bool status = true; /* return value */ @@ -806,15 +573,13 @@ bool Device_Set_Object_Instance_Number( return status; } -bool Device_Valid_Object_Instance_Number( - uint32_t object_id) +bool Device_Valid_Object_Instance_Number(uint32_t object_id) { return (Object_Instance_Number == object_id); } -bool Device_Object_Name( - uint32_t object_instance, - BACNET_CHARACTER_STRING * object_name) +bool Device_Object_Name(uint32_t object_instance, + BACNET_CHARACTER_STRING *object_name) { bool status = false; @@ -825,10 +590,9 @@ bool Device_Object_Name( return status; } -bool Device_Set_Object_Name( - BACNET_CHARACTER_STRING * object_name) +bool Device_Set_Object_Name(BACNET_CHARACTER_STRING *object_name) { - bool status = false; /*return value */ + bool status = false; /*return value */ if (!characterstring_same(&My_Object_Name, object_name)) { /* Make the change and update the database revision */ @@ -839,22 +603,19 @@ bool Device_Set_Object_Name( return status; } -bool Device_Object_Name_ANSI_Init(const char * value) +bool Device_Object_Name_ANSI_Init(const char *value) { return characterstring_init_ansi(&My_Object_Name, value); } -BACNET_DEVICE_STATUS Device_System_Status( - void) +BACNET_DEVICE_STATUS Device_System_Status(void) { return System_Status; } -int Device_Set_System_Status( - BACNET_DEVICE_STATUS status, - bool local) +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. */ @@ -915,39 +676,34 @@ int Device_Set_System_Status( return (result); } -const char *Device_Vendor_Name( - void) +const char *Device_Vendor_Name(void) { return Vendor_Name; } /** Returns the Vendor ID for this Device. - * See the assignments at http://www.bacnet.org/VendorID/BACnet%20Vendor%20IDs.htm + * See the assignments at + * http://www.bacnet.org/VendorID/BACnet%20Vendor%20IDs.htm * @return The Vendor ID of this Device. */ -uint16_t Device_Vendor_Identifier( - void) +uint16_t Device_Vendor_Identifier(void) { return Vendor_Identifier; } -void Device_Set_Vendor_Identifier( - uint16_t vendor_id) +void Device_Set_Vendor_Identifier(uint16_t vendor_id) { Vendor_Identifier = vendor_id; } -const char *Device_Model_Name( - void) +const char *Device_Model_Name(void) { return Model_Name; } -bool Device_Set_Model_Name( - const char *name, - size_t length) +bool Device_Set_Model_Name(const char *name, size_t length) { - bool status = false; /*return value */ + bool status = false; /*return value */ if (length < sizeof(Model_Name)) { memmove(Model_Name, name, length); @@ -958,23 +714,19 @@ bool Device_Set_Model_Name( return status; } -const char *Device_Firmware_Revision( - void) +const char *Device_Firmware_Revision(void) { return BACnet_Version; } -const char *Device_Application_Software_Version( - void) +const char *Device_Application_Software_Version(void) { return Application_Software_Version; } -bool Device_Set_Application_Software_Version( - const char *name, - size_t length) +bool Device_Set_Application_Software_Version(const char *name, size_t length) { - bool status = false; /*return value */ + bool status = false; /*return value */ if (length < sizeof(Application_Software_Version)) { memmove(Application_Software_Version, name, length); @@ -985,17 +737,14 @@ bool Device_Set_Application_Software_Version( return status; } -const char *Device_Description( - void) +const char *Device_Description(void) { return Description; } -bool Device_Set_Description( - const char *name, - size_t length) +bool Device_Set_Description(const char *name, size_t length) { - bool status = false; /*return value */ + bool status = false; /*return value */ if (length < sizeof(Description)) { memmove(Description, name, length); @@ -1006,17 +755,14 @@ bool Device_Set_Description( return status; } -const char *Device_Location( - void) +const char *Device_Location(void) { return Location; } -bool Device_Set_Location( - const char *name, - size_t length) +bool Device_Set_Location(const char *name, size_t length) { - bool status = false; /*return value */ + bool status = false; /*return value */ if (length < sizeof(Location)) { memmove(Location, name, length); @@ -1027,32 +773,27 @@ bool Device_Set_Location( return status; } -uint8_t Device_Protocol_Version( - void) +uint8_t Device_Protocol_Version(void) { return BACNET_PROTOCOL_VERSION; } -uint8_t Device_Protocol_Revision( - void) +uint8_t Device_Protocol_Revision(void) { return BACNET_PROTOCOL_REVISION; } -BACNET_SEGMENTATION Device_Segmentation_Supported( - void) +BACNET_SEGMENTATION Device_Segmentation_Supported(void) { return SEGMENTATION_NONE; } -uint32_t Device_Database_Revision( - void) +uint32_t Device_Database_Revision(void) { return Database_Revision; } -void Device_Set_Database_Revision( - uint32_t revision) +void Device_Set_Database_Revision(uint32_t revision) { Database_Revision = revision; } @@ -1062,8 +803,7 @@ void Device_Set_Database_Revision( * the most common operation if changing object names and ids is * implemented. */ -void Device_Inc_Database_Revision( - void) +void Device_Inc_Database_Revision(void) { Database_Revision++; } @@ -1073,8 +813,7 @@ void Device_Inc_Database_Revision( * for discovery, it must be consistent! * @return The count of objects, for all supported Object types. */ -unsigned Device_Object_List_Count( - void) +unsigned Device_Object_List_Count(void) { unsigned count = 0; /* number of objects */ struct object_functions *pObject = NULL; @@ -1101,10 +840,8 @@ unsigned Device_Object_List_Count( * @param instance [out] The object's instance number, if found. * @return True if found, else false. */ -bool Device_Object_List_Identifier( - uint32_t array_index, - int *object_type, - uint32_t * instance) +bool Device_Object_List_Identifier(uint32_t array_index, int *object_type, + uint32_t *instance) { bool status = false; uint32_t count = 0; @@ -1128,19 +865,19 @@ bool Device_Object_List_Identifier( * look for the index to instance to get the ID */ if (pObject->Object_Iterator) { /* First find the first object */ - temp_index = pObject->Object_Iterator(~(unsigned) 0); + temp_index = pObject->Object_Iterator(~(unsigned)0); /* Then step through the objects to find the nth */ while (object_index != 0) { temp_index = pObject->Object_Iterator(temp_index); object_index--; } - /* set the object_index up before falling through to next bit */ + /* 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); + *instance = pObject->Object_Index_To_Instance(object_index); status = true; break; } @@ -1157,13 +894,12 @@ bool Device_Object_List_Identifier( * and the lookup succeeds, they will be given the resulting values. * @param object_name [in] The desired Object Name to look for. * @param object_type [out] The BACNET_OBJECT_TYPE of the matching Object. - * @param object_instance [out] The object instance number of the matching Object. + * @param object_instance [out] The object instance number of the matching + * Object. * @return True on success or else False if not found. */ -bool Device_Valid_Object_Name( - BACNET_CHARACTER_STRING * object_name1, - int *object_type, - uint32_t * object_instance) +bool Device_Valid_Object_Name(BACNET_CHARACTER_STRING *object_name1, + int *object_type, uint32_t *object_instance) { bool found = false; int type = 0; @@ -1180,7 +916,7 @@ bool Device_Valid_Object_Name( pObject = Device_Objects_Find_Functions(type); if ((pObject != NULL) && (pObject->Object_Name != NULL) && (pObject->Object_Name(instance, &object_name2) && - characterstring_same(object_name1, &object_name2))) { + characterstring_same(object_name1, &object_name2))) { found = true; if (object_type) { *object_type = type; @@ -1201,11 +937,9 @@ bool Device_Valid_Object_Name( * @param object_instance [in] The object instance number to be looked up. * @return True if found, else False if no such Object in this device. */ -bool Device_Valid_Object_Id( - int object_type, - uint32_t object_instance) +bool Device_Valid_Object_Id(int object_type, uint32_t object_instance) { - bool status = false; /* return value */ + bool status = false; /* return value */ struct object_functions *pObject = NULL; pObject = Device_Objects_Find_Functions(object_type); @@ -1222,10 +956,9 @@ bool Device_Valid_Object_Id( * @param object_name [out] The Object Name found for this child Object. * @return True on success or else False if not found. */ -bool Device_Object_Name_Copy( - BACNET_OBJECT_TYPE object_type, - uint32_t object_instance, - BACNET_CHARACTER_STRING * object_name) +bool Device_Object_Name_Copy(BACNET_OBJECT_TYPE object_type, + uint32_t object_instance, + BACNET_CHARACTER_STRING *object_name) { struct object_functions *pObject = NULL; bool found = false; @@ -1238,8 +971,7 @@ bool Device_Object_Name_Copy( return found; } -static void Update_Current_Time( - void) +static void Update_Current_Time(void) { struct tm *tblock = NULL; #if defined(_MSC_VER) @@ -1270,15 +1002,16 @@ int tm_isdst Daylight Savings flag. #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); + 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)); + 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); + 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; @@ -1294,8 +1027,7 @@ int tm_isdst Daylight Savings flag. } } -void Device_getCurrentDateTime( - BACNET_DATE_TIME * DateTime) +void Device_getCurrentDateTime(BACNET_DATE_TIME *DateTime) { Update_Current_Time(); @@ -1396,13 +1128,12 @@ uint32_t Device_Interval_Offset(void) /* return the length of the apdu encoded or BACNET_STATUS_ERROR for error or BACNET_STATUS_ABORT for abort message */ -int Device_Read_Property_Local( - BACNET_READ_PROPERTY_DATA * rpdata) +int Device_Read_Property_Local(BACNET_READ_PROPERTY_DATA *rpdata) { - int apdu_len = 0; /* return value */ - int len = 0; /* apdu len intermediate value */ - BACNET_BIT_STRING bit_string = { 0 }; - BACNET_CHARACTER_STRING char_string = { 0 }; + int apdu_len = 0; /* return value */ + int len = 0; /* apdu len intermediate value */ + BACNET_BIT_STRING bit_string = {0}; + BACNET_CHARACTER_STRING char_string = {0}; uint32_t i = 0; int object_type = 0; uint32_t instance = 0; @@ -1420,9 +1151,8 @@ int Device_Read_Property_Local( apdu_max = rpdata->application_data_len; switch (rpdata->object_property) { case PROP_OBJECT_IDENTIFIER: - apdu_len = - encode_application_object_id(&apdu[0], OBJECT_DEVICE, - Object_Instance_Number); + apdu_len = encode_application_object_id(&apdu[0], OBJECT_DEVICE, + Object_Instance_Number); break; case PROP_OBJECT_NAME: apdu_len = @@ -1445,8 +1175,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], Vendor_Identifier); + apdu_len = encode_application_unsigned(&apdu[0], Vendor_Identifier); break; case PROP_MODEL_NAME: characterstring_init_ansi(&char_string, Model_Name); @@ -1460,7 +1189,7 @@ int Device_Read_Property_Local( break; case PROP_APPLICATION_SOFTWARE_VERSION: characterstring_init_ansi(&char_string, - Application_Software_Version); + Application_Software_Version); apdu_len = encode_application_character_string(&apdu[0], &char_string); break; @@ -1487,22 +1216,21 @@ int Device_Read_Property_Local( encode_application_boolean(&apdu[0], Daylight_Savings_Status); break; case PROP_PROTOCOL_VERSION: - apdu_len = - encode_application_unsigned(&apdu[0], - Device_Protocol_Version()); + apdu_len = encode_application_unsigned(&apdu[0], + Device_Protocol_Version()); break; case PROP_PROTOCOL_REVISION: - apdu_len = - encode_application_unsigned(&apdu[0], - Device_Protocol_Revision()); + apdu_len = encode_application_unsigned(&apdu[0], + Device_Protocol_Revision()); break; case PROP_PROTOCOL_SERVICES_SUPPORTED: /* Note: list of services that are executed, not initiated. */ bitstring_init(&bit_string); for (i = 0; i < MAX_BACNET_SERVICES_SUPPORTED; i++) { /* automatic lookup based on handlers set */ - bitstring_set_bit(&bit_string, (uint8_t) i, - apdu_service_supported((BACNET_SERVICES_SUPPORTED) i)); + bitstring_set_bit( + &bit_string, (uint8_t)i, + apdu_service_supported((BACNET_SERVICES_SUPPORTED)i)); } apdu_len = encode_application_bitstring(&apdu[0], &bit_string); break; @@ -1512,7 +1240,7 @@ int Device_Read_Property_Local( bitstring_init(&bit_string); for (i = 0; i < MAX_ASHRAE_OBJECT_TYPE; i++) { /* initialize all the object types to not-supported */ - bitstring_set_bit(&bit_string, (uint8_t) i, false); + bitstring_set_bit(&bit_string, (uint8_t)i, false); } /* set the object types with objects to supported */ @@ -1536,16 +1264,15 @@ 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], - object_type, instance); + len = encode_application_object_id( + &apdu[apdu_len], object_type, instance); apdu_len += len; /* assume next one is the same size as this one */ - /* can we all fit into the APDU? Don't check for last entry */ + /* can we all fit into the APDU? Don't check for last + * entry */ if ((i != count) && (apdu_len + len) >= apdu_max) { /* Abort response */ rpdata->error_code = @@ -1562,13 +1289,11 @@ 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, - instance); + apdu_len = encode_application_object_id( + &apdu[0], object_type, instance); } else { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX; @@ -1580,9 +1305,8 @@ int Device_Read_Property_Local( apdu_len = encode_application_unsigned(&apdu[0], MAX_APDU); break; case PROP_SEGMENTATION_SUPPORTED: - apdu_len = - encode_application_enumerated(&apdu[0], - Device_Segmentation_Supported()); + apdu_len = encode_application_enumerated( + &apdu[0], Device_Segmentation_Supported()); break; case PROP_APDU_TIMEOUT: apdu_len = encode_application_unsigned(&apdu[0], apdu_timeout()); @@ -1594,14 +1318,12 @@ int Device_Read_Property_Local( apdu_len = address_list_encode(&apdu[0], apdu_max); break; case PROP_DATABASE_REVISION: - apdu_len = - encode_application_unsigned(&apdu[0], Database_Revision); + apdu_len = encode_application_unsigned(&apdu[0], Database_Revision); break; #if defined(BACDL_MSTP) case PROP_MAX_INFO_FRAMES: apdu_len = - encode_application_unsigned(&apdu[0], - dlmstp_max_info_frames()); + encode_application_unsigned(&apdu[0], dlmstp_max_info_frames()); break; case PROP_MAX_MASTER: apdu_len = @@ -1619,16 +1341,15 @@ int Device_Read_Property_Local( break; case PROP_TIME_SYNCHRONIZATION_INTERVAL: apdu_len = encode_application_unsigned(&apdu[0], - Device_Time_Sync_Interval()); + Device_Time_Sync_Interval()); break; case PROP_ALIGN_INTERVALS: apdu_len = - encode_application_boolean(&apdu[0], - Device_Align_Intervals()); + encode_application_boolean(&apdu[0], Device_Align_Intervals()); break; case PROP_INTERVAL_OFFSET: - apdu_len = encode_application_unsigned(&apdu[0], - Device_Interval_Offset()); + apdu_len = + encode_application_unsigned(&apdu[0], Device_Interval_Offset()); break; #endif case PROP_ACTIVE_COV_SUBSCRIPTIONS: @@ -1651,7 +1372,8 @@ int Device_Read_Property_Local( return apdu_len; } -/** Looks up the requested Object and Property, and encodes its Value in an APDU. +/** Looks up the requested Object and Property, and encodes its Value in an + * APDU. * @ingroup ObjIntf * If the Object or Property can't be found, sets the error class and code. * @@ -1659,8 +1381,7 @@ int Device_Read_Property_Local( * on entry, and APDU message on return. * @return The length of the APDU on success, else BACNET_STATUS_ERROR */ -int Device_Read_Property( - BACNET_READ_PROPERTY_DATA * rpdata) +int Device_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata) { int apdu_len = BACNET_STATUS_ERROR; struct object_functions *pObject = NULL; @@ -1678,13 +1399,11 @@ int Device_Read_Property( if (pObject->Object_Read_Property) { #if (BACNET_PROTOCOL_REVISION >= 14) if ((int)rpdata->object_property == PROP_PROPERTY_LIST) { - Device_Objects_Property_List( - rpdata->object_type, - rpdata->object_instance, - &property_list); + Device_Objects_Property_List(rpdata->object_type, + rpdata->object_instance, + &property_list); apdu_len = property_list_encode( - rpdata, - property_list.Required.pList, + rpdata, property_list.Required.pList, property_list.Optional.pList, property_list.Proprietary.pList); } else @@ -1700,10 +1419,9 @@ int Device_Read_Property( } /* returns true if successful */ -bool Device_Write_Property_Local( - BACNET_WRITE_PROPERTY_DATA * wp_data) +bool Device_Write_Property_Local(BACNET_WRITE_PROPERTY_DATA *wp_data) { - bool status = false; /* return value */ + bool status = false; /* return value */ int len = 0; BACNET_APPLICATION_DATA_VALUE value; int object_type = 0; @@ -1712,9 +1430,8 @@ bool Device_Write_Property_Local( int temp; /* decode the some of the request */ - len = - bacapp_decode_application_data(wp_data->application_data, - wp_data->application_data_len, &value); + len = bacapp_decode_application_data(wp_data->application_data, + wp_data->application_data_len, &value); if (len < 0) { /* error while decoding - a value larger than we can handle */ wp_data->error_class = ERROR_CLASS_PROPERTY; @@ -1733,12 +1450,13 @@ bool Device_Write_Property_Local( case PROP_OBJECT_IDENTIFIER: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_OBJECT_ID, - &wp_data->error_class, &wp_data->error_code); + &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))) { - /* FIXME: we could send an I-Am broadcast to let the world know */ + (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; wp_data->error_class = ERROR_CLASS_PROPERTY; @@ -1749,38 +1467,37 @@ bool Device_Write_Property_Local( case PROP_NUMBER_OF_APDU_RETRIES: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { /* FIXME: bounds check? */ - apdu_retries_set((uint8_t) value.type.Unsigned_Int); + 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); + &wp_data->error_class, &wp_data->error_code); if (status) { /* FIXME: bounds check? */ - apdu_timeout_set((uint16_t) value.type.Unsigned_Int); + 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); + &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); + &wp_data->error_class, &wp_data->error_code); if (status) { - temp = Device_Set_System_Status((BACNET_DEVICE_STATUS) - value.type.Enumerated, false); + temp = Device_Set_System_Status( + (BACNET_DEVICE_STATUS)value.type.Enumerated, false); if (temp != 0) { status = false; wp_data->error_class = ERROR_CLASS_PROPERTY; @@ -1794,14 +1511,13 @@ bool Device_Write_Property_Local( } break; case PROP_OBJECT_NAME: - status = - WPValidateString(&value, - characterstring_capacity(&My_Object_Name), false, + status = WPValidateString( + &value, characterstring_capacity(&My_Object_Name), false, &wp_data->error_class, &wp_data->error_code); if (status) { /* All the object names in a device must be unique */ if (Device_Valid_Object_Name(&value.type.Character_String, - &object_type, &object_instance)) { + &object_type, &object_instance)) { if ((object_type == wp_data->object_type) && (object_instance == wp_data->object_instance)) { /* writing same name to same object */ @@ -1819,10 +1535,10 @@ bool Device_Write_Property_Local( case PROP_LOCATION: status = WPValidateString(&value, MAX_DEV_LOC_LEN, true, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { - Device_Set_Location(characterstring_value(&value. - type.Character_String), + Device_Set_Location( + characterstring_value(&value.type.Character_String), characterstring_length(&value.type.Character_String)); } break; @@ -1830,20 +1546,20 @@ bool Device_Write_Property_Local( case PROP_DESCRIPTION: status = WPValidateString(&value, MAX_DEV_DESC_LEN, true, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { - Device_Set_Description(characterstring_value(&value. - type.Character_String), + Device_Set_Description( + characterstring_value(&value.type.Character_String), characterstring_length(&value.type.Character_String)); } break; case PROP_MODEL_NAME: status = WPValidateString(&value, MAX_DEV_MOD_LEN, true, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { - Device_Set_Model_Name(characterstring_value(&value. - type.Character_String), + Device_Set_Model_Name( + characterstring_value(&value.type.Character_String), characterstring_length(&value.type.Character_String)); } break; @@ -1897,8 +1613,8 @@ bool Device_Write_Property_Local( #endif case PROP_UTC_OFFSET: if (value.tag == BACNET_APPLICATION_TAG_SIGNED_INT) { - if ((value.type.Signed_Int < (12*60)) && - (value.type.Signed_Int > (-12*60))) { + if ((value.type.Signed_Int < (12 * 60)) && + (value.type.Signed_Int > (-12 * 60))) { Device_UTC_Offset_Set(value.type.Signed_Int); status = true; } else { @@ -1909,16 +1625,16 @@ bool Device_Write_Property_Local( wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; } - break; + 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); + &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; @@ -1929,11 +1645,11 @@ bool Device_Write_Property_Local( case PROP_MAX_MASTER: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { if ((value.type.Unsigned_Int > 0) && (value.type.Unsigned_Int <= 127)) { - dlmstp_set_max_master((uint8_t) value.type.Unsigned_Int); + dlmstp_set_max_master((uint8_t)value.type.Unsigned_Int); } else { status = false; wp_data->error_class = ERROR_CLASS_PROPERTY; @@ -1989,10 +1705,9 @@ bool Device_Write_Property_Local( * and new Value on entry, and APDU message on return. * @return True on success, else False if there is an error. */ -bool Device_Write_Property( - BACNET_WRITE_PROPERTY_DATA * wp_data) +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 */ @@ -2036,12 +1751,11 @@ bool Device_Write_Property( * @param [out] The value list * @return True if the object instance supports this feature and value changed. */ -bool Device_Encode_Value_List( - BACNET_OBJECT_TYPE object_type, - uint32_t object_instance, - BACNET_PROPERTY_VALUE * value_list) +bool Device_Encode_Value_List(BACNET_OBJECT_TYPE object_type, + uint32_t object_instance, + BACNET_PROPERTY_VALUE *value_list) { - bool status = false; /* Ever the pessamist! */ + bool status = false; /* Ever the pessamist! */ struct object_functions *pObject = NULL; pObject = Device_Objects_Find_Functions(object_type); @@ -2064,11 +1778,9 @@ bool Device_Encode_Value_List( * @param [in] The object instance to be looked up. * @return True if the COV flag is set */ -bool Device_COV( - BACNET_OBJECT_TYPE object_type, - uint32_t object_instance) +bool Device_COV(BACNET_OBJECT_TYPE object_type, uint32_t object_instance) { - bool status = false; /* Ever the pessamist! */ + bool status = false; /* Ever the pessamist! */ struct object_functions *pObject = NULL; pObject = Device_Objects_Find_Functions(object_type); @@ -2089,9 +1801,7 @@ bool Device_COV( * @param [in] The object type to be looked up. * @param [in] The object instance to be looked up. */ -void Device_COV_Clear( - BACNET_OBJECT_TYPE object_type, - uint32_t object_instance) +void Device_COV_Clear(BACNET_OBJECT_TYPE object_type, uint32_t object_instance) { struct object_functions *pObject = NULL; @@ -2107,8 +1817,7 @@ void Device_COV_Clear( } #if defined(INTRINSIC_REPORTING) -void Device_local_reporting( - void) +void Device_local_reporting(void) { struct object_functions *pObject; uint32_t objects_count; @@ -2140,10 +1849,9 @@ void Device_local_reporting( * @param [in] The object type to be looked up. * @return True if the object instance supports this feature. */ -bool Device_Value_List_Supported( - BACNET_OBJECT_TYPE object_type) +bool Device_Value_List_Supported(BACNET_OBJECT_TYPE object_type) { - bool status = false; /* Ever the pessamist! */ + bool status = false; /* Ever the pessamist! */ struct object_functions *pObject = NULL; pObject = Device_Objects_Find_Functions(object_type); @@ -2164,8 +1872,7 @@ bool Device_Value_List_Supported( * Each Child Object must provide some implementation of each of these * functions in order to properly support the default handlers. */ -void Device_Init( - object_functions_t * object_table) +void Device_Init(object_functions_t *object_table) { struct object_functions *pObject = NULL; #if defined(BAC_UCI) @@ -2200,11 +1907,10 @@ 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 */ +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) { case PROP_VT_CLASSES_SUPPORTED: @@ -2240,7 +1946,6 @@ bool DeviceGetRRInfo( return status; } - #ifdef BAC_ROUTING /**************************************************************************** ************* BACnet Routing Functionality (Optional) ********************** @@ -2256,8 +1961,7 @@ bool DeviceGetRRInfo( * @param first_object_instance Set the first (gateway) Device to this instance number. */ -void Routing_Device_Init( - uint32_t first_object_instance) +void Routing_Device_Init(uint32_t first_object_instance) { struct object_functions *pDevObject = NULL; @@ -2276,17 +1980,14 @@ void Routing_Device_Init( #endif /* BAC_ROUTING */ - #ifdef TEST #include #include #include "ctest.h" -bool WPValidateArgType( - BACNET_APPLICATION_DATA_VALUE * pValue, - uint8_t ucExpectedTag, - BACNET_ERROR_CLASS * pErrorClass, - BACNET_ERROR_CODE * pErrorCode) +bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue, + uint8_t ucExpectedTag, BACNET_ERROR_CLASS *pErrorClass, + BACNET_ERROR_CODE *pErrorCode) { pValue = pValue; ucExpectedTag = ucExpectedTag; @@ -2296,12 +1997,9 @@ bool WPValidateArgType( return false; } -bool WPValidateString( - BACNET_APPLICATION_DATA_VALUE * pValue, - int iMaxLen, - bool bEmptyAllowed, - BACNET_ERROR_CLASS * pErrorClass, - BACNET_ERROR_CODE * pErrorCode) +bool WPValidateString(BACNET_APPLICATION_DATA_VALUE *pValue, int iMaxLen, + bool bEmptyAllowed, BACNET_ERROR_CLASS *pErrorClass, + BACNET_ERROR_CODE *pErrorCode) { pValue = pValue; iMaxLen = iMaxLen; @@ -2312,9 +2010,7 @@ bool WPValidateString( return false; } -int handler_cov_encode_subscriptions( - uint8_t * apdu, - int max_apdu) +int handler_cov_encode_subscriptions(uint8_t *apdu, int max_apdu) { apdu = apdu; max_apdu = max_apdu; @@ -2322,8 +2018,7 @@ int handler_cov_encode_subscriptions( return 0; } -void testDevice( - Test * pTest) +void testDevice(Test *pTest) { bool status = false; const char *name = "Patricia"; @@ -2336,14 +2031,13 @@ void testDevice( ct_test(pTest, status == true); status = Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE / 2); ct_test(pTest, - Device_Object_Instance_Number() == (BACNET_MAX_INSTANCE / 2)); + Device_Object_Instance_Number() == (BACNET_MAX_INSTANCE / 2)); ct_test(pTest, status == true); status = Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE + 1); ct_test(pTest, - Device_Object_Instance_Number() != (BACNET_MAX_INSTANCE + 1)); + Device_Object_Instance_Number() != (BACNET_MAX_INSTANCE + 1)); ct_test(pTest, status == false); - Device_Set_System_Status(STATUS_NON_OPERATIONAL, true); ct_test(pTest, Device_System_Status() == STATUS_NON_OPERATIONAL); @@ -2356,8 +2050,7 @@ void testDevice( } #ifdef TEST_DEVICE -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -2369,7 +2062,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/demo/object/gw_device.c b/demo/object/gw_device.c index 985535f1..39c0b53e 100644 --- a/demo/object/gw_device.c +++ b/demo/object/gw_device.c @@ -1,44 +1,45 @@ /************************************************************************** -* -* Copyright (C) 2005,2010 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2005,2010 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ -/** @file gw_device.c Functions that extend the Device object to support routing. */ +/** @file gw_device.c Functions that extend the Device object to support + * routing. */ #include #include -#include /* for memmove */ -#include /* for timezone, localtime */ +#include /* for memmove */ +#include /* for timezone, localtime */ #include "bacdef.h" #include "bacdcode.h" #include "bacenum.h" #include "bacapp.h" -#include "config.h" /* the custom stuff */ +#include "config.h" /* the custom stuff */ #include "apdu.h" #include "wp.h" /* write property handling */ #include "rp.h" /* read property handling */ #include "version.h" -#include "device.h" /* me */ +#include "device.h" /* me */ #include "handlers.h" #include "datalink.h" #include "address.h" @@ -56,7 +57,7 @@ #include "ms-input.h" #include "trendlog.h" #if defined(BACFILE) -#include "bacfile.h" /* object list dependency */ +#include "bacfile.h" /* object list dependency */ #endif /* os specfic includes */ #include "timer.h" @@ -68,19 +69,15 @@ long int timezone; #endif /* local forward and external prototypes */ -extern int Device_Read_Property_Local( - BACNET_READ_PROPERTY_DATA * rpdata); -extern bool Device_Write_Property_Local( - BACNET_WRITE_PROPERTY_DATA * wp_data); -int Routed_Device_Read_Property_Local( - BACNET_READ_PROPERTY_DATA * rpdata); -bool Routed_Device_Write_Property_Local( - BACNET_WRITE_PROPERTY_DATA * wp_data); - +extern int Device_Read_Property_Local(BACNET_READ_PROPERTY_DATA *rpdata); +extern bool Device_Write_Property_Local(BACNET_WRITE_PROPERTY_DATA *wp_data); +int Routed_Device_Read_Property_Local(BACNET_READ_PROPERTY_DATA *rpdata); +bool Routed_Device_Write_Property_Local(BACNET_WRITE_PROPERTY_DATA *wp_data); #if !defined(BAC_ROUTING) #ifdef _MSC_VER -#pragma message This file should not be included in the build unless BAC_ROUTING is enabled. +#pragma message This file should not be included in the build unless \ + BAC_ROUTING is enabled. #else #warning This file should not be included in the build unless BAC_ROUTING is enabled. #endif @@ -118,10 +115,9 @@ uint16_t iCurrent_Device_Idx = 0; * @return The index of this instance in the Devices[] array, * or -1 if there isn't enough room to add this Device. */ -uint16_t Add_Routed_Device( - uint32_t Object_Instance, - BACNET_CHARACTER_STRING * sObject_Name, - const char *sDescription) +uint16_t Add_Routed_Device(uint32_t Object_Instance, + BACNET_CHARACTER_STRING *sObject_Name, + const char *sDescription) { int i = Num_Managed_Devices; if (i < MAX_NUM_DEVICES) { @@ -132,21 +128,21 @@ uint16_t Add_Routed_Device( pDev->bacObj.Object_Instance_Number = Object_Instance; if (sObject_Name != NULL) Routed_Device_Set_Object_Name(sObject_Name->encoding, - sObject_Name->value, sObject_Name->length); + sObject_Name->value, + sObject_Name->length); else Routed_Device_Set_Object_Name(CHARACTER_UTF8, "No Name", - strlen("No Name")); + strlen("No Name")); if (sDescription != NULL) Routed_Device_Set_Description(sDescription, strlen(sDescription)); else Routed_Device_Set_Description("No Descr", strlen("No Descr")); - pDev->Database_Revision = 0; /* Reset/Initialize now */ + pDev->Database_Revision = 0; /* Reset/Initialize now */ return i; } else return -1; } - /** Return the Device Object descriptive data for the indicated entry. * @param idx [in] Index into Devices[] array being requested. * 0 is for the main, gateway Device entry. @@ -156,8 +152,7 @@ uint16_t Add_Routed_Device( * @return Pointer to the requested Device Object data, or NULL if the idx * is for an invalid row entry (eg, after the last good Device). */ -DEVICE_OBJECT_DATA *Get_Routed_Device_Object( - int idx) +DEVICE_OBJECT_DATA *Get_Routed_Device_Object(int idx) { if (idx == -1) return &Devices[iCurrent_Device_Idx]; @@ -174,11 +169,10 @@ DEVICE_OBJECT_DATA *Get_Routed_Device_Object( * -1 is a special case meaning "whichever iCurrent_Device_Idx * is currently set to" * If valid idx, will set iCurrent_Device_Idx with the idx - * @return Pointer to the requested Device Object BACnet address, or NULL if the idx - * is for an invalid row entry (eg, after the last good Device). + * @return Pointer to the requested Device Object BACnet address, or NULL if the + * idx is for an invalid row entry (eg, after the last good Device). */ -BACNET_ADDRESS *Get_Routed_Device_Address( - int idx) +BACNET_ADDRESS *Get_Routed_Device_Address(int idx) { if (idx == -1) return &Devices[iCurrent_Device_Idx].bacDevAddr; @@ -189,8 +183,6 @@ BACNET_ADDRESS *Get_Routed_Device_Address( return NULL; } - - /** Get the currently active BACnet address. * This is an implementation of the datalink_get_my_address() template for * devices with routing. @@ -198,16 +190,14 @@ BACNET_ADDRESS *Get_Routed_Device_Address( * @param my_address [out] Points to the currently active Device Object's * BACnet address. */ -void routed_get_my_address( - BACNET_ADDRESS * my_address) +void routed_get_my_address(BACNET_ADDRESS *my_address) { if (my_address) { memcpy(my_address, &Devices[iCurrent_Device_Idx].bacDevAddr, - sizeof(BACNET_ADDRESS)); + sizeof(BACNET_ADDRESS)); } } - /** See if the Gateway or Routed Device at the given idx matches * the given MAC address. * Has the desirable side-effect of setting iCurrent_Device_Idx to the @@ -225,10 +215,8 @@ void routed_get_my_address( * meaning MAC broadcast, so it's an automatic match). * Else False if no match or invalid idx is given. */ -bool Routed_Device_Address_Lookup( - int idx, - uint8_t address_len, - uint8_t * mac_adress) +bool Routed_Device_Address_Lookup(int idx, uint8_t address_len, + uint8_t *mac_adress) { bool result = false; DEVICE_OBJECT_DATA *pDev = &Devices[idx]; @@ -244,7 +232,7 @@ bool Routed_Device_Address_Lookup( if (pDev->bacDevAddr.mac[i] != mac_adress[i]) break; } - if (i == address_len) { /* Success! */ + if (i == address_len) { /* Success! */ iCurrent_Device_Idx = idx; result = true; } @@ -253,7 +241,6 @@ bool Routed_Device_Address_Lookup( return result; } - /** Find the next Gateway or Routed Device at the given MAC address, * starting the search at the "cursor". * Has the desirable side-effect of setting internal iCurrent_Device_Idx @@ -261,31 +248,27 @@ bool Routed_Device_Address_Lookup( * functions. * * @param dest [in] The BACNET_ADDRESS of the message's destination. - * If the Length of the mac_adress[] field is 0, then this is a MAC - * broadcast. Otherwise, size is determined - * by the DLL type (eg, 6 for BIP and 2 for MSTP). - * @param DNET_list [in] List of our reachable downstream BACnet Network numbers. - * Normally just one valid entry; terminated with a -1 value. + * If the Length of the mac_adress[] field is 0, then this is a + * MAC broadcast. Otherwise, size is determined by the DLL type (eg, 6 for BIP + * and 2 for MSTP). + * @param DNET_list [in] List of our reachable downstream BACnet Network + * numbers. Normally just one valid entry; terminated with a -1 value. * @param cursor [in,out] The concept of the cursor is that it is a starting - * "hint" for the search; on return, it is updated to provide the - * cursor value to use with a subsequent GetNext call, or it - * equals -1 if there are no further matches. - * Set it to 0 on entry to access the main, gateway Device entry, or - * to start looping through the routed devices. + * "hint" for the search; on return, it is updated to provide + * the cursor value to use with a subsequent GetNext call, or it equals -1 if + * there are no further matches. Set it to 0 on entry to access the main, + * gateway Device entry, or to start looping through the routed devices. * Otherwise, its returned value is implementation-dependent and the * calling function should not alter or interpret it. * * @return True if the MAC addresses match (or if BACNET_BROADCAST_NETWORK and - * the dest->len is 0, meaning MAC bcast, so it's an automatic match). - * Else False if no match or invalid idx is given; the cursor will - * be returned as -1 in these cases. + * the dest->len is 0, meaning MAC bcast, so it's an automatic + * match). Else False if no match or invalid idx is given; the cursor will be + * returned as -1 in these cases. */ -bool Routed_Device_GetNext( - BACNET_ADDRESS * dest, - int *DNET_list, - int *cursor) +bool Routed_Device_GetNext(BACNET_ADDRESS *dest, int *DNET_list, int *cursor) { - int dnet = DNET_list[0]; /* Get the DNET of our virtual network */ + int dnet = DNET_list[0]; /* Get the DNET of our virtual network */ int idx = *cursor; bool bSuccess = false; @@ -319,44 +302,40 @@ bool Routed_Device_GetNext( * For broadcasts, all Devices get a chance at it. */ else if (dest->net == dnet) { - if (idx == 0) /* Step over this case (starting point) */ + if (idx == 0) /* Step over this case (starting point) */ idx = 1; while (idx < MAX_NUM_DEVICES) { bSuccess = Routed_Device_Address_Lookup(idx++, dest->len, dest->adr); if (bSuccess) - break; /* We don't need to keep looking */ + break; /* We don't need to keep looking */ } } if (!bSuccess) *cursor = -1; - else if (idx == MAX_NUM_DEVICES) /* No more to GetNext */ + else if (idx == MAX_NUM_DEVICES) /* No more to GetNext */ *cursor = -1; else *cursor = idx; return bSuccess; } - /** Check if the destination network is reachable - is it our virtual network, * or local or else broadcast. * * @param dest_net [in] The BACnet network number of a message's destination. - * Success if it is our virtual network number, or 0 (local for the - * gateway, or 0xFFFF for a broadcast network number. - * @param DNET_list [in] List of our reachable downstream BACnet Network numbers. - * Normally just one valid entry; terminated with a -1 value. + * Success if it is our virtual network number, or 0 (local for + * the gateway, or 0xFFFF for a broadcast network number. + * @param DNET_list [in] List of our reachable downstream BACnet Network + * numbers. Normally just one valid entry; terminated with a -1 value. * @return True if matches our virtual network, or is for the local network - * Device (the gateway), or is BACNET_BROADCAST_NETWORK, which is - * an automatic match. - * Else False if not a reachable network. + * Device (the gateway), or is BACNET_BROADCAST_NETWORK, + * which is an automatic match. Else False if not a reachable network. */ -bool Routed_Device_Is_Valid_Network( - uint16_t dest_net, - int *DNET_list) +bool Routed_Device_Is_Valid_Network(uint16_t dest_net, int *DNET_list) { - int dnet = DNET_list[0]; /* Get the DNET of our virtual network */ + int dnet = DNET_list[0]; /* Get the DNET of our virtual network */ bool bSuccess = false; /* First, see if it's a BACnet broadcast (automatic pass). */ @@ -374,11 +353,9 @@ bool Routed_Device_Is_Valid_Network( return bSuccess; } - /* methods to override the normal Device objection functions */ -uint32_t Routed_Device_Index_To_Instance( - unsigned index) +uint32_t Routed_Device_Index_To_Instance(unsigned index) { index = index; return Devices[iCurrent_Device_Idx].bacObj.Object_Instance_Number; @@ -389,11 +366,11 @@ uint32_t Routed_Device_Index_To_Instance( * iCurrent_Device_Idx must have been set to point to this Device Object * before this function is called. * @param object_id [in] Object ID of the desired Device object. - * If the wildcard value (BACNET_MAX_INSTANCE), always matches. + * If the wildcard value (BACNET_MAX_INSTANCE), always + * matches. * @return True if Object ID matches the present Device, else False. */ -bool Routed_Device_Valid_Object_Instance_Number( - uint32_t object_id) +bool Routed_Device_Valid_Object_Instance_Number(uint32_t object_id) { bool bResult = false; DEVICE_OBJECT_DATA *pDev = &Devices[iCurrent_Device_Idx]; @@ -404,14 +381,12 @@ bool Routed_Device_Valid_Object_Instance_Number( return bResult; } -bool Routed_Device_Name( - uint32_t object_instance, - BACNET_CHARACTER_STRING * object_name) +bool Routed_Device_Name(uint32_t object_instance, + BACNET_CHARACTER_STRING *object_name) { DEVICE_OBJECT_DATA *pDev = &Devices[iCurrent_Device_Idx]; if (object_instance == pDev->bacObj.Object_Instance_Number) { - return characterstring_init_ansi(object_name, - pDev->bacObj.Object_Name); + return characterstring_init_ansi(object_name, pDev->bacObj.Object_Name); } return false; @@ -423,10 +398,9 @@ bool Routed_Device_Name( * @return The length of the apdu encoded, or BACNET_STATUS_ERROR for error or * BACNET_STATUS_ABORT for abort message. */ -int Routed_Device_Read_Property_Local( - BACNET_READ_PROPERTY_DATA * rpdata) +int Routed_Device_Read_Property_Local(BACNET_READ_PROPERTY_DATA *rpdata) { - int apdu_len = 0; /* return value */ + int apdu_len = 0; /* return value */ BACNET_CHARACTER_STRING char_string; uint8_t *apdu = NULL; DEVICE_OBJECT_DATA *pDev = &Devices[iCurrent_Device_Idx]; @@ -438,9 +412,8 @@ int Routed_Device_Read_Property_Local( apdu = rpdata->application_data; switch (rpdata->object_property) { case PROP_OBJECT_IDENTIFIER: - apdu_len = - encode_application_object_id(&apdu[0], OBJECT_DEVICE, - pDev->bacObj.Object_Instance_Number); + apdu_len = encode_application_object_id( + &apdu[0], OBJECT_DEVICE, pDev->bacObj.Object_Instance_Number); break; case PROP_OBJECT_NAME: characterstring_init_ansi(&char_string, pDev->bacObj.Object_Name); @@ -464,17 +437,15 @@ int Routed_Device_Read_Property_Local( return (apdu_len); } -bool Routed_Device_Write_Property_Local( - BACNET_WRITE_PROPERTY_DATA * wp_data) +bool Routed_Device_Write_Property_Local(BACNET_WRITE_PROPERTY_DATA *wp_data) { - bool status = false; /* return value */ + bool status = false; /* return value */ int len = 0; BACNET_APPLICATION_DATA_VALUE value; /* decode the some of the request */ - len = - bacapp_decode_application_data(wp_data->application_data, - wp_data->application_data_len, &value); + len = bacapp_decode_application_data(wp_data->application_data, + wp_data->application_data_len, &value); if (len < 0) { /* error while decoding - a value larger than we can handle */ wp_data->error_class = ERROR_CLASS_PROPERTY; @@ -493,12 +464,13 @@ bool Routed_Device_Write_Property_Local( case PROP_OBJECT_IDENTIFIER: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_OBJECT_ID, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { if ((value.type.Object_Id.type == OBJECT_DEVICE) && - (Routed_Device_Set_Object_Instance_Number(value.type. - Object_Id.instance))) { - /* FIXME: we could send an I-Am broadcast to let the world know */ + (Routed_Device_Set_Object_Instance_Number( + value.type.Object_Id.instance))) { + /* FIXME: we could send an I-Am broadcast to let the world + * know */ } else { status = false; wp_data->error_class = ERROR_CLASS_PROPERTY; @@ -509,10 +481,10 @@ bool Routed_Device_Write_Property_Local( case PROP_OBJECT_NAME: status = WPValidateString(&value, MAX_DEV_NAME_LEN, false, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { - Routed_Device_Set_Object_Name(characterstring_encoding(&value. - type.Character_String), + Routed_Device_Set_Object_Name( + characterstring_encoding(&value.type.Character_String), characterstring_value(&value.type.Character_String), characterstring_length(&value.type.Character_String)); } @@ -532,14 +504,12 @@ bool Routed_Device_Write_Property_Local( * * @return The Instance number of the currently active Device. */ -uint32_t Routed_Device_Object_Instance_Number( - void) +uint32_t Routed_Device_Object_Instance_Number(void) { return Devices[iCurrent_Device_Idx].bacObj.Object_Instance_Number; } -bool Routed_Device_Set_Object_Instance_Number( - uint32_t object_id) +bool Routed_Device_Set_Object_Instance_Number(uint32_t object_id) { bool status = true; /* return value */ @@ -559,12 +529,10 @@ bool Routed_Device_Set_Object_Instance_Number( * @param object_name [in] Character String for the new Object Name. * @return True if succeed in updating Object Name, else False. */ -bool Routed_Device_Set_Object_Name( - uint8_t encoding, - const char *value, - size_t length) +bool Routed_Device_Set_Object_Name(uint8_t encoding, const char *value, + size_t length) { - bool status = false; /*return value */ + bool status = false; /*return value */ DEVICE_OBJECT_DATA *pDev = &Devices[iCurrent_Device_Idx]; if ((encoding == CHARACTER_UTF8) && (length < MAX_DEV_NAME_LEN)) { @@ -578,11 +546,9 @@ bool Routed_Device_Set_Object_Name( return status; } -bool Routed_Device_Set_Description( - const char *name, - size_t length) +bool Routed_Device_Set_Description(const char *name, size_t length) { - bool status = false; /*return value */ + bool status = false; /*return value */ DEVICE_OBJECT_DATA *pDev = &Devices[iCurrent_Device_Idx]; if (length < MAX_DEV_DESC_LEN) { @@ -594,20 +560,17 @@ bool Routed_Device_Set_Description( return status; } - /* * Shortcut for incrementing database revision as this is potentially * the most common operation if changing object names and ids is * implemented. */ -void Routed_Device_Inc_Database_Revision( - void) +void Routed_Device_Inc_Database_Revision(void) { DEVICE_OBJECT_DATA *pDev = &Devices[iCurrent_Device_Idx]; pDev->Database_Revision++; } - /** Check to see if the current Device supports this service. * Presently checks for RD and DCC and only allows them if the current * device is the gateway device. @@ -621,11 +584,9 @@ void Routed_Device_Inc_Database_Revision( * just 1 if no apdu_buff was supplied and service is not supported, * else 0 if service is approved for the current device. */ -int Routed_Device_Service_Approval( - BACNET_CONFIRMED_SERVICE service, - int service_argument, - uint8_t * apdu_buff, - uint8_t invoke_id) +int Routed_Device_Service_Approval(BACNET_CONFIRMED_SERVICE service, + int service_argument, uint8_t *apdu_buff, + uint8_t invoke_id) { int len = 0; switch (service) { @@ -635,9 +596,9 @@ int Routed_Device_Service_Approval( if (apdu_buff != NULL) len = reject_encode_apdu(apdu_buff, invoke_id, - REJECT_REASON_UNRECOGNIZED_SERVICE); + REJECT_REASON_UNRECOGNIZED_SERVICE); else - len = 1; /* Non-zero return */ + len = 1; /* Non-zero return */ } break; case SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL: @@ -646,9 +607,9 @@ int Routed_Device_Service_Approval( if (apdu_buff != NULL) len = reject_encode_apdu(apdu_buff, invoke_id, - REJECT_REASON_UNRECOGNIZED_SERVICE); + REJECT_REASON_UNRECOGNIZED_SERVICE); else - len = 1; /* Non-zero return */ + len = 1; /* Non-zero return */ } break; default: diff --git a/demo/object/iv.c b/demo/object/iv.c index 440d539c..3df00aeb 100644 --- a/demo/object/iv.c +++ b/demo/object/iv.c @@ -41,7 +41,7 @@ #include "bacenum.h" #include "bacapp.h" #include "bactext.h" -#include "config.h" /* the custom stuff */ +#include "config.h" /* the custom stuff */ #include "device.h" #include "handlers.h" /* me! */ @@ -52,31 +52,25 @@ #endif struct integer_object { - bool Out_Of_Service:1; + bool Out_Of_Service : 1; int32_t Present_Value; uint16_t Units; }; struct integer_object Integer_Value[MAX_INTEGER_VALUES]; /* These three arrays are used by the ReadPropertyMultiple handler */ -static const int Integer_Value_Properties_Required[] = { - PROP_OBJECT_IDENTIFIER, - PROP_OBJECT_NAME, - PROP_OBJECT_TYPE, - PROP_PRESENT_VALUE, - PROP_STATUS_FLAGS, - PROP_UNITS, - -1 -}; +static const int Integer_Value_Properties_Required[] = {PROP_OBJECT_IDENTIFIER, + PROP_OBJECT_NAME, + PROP_OBJECT_TYPE, + PROP_PRESENT_VALUE, + PROP_STATUS_FLAGS, + PROP_UNITS, + -1}; -static const int Integer_Value_Properties_Optional[] = { - PROP_OUT_OF_SERVICE, - -1 -}; +static const int Integer_Value_Properties_Optional[] = {PROP_OUT_OF_SERVICE, + -1}; -static const int Integer_Value_Properties_Proprietary[] = { - -1 -}; +static const int Integer_Value_Properties_Proprietary[] = {-1}; /** * Returns the list of required, optional, and proprietary properties. @@ -89,10 +83,8 @@ static const int Integer_Value_Properties_Proprietary[] = { * @param pProprietary - pointer to list of int terminated by -1, of * BACnet proprietary properties for this object. */ -void Integer_Value_Property_Lists( - const int **pRequired, - const int **pOptional, - const int **pProprietary) +void Integer_Value_Property_Lists(const int **pRequired, const int **pOptional, + const int **pProprietary) { if (pRequired) *pRequired = Integer_Value_Properties_Required; @@ -111,8 +103,7 @@ void Integer_Value_Property_Lists( * * @return true if the instance is valid, and false if not */ -bool Integer_Value_Valid_Instance( - uint32_t object_instance) +bool Integer_Value_Valid_Instance(uint32_t object_instance) { unsigned int index; @@ -129,8 +120,7 @@ bool Integer_Value_Valid_Instance( * * @return Number of Analog Value objects */ -unsigned Integer_Value_Count( - void) +unsigned Integer_Value_Count(void) { return MAX_INTEGER_VALUES; } @@ -143,8 +133,7 @@ unsigned Integer_Value_Count( * * @return object instance-number for the given index */ -uint32_t Integer_Value_Index_To_Instance( - unsigned index) +uint32_t Integer_Value_Index_To_Instance(unsigned index) { uint32_t instance = 1; @@ -162,8 +151,7 @@ uint32_t Integer_Value_Index_To_Instance( * @return index for the given instance-number, or MAX_INTEGER_VALUES * if not valid. */ -unsigned Integer_Value_Instance_To_Index( - uint32_t object_instance) +unsigned Integer_Value_Instance_To_Index(uint32_t object_instance) { unsigned index = MAX_INTEGER_VALUES; @@ -184,8 +172,7 @@ unsigned Integer_Value_Instance_To_Index( * * @return present-value of the object */ -int32_t Integer_Value_Present_Value( - uint32_t object_instance) +int32_t Integer_Value_Present_Value(uint32_t object_instance) { int32_t value = 0; unsigned int index; @@ -206,10 +193,8 @@ int32_t Integer_Value_Present_Value( * * @return true if values are within range and present-value is set. */ -bool Integer_Value_Present_Value_Set( - uint32_t object_instance, - int32_t value, - uint8_t priority) +bool Integer_Value_Present_Value_Set(uint32_t object_instance, int32_t value, + uint8_t priority) { bool status = false; unsigned int index; @@ -234,9 +219,8 @@ bool Integer_Value_Present_Value_Set( * * @return true if object-name was retrieved */ -bool Integer_Value_Object_Name( - uint32_t object_instance, - BACNET_CHARACTER_STRING * object_name) +bool Integer_Value_Object_Name(uint32_t object_instance, + BACNET_CHARACTER_STRING *object_name) { char text_string[32] = ""; unsigned int index; @@ -244,7 +228,8 @@ bool Integer_Value_Object_Name( index = Integer_Value_Instance_To_Index(object_instance); if (index < MAX_INTEGER_VALUES) { - sprintf(text_string, "ANALOG VALUE %lu", (unsigned long) object_instance); + sprintf(text_string, "ANALOG VALUE %lu", + (unsigned long)object_instance); status = characterstring_init_ansi(object_name, text_string); } @@ -258,8 +243,7 @@ bool Integer_Value_Object_Name( * * @return units property value */ -uint16_t Integer_Value_Units( - uint32_t instance) +uint16_t Integer_Value_Units(uint32_t instance) { unsigned int index; uint16_t units = UNITS_NO_UNITS; @@ -280,9 +264,7 @@ uint16_t Integer_Value_Units( * * @return true if the units property value was set */ -bool Integer_Value_Units_Set( - uint32_t instance, - uint16_t units) +bool Integer_Value_Units_Set(uint32_t instance, uint16_t units) { unsigned int index = 0; bool status = false; @@ -304,15 +286,14 @@ bool Integer_Value_Units_Set( * * @return out-of-service property value */ -bool Integer_Value_Out_Of_Service( - uint32_t instance) +bool Integer_Value_Out_Of_Service(uint32_t instance) { unsigned int index = 0; bool value = false; index = Integer_Value_Instance_To_Index(instance); if (index < MAX_INTEGER_VALUES) { - value= Integer_Value[index].Out_Of_Service; + value = Integer_Value[index].Out_Of_Service; } return value; @@ -326,9 +307,7 @@ bool Integer_Value_Out_Of_Service( * * @return true if the out-of-service property value was set */ -void Integer_Value_Out_Of_Service_Set( - uint32_t instance, - bool value) +void Integer_Value_Out_Of_Service_Set(uint32_t instance, bool value) { unsigned int index = 0; @@ -348,10 +327,9 @@ void Integer_Value_Out_Of_Service_Set( * @return number of APDU bytes in the response, or * BACNET_STATUS_ERROR on error. */ -int Integer_Value_Read_Property( - BACNET_READ_PROPERTY_DATA * rpdata) +int Integer_Value_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata) { - int apdu_len = 0; /* return value */ + int apdu_len = 0; /* return value */ BACNET_BIT_STRING bit_string; BACNET_CHARACTER_STRING char_string; uint8_t *apdu = NULL; @@ -367,9 +345,8 @@ int Integer_Value_Read_Property( apdu = rpdata->application_data; switch (rpdata->object_property) { case PROP_OBJECT_IDENTIFIER: - apdu_len = - encode_application_object_id(&apdu[0], OBJECT_INTEGER_VALUE, - rpdata->object_instance); + apdu_len = encode_application_object_id( + &apdu[0], OBJECT_INTEGER_VALUE, rpdata->object_instance); break; case PROP_OBJECT_NAME: Integer_Value_Object_Name(rpdata->object_instance, &char_string); @@ -381,7 +358,8 @@ int Integer_Value_Read_Property( encode_application_enumerated(&apdu[0], OBJECT_INTEGER_VALUE); break; case PROP_PRESENT_VALUE: - integer_value = Integer_Value_Present_Value(rpdata->object_instance); + integer_value = + Integer_Value_Present_Value(rpdata->object_instance); apdu_len = encode_application_signed(&apdu[0], integer_value); break; case PROP_STATUS_FLAGS: @@ -428,17 +406,15 @@ int Integer_Value_Read_Property( * * @return false if an error is loaded, true if no errors */ -bool Integer_Value_Write_Property( - BACNET_WRITE_PROPERTY_DATA * wp_data) +bool Integer_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data) { - bool status = false; /* return value */ + bool status = false; /* return value */ int len = 0; BACNET_APPLICATION_DATA_VALUE value; /* decode the some of the request */ - len = - bacapp_decode_application_data(wp_data->application_data, - wp_data->application_data_len, &value); + len = bacapp_decode_application_data(wp_data->application_data, + wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ if (len < 0) { /* error while decoding - a value larger than we can handle */ @@ -456,22 +432,22 @@ bool Integer_Value_Write_Property( } switch (wp_data->object_property) { case PROP_PRESENT_VALUE: - status = + status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_SIGNED_INT, - &wp_data->error_class, &wp_data->error_code); - if (status) { + &wp_data->error_class, &wp_data->error_code); + if (status) { Integer_Value_Present_Value_Set(wp_data->object_instance, - value.type.Signed_Int, wp_data->priority); + value.type.Signed_Int, + wp_data->priority); } break; case PROP_OUT_OF_SERVICE: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { - Integer_Value_Out_Of_Service_Set( - wp_data->object_instance, - value.type.Boolean); + Integer_Value_Out_Of_Service_Set(wp_data->object_instance, + value.type.Boolean); } break; case PROP_OBJECT_IDENTIFIER: @@ -494,8 +470,7 @@ bool Integer_Value_Write_Property( /** * Initializes the Integer Value object data */ -void Integer_Value_Init( - void) +void Integer_Value_Init(void) { unsigned index = 0; diff --git a/demo/object/lc.c b/demo/object/lc.c index 4806bc14..59cc67c5 100644 --- a/demo/object/lc.c +++ b/demo/object/lc.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2007 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2007 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* Load Control Objects - customize for your use */ /* from 135-2004-Addendum e */ @@ -29,13 +29,13 @@ #include #include #include -#include /* for memcpy */ +#include /* for memcpy */ #include #include "bacdef.h" #include "bacdcode.h" #include "datetime.h" #include "bacenum.h" -#include "config.h" /* the custom stuff */ +#include "config.h" /* the custom stuff */ #include "lc.h" #include "ao.h" #include "wp.h" @@ -51,9 +51,9 @@ static BACNET_SHED_STATE Present_Value[MAX_LOAD_CONTROLS]; /* load control objects are required to support LEVEL */ typedef enum BACnetShedLevelType { - BACNET_SHED_TYPE_PERCENT, /* Unsigned */ - BACNET_SHED_TYPE_LEVEL, /* Unsigned */ - BACNET_SHED_TYPE_AMOUNT /* REAL */ + BACNET_SHED_TYPE_PERCENT, /* Unsigned */ + BACNET_SHED_TYPE_LEVEL, /* Unsigned */ + BACNET_SHED_TYPE_AMOUNT /* REAL */ } BACNET_SHED_LEVEL_TYPE; #define DEFAULT_VALUE_PERCENT 100 @@ -126,17 +126,9 @@ static unsigned Shed_Levels[MAX_LOAD_CONTROLS][MAX_SHED_LEVELS]; Load Control object can take on. It is the same for all the load control objects in this example device. */ static char *Shed_Level_Descriptions[MAX_SHED_LEVELS] = { - "dim lights 10%", - "dim lights 20%", - "dim lights 30%" -}; - -static float Shed_Level_Values[MAX_SHED_LEVELS] = { - 90.0, - 80.0, - 70.0 -}; + "dim lights 10%", "dim lights 20%", "dim lights 30%"}; +static float Shed_Level_Values[MAX_SHED_LEVELS] = {90.0, 80.0, 70.0}; /* These three arrays are used by the ReadPropertyMultiple handler */ static const int Load_Control_Properties_Required[] = { @@ -155,23 +147,15 @@ static const int Load_Control_Properties_Required[] = { PROP_ACTUAL_SHED_LEVEL, PROP_SHED_LEVELS, PROP_SHED_LEVEL_DESCRIPTIONS, - -1 -}; + -1}; static const int Load_Control_Properties_Optional[] = { - PROP_DESCRIPTION, - PROP_FULL_DUTY_BASELINE, - -1 -}; + PROP_DESCRIPTION, PROP_FULL_DUTY_BASELINE, -1}; -static const int Load_Control_Properties_Proprietary[] = { - -1 -}; +static const int Load_Control_Properties_Proprietary[] = {-1}; -void Load_Control_Property_Lists( - const int **pRequired, - const int **pOptional, - const int **pProprietary) +void Load_Control_Property_Lists(const int **pRequired, const int **pOptional, + const int **pProprietary) { if (pRequired) *pRequired = Load_Control_Properties_Required; @@ -183,8 +167,7 @@ void Load_Control_Property_Lists( return; } -void Load_Control_Init( - void) +void Load_Control_Init(void) { unsigned i, j; @@ -199,7 +182,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; @@ -217,8 +200,7 @@ void Load_Control_Init( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need validate that the */ /* given instance exists */ -bool Load_Control_Valid_Instance( - uint32_t object_instance) +bool Load_Control_Valid_Instance(uint32_t object_instance) { if (object_instance < MAX_LOAD_CONTROLS) return true; @@ -228,8 +210,7 @@ bool Load_Control_Valid_Instance( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then count how many you have */ -unsigned Load_Control_Count( - void) +unsigned Load_Control_Count(void) { return MAX_LOAD_CONTROLS; } @@ -237,8 +218,7 @@ unsigned Load_Control_Count( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need to return the instance */ /* that correlates to the correct index */ -uint32_t Load_Control_Index_To_Instance( - unsigned index) +uint32_t Load_Control_Index_To_Instance(unsigned index) { return index; } @@ -246,8 +226,7 @@ uint32_t Load_Control_Index_To_Instance( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need to return the index */ /* that correlates to the correct instance number */ -unsigned Load_Control_Instance_To_Index( - uint32_t object_instance) +unsigned Load_Control_Instance_To_Index(uint32_t object_instance) { unsigned index = MAX_LOAD_CONTROLS; @@ -257,8 +236,7 @@ unsigned Load_Control_Instance_To_Index( return index; } -static BACNET_SHED_STATE Load_Control_Present_Value( - uint32_t object_instance) +static BACNET_SHED_STATE Load_Control_Present_Value(uint32_t object_instance) { BACNET_SHED_STATE value = BACNET_SHED_INACTIVE; unsigned index = 0; @@ -272,11 +250,10 @@ static BACNET_SHED_STATE Load_Control_Present_Value( } /* note: the object name must be unique within this device */ -bool Load_Control_Object_Name( - uint32_t object_instance, - BACNET_CHARACTER_STRING * object_name) +bool Load_Control_Object_Name(uint32_t object_instance, + BACNET_CHARACTER_STRING *object_name) { - static char text_string[32] = ""; /* okay for single thread */ + static char text_string[32] = ""; /* okay for single thread */ bool status = false; if (object_instance < MAX_LOAD_CONTROLS) { @@ -287,37 +264,35 @@ bool Load_Control_Object_Name( return status; } -static void Update_Current_Time( - BACNET_DATE_TIME * bdatetime) +static void Update_Current_Time(BACNET_DATE_TIME *bdatetime) { time_t timer; struct tm *tblock; -/* -struct tm { - int tm_sec; - int tm_min; - int tm_hour; - int tm_mday; - int tm_mon; - int tm_year; - int tm_wday; - int tm_yday; - int tm_isdst; -}; -*/ + /* + struct tm { + int tm_sec; + int tm_min; + int tm_hour; + int tm_mday; + int tm_mon; + int tm_year; + int tm_wday; + int tm_yday; + int tm_isdst; + }; + */ timer = time(NULL); tblock = localtime(&timer); - datetime_set_values(bdatetime, (uint16_t) tblock->tm_year, - (uint8_t) tblock->tm_mon, (uint8_t) tblock->tm_mday, - (uint8_t) tblock->tm_hour, (uint8_t) tblock->tm_min, - (uint8_t) tblock->tm_sec, 0); + datetime_set_values(bdatetime, (uint16_t)tblock->tm_year, + (uint8_t)tblock->tm_mon, (uint8_t)tblock->tm_mday, + (uint8_t)tblock->tm_hour, (uint8_t)tblock->tm_min, + (uint8_t)tblock->tm_sec, 0); } /* convert the shed level request into an Analog Output Present_Value */ -static float Requested_Shed_Level_Value( - int object_index) +static float Requested_Shed_Level_Value(int object_index) { unsigned shed_level_index = 0; unsigned i = 0; @@ -326,13 +301,12 @@ static float Requested_Shed_Level_Value( switch (Requested_Shed_Level[object_index].type) { case BACNET_SHED_TYPE_PERCENT: requested_level = - (float) Requested_Shed_Level[object_index].value.percent; + (float)Requested_Shed_Level[object_index].value.percent; break; case BACNET_SHED_TYPE_AMOUNT: /* Assumptions: wattage is linear with analog output level */ - requested_level = - Full_Duty_Baseline[object_index] - - Requested_Shed_Level[object_index].value.amount; + requested_level = Full_Duty_Baseline[object_index] - + Requested_Shed_Level[object_index].value.amount; requested_level /= Full_Duty_Baseline[object_index]; requested_level *= 100.0; break; @@ -350,9 +324,7 @@ static float Requested_Shed_Level_Value( return requested_level; } -static void Shed_Level_Copy( - BACNET_SHED_LEVEL * dest, - BACNET_SHED_LEVEL * src) +static void Shed_Level_Copy(BACNET_SHED_LEVEL *dest, BACNET_SHED_LEVEL *src) { if (dest && src) { dest->type = src->type; @@ -371,9 +343,8 @@ static void Shed_Level_Copy( } } -static void Shed_Level_Default_Set( - BACNET_SHED_LEVEL * dest, - BACNET_SHED_LEVEL_TYPE type) +static void Shed_Level_Default_Set(BACNET_SHED_LEVEL *dest, + BACNET_SHED_LEVEL_TYPE type) { if (dest) { dest->type = type; @@ -392,8 +363,7 @@ static void Shed_Level_Default_Set( } } -static bool Able_To_Meet_Shed_Request( - int object_index) +static bool Able_To_Meet_Shed_Request(int object_index) { float level = 0.0; float requested_level = 0.0; @@ -428,30 +398,25 @@ static LOAD_CONTROL_STATE Load_Control_State[MAX_LOAD_CONTROLS]; static LOAD_CONTROL_STATE Load_Control_State_Previously[MAX_LOAD_CONTROLS]; #if PRINT_ENABLED_DEBUG -static void Print_Load_Control_State( - int object_index) +static void Print_Load_Control_State(int object_index) { char *Load_Control_State_Text[MAX_LOAD_CONTROLS] = { - "SHED_INACTIVE", - "SHED_REQUEST_PENDING", - "SHED_NON_COMPLIANT", - "SHED_COMPLIANT" - }; + "SHED_INACTIVE", "SHED_REQUEST_PENDING", "SHED_NON_COMPLIANT", + "SHED_COMPLIANT"}; if (object_index < MAX_LOAD_CONTROLS) { if (Load_Control_State[object_index] < MAX_LOAD_CONTROL_STATE) { printf("Load Control[%d]=%s\n", object_index, - Load_Control_State_Text[Load_Control_State[object_index]]); + Load_Control_State_Text[Load_Control_State[object_index]]); } } } #endif -void Load_Control_State_Machine( - int object_index) +void Load_Control_State_Machine(int object_index) { - unsigned i = 0; /* loop counter */ - int diff = 0; /* used for datetime comparison */ + unsigned i = 0; /* loop counter */ + int diff = 0; /* used for datetime comparison */ /* is the state machine enabled? */ if (!Load_Control_Enable[object_index]) { @@ -485,7 +450,7 @@ void Load_Control_State_Machine( if (Load_Control_State[object_index] == SHED_INACTIVE) { #if PRINT_ENABLED_DEBUG printf("Load Control[%d]:Requested Shed Level=Default\n", - object_index); + object_index); #endif break; } @@ -498,7 +463,7 @@ void Load_Control_State_Machine( Load_Control_State[object_index] = SHED_INACTIVE; #if PRINT_ENABLED_DEBUG printf("Load Control[%d]:Start Time=Wildcard\n", - object_index); + object_index); #endif break; } @@ -506,14 +471,16 @@ void Load_Control_State_Machine( /* cancel because current time is after start time + duration? */ datetime_copy(&End_Time[object_index], &Start_Time[object_index]); datetime_add_minutes(&End_Time[object_index], - Shed_Duration[object_index]); + Shed_Duration[object_index]); diff = datetime_compare(&End_Time[object_index], &Current_Time); if (diff < 0) { /* CancelShed */ /* FIXME: stop shedding! i.e. relinquish */ #if PRINT_ENABLED_DEBUG - printf("Load Control[%d]:Current Time" - " is after Start Time + Duration\n", object_index); + printf( + "Load Control[%d]:Current Time" + " is after Start Time + Duration\n", + object_index); #endif Load_Control_State[object_index] = SHED_INACTIVE; break; @@ -523,29 +490,34 @@ void Load_Control_State_Machine( /* current time prior to start time */ /* ReconfigurePending */ Shed_Level_Copy(&Expected_Shed_Level[object_index], - &Requested_Shed_Level[object_index]); + &Requested_Shed_Level[object_index]); Shed_Level_Default_Set(&Actual_Shed_Level[object_index], - Requested_Shed_Level[object_index].type); + Requested_Shed_Level[object_index].type); } else if (diff > 0) { /* current time after to start time */ #if PRINT_ENABLED_DEBUG - printf("Load Control[%d]:Current Time" - " is after Start Time\n", object_index); + printf( + "Load Control[%d]:Current Time" + " is after Start Time\n", + object_index); #endif /* AbleToMeetShed */ if (Able_To_Meet_Shed_Request(object_index)) { Shed_Level_Copy(&Expected_Shed_Level[object_index], - &Requested_Shed_Level[object_index]); - Analog_Output_Present_Value_Set(object_index, - Requested_Shed_Level_Value(object_index), 4); + &Requested_Shed_Level[object_index]); + Analog_Output_Present_Value_Set( + object_index, Requested_Shed_Level_Value(object_index), + 4); Shed_Level_Copy(&Actual_Shed_Level[object_index], - &Requested_Shed_Level[object_index]); + &Requested_Shed_Level[object_index]); Load_Control_State[object_index] = SHED_COMPLIANT; } else { /* CannotMeetShed */ - Shed_Level_Default_Set(&Expected_Shed_Level[object_index], + Shed_Level_Default_Set( + &Expected_Shed_Level[object_index], Requested_Shed_Level[object_index].type); - Shed_Level_Default_Set(&Actual_Shed_Level[object_index], + Shed_Level_Default_Set( + &Actual_Shed_Level[object_index], Requested_Shed_Level[object_index].type); Load_Control_State[object_index] = SHED_NON_COMPLIANT; } @@ -554,13 +526,14 @@ void Load_Control_State_Machine( case SHED_NON_COMPLIANT: datetime_copy(&End_Time[object_index], &Start_Time[object_index]); datetime_add_minutes(&End_Time[object_index], - Shed_Duration[object_index]); + Shed_Duration[object_index]); diff = datetime_compare(&End_Time[object_index], &Current_Time); if (diff < 0) { /* FinishedUnsuccessfulShed */ #if PRINT_ENABLED_DEBUG - printf - ("Load Control[%d]:Current Time is after Start Time + Duration\n", + printf( + "Load Control[%d]:Current Time is after Start Time + " + "Duration\n", object_index); #endif Load_Control_State[object_index] = SHED_INACTIVE; @@ -571,7 +544,7 @@ void Load_Control_State_Machine( /* UnsuccessfulShedReconfigured */ #if PRINT_ENABLED_DEBUG printf("Load Control[%d]:Control Property written\n", - object_index); + object_index); #endif /* The Written flags will cleared in the next state */ Load_Control_State[object_index] = SHED_REQUEST_PENDING; @@ -581,27 +554,28 @@ void Load_Control_State_Machine( /* CanNowComplyWithShed */ #if PRINT_ENABLED_DEBUG printf("Load Control[%d]:Able to meet Shed Request\n", - object_index); + object_index); #endif Shed_Level_Copy(&Expected_Shed_Level[object_index], - &Requested_Shed_Level[object_index]); - Analog_Output_Present_Value_Set(object_index, - Requested_Shed_Level_Value(object_index), 4); + &Requested_Shed_Level[object_index]); + Analog_Output_Present_Value_Set( + object_index, Requested_Shed_Level_Value(object_index), 4); Shed_Level_Copy(&Actual_Shed_Level[object_index], - &Requested_Shed_Level[object_index]); + &Requested_Shed_Level[object_index]); Load_Control_State[object_index] = SHED_COMPLIANT; } break; case SHED_COMPLIANT: datetime_copy(&End_Time[object_index], &Start_Time[object_index]); datetime_add_minutes(&End_Time[object_index], - Shed_Duration[object_index]); + Shed_Duration[object_index]); diff = datetime_compare(&End_Time[object_index], &Current_Time); if (diff < 0) { /* FinishedSuccessfulShed */ #if PRINT_ENABLED_DEBUG - printf - ("Load Control[%d]:Current Time is after Start Time + Duration\n", + printf( + "Load Control[%d]:Current Time is after Start Time + " + "Duration\n", object_index); #endif datetime_wildcard_set(&Start_Time[i]); @@ -614,7 +588,7 @@ void Load_Control_State_Machine( /* UnsuccessfulShedReconfigured */ #if PRINT_ENABLED_DEBUG printf("Load Control[%d]:Control Property written\n", - object_index); + object_index); #endif /* The Written flags will cleared in the next state */ Load_Control_State[object_index] = SHED_REQUEST_PENDING; @@ -624,12 +598,12 @@ void Load_Control_State_Machine( /* CanNoLongerComplyWithShed */ #if PRINT_ENABLED_DEBUG printf("Load Control[%d]:Not able to meet Shed Request\n", - object_index); + object_index); #endif Shed_Level_Default_Set(&Expected_Shed_Level[object_index], - Requested_Shed_Level[object_index].type); + Requested_Shed_Level[object_index].type); Shed_Level_Default_Set(&Actual_Shed_Level[object_index], - Requested_Shed_Level[object_index].type); + Requested_Shed_Level[object_index].type); Load_Control_State[object_index] = SHED_NON_COMPLIANT; } break; @@ -641,9 +615,9 @@ void Load_Control_State_Machine( #endif /* The Written flag will cleared in the next state */ Shed_Level_Copy(&Expected_Shed_Level[object_index], - &Requested_Shed_Level[object_index]); + &Requested_Shed_Level[object_index]); Shed_Level_Default_Set(&Actual_Shed_Level[object_index], - Requested_Shed_Level[object_index].type); + Requested_Shed_Level[object_index].type); Load_Control_State[object_index] = SHED_REQUEST_PENDING; } break; @@ -653,8 +627,7 @@ void Load_Control_State_Machine( } /* call every second or so */ -void Load_Control_State_Machine_Handler( - void) +void Load_Control_State_Machine_Handler(void) { unsigned i = 0; static bool initialized = false; @@ -675,17 +648,14 @@ void Load_Control_State_Machine_Handler( #endif Load_Control_State_Previously[i] = Load_Control_State[i]; } - - } } /* return apdu len, or BACNET_STATUS_ERROR on error */ -int Load_Control_Read_Property( - BACNET_READ_PROPERTY_DATA * rpdata) +int Load_Control_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata) { int len = 0; - int apdu_len = 0; /* return value */ + int apdu_len = 0; /* return value */ BACNET_BIT_STRING bit_string; BACNET_CHARACTER_STRING char_string; int enumeration = 0; @@ -702,9 +672,8 @@ int Load_Control_Read_Property( object_index = Load_Control_Instance_To_Index(rpdata->object_instance); switch (rpdata->object_property) { case PROP_OBJECT_IDENTIFIER: - apdu_len = - encode_application_object_id(&apdu[0], OBJECT_LOAD_CONTROL, - rpdata->object_instance); + apdu_len = encode_application_object_id( + &apdu[0], OBJECT_LOAD_CONTROL, rpdata->object_instance); break; case PROP_OBJECT_NAME: case PROP_DESCRIPTION: @@ -744,68 +713,63 @@ int Load_Control_Read_Property( case PROP_REQUESTED_SHED_LEVEL: switch (Requested_Shed_Level[object_index].type) { case BACNET_SHED_TYPE_PERCENT: - apdu_len = - encode_context_unsigned(&apdu[0], 0, + apdu_len = encode_context_unsigned( + &apdu[0], 0, Requested_Shed_Level[object_index].value.percent); break; case BACNET_SHED_TYPE_AMOUNT: - apdu_len = - encode_context_real(&apdu[0], 2, + apdu_len = encode_context_real( + &apdu[0], 2, Requested_Shed_Level[object_index].value.amount); break; case BACNET_SHED_TYPE_LEVEL: default: - apdu_len = - encode_context_unsigned(&apdu[0], 1, + apdu_len = encode_context_unsigned( + &apdu[0], 1, Requested_Shed_Level[object_index].value.level); break; } break; case PROP_START_TIME: - len = - encode_application_date(&apdu[0], - &Start_Time[object_index].date); + len = encode_application_date(&apdu[0], + &Start_Time[object_index].date); apdu_len = len; - len = - encode_application_time(&apdu[apdu_len], - &Start_Time[object_index].time); + len = encode_application_time(&apdu[apdu_len], + &Start_Time[object_index].time); apdu_len += len; break; case PROP_SHED_DURATION: - apdu_len = - encode_application_unsigned(&apdu[0], - Shed_Duration[object_index]); + apdu_len = encode_application_unsigned(&apdu[0], + Shed_Duration[object_index]); break; case PROP_DUTY_WINDOW: - apdu_len = - encode_application_unsigned(&apdu[0], - Duty_Window[object_index]); + apdu_len = encode_application_unsigned(&apdu[0], + Duty_Window[object_index]); break; case PROP_ENABLE: state = Load_Control_Enable[object_index]; apdu_len = encode_application_boolean(&apdu[0], state); break; - case PROP_FULL_DUTY_BASELINE: /* optional */ - apdu_len = - encode_application_real(&apdu[0], - Full_Duty_Baseline[object_index]); + case PROP_FULL_DUTY_BASELINE: /* optional */ + apdu_len = encode_application_real( + &apdu[0], Full_Duty_Baseline[object_index]); break; case PROP_EXPECTED_SHED_LEVEL: switch (Expected_Shed_Level[object_index].type) { case BACNET_SHED_TYPE_PERCENT: - apdu_len = - encode_context_unsigned(&apdu[0], 0, + apdu_len = encode_context_unsigned( + &apdu[0], 0, Expected_Shed_Level[object_index].value.percent); break; case BACNET_SHED_TYPE_AMOUNT: - apdu_len = - encode_context_real(&apdu[0], 2, + apdu_len = encode_context_real( + &apdu[0], 2, Expected_Shed_Level[object_index].value.amount); break; case BACNET_SHED_TYPE_LEVEL: default: - apdu_len = - encode_context_unsigned(&apdu[0], 1, + apdu_len = encode_context_unsigned( + &apdu[0], 1, Expected_Shed_Level[object_index].value.level); break; } @@ -813,19 +777,19 @@ int Load_Control_Read_Property( case PROP_ACTUAL_SHED_LEVEL: switch (Actual_Shed_Level[object_index].type) { case BACNET_SHED_TYPE_PERCENT: - apdu_len = - encode_context_unsigned(&apdu[0], 0, + apdu_len = encode_context_unsigned( + &apdu[0], 0, Actual_Shed_Level[object_index].value.percent); break; case BACNET_SHED_TYPE_AMOUNT: - apdu_len = - encode_context_real(&apdu[0], 2, + apdu_len = encode_context_real( + &apdu[0], 2, Actual_Shed_Level[object_index].value.amount); break; case BACNET_SHED_TYPE_LEVEL: default: - apdu_len = - encode_context_unsigned(&apdu[0], 1, + apdu_len = encode_context_unsigned( + &apdu[0], 1, Actual_Shed_Level[object_index].value.level); break; } @@ -841,9 +805,8 @@ int Load_Control_Read_Property( apdu_len = 0; for (i = 0; i < MAX_SHED_LEVELS; i++) { /* FIXME: check if we have room before adding it to APDU */ - len = - encode_application_unsigned(&apdu[apdu_len], - Shed_Levels[object_index][i]); + len = encode_application_unsigned( + &apdu[apdu_len], Shed_Levels[object_index][i]); /* add it if we have room */ if ((apdu_len + len) < MAX_APDU) apdu_len += len; @@ -856,8 +819,8 @@ int Load_Control_Read_Property( } } else { if (rpdata->array_index <= MAX_SHED_LEVELS) { - apdu_len = - encode_application_unsigned(&apdu[0], + apdu_len = encode_application_unsigned( + &apdu[0], Shed_Levels[object_index][rpdata->array_index - 1]); } else { rpdata->error_class = ERROR_CLASS_PROPERTY; @@ -878,10 +841,9 @@ int Load_Control_Read_Property( for (i = 0; i < MAX_SHED_LEVELS; i++) { /* FIXME: check if we have room before adding it to APDU */ characterstring_init_ansi(&char_string, - Shed_Level_Descriptions[i]); - len = - encode_application_character_string(&apdu[apdu_len], - &char_string); + Shed_Level_Descriptions[i]); + len = encode_application_character_string(&apdu[apdu_len], + &char_string); /* add it if we have room */ if ((apdu_len + len) < MAX_APDU) apdu_len += len; @@ -894,11 +856,11 @@ int Load_Control_Read_Property( } } else { if (rpdata->array_index <= MAX_SHED_LEVELS) { - characterstring_init_ansi(&char_string, + characterstring_init_ansi( + &char_string, Shed_Level_Descriptions[rpdata->array_index - 1]); - apdu_len = - encode_application_character_string(&apdu[0], - &char_string); + apdu_len = encode_application_character_string( + &apdu[0], &char_string); } else { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX; @@ -926,19 +888,18 @@ int Load_Control_Read_Property( } /* returns true if successful */ -bool Load_Control_Write_Property( - BACNET_WRITE_PROPERTY_DATA * wp_data) +bool Load_Control_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data) { - bool status = false; /* return value */ + bool status = false; /* return value */ 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 = - bacapp_decode_application_data(wp_data->application_data, - wp_data->application_data_len, &value); + len = bacapp_decode_application_data(wp_data->application_data, + wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ if (len < 0) { /* error while decoding - a value larger than we can handle */ @@ -956,10 +917,9 @@ bool Load_Control_Write_Property( object_index = Load_Control_Instance_To_Index(wp_data->object_instance); switch (wp_data->object_property) { case PROP_REQUESTED_SHED_LEVEL: - len = - bacapp_decode_context_data(wp_data->application_data, - wp_data->application_data_len, &value, - PROP_REQUESTED_SHED_LEVEL); + len = bacapp_decode_context_data(wp_data->application_data, + wp_data->application_data_len, + &value, PROP_REQUESTED_SHED_LEVEL); if (value.context_tag == 0) { /* percent - Unsigned */ Requested_Shed_Level[object_index].type = @@ -994,20 +954,20 @@ bool Load_Control_Write_Property( case PROP_START_TIME: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_DATE, - &wp_data->error_class, &wp_data->error_code); + &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; @@ -1024,7 +984,7 @@ bool Load_Control_Write_Property( case PROP_SHED_DURATION: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, - &wp_data->error_class, &wp_data->error_code); + &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; @@ -1034,7 +994,7 @@ bool Load_Control_Write_Property( case PROP_DUTY_WINDOW: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, - &wp_data->error_class, &wp_data->error_code); + &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; @@ -1044,7 +1004,7 @@ bool Load_Control_Write_Property( case PROP_SHED_LEVELS: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { /* re-write the size of the array? */ if (wp_data->array_index == 0) { @@ -1069,7 +1029,7 @@ bool Load_Control_Write_Property( case PROP_ENABLE: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { Load_Control_Enable[object_index] = value.type.Boolean; } @@ -1117,10 +1077,9 @@ static void Load_Control_WriteProperty_Request_Shed_Percent( } #endif -static void Load_Control_WriteProperty_Request_Shed_Level( - Test * pTest, - int instance, - unsigned level) +static void Load_Control_WriteProperty_Request_Shed_Level(Test *pTest, + int instance, + unsigned level) { bool status = false; BACNET_APPLICATION_DATA_VALUE value; @@ -1169,10 +1128,8 @@ static void Load_Control_WriteProperty_Request_Shed_Amount( } #endif -static void Load_Control_WriteProperty_Enable( - Test * pTest, - int instance, - bool enable) +static void Load_Control_WriteProperty_Enable(Test *pTest, int instance, + bool enable) { bool status = false; BACNET_APPLICATION_DATA_VALUE value; @@ -1195,10 +1152,8 @@ static void Load_Control_WriteProperty_Enable( ct_test(pTest, status == true); } -static void Load_Control_WriteProperty_Shed_Duration( - Test * pTest, - int instance, - unsigned duration) +static void Load_Control_WriteProperty_Shed_Duration(Test *pTest, int instance, + unsigned duration) { bool status = false; BACNET_APPLICATION_DATA_VALUE value; @@ -1220,10 +1175,8 @@ static void Load_Control_WriteProperty_Shed_Duration( ct_test(pTest, status == true); } -static void Load_Control_WriteProperty_Duty_Window( - Test * pTest, - int instance, - unsigned duration) +static void Load_Control_WriteProperty_Duty_Window(Test *pTest, int instance, + unsigned duration) { bool status = false; BACNET_APPLICATION_DATA_VALUE value; @@ -1245,9 +1198,8 @@ static void Load_Control_WriteProperty_Duty_Window( ct_test(pTest, status == true); } -static void Load_Control_WriteProperty_Start_Time_Wildcards( - Test * pTest, - int instance) +static void Load_Control_WriteProperty_Start_Time_Wildcards(Test *pTest, + int instance) { int len = 0; bool status = false; @@ -1278,15 +1230,8 @@ static void Load_Control_WriteProperty_Start_Time_Wildcards( } static void Load_Control_WriteProperty_Start_Time( - Test * pTest, - int instance, - uint16_t year, - uint8_t month, - uint8_t day, - uint8_t hour, - uint8_t minute, - uint8_t seconds, - uint8_t hundredths) + Test *pTest, int instance, uint16_t year, uint8_t month, uint8_t day, + uint8_t hour, uint8_t minute, uint8_t seconds, uint8_t hundredths) { int len = 0; bool status = false; @@ -1316,8 +1261,7 @@ static void Load_Control_WriteProperty_Start_Time( ct_test(pTest, status == true); } -void testLoadControlStateMachine( - Test * pTest) +void testLoadControlStateMachine(Test *pTest) { unsigned i = 0, j = 0; uint8_t level = 0; @@ -1456,10 +1400,9 @@ void testLoadControlStateMachine( ct_test(pTest, level == 100); } -void testLoadControl( - Test * pTest) +void testLoadControl(Test *pTest) { - uint8_t apdu[MAX_APDU] = { 0 }; + uint8_t apdu[MAX_APDU] = {0}; int len = 0; uint32_t len_value = 0; uint8_t tag_number = 0; @@ -1487,8 +1430,7 @@ void testLoadControl( } #ifdef TEST_LOAD_CONTROL -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -1502,7 +1444,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/demo/object/lo.c b/demo/object/lo.c index 17092063..a431aa69 100644 --- a/demo/object/lo.c +++ b/demo/object/lo.c @@ -1,31 +1,31 @@ /** -* @file -* @author Steve Karg -* @date 2013 -* @brief Lighting Output object -* -* @section LICENSE -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*/ + * @file + * @author Steve Karg + * @date 2013 + * @brief Lighting Output object + * + * @section LICENSE + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ #include #include @@ -34,7 +34,7 @@ #include "bacdcode.h" #include "bacenum.h" #include "bacapp.h" -#include "config.h" /* the custom stuff */ +#include "config.h" /* the custom stuff */ #include "rp.h" #include "wp.h" #include "lighting.h" @@ -53,9 +53,9 @@ struct lighting_output_object { float Physical_Value; BACNET_LIGHTING_COMMAND Lighting_Command; BACNET_LIGHTING_IN_PROGRESS In_Progress; - bool Out_Of_Service:1; - bool Blink_Warn_Enable:1; - bool Egress_Active:1; + bool Out_Of_Service : 1; + bool Blink_Warn_Enable : 1; + bool Egress_Active : 1; uint32_t Egress_Time; uint32_t Default_Fade_Time; float Default_Ramp_Rate; @@ -94,15 +94,10 @@ static const int Lighting_Output_Properties_Required[] = { PROP_PRIORITY_ARRAY, PROP_RELINQUISH_DEFAULT, PROP_LIGHTING_COMMAND_DEFAULT_PRIORITY, - -1 -}; -static const int Lighting_Output_Properties_Optional[] = { - -1 -}; + -1}; +static const int Lighting_Output_Properties_Optional[] = {-1}; -static const int Lighting_Output_Properties_Proprietary[] = { - -1 -}; +static const int Lighting_Output_Properties_Proprietary[] = {-1}; /** * Returns the list of required, optional, and proprietary properties. @@ -115,10 +110,9 @@ static const int Lighting_Output_Properties_Proprietary[] = { * @param pProprietary - pointer to list of int terminated by -1, of * BACnet proprietary properties for this object. */ -void Lighting_Output_Property_Lists( - const int **pRequired, - const int **pOptional, - const int **pProprietary) +void Lighting_Output_Property_Lists(const int **pRequired, + const int **pOptional, + const int **pProprietary) { if (pRequired) *pRequired = Lighting_Output_Properties_Required; @@ -137,8 +131,7 @@ void Lighting_Output_Property_Lists( * * @return true if the instance is valid, and false if not */ -bool Lighting_Output_Valid_Instance( - uint32_t object_instance) +bool Lighting_Output_Valid_Instance(uint32_t object_instance) { unsigned int index; @@ -155,8 +148,7 @@ bool Lighting_Output_Valid_Instance( * * @return Number of Lighting Output objects */ -unsigned Lighting_Output_Count( - void) +unsigned Lighting_Output_Count(void) { return MAX_LIGHTING_OUTPUTS; } @@ -169,8 +161,7 @@ unsigned Lighting_Output_Count( * * @return object instance-number for the given index */ -uint32_t Lighting_Output_Index_To_Instance( - unsigned index) +uint32_t Lighting_Output_Index_To_Instance(unsigned index) { uint32_t instance = 1; @@ -188,8 +179,7 @@ uint32_t Lighting_Output_Index_To_Instance( * @return index for the given instance-number, or MAX_LIGHTING_OUTPUTS * if not valid. */ -unsigned Lighting_Output_Instance_To_Index( - uint32_t object_instance) +unsigned Lighting_Output_Instance_To_Index(uint32_t object_instance) { unsigned index = MAX_LIGHTING_OUTPUTS; @@ -210,8 +200,7 @@ unsigned Lighting_Output_Instance_To_Index( * * @return present-value of the object */ -float Lighting_Output_Present_Value( - uint32_t object_instance) +float Lighting_Output_Present_Value(uint32_t object_instance) { float value = 0.0; unsigned index = 0; @@ -240,9 +229,8 @@ float Lighting_Output_Present_Value( * * @return priority-value of the object */ -static float Lighting_Output_Priority_Value( - uint32_t object_instance, - unsigned priority) +static float Lighting_Output_Priority_Value(uint32_t object_instance, + unsigned priority) { float value = 0.0; unsigned index = 0; @@ -267,9 +255,8 @@ static float Lighting_Output_Priority_Value( * * @return true if the priority slot is active */ -static bool Lighting_Output_Priority_Active( - uint32_t object_instance, - unsigned priority) +static bool Lighting_Output_Priority_Active(uint32_t object_instance, + unsigned priority) { bool status = false; unsigned index = 0; @@ -278,7 +265,8 @@ static bool Lighting_Output_Priority_Active( if (index < MAX_LIGHTING_OUTPUTS) { if (priority && (priority <= BACNET_MAX_PRIORITY)) { priority--; - if (BIT_CHECK(Lighting_Output[index].Priority_Active_Bits, priority)) { + if (BIT_CHECK(Lighting_Output[index].Priority_Active_Bits, + priority)) { status = true; } } @@ -294,12 +282,11 @@ static bool Lighting_Output_Priority_Active( * * @return active priority 1..16, or 0 if no priority is active */ -unsigned Lighting_Output_Present_Value_Priority( - uint32_t object_instance) +unsigned Lighting_Output_Present_Value_Priority(uint32_t object_instance) { - unsigned index = 0; /* instance to index conversion */ - unsigned p = 0; /* loop counter */ - unsigned priority = 0; /* return value */ + unsigned index = 0; /* instance to index conversion */ + unsigned p = 0; /* loop counter */ + unsigned priority = 0; /* return value */ index = Lighting_Output_Instance_To_Index(object_instance); if (index < MAX_LIGHTING_OUTPUTS) { @@ -324,10 +311,8 @@ unsigned Lighting_Output_Present_Value_Priority( * * @return true if values are within range and present-value is set. */ -bool Lighting_Output_Present_Value_Set( - uint32_t object_instance, - float value, - unsigned priority) +bool Lighting_Output_Present_Value_Set(uint32_t object_instance, float value, + unsigned priority) { unsigned index = 0; bool status = false; @@ -335,7 +320,7 @@ bool Lighting_Output_Present_Value_Set( index = Lighting_Output_Instance_To_Index(object_instance); if (index < MAX_LIGHTING_OUTPUTS) { if (priority && (priority <= BACNET_MAX_PRIORITY) && - (priority != 6 /* reserved */ )) { + (priority != 6 /* reserved */)) { priority--; BIT_SET(Lighting_Output[index].Priority_Active_Bits, priority); Lighting_Output[index].Priority_Array[priority] = value; @@ -355,9 +340,8 @@ bool Lighting_Output_Present_Value_Set( * * @return true if values are within range and present-value is set. */ -bool Lighting_Output_Present_Value_Relinquish( - uint32_t object_instance, - unsigned priority) +bool Lighting_Output_Present_Value_Relinquish(uint32_t object_instance, + unsigned priority) { unsigned index = 0; bool status = false; @@ -365,7 +349,7 @@ bool Lighting_Output_Present_Value_Relinquish( index = Lighting_Output_Instance_To_Index(object_instance); if (index < MAX_LIGHTING_OUTPUTS) { if (priority && (priority <= BACNET_MAX_PRIORITY) && - (priority != 6 /* reserved */ )) { + (priority != 6 /* reserved */)) { priority--; BIT_CLEAR(Lighting_Output[index].Priority_Active_Bits, priority); Lighting_Output[index].Priority_Array[priority] = 0.0; @@ -386,9 +370,8 @@ bool Lighting_Output_Present_Value_Relinquish( * * @return true if object-name was retrieved */ -bool Lighting_Output_Object_Name( - uint32_t object_instance, - BACNET_CHARACTER_STRING * object_name) +bool Lighting_Output_Object_Name(uint32_t object_instance, + BACNET_CHARACTER_STRING *object_name) { char text_string[32] = ""; bool status = false; @@ -397,7 +380,7 @@ bool Lighting_Output_Object_Name( index = Lighting_Output_Instance_To_Index(object_instance); if (index < MAX_LIGHTING_OUTPUTS) { sprintf(text_string, "LIGHTING OUTPUT %lu", - (unsigned long) object_instance); + (unsigned long)object_instance); status = characterstring_init_ansi(object_name, text_string); } @@ -412,9 +395,8 @@ bool Lighting_Output_Object_Name( * * @return true if lighting command was set */ -bool Lighting_Output_Lighting_Command_Set( - uint32_t object_instance, - BACNET_LIGHTING_COMMAND *value) +bool Lighting_Output_Lighting_Command_Set(uint32_t object_instance, + BACNET_LIGHTING_COMMAND *value) { bool status = false; unsigned index = 0; @@ -422,9 +404,8 @@ bool Lighting_Output_Lighting_Command_Set( index = Lighting_Output_Instance_To_Index(object_instance); if (index < MAX_LIGHTING_OUTPUTS) { // FIXME: check lighting command member values - status = lighting_command_copy( - &Lighting_Output[index].Lighting_Command, - value); + status = lighting_command_copy(&Lighting_Output[index].Lighting_Command, + value); // FIXME: set all the other values, and get the light levels moving } @@ -439,17 +420,16 @@ bool Lighting_Output_Lighting_Command_Set( * * @return true if lighting command was retrieved */ -bool Lighting_Output_Lighting_Command( - uint32_t object_instance, - BACNET_LIGHTING_COMMAND *value) +bool Lighting_Output_Lighting_Command(uint32_t object_instance, + BACNET_LIGHTING_COMMAND *value) { bool status = false; unsigned index = 0; index = Lighting_Output_Instance_To_Index(object_instance); if (index < MAX_LIGHTING_OUTPUTS) { - status = lighting_command_copy(value, - &Lighting_Output[index].Lighting_Command); + status = lighting_command_copy( + value, &Lighting_Output[index].Lighting_Command); } return status; @@ -485,9 +465,8 @@ BACNET_LIGHTING_IN_PROGRESS Lighting_Output_In_Progress( * * @return true if value was set */ -bool Lighting_Output_In_Progress_Set( - uint32_t object_instance, - BACNET_LIGHTING_IN_PROGRESS in_progress) +bool Lighting_Output_In_Progress_Set(uint32_t object_instance, + BACNET_LIGHTING_IN_PROGRESS in_progress) { bool status = false; unsigned index = 0; @@ -495,7 +474,6 @@ bool Lighting_Output_In_Progress_Set( index = Lighting_Output_Instance_To_Index(object_instance); if (index < MAX_LIGHTING_OUTPUTS) { Lighting_Output[index].In_Progress = in_progress; - } return status; @@ -508,8 +486,7 @@ bool Lighting_Output_In_Progress_Set( * * @return the tracking-value of this object instance. */ -float Lighting_Output_Tracking_Value( - uint32_t object_instance) +float Lighting_Output_Tracking_Value(uint32_t object_instance) { float value = 0.0; unsigned index = 0; @@ -531,9 +508,7 @@ float Lighting_Output_Tracking_Value( * * @return true if value was set */ -bool Lighting_Output_Tracking_Value_Set( - uint32_t object_instance, - float value) +bool Lighting_Output_Tracking_Value_Set(uint32_t object_instance, float value) { bool status = false; unsigned int index = 0; @@ -555,8 +530,7 @@ bool Lighting_Output_Tracking_Value_Set( * * @return the blink-warn-enable property value of this object */ -bool Lighting_Output_Blink_Warn_Enable( - uint32_t object_instance) +bool Lighting_Output_Blink_Warn_Enable(uint32_t object_instance) { bool value = false; unsigned index = 0; @@ -578,9 +552,8 @@ bool Lighting_Output_Blink_Warn_Enable( * * @return true if value was set */ -bool Lighting_Output_Blink_Warn_Enable_Set( - uint32_t object_instance, - bool enable) +bool Lighting_Output_Blink_Warn_Enable_Set(uint32_t object_instance, + bool enable) { bool status = false; unsigned int index = 0; @@ -602,8 +575,7 @@ bool Lighting_Output_Blink_Warn_Enable_Set( * * @return the egress-time property value of this object */ -uint32_t Lighting_Output_Egress_Time( - uint32_t object_instance) +uint32_t Lighting_Output_Egress_Time(uint32_t object_instance) { uint32_t value = 0; unsigned int index = 0; @@ -625,9 +597,7 @@ uint32_t Lighting_Output_Egress_Time( * * @return true if value was set */ -bool Lighting_Output_Egress_Time_Set( - uint32_t object_instance, - uint32_t seconds) +bool Lighting_Output_Egress_Time_Set(uint32_t object_instance, uint32_t seconds) { bool status = false; unsigned int index = 0; @@ -649,8 +619,7 @@ bool Lighting_Output_Egress_Time_Set( * * @return the egress-active property value of this object */ -bool Lighting_Output_Egress_Active( - uint32_t object_instance) +bool Lighting_Output_Egress_Active(uint32_t object_instance) { bool value = false; unsigned int index = 0; @@ -671,8 +640,7 @@ bool Lighting_Output_Egress_Active( * * @return the fade-time property value of this object */ -uint32_t Lighting_Output_Default_Fade_Time( - uint32_t object_instance) +uint32_t Lighting_Output_Default_Fade_Time(uint32_t object_instance) { uint32_t value = 0; unsigned int index = 0; @@ -694,16 +662,14 @@ uint32_t Lighting_Output_Default_Fade_Time( * * @return true if value was set */ -bool Lighting_Output_Default_Fade_Time_Set( - uint32_t object_instance, - uint32_t milliseconds) +bool Lighting_Output_Default_Fade_Time_Set(uint32_t object_instance, + uint32_t milliseconds) { bool status = false; unsigned int index = 0; index = Lighting_Output_Instance_To_Index(object_instance); - if ((index < MAX_LIGHTING_OUTPUTS) && - (milliseconds >= 100) && + if ((index < MAX_LIGHTING_OUTPUTS) && (milliseconds >= 100) && (milliseconds <= 86400000)) { Lighting_Output[index].Default_Fade_Time = milliseconds; status = true; @@ -720,8 +686,7 @@ bool Lighting_Output_Default_Fade_Time_Set( * * @return the ramp-rate property value of this object */ -float Lighting_Output_Default_Ramp_Rate( - uint32_t object_instance) +float Lighting_Output_Default_Ramp_Rate(uint32_t object_instance) { float value = 0.0; unsigned int index = 0; @@ -743,16 +708,14 @@ float Lighting_Output_Default_Ramp_Rate( * * @return true if value was set */ -bool Lighting_Output_Default_Ramp_Rate_Set( - uint32_t object_instance, - float percent_per_second) +bool Lighting_Output_Default_Ramp_Rate_Set(uint32_t object_instance, + float percent_per_second) { bool status = false; unsigned int index = 0; index = Lighting_Output_Instance_To_Index(object_instance); - if ((index < MAX_LIGHTING_OUTPUTS) && - (percent_per_second >= 0.1) && + if ((index < MAX_LIGHTING_OUTPUTS) && (percent_per_second >= 0.1) && (percent_per_second <= 100.0)) { Lighting_Output[index].Default_Ramp_Rate = percent_per_second; status = true; @@ -769,8 +732,7 @@ bool Lighting_Output_Default_Ramp_Rate_Set( * * @return the default-step-increment property value of this object */ -float Lighting_Output_Default_Step_Increment( - uint32_t object_instance) +float Lighting_Output_Default_Step_Increment(uint32_t object_instance) { float value = 0.0; unsigned int index = 0; @@ -792,16 +754,14 @@ float Lighting_Output_Default_Step_Increment( * * @return true if value was set */ -bool Lighting_Output_Default_Step_Increment_Set( - uint32_t object_instance, - float step_increment) +bool Lighting_Output_Default_Step_Increment_Set(uint32_t object_instance, + float step_increment) { bool status = false; unsigned int index = 0; index = Lighting_Output_Instance_To_Index(object_instance); - if ((index < MAX_LIGHTING_OUTPUTS) && - (step_increment >= 0.1) && + if ((index < MAX_LIGHTING_OUTPUTS) && (step_increment >= 0.1) && (step_increment <= 100.0)) { Lighting_Output[index].Default_Step_Increment = step_increment; status = true; @@ -820,8 +780,7 @@ bool Lighting_Output_Default_Step_Increment_Set( * @return the lighting-command-default-priority property value of * this object */ -unsigned Lighting_Output_Default_Priority( - uint32_t object_instance) +unsigned Lighting_Output_Default_Priority(uint32_t object_instance) { unsigned value = 0; unsigned int index = 0; @@ -843,16 +802,14 @@ unsigned Lighting_Output_Default_Priority( * * @return true if value was set */ -bool Lighting_Output_Default_Priority_Set( - uint32_t object_instance, - unsigned priority) +bool Lighting_Output_Default_Priority_Set(uint32_t object_instance, + unsigned priority) { bool status = false; unsigned int index = 0; index = Lighting_Output_Instance_To_Index(object_instance); - if ((index < MAX_LIGHTING_OUTPUTS) && - (priority >= BACNET_MIN_PRIORITY) && + if ((index < MAX_LIGHTING_OUTPUTS) && (priority >= BACNET_MIN_PRIORITY) && (priority <= BACNET_MAX_PRIORITY)) { Lighting_Output[index].Lighting_Command_Default_Priority = priority; status = true; @@ -869,8 +826,7 @@ bool Lighting_Output_Default_Priority_Set( * * @return out-of-service property value */ -bool Lighting_Output_Out_Of_Service( - uint32_t object_instance) +bool Lighting_Output_Out_Of_Service(uint32_t object_instance) { bool value = false; unsigned int index = 0; @@ -891,9 +847,7 @@ bool Lighting_Output_Out_Of_Service( * * @return true if the out-of-service property value was set */ -void Lighting_Output_Out_Of_Service_Set( - uint32_t object_instance, - bool value) +void Lighting_Output_Out_Of_Service_Set(uint32_t object_instance, bool value) { unsigned int index = 0; @@ -911,8 +865,7 @@ void Lighting_Output_Out_Of_Service_Set( * * @return relinquish-default property value */ -float Lighting_Output_Relinquish_Default( - uint32_t object_instance) +float Lighting_Output_Relinquish_Default(uint32_t object_instance) { float value = 0.0; unsigned int index = 0; @@ -934,9 +887,8 @@ float Lighting_Output_Relinquish_Default( * * @return true if the relinquish-default property value was set */ -bool Lighting_Output_Relinquish_Default_Set( - uint32_t object_instance, - float value) +bool Lighting_Output_Relinquish_Default_Set(uint32_t object_instance, + float value) { bool status = false; unsigned int index = 0; @@ -959,15 +911,14 @@ bool Lighting_Output_Relinquish_Default_Set( * @return number of APDU bytes in the response, or * BACNET_STATUS_ERROR on error. */ -int Lighting_Output_Read_Property( - BACNET_READ_PROPERTY_DATA * rpdata) +int Lighting_Output_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata) { int len = 0; - int apdu_len = 0; /* return value */ + int apdu_len = 0; /* return value */ BACNET_BIT_STRING bit_string; BACNET_CHARACTER_STRING char_string; BACNET_LIGHTING_COMMAND lighting_command; - float real_value = (float) 1.414; + float real_value = (float)1.414; uint32_t unsigned_value = 0; unsigned i = 0; bool state = false; @@ -980,9 +931,8 @@ int Lighting_Output_Read_Property( apdu = rpdata->application_data; switch (rpdata->object_property) { case PROP_OBJECT_IDENTIFIER: - apdu_len = - encode_application_object_id(&apdu[0], OBJECT_LIGHTING_OUTPUT, - rpdata->object_instance); + apdu_len = encode_application_object_id( + &apdu[0], OBJECT_LIGHTING_OUTPUT, rpdata->object_instance); break; case PROP_OBJECT_NAME: Lighting_Output_Object_Name(rpdata->object_instance, &char_string); @@ -1003,17 +953,14 @@ int Lighting_Output_Read_Property( apdu_len = encode_application_real(&apdu[0], real_value); break; case PROP_LIGHTING_COMMAND: - Lighting_Output_Lighting_Command( - rpdata->object_instance, - &lighting_command); - apdu_len = lighting_command_encode(&apdu[0], - &lighting_command); + Lighting_Output_Lighting_Command(rpdata->object_instance, + &lighting_command); + apdu_len = lighting_command_encode(&apdu[0], &lighting_command); break; case PROP_IN_PROGRESS: - unsigned_value = Lighting_Output_In_Progress( - rpdata->object_instance); - apdu_len = encode_application_enumerated(&apdu[0], - unsigned_value); + unsigned_value = + Lighting_Output_In_Progress(rpdata->object_instance); + apdu_len = encode_application_enumerated(&apdu[0], unsigned_value); break; case PROP_STATUS_FLAGS: bitstring_init(&bit_string); @@ -1033,20 +980,18 @@ int Lighting_Output_Read_Property( apdu_len = encode_application_boolean(&apdu[0], state); break; case PROP_EGRESS_TIME: - unsigned_value = Lighting_Output_Egress_Time( - rpdata->object_instance); - apdu_len = encode_application_unsigned(&apdu[0], - unsigned_value); + unsigned_value = + Lighting_Output_Egress_Time(rpdata->object_instance); + apdu_len = encode_application_unsigned(&apdu[0], unsigned_value); break; case PROP_EGRESS_ACTIVE: state = Lighting_Output_Egress_Active(rpdata->object_instance); apdu_len = encode_application_boolean(&apdu[0], state); break; case PROP_DEFAULT_FADE_TIME: - unsigned_value = Lighting_Output_Default_Fade_Time( - rpdata->object_instance); - apdu_len = encode_application_unsigned(&apdu[0], - unsigned_value); + unsigned_value = + Lighting_Output_Default_Fade_Time(rpdata->object_instance); + apdu_len = encode_application_unsigned(&apdu[0], unsigned_value); break; case PROP_DEFAULT_RAMP_RATE: real_value = @@ -1063,17 +1008,17 @@ int Lighting_Output_Read_Property( if (rpdata->array_index == 0) { apdu_len = encode_application_unsigned(&apdu[0], BACNET_MAX_PRIORITY); - /* if no index was specified, then try to encode the entire list */ - /* into one packet. */ + /* if no index was specified, then try to encode the entire list + */ + /* into one packet. */ } else if (rpdata->array_index == BACNET_ARRAY_ALL) { for (i = 1; i <= BACNET_MAX_PRIORITY; i++) { - if (Lighting_Output_Priority_Active( - rpdata->object_instance, i)) { + if (Lighting_Output_Priority_Active(rpdata->object_instance, + i)) { real_value = Lighting_Output_Priority_Value( rpdata->object_instance, i); - len = - encode_application_real(&apdu[apdu_len], - real_value); + len = encode_application_real(&apdu[apdu_len], + real_value); } else { len = encode_application_null(&apdu[apdu_len]); } @@ -1089,15 +1034,12 @@ int Lighting_Output_Read_Property( } } else { if (rpdata->array_index <= BACNET_MAX_PRIORITY) { - if (Lighting_Output_Priority_Active( - rpdata->object_instance, - rpdata->array_index)) { + if (Lighting_Output_Priority_Active(rpdata->object_instance, + rpdata->array_index)) { real_value = Lighting_Output_Priority_Value( - rpdata->object_instance, - rpdata->array_index); - len = - encode_application_real(&apdu[apdu_len], - real_value); + rpdata->object_instance, rpdata->array_index); + len = encode_application_real(&apdu[apdu_len], + real_value); } else { len = encode_application_null(&apdu[apdu_len]); } @@ -1109,15 +1051,14 @@ int Lighting_Output_Read_Property( } break; case PROP_RELINQUISH_DEFAULT: - real_value = Lighting_Output_Relinquish_Default( - rpdata->object_instance); + real_value = + Lighting_Output_Relinquish_Default(rpdata->object_instance); apdu_len = encode_application_real(&apdu[0], real_value); break; case PROP_LIGHTING_COMMAND_DEFAULT_PRIORITY: - unsigned_value = Lighting_Output_Default_Priority( - rpdata->object_instance); - apdu_len = encode_application_unsigned(&apdu[0], - unsigned_value); + unsigned_value = + Lighting_Output_Default_Priority(rpdata->object_instance); + apdu_len = encode_application_unsigned(&apdu[0], unsigned_value); break; default: rpdata->error_class = ERROR_CLASS_PROPERTY; @@ -1145,17 +1086,15 @@ int Lighting_Output_Read_Property( * * @return false if an error is loaded, true if no errors */ -bool Lighting_Output_Write_Property( - BACNET_WRITE_PROPERTY_DATA * wp_data) +bool Lighting_Output_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data) { - bool status = false; /* return value */ + bool status = false; /* return value */ int len = 0; BACNET_APPLICATION_DATA_VALUE value; /* decode the some of the request */ - len = - bacapp_decode_application_data(wp_data->application_data, - wp_data->application_data_len, &value); + len = bacapp_decode_application_data(wp_data->application_data, + wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ if (len < 0) { /* error while decoding - a value larger than we can handle */ @@ -1176,9 +1115,9 @@ bool Lighting_Output_Write_Property( /* Command priority 6 is reserved for use by Minimum On/Off algorithm and may not be used for other purposes in any object. */ - status = - Lighting_Output_Present_Value_Set(wp_data->object_instance, - value.type.Real, wp_data->priority); + status = Lighting_Output_Present_Value_Set( + wp_data->object_instance, value.type.Real, + 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 @@ -1190,14 +1129,15 @@ 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) { 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 - object. - Note Lighting_Output_Present_Value_Relinquish() + /* Command priority 6 is reserved for use by Minimum + On/Off algorithm and may not be used for other + purposes in any object. - Note + Lighting_Output_Present_Value_Relinquish() will have returned false because of this */ wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED; @@ -1215,8 +1155,7 @@ bool Lighting_Output_Write_Property( case PROP_LIGHTING_COMMAND: if (value.tag == BACNET_APPLICATION_TAG_LIGHTING_COMMAND) { status = Lighting_Output_Lighting_Command_Set( - wp_data->object_instance, - &value.type.Lighting_Command); + wp_data->object_instance, &value.type.Lighting_Command); if (!status) { wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; @@ -1229,11 +1168,10 @@ bool Lighting_Output_Write_Property( case PROP_OUT_OF_SERVICE: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { - Lighting_Output_Out_Of_Service_Set( - wp_data->object_instance, - value.type.Boolean); + Lighting_Output_Out_Of_Service_Set(wp_data->object_instance, + value.type.Boolean); } break; case PROP_OBJECT_IDENTIFIER: @@ -1270,13 +1208,11 @@ bool Lighting_Output_Write_Property( * @param milliseconds - number of milliseconds elapsed since previously * called. Works best when called about every 10 milliseconds. */ -static void Lighting_Output_Ramp_Handler( - struct lighting_output_object *pLight, - BACNET_LIGHTING_COMMAND *pCommand, - uint16_t milliseconds) +static void Lighting_Output_Ramp_Handler(struct lighting_output_object *pLight, + BACNET_LIGHTING_COMMAND *pCommand, + uint16_t milliseconds) { if (pLight && pCommand) { - } } @@ -1288,13 +1224,11 @@ static void Lighting_Output_Ramp_Handler( * @param milliseconds - number of milliseconds elapsed since previously * called. Works best when called about every 10 milliseconds. */ -static void Lighting_Output_Fade_Handler( - struct lighting_output_object *pLight, - BACNET_LIGHTING_COMMAND *pCommand, - uint16_t milliseconds) +static void Lighting_Output_Fade_Handler(struct lighting_output_object *pLight, + BACNET_LIGHTING_COMMAND *pCommand, + uint16_t milliseconds) { if (pLight && pCommand) { - } } @@ -1305,9 +1239,7 @@ static void Lighting_Output_Fade_Handler( * @param milliseconds - number of milliseconds elapsed since previously * called. Works best when called about every 10 milliseconds. */ -static void Lighting_Output_Timer_Handler( - unsigned index, - uint16_t milliseconds) +static void Lighting_Output_Timer_Handler(unsigned index, uint16_t milliseconds) { struct lighting_output_object *pLight = NULL; BACNET_LIGHTING_COMMAND *pCommand = NULL; @@ -1352,8 +1284,7 @@ static void Lighting_Output_Timer_Handler( * @param milliseconds - number of milliseconds elapsed since previously * called. Works best when called about every 10 milliseconds. */ -void Lighting_Output_Timer( - uint16_t milliseconds) +void Lighting_Output_Timer(uint16_t milliseconds) { unsigned i = 0; @@ -1365,8 +1296,7 @@ void Lighting_Output_Timer( /** * Initializes the Lighting Output object data */ -void Lighting_Output_Init( - void) +void Lighting_Output_Init(void) { unsigned i, p; @@ -1410,11 +1340,9 @@ void Lighting_Output_Init( #include #include "ctest.h" -bool WPValidateArgType( - BACNET_APPLICATION_DATA_VALUE * pValue, - uint8_t ucExpectedTag, - BACNET_ERROR_CLASS * pErrorClass, - BACNET_ERROR_CODE * pErrorCode) +bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue, + uint8_t ucExpectedTag, BACNET_ERROR_CLASS *pErrorClass, + BACNET_ERROR_CODE *pErrorCode) { pValue = pValue; ucExpectedTag = ucExpectedTag; @@ -1424,10 +1352,9 @@ bool WPValidateArgType( return false; } -void testLightingOutput( - Test * pTest) +void testLightingOutput(Test *pTest) { - uint8_t apdu[MAX_APDU] = { 0 }; + uint8_t apdu[MAX_APDU] = {0}; int len = 0; uint32_t len_value = 0; uint8_t tag_number = 0; @@ -1454,8 +1381,7 @@ void testLightingOutput( } #ifdef TEST_LIGHTING_OUTPUT -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -1467,7 +1393,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/demo/object/lsp.c b/demo/object/lsp.c index 2b54660d..0f26882b 100644 --- a/demo/object/lsp.c +++ b/demo/object/lsp.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2005 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2005 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* Life Safety Point Objects - customize for your use */ @@ -32,7 +32,7 @@ #include "bacdcode.h" #include "bacenum.h" #include "bacapp.h" -#include "config.h" /* the custom stuff */ +#include "config.h" /* the custom stuff */ #include "rp.h" #include "wp.h" #include "lsp.h" @@ -45,8 +45,7 @@ /* Here are our stored levels.*/ static BACNET_LIFE_SAFETY_MODE Life_Safety_Point_Mode[MAX_LIFE_SAFETY_POINTS]; -static BACNET_LIFE_SAFETY_STATE - Life_Safety_Point_State[MAX_LIFE_SAFETY_POINTS]; +static BACNET_LIFE_SAFETY_STATE Life_Safety_Point_State[MAX_LIFE_SAFETY_POINTS]; static BACNET_SILENCED_STATE Life_Safety_Point_Silenced_State[MAX_LIFE_SAFETY_POINTS]; static BACNET_LIFE_SAFETY_OPERATION @@ -57,30 +56,18 @@ static bool Life_Safety_Point_Out_Of_Service[MAX_LIFE_SAFETY_POINTS]; /* These three arrays are used by the ReadPropertyMultiple handler */ static const int Life_Safety_Point_Properties_Required[] = { - PROP_OBJECT_IDENTIFIER, - PROP_OBJECT_NAME, - PROP_OBJECT_TYPE, - PROP_PRESENT_VALUE, - PROP_TRACKING_VALUE, - PROP_STATUS_FLAGS, - PROP_EVENT_STATE, - PROP_OUT_OF_SERVICE, - PROP_RELIABILITY, - PROP_MODE, - PROP_ACCEPTED_MODES, - PROP_SILENCED, - PROP_OPERATION_EXPECTED, - -1 -}; + PROP_OBJECT_IDENTIFIER, PROP_OBJECT_NAME, + PROP_OBJECT_TYPE, PROP_PRESENT_VALUE, + PROP_TRACKING_VALUE, PROP_STATUS_FLAGS, + PROP_EVENT_STATE, PROP_OUT_OF_SERVICE, + PROP_RELIABILITY, PROP_MODE, + PROP_ACCEPTED_MODES, PROP_SILENCED, + PROP_OPERATION_EXPECTED, -1}; -static const int Life_Safety_Point_Properties_Optional[] = { - PROP_DESCRIPTION, - -1 -}; +static const int Life_Safety_Point_Properties_Optional[] = {PROP_DESCRIPTION, + -1}; -static const int Life_Safety_Point_Properties_Proprietary[] = { - -1 -}; +static const int Life_Safety_Point_Properties_Proprietary[] = {-1}; /** * Returns the list of required, optional, and proprietary properties. @@ -93,10 +80,9 @@ static const int Life_Safety_Point_Properties_Proprietary[] = { * @param pProprietary - pointer to list of int terminated by -1, of * BACnet proprietary properties for this object. */ -void Life_Safety_Point_Property_Lists( - const int **pRequired, - const int **pOptional, - const int **pProprietary) +void Life_Safety_Point_Property_Lists(const int **pRequired, + const int **pOptional, + const int **pProprietary) { if (pRequired) { *pRequired = Life_Safety_Point_Properties_Required; @@ -111,8 +97,7 @@ void Life_Safety_Point_Property_Lists( return; } -void Life_Safety_Point_Init( - void) +void Life_Safety_Point_Init(void) { static bool initialized = false; unsigned i; @@ -135,8 +120,7 @@ void Life_Safety_Point_Init( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need validate that the */ /* given instance exists */ -bool Life_Safety_Point_Valid_Instance( - uint32_t object_instance) +bool Life_Safety_Point_Valid_Instance(uint32_t object_instance) { if (object_instance < MAX_LIFE_SAFETY_POINTS) return true; @@ -146,8 +130,7 @@ bool Life_Safety_Point_Valid_Instance( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then count how many you have */ -unsigned Life_Safety_Point_Count( - void) +unsigned Life_Safety_Point_Count(void) { return MAX_LIFE_SAFETY_POINTS; } @@ -155,8 +138,7 @@ unsigned Life_Safety_Point_Count( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need to return the instance */ /* that correlates to the correct index */ -uint32_t Life_Safety_Point_Index_To_Instance( - unsigned index) +uint32_t Life_Safety_Point_Index_To_Instance(unsigned index) { return index; } @@ -164,8 +146,7 @@ uint32_t Life_Safety_Point_Index_To_Instance( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need to return the index */ /* that correlates to the correct instance number */ -unsigned Life_Safety_Point_Instance_To_Index( - uint32_t object_instance) +unsigned Life_Safety_Point_Instance_To_Index(uint32_t object_instance) { unsigned index = MAX_LIFE_SAFETY_POINTS; @@ -189,11 +170,10 @@ static BACNET_LIFE_SAFETY_STATE Life_Safety_Point_Present_Value( } /* note: the object name must be unique within this device */ -bool Life_Safety_Point_Object_Name( - uint32_t object_instance, - BACNET_CHARACTER_STRING * object_name) +bool Life_Safety_Point_Object_Name(uint32_t object_instance, + BACNET_CHARACTER_STRING *object_name) { - static char text_string[32] = ""; /* okay for single thread */ + static char text_string[32] = ""; /* okay for single thread */ bool status = false; if (object_instance < MAX_LIFE_SAFETY_POINTS) { @@ -205,11 +185,10 @@ bool Life_Safety_Point_Object_Name( } /* return apdu len, or BACNET_STATUS_ERROR on error */ -int Life_Safety_Point_Read_Property( - BACNET_READ_PROPERTY_DATA * rpdata) +int Life_Safety_Point_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata) { int len = 0; - int apdu_len = 0; /* return value */ + int apdu_len = 0; /* return value */ BACNET_BIT_STRING bit_string; BACNET_CHARACTER_STRING char_string; BACNET_LIFE_SAFETY_STATE present_value = LIFE_SAFETY_STATE_QUIET; @@ -228,21 +207,19 @@ int Life_Safety_Point_Read_Property( apdu = rpdata->application_data; switch (rpdata->object_property) { case PROP_OBJECT_IDENTIFIER: - apdu_len = - encode_application_object_id(&apdu[0], - OBJECT_LIFE_SAFETY_POINT, rpdata->object_instance); + apdu_len = encode_application_object_id( + &apdu[0], OBJECT_LIFE_SAFETY_POINT, rpdata->object_instance); break; case PROP_OBJECT_NAME: case PROP_DESCRIPTION: Life_Safety_Point_Object_Name(rpdata->object_instance, - &char_string); + &char_string); apdu_len = encode_application_character_string(&apdu[0], &char_string); break; case PROP_OBJECT_TYPE: - apdu_len = - encode_application_enumerated(&apdu[0], - OBJECT_LIFE_SAFETY_POINT); + apdu_len = encode_application_enumerated(&apdu[0], + OBJECT_LIFE_SAFETY_POINT); break; case PROP_PRESENT_VALUE: present_value = @@ -286,7 +263,7 @@ int Life_Safety_Point_Read_Property( break; case PROP_ACCEPTED_MODES: for (mode = MIN_LIFE_SAFETY_MODE; mode < MAX_LIFE_SAFETY_MODE; - mode++) { + mode++) { len = encode_application_enumerated(&apdu[apdu_len], mode); apdu_len += len; } @@ -320,18 +297,16 @@ int Life_Safety_Point_Read_Property( } /* returns true if successful */ -bool Life_Safety_Point_Write_Property( - BACNET_WRITE_PROPERTY_DATA * wp_data) +bool Life_Safety_Point_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data) { - bool status = false; /* return value */ + bool status = false; /* return value */ unsigned int object_index = 0; int len = 0; BACNET_APPLICATION_DATA_VALUE value; /* decode the some of the request */ - len = - bacapp_decode_application_data(wp_data->application_data, - wp_data->application_data_len, &value); + len = bacapp_decode_application_data(wp_data->application_data, + wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ if (len < 0) { /* error while decoding - a value larger than we can handle */ @@ -349,12 +324,11 @@ bool Life_Safety_Point_Write_Property( case PROP_MODE: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_ENUMERATED, - &wp_data->error_class, &wp_data->error_code); + &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); + object_index = Life_Safety_Point_Instance_To_Index( + wp_data->object_instance); Life_Safety_Point_Mode[object_index] = value.type.Enumerated; } else { @@ -367,18 +341,15 @@ bool Life_Safety_Point_Write_Property( case PROP_OUT_OF_SERVICE: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { - object_index = - Life_Safety_Point_Instance_To_Index - (wp_data->object_instance); + object_index = Life_Safety_Point_Instance_To_Index( + wp_data->object_instance); Life_Safety_Point_Out_Of_Service[object_index] = value.type.Boolean; } break; - - case PROP_OBJECT_IDENTIFIER: case PROP_OBJECT_NAME: case PROP_DESCRIPTION: @@ -403,17 +374,14 @@ bool Life_Safety_Point_Write_Property( return status; } - #ifdef TEST #include #include #include "ctest.h" -bool WPValidateArgType( - BACNET_APPLICATION_DATA_VALUE * pValue, - uint8_t ucExpectedTag, - BACNET_ERROR_CLASS * pErrorClass, - BACNET_ERROR_CODE * pErrorCode) +bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue, + uint8_t ucExpectedTag, BACNET_ERROR_CLASS *pErrorClass, + BACNET_ERROR_CODE *pErrorCode) { pValue = pValue; ucExpectedTag = ucExpectedTag; @@ -423,10 +391,9 @@ bool WPValidateArgType( return false; } -void testLifeSafetyPoint( - Test * pTest) +void testLifeSafetyPoint(Test *pTest) { - uint8_t apdu[MAX_APDU] = { 0 }; + uint8_t apdu[MAX_APDU] = {0}; int len = 0; uint32_t len_value = 0; uint8_t tag_number = 0; @@ -453,8 +420,7 @@ void testLifeSafetyPoint( } #ifdef TEST_LIFE_SAFETY_POINT -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -466,7 +432,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/demo/object/ms-input.c b/demo/object/ms-input.c index 0ddbc88c..269825d8 100644 --- a/demo/object/ms-input.c +++ b/demo/object/ms-input.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2009 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2009 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* Multi-state Input Objects */ @@ -32,7 +32,7 @@ #include "bacdcode.h" #include "bacenum.h" #include "bacapp.h" -#include "config.h" /* the custom stuff */ +#include "config.h" /* the custom stuff */ #include "rp.h" #include "wp.h" #include "device.h" @@ -59,31 +59,18 @@ static char State_Text[MAX_MULTISTATE_INPUTS][MULTISTATE_NUMBER_OF_STATES][64]; /* These three arrays are used by the ReadPropertyMultiple handler */ static const int Properties_Required[] = { - PROP_OBJECT_IDENTIFIER, - PROP_OBJECT_NAME, - PROP_OBJECT_TYPE, - PROP_PRESENT_VALUE, - PROP_STATUS_FLAGS, - PROP_EVENT_STATE, - PROP_OUT_OF_SERVICE, - PROP_NUMBER_OF_STATES, - -1 -}; + PROP_OBJECT_IDENTIFIER, PROP_OBJECT_NAME, PROP_OBJECT_TYPE, + PROP_PRESENT_VALUE, PROP_STATUS_FLAGS, PROP_EVENT_STATE, + PROP_OUT_OF_SERVICE, PROP_NUMBER_OF_STATES, -1}; -static const int Properties_Optional[] = { - PROP_DESCRIPTION, - PROP_STATE_TEXT, - -1 -}; +static const int Properties_Optional[] = {PROP_DESCRIPTION, PROP_STATE_TEXT, + -1}; -static const int Properties_Proprietary[] = { - -1 -}; +static const int Properties_Proprietary[] = {-1}; -void Multistate_Input_Property_Lists( - const int **pRequired, - const int **pOptional, - const int **pProprietary) +void Multistate_Input_Property_Lists(const int **pRequired, + const int **pOptional, + const int **pProprietary) { if (pRequired) *pRequired = Properties_Required; @@ -95,8 +82,7 @@ void Multistate_Input_Property_Lists( return; } -void Multistate_Input_Init( - void) +void Multistate_Input_Init(void) { unsigned i; @@ -113,8 +99,7 @@ void Multistate_Input_Init( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need to return the index */ /* that correlates to the correct instance number */ -unsigned Multistate_Input_Instance_To_Index( - uint32_t object_instance) +unsigned Multistate_Input_Instance_To_Index(uint32_t object_instance) { unsigned index = MAX_MULTISTATE_INPUTS; @@ -127,22 +112,19 @@ unsigned Multistate_Input_Instance_To_Index( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need to return the instance */ /* that correlates to the correct index */ -uint32_t Multistate_Input_Index_To_Instance( - unsigned index) +uint32_t Multistate_Input_Index_To_Instance(unsigned index) { return index; } /* we simply have 0-n object instances. Yours might be */ /* more complex, and then count how many you have */ -unsigned Multistate_Input_Count( - void) +unsigned Multistate_Input_Count(void) { return MAX_MULTISTATE_INPUTS; } -bool Multistate_Input_Valid_Instance( - uint32_t object_instance) +bool Multistate_Input_Valid_Instance(uint32_t object_instance) { unsigned index = 0; /* offset from instance lookup */ @@ -154,14 +136,12 @@ bool Multistate_Input_Valid_Instance( return false; } -static uint32_t Multistate_Input_Max_States( - uint32_t instance) +static uint32_t Multistate_Input_Max_States(uint32_t instance) { return MULTISTATE_NUMBER_OF_STATES; } -uint32_t Multistate_Input_Present_Value( - uint32_t object_instance) +uint32_t Multistate_Input_Present_Value(uint32_t object_instance) { uint32_t value = 1; unsigned index = 0; /* offset from instance lookup */ @@ -174,9 +154,8 @@ uint32_t Multistate_Input_Present_Value( return value; } -bool Multistate_Input_Present_Value_Set( - uint32_t object_instance, - uint32_t value) +bool Multistate_Input_Present_Value_Set(uint32_t object_instance, + uint32_t value) { bool status = false; unsigned index = 0; /* offset from instance lookup */ @@ -184,7 +163,7 @@ bool Multistate_Input_Present_Value_Set( index = Multistate_Input_Instance_To_Index(object_instance); if (index < MAX_MULTISTATE_INPUTS) { if ((value > 0) && (value <= MULTISTATE_NUMBER_OF_STATES)) { - Present_Value[index] = (uint8_t) value; + Present_Value[index] = (uint8_t)value; status = true; } } @@ -192,8 +171,7 @@ bool Multistate_Input_Present_Value_Set( return status; } -bool Multistate_Input_Out_Of_Service( - uint32_t object_instance) +bool Multistate_Input_Out_Of_Service(uint32_t object_instance) { bool value = false; unsigned index = 0; @@ -206,9 +184,7 @@ bool Multistate_Input_Out_Of_Service( return value; } -void Multistate_Input_Out_Of_Service_Set( - uint32_t object_instance, - bool value) +void Multistate_Input_Out_Of_Service_Set(uint32_t object_instance, bool value) { unsigned index = 0; @@ -220,8 +196,7 @@ void Multistate_Input_Out_Of_Service_Set( return; } -char *Multistate_Input_Description( - uint32_t object_instance) +char *Multistate_Input_Description(uint32_t object_instance) { unsigned index = 0; /* offset from instance lookup */ char *pName = NULL; /* return value */ @@ -234,13 +209,11 @@ char *Multistate_Input_Description( return pName; } -bool Multistate_Input_Description_Set( - uint32_t object_instance, - char *new_name) +bool Multistate_Input_Description_Set(uint32_t object_instance, char *new_name) { - unsigned index = 0; /* offset from instance lookup */ - size_t i = 0; /* loop counter */ - bool status = false; /* return value */ + unsigned index = 0; /* offset from instance lookup */ + size_t i = 0; /* loop counter */ + bool status = false; /* return value */ index = Multistate_Input_Instance_To_Index(object_instance); if (index < MAX_MULTISTATE_INPUTS) { @@ -263,15 +236,13 @@ bool Multistate_Input_Description_Set( } static bool Multistate_Input_Description_Write( - uint32_t object_instance, - BACNET_CHARACTER_STRING * char_string, - BACNET_ERROR_CLASS * error_class, - BACNET_ERROR_CODE * error_code) + uint32_t object_instance, BACNET_CHARACTER_STRING *char_string, + BACNET_ERROR_CLASS *error_class, BACNET_ERROR_CODE *error_code) { unsigned index = 0; /* offset from instance lookup */ size_t length = 0; uint8_t encoding = 0; - bool status = false; /* return value */ + bool status = false; /* return value */ index = Multistate_Input_Instance_To_Index(object_instance); if (index < MAX_MULTISTATE_INPUTS) { @@ -279,8 +250,8 @@ static bool Multistate_Input_Description_Write( if (length <= sizeof(Object_Description[index])) { encoding = characterstring_encoding(char_string); if (encoding == CHARACTER_UTF8) { - status = - characterstring_ansi_copy(Object_Description[index], + status = characterstring_ansi_copy( + Object_Description[index], sizeof(Object_Description[index]), char_string); if (!status) { *error_class = ERROR_CLASS_PROPERTY; @@ -299,10 +270,8 @@ static bool Multistate_Input_Description_Write( return status; } - -bool Multistate_Input_Object_Name( - uint32_t object_instance, - BACNET_CHARACTER_STRING * object_name) +bool Multistate_Input_Object_Name(uint32_t object_instance, + BACNET_CHARACTER_STRING *object_name) { unsigned index = 0; /* offset from instance lookup */ bool status = false; @@ -316,13 +285,11 @@ bool Multistate_Input_Object_Name( } /* note: the object name must be unique within this device */ -bool Multistate_Input_Name_Set( - uint32_t object_instance, - char *new_name) +bool Multistate_Input_Name_Set(uint32_t object_instance, char *new_name) { - unsigned index = 0; /* offset from instance lookup */ - size_t i = 0; /* loop counter */ - bool status = false; /* return value */ + unsigned index = 0; /* offset from instance lookup */ + size_t i = 0; /* loop counter */ + bool status = false; /* return value */ index = Multistate_Input_Instance_To_Index(object_instance); if (index < MAX_MULTISTATE_INPUTS) { @@ -346,15 +313,13 @@ bool Multistate_Input_Name_Set( } static bool Multistate_Input_Object_Name_Write( - uint32_t object_instance, - BACNET_CHARACTER_STRING * char_string, - BACNET_ERROR_CLASS * error_class, - BACNET_ERROR_CODE * error_code) + uint32_t object_instance, BACNET_CHARACTER_STRING *char_string, + BACNET_ERROR_CLASS *error_class, BACNET_ERROR_CODE *error_code) { unsigned index = 0; /* offset from instance lookup */ size_t length = 0; uint8_t encoding = 0; - bool status = false; /* return value */ + bool status = false; /* return value */ index = Multistate_Input_Instance_To_Index(object_instance); if (index < MAX_MULTISTATE_INPUTS) { @@ -362,9 +327,9 @@ static bool Multistate_Input_Object_Name_Write( if (length <= sizeof(Object_Name[index])) { encoding = characterstring_encoding(char_string); if (encoding == CHARACTER_UTF8) { - status = - characterstring_ansi_copy(Object_Name[index], - sizeof(Object_Name[index]), char_string); + status = characterstring_ansi_copy(Object_Name[index], + sizeof(Object_Name[index]), + char_string); if (!status) { *error_class = ERROR_CLASS_PROPERTY; *error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; @@ -382,9 +347,8 @@ static bool Multistate_Input_Object_Name_Write( return status; } -char *Multistate_Input_State_Text( - uint32_t object_instance, - uint32_t state_index) +char *Multistate_Input_State_Text(uint32_t object_instance, + uint32_t state_index) { unsigned index = 0; /* offset from instance lookup */ char *pName = NULL; /* return value */ @@ -400,14 +364,12 @@ char *Multistate_Input_State_Text( } /* note: the object name must be unique within this device */ -bool Multistate_Input_State_Text_Set( - uint32_t object_instance, - uint32_t state_index, - char *new_name) +bool Multistate_Input_State_Text_Set(uint32_t object_instance, + uint32_t state_index, char *new_name) { - unsigned index = 0; /* offset from instance lookup */ - size_t i = 0; /* loop counter */ - bool status = false; /* return value */ + unsigned index = 0; /* offset from instance lookup */ + size_t i = 0; /* loop counter */ + bool status = false; /* return value */ index = Multistate_Input_Instance_To_Index(object_instance); if ((index < MAX_MULTISTATE_INPUTS) && (state_index > 0) && @@ -428,20 +390,19 @@ bool Multistate_Input_State_Text_Set( } } - return status;; + return status; + ; } static bool Multistate_Input_State_Text_Write( - uint32_t object_instance, - uint32_t state_index, - BACNET_CHARACTER_STRING * char_string, - BACNET_ERROR_CLASS * error_class, - BACNET_ERROR_CODE * error_code) + uint32_t object_instance, uint32_t state_index, + BACNET_CHARACTER_STRING *char_string, BACNET_ERROR_CLASS *error_class, + BACNET_ERROR_CODE *error_code) { unsigned index = 0; /* offset from instance lookup */ size_t length = 0; uint8_t encoding = 0; - bool status = false; /* return value */ + bool status = false; /* return value */ index = Multistate_Input_Instance_To_Index(object_instance); if ((index < MAX_MULTISTATE_INPUTS) && (state_index > 0) && @@ -451,8 +412,8 @@ static bool Multistate_Input_State_Text_Write( if (length <= sizeof(State_Text[index][state_index])) { encoding = characterstring_encoding(char_string); if (encoding == CHARACTER_UTF8) { - status = - characterstring_ansi_copy(State_Text[index][state_index], + status = characterstring_ansi_copy( + State_Text[index][state_index], sizeof(State_Text[index][state_index]), char_string); if (!status) { *error_class = ERROR_CLASS_PROPERTY; @@ -475,11 +436,10 @@ static bool Multistate_Input_State_Text_Write( } /* return apdu len, or BACNET_STATUS_ERROR on error */ -int Multistate_Input_Read_Property( - BACNET_READ_PROPERTY_DATA * rpdata) +int Multistate_Input_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata) { int len = 0; - int apdu_len = 0; /* return value */ + int apdu_len = 0; /* return value */ BACNET_BIT_STRING bit_string; BACNET_CHARACTER_STRING char_string; uint32_t present_value = 0; @@ -495,28 +455,26 @@ int Multistate_Input_Read_Property( apdu = rpdata->application_data; switch (rpdata->object_property) { case PROP_OBJECT_IDENTIFIER: - apdu_len = - encode_application_object_id(&apdu[0], - OBJECT_MULTI_STATE_INPUT, rpdata->object_instance); + apdu_len = encode_application_object_id( + &apdu[0], OBJECT_MULTI_STATE_INPUT, rpdata->object_instance); break; /* note: Name and Description don't have to be the same. You could make Description writable and different */ case PROP_OBJECT_NAME: - Multistate_Input_Object_Name(rpdata->object_instance, - &char_string); + Multistate_Input_Object_Name(rpdata->object_instance, &char_string); apdu_len = encode_application_character_string(&apdu[0], &char_string); break; case PROP_DESCRIPTION: - characterstring_init_ansi(&char_string, + characterstring_init_ansi( + &char_string, Multistate_Input_Description(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_MULTI_STATE_INPUT); + apdu_len = encode_application_enumerated(&apdu[0], + OBJECT_MULTI_STATE_INPUT); break; case PROP_PRESENT_VALUE: present_value = @@ -531,10 +489,10 @@ int Multistate_Input_Read_Property( bitstring_set_bit(&bit_string, STATUS_FLAG_OVERRIDDEN, false); if (Multistate_Input_Out_Of_Service(rpdata->object_instance)) { bitstring_set_bit(&bit_string, STATUS_FLAG_OUT_OF_SERVICE, - true); + true); } else { bitstring_set_bit(&bit_string, STATUS_FLAG_OUT_OF_SERVICE, - false); + false); } apdu_len = encode_application_bitstring(&apdu[0], &bit_string); break; @@ -548,29 +506,29 @@ int Multistate_Input_Read_Property( apdu_len = encode_application_boolean(&apdu[0], state); break; case PROP_NUMBER_OF_STATES: - apdu_len = - encode_application_unsigned(&apdu[apdu_len], + apdu_len = encode_application_unsigned( + &apdu[apdu_len], Multistate_Input_Max_States(rpdata->object_instance)); break; case PROP_STATE_TEXT: if (rpdata->array_index == 0) { /* Array element zero is the number of elements in the array */ - apdu_len = - encode_application_unsigned(&apdu[0], + apdu_len = encode_application_unsigned( + &apdu[0], Multistate_Input_Max_States(rpdata->object_instance)); } else if (rpdata->array_index == BACNET_ARRAY_ALL) { - /* if no index was specified, then try to encode the entire list */ + /* if no index was specified, then try to encode the entire list + */ /* into one packet. */ max_states = Multistate_Input_Max_States(rpdata->object_instance); for (i = 1; i <= max_states; i++) { characterstring_init_ansi(&char_string, - Multistate_Input_State_Text(rpdata->object_instance, - 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], - &char_string); + len = encode_application_character_string(&apdu[apdu_len], + &char_string); /* add it if we have room */ if ((apdu_len + len) < MAX_APDU) { apdu_len += len; @@ -585,12 +543,12 @@ int Multistate_Input_Read_Property( max_states = Multistate_Input_Max_States(rpdata->object_instance); if (rpdata->array_index <= max_states) { - characterstring_init_ansi(&char_string, + characterstring_init_ansi( + &char_string, Multistate_Input_State_Text(rpdata->object_instance, - rpdata->array_index)); - apdu_len = - encode_application_character_string(&apdu[0], - &char_string); + rpdata->array_index)); + apdu_len = encode_application_character_string( + &apdu[0], &char_string); } else { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX; @@ -616,10 +574,9 @@ int Multistate_Input_Read_Property( } /* returns true if successful */ -bool Multistate_Input_Write_Property( - BACNET_WRITE_PROPERTY_DATA * wp_data) +bool Multistate_Input_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data) { - bool status = false; /* return value */ + bool status = false; /* return value */ int len = 0; int element_len = 0; BACNET_APPLICATION_DATA_VALUE value; @@ -629,9 +586,8 @@ bool Multistate_Input_Write_Property( uint32_t object_instance = 0; /* decode the first chunk of the request */ - len = - bacapp_decode_application_data(wp_data->application_data, - wp_data->application_data_len, &value); + len = bacapp_decode_application_data(wp_data->application_data, + wp_data->application_data_len, &value); /* len < application_data_len: extra data for arrays only */ if (len < 0) { /* error while decoding - a value larger than we can handle */ @@ -651,7 +607,7 @@ bool Multistate_Input_Write_Property( if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) { /* All the object names in a device must be unique */ if (Device_Valid_Object_Name(&value.type.Character_String, - &object_type, &object_instance)) { + &object_type, &object_instance)) { if ((object_type == wp_data->object_type) && (object_instance == wp_data->object_instance)) { /* writing same name to same object */ @@ -662,9 +618,8 @@ bool Multistate_Input_Write_Property( wp_data->error_code = ERROR_CODE_DUPLICATE_NAME; } } else { - status = - Multistate_Input_Object_Name_Write(wp_data-> - object_instance, &value.type.Character_String, + status = Multistate_Input_Object_Name_Write( + wp_data->object_instance, &value.type.Character_String, &wp_data->error_class, &wp_data->error_code); } } else { @@ -674,9 +629,8 @@ bool Multistate_Input_Write_Property( break; case PROP_DESCRIPTION: if (value.tag == BACNET_APPLICATION_TAG_CHARACTER_STRING) { - status = - Multistate_Input_Description_Write(wp_data-> - object_instance, &value.type.Character_String, + status = Multistate_Input_Description_Write( + wp_data->object_instance, &value.type.Character_String, &wp_data->error_class, &wp_data->error_code); } else { wp_data->error_class = ERROR_CLASS_PROPERTY; @@ -686,11 +640,10 @@ bool Multistate_Input_Write_Property( case PROP_PRESENT_VALUE: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { - 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; @@ -700,10 +653,10 @@ bool Multistate_Input_Write_Property( case PROP_OUT_OF_SERVICE: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { Multistate_Input_Out_Of_Service_Set(wp_data->object_instance, - value.type.Boolean); + value.type.Boolean); } break; case PROP_STATE_TEXT: @@ -721,18 +674,16 @@ bool Multistate_Input_Write_Property( element_len = len; do { if (element_len) { - status = - Multistate_Input_State_Text_Write(wp_data-> - object_instance, array_index, + status = Multistate_Input_State_Text_Write( + wp_data->object_instance, array_index, &value.type.Character_String, &wp_data->error_class, &wp_data->error_code); } max_states--; array_index++; if (max_states) { - element_len = - bacapp_decode_application_data(&wp_data-> - application_data[len], + element_len = bacapp_decode_application_data( + &wp_data->application_data[len], wp_data->application_data_len - len, &value); if (element_len < 0) { wp_data->error_class = ERROR_CLASS_PROPERTY; @@ -747,11 +698,10 @@ bool Multistate_Input_Write_Property( max_states = Multistate_Input_Max_States(wp_data->object_instance); if (wp_data->array_index <= max_states) { - status = - Multistate_Input_State_Text_Write(wp_data-> - object_instance, wp_data->array_index, - &value.type.Character_String, - &wp_data->error_class, &wp_data->error_code); + status = Multistate_Input_State_Text_Write( + wp_data->object_instance, wp_data->array_index, + &value.type.Character_String, &wp_data->error_class, + &wp_data->error_code); } else { wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_WRITE_ACCESS_DENIED; @@ -779,26 +729,20 @@ bool Multistate_Input_Write_Property( return status; } - #ifdef TEST #include #include #include "ctest.h" - -bool Device_Valid_Object_Name( - BACNET_CHARACTER_STRING * object_name, - int *object_type, - uint32_t * object_instance) +bool Device_Valid_Object_Name(BACNET_CHARACTER_STRING *object_name, + int *object_type, uint32_t *object_instance) { return true; } -bool WPValidateArgType( - BACNET_APPLICATION_DATA_VALUE * pValue, - uint8_t ucExpectedTag, - BACNET_ERROR_CLASS * pErrorClass, - BACNET_ERROR_CODE * pErrorCode) +bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue, + uint8_t ucExpectedTag, BACNET_ERROR_CLASS *pErrorClass, + BACNET_ERROR_CODE *pErrorCode) { pValue = pValue; ucExpectedTag = ucExpectedTag; @@ -808,10 +752,9 @@ bool WPValidateArgType( return false; } -void testMultistateInput( - Test * pTest) +void testMultistateInput(Test *pTest) { - uint8_t apdu[MAX_APDU] = { 0 }; + uint8_t apdu[MAX_APDU] = {0}; int len = 0; uint32_t len_value = 0; uint8_t tag_number = 0; @@ -838,8 +781,7 @@ void testMultistateInput( } #ifdef TEST_MULTISTATE_INPUT -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -851,7 +793,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/demo/object/mso.c b/demo/object/mso.c index 78f3dbbc..ff170751 100644 --- a/demo/object/mso.c +++ b/demo/object/mso.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2006 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2006 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* Multi-state Output Objects - customize for your use */ @@ -32,7 +32,7 @@ #include "bacdcode.h" #include "bacenum.h" #include "bacapp.h" -#include "config.h" /* the custom stuff */ +#include "config.h" /* the custom stuff */ #include "rp.h" #include "wp.h" #include "mso.h" @@ -51,8 +51,8 @@ /* how many states? 1 to 254 states, 0 is not allowed */ #define MULTISTATE_NUMBER_OF_STATES (254) /* Here is our Priority Array.*/ -static uint8_t - Multistate_Output_Level[MAX_MULTISTATE_OUTPUTS][BACNET_MAX_PRIORITY]; +static uint8_t Multistate_Output_Level[MAX_MULTISTATE_OUTPUTS] + [BACNET_MAX_PRIORITY]; /* Writable out-of-service allows others to play with our Present Value */ /* without changing the physical output */ static bool Out_Of_Service[MAX_MULTISTATE_OUTPUTS]; @@ -69,22 +69,16 @@ static const int Multistate_Output_Properties_Required[] = { PROP_NUMBER_OF_STATES, PROP_PRIORITY_ARRAY, PROP_RELINQUISH_DEFAULT, - -1 -}; + -1}; -static const int Multistate_Output_Properties_Optional[] = { - PROP_DESCRIPTION, - -1 -}; +static const int Multistate_Output_Properties_Optional[] = {PROP_DESCRIPTION, + -1}; -static const int Multistate_Output_Properties_Proprietary[] = { - -1 -}; +static const int Multistate_Output_Properties_Proprietary[] = {-1}; -void Multistate_Output_Property_Lists( - const int **pRequired, - const int **pOptional, - const int **pProprietary) +void Multistate_Output_Property_Lists(const int **pRequired, + const int **pOptional, + const int **pProprietary) { if (pRequired) *pRequired = Multistate_Output_Properties_Required; @@ -96,8 +90,7 @@ void Multistate_Output_Property_Lists( return; } -void Multistate_Output_Init( - void) +void Multistate_Output_Init(void) { unsigned i, j; static bool initialized = false; @@ -119,8 +112,7 @@ void Multistate_Output_Init( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need validate that the */ /* given instance exists */ -bool Multistate_Output_Valid_Instance( - uint32_t object_instance) +bool Multistate_Output_Valid_Instance(uint32_t object_instance) { if (object_instance < MAX_MULTISTATE_OUTPUTS) return true; @@ -130,8 +122,7 @@ bool Multistate_Output_Valid_Instance( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then count how many you have */ -unsigned Multistate_Output_Count( - void) +unsigned Multistate_Output_Count(void) { return MAX_MULTISTATE_OUTPUTS; } @@ -139,8 +130,7 @@ unsigned Multistate_Output_Count( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need to return the instance */ /* that correlates to the correct index */ -uint32_t Multistate_Output_Index_To_Instance( - unsigned index) +uint32_t Multistate_Output_Index_To_Instance(unsigned index) { return index; } @@ -148,8 +138,7 @@ uint32_t Multistate_Output_Index_To_Instance( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need to return the index */ /* that correlates to the correct instance number */ -unsigned Multistate_Output_Instance_To_Index( - uint32_t object_instance) +unsigned Multistate_Output_Instance_To_Index(uint32_t object_instance) { unsigned index = MAX_MULTISTATE_OUTPUTS; @@ -159,8 +148,7 @@ unsigned Multistate_Output_Instance_To_Index( return index; } -uint32_t Multistate_Output_Present_Value( - uint32_t object_instance) +uint32_t Multistate_Output_Present_Value(uint32_t object_instance) { uint32_t value = MULTISTATE_RELINQUISH_DEFAULT; unsigned index = 0; @@ -180,11 +168,10 @@ uint32_t Multistate_Output_Present_Value( } /* note: the object name must be unique within this device */ -bool Multistate_Output_Object_Name( - uint32_t object_instance, - BACNET_CHARACTER_STRING * object_name) +bool Multistate_Output_Object_Name(uint32_t object_instance, + BACNET_CHARACTER_STRING *object_name) { - static char text_string[32] = ""; /* okay for single thread */ + static char text_string[32] = ""; /* okay for single thread */ bool status = false; if (object_instance < MAX_MULTISTATE_OUTPUTS) { @@ -195,8 +182,7 @@ bool Multistate_Output_Object_Name( return status; } -bool Multistate_Output_Out_Of_Service( - uint32_t instance) +bool Multistate_Output_Out_Of_Service(uint32_t instance) { unsigned index = 0; bool oos_flag = false; @@ -209,9 +195,7 @@ bool Multistate_Output_Out_Of_Service( return oos_flag; } -void Multistate_Output_Out_Of_Service_Set( - uint32_t instance, - bool oos_flag) +void Multistate_Output_Out_Of_Service_Set(uint32_t instance, bool oos_flag) { unsigned index = 0; @@ -222,11 +206,10 @@ void Multistate_Output_Out_Of_Service_Set( } /* return apdu len, or BACNET_STATUS_ERROR on error */ -int Multistate_Output_Read_Property( - BACNET_READ_PROPERTY_DATA * rpdata) +int Multistate_Output_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata) { int len = 0; - int apdu_len = 0; /* return value */ + int apdu_len = 0; /* return value */ BACNET_BIT_STRING bit_string; BACNET_CHARACTER_STRING char_string; uint32_t present_value = 0; @@ -242,23 +225,21 @@ int Multistate_Output_Read_Property( apdu = rpdata->application_data; switch (rpdata->object_property) { case PROP_OBJECT_IDENTIFIER: - apdu_len = - encode_application_object_id(&apdu[0], - OBJECT_MULTI_STATE_OUTPUT, rpdata->object_instance); + apdu_len = encode_application_object_id( + &apdu[0], OBJECT_MULTI_STATE_OUTPUT, rpdata->object_instance); break; /* note: Name and Description don't have to be the same. You could make Description writable and different */ case PROP_OBJECT_NAME: case PROP_DESCRIPTION: Multistate_Output_Object_Name(rpdata->object_instance, - &char_string); + &char_string); apdu_len = encode_application_character_string(&apdu[0], &char_string); break; case PROP_OBJECT_TYPE: - apdu_len = - encode_application_enumerated(&apdu[0], - OBJECT_MULTI_STATE_OUTPUT); + apdu_len = encode_application_enumerated(&apdu[0], + OBJECT_MULTI_STATE_OUTPUT); break; case PROP_PRESENT_VALUE: present_value = @@ -292,9 +273,8 @@ int Multistate_Output_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 = - Multistate_Output_Instance_To_Index - (rpdata->object_instance); + object_index = 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] == @@ -303,9 +283,8 @@ int Multistate_Output_Read_Property( else { present_value = Multistate_Output_Level[object_index][i]; - len = - encode_application_unsigned(&apdu[apdu_len], - present_value); + len = encode_application_unsigned(&apdu[apdu_len], + present_value); } /* add it if we have room */ if ((apdu_len + len) < MAX_APDU) @@ -318,19 +297,19 @@ int Multistate_Output_Read_Property( } } } else { - object_index = - Multistate_Output_Instance_To_Index - (rpdata->object_instance); + object_index = 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) + [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]; - apdu_len = - encode_application_unsigned(&apdu[0], - present_value); + present_value = + Multistate_Output_Level[object_index] + [rpdata->array_index - 1]; + apdu_len = encode_application_unsigned(&apdu[0], + present_value); } } else { rpdata->error_class = ERROR_CLASS_PROPERTY; @@ -345,9 +324,8 @@ int Multistate_Output_Read_Property( apdu_len = encode_application_unsigned(&apdu[0], present_value); break; case PROP_NUMBER_OF_STATES: - apdu_len = - encode_application_unsigned(&apdu[apdu_len], - MULTISTATE_NUMBER_OF_STATES); + apdu_len = encode_application_unsigned(&apdu[apdu_len], + MULTISTATE_NUMBER_OF_STATES); break; default: @@ -369,10 +347,9 @@ int Multistate_Output_Read_Property( } /* returns true if successful */ -bool Multistate_Output_Write_Property( - BACNET_WRITE_PROPERTY_DATA * wp_data) +bool Multistate_Output_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data) { - bool status = false; /* return value */ + bool status = false; /* return value */ unsigned int object_index = 0; unsigned int priority = 0; uint32_t level = 0; @@ -380,9 +357,8 @@ bool Multistate_Output_Write_Property( BACNET_APPLICATION_DATA_VALUE value; /* decode the some of the request */ - len = - bacapp_decode_application_data(wp_data->application_data, - wp_data->application_data_len, &value); + len = bacapp_decode_application_data(wp_data->application_data, + wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ if (len < 0) { /* error while decoding - a value larger than we can handle */ @@ -406,21 +382,21 @@ bool Multistate_Output_Write_Property( algorithm and may not be used for other purposes in any object. */ if (priority && (priority <= BACNET_MAX_PRIORITY) && - (priority != 6 /* reserved */ ) && + (priority != 6 /* reserved */) && (value.type.Unsigned_Int > 0) && (value.type.Unsigned_Int <= MULTISTATE_NUMBER_OF_STATES)) { level = value.type.Unsigned_Int; - object_index = - Multistate_Output_Instance_To_Index - (wp_data->object_instance); + object_index = Multistate_Output_Instance_To_Index( + wp_data->object_instance); priority--; Multistate_Output_Level[object_index][priority] = - (uint8_t) level; + (uint8_t)level; /* Note: you could set the physical output here if we are the highest priority. However, if Out of Service is TRUE, then don't set the physical output. This comment may apply to the - main loop (i.e. check out of service before changing output) */ + main loop (i.e. check out of service before changing + output) */ status = true; } else if (priority == 6) { /* Command priority 6 is reserved for use by Minimum On/Off @@ -433,25 +409,25 @@ 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); + object_index = Multistate_Output_Instance_To_Index( + wp_data->object_instance); priority = wp_data->priority; if (priority && (priority <= BACNET_MAX_PRIORITY)) { priority--; Multistate_Output_Level[object_index][priority] = - (uint8_t) level; - /* Note: you could set the physical output here to the next - highest priority, or to the relinquish default if no - priorities are set. - However, if Out of Service is TRUE, then don't set the - physical output. This comment may apply to the - main loop (i.e. check out of service before changing output) */ + (uint8_t)level; + /* Note: you could set the physical output here to the + next highest priority, or to the relinquish default + if no priorities are set. However, if Out of Service + is TRUE, then don't set the physical output. This + comment may apply to the + main loop (i.e. check out of service before changing + output) */ } else { status = false; wp_data->error_class = ERROR_CLASS_PROPERTY; @@ -463,10 +439,10 @@ bool Multistate_Output_Write_Property( case PROP_OUT_OF_SERVICE: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { Multistate_Output_Out_Of_Service_Set(wp_data->object_instance, - value.type.Boolean); + value.type.Boolean); } break; case PROP_OBJECT_IDENTIFIER: @@ -490,17 +466,14 @@ bool Multistate_Output_Write_Property( return status; } - #ifdef TEST #include #include #include "ctest.h" -bool WPValidateArgType( - BACNET_APPLICATION_DATA_VALUE * pValue, - uint8_t ucExpectedTag, - BACNET_ERROR_CLASS * pErrorClass, - BACNET_ERROR_CODE * pErrorCode) +bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue, + uint8_t ucExpectedTag, BACNET_ERROR_CLASS *pErrorClass, + BACNET_ERROR_CODE *pErrorCode) { pValue = pValue; ucExpectedTag = ucExpectedTag; @@ -510,10 +483,9 @@ bool WPValidateArgType( return false; } -void testMultistateOutput( - Test * pTest) +void testMultistateOutput(Test *pTest) { - uint8_t apdu[MAX_APDU] = { 0 }; + uint8_t apdu[MAX_APDU] = {0}; int len = 0; uint32_t len_value = 0; uint8_t tag_number = 0; @@ -540,8 +512,7 @@ void testMultistateOutput( } #ifdef TEST_MULTISTATE_OUTPUT -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -553,7 +524,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/demo/object/msv.c b/demo/object/msv.c index 88ef3769..665b3159 100644 --- a/demo/object/msv.c +++ b/demo/object/msv.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2012 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2012 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* Multi-state Value Objects */ @@ -32,7 +32,7 @@ #include "bacdcode.h" #include "bacenum.h" #include "bacapp.h" -#include "config.h" /* the custom stuff */ +#include "config.h" /* the custom stuff */ #include "rp.h" #include "wp.h" #include "msv.h" @@ -63,31 +63,18 @@ static char State_Text[MAX_MULTISTATE_VALUES][MULTISTATE_NUMBER_OF_STATES][64]; /* These three arrays are used by the ReadPropertyMultiple handler */ static const int Properties_Required[] = { - PROP_OBJECT_IDENTIFIER, - PROP_OBJECT_NAME, - PROP_OBJECT_TYPE, - PROP_PRESENT_VALUE, - PROP_STATUS_FLAGS, - PROP_EVENT_STATE, - PROP_OUT_OF_SERVICE, - PROP_NUMBER_OF_STATES, - -1 -}; + PROP_OBJECT_IDENTIFIER, PROP_OBJECT_NAME, PROP_OBJECT_TYPE, + PROP_PRESENT_VALUE, PROP_STATUS_FLAGS, PROP_EVENT_STATE, + PROP_OUT_OF_SERVICE, PROP_NUMBER_OF_STATES, -1}; -static const int Properties_Optional[] = { - PROP_DESCRIPTION, - PROP_STATE_TEXT, - -1 -}; +static const int Properties_Optional[] = {PROP_DESCRIPTION, PROP_STATE_TEXT, + -1}; -static const int Properties_Proprietary[] = { - -1 -}; +static const int Properties_Proprietary[] = {-1}; -void Multistate_Value_Property_Lists( - const int **pRequired, - const int **pOptional, - const int **pProprietary) +void Multistate_Value_Property_Lists(const int **pRequired, + const int **pOptional, + const int **pProprietary) { if (pRequired) *pRequired = Properties_Required; @@ -99,8 +86,7 @@ void Multistate_Value_Property_Lists( return; } -void Multistate_Value_Init( - void) +void Multistate_Value_Init(void) { unsigned int i; @@ -117,8 +103,7 @@ void Multistate_Value_Init( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need to return the index */ /* that correlates to the correct instance number */ -unsigned Multistate_Value_Instance_To_Index( - uint32_t object_instance) +unsigned Multistate_Value_Instance_To_Index(uint32_t object_instance) { unsigned index = MAX_MULTISTATE_VALUES; @@ -131,22 +116,19 @@ unsigned Multistate_Value_Instance_To_Index( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need to return the instance */ /* that correlates to the correct index */ -uint32_t Multistate_Value_Index_To_Instance( - unsigned index) +uint32_t Multistate_Value_Index_To_Instance(unsigned index) { return index; } /* we simply have 0-n object instances. Yours might be */ /* more complex, and then count how many you have */ -unsigned Multistate_Value_Count( - void) +unsigned Multistate_Value_Count(void) { return MAX_MULTISTATE_VALUES; } -bool Multistate_Value_Valid_Instance( - uint32_t object_instance) +bool Multistate_Value_Valid_Instance(uint32_t object_instance) { unsigned index = 0; /* offset from instance lookup */ @@ -158,8 +140,7 @@ bool Multistate_Value_Valid_Instance( return false; } -uint32_t Multistate_Value_Present_Value( - uint32_t object_instance) +uint32_t Multistate_Value_Present_Value(uint32_t object_instance) { uint32_t value = 1; unsigned index = 0; /* offset from instance lookup */ @@ -172,9 +153,8 @@ uint32_t Multistate_Value_Present_Value( return value; } -bool Multistate_Value_Present_Value_Set( - uint32_t object_instance, - uint32_t value) +bool Multistate_Value_Present_Value_Set(uint32_t object_instance, + uint32_t value) { bool status = false; unsigned index = 0; /* offset from instance lookup */ @@ -185,7 +165,7 @@ bool Multistate_Value_Present_Value_Set( if (Present_Value[index] != (uint8_t)value) { Change_Of_Value[index] = true; } - Present_Value[index] = (uint8_t) value; + Present_Value[index] = (uint8_t)value; status = true; } } @@ -193,8 +173,7 @@ bool Multistate_Value_Present_Value_Set( return status; } -bool Multistate_Value_Out_Of_Service( - uint32_t object_instance) +bool Multistate_Value_Out_Of_Service(uint32_t object_instance) { bool value = false; unsigned index = 0; @@ -207,9 +186,7 @@ bool Multistate_Value_Out_Of_Service( return value; } -void Multistate_Value_Out_Of_Service_Set( - uint32_t object_instance, - bool value) +void Multistate_Value_Out_Of_Service_Set(uint32_t object_instance, bool value) { unsigned index = 0; @@ -224,8 +201,7 @@ void Multistate_Value_Out_Of_Service_Set( return; } -char *Multistate_Value_Description( - uint32_t object_instance) +char *Multistate_Value_Description(uint32_t object_instance) { unsigned index = 0; /* offset from instance lookup */ char *pName = NULL; /* return value */ @@ -238,13 +214,11 @@ char *Multistate_Value_Description( return pName; } -bool Multistate_Value_Description_Set( - uint32_t object_instance, - char *new_name) +bool Multistate_Value_Description_Set(uint32_t object_instance, char *new_name) { - unsigned index = 0; /* offset from instance lookup */ - size_t i = 0; /* loop counter */ - bool status = false; /* return value */ + unsigned index = 0; /* offset from instance lookup */ + size_t i = 0; /* loop counter */ + bool status = false; /* return value */ index = Multistate_Value_Instance_To_Index(object_instance); if (index < MAX_MULTISTATE_VALUES) { @@ -266,9 +240,8 @@ bool Multistate_Value_Description_Set( return status; } -bool Multistate_Value_Object_Name( - uint32_t object_instance, - BACNET_CHARACTER_STRING * object_name) +bool Multistate_Value_Object_Name(uint32_t object_instance, + BACNET_CHARACTER_STRING *object_name) { unsigned index = 0; /* offset from instance lookup */ bool status = false; @@ -282,13 +255,11 @@ bool Multistate_Value_Object_Name( } /* note: the object name must be unique within this device */ -bool Multistate_Value_Name_Set( - uint32_t object_instance, - char *new_name) +bool Multistate_Value_Name_Set(uint32_t object_instance, char *new_name) { - unsigned index = 0; /* offset from instance lookup */ - size_t i = 0; /* loop counter */ - bool status = false; /* return value */ + unsigned index = 0; /* offset from instance lookup */ + size_t i = 0; /* loop counter */ + bool status = false; /* return value */ index = Multistate_Value_Instance_To_Index(object_instance); if (index < MAX_MULTISTATE_VALUES) { @@ -311,9 +282,8 @@ bool Multistate_Value_Name_Set( return status; } -char *Multistate_Value_State_Text( - uint32_t object_instance, - uint32_t state_index) +char *Multistate_Value_State_Text(uint32_t object_instance, + uint32_t state_index) { unsigned index = 0; /* offset from instance lookup */ char *pName = NULL; /* return value */ @@ -329,14 +299,12 @@ char *Multistate_Value_State_Text( } /* note: the object name must be unique within this device */ -bool Multistate_Value_State_Text_Set( - uint32_t object_instance, - uint32_t state_index, - char *new_name) +bool Multistate_Value_State_Text_Set(uint32_t object_instance, + uint32_t state_index, char *new_name) { - unsigned index = 0; /* offset from instance lookup */ - size_t i = 0; /* loop counter */ - bool status = false; /* return value */ + unsigned index = 0; /* offset from instance lookup */ + size_t i = 0; /* loop counter */ + bool status = false; /* return value */ index = Multistate_Value_Instance_To_Index(object_instance); if ((index < MAX_MULTISTATE_VALUES) && (state_index > 0) && @@ -357,11 +325,11 @@ bool Multistate_Value_State_Text_Set( } } - return status;; + return status; + ; } -bool Multistate_Value_Change_Of_Value( - uint32_t object_instance) +bool Multistate_Value_Change_Of_Value(uint32_t object_instance) { bool status = false; unsigned index; @@ -374,8 +342,7 @@ bool Multistate_Value_Change_Of_Value( return status; } -void Multistate_Value_Change_Of_Value_Clear( - uint32_t object_instance) +void Multistate_Value_Change_Of_Value_Clear(uint32_t object_instance) { unsigned index; @@ -395,9 +362,8 @@ void Multistate_Value_Change_Of_Value_Clear( * * @return true if the value list is encoded */ -bool Multistate_Value_Encode_Value_List( - uint32_t object_instance, - BACNET_PROPERTY_VALUE * value_list) +bool Multistate_Value_Encode_Value_List(uint32_t object_instance, + BACNET_PROPERTY_VALUE *value_list) { bool status = false; @@ -420,17 +386,17 @@ bool Multistate_Value_Encode_Value_List( value_list->value.next = NULL; bitstring_init(&value_list->value.type.Bit_String); bitstring_set_bit(&value_list->value.type.Bit_String, - STATUS_FLAG_IN_ALARM, false); + STATUS_FLAG_IN_ALARM, false); + bitstring_set_bit(&value_list->value.type.Bit_String, STATUS_FLAG_FAULT, + false); bitstring_set_bit(&value_list->value.type.Bit_String, - STATUS_FLAG_FAULT, false); - bitstring_set_bit(&value_list->value.type.Bit_String, - STATUS_FLAG_OVERRIDDEN, false); + STATUS_FLAG_OVERRIDDEN, false); if (Multistate_Value_Out_Of_Service(object_instance)) { bitstring_set_bit(&value_list->value.type.Bit_String, - STATUS_FLAG_OUT_OF_SERVICE, true); + STATUS_FLAG_OUT_OF_SERVICE, true); } else { bitstring_set_bit(&value_list->value.type.Bit_String, - STATUS_FLAG_OUT_OF_SERVICE, false); + STATUS_FLAG_OUT_OF_SERVICE, false); } value_list->priority = BACNET_NO_PRIORITY; value_list->next = NULL; @@ -440,14 +406,11 @@ bool Multistate_Value_Encode_Value_List( return status; } - - /* return apdu len, or BACNET_STATUS_ERROR on error */ -int Multistate_Value_Read_Property( - BACNET_READ_PROPERTY_DATA * rpdata) +int Multistate_Value_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata) { int len = 0; - int apdu_len = 0; /* return value */ + int apdu_len = 0; /* return value */ BACNET_BIT_STRING bit_string; BACNET_CHARACTER_STRING char_string; uint32_t present_value = 0; @@ -462,28 +425,26 @@ int Multistate_Value_Read_Property( apdu = rpdata->application_data; switch (rpdata->object_property) { case PROP_OBJECT_IDENTIFIER: - apdu_len = - encode_application_object_id(&apdu[0], - OBJECT_MULTI_STATE_VALUE, rpdata->object_instance); + apdu_len = encode_application_object_id( + &apdu[0], OBJECT_MULTI_STATE_VALUE, rpdata->object_instance); break; /* note: Name and Description don't have to be the same. You could make Description writable and different */ case PROP_OBJECT_NAME: - Multistate_Value_Object_Name(rpdata->object_instance, - &char_string); + Multistate_Value_Object_Name(rpdata->object_instance, &char_string); apdu_len = encode_application_character_string(&apdu[0], &char_string); break; case PROP_DESCRIPTION: - characterstring_init_ansi(&char_string, + characterstring_init_ansi( + &char_string, Multistate_Value_Description(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_MULTI_STATE_VALUE); + apdu_len = encode_application_enumerated(&apdu[0], + OBJECT_MULTI_STATE_VALUE); break; case PROP_PRESENT_VALUE: present_value = @@ -510,27 +471,25 @@ int Multistate_Value_Read_Property( apdu_len = encode_application_boolean(&apdu[0], state); break; case PROP_NUMBER_OF_STATES: - apdu_len = - encode_application_unsigned(&apdu[apdu_len], - MULTISTATE_NUMBER_OF_STATES); + apdu_len = encode_application_unsigned(&apdu[apdu_len], + MULTISTATE_NUMBER_OF_STATES); break; case PROP_STATE_TEXT: if (rpdata->array_index == 0) { /* Array element zero is the number of elements in the array */ - apdu_len = - encode_application_unsigned(&apdu[0], - MULTISTATE_NUMBER_OF_STATES); + apdu_len = encode_application_unsigned( + &apdu[0], MULTISTATE_NUMBER_OF_STATES); } else if (rpdata->array_index == BACNET_ARRAY_ALL) { - /* if no index was specified, then try to encode the entire list */ + /* if no index was specified, then try to encode the entire list + */ /* into one packet. */ for (i = 1; i <= MULTISTATE_NUMBER_OF_STATES; i++) { characterstring_init_ansi(&char_string, - Multistate_Value_State_Text(rpdata->object_instance, - i)); + Multistate_Value_State_Text( + rpdata->object_instance, i)); /* FIXME: this might go beyond MAX_APDU length! */ - len = - encode_application_character_string(&apdu[apdu_len], - &char_string); + len = encode_application_character_string(&apdu[apdu_len], + &char_string); /* add it if we have room */ if ((apdu_len + len) < MAX_APDU) { apdu_len += len; @@ -543,12 +502,12 @@ int Multistate_Value_Read_Property( } } else { if (rpdata->array_index <= MULTISTATE_NUMBER_OF_STATES) { - characterstring_init_ansi(&char_string, + characterstring_init_ansi( + &char_string, Multistate_Value_State_Text(rpdata->object_instance, - rpdata->array_index)); - apdu_len = - encode_application_character_string(&apdu[0], - &char_string); + rpdata->array_index)); + apdu_len = encode_application_character_string( + &apdu[0], &char_string); } else { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX; @@ -575,17 +534,15 @@ int Multistate_Value_Read_Property( } /* returns true if successful */ -bool Multistate_Value_Write_Property( - BACNET_WRITE_PROPERTY_DATA * wp_data) +bool Multistate_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data) { - bool status = false; /* return value */ + bool status = false; /* return value */ int len = 0; BACNET_APPLICATION_DATA_VALUE value; /* decode the some of the request */ - len = - bacapp_decode_application_data(wp_data->application_data, - wp_data->application_data_len, &value); + len = bacapp_decode_application_data(wp_data->application_data, + wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ if (len < 0) { /* error while decoding - a value larger than we can handle */ @@ -605,11 +562,10 @@ bool Multistate_Value_Write_Property( case PROP_PRESENT_VALUE: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { - status = - Multistate_Value_Present_Value_Set - (wp_data->object_instance, value.type.Unsigned_Int); + status = Multistate_Value_Present_Value_Set( + wp_data->object_instance, value.type.Unsigned_Int); if (!status) { wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; @@ -619,10 +575,10 @@ bool Multistate_Value_Write_Property( case PROP_OUT_OF_SERVICE: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { Multistate_Value_Out_Of_Service_Set(wp_data->object_instance, - value.type.Boolean); + value.type.Boolean); } break; case PROP_OBJECT_IDENTIFIER: @@ -645,17 +601,14 @@ bool Multistate_Value_Write_Property( return status; } - #ifdef TEST #include #include #include "ctest.h" -bool WPValidateArgType( - BACNET_APPLICATION_DATA_VALUE * pValue, - uint8_t ucExpectedTag, - BACNET_ERROR_CLASS * pErrorClass, - BACNET_ERROR_CODE * pErrorCode) +bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue, + uint8_t ucExpectedTag, BACNET_ERROR_CLASS *pErrorClass, + BACNET_ERROR_CODE *pErrorCode) { pValue = pValue; ucExpectedTag = ucExpectedTag; @@ -665,10 +618,9 @@ bool WPValidateArgType( return false; } -void testMultistateInput( - Test * pTest) +void testMultistateInput(Test *pTest) { - uint8_t apdu[MAX_APDU] = { 0 }; + uint8_t apdu[MAX_APDU] = {0}; int len = 0; uint32_t len_value = 0; uint8_t tag_number = 0; @@ -695,8 +647,7 @@ void testMultistateInput( } #ifdef TEST_MULTISTATE_VALUE -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -708,7 +659,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/demo/object/nc.c b/demo/object/nc.c index 563888d3..f69ea0df 100644 --- a/demo/object/nc.c +++ b/demo/object/nc.c @@ -1,32 +1,32 @@ /************************************************************************** -* -* Copyright (C) 2011 Krzysztof Malorny -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -* Additional changes, Copyright (c) 2018 Ed Hague -* -* 2018.06.17 - Attempting to write to Object_Name returned UNKNOWN_PROPERTY. -* Now returns WRITE_ACCESS_DENIED -* -*********************************************************************/ + * + * Copyright (C) 2011 Krzysztof Malorny + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * Additional changes, Copyright (c) 2018 Ed Hague + * + * 2018.06.17 - Attempting to write to Object_Name returned + *UNKNOWN_PROPERTY. Now returns WRITE_ACCESS_DENIED + * + *********************************************************************/ #include #include @@ -47,40 +47,27 @@ #include "wp.h" #include "nc.h" - #ifndef MAX_NOTIFICATION_CLASSES #define MAX_NOTIFICATION_CLASSES 2 #endif - #if defined(INTRINSIC_REPORTING) static NOTIFICATION_CLASS_INFO NC_Info[MAX_NOTIFICATION_CLASSES]; /* These three arrays are used by the ReadPropertyMultiple handler */ static const int Notification_Properties_Required[] = { - PROP_OBJECT_IDENTIFIER, - PROP_OBJECT_NAME, - PROP_OBJECT_TYPE, - PROP_NOTIFICATION_CLASS, - PROP_PRIORITY, - PROP_ACK_REQUIRED, - PROP_RECIPIENT_LIST, - -1 -}; + PROP_OBJECT_IDENTIFIER, PROP_OBJECT_NAME, + PROP_OBJECT_TYPE, PROP_NOTIFICATION_CLASS, + PROP_PRIORITY, PROP_ACK_REQUIRED, + PROP_RECIPIENT_LIST, -1}; -static const int Notification_Properties_Optional[] = { - PROP_DESCRIPTION, - -1 -}; +static const int Notification_Properties_Optional[] = {PROP_DESCRIPTION, -1}; -static const int Notification_Properties_Proprietary[] = { - -1 -}; +static const int Notification_Properties_Proprietary[] = {-1}; -void Notification_Class_Property_Lists( - const int **pRequired, - const int **pOptional, - const int **pProprietary) +void Notification_Class_Property_Lists(const int **pRequired, + const int **pOptional, + const int **pProprietary) { if (pRequired) *pRequired = Notification_Properties_Required; @@ -91,8 +78,7 @@ void Notification_Class_Property_Lists( return; } -void Notification_Class_Init( - void) +void Notification_Class_Init(void) { uint8_t NotifyIdx = 0; @@ -101,20 +87,21 @@ void Notification_Class_Init( memset(&NC_Info[NotifyIdx], 0x00, sizeof(NOTIFICATION_CLASS_INFO)); /* set the basic parameters */ NC_Info[NotifyIdx].Ack_Required = 0; - NC_Info[NotifyIdx].Priority[TRANSITION_TO_OFFNORMAL] = 255; /* The lowest priority for Normal message. */ - NC_Info[NotifyIdx].Priority[TRANSITION_TO_FAULT] = 255; /* The lowest priority for Normal message. */ - NC_Info[NotifyIdx].Priority[TRANSITION_TO_NORMAL] = 255; /* The lowest priority for Normal message. */ + NC_Info[NotifyIdx].Priority[TRANSITION_TO_OFFNORMAL] = + 255; /* The lowest priority for Normal message. */ + NC_Info[NotifyIdx].Priority[TRANSITION_TO_FAULT] = + 255; /* The lowest priority for Normal message. */ + NC_Info[NotifyIdx].Priority[TRANSITION_TO_NORMAL] = + 255; /* The lowest priority for Normal message. */ } return; } - /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need validate that the */ /* given instance exists */ -bool Notification_Class_Valid_Instance( - uint32_t object_instance) +bool Notification_Class_Valid_Instance(uint32_t object_instance) { unsigned int index; @@ -127,8 +114,7 @@ bool Notification_Class_Valid_Instance( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then count how many you have */ -unsigned Notification_Class_Count( - void) +unsigned Notification_Class_Count(void) { return MAX_NOTIFICATION_CLASSES; } @@ -136,8 +122,7 @@ unsigned Notification_Class_Count( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need to return the instance */ /* that correlates to the correct index */ -uint32_t Notification_Class_Index_To_Instance( - unsigned index) +uint32_t Notification_Class_Index_To_Instance(unsigned index) { return index; } @@ -145,8 +130,7 @@ uint32_t Notification_Class_Index_To_Instance( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need to return the index */ /* that correlates to the correct instance number */ -unsigned Notification_Class_Instance_To_Index( - uint32_t object_instance) +unsigned Notification_Class_Instance_To_Index(uint32_t object_instance) { unsigned index = MAX_NOTIFICATION_CLASSES; @@ -156,27 +140,23 @@ unsigned Notification_Class_Instance_To_Index( return index; } -bool Notification_Class_Object_Name( - uint32_t object_instance, - BACNET_CHARACTER_STRING * object_name) +bool Notification_Class_Object_Name(uint32_t object_instance, + BACNET_CHARACTER_STRING *object_name) { - static char text_string[32] = ""; /* okay for single thread */ + static char text_string[32] = ""; /* okay for single thread */ unsigned int index; bool status = false; index = Notification_Class_Instance_To_Index(object_instance); if (index < MAX_NOTIFICATION_CLASSES) { - sprintf(text_string, "NOTIFICATION CLASS %lu", (unsigned long) index); + sprintf(text_string, "NOTIFICATION CLASS %lu", (unsigned long)index); status = characterstring_init_ansi(object_name, text_string); } return status; } - - -int Notification_Class_Read_Property( - BACNET_READ_PROPERTY_DATA * rpdata) +int Notification_Class_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata) { NOTIFICATION_CLASS_INFO *CurrentNotify; BACNET_CHARACTER_STRING char_string; @@ -185,8 +165,7 @@ int Notification_Class_Read_Property( uint8_t *apdu = NULL; uint8_t u8Val; int idx; - int apdu_len = 0; /* return value */ - + int apdu_len = 0; /* return value */ if ((rpdata == NULL) || (rpdata->application_data == NULL) || (rpdata->application_data_len == 0)) { @@ -195,28 +174,25 @@ int Notification_Class_Read_Property( apdu = rpdata->application_data; CurrentNotify = - &NC_Info[Notification_Class_Instance_To_Index(rpdata-> - object_instance)]; + &NC_Info[Notification_Class_Instance_To_Index(rpdata->object_instance)]; switch (rpdata->object_property) { case PROP_OBJECT_IDENTIFIER: - apdu_len = - encode_application_object_id(&apdu[0], - OBJECT_NOTIFICATION_CLASS, rpdata->object_instance); + apdu_len = encode_application_object_id( + &apdu[0], OBJECT_NOTIFICATION_CLASS, rpdata->object_instance); break; case PROP_OBJECT_NAME: case PROP_DESCRIPTION: Notification_Class_Object_Name(rpdata->object_instance, - &char_string); + &char_string); apdu_len = encode_application_character_string(&apdu[0], &char_string); break; case PROP_OBJECT_TYPE: - apdu_len = - encode_application_enumerated(&apdu[0], - OBJECT_NOTIFICATION_CLASS); + apdu_len = encode_application_enumerated(&apdu[0], + OBJECT_NOTIFICATION_CLASS); break; case PROP_NOTIFICATION_CLASS: @@ -229,18 +205,18 @@ int Notification_Class_Read_Property( apdu_len += encode_application_unsigned(&apdu[0], 3); else { if (rpdata->array_index == BACNET_ARRAY_ALL) { - apdu_len += - encode_application_unsigned(&apdu[apdu_len], + apdu_len += encode_application_unsigned( + &apdu[apdu_len], CurrentNotify->Priority[TRANSITION_TO_OFFNORMAL]); - apdu_len += - encode_application_unsigned(&apdu[apdu_len], + apdu_len += encode_application_unsigned( + &apdu[apdu_len], CurrentNotify->Priority[TRANSITION_TO_FAULT]); - apdu_len += - encode_application_unsigned(&apdu[apdu_len], + apdu_len += encode_application_unsigned( + &apdu[apdu_len], CurrentNotify->Priority[TRANSITION_TO_NORMAL]); } else if (rpdata->array_index <= MAX_BACNET_EVENT_TRANSITION) { - apdu_len += - encode_application_unsigned(&apdu[apdu_len], + apdu_len += encode_application_unsigned( + &apdu[apdu_len], CurrentNotify->Priority[rpdata->array_index - 1]); } else { rpdata->error_class = ERROR_CLASS_PROPERTY; @@ -254,11 +230,14 @@ int Notification_Class_Read_Property( u8Val = CurrentNotify->Ack_Required; bitstring_init(&bit_string); - bitstring_set_bit(&bit_string, TRANSITION_TO_OFFNORMAL, + bitstring_set_bit( + &bit_string, TRANSITION_TO_OFFNORMAL, (u8Val & TRANSITION_TO_OFFNORMAL_MASKED) ? true : false); - bitstring_set_bit(&bit_string, TRANSITION_TO_FAULT, + bitstring_set_bit( + &bit_string, TRANSITION_TO_FAULT, (u8Val & TRANSITION_TO_FAULT_MASKED) ? true : false); - bitstring_set_bit(&bit_string, TRANSITION_TO_NORMAL, + bitstring_set_bit( + &bit_string, TRANSITION_TO_NORMAL, (u8Val & TRANSITION_TO_NORMAL_MASKED) ? true : false); /* encode bitstring */ apdu_len += @@ -271,11 +250,13 @@ int Notification_Class_Read_Property( BACNET_DESTINATION *RecipientEntry; int i = 0; - /* get pointer of current element for Recipient_List - easier for use */ + /* get pointer of current element for Recipient_List - easier + * for use */ RecipientEntry = &CurrentNotify->Recipient_List[idx]; if (RecipientEntry->Recipient.RecipientType != RECIPIENT_TYPE_NOTINITIALIZED) { - /* Valid Days - BACnetDaysOfWeek - [bitstring] monday-sunday */ + /* Valid Days - BACnetDaysOfWeek - [bitstring] monday-sunday + */ u8Val = 0x01; bitstring_init(&bit_string); @@ -284,21 +265,18 @@ int Notification_Class_Read_Property( bitstring_set_bit(&bit_string, i, true); else bitstring_set_bit(&bit_string, i, false); - u8Val <<= 1; /* next day */ + u8Val <<= 1; /* next day */ } - apdu_len += - encode_application_bitstring(&apdu[apdu_len], - &bit_string); + apdu_len += encode_application_bitstring(&apdu[apdu_len], + &bit_string); /* From Time */ - apdu_len += - encode_application_time(&apdu[apdu_len], - &RecipientEntry->FromTime); + apdu_len += encode_application_time( + &apdu[apdu_len], &RecipientEntry->FromTime); /* To Time */ - apdu_len += - encode_application_time(&apdu[apdu_len], - &RecipientEntry->ToTime); + apdu_len += encode_application_time( + &apdu[apdu_len], &RecipientEntry->ToTime); /* BACnetRecipient ::= CHOICE { @@ -309,66 +287,67 @@ int Notification_Class_Read_Property( /* CHOICE - device [0] BACnetObjectIdentifier */ if (RecipientEntry->Recipient.RecipientType == RECIPIENT_TYPE_DEVICE) { - apdu_len += - encode_context_object_id(&apdu[apdu_len], 0, - OBJECT_DEVICE, + apdu_len += encode_context_object_id( + &apdu[apdu_len], 0, OBJECT_DEVICE, RecipientEntry->Recipient._.DeviceIdentifier); } /* CHOICE - address [1] BACnetAddress */ else if (RecipientEntry->Recipient.RecipientType == - RECIPIENT_TYPE_ADDRESS) { + RECIPIENT_TYPE_ADDRESS) { /* opening tag 1 */ apdu_len += encode_opening_tag(&apdu[apdu_len], 1); /* network-number Unsigned16, */ - apdu_len += - encode_application_unsigned(&apdu[apdu_len], + apdu_len += encode_application_unsigned( + &apdu[apdu_len], RecipientEntry->Recipient._.Address.net); /* mac-address OCTET STRING */ if (RecipientEntry->Recipient._.Address.net) { - octetstring_init(&octet_string, + octetstring_init( + &octet_string, RecipientEntry->Recipient._.Address.adr, RecipientEntry->Recipient._.Address.len); } else { - octetstring_init(&octet_string, + octetstring_init( + &octet_string, RecipientEntry->Recipient._.Address.mac, RecipientEntry->Recipient._.Address.mac_len); } - apdu_len += - encode_application_octet_string(&apdu[apdu_len], - &octet_string); + apdu_len += encode_application_octet_string( + &apdu[apdu_len], &octet_string); /* closing tag 1 */ apdu_len += encode_closing_tag(&apdu[apdu_len], 1); - } else {; - } /* shouldn't happen */ + } else { + ; + } /* shouldn't happen */ /* Process Identifier - Unsigned32 */ - apdu_len += - encode_application_unsigned(&apdu[apdu_len], - RecipientEntry->ProcessIdentifier); + apdu_len += encode_application_unsigned( + &apdu[apdu_len], RecipientEntry->ProcessIdentifier); /* Issue Confirmed Notifications - boolean */ - apdu_len += - encode_application_boolean(&apdu[apdu_len], - RecipientEntry->ConfirmedNotify); + apdu_len += encode_application_boolean( + &apdu[apdu_len], RecipientEntry->ConfirmedNotify); /* Transitions - BACnet Event Transition Bits [bitstring] */ u8Val = RecipientEntry->Transitions; bitstring_init(&bit_string); bitstring_set_bit(&bit_string, TRANSITION_TO_OFFNORMAL, - (u8Val & TRANSITION_TO_OFFNORMAL_MASKED) ? true : - false); - bitstring_set_bit(&bit_string, TRANSITION_TO_FAULT, + (u8Val & TRANSITION_TO_OFFNORMAL_MASKED) + ? true + : false); + bitstring_set_bit( + &bit_string, TRANSITION_TO_FAULT, (u8Val & TRANSITION_TO_FAULT_MASKED) ? true : false); - bitstring_set_bit(&bit_string, TRANSITION_TO_NORMAL, + bitstring_set_bit( + &bit_string, TRANSITION_TO_NORMAL, (u8Val & TRANSITION_TO_NORMAL_MASKED) ? true : false); - apdu_len += - encode_application_bitstring(&apdu[apdu_len], - &bit_string); + apdu_len += encode_application_bitstring(&apdu[apdu_len], + &bit_string); } } break; @@ -391,29 +370,24 @@ int Notification_Class_Read_Property( return apdu_len; } - -bool Notification_Class_Write_Property( - BACNET_WRITE_PROPERTY_DATA * wp_data) +bool Notification_Class_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data) { NOTIFICATION_CLASS_INFO *CurrentNotify; NOTIFICATION_CLASS_INFO TmpNotify; BACNET_APPLICATION_DATA_VALUE value; - uint8_t TmpPriority[MAX_BACNET_EVENT_TRANSITION]; /* BACnetARRAY[3] of Unsigned */ + uint8_t TmpPriority[MAX_BACNET_EVENT_TRANSITION]; /* BACnetARRAY[3] of + Unsigned */ bool status = false; int iOffset; uint8_t idx; int len = 0; - - - CurrentNotify = - &NC_Info[Notification_Class_Instance_To_Index(wp_data-> - object_instance)]; + CurrentNotify = &NC_Info[Notification_Class_Instance_To_Index( + wp_data->object_instance)]; /* decode some of the request */ - len = - bacapp_decode_application_data(wp_data->application_data, - wp_data->application_data_len, &value); + len = bacapp_decode_application_data(wp_data->application_data, + wp_data->application_data_len, &value); if (len < 0) { /* error while decoding - a value larger than we can handle */ wp_data->error_class = ERROR_CLASS_PROPERTY; @@ -431,7 +405,7 @@ bool Notification_Class_Write_Property( case PROP_PRIORITY: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { if (wp_data->array_index == 0) { @@ -440,16 +414,15 @@ bool Notification_Class_Write_Property( status = false; } else if (wp_data->array_index == BACNET_ARRAY_ALL) { iOffset = 0; - for (idx = 0; idx < MAX_BACNET_EVENT_TRANSITION; idx++) - { - len = - bacapp_decode_application_data(&wp_data-> - application_data[iOffset], wp_data->application_data_len, - &value); + for (idx = 0; idx < MAX_BACNET_EVENT_TRANSITION; idx++) { + len = bacapp_decode_application_data( + &wp_data->application_data[iOffset], + wp_data->application_data_len, &value); if ((len == 0) || - (value.tag != BACNET_APPLICATION_TAG_UNSIGNED_INT)) - { - /* Bad decode, wrong tag or following required parameter missing */ + (value.tag != + BACNET_APPLICATION_TAG_UNSIGNED_INT)) { + /* Bad decode, wrong tag or following required + * parameter missing */ wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; status = false; @@ -461,22 +434,21 @@ bool Notification_Class_Write_Property( status = false; break; } - TmpPriority[idx] = (uint8_t) value.type.Unsigned_Int; + TmpPriority[idx] = (uint8_t)value.type.Unsigned_Int; iOffset += len; } if (status == true) { for (idx = 0; idx < MAX_BACNET_EVENT_TRANSITION; idx++) - CurrentNotify->Priority[idx] = TmpPriority[idx]; + CurrentNotify->Priority[idx] = TmpPriority[idx]; } } else if (wp_data->array_index <= 3) { if (value.type.Unsigned_Int > 255) { wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_VALUE_OUT_OF_RANGE; status = false; - } - else - CurrentNotify->Priority[wp_data->array_index - 1] = - value.type.Unsigned_Int; + } else + CurrentNotify->Priority[wp_data->array_index - 1] = + value.type.Unsigned_Int; } else { wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_INVALID_ARRAY_INDEX; @@ -488,7 +460,7 @@ bool Notification_Class_Write_Property( case PROP_ACK_REQUIRED: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_BIT_STRING, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { if (value.type.Bit_String.bits_used == 3) { @@ -509,14 +481,14 @@ bool Notification_Class_Write_Property( /* decode all packed */ while (iOffset < wp_data->application_data_len) { /* Decode Valid Days */ - len = - bacapp_decode_application_data(&wp_data-> - application_data[iOffset], wp_data->application_data_len, - &value); + len = bacapp_decode_application_data( + &wp_data->application_data[iOffset], + wp_data->application_data_len, &value); if ((len == 0) || (value.tag != BACNET_APPLICATION_TAG_BIT_STRING)) { - /* Bad decode, wrong tag or following required parameter missing */ + /* Bad decode, wrong tag or following required parameter + * missing */ wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; return false; @@ -534,13 +506,13 @@ bool Notification_Class_Write_Property( iOffset += len; /* Decode From Time */ - len = - bacapp_decode_application_data(&wp_data-> - application_data[iOffset], wp_data->application_data_len, - &value); + len = bacapp_decode_application_data( + &wp_data->application_data[iOffset], + wp_data->application_data_len, &value); if ((len == 0) || (value.tag != BACNET_APPLICATION_TAG_TIME)) { - /* Bad decode, wrong tag or following required parameter missing */ + /* Bad decode, wrong tag or following required parameter + * missing */ wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; return false; @@ -550,13 +522,13 @@ bool Notification_Class_Write_Property( iOffset += len; /* Decode To Time */ - len = - bacapp_decode_application_data(&wp_data-> - application_data[iOffset], wp_data->application_data_len, - &value); + len = bacapp_decode_application_data( + &wp_data->application_data[iOffset], + wp_data->application_data_len, &value); if ((len == 0) || (value.tag != BACNET_APPLICATION_TAG_TIME)) { - /* Bad decode, wrong tag or following required parameter missing */ + /* Bad decode, wrong tag or following required parameter + * missing */ wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; return false; @@ -567,44 +539,44 @@ bool Notification_Class_Write_Property( iOffset += len; /* context tag [0] - Device */ if (decode_is_context_tag(&wp_data->application_data[iOffset], - 0)) { + 0)) { TmpNotify.Recipient_List[idx].Recipient.RecipientType = RECIPIENT_TYPE_DEVICE; /* Decode Network Number */ - len = - bacapp_decode_context_data(&wp_data-> - application_data[iOffset], + len = bacapp_decode_context_data( + &wp_data->application_data[iOffset], wp_data->application_data_len, &value, PROP_RECIPIENT_LIST); if ((len == 0) || (value.tag != BACNET_APPLICATION_TAG_OBJECT_ID)) { - /* Bad decode, wrong tag or following required parameter missing */ + /* Bad decode, wrong tag or following required parameter + * missing */ wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; return false; } /* store value */ - TmpNotify.Recipient_List[idx].Recipient._. - DeviceIdentifier = value.type.Object_Id.instance; + TmpNotify.Recipient_List[idx].Recipient._.DeviceIdentifier = + value.type.Object_Id.instance; iOffset += len; } /* opening tag [1] - Recipient */ - else if (decode_is_opening_tag_number(&wp_data-> - application_data[iOffset], 1)) { + else if (decode_is_opening_tag_number( + &wp_data->application_data[iOffset], 1)) { iOffset++; TmpNotify.Recipient_List[idx].Recipient.RecipientType = RECIPIENT_TYPE_ADDRESS; /* Decode Network Number */ - len = - bacapp_decode_application_data(&wp_data-> - application_data[iOffset], + len = bacapp_decode_application_data( + &wp_data->application_data[iOffset], wp_data->application_data_len, &value); if ((len == 0) || (value.tag != BACNET_APPLICATION_TAG_UNSIGNED_INT)) { - /* Bad decode, wrong tag or following required parameter missing */ + /* Bad decode, wrong tag or following required parameter + * missing */ wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; return false; @@ -615,61 +587,66 @@ bool Notification_Class_Write_Property( iOffset += len; /* Decode Address */ - len = - bacapp_decode_application_data(&wp_data-> - application_data[iOffset], + len = bacapp_decode_application_data( + &wp_data->application_data[iOffset], wp_data->application_data_len, &value); if ((len == 0) || (value.tag != BACNET_APPLICATION_TAG_OCTET_STRING)) { - /* Bad decode, wrong tag or following required parameter missing */ + /* Bad decode, wrong tag or following required parameter + * missing */ wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; return false; } /* store value */ - if (TmpNotify.Recipient_List[idx].Recipient._.Address. - net == 0) { - memcpy(TmpNotify.Recipient_List[idx].Recipient._. - Address.mac, value.type.Octet_String.value, - value.type.Octet_String.length); - TmpNotify.Recipient_List[idx].Recipient._.Address. - mac_len = value.type.Octet_String.length; + if (TmpNotify.Recipient_List[idx].Recipient._.Address.net == + 0) { + memcpy(TmpNotify.Recipient_List[idx] + .Recipient._.Address.mac, + value.type.Octet_String.value, + value.type.Octet_String.length); + TmpNotify.Recipient_List[idx] + .Recipient._.Address.mac_len = + value.type.Octet_String.length; } else { - memcpy(TmpNotify.Recipient_List[idx].Recipient._. - Address.adr, value.type.Octet_String.value, - value.type.Octet_String.length); + memcpy(TmpNotify.Recipient_List[idx] + .Recipient._.Address.adr, + value.type.Octet_String.value, + value.type.Octet_String.length); TmpNotify.Recipient_List[idx].Recipient._.Address.len = value.type.Octet_String.length; } iOffset += len; /* closing tag [1] - Recipient */ - if (decode_is_closing_tag_number(&wp_data-> - application_data[iOffset], 1)) + if (decode_is_closing_tag_number( + &wp_data->application_data[iOffset], 1)) iOffset++; else { - /* Bad decode, wrong tag or following required parameter missing */ + /* Bad decode, wrong tag or following required parameter + * missing */ wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; return false; } } else { - /* Bad decode, wrong tag or following required parameter missing */ + /* Bad decode, wrong tag or following required parameter + * missing */ wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; return false; } /* Process Identifier */ - len = - bacapp_decode_application_data(&wp_data-> - application_data[iOffset], wp_data->application_data_len, - &value); + len = bacapp_decode_application_data( + &wp_data->application_data[iOffset], + wp_data->application_data_len, &value); if ((len == 0) || (value.tag != BACNET_APPLICATION_TAG_UNSIGNED_INT)) { - /* Bad decode, wrong tag or following required parameter missing */ + /* Bad decode, wrong tag or following required parameter + * missing */ wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; return false; @@ -680,14 +657,14 @@ bool Notification_Class_Write_Property( iOffset += len; /* Issue Confirmed Notifications */ - len = - bacapp_decode_application_data(&wp_data-> - application_data[iOffset], wp_data->application_data_len, - &value); + len = bacapp_decode_application_data( + &wp_data->application_data[iOffset], + wp_data->application_data_len, &value); if ((len == 0) || (value.tag != BACNET_APPLICATION_TAG_BOOLEAN)) { - /* Bad decode, wrong tag or following required parameter missing */ + /* Bad decode, wrong tag or following required parameter + * missing */ wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; return false; @@ -698,14 +675,14 @@ bool Notification_Class_Write_Property( iOffset += len; /* Transitions */ - len = - bacapp_decode_application_data(&wp_data-> - application_data[iOffset], wp_data->application_data_len, - &value); + len = bacapp_decode_application_data( + &wp_data->application_data[iOffset], + wp_data->application_data_len, &value); if ((len == 0) || (value.tag != BACNET_APPLICATION_TAG_BIT_STRING)) { - /* Bad decode, wrong tag or following required parameter missing */ + /* Bad decode, wrong tag or following required parameter + * missing */ wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_INVALID_DATA_TYPE; return false; @@ -726,8 +703,7 @@ bool Notification_Class_Write_Property( /* Increasing element of list */ if (++idx >= NC_MAX_RECIPIENTS) { wp_data->error_class = ERROR_CLASS_RESOURCES; - wp_data->error_code = - ERROR_CODE_NO_SPACE_TO_WRITE_PROPERTY; + wp_data->error_code = ERROR_CODE_NO_SPACE_TO_WRITE_PROPERTY; return false; } } @@ -735,26 +711,29 @@ bool Notification_Class_Write_Property( /* Decoded all recipient list */ /* copy elements from temporary object */ for (idx = 0; idx < NC_MAX_RECIPIENTS; idx++) { - BACNET_ADDRESS src = { 0 }; + BACNET_ADDRESS src = {0}; unsigned max_apdu = 0; int32_t DeviceID; CurrentNotify->Recipient_List[idx] = TmpNotify.Recipient_List[idx]; - if (CurrentNotify->Recipient_List[idx].Recipient. - RecipientType == RECIPIENT_TYPE_DEVICE) { + if (CurrentNotify->Recipient_List[idx] + .Recipient.RecipientType == RECIPIENT_TYPE_DEVICE) { /* copy Device_ID */ - DeviceID = - CurrentNotify->Recipient_List[idx].Recipient._. - DeviceIdentifier; + DeviceID = CurrentNotify->Recipient_List[idx] + .Recipient._.DeviceIdentifier; address_bind_request(DeviceID, &max_apdu, &src); - } else if (CurrentNotify->Recipient_List[idx].Recipient. - RecipientType == RECIPIENT_TYPE_ADDRESS) { + } else if (CurrentNotify->Recipient_List[idx] + .Recipient.RecipientType == + RECIPIENT_TYPE_ADDRESS) { /* copy Address */ - /* src = CurrentNotify->Recipient_List[idx].Recipient._.Address; */ - /* address_bind_request(BACNET_MAX_INSTANCE, &max_apdu, &src); */ + /* src = + * CurrentNotify->Recipient_List[idx].Recipient._.Address; + */ + /* address_bind_request(BACNET_MAX_INSTANCE, &max_apdu, + * &src); */ } } @@ -774,10 +753,8 @@ bool Notification_Class_Write_Property( return status; } - -void Notification_Class_Get_Priorities( - uint32_t Object_Instance, - uint32_t * pPriorityArray) +void Notification_Class_Get_Priorities(uint32_t Object_Instance, + uint32_t *pPriorityArray) { NOTIFICATION_CLASS_INFO *CurrentNotify; uint32_t object_index; @@ -797,10 +774,8 @@ void Notification_Class_Get_Priorities( pPriorityArray[i] = CurrentNotify->Priority[i]; } - -static bool IsRecipientActive( - BACNET_DESTINATION * pBacDest, - uint8_t EventToState) +static bool IsRecipientActive(BACNET_DESTINATION *pBacDest, + uint8_t EventToState) { BACNET_DATE_TIME DateTime; @@ -824,7 +799,7 @@ static bool IsRecipientActive( break; default: - return false; /* shouldn't happen */ + return false; /* shouldn't happen */ } /* get actual date and time */ @@ -845,9 +820,8 @@ static bool IsRecipientActive( return true; } - void Notification_Class_common_reporting_function( - BACNET_EVENT_NOTIFICATION_DATA * event_data) + BACNET_EVENT_NOTIFICATION_DATA *event_data) { /* Fill the parameters common for all types of events. */ @@ -856,7 +830,6 @@ void Notification_Class_common_reporting_function( uint32_t notify_index; uint8_t index; - notify_index = Notification_Class_Instance_To_Index(event_data->notificationClass); @@ -865,7 +838,6 @@ void Notification_Class_common_reporting_function( else return; - /* Initiating Device Identifier */ event_data->initiatingObjectIdentifier.type = OBJECT_DEVICE; event_data->initiatingObjectIdentifier.instance = @@ -877,16 +849,17 @@ void Notification_Class_common_reporting_function( event_data->priority = CurrentNotify->Priority[TRANSITION_TO_NORMAL]; event_data->ackRequired = - (CurrentNotify-> - Ack_Required & TRANSITION_TO_NORMAL_MASKED) ? true : false; + (CurrentNotify->Ack_Required & TRANSITION_TO_NORMAL_MASKED) + ? true + : false; break; case EVENT_STATE_FAULT: - event_data->priority = - CurrentNotify->Priority[TRANSITION_TO_FAULT]; + event_data->priority = CurrentNotify->Priority[TRANSITION_TO_FAULT]; event_data->ackRequired = - (CurrentNotify-> - Ack_Required & TRANSITION_TO_FAULT_MASKED) ? true : false; + (CurrentNotify->Ack_Required & TRANSITION_TO_FAULT_MASKED) + ? true + : false; break; case EVENT_STATE_OFFNORMAL: @@ -896,10 +869,11 @@ void Notification_Class_common_reporting_function( CurrentNotify->Priority[TRANSITION_TO_OFFNORMAL]; event_data->ackRequired = (CurrentNotify->Ack_Required & TRANSITION_TO_OFFNORMAL_MASKED) - ? true : false; + ? true + : false; break; - default: /* shouldn't happen */ + default: /* shouldn't happen */ break; } @@ -909,7 +883,7 @@ void Notification_Class_common_reporting_function( for (index = 0; index < NC_MAX_RECIPIENTS; index++, pBacDest++) { /* check if recipient is defined */ if (pBacDest->Recipient.RecipientType == RECIPIENT_TYPE_NOTINITIALIZED) - break; /* recipient doesn't defined - end of list */ + break; /* recipient doesn't defined - end of list */ if (IsRecipientActive(pBacDest, event_data->toState) == true) { BACNET_ADDRESS dest; @@ -928,9 +902,9 @@ void Notification_Class_common_reporting_function( Send_CEvent_Notify(device_id, event_data); else if (address_get_by_device(device_id, &max_apdu, &dest)) Send_UEvent_Notify(Handler_Transmit_Buffer, event_data, - &dest); + &dest); } else if (pBacDest->Recipient.RecipientType == - RECIPIENT_TYPE_ADDRESS) { + RECIPIENT_TYPE_ADDRESS) { /* send notification to the address indicated */ if (pBacDest->ConfirmedNotify == true) { if (address_get_device_id(&dest, &device_id)) @@ -938,7 +912,7 @@ void Notification_Class_common_reporting_function( } else { dest = pBacDest->Recipient._.Address; Send_UEvent_Notify(Handler_Transmit_Buffer, event_data, - &dest); + &dest); } } } @@ -947,20 +921,18 @@ void Notification_Class_common_reporting_function( /* This function tries to find the addresses of the defined devices. */ /* It should be called periodically (example once per minute). */ -void Notification_Class_find_recipient( - void) +void Notification_Class_find_recipient(void) { NOTIFICATION_CLASS_INFO *CurrentNotify; BACNET_DESTINATION *pBacDest; - BACNET_ADDRESS src = { 0 }; + BACNET_ADDRESS src = {0}; unsigned max_apdu = 0; uint32_t notify_index; uint32_t DeviceID; uint8_t idx; - for (notify_index = 0; notify_index < MAX_NOTIFICATION_CLASSES; - notify_index++) { + notify_index++) { /* pointer to current notification */ CurrentNotify = &NC_Info[Notification_Class_Instance_To_Index(notify_index)]; @@ -970,15 +942,14 @@ void Notification_Class_find_recipient( if (CurrentNotify->Recipient_List[idx].Recipient.RecipientType == RECIPIENT_TYPE_DEVICE) { /* Device ID */ - DeviceID = - CurrentNotify->Recipient_List[idx].Recipient._. - DeviceIdentifier; - /* Send who_ is request only when address of device is unknown. */ + DeviceID = CurrentNotify->Recipient_List[idx] + .Recipient._.DeviceIdentifier; + /* Send who_ is request only when address of device is unknown. + */ if (!address_bind_request(DeviceID, &max_apdu, &src)) Send_WhoIs(DeviceID, DeviceID); - } else if (CurrentNotify->Recipient_List[idx].Recipient. - RecipientType == RECIPIENT_TYPE_ADDRESS) { - + } else if (CurrentNotify->Recipient_List[idx] + .Recipient.RecipientType == RECIPIENT_TYPE_ADDRESS) { } } } diff --git a/demo/object/netport.c b/demo/object/netport.c index 7f60396f..b812ca22 100644 --- a/demo/object/netport.c +++ b/demo/object/netport.c @@ -93,8 +93,8 @@ struct object_data { uint32_t Instance_Number; char *Object_Name; uint8_t Reliability; - bool Out_Of_Service:1; - bool Changes_Pending:1; + bool Out_Of_Service : 1; + bool Changes_Pending : 1; uint8_t Network_Type; uint16_t Network_Number; uint8_t Quality; @@ -114,35 +114,20 @@ struct object_data Object_List[BACNET_NETWORK_PORTS_MAX]; /* These three arrays are used by the ReadPropertyMultiple handler */ static const int Network_Port_Properties_Required[] = { - PROP_OBJECT_IDENTIFIER, - PROP_OBJECT_NAME, - PROP_OBJECT_TYPE, - PROP_STATUS_FLAGS, - PROP_RELIABILITY, - PROP_OUT_OF_SERVICE, - PROP_NETWORK_TYPE, - PROP_PROTOCOL_LEVEL, - PROP_NETWORK_NUMBER, - PROP_NETWORK_NUMBER_QUALITY, - PROP_CHANGES_PENDING, - PROP_APDU_LENGTH, - PROP_LINK_SPEED, - -1 -}; + PROP_OBJECT_IDENTIFIER, PROP_OBJECT_NAME, + PROP_OBJECT_TYPE, PROP_STATUS_FLAGS, + PROP_RELIABILITY, PROP_OUT_OF_SERVICE, + PROP_NETWORK_TYPE, PROP_PROTOCOL_LEVEL, + PROP_NETWORK_NUMBER, PROP_NETWORK_NUMBER_QUALITY, + PROP_CHANGES_PENDING, PROP_APDU_LENGTH, + PROP_LINK_SPEED, -1}; static const int Ethernet_Port_Properties_Optional[] = { - PROP_MAC_ADDRESS, - PROP_MAX_APDU_LENGTH_ACCEPTED, - -1 -}; + PROP_MAC_ADDRESS, PROP_MAX_APDU_LENGTH_ACCEPTED, -1}; static const int MSTP_Port_Properties_Optional[] = { - PROP_MAC_ADDRESS, - PROP_MAX_APDU_LENGTH_ACCEPTED, - PROP_MAX_MASTER, - PROP_MAX_INFO_FRAMES, - -1 -}; + PROP_MAC_ADDRESS, PROP_MAX_APDU_LENGTH_ACCEPTED, PROP_MAX_MASTER, + PROP_MAX_INFO_FRAMES, -1}; static const int BIP_Port_Properties_Optional[] = { PROP_MAC_ADDRESS, @@ -158,8 +143,7 @@ static const int BIP_Port_Properties_Optional[] = { PROP_BBMD_BROADCAST_DISTRIBUTION_TABLE, PROP_BBMD_FOREIGN_DEVICE_TABLE, #endif - -1 -}; + -1}; static const int BIP6_Port_Properties_Optional[] = { PROP_MAC_ADDRESS, @@ -176,12 +160,9 @@ static const int BIP6_Port_Properties_Optional[] = { PROP_IPV6_DHCP_LEASE_TIME_REMAINING, PROP_IPV6_DHCP_SERVER, PROP_IPV6_ZONE_INDEX, - -1 -}; + -1}; -static const int Network_Port_Properties_Proprietary[] = { - -1 -}; +static const int Network_Port_Properties_Proprietary[] = {-1}; /** * Returns the list of required, optional, and proprietary properties. @@ -195,11 +176,8 @@ static const int Network_Port_Properties_Proprietary[] = { * @param pProprietary - pointer to list of int terminated by -1, of * BACnet proprietary properties for this object. */ -void Network_Port_Property_List( - uint32_t object_instance, - const int **pRequired, - const int **pOptional, - const int **pProprietary) +void Network_Port_Property_List(uint32_t object_instance, const int **pRequired, + const int **pOptional, const int **pProprietary) { unsigned index = 0; @@ -244,16 +222,11 @@ void Network_Port_Property_List( * @param pProprietary - pointer to list of int terminated by -1, of * BACnet proprietary properties for this object. */ -void Network_Port_Property_Lists( - const int **pRequired, - const int **pOptional, - const int **pProprietary) +void Network_Port_Property_Lists(const int **pRequired, const int **pOptional, + const int **pProprietary) { - Network_Port_Property_List( - Object_List[0].Instance_Number, - pRequired, - pOptional, - pProprietary); + Network_Port_Property_List(Object_List[0].Instance_Number, pRequired, + pOptional, pProprietary); } /** @@ -266,9 +239,8 @@ void Network_Port_Property_Lists( * * @return true if object-name was retrieved */ -bool Network_Port_Object_Name( - uint32_t object_instance, - BACNET_CHARACTER_STRING *object_name) +bool Network_Port_Object_Name(uint32_t object_instance, + BACNET_CHARACTER_STRING *object_name) { unsigned index = 0; /* offset from instance lookup */ bool status = false; @@ -276,7 +248,7 @@ bool Network_Port_Object_Name( index = Network_Port_Instance_To_Index(object_instance); if (index < BACNET_NETWORK_PORTS_MAX) { status = characterstring_init_ansi(object_name, - Object_List[index].Object_Name); + Object_List[index].Object_Name); } return status; @@ -292,9 +264,7 @@ bool Network_Port_Object_Name( * * @return true if object-name was set */ -bool Network_Port_Name_Set( - uint32_t object_instance, - char *new_name) +bool Network_Port_Name_Set(uint32_t object_instance, char *new_name) { unsigned index = 0; /* offset from instance lookup */ bool status = false; @@ -314,8 +284,7 @@ bool Network_Port_Name_Set( * * @return true if the instance is valid, and false if not */ -bool Network_Port_Valid_Instance( - uint32_t object_instance) +bool Network_Port_Valid_Instance(uint32_t object_instance) { unsigned index = 0; /* offset from instance lookup */ @@ -332,8 +301,7 @@ bool Network_Port_Valid_Instance( * * @return Number of Network Port objects */ -unsigned Network_Port_Count( - void) +unsigned Network_Port_Count(void) { return BACNET_NETWORK_PORTS_MAX; } @@ -347,8 +315,7 @@ unsigned Network_Port_Count( * @return object instance-number for the given index, or BACNET_MAX_INSTANCE * for an invalid index. */ -uint32_t Network_Port_Index_To_Instance( - unsigned index) +uint32_t Network_Port_Index_To_Instance(unsigned index) { if (index < BACNET_NETWORK_PORTS_MAX) { return Object_List[index].Instance_Number; @@ -366,8 +333,7 @@ uint32_t Network_Port_Index_To_Instance( * @return index for the given instance-number, or BACNET_NETWORK_PORTS_MAX * if not valid. */ -unsigned Network_Port_Instance_To_Index( - uint32_t object_instance) +unsigned Network_Port_Instance_To_Index(uint32_t object_instance) { unsigned index = 0; @@ -388,9 +354,8 @@ unsigned Network_Port_Instance_To_Index( * * @return true if values are within range and property is set. */ -bool Network_Port_Object_Instance_Number_Set( - unsigned index, - uint32_t object_instance) +bool Network_Port_Object_Instance_Number_Set(unsigned index, + uint32_t object_instance) { bool status = false; /* return value */ @@ -412,8 +377,7 @@ bool Network_Port_Object_Instance_Number_Set( * * @return out-of-service property value */ -bool Network_Port_Out_Of_Service( - uint32_t object_instance) +bool Network_Port_Out_Of_Service(uint32_t object_instance) { bool oos_flag = false; unsigned index = 0; @@ -434,9 +398,7 @@ bool Network_Port_Out_Of_Service( * * @return true if the out-of-service property value was set */ -bool Network_Port_Out_Of_Service_Set( - uint32_t object_instance, - bool value) +bool Network_Port_Out_Of_Service_Set(uint32_t object_instance, bool value) { bool status = false; unsigned index = 0; @@ -457,8 +419,7 @@ bool Network_Port_Out_Of_Service_Set( * * @return reliability value */ -BACNET_RELIABILITY Network_Port_Reliability( - uint32_t object_instance) +BACNET_RELIABILITY Network_Port_Reliability(uint32_t object_instance) { BACNET_RELIABILITY reliability = RELIABILITY_NO_FAULT_DETECTED; unsigned index = 0; @@ -479,9 +440,8 @@ BACNET_RELIABILITY Network_Port_Reliability( * * @return true if values are within range and property is set. */ -bool Network_Port_Reliability_Set( - uint32_t object_instance, - BACNET_RELIABILITY value) +bool Network_Port_Reliability_Set(uint32_t object_instance, + BACNET_RELIABILITY value) { bool status = false; unsigned index = 0; @@ -502,8 +462,7 @@ bool Network_Port_Reliability_Set( * * @return BACnet network type value */ -uint8_t Network_Port_Type( - uint32_t object_instance) +uint8_t Network_Port_Type(uint32_t object_instance) { uint8_t port_type = PORT_TYPE_NON_BACNET; unsigned index = 0; @@ -526,9 +485,7 @@ uint8_t Network_Port_Type( * * @return true if values are within range and property is set. */ -bool Network_Port_Type_Set( - uint32_t object_instance, - uint8_t value) +bool Network_Port_Type_Set(uint32_t object_instance, uint8_t value) { bool status = false; unsigned index = 0; @@ -549,8 +506,7 @@ bool Network_Port_Type_Set( * * @return BACnet network type value */ -uint16_t Network_Port_Network_Number( - uint32_t object_instance) +uint16_t Network_Port_Network_Number(uint32_t object_instance) { uint16_t network_number = 0; unsigned index = 0; @@ -571,9 +527,7 @@ uint16_t Network_Port_Network_Number( * * @return true if values are within range and property is set. */ -bool Network_Port_Network_Number_Set( - uint32_t object_instance, - uint16_t value) +bool Network_Port_Network_Number_Set(uint32_t object_instance, uint16_t value) { bool status = false; unsigned index = 0; @@ -594,8 +548,7 @@ bool Network_Port_Network_Number_Set( * * @return quality property value */ -BACNET_PORT_QUALITY Network_Port_Quality( - uint32_t object_instance) +BACNET_PORT_QUALITY Network_Port_Quality(uint32_t object_instance) { BACNET_PORT_QUALITY value = PORT_QUALITY_UNKNOWN; unsigned index = 0; @@ -616,9 +569,8 @@ BACNET_PORT_QUALITY Network_Port_Quality( * * @return true if values are within range and property is set. */ -bool Network_Port_Quality_Set( - uint32_t object_instance, - BACNET_PORT_QUALITY value) +bool Network_Port_Quality_Set(uint32_t object_instance, + BACNET_PORT_QUALITY value) { bool status = false; unsigned index = 0; @@ -642,14 +594,13 @@ bool Network_Port_Quality_Set( * * @return true if mac-address was retrieved */ -bool Network_Port_MAC_Address( - uint32_t object_instance, - BACNET_OCTET_STRING *mac_address) +bool Network_Port_MAC_Address(uint32_t object_instance, + BACNET_OCTET_STRING *mac_address) { unsigned index = 0; /* offset from instance lookup */ bool status = false; uint8_t *mac = NULL; - uint8_t ip_mac[4+2] = {0}; + uint8_t ip_mac[4 + 2] = {0}; size_t mac_len = 0; index = Network_Port_Instance_To_Index(object_instance); @@ -657,17 +608,17 @@ bool Network_Port_MAC_Address( switch (Object_List[index].Network_Type) { case PORT_TYPE_ETHERNET: mac = &Object_List[index].Network.Ethernet.MAC_Address[0]; - mac_len = sizeof(Object_List[index].Network.Ethernet.MAC_Address); + mac_len = + sizeof(Object_List[index].Network.Ethernet.MAC_Address); break; case PORT_TYPE_MSTP: mac = &Object_List[index].Network.MSTP.MAC_Address; mac_len = sizeof(Object_List[index].Network.MSTP.MAC_Address); break; case PORT_TYPE_BIP: - memcpy(&ip_mac[0], - &Object_List[index].Network.IPv4.IP_Address, 4); - memcpy(&ip_mac[4], - &Object_List[index].Network.IPv4.Port, 2); + memcpy(&ip_mac[0], &Object_List[index].Network.IPv4.IP_Address, + 4); + memcpy(&ip_mac[4], &Object_List[index].Network.IPv4.Port, 2); mac = &ip_mac[0]; mac_len = sizeof(ip_mac); break; @@ -696,10 +647,8 @@ bool Network_Port_MAC_Address( * * @return true if object-name was set */ -bool Network_Port_MAC_Address_Set( - uint32_t object_instance, - uint8_t *mac_src, - uint8_t mac_len) +bool Network_Port_MAC_Address_Set(uint32_t object_instance, uint8_t *mac_src, + uint8_t mac_len) { unsigned index = 0; /* offset from instance lookup */ bool status = false; @@ -711,7 +660,8 @@ bool Network_Port_MAC_Address_Set( switch (Object_List[index].Network_Type) { case PORT_TYPE_ETHERNET: mac_dest = &Object_List[index].Network.Ethernet.MAC_Address[0]; - mac_size = sizeof(Object_List[index].Network.Ethernet.MAC_Address); + mac_size = + sizeof(Object_List[index].Network.Ethernet.MAC_Address); break; case PORT_TYPE_MSTP: mac_dest = &Object_List[index].Network.MSTP.MAC_Address; @@ -743,8 +693,7 @@ bool Network_Port_MAC_Address_Set( * * @return APDU length for this network port */ -uint16_t Network_Port_APDU_Length( - uint32_t object_instance) +uint16_t Network_Port_APDU_Length(uint32_t object_instance) { uint16_t value = 0; unsigned index = 0; @@ -765,9 +714,7 @@ uint16_t Network_Port_APDU_Length( * * @return true if values are within range and property is set. */ -bool Network_Port_APDU_Length_Set( - uint32_t object_instance, - uint16_t value) +bool Network_Port_APDU_Length_Set(uint32_t object_instance, uint16_t value) { bool status = false; unsigned index = 0; @@ -790,8 +737,7 @@ bool Network_Port_APDU_Length_Set( * * @return Link_Speed for this network port, or 0 if unknown */ -float Network_Port_Link_Speed( - uint32_t object_instance) +float Network_Port_Link_Speed(uint32_t object_instance) { float value = 0.0; unsigned index = 0; @@ -812,9 +758,7 @@ float Network_Port_Link_Speed( * * @return true if values are within range and property is set. */ -bool Network_Port_Link_Speed_Set( - uint32_t object_instance, - float value) +bool Network_Port_Link_Speed_Set(uint32_t object_instance, float value) { bool status = false; unsigned index = 0; @@ -836,8 +780,7 @@ bool Network_Port_Link_Speed_Set( * * @return changes-pending property value */ -bool Network_Port_Changes_Pending( - uint32_t object_instance) +bool Network_Port_Changes_Pending(uint32_t object_instance) { bool flag = false; unsigned index = 0; @@ -858,9 +801,7 @@ bool Network_Port_Changes_Pending( * * @return true if the changes-pending property value was set */ -bool Network_Port_Changes_Pending_Set( - uint32_t object_instance, - bool value) +bool Network_Port_Changes_Pending_Set(uint32_t object_instance, bool value) { bool status = false; unsigned index = 0; @@ -882,8 +823,7 @@ bool Network_Port_Changes_Pending_Set( * * @return MS/TP Max_Master value */ -uint8_t Network_Port_MSTP_Max_Master( - uint32_t object_instance) +uint8_t Network_Port_MSTP_Max_Master(uint32_t object_instance) { uint8_t value = 0; unsigned index = 0; @@ -907,9 +847,7 @@ uint8_t Network_Port_MSTP_Max_Master( * * @return true if values are within range and property is set. */ -bool Network_Port_MSTP_Max_Master_Set( - uint32_t object_instance, - uint8_t value) +bool Network_Port_MSTP_Max_Master_Set(uint32_t object_instance, uint8_t value) { bool status = false; unsigned index = 0; @@ -940,9 +878,8 @@ bool Network_Port_MSTP_Max_Master_Set( * * @return true if ip-address was retrieved */ -bool Network_Port_IP_Address( - uint32_t object_instance, - BACNET_OCTET_STRING *ip_address) +bool Network_Port_IP_Address(uint32_t object_instance, + BACNET_OCTET_STRING *ip_address) { unsigned index = 0; /* offset from instance lookup */ bool status = false; @@ -950,8 +887,8 @@ bool Network_Port_IP_Address( index = Network_Port_Instance_To_Index(object_instance); if (index < BACNET_NETWORK_PORTS_MAX) { if (Object_List[index].Network_Type == PORT_TYPE_BIP) { - status = octetstring_init(ip_address, - &Object_List[index].Network.IPv4.IP_Address[0], 4); + status = octetstring_init( + ip_address, &Object_List[index].Network.IPv4.IP_Address[0], 4); } } @@ -970,9 +907,8 @@ bool Network_Port_IP_Address( * * @return true if ip-address was set */ -bool Network_Port_IP_Address_Set( - uint32_t object_instance, - uint8_t a, uint8_t b, uint8_t c, uint8_t d) +bool Network_Port_IP_Address_Set(uint32_t object_instance, uint8_t a, uint8_t b, + uint8_t c, uint8_t d) { unsigned index = 0; /* offset from instance lookup */ bool status = false; @@ -1000,9 +936,8 @@ bool Network_Port_IP_Address_Set( * * @return true if ip-address was retrieved */ -bool Network_Port_IP_Subnet( - uint32_t object_instance, - BACNET_OCTET_STRING *subnet_mask) +bool Network_Port_IP_Subnet(uint32_t object_instance, + BACNET_OCTET_STRING *subnet_mask) { unsigned index = 0; /* offset from instance lookup */ bool status = false; @@ -1031,8 +966,7 @@ bool Network_Port_IP_Subnet( * * @return BACnet/IP subnet prefix value */ -uint8_t Network_Port_IP_Subnet_Prefix( - uint32_t object_instance) +uint8_t Network_Port_IP_Subnet_Prefix(uint32_t object_instance) { uint8_t value = 0; unsigned index = 0; @@ -1056,9 +990,7 @@ uint8_t Network_Port_IP_Subnet_Prefix( * * @return true if values are within range and property is set. */ -bool Network_Port_IP_Subnet_Prefix_Set( - uint32_t object_instance, - uint8_t value) +bool Network_Port_IP_Subnet_Prefix_Set(uint32_t object_instance, uint8_t value) { bool status = false; unsigned index = 0; @@ -1089,9 +1021,8 @@ bool Network_Port_IP_Subnet_Prefix_Set( * * @return true if ip-address was retrieved */ -bool Network_Port_IP_Gateway( - uint32_t object_instance, - BACNET_OCTET_STRING *ip_address) +bool Network_Port_IP_Gateway(uint32_t object_instance, + BACNET_OCTET_STRING *ip_address) { unsigned index = 0; /* offset from instance lookup */ bool status = false; @@ -1099,8 +1030,8 @@ bool Network_Port_IP_Gateway( index = Network_Port_Instance_To_Index(object_instance); if (index < BACNET_NETWORK_PORTS_MAX) { if (Object_List[index].Network_Type == PORT_TYPE_BIP) { - status = octetstring_init(ip_address, - &Object_List[index].Network.IPv4.IP_Gateway[0], 4); + status = octetstring_init( + ip_address, &Object_List[index].Network.IPv4.IP_Gateway[0], 4); } } @@ -1119,9 +1050,8 @@ bool Network_Port_IP_Gateway( * * @return true if ip-address was set */ -bool Network_Port_IP_Gateway_Set( - uint32_t object_instance, - uint8_t a, uint8_t b, uint8_t c, uint8_t d) +bool Network_Port_IP_Gateway_Set(uint32_t object_instance, uint8_t a, uint8_t b, + uint8_t c, uint8_t d) { unsigned index = 0; /* offset from instance lookup */ bool status = false; @@ -1150,10 +1080,8 @@ bool Network_Port_IP_Gateway_Set( * * @return true if ip-address was retrieved */ -bool Network_Port_IP_DNS_Server( - uint32_t object_instance, - unsigned dns_index, - BACNET_OCTET_STRING *ip_address) +bool Network_Port_IP_DNS_Server(uint32_t object_instance, unsigned dns_index, + BACNET_OCTET_STRING *ip_address) { unsigned index = 0; /* offset from instance lookup */ bool status = false; @@ -1162,8 +1090,10 @@ bool Network_Port_IP_DNS_Server( if (index < BACNET_NETWORK_PORTS_MAX) { if (Object_List[index].Network_Type == PORT_TYPE_BIP) { if (dns_index < BIP_DNS_MAX) { - status = octetstring_init(ip_address, - &Object_List[index].Network.IPv4.IP_DNS_Server[dns_index][0], + status = octetstring_init( + ip_address, + &Object_List[index] + .Network.IPv4.IP_DNS_Server[dns_index][0], 4); } } @@ -1185,10 +1115,9 @@ bool Network_Port_IP_DNS_Server( * * @return true if ip-address was set */ -bool Network_Port_IP_DNS_Server_Set( - uint32_t object_instance, - unsigned dns_index, - uint8_t a, uint8_t b, uint8_t c, uint8_t d) +bool Network_Port_IP_DNS_Server_Set(uint32_t object_instance, + unsigned dns_index, uint8_t a, uint8_t b, + uint8_t c, uint8_t d) { unsigned index = 0; /* offset from instance lookup */ bool status = false; @@ -1216,8 +1145,7 @@ bool Network_Port_IP_DNS_Server_Set( * * @return BACnet/IP UDP Port number */ -uint16_t Network_Port_BIP_Port( - uint32_t object_instance) +uint16_t Network_Port_BIP_Port(uint32_t object_instance) { uint16_t value = 0; unsigned index = 0; @@ -1241,9 +1169,7 @@ uint16_t Network_Port_BIP_Port( * * @return true if values are within range and property is set. */ -bool Network_Port_BIP_Port_Set( - uint32_t object_instance, - uint16_t value) +bool Network_Port_BIP_Port_Set(uint32_t object_instance, uint16_t value) { bool status = false; unsigned index = 0; @@ -1270,8 +1196,7 @@ bool Network_Port_BIP_Port_Set( * * @return BACnet/IP UDP Port number */ -BACNET_IP_MODE Network_Port_BIP_Mode( - uint32_t object_instance) +BACNET_IP_MODE Network_Port_BIP_Mode(uint32_t object_instance) { BACNET_IP_MODE value = 0; unsigned index = 0; @@ -1295,9 +1220,7 @@ BACNET_IP_MODE Network_Port_BIP_Mode( * * @return true if values are within range and property is set. */ -bool Network_Port_BIP_Mode_Set( - uint32_t object_instance, - BACNET_IP_MODE value) +bool Network_Port_BIP_Mode_Set(uint32_t object_instance, BACNET_IP_MODE value) { bool status = false; unsigned index = 0; @@ -1326,8 +1249,7 @@ bool Network_Port_BIP_Mode_Set( * * @return BBMD-Accept-FD-Registrations property value */ -bool Network_Port_BBMD_Accept_FD_Registrations( - uint32_t object_instance) +bool Network_Port_BBMD_Accept_FD_Registrations(uint32_t object_instance) { bool flag = false; unsigned index = 0; @@ -1351,9 +1273,8 @@ bool Network_Port_BBMD_Accept_FD_Registrations( * * @return true if the BBMD-Accept-FD-Registrations property value was set */ -bool Network_Port_BBMD_Accept_FD_Registrations_Set( - uint32_t object_instance, - bool flag) +bool Network_Port_BBMD_Accept_FD_Registrations_Set(uint32_t object_instance, + bool flag) { bool status = false; unsigned index = 0; @@ -1380,8 +1301,7 @@ bool Network_Port_BBMD_Accept_FD_Registrations_Set( * * @return BACnet/IP UDP Port number */ -BACNET_IP_MODE Network_Port_BIP6_Mode( - uint32_t object_instance) +BACNET_IP_MODE Network_Port_BIP6_Mode(uint32_t object_instance) { BACNET_IP_MODE value = 0; unsigned index = 0; @@ -1405,9 +1325,7 @@ BACNET_IP_MODE Network_Port_BIP6_Mode( * * @return true if values are within range and property is set. */ -bool Network_Port_BIP6_Mode_Set( - uint32_t object_instance, - BACNET_IP_MODE value) +bool Network_Port_BIP6_Mode_Set(uint32_t object_instance, BACNET_IP_MODE value) { bool status = false; unsigned index = 0; @@ -1438,9 +1356,8 @@ bool Network_Port_BIP6_Mode_Set( * * @return true if ip-address was retrieved */ -bool Network_Port_IPv6_Address( - uint32_t object_instance, - BACNET_OCTET_STRING *ip_address) +bool Network_Port_IPv6_Address(uint32_t object_instance, + BACNET_OCTET_STRING *ip_address) { unsigned index = 0; /* offset from instance lookup */ bool status = false; @@ -1448,8 +1365,9 @@ bool Network_Port_IPv6_Address( index = Network_Port_Instance_To_Index(object_instance); if (index < BACNET_NETWORK_PORTS_MAX) { if (Object_List[index].Network_Type == PORT_TYPE_BIP6) { - status = octetstring_init(ip_address, - &Object_List[index].Network.IPv6.IP_Address[0], IPV6_ADDR_SIZE); + status = octetstring_init( + ip_address, &Object_List[index].Network.IPv6.IP_Address[0], + IPV6_ADDR_SIZE); } } @@ -1465,9 +1383,8 @@ bool Network_Port_IPv6_Address( * * @return true if ip-address was set */ -bool Network_Port_IPv6_Address_Set( - uint32_t object_instance, - uint8_t *ip_address) +bool Network_Port_IPv6_Address_Set(uint32_t object_instance, + uint8_t *ip_address) { unsigned index = 0; /* offset from instance lookup */ bool status = false; @@ -1494,8 +1411,7 @@ bool Network_Port_IPv6_Address_Set( * * @return BACnet/IP subnet prefix value */ -uint8_t Network_Port_IPv6_Subnet_Prefix( - uint32_t object_instance) +uint8_t Network_Port_IPv6_Subnet_Prefix(uint32_t object_instance) { uint8_t value = 0; unsigned index = 0; @@ -1519,9 +1435,8 @@ uint8_t Network_Port_IPv6_Subnet_Prefix( * * @return true if values are within range and property is set. */ -bool Network_Port_IPv6_Subnet_Prefix_Set( - uint32_t object_instance, - uint8_t value) +bool Network_Port_IPv6_Subnet_Prefix_Set(uint32_t object_instance, + uint8_t value) { bool status = false; unsigned index = 0; @@ -1552,9 +1467,8 @@ bool Network_Port_IPv6_Subnet_Prefix_Set( * * @return true if ip-address was retrieved */ -bool Network_Port_IPv6_Gateway( - uint32_t object_instance, - BACNET_OCTET_STRING *ip_address) +bool Network_Port_IPv6_Gateway(uint32_t object_instance, + BACNET_OCTET_STRING *ip_address) { unsigned index = 0; /* offset from instance lookup */ bool status = false; @@ -1562,8 +1476,9 @@ bool Network_Port_IPv6_Gateway( index = Network_Port_Instance_To_Index(object_instance); if (index < BACNET_NETWORK_PORTS_MAX) { if (Object_List[index].Network_Type == PORT_TYPE_BIP6) { - status = octetstring_init(ip_address, - &Object_List[index].Network.IPv6.IP_Gateway[0], IPV6_ADDR_SIZE); + status = octetstring_init( + ip_address, &Object_List[index].Network.IPv6.IP_Gateway[0], + IPV6_ADDR_SIZE); } } @@ -1579,9 +1494,8 @@ bool Network_Port_IPv6_Gateway( * * @return true if ip-address was set */ -bool Network_Port_IPv6_Gateway_Set( - uint32_t object_instance, - uint8_t *ip_address) +bool Network_Port_IPv6_Gateway_Set(uint32_t object_instance, + uint8_t *ip_address) { unsigned index = 0; /* offset from instance lookup */ bool status = false; @@ -1592,8 +1506,7 @@ bool Network_Port_IPv6_Gateway_Set( if ((Object_List[index].Network_Type == PORT_TYPE_BIP6) && (ip_address)) { for (i = 0; i < IPV6_ADDR_SIZE; i++) { - Object_List[index].Network.IPv6.IP_Gateway[i] = - ip_address[i]; + Object_List[index].Network.IPv6.IP_Gateway[i] = ip_address[i]; } } } @@ -1612,10 +1525,8 @@ bool Network_Port_IPv6_Gateway_Set( * * @return true if ip-address was retrieved */ -bool Network_Port_IPv6_DNS_Server( - uint32_t object_instance, - unsigned dns_index, - BACNET_OCTET_STRING *ip_address) +bool Network_Port_IPv6_DNS_Server(uint32_t object_instance, unsigned dns_index, + BACNET_OCTET_STRING *ip_address) { unsigned index = 0; /* offset from instance lookup */ bool status = false; @@ -1624,9 +1535,10 @@ bool Network_Port_IPv6_DNS_Server( if (index < BACNET_NETWORK_PORTS_MAX) { if (Object_List[index].Network_Type == PORT_TYPE_BIP6) { if (dns_index < BIP_DNS_MAX) { - status = octetstring_init(ip_address, - &Object_List[index].Network.IPv6.IP_DNS_Server[ - dns_index][0], + status = octetstring_init( + ip_address, + &Object_List[index] + .Network.IPv6.IP_DNS_Server[dns_index][0], IPV6_ADDR_SIZE); } } @@ -1645,10 +1557,8 @@ bool Network_Port_IPv6_DNS_Server( * * @return true if ip-address was set */ -bool Network_Port_IPv6_DNS_Server_Set( - uint32_t object_instance, - unsigned dns_index, - uint8_t *ip_address) +bool Network_Port_IPv6_DNS_Server_Set(uint32_t object_instance, + unsigned dns_index, uint8_t *ip_address) { unsigned index = 0; /* offset from instance lookup */ bool status = false; @@ -1678,9 +1588,8 @@ bool Network_Port_IPv6_DNS_Server_Set( * * @return true if ip-address was retrieved */ -bool Network_Port_IPv6_Multicast_Address( - uint32_t object_instance, - BACNET_OCTET_STRING *ip_address) +bool Network_Port_IPv6_Multicast_Address(uint32_t object_instance, + BACNET_OCTET_STRING *ip_address) { unsigned index = 0; /* offset from instance lookup */ bool status = false; @@ -1688,7 +1597,8 @@ bool Network_Port_IPv6_Multicast_Address( index = Network_Port_Instance_To_Index(object_instance); if (index < BACNET_NETWORK_PORTS_MAX) { if (Object_List[index].Network_Type == PORT_TYPE_BIP6) { - status = octetstring_init(ip_address, + status = octetstring_init( + ip_address, &Object_List[index].Network.IPv6.IP_Multicast_Address[0], IPV6_ADDR_SIZE); } @@ -1706,9 +1616,8 @@ bool Network_Port_IPv6_Multicast_Address( * * @return true if ip-address was set */ -bool Network_Port_IPv6_Multicast_Address_Set( - uint32_t object_instance, - uint8_t *ip_address) +bool Network_Port_IPv6_Multicast_Address_Set(uint32_t object_instance, + uint8_t *ip_address) { unsigned index = 0; /* offset from instance lookup */ bool status = false; @@ -1738,9 +1647,8 @@ bool Network_Port_IPv6_Multicast_Address_Set( * * @return true if ip-address was retrieved */ -bool Network_Port_IPv6_DHCP_Server( - uint32_t object_instance, - BACNET_OCTET_STRING *ip_address) +bool Network_Port_IPv6_DHCP_Server(uint32_t object_instance, + BACNET_OCTET_STRING *ip_address) { unsigned index = 0; /* offset from instance lookup */ bool status = false; @@ -1748,8 +1656,8 @@ bool Network_Port_IPv6_DHCP_Server( index = Network_Port_Instance_To_Index(object_instance); if (index < BACNET_NETWORK_PORTS_MAX) { if (Object_List[index].Network_Type == PORT_TYPE_BIP6) { - status = octetstring_init(ip_address, - &Object_List[index].Network.IPv6.IP_DHCP_Server[0], + status = octetstring_init( + ip_address, &Object_List[index].Network.IPv6.IP_DHCP_Server[0], IPV6_ADDR_SIZE); } } @@ -1766,9 +1674,8 @@ bool Network_Port_IPv6_DHCP_Server( * * @return true if ip-address was set */ -bool Network_Port_IPv6_DHCP_Server_Set( - uint32_t object_instance, - uint8_t *ip_address) +bool Network_Port_IPv6_DHCP_Server_Set(uint32_t object_instance, + uint8_t *ip_address) { unsigned index = 0; /* offset from instance lookup */ bool status = false; @@ -1796,8 +1703,7 @@ bool Network_Port_IPv6_DHCP_Server_Set( * * @return BACnet/IP UDP Port number */ -uint16_t Network_Port_BIP6_Port( - uint32_t object_instance) +uint16_t Network_Port_BIP6_Port(uint32_t object_instance) { uint16_t value = 0; unsigned index = 0; @@ -1821,9 +1727,7 @@ uint16_t Network_Port_BIP6_Port( * * @return true if values are within range and property is set. */ -bool Network_Port_BIP6_Port_Set( - uint32_t object_instance, - uint16_t value) +bool Network_Port_BIP6_Port_Set(uint32_t object_instance, uint16_t value) { bool status = false; unsigned index = 0; @@ -1852,9 +1756,8 @@ bool Network_Port_BIP6_Port_Set( * * @return true if zone_index was retrieved */ -bool Network_Port_IPv6_Zone_Index( - uint32_t object_instance, - BACNET_CHARACTER_STRING *zone_index) +bool Network_Port_IPv6_Zone_Index(uint32_t object_instance, + BACNET_CHARACTER_STRING *zone_index) { unsigned index = 0; /* offset from instance lookup */ bool status = false; @@ -1862,8 +1765,8 @@ bool Network_Port_IPv6_Zone_Index( index = Network_Port_Instance_To_Index(object_instance); if (index < BACNET_NETWORK_PORTS_MAX) { if (Object_List[index].Network_Type == PORT_TYPE_BIP6) { - status = characterstring_init_ansi(zone_index, - &Object_List[index].Network.IPv6.Zone_Index[0]); + status = characterstring_init_ansi( + zone_index, &Object_List[index].Network.IPv6.Zone_Index[0]); } } @@ -1879,9 +1782,8 @@ bool Network_Port_IPv6_Zone_Index( * * @return true if ip-address was set */ -bool Network_Port_IPv6_Gateway_Zone_Index_Set( - uint32_t object_instance, - char *zone_index) +bool Network_Port_IPv6_Gateway_Zone_Index_Set(uint32_t object_instance, + char *zone_index) { unsigned index = 0; /* offset from instance lookup */ bool status = false; @@ -1891,7 +1793,7 @@ bool Network_Port_IPv6_Gateway_Zone_Index_Set( if ((Object_List[index].Network_Type == PORT_TYPE_BIP6) && (zone_index)) { snprintf(&Object_List[index].Network.IPv6.Zone_Index[0], - ZONE_INDEX_SIZE, "%s", zone_index); + ZONE_INDEX_SIZE, "%s", zone_index); } } @@ -1906,8 +1808,7 @@ bool Network_Port_IPv6_Gateway_Zone_Index_Set( * * @return MS/TP Max_Info_Frames value */ -uint8_t Network_Port_MSTP_Max_Info_Frames( - uint32_t object_instance) +uint8_t Network_Port_MSTP_Max_Info_Frames(uint32_t object_instance) { uint8_t value = 0; unsigned index = 0; @@ -1931,9 +1832,8 @@ uint8_t Network_Port_MSTP_Max_Info_Frames( * * @return true if values are within range and property is set. */ -bool Network_Port_MSTP_Max_Info_Frames_Set( - uint32_t object_instance, - uint8_t value) +bool Network_Port_MSTP_Max_Info_Frames_Set(uint32_t object_instance, + uint8_t value) { bool status = false; unsigned index = 0; @@ -1962,8 +1862,7 @@ bool Network_Port_MSTP_Max_Info_Frames_Set( * @return number of APDU bytes in the response, or * BACNET_STATUS_ERROR on error. */ -int Network_Port_Read_Property( - BACNET_READ_PROPERTY_DATA *rpdata) +int Network_Port_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata) { int apdu_len = 0; BACNET_BIT_STRING bit_string; @@ -1971,28 +1870,27 @@ int Network_Port_Read_Property( 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; } if ((Network_Port_Type(rpdata->object_instance) != PORT_TYPE_MSTP) && property_list_member(MSTP_Port_Properties_Optional, - rpdata->object_property)) { + rpdata->object_property)) { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_UNKNOWN_PROPERTY; return BACNET_STATUS_ERROR; } if ((Network_Port_Type(rpdata->object_instance) != PORT_TYPE_BIP) && property_list_member(BIP_Port_Properties_Optional, - rpdata->object_property)) { + rpdata->object_property)) { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_UNKNOWN_PROPERTY; return BACNET_STATUS_ERROR; } if ((Network_Port_Type(rpdata->object_instance) != PORT_TYPE_BIP6) && property_list_member(BIP6_Port_Properties_Optional, - rpdata->object_property)) { + rpdata->object_property)) { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_UNKNOWN_PROPERTY; return BACNET_STATUS_ERROR; @@ -2000,16 +1898,17 @@ int Network_Port_Read_Property( apdu = rpdata->application_data; switch (rpdata->object_property) { case PROP_OBJECT_IDENTIFIER: - apdu_len = - encode_application_object_id(&apdu[0], OBJECT_NETWORK_PORT, - rpdata->object_instance); + apdu_len = encode_application_object_id( + &apdu[0], OBJECT_NETWORK_PORT, rpdata->object_instance); break; case PROP_OBJECT_NAME: Network_Port_Object_Name(rpdata->object_instance, &char_string); - apdu_len = encode_application_character_string(&apdu[0], &char_string); + apdu_len = + encode_application_character_string(&apdu[0], &char_string); break; case PROP_OBJECT_TYPE: - apdu_len = encode_application_enumerated(&apdu[0], OBJECT_NETWORK_PORT); + apdu_len = + encode_application_enumerated(&apdu[0], OBJECT_NETWORK_PORT); break; case PROP_STATUS_FLAGS: bitstring_init(&bit_string); @@ -2023,76 +1922,79 @@ int Network_Port_Read_Property( bitstring_set_bit(&bit_string, STATUS_FLAG_OVERRIDDEN, false); if (Network_Port_Out_Of_Service(rpdata->object_instance)) { bitstring_set_bit(&bit_string, STATUS_FLAG_OUT_OF_SERVICE, - true); + true); } else { bitstring_set_bit(&bit_string, STATUS_FLAG_OUT_OF_SERVICE, - false); + false); } apdu_len = encode_application_bitstring(&apdu[0], &bit_string); break; case PROP_RELIABILITY: - apdu_len = encode_application_enumerated(&apdu[0], - Network_Port_Reliability(rpdata->object_instance)); + apdu_len = encode_application_enumerated( + &apdu[0], Network_Port_Reliability(rpdata->object_instance)); break; case PROP_OUT_OF_SERVICE: - apdu_len = encode_application_boolean(&apdu[0], - Network_Port_Out_Of_Service(rpdata->object_instance)); + apdu_len = encode_application_boolean( + &apdu[0], Network_Port_Out_Of_Service(rpdata->object_instance)); break; case PROP_NETWORK_TYPE: - apdu_len = encode_application_enumerated(&apdu[0], - Network_Port_Type(rpdata->object_instance)); + apdu_len = encode_application_enumerated( + &apdu[0], Network_Port_Type(rpdata->object_instance)); break; case PROP_PROTOCOL_LEVEL: - apdu_len = encode_application_enumerated(&apdu[0], - BACNET_PROTOCOL_LEVEL_BACNET_APPLICATION); + apdu_len = encode_application_enumerated( + &apdu[0], BACNET_PROTOCOL_LEVEL_BACNET_APPLICATION); break; case PROP_NETWORK_NUMBER: - apdu_len = encode_application_unsigned(&apdu[0], - Network_Port_Network_Number(rpdata->object_instance)); + apdu_len = encode_application_unsigned( + &apdu[0], Network_Port_Network_Number(rpdata->object_instance)); break; case PROP_NETWORK_NUMBER_QUALITY: - apdu_len = encode_application_enumerated(&apdu[0], - Network_Port_Quality(rpdata->object_instance)); + apdu_len = encode_application_enumerated( + &apdu[0], Network_Port_Quality(rpdata->object_instance)); break; case PROP_MAC_ADDRESS: Network_Port_MAC_Address(rpdata->object_instance, &octet_string); apdu_len = encode_application_octet_string(&apdu[0], &octet_string); break; case PROP_MAX_APDU_LENGTH_ACCEPTED: - apdu_len = encode_application_unsigned(&apdu[0], - Network_Port_APDU_Length(rpdata->object_instance)); + apdu_len = encode_application_unsigned( + &apdu[0], Network_Port_APDU_Length(rpdata->object_instance)); break; case PROP_LINK_SPEED: - apdu_len = encode_application_real(&apdu[0], - Network_Port_Link_Speed(rpdata->object_instance)); + apdu_len = encode_application_real( + &apdu[0], Network_Port_Link_Speed(rpdata->object_instance)); break; case PROP_CHANGES_PENDING: - apdu_len = encode_application_boolean(&apdu[0], + apdu_len = encode_application_boolean( + &apdu[0], Network_Port_Changes_Pending(rpdata->object_instance)); break; case PROP_APDU_LENGTH: - apdu_len = encode_application_unsigned(&apdu[0], - Network_Port_APDU_Length(rpdata->object_instance)); + apdu_len = encode_application_unsigned( + &apdu[0], Network_Port_APDU_Length(rpdata->object_instance)); break; case PROP_MAX_MASTER: - apdu_len = encode_application_unsigned(&apdu[0], + apdu_len = encode_application_unsigned( + &apdu[0], Network_Port_MSTP_Max_Master(rpdata->object_instance)); break; case PROP_MAX_INFO_FRAMES: - apdu_len = encode_application_unsigned(&apdu[0], + apdu_len = encode_application_unsigned( + &apdu[0], Network_Port_MSTP_Max_Info_Frames(rpdata->object_instance)); break; case PROP_BACNET_IP_MODE: - apdu_len = encode_application_enumerated(&apdu[0], - Network_Port_BIP_Mode(rpdata->object_instance)); + apdu_len = encode_application_enumerated( + &apdu[0], Network_Port_BIP_Mode(rpdata->object_instance)); break; case PROP_IP_ADDRESS: Network_Port_IP_Address(rpdata->object_instance, &octet_string); apdu_len = encode_application_octet_string(&apdu[0], &octet_string); break; case PROP_BACNET_IP_UDP_PORT: - apdu_len = encode_application_unsigned(&apdu[0], - Network_Port_BIP_Port(rpdata->object_instance)); + apdu_len = encode_application_unsigned( + &apdu[0], Network_Port_BIP_Port(rpdata->object_instance)); break; case PROP_IP_SUBNET_MASK: Network_Port_IP_Subnet(rpdata->object_instance, &octet_string); @@ -2102,20 +2004,21 @@ int Network_Port_Read_Property( Network_Port_IP_Gateway(rpdata->object_instance, &octet_string); apdu_len = encode_application_octet_string(&apdu[0], &octet_string); break; - case PROP_IP_DNS_SERVER: + case PROP_IP_DNS_SERVER: if (rpdata->array_index == 0) /* Array element zero is the number of objects in the list */ apdu_len = encode_application_unsigned(&apdu[0], BIP_DNS_MAX); else if (rpdata->array_index == BACNET_ARRAY_ALL) { - /* if no index was specified, then try to encode the entire list */ + /* if no index was specified, then try to encode the entire list + */ /* into one packet. */ int len; unsigned index; for (index = 0; index < BIP_DNS_MAX; index++) { Network_Port_IP_DNS_Server(rpdata->object_instance, index, - &octet_string); + &octet_string); len = encode_application_octet_string(&apdu[apdu_len], - &octet_string); + &octet_string); apdu_len += len; } } else if (rpdata->array_index <= BIP_DNS_MAX) { @@ -2123,9 +2026,9 @@ int Network_Port_Read_Property( unsigned index; index = rpdata->array_index - 1; Network_Port_IP_DNS_Server(rpdata->object_instance, index, - &octet_string); - apdu_len = encode_application_octet_string(&apdu[0], - &octet_string); + &octet_string); + apdu_len = + encode_application_octet_string(&apdu[0], &octet_string); } else { /* index was specified, but out of range */ rpdata->error_class = ERROR_CLASS_PROPERTY; @@ -2135,9 +2038,9 @@ int Network_Port_Read_Property( break; #if defined(BBMD_ENABLED) case PROP_BBMD_ACCEPT_FD_REGISTRATIONS: - apdu_len = encode_application_boolean(&apdu[0], - Network_Port_BBMD_Accept_FD_Registrations( - rpdata->object_instance)); + apdu_len = encode_application_boolean( + &apdu[0], Network_Port_BBMD_Accept_FD_Registrations( + rpdata->object_instance)); break; case PROP_BBMD_BROADCAST_DISTRIBUTION_TABLE: case PROP_BBMD_FOREIGN_DEVICE_TABLE: @@ -2147,20 +2050,21 @@ int Network_Port_Read_Property( break; #endif case PROP_BACNET_IPV6_MODE: - apdu_len = encode_application_enumerated(&apdu[0], - Network_Port_BIP6_Mode(rpdata->object_instance)); + apdu_len = encode_application_enumerated( + &apdu[0], Network_Port_BIP6_Mode(rpdata->object_instance)); break; case PROP_IPV6_ADDRESS: Network_Port_IPv6_Address(rpdata->object_instance, &octet_string); apdu_len = encode_application_octet_string(&apdu[0], &octet_string); break; case PROP_IPV6_PREFIX_LENGTH: - apdu_len = encode_application_unsigned(&apdu[0], + apdu_len = encode_application_unsigned( + &apdu[0], Network_Port_IPv6_Subnet_Prefix(rpdata->object_instance)); break; case PROP_BACNET_IPV6_UDP_PORT: - apdu_len = encode_application_unsigned(&apdu[0], - Network_Port_BIP6_Port(rpdata->object_instance)); + apdu_len = encode_application_unsigned( + &apdu[0], Network_Port_BIP6_Port(rpdata->object_instance)); break; case PROP_IPV6_DEFAULT_GATEWAY: Network_Port_IPv6_Gateway(rpdata->object_instance, &octet_string); @@ -2168,7 +2072,7 @@ int Network_Port_Read_Property( break; case PROP_BACNET_IPV6_MULTICAST_ADDRESS: Network_Port_IPv6_Multicast_Address(rpdata->object_instance, - &octet_string); + &octet_string); apdu_len = encode_application_octet_string(&apdu[0], &octet_string); break; case PROP_IPV6_DNS_SERVER: @@ -2176,15 +2080,16 @@ int Network_Port_Read_Property( /* Array element zero is the number of objects in the list */ apdu_len = encode_application_unsigned(&apdu[0], BIP_DNS_MAX); else if (rpdata->array_index == BACNET_ARRAY_ALL) { - /* if no index was specified, then try to encode the entire list */ + /* if no index was specified, then try to encode the entire list + */ /* into one packet. */ int len; unsigned index; for (index = 0; index < BIP_DNS_MAX; index++) { Network_Port_IPv6_DNS_Server(rpdata->object_instance, index, - &octet_string); + &octet_string); len = encode_application_octet_string(&apdu[apdu_len], - &octet_string); + &octet_string); apdu_len += len; } } else if (rpdata->array_index <= BIP_DNS_MAX) { @@ -2192,9 +2097,9 @@ int Network_Port_Read_Property( unsigned index; index = rpdata->array_index - 1; Network_Port_IPv6_DNS_Server(rpdata->object_instance, index, - &octet_string); - apdu_len = encode_application_octet_string(&apdu[0], - &octet_string); + &octet_string); + apdu_len = + encode_application_octet_string(&apdu[0], &octet_string); } else { /* index was specified, but out of range */ rpdata->error_class = ERROR_CLASS_PROPERTY; @@ -2213,14 +2118,13 @@ int Network_Port_Read_Property( break; case PROP_IPV6_DHCP_SERVER: Network_Port_IPv6_DHCP_Server(rpdata->object_instance, - &octet_string); + &octet_string); apdu_len = encode_application_octet_string(&apdu[0], &octet_string); break; case PROP_IPV6_ZONE_INDEX: - Network_Port_IPv6_Zone_Index(rpdata->object_instance, - &char_string); - apdu_len = encode_application_character_string(&apdu[0], - &char_string); + Network_Port_IPv6_Zone_Index(rpdata->object_instance, &char_string); + apdu_len = + encode_application_character_string(&apdu[0], &char_string); break; default: rpdata->error_class = ERROR_CLASS_PROPERTY; @@ -2241,10 +2145,9 @@ int Network_Port_Read_Property( * * @return false if an error is loaded, true if no errors */ -bool Network_Port_Write_Property( - BACNET_WRITE_PROPERTY_DATA * wp_data) +bool Network_Port_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data) { - bool status = false; /* return value */ + bool status = false; /* return value */ int len = 0; BACNET_APPLICATION_DATA_VALUE value; @@ -2254,9 +2157,8 @@ bool Network_Port_Write_Property( return false; } /* decode the some of the request */ - len = - bacapp_decode_application_data(wp_data->application_data, - wp_data->application_data_len, &value); + len = bacapp_decode_application_data(wp_data->application_data, + wp_data->application_data_len, &value); if (len < 0) { /* error while decoding - a value larger than we can handle */ wp_data->error_class = ERROR_CLASS_PROPERTY; @@ -2349,9 +2251,7 @@ bool Network_Port_Write_Property( * * @return number of bytes encoded */ -int Network_Port_Read_Range_BDT( - uint8_t * apdu, - BACNET_READ_RANGE_DATA * pRequest) +int Network_Port_Read_Range_BDT(uint8_t *apdu, BACNET_READ_RANGE_DATA *pRequest) { return 0; } @@ -2364,16 +2264,13 @@ int Network_Port_Read_Range_BDT( * * @return number of bytes encoded */ -int Network_Port_Read_Range_FDT( - uint8_t * apdu, - BACNET_READ_RANGE_DATA * pRequest) +int Network_Port_Read_Range_FDT(uint8_t *apdu, BACNET_READ_RANGE_DATA *pRequest) { return 0; } -bool Network_Port_Read_Range( - BACNET_READ_RANGE_DATA * pRequest, - RR_PROP_INFO * pInfo) +bool Network_Port_Read_Range(BACNET_READ_RANGE_DATA *pRequest, + RR_PROP_INFO *pInfo) { /* return value */ bool status = false; @@ -2445,8 +2342,7 @@ bool Network_Port_Read_Range( /** * Initializes the Network Port object data */ -void Network_Port_Init( - void) +void Network_Port_Init(void) { /* do something interesting */ } @@ -2456,11 +2352,9 @@ void Network_Port_Init( #include #include "ctest.h" -bool WPValidateArgType( - BACNET_APPLICATION_DATA_VALUE * pValue, - uint8_t ucExpectedTag, - BACNET_ERROR_CLASS * pErrorClass, - BACNET_ERROR_CODE * pErrorCode) +bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue, + uint8_t ucExpectedTag, BACNET_ERROR_CLASS *pErrorClass, + BACNET_ERROR_CODE *pErrorCode) { pValue = pValue; ucExpectedTag = ucExpectedTag; @@ -2470,10 +2364,9 @@ bool WPValidateArgType( return false; } -void test_network_port( - Test * pTest) +void test_network_port(Test *pTest) { - uint8_t apdu[MAX_APDU] = { 0 }; + uint8_t apdu[MAX_APDU] = {0}; int len = 0; int test_len = 0; BACNET_READ_PROPERTY_DATA rpdata; @@ -2487,18 +2380,10 @@ void test_network_port( uint32_t object_instance = 0; bool status = false; uint8_t port_type[] = { - PORT_TYPE_ETHERNET, - PORT_TYPE_ARCNET, - PORT_TYPE_MSTP, - PORT_TYPE_PTP, - PORT_TYPE_LONTALK, - PORT_TYPE_BIP, - PORT_TYPE_ZIGBEE, - PORT_TYPE_VIRTUAL, - PORT_TYPE_NON_BACNET, - PORT_TYPE_BIP6, - PORT_TYPE_MAX - }; + PORT_TYPE_ETHERNET, PORT_TYPE_ARCNET, PORT_TYPE_MSTP, + PORT_TYPE_PTP, PORT_TYPE_LONTALK, PORT_TYPE_BIP, + PORT_TYPE_ZIGBEE, PORT_TYPE_VIRTUAL, PORT_TYPE_NON_BACNET, + PORT_TYPE_BIP6, PORT_TYPE_MAX}; while (port_type[port] != PORT_TYPE_MAX) { object_instance = 1234; @@ -2520,8 +2405,7 @@ void test_network_port( len = Network_Port_Read_Property(&rpdata); ct_test(pTest, len != 0); test_len = bacapp_decode_application_data( - rpdata.application_data, - (uint8_t) rpdata.application_data_len, + rpdata.application_data, (uint8_t)rpdata.application_data_len, &value); ct_test(pTest, test_len >= 0); if (test_len < 0) { @@ -2535,8 +2419,7 @@ void test_network_port( len = Network_Port_Read_Property(&rpdata); ct_test(pTest, len != 0); test_len = bacapp_decode_application_data( - rpdata.application_data, - (uint8_t) rpdata.application_data_len, + rpdata.application_data, (uint8_t)rpdata.application_data_len, &value); ct_test(pTest, test_len >= 0); if (test_len < 0) { @@ -2551,8 +2434,7 @@ void test_network_port( } #ifdef TEST_NETWORK_PORT -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -2564,11 +2446,10 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; } #endif #endif /* TEST */ - diff --git a/demo/object/osv.c b/demo/object/osv.c index f4a40f4a..adba4d08 100644 --- a/demo/object/osv.c +++ b/demo/object/osv.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2015 Nikola Jelic -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2015 Nikola Jelic + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* OctetString Value Objects - customize for your use */ @@ -35,12 +35,11 @@ #include "bacenum.h" #include "bacapp.h" #include "bactext.h" -#include "config.h" /* the custom stuff */ +#include "config.h" /* the custom stuff */ #include "device.h" #include "handlers.h" #include "osv.h" - #ifndef MAX_OCTETSTRING_VALUES #define MAX_OCTETSTRING_VALUES 4 #endif @@ -49,28 +48,17 @@ OCTETSTRING_VALUE_DESCR AV_Descr[MAX_OCTETSTRING_VALUES]; /* These three arrays are used by the ReadPropertyMultiple handler */ static const int OctetString_Value_Properties_Required[] = { - PROP_OBJECT_IDENTIFIER, - PROP_OBJECT_NAME, - PROP_OBJECT_TYPE, - PROP_PRESENT_VALUE, - PROP_STATUS_FLAGS, - -1 -}; + PROP_OBJECT_IDENTIFIER, PROP_OBJECT_NAME, PROP_OBJECT_TYPE, + PROP_PRESENT_VALUE, PROP_STATUS_FLAGS, -1}; static const int OctetString_Value_Properties_Optional[] = { - PROP_EVENT_STATE, - PROP_OUT_OF_SERVICE, - PROP_DESCRIPTION, - -1 -}; + PROP_EVENT_STATE, PROP_OUT_OF_SERVICE, PROP_DESCRIPTION, -1}; -static const int OctetString_Value_Properties_Proprietary[] = { - -1 -}; +static const int OctetString_Value_Properties_Proprietary[] = {-1}; void OctetString_Value_Property_Lists(const int **pRequired, - const int **pOptional, - const int **pProprietary) + const int **pOptional, + const int **pProprietary) { if (pRequired) *pRequired = OctetString_Value_Properties_Required; @@ -142,8 +130,8 @@ unsigned OctetString_Value_Instance_To_Index(uint32_t object_instance) * @return true if values are within range and present-value is set. */ bool OctetString_Value_Present_Value_Set(uint32_t object_instance, - BACNET_OCTET_STRING * value, - uint8_t priority) + BACNET_OCTET_STRING *value, + uint8_t priority) { unsigned index = 0; bool status = false; @@ -171,14 +159,14 @@ BACNET_OCTET_STRING *OctetString_Value_Present_Value(uint32_t object_instance) /* note: the object name must be unique within this device */ bool OctetString_Value_Object_Name(uint32_t object_instance, - BACNET_CHARACTER_STRING * object_name) + BACNET_CHARACTER_STRING *object_name) { - static char text_string[32] = ""; /* okay for single thread */ + static char text_string[32] = ""; /* okay for single thread */ bool status = false; if (object_instance < MAX_OCTETSTRING_VALUES) { sprintf(text_string, "OCTETSTRING VALUE %lu", - (unsigned long) object_instance); + (unsigned long)object_instance); status = characterstring_init_ansi(object_name, text_string); } @@ -186,9 +174,9 @@ bool OctetString_Value_Object_Name(uint32_t object_instance, } /* return apdu len, or BACNET_STATUS_ERROR on error */ -int OctetString_Value_Read_Property(BACNET_READ_PROPERTY_DATA * rpdata) +int OctetString_Value_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata) { - int apdu_len = 0; /* return value */ + int apdu_len = 0; /* return value */ BACNET_BIT_STRING bit_string; BACNET_CHARACTER_STRING char_string; BACNET_OCTET_STRING *real_value = NULL; @@ -204,8 +192,7 @@ int OctetString_Value_Read_Property(BACNET_READ_PROPERTY_DATA * rpdata) apdu = rpdata->application_data; - object_index = - OctetString_Value_Instance_To_Index(rpdata->object_instance); + object_index = OctetString_Value_Instance_To_Index(rpdata->object_instance); if (object_index < MAX_OCTETSTRING_VALUES) CurrentAV = &AV_Descr[object_index]; else @@ -213,23 +200,21 @@ int OctetString_Value_Read_Property(BACNET_READ_PROPERTY_DATA * rpdata) switch (rpdata->object_property) { case PROP_OBJECT_IDENTIFIER: - apdu_len = - encode_application_object_id(&apdu[0], - OBJECT_OCTETSTRING_VALUE, rpdata->object_instance); + apdu_len = encode_application_object_id( + &apdu[0], OBJECT_OCTETSTRING_VALUE, rpdata->object_instance); break; case PROP_OBJECT_NAME: case PROP_DESCRIPTION: OctetString_Value_Object_Name(rpdata->object_instance, - &char_string); + &char_string); apdu_len = encode_application_character_string(&apdu[0], &char_string); break; case PROP_OBJECT_TYPE: - apdu_len = - encode_application_enumerated(&apdu[0], - OBJECT_OCTETSTRING_VALUE); + apdu_len = encode_application_enumerated(&apdu[0], + OBJECT_OCTETSTRING_VALUE); break; case PROP_PRESENT_VALUE: @@ -244,7 +229,7 @@ int OctetString_Value_Read_Property(BACNET_READ_PROPERTY_DATA * rpdata) bitstring_set_bit(&bit_string, STATUS_FLAG_FAULT, false); bitstring_set_bit(&bit_string, STATUS_FLAG_OVERRIDDEN, false); bitstring_set_bit(&bit_string, STATUS_FLAG_OUT_OF_SERVICE, - CurrentAV->Out_Of_Service); + CurrentAV->Out_Of_Service); apdu_len = encode_application_bitstring(&apdu[0], &bit_string); break; @@ -277,18 +262,17 @@ int OctetString_Value_Read_Property(BACNET_READ_PROPERTY_DATA * rpdata) } /* returns true if successful */ -bool OctetString_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data) +bool OctetString_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data) { - bool status = false; /* return value */ + bool status = false; /* return value */ unsigned int object_index = 0; int len = 0; BACNET_APPLICATION_DATA_VALUE value; OCTETSTRING_VALUE_DESCR *CurrentAV; /* decode the some of the request */ - len = - bacapp_decode_application_data(wp_data->application_data, - wp_data->application_data_len, &value); + len = bacapp_decode_application_data(wp_data->application_data, + wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ if (len < 0) { /* error while decoding - a value larger than we can handle */ @@ -317,8 +301,8 @@ bool OctetString_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data) /* Command priority 6 is reserved for use by Minimum On/Off algorithm and may not be used for other purposes in any object. */ - if (OctetString_Value_Present_Value_Set(wp_data-> - object_instance, &value.type.Octet_String, + if (OctetString_Value_Present_Value_Set( + wp_data->object_instance, &value.type.Octet_String, wp_data->priority)) { status = true; } else if (wp_data->priority == 6) { @@ -341,7 +325,7 @@ bool OctetString_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data) case PROP_OUT_OF_SERVICE: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { CurrentAV->Out_Of_Service = value.type.Boolean; } @@ -365,7 +349,6 @@ bool OctetString_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data) return status; } - void OctetString_Value_Intrinsic_Reporting(uint32_t object_instance) { } @@ -375,10 +358,9 @@ void OctetString_Value_Intrinsic_Reporting(uint32_t object_instance) #include #include "ctest.h" -bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE * pValue, - uint8_t ucExpectedTag, - BACNET_ERROR_CLASS * pErrorClass, - BACNET_ERROR_CODE * pErrorCode) +bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue, + uint8_t ucExpectedTag, BACNET_ERROR_CLASS *pErrorClass, + BACNET_ERROR_CODE *pErrorCode) { pValue = pValue; ucExpectedTag = ucExpectedTag; @@ -388,10 +370,10 @@ bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE * pValue, return false; } -void testOctetString_Value(Test * pTest) +void testOctetString_Value(Test *pTest) { BACNET_READ_PROPERTY_DATA rpdata; - uint8_t apdu[MAX_APDU] = { 0 }; + uint8_t apdu[MAX_APDU] = {0}; int len = 0; uint32_t len_value = 0; uint8_t tag_number = 0; @@ -429,7 +411,7 @@ int main(void) ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/demo/object/piv.c b/demo/object/piv.c index facb5d62..15d78845 100644 --- a/demo/object/piv.c +++ b/demo/object/piv.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2015 Nikola Jelic -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2015 Nikola Jelic + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* Positiveinteger Value Objects - customize for your use */ @@ -35,12 +35,11 @@ #include "bacenum.h" #include "bacapp.h" #include "bactext.h" -#include "config.h" /* the custom stuff */ +#include "config.h" /* the custom stuff */ #include "device.h" #include "handlers.h" #include "piv.h" - #ifndef MAX_POSITIVEINTEGER_VALUES #define MAX_POSITIVEINTEGER_VALUES 4 #endif @@ -55,21 +54,16 @@ static const int PositiveInteger_Value_Properties_Required[] = { PROP_PRESENT_VALUE, PROP_STATUS_FLAGS, PROP_UNITS, - - 1 -}; + -1}; static const int PositiveInteger_Value_Properties_Optional[] = { - PROP_OUT_OF_SERVICE, - -1 -}; + PROP_OUT_OF_SERVICE, -1}; -static const int PositiveInteger_Value_Properties_Proprietary[] = { - -1 -}; +static const int PositiveInteger_Value_Properties_Proprietary[] = {-1}; void PositiveInteger_Value_Property_Lists(const int **pRequired, - const int **pOptional, - const int **pProprietary) + const int **pOptional, + const int **pProprietary) { if (pRequired) *pRequired = PositiveInteger_Value_Properties_Required; @@ -140,8 +134,7 @@ unsigned PositiveInteger_Value_Instance_To_Index(uint32_t object_instance) * @return true if values are within range and present-value is set. */ bool PositiveInteger_Value_Present_Value_Set(uint32_t object_instance, - uint32_t value, - uint8_t priority) + uint32_t value, uint8_t priority) { unsigned index = 0; bool status = false; @@ -169,14 +162,14 @@ uint32_t PositiveInteger_Value_Present_Value(uint32_t object_instance) /* note: the object name must be unique within this device */ bool PositiveInteger_Value_Object_Name(uint32_t object_instance, - BACNET_CHARACTER_STRING * object_name) + BACNET_CHARACTER_STRING *object_name) { - static char text_string[32] = ""; /* okay for single thread */ + static char text_string[32] = ""; /* okay for single thread */ bool status = false; if (object_instance < MAX_POSITIVEINTEGER_VALUES) { sprintf(text_string, "POSITIVEINTEGER VALUE %lu", - (unsigned long) object_instance); + (unsigned long)object_instance); status = characterstring_init_ansi(object_name, text_string); } @@ -184,9 +177,9 @@ bool PositiveInteger_Value_Object_Name(uint32_t object_instance, } /* return apdu len, or BACNET_STATUS_ERROR on error */ -int PositiveInteger_Value_Read_Property(BACNET_READ_PROPERTY_DATA * rpdata) +int PositiveInteger_Value_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata) { - int apdu_len = 0; /* return value */ + int apdu_len = 0; /* return value */ BACNET_BIT_STRING bit_string; BACNET_CHARACTER_STRING char_string; unsigned object_index = 0; @@ -210,27 +203,26 @@ int PositiveInteger_Value_Read_Property(BACNET_READ_PROPERTY_DATA * rpdata) switch (rpdata->object_property) { case PROP_OBJECT_IDENTIFIER: - apdu_len = - encode_application_object_id(&apdu[0], - OBJECT_POSITIVE_INTEGER_VALUE, rpdata->object_instance); + apdu_len = encode_application_object_id( + &apdu[0], OBJECT_POSITIVE_INTEGER_VALUE, + rpdata->object_instance); break; case PROP_OBJECT_NAME: PositiveInteger_Value_Object_Name(rpdata->object_instance, - &char_string); + &char_string); apdu_len = encode_application_character_string(&apdu[0], &char_string); break; case PROP_OBJECT_TYPE: - apdu_len = - encode_application_enumerated(&apdu[0], - OBJECT_POSITIVE_INTEGER_VALUE); + apdu_len = encode_application_enumerated( + &apdu[0], OBJECT_POSITIVE_INTEGER_VALUE); break; case PROP_PRESENT_VALUE: - apdu_len = - encode_application_unsigned(&apdu[0], + apdu_len = encode_application_unsigned( + &apdu[0], PositiveInteger_Value_Present_Value(rpdata->object_instance)); break; @@ -240,7 +232,7 @@ int PositiveInteger_Value_Read_Property(BACNET_READ_PROPERTY_DATA * rpdata) bitstring_set_bit(&bit_string, STATUS_FLAG_FAULT, false); bitstring_set_bit(&bit_string, STATUS_FLAG_OVERRIDDEN, false); bitstring_set_bit(&bit_string, STATUS_FLAG_OUT_OF_SERVICE, - CurrentAV->Out_Of_Service); + CurrentAV->Out_Of_Service); apdu_len = encode_application_bitstring(&apdu[0], &bit_string); break; @@ -248,16 +240,15 @@ int PositiveInteger_Value_Read_Property(BACNET_READ_PROPERTY_DATA * rpdata) case PROP_UNITS: apdu_len = encode_application_enumerated(&apdu[0], CurrentAV->Units); - break; - /* BACnet Testing Observed Incident oi00109 - Positive Integer Value / Units returned wrong datatype - missing break. - Revealed by BACnet Test Client v1.8.16 ( www.bac-test.com/bacnet-test-client-download ) - BITS: BIT00031 - BC 135.1: 9.20.1.7 - BC 135.1: 9.20.1.9 - Any discussions can be directed to edward@bac-test.com - Please feel free to remove this comment when my changes have been reviewed - by all interested parties. Say 6 months -> September 2016 */ + break; + /* BACnet Testing Observed Incident oi00109 + Positive Integer Value / Units returned wrong datatype - + missing break. Revealed by BACnet Test Client v1.8.16 ( + www.bac-test.com/bacnet-test-client-download ) BITS: BIT00031 BC + 135.1: 9.20.1.7 BC 135.1: 9.20.1.9 Any discussions can be + directed to edward@bac-test.com Please feel free to remove this + comment when my changes have been reviewed by all interested + parties. Say 6 months -> September 2016 */ case PROP_OUT_OF_SERVICE: state = CurrentAV->Out_Of_Service; @@ -282,18 +273,17 @@ int PositiveInteger_Value_Read_Property(BACNET_READ_PROPERTY_DATA * rpdata) } /* returns true if successful */ -bool PositiveInteger_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data) +bool PositiveInteger_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data) { - bool status = false; /* return value */ + bool status = false; /* return value */ unsigned int object_index = 0; int len = 0; BACNET_APPLICATION_DATA_VALUE value; POSITIVEINTEGER_VALUE_DESCR *CurrentAV; /* decode the some of the request */ - len = - bacapp_decode_application_data(wp_data->application_data, - wp_data->application_data_len, &value); + len = bacapp_decode_application_data(wp_data->application_data, + wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ if (len < 0) { /* error while decoding - a value larger than we can handle */ @@ -322,8 +312,8 @@ bool PositiveInteger_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data) /* Command priority 6 is reserved for use by Minimum On/Off algorithm and may not be used for other purposes in any object. */ - if (PositiveInteger_Value_Present_Value_Set(wp_data-> - object_instance, value.type.Unsigned_Int, + if (PositiveInteger_Value_Present_Value_Set( + wp_data->object_instance, value.type.Unsigned_Int, wp_data->priority)) { status = true; } else if (wp_data->priority == 6) { @@ -346,7 +336,7 @@ bool PositiveInteger_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data) case PROP_OUT_OF_SERVICE: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { CurrentAV->Out_Of_Service = value.type.Boolean; } @@ -369,7 +359,6 @@ bool PositiveInteger_Value_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data) return status; } - void PositiveInteger_Value_Intrinsic_Reporting(uint32_t object_instance) { } @@ -379,10 +368,9 @@ void PositiveInteger_Value_Intrinsic_Reporting(uint32_t object_instance) #include #include "ctest.h" -bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE * pValue, - uint8_t ucExpectedTag, - BACNET_ERROR_CLASS * pErrorClass, - BACNET_ERROR_CODE * pErrorCode) +bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue, + uint8_t ucExpectedTag, BACNET_ERROR_CLASS *pErrorClass, + BACNET_ERROR_CODE *pErrorCode) { pValue = pValue; ucExpectedTag = ucExpectedTag; @@ -392,10 +380,10 @@ bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE * pValue, return false; } -void testPositiveInteger_Value(Test * pTest) +void testPositiveInteger_Value(Test *pTest) { BACNET_READ_PROPERTY_DATA rpdata; - uint8_t apdu[MAX_APDU] = { 0 }; + uint8_t apdu[MAX_APDU] = {0}; int len = 0; uint32_t len_value = 0; uint8_t tag_number = 0; @@ -433,7 +421,7 @@ int main(void) ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/demo/object/schedule.c b/demo/object/schedule.c index af517bf2..30dcfdbc 100644 --- a/demo/object/schedule.c +++ b/demo/object/schedule.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2015 Nikola Jelic -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2015 Nikola Jelic + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include @@ -55,21 +55,14 @@ static const int Schedule_Properties_Required[] = { PROP_STATUS_FLAGS, PROP_RELIABILITY, PROP_OUT_OF_SERVICE, - -1 -}; + -1}; -static const int Schedule_Properties_Optional[] = { - PROP_WEEKLY_SCHEDULE, - -1 -}; +static const int Schedule_Properties_Optional[] = {PROP_WEEKLY_SCHEDULE, -1}; -static const int Schedule_Properties_Proprietary[] = { - -1 -}; +static const int Schedule_Properties_Proprietary[] = {-1}; -void Schedule_Property_Lists(const int **pRequired, - const int **pOptional, - const int **pProprietary) +void Schedule_Property_Lists(const int **pRequired, const int **pOptional, + const int **pProprietary) { if (pRequired) *pRequired = Schedule_Properties_Required; @@ -98,9 +91,11 @@ void Schedule_Init(void) Schedule_Descr[i].Present_Value = &Schedule_Descr[i].Schedule_Default; Schedule_Descr[i].Schedule_Default.context_specific = false; Schedule_Descr[i].Schedule_Default.tag = BACNET_APPLICATION_TAG_REAL; - Schedule_Descr[i].Schedule_Default.type.Real = 21.0; /* 21 C, room temperature */ - Schedule_Descr[i].obj_prop_ref_cnt = 0; /* no references, add as needed */ - Schedule_Descr[i].Priority_For_Writing = 16; /* lowest priority */ + Schedule_Descr[i].Schedule_Default.type.Real = + 21.0; /* 21 C, room temperature */ + Schedule_Descr[i].obj_prop_ref_cnt = + 0; /* no references, add as needed */ + Schedule_Descr[i].Priority_For_Writing = 16; /* lowest priority */ Schedule_Descr[i].Out_Of_Service = false; } } @@ -135,15 +130,15 @@ unsigned Schedule_Instance_To_Index(uint32_t instance) } bool Schedule_Object_Name(uint32_t object_instance, - BACNET_CHARACTER_STRING * object_name) + BACNET_CHARACTER_STRING *object_name) { - static char text_string[32] = ""; /* okay for single thread */ + static char text_string[32] = ""; /* okay for single thread */ unsigned int index; bool status = false; index = Schedule_Instance_To_Index(object_instance); if (index < MAX_SCHEDULES) { - sprintf(text_string, "SCHEDULE %lu", (unsigned long) index); + sprintf(text_string, "SCHEDULE %lu", (unsigned long)index); status = characterstring_init_ansi(object_name, text_string); } @@ -151,15 +146,13 @@ bool Schedule_Object_Name(uint32_t object_instance, } /* BACnet Testing Observed Incident oi00106 - Out of service was not supported by Schedule object - Revealed by BACnet Test Client v1.8.16 ( www.bac-test.com/bacnet-test-client-download ) - BITS: BIT00032 - Any discussions can be directed to edward@bac-test.com - Please feel free to remove this comment when my changes accepted after suitable time for - review by all interested parties. Say 6 months -> September 2016 */ -void Schedule_Out_Of_Service_Set( - uint32_t object_instance, - bool value) + Out of service was not supported by Schedule object + Revealed by BACnet Test Client v1.8.16 ( + www.bac-test.com/bacnet-test-client-download ) BITS: BIT00032 Any discussions + can be directed to edward@bac-test.com Please feel free to remove this + comment when my changes accepted after suitable time for review by all + interested parties. Say 6 months -> September 2016 */ +void Schedule_Out_Of_Service_Set(uint32_t object_instance, bool value) { unsigned index = 0; @@ -169,8 +162,7 @@ void Schedule_Out_Of_Service_Set( } } - -int Schedule_Read_Property(BACNET_READ_PROPERTY_DATA * rpdata) +int Schedule_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata) { int apdu_len = 0; unsigned object_index = 0; @@ -192,11 +184,10 @@ int Schedule_Read_Property(BACNET_READ_PROPERTY_DATA * rpdata) return BACNET_STATUS_ERROR; apdu = rpdata->application_data; - switch ((int) rpdata->object_property) { + switch ((int)rpdata->object_property) { case PROP_OBJECT_IDENTIFIER: - apdu_len = - encode_application_object_id(&apdu[0], OBJECT_SCHEDULE, - rpdata->object_instance); + apdu_len = encode_application_object_id(&apdu[0], OBJECT_SCHEDULE, + rpdata->object_instance); break; case PROP_OBJECT_NAME: Schedule_Object_Name(rpdata->object_instance, &char_string); @@ -204,49 +195,51 @@ int Schedule_Read_Property(BACNET_READ_PROPERTY_DATA * rpdata) encode_application_character_string(&apdu[0], &char_string); break; case PROP_OBJECT_TYPE: - apdu_len = - encode_application_enumerated(&apdu[0], OBJECT_SCHEDULE); + apdu_len = encode_application_enumerated(&apdu[0], OBJECT_SCHEDULE); break; case PROP_PRESENT_VALUE: apdu_len = bacapp_encode_data(&apdu[0], CurrentSC->Present_Value); break; case PROP_EFFECTIVE_PERIOD: - /* BACnet Testing Observed Incident oi00110 - Effective Period of Schedule object not correctly formatted - Revealed by BACnet Test Client v1.8.16 ( www.bac-test.com/bacnet-test-client-download ) - BITS: BIT00031 - Any discussions can be directed to edward@bac-test.com - Please feel free to remove this comment when my changes accepted after suitable time for - review by all interested parties. Say 6 months -> September 2016 */ - apdu_len = encode_application_date(&apdu[0], &CurrentSC->Start_Date); + /* BACnet Testing Observed Incident oi00110 + Effective Period of Schedule object not correctly formatted + Revealed by BACnet Test Client v1.8.16 ( + www.bac-test.com/bacnet-test-client-download ) BITS: BIT00031 Any + discussions can be directed to edward@bac-test.com Please feel + free to remove this comment when my changes accepted after + suitable time for + review by all interested parties. Say 6 months -> September + 2016 */ + apdu_len = + encode_application_date(&apdu[0], &CurrentSC->Start_Date); apdu_len += encode_application_date(&apdu[apdu_len], &CurrentSC->End_Date); break; case PROP_WEEKLY_SCHEDULE: - if (rpdata->array_index == 0) /* count, always 7 */ + if (rpdata->array_index == 0) /* count, always 7 */ apdu_len = encode_application_unsigned(&apdu[0], 7); else if (rpdata->array_index == BACNET_ARRAY_ALL) { /* full array */ int day; for (day = 0; day < 7; day++) { apdu_len += encode_opening_tag(&apdu[apdu_len], 0); for (i = 0; i < CurrentSC->Weekly_Schedule[day].TV_Count; - i++) { - apdu_len += - bacapp_encode_time_value(&apdu[apdu_len], + i++) { + apdu_len += bacapp_encode_time_value( + &apdu[apdu_len], &CurrentSC->Weekly_Schedule[day].Time_Values[i]); } apdu_len += encode_closing_tag(&apdu[apdu_len], 0); } - } else if (rpdata->array_index <= 7) { /* some array element */ + } else if (rpdata->array_index <= 7) { /* some array element */ int day = rpdata->array_index - 1; apdu_len += encode_opening_tag(&apdu[apdu_len], 0); for (i = 0; i < CurrentSC->Weekly_Schedule[day].TV_Count; i++) { - apdu_len += - bacapp_encode_time_value(&apdu[apdu_len], + apdu_len += bacapp_encode_time_value( + &apdu[apdu_len], &CurrentSC->Weekly_Schedule[day].Time_Values[i]); } apdu_len += encode_closing_tag(&apdu[apdu_len], 0); - } else { /* out of bounds */ + } else { /* out of bounds */ rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX; apdu_len = BACNET_STATUS_ERROR; @@ -258,15 +251,13 @@ int Schedule_Read_Property(BACNET_READ_PROPERTY_DATA * rpdata) break; case PROP_LIST_OF_OBJECT_PROPERTY_REFERENCES: for (i = 0; i < CurrentSC->obj_prop_ref_cnt; i++) { - apdu_len += - bacapp_encode_device_obj_property_ref(&apdu[apdu_len], - &CurrentSC->Object_Property_References[i]); + apdu_len += bacapp_encode_device_obj_property_ref( + &apdu[apdu_len], &CurrentSC->Object_Property_References[i]); } break; case PROP_PRIORITY_FOR_WRITING: - apdu_len = - encode_application_unsigned(&apdu[0], - CurrentSC->Priority_For_Writing); + apdu_len = encode_application_unsigned( + &apdu[0], CurrentSC->Priority_For_Writing); break; case PROP_STATUS_FLAGS: bitstring_init(&bit_string); @@ -277,21 +268,22 @@ int Schedule_Read_Property(BACNET_READ_PROPERTY_DATA * rpdata) apdu_len = encode_application_bitstring(&apdu[0], &bit_string); break; case PROP_RELIABILITY: - apdu_len = - encode_application_enumerated(&apdu[0], - RELIABILITY_NO_FAULT_DETECTED); + apdu_len = encode_application_enumerated( + &apdu[0], RELIABILITY_NO_FAULT_DETECTED); break; - + case PROP_OUT_OF_SERVICE: - /* BACnet Testing Observed Incident oi00106 - Out of service was not supported by Schedule object - Revealed by BACnet Test Client v1.8.16 ( www.bac-test.com/bacnet-test-client-download ) - BITS: BIT00032 - Any discussions can be directed to edward@bac-test.com - Please feel free to remove this comment when my changes accepted after suitable time for - review by all interested parties. Say 6 months -> September 2016 */ - apdu_len = encode_application_boolean(&apdu[0], - CurrentSC->Out_Of_Service ); + /* BACnet Testing Observed Incident oi00106 + Out of service was not supported by Schedule object + Revealed by BACnet Test Client v1.8.16 ( + www.bac-test.com/bacnet-test-client-download ) BITS: BIT00032 Any + discussions can be directed to edward@bac-test.com Please feel + free to remove this comment when my changes accepted after + suitable time for + review by all interested parties. Say 6 months -> September + 2016 */ + apdu_len = + encode_application_boolean(&apdu[0], CurrentSC->Out_Of_Service); break; default: rpdata->error_class = ERROR_CLASS_PROPERTY; @@ -300,8 +292,8 @@ int Schedule_Read_Property(BACNET_READ_PROPERTY_DATA * rpdata) break; } - if ((apdu_len >= 0) && (rpdata->object_property != PROP_WEEKLY_SCHEDULE) - && (rpdata->array_index != BACNET_ARRAY_ALL)) { + if ((apdu_len >= 0) && (rpdata->object_property != PROP_WEEKLY_SCHEDULE) && + (rpdata->array_index != BACNET_ARRAY_ALL)) { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY; apdu_len = BACNET_STATUS_ERROR; @@ -310,28 +302,29 @@ int Schedule_Read_Property(BACNET_READ_PROPERTY_DATA * rpdata) return apdu_len; } -bool Schedule_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data) +bool Schedule_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data) { - /* Ed->Steve, I know that initializing stack values used to be 'safer', but warnings in latest compilers indicate when - uninitialized values are being used, and I think that the warnings are more useful to reveal bad code flow than the - "safety: of pre-intializing variables. Please give this some thought let me know if you agree we should start to - remove initializations */ - unsigned object_index ; - bool status = false; /* return value */ - int len ; + /* Ed->Steve, I know that initializing stack values used to be 'safer', but + warnings in latest compilers indicate when uninitialized values are being + used, and I think that the warnings are more useful to reveal bad code + flow than the "safety: of pre-intializing variables. Please give this + some thought let me know if you agree we should start to remove + initializations */ + unsigned object_index; + bool status = false; /* return value */ + int len; BACNET_APPLICATION_DATA_VALUE value; - /* BACnet Testing Observed Incident oi00106 - Out of service was not supported by Schedule object - Revealed by BACnet Test Client v1.8.16 ( www.bac-test.com/bacnet-test-client-download ) - BITS: BIT00032 - Any discussions can be directed to edward@bac-test.com - Please feel free to remove this comment when my changes accepted after suitable time for - review by all interested parties. Say 6 months -> September 2016 */ + /* BACnet Testing Observed Incident oi00106 + Out of service was not supported by Schedule object + Revealed by BACnet Test Client v1.8.16 ( + www.bac-test.com/bacnet-test-client-download ) BITS: BIT00032 Any + discussions can be directed to edward@bac-test.com Please feel free to + remove this comment when my changes accepted after suitable time for + review by all interested parties. Say 6 months -> September 2016 */ /* decode the some of the request */ - len = - bacapp_decode_application_data(wp_data->application_data, - wp_data->application_data_len, &value); + len = bacapp_decode_application_data(wp_data->application_data, + wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ if (len < 0) { /* error while decoding - a value larger than we can handle */ @@ -345,22 +338,23 @@ bool Schedule_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data) return false; } - switch ((int) wp_data->object_property) { + switch ((int)wp_data->object_property) { case PROP_OUT_OF_SERVICE: - /* BACnet Testing Observed Incident oi00106 - Out of service was not supported by Schedule object - Revealed by BACnet Test Client v1.8.16 ( www.bac-test.com/bacnet-test-client-download ) - BITS: BIT00032 - Any discussions can be directed to edward@bac-test.com - Please feel free to remove this comment when my changes accepted after suitable time for - review by all interested parties. Say 6 months -> September 2016 */ + /* BACnet Testing Observed Incident oi00106 + Out of service was not supported by Schedule object + Revealed by BACnet Test Client v1.8.16 ( + www.bac-test.com/bacnet-test-client-download ) BITS: BIT00032 Any + discussions can be directed to edward@bac-test.com Please feel + free to remove this comment when my changes accepted after + suitable time for + review by all interested parties. Say 6 months -> September + 2016 */ status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { - Schedule_Out_Of_Service_Set( - wp_data->object_instance, - value.type.Boolean); + Schedule_Out_Of_Service_Set(wp_data->object_instance, + value.type.Boolean); } break; @@ -387,8 +381,7 @@ bool Schedule_Write_Property(BACNET_WRITE_PROPERTY_DATA * wp_data) return status; } -bool Schedule_In_Effective_Period(SCHEDULE_DESCR * desc, - BACNET_DATE * date) +bool Schedule_In_Effective_Period(SCHEDULE_DESCR *desc, BACNET_DATE *date) { bool res = false; @@ -401,29 +394,29 @@ bool Schedule_In_Effective_Period(SCHEDULE_DESCR * desc, return res; } -void Schedule_Recalculate_PV(SCHEDULE_DESCR * desc, - BACNET_WEEKDAY wday, - BACNET_TIME * time) +void Schedule_Recalculate_PV(SCHEDULE_DESCR *desc, BACNET_WEEKDAY wday, + BACNET_TIME *time) { int i; desc->Present_Value = NULL; /* for future development, here should be the loop for Exception Schedule */ - - /* Just a note to developers: We have a paying customer who has asked us to fully implement the Schedule Object. - In good spirit, they have agreed to allow us to release the code we develop back to the Open Source community after a 6-12 month waiting period. - However, if you are about to work on this yourself, please ping us at info@connect-ex.com, we may be able to broker an early release on a - case-by-case basis. */ - - for (i = 0; - i < desc->Weekly_Schedule[wday - 1].TV_Count && - desc->Present_Value == NULL; i++) { - int diff = datetime_wildcard_compare_time(time, - &desc->Weekly_Schedule[wday - 1].Time_Values[i].Time); + /* Just a note to developers: We have a paying customer who has asked us to + fully implement the Schedule Object. In good spirit, they have agreed to + allow us to release the code we develop back to the Open Source community + after a 6-12 month waiting period. However, if you are about to work on + this yourself, please ping us at info@connect-ex.com, we may be able to + broker an early release on a case-by-case basis. */ + + for (i = 0; i < desc->Weekly_Schedule[wday - 1].TV_Count && + desc->Present_Value == NULL; + i++) { + int diff = datetime_wildcard_compare_time( + time, &desc->Weekly_Schedule[wday - 1].Time_Values[i].Time); if (diff >= 0 && desc->Weekly_Schedule[wday - 1].Time_Values[i].Value.tag != - BACNET_APPLICATION_TAG_NULL) { + BACNET_APPLICATION_TAG_NULL) { desc->Present_Value = &desc->Weekly_Schedule[wday - 1].Time_Values[i].Value; } @@ -438,11 +431,10 @@ void Schedule_Recalculate_PV(SCHEDULE_DESCR * desc, #include #include "ctest.h" - -void testSchedule(Test * pTest) +void testSchedule(Test *pTest) { BACNET_READ_PROPERTY_DATA rpdata; - uint8_t apdu[MAX_APDU] = { 0 }; + uint8_t apdu[MAX_APDU] = {0}; int len = 0; uint32_t len_value = 0; uint8_t tag_number = 0; @@ -467,7 +459,6 @@ void testSchedule(Test * pTest) return; } - #ifdef TEST_SCHEDULE int main(void) @@ -482,7 +473,7 @@ int main(void) ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/demo/object/trendlog.c b/demo/object/trendlog.c index 8b7fc1d3..526774a8 100644 --- a/demo/object/trendlog.c +++ b/demo/object/trendlog.c @@ -1,47 +1,47 @@ /************************************************************************** -* -* Copyright (C) 2009 Peter Mc Shane -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2009 Peter Mc Shane + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include -#include /* for memmove */ +#include /* for memmove */ #include "bacdef.h" #include "bacdcode.h" #include "bacenum.h" #include "bacapp.h" -#include "config.h" /* the custom stuff */ +#include "config.h" /* the custom stuff */ #include "apdu.h" #include "wp.h" /* write property handling */ #include "version.h" -#include "device.h" /* me */ +#include "device.h" /* me */ #include "handlers.h" #include "datalink.h" #include "address.h" #include "bacdevobjpropref.h" #include "trendlog.h" #if defined(BACFILE) -#include "bacfile.h" /* object list dependency */ +#include "bacfile.h" /* object list dependency */ #endif /* number of demo objects */ @@ -53,57 +53,44 @@ TL_DATA_REC Logs[MAX_TREND_LOGS][TL_MAX_ENTRIES]; static TL_LOG_INFO LogInfo[MAX_TREND_LOGS]; /* These three arrays are used by the ReadPropertyMultiple handler */ -static const int Trend_Log_Properties_Required[] = { - PROP_OBJECT_IDENTIFIER, - PROP_OBJECT_NAME, - PROP_OBJECT_TYPE, - PROP_ENABLE, - PROP_STOP_WHEN_FULL, - PROP_BUFFER_SIZE, - PROP_LOG_BUFFER, - PROP_RECORD_COUNT, - PROP_TOTAL_RECORD_COUNT, - PROP_EVENT_STATE, - PROP_LOGGING_TYPE, - PROP_STATUS_FLAGS, - -1 -}; +static const int Trend_Log_Properties_Required[] = {PROP_OBJECT_IDENTIFIER, + PROP_OBJECT_NAME, + PROP_OBJECT_TYPE, + PROP_ENABLE, + PROP_STOP_WHEN_FULL, + PROP_BUFFER_SIZE, + PROP_LOG_BUFFER, + PROP_RECORD_COUNT, + PROP_TOTAL_RECORD_COUNT, + PROP_EVENT_STATE, + PROP_LOGGING_TYPE, + PROP_STATUS_FLAGS, + -1}; static const int Trend_Log_Properties_Optional[] = { - PROP_DESCRIPTION, - PROP_START_TIME, - PROP_STOP_TIME, - PROP_LOG_DEVICE_OBJECT_PROPERTY, - PROP_LOG_INTERVAL, + PROP_DESCRIPTION, PROP_START_TIME, PROP_STOP_TIME, + PROP_LOG_DEVICE_OBJECT_PROPERTY, PROP_LOG_INTERVAL, -/* Required if COV logging supported - PROP_COV_RESUBSCRIPTION_INTERVAL, - PROP_CLIENT_COV_INCREMENT, */ + /* 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, - PROP_LAST_NOTIFY_RECORD, - PROP_NOTIFICATION_CLASS, - PROP_EVENT_ENABLE, - PROP_ACKED_TRANSITIONS, - PROP_NOTIFY_TYPE, - PROP_EVENT_TIME_STAMPS, */ + /* Required if intrinsic reporting supported + PROP_NOTIFICATION_THRESHOLD, + PROP_RECORDS_SINCE_NOTIFICATION, + PROP_LAST_NOTIFY_RECORD, + PROP_NOTIFICATION_CLASS, + PROP_EVENT_ENABLE, + PROP_ACKED_TRANSITIONS, + PROP_NOTIFY_TYPE, + PROP_EVENT_TIME_STAMPS, */ - PROP_ALIGN_INTERVALS, - PROP_INTERVAL_OFFSET, - PROP_TRIGGER, - -1 -}; + PROP_ALIGN_INTERVALS, PROP_INTERVAL_OFFSET, PROP_TRIGGER, -1}; -static const int Trend_Log_Properties_Proprietary[] = { - -1 -}; +static const int Trend_Log_Properties_Proprietary[] = {-1}; -void Trend_Log_Property_Lists( - const int **pRequired, - const int **pOptional, - const int **pProprietary) +void Trend_Log_Property_Lists(const int **pRequired, const int **pOptional, + const int **pProprietary) { if (pRequired) *pRequired = Trend_Log_Properties_Required; @@ -118,8 +105,7 @@ void Trend_Log_Property_Lists( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need validate that the */ /* given instance exists */ -bool Trend_Log_Valid_Instance( - uint32_t object_instance) +bool Trend_Log_Valid_Instance(uint32_t object_instance) { if (object_instance < MAX_TREND_LOGS) { return true; @@ -130,8 +116,7 @@ bool Trend_Log_Valid_Instance( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then count how many you have */ -unsigned Trend_Log_Count( - void) +unsigned Trend_Log_Count(void) { return MAX_TREND_LOGS; } @@ -139,8 +124,7 @@ unsigned Trend_Log_Count( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need to return the instance */ /* that correlates to the correct index */ -uint32_t Trend_Log_Index_To_Instance( - unsigned index) +uint32_t Trend_Log_Index_To_Instance(unsigned index) { return index; } @@ -148,8 +132,7 @@ uint32_t Trend_Log_Index_To_Instance( /* we simply have 0-n object instances. Yours might be */ /* more complex, and then you need to return the index */ /* that correlates to the correct instance number */ -unsigned Trend_Log_Instance_To_Index( - uint32_t object_instance) +unsigned Trend_Log_Instance_To_Index(uint32_t object_instance) { unsigned index = MAX_TREND_LOGS; @@ -164,8 +147,7 @@ unsigned Trend_Log_Instance_To_Index( * Things to do when starting up the stack for Trend Logs. * Should be called whenever we reset the device or power it up */ -void Trend_Log_Init( - void) +void Trend_Log_Init(void) { static bool initialized = false; int iLog; @@ -206,13 +188,13 @@ void Trend_Log_Init( Logs[iLog][iEntry].tTimeStamp = tClock; Logs[iLog][iEntry].ucRecType = TL_TYPE_REAL; Logs[iLog][iEntry].Datum.fReal = - (float) (iEntry + (iLog * TL_MAX_ENTRIES)); + (float)(iEntry + (iLog * TL_MAX_ENTRIES)); /* Put status flags with every second log */ if ((iLog & 1) == 0) Logs[iLog][iEntry].ucStatus = 128; else Logs[iLog][iEntry].ucStatus = 0; - tClock += 900; /* advance 15 minutes */ + tClock += 900; /* advance 15 minutes */ } LogInfo[iLog].tLastDataTime = tClock - 900; @@ -238,11 +220,11 @@ void Trend_Log_Init( LogInfo[iLog].Source.propertyIdentifier = PROP_PRESENT_VALUE; datetime_set_values(&LogInfo[iLog].StartTime, 2009, 1, 1, 0, 0, 0, - 0); + 0); LogInfo[iLog].tStartTime = TL_BAC_Time_To_Local(&LogInfo[iLog].StartTime); datetime_set_values(&LogInfo[iLog].StopTime, 2020, 12, 22, 23, 59, - 59, 99); + 59, 99); LogInfo[iLog].tStopTime = TL_BAC_Time_To_Local(&LogInfo[iLog].StopTime); } @@ -251,17 +233,15 @@ void Trend_Log_Init( return; } - /* * Note: we use the instance number here and build the name based * on the assumption that there is a 1 to 1 correspondance. If there * is not we need to convert to index before proceeding. */ -bool Trend_Log_Object_Name( - uint32_t object_instance, - BACNET_CHARACTER_STRING * object_name) +bool Trend_Log_Object_Name(uint32_t object_instance, + BACNET_CHARACTER_STRING *object_name) { - static char text_string[32] = ""; /* okay for single thread */ + static char text_string[32] = ""; /* okay for single thread */ bool status = false; if (object_instance < MAX_TREND_LOGS) { @@ -272,14 +252,12 @@ bool Trend_Log_Object_Name( return status; } - /* return the length of the apdu encoded or BACNET_STATUS_ERROR for error or BACNET_STATUS_ABORT for abort message */ -int Trend_Log_Read_Property( - BACNET_READ_PROPERTY_DATA * rpdata) +int Trend_Log_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata) { - int apdu_len = 0; /* return value */ - int len = 0; /* apdu len intermediate value */ + int apdu_len = 0; /* return value */ + int len = 0; /* apdu len intermediate value */ BACNET_BIT_STRING bit_string; BACNET_CHARACTER_STRING char_string; TL_LOG_INFO *CurrentLog; @@ -290,12 +268,12 @@ int Trend_Log_Read_Property( 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 = - encode_application_object_id(&apdu[0], OBJECT_TRENDLOG, - rpdata->object_instance); + apdu_len = encode_application_object_id(&apdu[0], OBJECT_TRENDLOG, + rpdata->object_instance); break; case PROP_DESCRIPTION: @@ -306,8 +284,7 @@ int Trend_Log_Read_Property( 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: @@ -317,8 +294,7 @@ int Trend_Log_Read_Property( case PROP_STOP_WHEN_FULL: apdu_len = - encode_application_boolean(&apdu[0], - CurrentLog->bStopWhenFull); + encode_application_boolean(&apdu[0], CurrentLog->bStopWhenFull); break; case PROP_BUFFER_SIZE: @@ -333,15 +309,13 @@ 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: @@ -351,9 +325,8 @@ int Trend_Log_Read_Property( 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: @@ -370,19 +343,16 @@ int Trend_Log_Read_Property( len = encode_application_date(&apdu[0], &CurrentLog->StartTime.date); apdu_len = len; - len = - encode_application_time(&apdu[apdu_len], - &CurrentLog->StartTime.time); + 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], - &CurrentLog->StopTime.time); + len = encode_application_time(&apdu[apdu_len], + &CurrentLog->StopTime.time); apdu_len += len; break; @@ -391,35 +361,36 @@ int Trend_Log_Read_Property( * BACnetDeviceObjectPropertyReference ::= SEQUENCE { * objectIdentifier [0] BACnetObjectIdentifier, * propertyIdentifier [1] BACnetPropertyIdentifier, - * propertyArrayIndex [2] Unsigned OPTIONAL, -- used only with array datatype - * -- if omitted with an array then - * -- the entire array is referenced - * deviceIdentifier [3] BACnetObjectIdentifier OPTIONAL + * propertyArrayIndex [2] Unsigned OPTIONAL, -- used only with + * array datatype + * -- if omitted with + * an array then + * -- the entire array + * is referenced 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); + /* 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); 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); + /* 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); break; case PROP_TRIGGER: @@ -434,8 +405,9 @@ 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 = BACNET_STATUS_ERROR; @@ -445,14 +417,14 @@ int Trend_Log_Read_Property( } /* returns true if successful */ -bool Trend_Log_Write_Property( - BACNET_WRITE_PROPERTY_DATA * wp_data) +bool Trend_Log_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data) { - bool status = false; /* return value */ + bool status = false; /* return value */ int len = 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; @@ -462,9 +434,8 @@ bool Trend_Log_Write_Property( CurrentLog = &LogInfo[log_index]; /* decode the some of the request */ - len = - bacapp_decode_application_data(wp_data->application_data, - wp_data->application_data_len, &value); + len = bacapp_decode_application_data(wp_data->application_data, + wp_data->application_data_len, &value); /* FIXME: len < application_data_len: more data? */ if (len < 0) { /* error while decoding - a value larger than we can handle */ @@ -483,9 +454,10 @@ bool Trend_Log_Write_Property( case PROP_ENABLE: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, - &wp_data->error_class, &wp_data->error_code); + &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 */ + /* 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) && @@ -496,7 +468,8 @@ bool Trend_Log_Write_Property( break; } - /* Only trigger this validation on a potential change of state */ + /* Only trigger this validation on a potential change of state + */ if (CurrentLog->bEnable != value.type.Boolean) { bEffectiveEnable = TL_Is_Enabled(log_index); CurrentLog->bEnable = value.type.Boolean; @@ -506,15 +479,15 @@ bool Trend_Log_Write_Property( /* Only insert record if we really were enabled i.e. times and enable flags */ TL_Insert_Status_Rec(log_index, - LOG_STATUS_LOG_DISABLED, true); + LOG_STATUS_LOG_DISABLED, true); } } else { 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, - LOG_STATUS_LOG_DISABLED, false); + TL_Insert_Status_Rec( + log_index, LOG_STATUS_LOG_DISABLED, false); } } } @@ -524,7 +497,7 @@ bool Trend_Log_Write_Property( case PROP_STOP_WHEN_FULL: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { /* Only trigger this on a change of state */ if (CurrentLog->bStopWhenFull != value.type.Boolean) { @@ -533,13 +506,13 @@ bool Trend_Log_Write_Property( 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 + /* 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); } } } @@ -557,14 +530,14 @@ bool Trend_Log_Write_Property( case PROP_RECORD_COUNT: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { 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); + true); } } break; @@ -575,18 +548,20 @@ bool Trend_Log_Write_Property( */ status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_ENUMERATED, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { if (value.type.Enumerated != LOGGING_TYPE_COV) { CurrentLog->LoggingType = value.type.Enumerated; if (value.type.Enumerated == LOGGING_TYPE_POLLED) { - /* As per 12.25.27 pick a suitable default if interval is 0 */ + /* As per 12.25.27 pick a suitable default if interval + * is 0 */ if (CurrentLog->ulLogInterval == 0) { CurrentLog->ulLogInterval = 900; } } if (value.type.Enumerated == LOGGING_TYPE_TRIGGERED) { - /* As per 12.25.27 0 the interval if triggered logging selected */ + /* As per 12.25.27 0 the interval if triggered logging + * selected */ CurrentLog->ulLogInterval = 0; } } else { @@ -603,26 +578,27 @@ bool Trend_Log_Write_Property( /* Copy the date part to safe place */ status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_DATE, - &wp_data->error_class, &wp_data->error_code); + &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)) { @@ -640,12 +616,12 @@ bool Trend_Log_Write_Property( /* Enable status has changed because of time update */ 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); } } } @@ -655,32 +631,35 @@ bool Trend_Log_Write_Property( /* Copy the date part to safe place */ status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_DATE, - &wp_data->error_class, &wp_data->error_code); + &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; - CurrentLog->tStopTime = 0xFFFFFFFF; /* Fixme: how do we set this to max for time_t ? */ + CurrentLog->tStopTime = + 0xFFFFFFFF; /* Fixme: how do we set this to max for + time_t ? */ } else { /* Clear wild card flag and set time in local format */ CurrentLog->ucTimeFlags &= ~TL_T_STOP_WILD; @@ -692,42 +671,46 @@ bool Trend_Log_Write_Property( /* Enable status has changed because of time update */ 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: - len = bacapp_decode_device_obj_property_ref(wp_data->application_data, &TempSource); - if((len < 0) || (len > wp_data->application_data_len)) // Hmm, that didn't go as planned... - { + len = bacapp_decode_device_obj_property_ref( + wp_data->application_data, &TempSource); + if ((len < 0) || + (len > wp_data->application_data_len)) // Hmm, that didn't go + // as planned... + { wp_data->error_class = ERROR_CLASS_PROPERTY; wp_data->error_code = ERROR_CODE_OTHER; break; - } + } // We only support references to objects in ourself for now - if((TempSource.deviceIdentifier.type == OBJECT_DEVICE) && (TempSource.deviceIdentifier.instance != Device_Object_Instance_Number())) - { - wp_data->error_class = ERROR_CLASS_PROPERTY; - wp_data->error_code = ERROR_CODE_OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED; - break; - } + if ((TempSource.deviceIdentifier.type == OBJECT_DEVICE) && + (TempSource.deviceIdentifier.instance != + Device_Object_Instance_Number())) { + wp_data->error_class = ERROR_CLASS_PROPERTY; + wp_data->error_code = + ERROR_CODE_OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED; + break; + } /* Quick comparison if structures are packed ... */ if (memcmp(&TempSource, &CurrentLog->Source, - sizeof(BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE)) != 0) { + sizeof(BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE)) != 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; status = true; @@ -742,21 +725,24 @@ bool Trend_Log_Write_Property( } status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { 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 */ + /* 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; status = false; } else { - /* We only log to 1 sec accuracy so must divide by 100 before passing it on */ + /* We only log to 1 sec accuracy so must divide by 100 + * before passing it on */ CurrentLog->ulLogInterval = value.type.Unsigned_Int / 100; - if(0 == CurrentLog->ulLogInterval) - CurrentLog->ulLogInterval = 1; /* Interval of 0 is not a good idea */ + if (0 == CurrentLog->ulLogInterval) + CurrentLog->ulLogInterval = + 1; /* Interval of 0 is not a good idea */ } } break; @@ -764,17 +750,18 @@ bool Trend_Log_Write_Property( case PROP_ALIGN_INTERVALS: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, - &wp_data->error_class, &wp_data->error_code); + &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 */ + /* 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); + &wp_data->error_class, &wp_data->error_code); if (status) { CurrentLog->ulIntervalOffset = value.type.Unsigned_Int / 100; } @@ -783,11 +770,12 @@ bool Trend_Log_Write_Property( case PROP_TRIGGER: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_BOOLEAN, - &wp_data->error_class, &wp_data->error_code); + &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 + /* 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)) { @@ -811,9 +799,9 @@ 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); @@ -839,10 +827,7 @@ 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; @@ -886,8 +871,7 @@ void TL_Insert_Status_Rec( * 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; @@ -905,7 +889,7 @@ bool TL_Is_Enabled( /* Not enabled so time is irrelevant */ bStatus = false; } else if ((CurrentLog->ucTimeFlags == 0) && - (CurrentLog->tStopTime < CurrentLog->tStartTime)) { + (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)) { @@ -945,13 +929,13 @@ bool TL_Is_Enabled( * 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. @@ -977,27 +961,25 @@ time_t TL_BAC_Time_To_Local( * 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 = (uint16_t) (TempTime->tm_year + 1900); - DestTime->date.month = (uint8_t) (TempTime->tm_mon + 1); - DestTime->date.day = (uint8_t) TempTime->tm_mday; + DestTime->date.year = (uint16_t)(TempTime->tm_year + 1900); + DestTime->date.month = (uint8_t)(TempTime->tm_mon + 1); + DestTime->date.day = (uint8_t)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) DestTime->date.wday = 7; else - DestTime->date.wday = (uint8_t) TempTime->tm_wday; - DestTime->time.hour = (uint8_t) TempTime->tm_hour; - DestTime->time.min = (uint8_t) TempTime->tm_min; - DestTime->time.sec = (uint8_t) TempTime->tm_sec; + DestTime->date.wday = (uint8_t)TempTime->tm_wday; + DestTime->time.hour = (uint8_t)TempTime->tm_hour; + DestTime->time.min = (uint8_t)TempTime->tm_min; + DestTime->time.sec = (uint8_t)TempTime->tm_sec; DestTime->time.hundredths = 0; } @@ -1020,22 +1002,20 @@ void TL_Local_Time_To_BAC( * + 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) +int rr_trend_log_encode(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_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) + if (LogInfo[Trend_Log_Instance_To_Index(pRequest->object_instance)] + .ulRecordCount == 0) return (0); if ((pRequest->RequestType == RR_BY_POSITION) || @@ -1053,20 +1033,18 @@ int rr_trend_log_encode( * 1 and of maximum log size length. * ****************************************************************************/ -int TL_encode_by_position( - uint8_t * apdu, - BACNET_READ_RANGE_DATA * pRequest) +int TL_encode_by_position(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; @@ -1078,11 +1056,12 @@ int TL_encode_by_position( * 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 @@ -1096,12 +1075,14 @@ int TL_encode_by_position( * 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; } @@ -1109,15 +1090,19 @@ int TL_encode_by_position( /* 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 */ + 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 = 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 */ + uiFirst = uiIndex; /* Record where we started from */ while (uiIndex <= uiTarget) { if (uiRemaining < TL_MAX_ENC) { /* @@ -1125,23 +1110,22 @@ int TL_encode_by_position( * was more and drop out of the loop early */ bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_MORE_ITEMS, - true); + 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 */ + 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 */ } /* Set remaining result flags if necessary */ if (uiFirst == 1) - bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_FIRST_ITEM, - true); + bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_FIRST_ITEM, true); if (uiLast == CurrentLog->ulRecordCount) bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_LAST_ITEM, true); @@ -1149,7 +1133,6 @@ int TL_encode_by_position( return (iLen); } - /**************************************************************************** * Handle encoding for the By Sequence option. * * The fact that the buffer always has at least a single entry is used * @@ -1157,32 +1140,33 @@ int TL_encode_by_position( * empty buffer. * ****************************************************************************/ -int TL_encode_by_sequence( - uint8_t * apdu, - BACNET_READ_RANGE_DATA * pRequest) +int TL_encode_by_sequence(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; 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 */ + /* Figure out the sequence number for the first record, last is + * ulTotalRecordCount */ uiFirstSeq = CurrentLog->ulTotalRecordCount - (CurrentLog->ulRecordCount - 1); @@ -1200,7 +1184,7 @@ int TL_encode_by_sequence( 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); @@ -1214,12 +1198,12 @@ int TL_encode_by_sequence( 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 (bWrapLog == false) { /* Only request range wraps */ if (uiEnd < uiFirstSeq) { uiEnd = CurrentLog->ulTotalRecordCount; if (uiBegin < uiFirstSeq) @@ -1237,7 +1221,7 @@ int TL_encode_by_sequence( if (uiEnd > CurrentLog->ulTotalRecordCount) uiEnd = CurrentLog->ulTotalRecordCount; } - } else { /* Both wrap */ + } else { /* Both wrap */ if (uiBegin < uiFirstSeq) uiBegin = uiFirstSeq; @@ -1251,7 +1235,7 @@ int TL_encode_by_sequence( */ uiIndex = uiBegin - uiFirstSeq + 1; uiSequence = uiBegin; - uiFirst = uiIndex; /* Record where we started from */ + uiFirst = uiIndex; /* Record where we started from */ while (uiSequence != uiEnd + 1) { if (uiRemaining < TL_MAX_ENC) { /* @@ -1259,24 +1243,23 @@ int TL_encode_by_sequence( * was more and drop out of the loop early */ bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_MORE_ITEMS, - true); + 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 */ + 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 */ uiSequence++; - pRequest->ItemCount++; /* Chalk up another one for the response count */ + 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); + bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_FIRST_ITEM, true); if (uiLast == CurrentLog->ulRecordCount) bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_LAST_ITEM, true); @@ -1293,9 +1276,7 @@ int TL_encode_by_sequence( * empty buffer. * ****************************************************************************/ -int TL_encode_by_time( - uint8_t * apdu, - BACNET_READ_RANGE_DATA * pRequest) +int TL_encode_by_time(uint8_t *apdu, BACNET_READ_RANGE_DATA *pRequest) { int log_index = 0; int iLen = 0; @@ -1303,12 +1284,12 @@ 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; @@ -1330,8 +1311,9 @@ int TL_encode_by_time( /* 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) + if (Logs[pRequest->object_instance] + [(uiIndex + iCount) % TL_MAX_ENTRIES] + .tTimeStamp < tRefTime) break; uiFirstSeq--; @@ -1344,7 +1326,7 @@ int TL_encode_by_time( * 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 @@ -1364,25 +1346,27 @@ int TL_encode_by_time( * timestamp greater than the reference time. */ iCount = 0; - /* Figure out the sequence number for the first record, last is ulTotalRecordCount */ + /* 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) + if (Logs[pRequest->object_instance] + [(uiIndex + iCount) % TL_MAX_ENTRIES] + .tTimeStamp > tRefTime) break; uiFirstSeq++; iCount++; - if ((uint32_t) iCount == CurrentLog->ulRecordCount) + 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 */ + 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) { @@ -1391,27 +1375,28 @@ int TL_encode_by_time( * was more and drop out of the loop early */ bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_MORE_ITEMS, - true); + 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 */ + 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 */ + 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); + bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_FIRST_ITEM, true); if (uiLast == CurrentLog->ulRecordCount) bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_LAST_ITEM, true); @@ -1421,11 +1406,7 @@ int TL_encode_by_time( 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; @@ -1449,46 +1430,41 @@ int TL_encode_entry( /* 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 */ + /* The data entry is tagged individually [0] - [10] to indicate which type + */ 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: @@ -1497,16 +1473,15 @@ int TL_encode_entry( */ bitstring_init(&TempBits); bitstring_set_bits_used(&TempBits, - (pSource->Datum.Bits.ucLen >> 4) & 0x0F, - pSource->Datum.Bits.ucLen & 0x0F); + (pSource->Datum.Bits.ucLen >> 4) & 0x0F, + pSource->Datum.Bits.ucLen & 0x0F); for (ucCount = pSource->Datum.Bits.ucLen >> 4; ucCount > 0; - ucCount--) + ucCount--) bitstring_set_octet(&TempBits, ucCount - 1, - pSource->Datum.Bits.ucStore[ucCount - 1]); + pSource->Datum.Bits.ucStore[ucCount - 1]); - iLen += - encode_context_bitstring(&apdu[iLen], pSource->ucRecType, - &TempBits); + iLen += encode_context_bitstring(&apdu[iLen], pSource->ucRecType, + &TempBits); break; case TL_TYPE_NULL: @@ -1515,19 +1490,16 @@ int TL_encode_entry( 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: @@ -1548,12 +1520,10 @@ int TL_encode_entry( return (iLen); } -static int local_read_property( - uint8_t * value, - uint8_t * status, - BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE * Source, - BACNET_ERROR_CLASS * error_class, - BACNET_ERROR_CODE * error_code) +static int local_read_property(uint8_t *value, uint8_t *status, + BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE *Source, + BACNET_ERROR_CLASS *error_class, + BACNET_ERROR_CODE *error_code) { int len = 0; BACNET_READ_PROPERTY_DATA rpdata; @@ -1594,11 +1564,12 @@ static int local_read_property( * Attempt to fetch the logged property and store it in the Trend Log * ****************************************************************************/ -static void TL_fetch_property( - int iLog) +static 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 */ + 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 */ BACNET_ERROR_CLASS error_class = ERROR_CLASS_SERVICES; BACNET_ERROR_CODE error_code = ERROR_CODE_OTHER; int iLen; @@ -1617,9 +1588,8 @@ static void TL_fetch_property( CurrentLog->tLastDataTime = TempRec.tTimeStamp; TempRec.ucStatus = 0; - iLen = - local_read_property(ValueBuf, StatusBuf, &LogInfo[iLog].Source, - &error_class, &error_code); + 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; @@ -1628,8 +1598,7 @@ static void TL_fetch_property( } 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); + decode_tag_number_and_value(ValueBuf, &tag_number, &len_value_type); switch (tag_number) { case BACNET_APPLICATION_TAG_NULL: TempRec.ucRecType = TL_TYPE_NULL; @@ -1643,19 +1612,19 @@ static void TL_fetch_property( case BACNET_APPLICATION_TAG_UNSIGNED_INT: TempRec.ucRecType = TL_TYPE_UNSIGN; decode_unsigned(&ValueBuf[iLen], len_value_type, - &TempRec.Datum.ulUValue); + &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); + &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); + &TempRec.Datum.fReal); break; case BACNET_APPLICATION_TAG_BIT_STRING: @@ -1663,14 +1632,15 @@ static void TL_fetch_property( decode_bitstring(&ValueBuf[iLen], len_value_type, &TempBits); /* We truncate any bitstrings at 32 bits to conserve space */ 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; + /* 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; /* Fetch the octets with the bits directly */ - for (ucCount = 0; - ucCount < bitstring_bytes_used(&TempBits); ucCount++) + for (ucCount = 0; ucCount < bitstring_bytes_used(&TempBits); + ucCount++) TempRec.Datum.Bits.ucStore[ucCount] = bitstring_octet(&TempBits, ucCount); } else { @@ -1685,7 +1655,7 @@ static void TL_fetch_property( case BACNET_APPLICATION_TAG_ENUMERATED: TempRec.ucRecType = TL_TYPE_ENUM; decode_enumerated(&ValueBuf[iLen], len_value_type, - &TempRec.Datum.ulEnum); + &TempRec.Datum.ulEnum); break; default: @@ -1696,9 +1666,8 @@ static void TL_fetch_property( 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); } @@ -1717,8 +1686,7 @@ static void TL_fetch_property( * Check each log to see if any data needs to be recorded. * ****************************************************************************/ -void trend_log_timer( - uint16_t uSeconds) +void trend_log_timer(uint16_t uSeconds) { TL_LOG_INFO *CurrentLog = NULL; int iCount = 0; @@ -1737,39 +1705,42 @@ void trend_log_timer( */ 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 - * we don't miss a reading if we aren't called at the precise second - * when the match occurrs. + * and the offset to decide when to log. Also log a reading + * if more than interval time has elapsed since last reading + * to ensure we don't miss a reading if we aren't called at + * the precise second when the match occurrs. */ -/* if(((tNow % CurrentLog->ulLogInterval) >= (CurrentLog->ulIntervalOffset % CurrentLog->ulLogInterval)) && */ -/* ((tNow - CurrentLog->tLastDataTime) >= CurrentLog->ulLogInterval)) { */ + /* if(((tNow % CurrentLog->ulLogInterval) >= + * (CurrentLog->ulIntervalOffset % + * CurrentLog->ulLogInterval)) && */ + /* ((tNow - CurrentLog->tLastDataTime) >= + * 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. + 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) { - /* 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 - * more than a single period. + 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 more than a single period. */ TL_fetch_property(iCount); } } 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. + 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 */ + 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 diff --git a/demo/perl/perl_bindings.c b/demo/perl/perl_bindings.c index 25442664..3e5f0c9d 100644 --- a/demo/perl/perl_bindings.c +++ b/demo/perl/perl_bindings.c @@ -27,24 +27,20 @@ static bool isAtomicReadFileHandlerRegistered = false; #define MAX_ERROR_STRING 128 #define NO_ERROR "No Error" static char Last_Error[MAX_ERROR_STRING] = NO_ERROR; -static void LogError( - const char *msg) +static void LogError(const char *msg) { strcpy(Last_Error, msg); Error_Detected = true; } -void BacnetGetError( - SV * errorMsg) +void BacnetGetError(SV *errorMsg) { sv_setpv(errorMsg, Last_Error); strcpy(Last_Error, NO_ERROR); Error_Detected = false; } -static void __LogAnswer( - const char *msg, - unsigned append) +static void __LogAnswer(const char *msg, unsigned append) { dSP; ENTER; @@ -61,48 +57,41 @@ static void __LogAnswer( /**************************************/ /* error handlers */ /*************************************/ -static void MyAbortHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t abort_reason, - bool server) +static void MyAbortHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t abort_reason, bool server) { - (void) server; + (void)server; if (address_match(&Target_Address, src) && (invoke_id == Request_Invoke_ID)) { char msg[MAX_ERROR_STRING]; sprintf(msg, "BACnet Abort: %s", - bactext_abort_reason_name((int) abort_reason)); + bactext_abort_reason_name((int)abort_reason)); LogError(msg); } } -static void MyRejectHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t reject_reason) +static void MyRejectHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t reject_reason) { if (address_match(&Target_Address, src) && (invoke_id == Request_Invoke_ID)) { char msg[MAX_ERROR_STRING]; sprintf(msg, "BACnet Reject: %s", - bactext_reject_reason_name((int) reject_reason)); + bactext_reject_reason_name((int)reject_reason)); LogError(msg); } } -static void My_Error_Handler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - BACNET_ERROR_CLASS error_class, - BACNET_ERROR_CODE error_code) +static void My_Error_Handler(BACNET_ADDRESS *src, uint8_t invoke_id, + BACNET_ERROR_CLASS error_class, + BACNET_ERROR_CODE error_code) { if (address_match(&Target_Address, src) && (invoke_id == Request_Invoke_ID)) { char msg[MAX_ERROR_STRING]; sprintf(msg, "BACnet Error: %s: %s", - bactext_error_class_name((int) error_class), - bactext_error_code_name((int) error_code)); + bactext_error_class_name((int)error_class), + bactext_error_code_name((int)error_code)); LogError(msg); } } @@ -115,13 +104,12 @@ static void My_Error_Handler( /* Decode the ReadProperty Ack and pass to perl */ /****************************************/ #define MAX_ACK_STRING 512 -void rp_ack_extract_data( - BACNET_READ_PROPERTY_DATA * data) +void rp_ack_extract_data(BACNET_READ_PROPERTY_DATA *data) { char ackString[MAX_ACK_STRING] = ""; char *pAckString = &ackString[0]; - BACNET_OBJECT_PROPERTY_VALUE object_value; /* for bacapp printing */ - BACNET_APPLICATION_DATA_VALUE value; /* for decode value data */ + BACNET_OBJECT_PROPERTY_VALUE object_value; /* for bacapp printing */ + BACNET_APPLICATION_DATA_VALUE value; /* for decode value data */ int len = 0; uint8_t *application_data; int application_data_len; @@ -134,9 +122,8 @@ void rp_ack_extract_data( /* FIXME: what if application_data_len is bigger than 255? */ /* value? need to loop until all of the len is gone... */ for (;;) { - len = - bacapp_decode_application_data(application_data, - (uint8_t) application_data_len, &value); + len = bacapp_decode_application_data( + application_data, (uint8_t)application_data_len, &value); if (first_value && (len < application_data_len)) { first_value = false; strncat(pAckString, "{", 1); @@ -149,7 +136,8 @@ void rp_ack_extract_data( object_value.array_index = data->array_index; object_value.value = &value; bacapp_snprintf_value(pAckString, - MAX_ACK_STRING - (pAckString - ackString), &object_value); + MAX_ACK_STRING - (pAckString - ackString), + &object_value); if (len > 0) { if (len < application_data_len) { application_data += len; @@ -176,10 +164,9 @@ void rp_ack_extract_data( /*****************************************/ /* Decode the ReadPropertyMultiple Ack and pass to perl */ /****************************************/ -void rpm_ack_extract_data( - BACNET_READ_ACCESS_DATA * rpm_data) +void rpm_ack_extract_data(BACNET_READ_ACCESS_DATA *rpm_data) { - BACNET_OBJECT_PROPERTY_VALUE object_value; /* for bacapp printing */ + BACNET_OBJECT_PROPERTY_VALUE object_value; /* for bacapp printing */ BACNET_PROPERTY_REFERENCE *listOfProperties; BACNET_APPLICATION_DATA_VALUE *value; bool array_value = false; @@ -206,8 +193,8 @@ void rpm_ack_extract_data( object_value.array_index = listOfProperties->propertyArrayIndex; object_value.value = value; - bacapp_snprintf_value(pAckString, - MAX_ACK_STRING - (pAckString - ackString), + bacapp_snprintf_value( + pAckString, MAX_ACK_STRING - (pAckString - ackString), &object_value); if (value->next) { strncat(pAckString, ",", 1); @@ -223,10 +210,10 @@ void rpm_ack_extract_data( } else { /* AccessError */ sprintf(ackString, "BACnet Error: %s: %s", - bactext_error_class_name((int) listOfProperties-> - error.error_class), - bactext_error_code_name((int) listOfProperties-> - error.error_code)); + bactext_error_class_name( + (int)listOfProperties->error.error_class), + bactext_error_code_name( + (int)listOfProperties->error.error_code)); LogError(ackString); } listOfProperties = listOfProperties->next; @@ -243,10 +230,8 @@ void rpm_ack_extract_data( } static void AtomicReadFileAckHandler( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src, - BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data) + uint8_t *service_request, uint16_t service_len, BACNET_ADDRESS *src, + BACNET_CONFIRMED_SERVICE_ACK_DATA *service_data) { int len = 0; BACNET_ATOMIC_READ_FILE_DATA data; @@ -254,8 +239,7 @@ static void AtomicReadFileAckHandler( if (address_match(&Target_Address, src) && (service_data->invoke_id == Request_Invoke_ID)) { len = - arf_ack_decode_service_request(service_request, service_len, - &data); + arf_ack_decode_service_request(service_request, service_len, &data); if (len > 0) { /* validate the parameters before storing data */ if ((data.access == FILE_STREAM_ACCESS) && @@ -265,7 +249,7 @@ static void AtomicReadFileAckHandler( int i; sprintf(msg, "EOF=%d,start=%d,", data.endOfFile, - data.type.stream.fileStartPosition); + data.type.stream.fileStartPosition); __LogAnswer(msg, 0); pFileData = octetstring_value(&data.fileData); @@ -281,7 +265,6 @@ static void AtomicReadFileAckHandler( } } - /** Handler for a ReadProperty ACK. * @ingroup DSRP * Doesn't actually do anything, except, for debugging, to @@ -294,10 +277,8 @@ static void AtomicReadFileAckHandler( * decoded from the APDU header of this message. */ static void My_Read_Property_Ack_Handler( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src, - BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data) + uint8_t *service_request, uint16_t service_len, BACNET_ADDRESS *src, + BACNET_CONFIRMED_SERVICE_ACK_DATA *service_data) { int len = 0; BACNET_READ_PROPERTY_DATA data; @@ -324,10 +305,8 @@ static void My_Read_Property_Ack_Handler( * decoded from the APDU header of this message. */ static void My_Read_Property_Multiple_Ack_Handler( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src, - BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data) + uint8_t *service_request, uint16_t service_len, BACNET_ADDRESS *src, + BACNET_CONFIRMED_SERVICE_ACK_DATA *service_data) { int len = 0; BACNET_READ_ACCESS_DATA *rpm_data; @@ -341,9 +320,8 @@ static void My_Read_Property_Multiple_Ack_Handler( (service_data->invoke_id == Request_Invoke_ID)) { rpm_data = calloc(1, sizeof(BACNET_READ_ACCESS_DATA)); if (rpm_data) { - len = - rpm_ack_decode_service_request(service_request, service_len, - rpm_data); + len = rpm_ack_decode_service_request(service_request, service_len, + rpm_data); } if (len > 0) { while (rpm_data) { @@ -387,9 +365,7 @@ static void My_Read_Property_Multiple_Ack_Handler( } } -void My_Write_Property_SimpleAck_Handler( - BACNET_ADDRESS * src, - uint8_t invoke_id) +void My_Write_Property_SimpleAck_Handler(BACNET_ADDRESS *src, uint8_t invoke_id) { if (address_match(&Target_Address, src) && (invoke_id == Request_Invoke_ID)) { @@ -397,9 +373,7 @@ void My_Write_Property_SimpleAck_Handler( } } - -static void Init_Service_Handlers( - ) +static void Init_Service_Handlers() { Device_Init(NULL); @@ -411,12 +385,11 @@ static void Init_Service_Handlers( /* set the handler for all the services we don't implement It is required to send the proper reject message... */ - apdu_set_unrecognized_service_handler_handler - (handler_unrecognized_service); + apdu_set_unrecognized_service_handler_handler(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 generic errors coming back */ apdu_set_abort_handler(MyAbortHandler); @@ -428,17 +401,15 @@ typedef enum { waitBind, } waitAction; -static void Wait_For_Answer_Or_Timeout( - unsigned timeout_ms, - waitAction action) +static void Wait_For_Answer_Or_Timeout(unsigned timeout_ms, waitAction action) { /* Wait for timeout, failure, or success */ time_t last_seconds = time(NULL); time_t timeout_seconds = (apdu_timeout() / 1000) * apdu_retries(); time_t elapsed_seconds = 0; uint16_t pdu_len = 0; - BACNET_ADDRESS src = { 0 }; /* address where message came from */ - uint8_t Rx_Buf[MAX_MPDU] = { 0 }; + BACNET_ADDRESS src = {0}; /* address where message came from */ + uint8_t Rx_Buf[MAX_MPDU] = {0}; while (true) { time_t current_seconds = time(NULL); @@ -476,7 +447,7 @@ static void Wait_For_Answer_Or_Timeout( } } else if (action == waitBind) { if (address_bind_request(Target_Device_Object_Instance, - &Target_Max_APDU, &Target_Address)) { + &Target_Max_APDU, &Target_Address)) { break; } } else { @@ -497,8 +468,7 @@ static void Wait_For_Answer_Or_Timeout( /****************************************************/ /* This is the most fundamental setup needed to start communication */ /****************************************************/ -void BacnetPrepareComm( - ) +void BacnetPrepareComm() { /* setup my info */ Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE); @@ -511,8 +481,7 @@ void BacnetPrepareComm( /* Try to bind to a device. If successful, return zero. If failure, return */ /* non-zero and log the error details */ /****************************************************/ -int BacnetBindToDevice( - int deviceInstanceNumber) +int BacnetBindToDevice(int deviceInstanceNumber) { int isFailure = 0; @@ -522,9 +491,9 @@ int BacnetBindToDevice( /* try to bind with the device */ if (!address_bind_request(deviceInstanceNumber, &Target_Max_APDU, - &Target_Address)) { + &Target_Address)) { Send_WhoIs(Target_Device_Object_Instance, - Target_Device_Object_Instance); + Target_Device_Object_Instance); /* Wait for timeout, failure, or success */ Wait_For_Answer_Or_Timeout(100, waitBind); @@ -538,29 +507,26 @@ int BacnetBindToDevice( /****************************************************/ /* This is the interface to ReadProperty */ /****************************************************/ -int BacnetReadProperty( - int deviceInstanceNumber, - int objectType, - int objectInstanceNumber, - int objectProperty, - int objectIndex) +int BacnetReadProperty(int deviceInstanceNumber, int objectType, + int objectInstanceNumber, int objectProperty, + int objectIndex) { if (!isReadPropertyHandlerRegistered) { /* handle the data coming back from confirmed requests */ apdu_set_confirmed_ack_handler(SERVICE_CONFIRMED_READ_PROPERTY, - My_Read_Property_Ack_Handler); + My_Read_Property_Ack_Handler); /* handle any errors coming back */ apdu_set_error_handler(SERVICE_CONFIRMED_READ_PROPERTY, - My_Error_Handler); + My_Error_Handler); /* indicate that handlers are now registered */ isReadPropertyHandlerRegistered = true; } /* Send the message out */ - Request_Invoke_ID = - Send_Read_Property_Request(deviceInstanceNumber, objectType, - objectInstanceNumber, objectProperty, objectIndex); + Request_Invoke_ID = Send_Read_Property_Request( + deviceInstanceNumber, objectType, objectInstanceNumber, objectProperty, + objectIndex); Wait_For_Answer_Or_Timeout(100, waitAnswer); int isFailure = Error_Detected; @@ -571,9 +537,7 @@ int BacnetReadProperty( /************************************************/ /* This is the interface to ReadPropertyMultiple */ /************************************************/ -int BacnetReadPropertyMultiple( - int deviceInstanceNumber, - ...) +int BacnetReadPropertyMultiple(int deviceInstanceNumber, ...) { /* Get the variable argument list from the stack */ Inline_Stack_Vars; @@ -582,7 +546,7 @@ int BacnetReadPropertyMultiple( calloc(1, sizeof(BACNET_READ_ACCESS_DATA)); BACNET_READ_ACCESS_DATA *Read_Access_Data = rpm_object; BACNET_PROPERTY_REFERENCE *rpm_property; - uint8_t buffer[MAX_PDU] = { 0 }; + uint8_t buffer[MAX_PDU] = {0}; while (rpmIndex < Inline_Stack_Items) { SV *pSV = Inline_Stack_Item(rpmIndex++); @@ -600,7 +564,7 @@ int BacnetReadPropertyMultiple( break; } - AV *pAV = (AV *) SvRV(pSV); + AV *pAV = (AV *)SvRV(pSV); SV **ppSV; /* The 0th argument is the object type */ @@ -658,20 +622,19 @@ int BacnetReadPropertyMultiple( if (!isReadPropertyMultipleHandlerRegistered) { /* handle the data coming back from confirmed requests */ apdu_set_confirmed_ack_handler(SERVICE_CONFIRMED_READ_PROP_MULTIPLE, - My_Read_Property_Multiple_Ack_Handler); + My_Read_Property_Multiple_Ack_Handler); /* handle any errors coming back */ apdu_set_error_handler(SERVICE_CONFIRMED_READ_PROP_MULTIPLE, - My_Error_Handler); + My_Error_Handler); /* indicate that handlers are now registered */ isReadPropertyMultipleHandlerRegistered = true; } /* Send the message out */ if (!Error_Detected) { - Request_Invoke_ID = - Send_Read_Property_Multiple_Request(&buffer[0], sizeof(buffer), - deviceInstanceNumber, Read_Access_Data); + Request_Invoke_ID = Send_Read_Property_Multiple_Request( + &buffer[0], sizeof(buffer), deviceInstanceNumber, Read_Access_Data); Wait_For_Answer_Or_Timeout(100, waitAnswer); } /* Clean up allocated memory */ @@ -701,27 +664,23 @@ int BacnetReadPropertyMultiple( /****************************************************/ /* This is the interface to WriteProperty */ /****************************************************/ -int BacnetWriteProperty( - int deviceInstanceNumber, - int objectType, - int objectInstanceNumber, - int objectProperty, - int objectPriority, - int objectIndex, - const char *tag, - const char *value) +int BacnetWriteProperty(int deviceInstanceNumber, int objectType, + int objectInstanceNumber, int objectProperty, + int objectPriority, int objectIndex, const char *tag, + const char *value) { char msg[MAX_ERROR_STRING]; int isFailure = 1; if (!isWritePropertyHandlerRegistered) { /* handle the ack coming back */ - apdu_set_confirmed_simple_ack_handler(SERVICE_CONFIRMED_WRITE_PROPERTY, + apdu_set_confirmed_simple_ack_handler( + SERVICE_CONFIRMED_WRITE_PROPERTY, My_Write_Property_SimpleAck_Handler); /* handle any errors coming back */ apdu_set_error_handler(SERVICE_CONFIRMED_WRITE_PROPERTY, - My_Error_Handler); + My_Error_Handler); /* indicate that handlers are now registered */ isWritePropertyHandlerRegistered = true; @@ -748,12 +707,12 @@ int BacnetWriteProperty( if (property_tag >= MAX_BACNET_APPLICATION_TAG) { sprintf(msg, "Error: tag=%u - it must be less than %u", - property_tag, MAX_BACNET_APPLICATION_TAG); + property_tag, MAX_BACNET_APPLICATION_TAG); LogError(msg); break; } if (!bacapp_parse_application_data(property_tag, value, - &propertyValue)) { + &propertyValue)) { sprintf(msg, "Error: unable to parse the tag value"); LogError(msg); break; @@ -761,13 +720,13 @@ int BacnetWriteProperty( propertyValue.next = NULL; /* Send out the message */ - Request_Invoke_ID = - Send_Write_Property_Request(deviceInstanceNumber, objectType, - objectInstanceNumber, objectProperty, &propertyValue, - objectPriority, objectIndex); + Request_Invoke_ID = Send_Write_Property_Request( + deviceInstanceNumber, objectType, objectInstanceNumber, + objectProperty, &propertyValue, objectPriority, objectIndex); Wait_For_Answer_Or_Timeout(100, waitAnswer); - /* If we get here, then there were no explicit failures. However, there */ + /* If we get here, then there were no explicit failures. However, there + */ /* could have been implicit failures. Let's look at those also. */ isFailure = Error_Detected; } while (false); @@ -777,13 +736,9 @@ int BacnetWriteProperty( return isFailure; } - -int BacnetAtomicWriteFile( - int deviceInstanceNumber, - int fileInstanceNumber, - int blockStartAddr, - int blockNumBytes, - char *nibbleBuffer) +int BacnetAtomicWriteFile(int deviceInstanceNumber, int fileInstanceNumber, + int blockStartAddr, int blockNumBytes, + char *nibbleBuffer) { BACNET_OCTET_STRING fileData; int i, nibble; @@ -793,7 +748,7 @@ int BacnetAtomicWriteFile( if (!isAtomicWriteFileHandlerRegistered) { /* handle any errors coming back */ apdu_set_error_handler(SERVICE_CONFIRMED_ATOMIC_WRITE_FILE, - My_Error_Handler); + My_Error_Handler); /* indicate that handlers are now registered */ isAtomicWriteFileHandlerRegistered = true; @@ -817,9 +772,9 @@ int BacnetAtomicWriteFile( /* Send out the message and wait for answer */ if (!Error_Detected) { - Request_Invoke_ID = - Send_Atomic_Write_File_Stream(deviceInstanceNumber, - fileInstanceNumber, blockStartAddr, &fileData); + Request_Invoke_ID = Send_Atomic_Write_File_Stream( + deviceInstanceNumber, fileInstanceNumber, blockStartAddr, + &fileData); Wait_For_Answer_Or_Timeout(100, waitAnswer); } @@ -828,8 +783,7 @@ int BacnetAtomicWriteFile( return isFailure; } -int BacnetGetMaxApdu( - ) +int BacnetGetMaxApdu() { unsigned requestedOctetCount = 0; uint16_t my_max_apdu = 0; @@ -857,16 +811,8 @@ int BacnetGetMaxApdu( return requestedOctetCount; } -int BacnetTimeSync( - int deviceInstanceNumber, - int year, - int month, - int day, - int hour, - int minute, - int second, - int isUTC, - int UTCOffset) +int BacnetTimeSync(int deviceInstanceNumber, int year, int month, int day, + int hour, int minute, int second, int isUTC, int UTCOffset) { BACNET_DATE bdate; BACNET_TIME btime; @@ -880,9 +826,9 @@ int BacnetTimeSync( my_time.tm_mday = day; my_time.tm_mon = month - 1; my_time.tm_year = year - 1900; - my_time.tm_wday = 0; /* does not matter */ - my_time.tm_yday = 0; /* does not matter */ - my_time.tm_isdst = 0; /* does not matter */ + my_time.tm_wday = 0; /* does not matter */ + my_time.tm_yday = 0; /* does not matter */ + my_time.tm_isdst = 0; /* does not matter */ aTime = mktime(&my_time); newTime = localtime(&aTime); @@ -901,7 +847,7 @@ int BacnetTimeSync( int bytes_sent = 0; BACNET_NPDU_DATA npdu_data; BACNET_ADDRESS my_address; - uint8_t Handler_Transmit_Buffer[MAX_PDU] = { 0 }; + uint8_t Handler_Transmit_Buffer[MAX_PDU] = {0}; /* Loop for eary exit */ do { @@ -913,25 +859,22 @@ int BacnetTimeSync( /* encode the NPDU portion of the packet */ npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL); datalink_get_my_address(&my_address); - pdu_len = - npdu_encode_pdu(&Handler_Transmit_Buffer[0], &Target_Address, - &my_address, &npdu_data); + pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], &Target_Address, + &my_address, &npdu_data); /* encode the APDU portion of the packet */ - len = - timesync_encode_apdu(&Handler_Transmit_Buffer[pdu_len], &bdate, - &btime); + len = timesync_encode_apdu(&Handler_Transmit_Buffer[pdu_len], &bdate, + &btime); pdu_len += len; /* send it out the datalink */ - bytes_sent = - datalink_send_pdu(&Target_Address, &npdu_data, - &Handler_Transmit_Buffer[0], pdu_len); + bytes_sent = datalink_send_pdu(&Target_Address, &npdu_data, + &Handler_Transmit_Buffer[0], pdu_len); if (bytes_sent <= 0) { char errorMsg[64]; sprintf(errorMsg, - "Failed to Send Time-Synchronization Request (%s)!", - strerror(errno)); + "Failed to Send Time-Synchronization Request (%s)!", + strerror(errno)); LogError(errorMsg); break; } @@ -947,28 +890,24 @@ int BacnetTimeSync( /****************************************************/ /* This is the interface to AtomicReadFile */ /****************************************************/ -int BacnetAtomicReadFile( - int deviceInstanceNumber, - int fileInstanceNumber, - int startOffset, - int numBytes) +int BacnetAtomicReadFile(int deviceInstanceNumber, int fileInstanceNumber, + int startOffset, int numBytes) { if (!isAtomicReadFileHandlerRegistered) { /* handle the data coming back from confirmed requests */ apdu_set_confirmed_ack_handler(SERVICE_CONFIRMED_ATOMIC_READ_FILE, - AtomicReadFileAckHandler); + AtomicReadFileAckHandler); /* handle any errors coming back */ apdu_set_error_handler(SERVICE_CONFIRMED_ATOMIC_READ_FILE, - My_Error_Handler); + My_Error_Handler); /* indicate that handlers are now registered */ isAtomicReadFileHandlerRegistered = true; } /* Send the message out */ - Request_Invoke_ID = - Send_Atomic_Read_File_Stream(deviceInstanceNumber, fileInstanceNumber, - startOffset, numBytes); + Request_Invoke_ID = Send_Atomic_Read_File_Stream( + deviceInstanceNumber, fileInstanceNumber, startOffset, numBytes); Wait_For_Answer_Or_Timeout(100, waitAnswer); int isFailure = Error_Detected; diff --git a/demo/piface/device.c b/demo/piface/device.c index dfdfd0b6..b0afa3d1 100644 --- a/demo/piface/device.c +++ b/demo/piface/device.c @@ -1,42 +1,42 @@ /************************************************************************** -* -* Copyright (C) 2014 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2014 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include -#include /* for memmove */ -#include /* for timezone, localtime */ +#include /* for memmove */ +#include /* for timezone, localtime */ #include "bacdef.h" #include "bacdcode.h" #include "bacenum.h" #include "bacapp.h" -#include "config.h" /* the custom stuff */ +#include "config.h" /* the custom stuff */ #include "apdu.h" -#include "wp.h" /* WriteProperty handling */ -#include "rp.h" /* ReadProperty handling */ -#include "dcc.h" /* DeviceCommunicationControl handling */ +#include "wp.h" /* WriteProperty handling */ +#include "rp.h" /* ReadProperty handling */ +#include "dcc.h" /* DeviceCommunicationControl handling */ #include "version.h" -#include "device.h" /* me */ +#include "device.h" /* me */ #include "handlers.h" #include "datalink.h" #include "address.h" @@ -51,102 +51,56 @@ #endif /* local forward (semi-private) and external prototypes */ -int Device_Read_Property_Local( - BACNET_READ_PROPERTY_DATA * rpdata); -bool Device_Write_Property_Local( - BACNET_WRITE_PROPERTY_DATA * wp_data); -extern int Routed_Device_Read_Property_Local( - BACNET_READ_PROPERTY_DATA * rpdata); +int Device_Read_Property_Local(BACNET_READ_PROPERTY_DATA *rpdata); +bool Device_Write_Property_Local(BACNET_WRITE_PROPERTY_DATA *wp_data); +extern int Routed_Device_Read_Property_Local(BACNET_READ_PROPERTY_DATA *rpdata); extern bool Routed_Device_Write_Property_Local( - BACNET_WRITE_PROPERTY_DATA * wp_data); + BACNET_WRITE_PROPERTY_DATA *wp_data); /* may be overridden by outside table */ static object_functions_t *Object_Table; static object_functions_t My_Object_Table[] = { - {OBJECT_DEVICE, - NULL /* Init - don't init Device or it will recourse! */ , - Device_Count, - Device_Index_To_Instance, - Device_Valid_Object_Instance_Number, - Device_Object_Name, - Device_Read_Property_Local, - Device_Write_Property_Local, - Device_Property_Lists, - DeviceGetRRInfo, - NULL /* Iterator */ , - NULL /* Value_Lists */ , - NULL /* COV */ , - NULL /* COV Clear */ , - NULL /* Intrinsic Reporting */ }, + {OBJECT_DEVICE, NULL /* Init - don't init Device or it will recourse! */, + Device_Count, Device_Index_To_Instance, + Device_Valid_Object_Instance_Number, Device_Object_Name, + Device_Read_Property_Local, Device_Write_Property_Local, + Device_Property_Lists, DeviceGetRRInfo, NULL /* Iterator */, + NULL /* Value_Lists */, NULL /* COV */, NULL /* COV Clear */, + NULL /* Intrinsic Reporting */}, #if (BACNET_PROTOCOL_REVISION >= 17) - {OBJECT_NETWORK_PORT, - Network_Port_Init, - Network_Port_Count, - Network_Port_Index_To_Instance, - Network_Port_Valid_Instance, - Network_Port_Object_Name, - Network_Port_Read_Property, - Network_Port_Write_Property, - Network_Port_Property_Lists, - NULL /* ReadRangeInfo */ , - NULL /* Iterator */ , - NULL /* Value_Lists */ , - NULL /* COV */ , - NULL /* COV Clear */ , - NULL /* Intrinsic Reporting */ }, + {OBJECT_NETWORK_PORT, Network_Port_Init, Network_Port_Count, + Network_Port_Index_To_Instance, Network_Port_Valid_Instance, + Network_Port_Object_Name, Network_Port_Read_Property, + Network_Port_Write_Property, Network_Port_Property_Lists, + NULL /* ReadRangeInfo */, NULL /* Iterator */, NULL /* Value_Lists */, + NULL /* COV */, NULL /* COV Clear */, NULL /* Intrinsic Reporting */}, #endif - {OBJECT_BINARY_INPUT, - Binary_Input_Init, - Binary_Input_Count, - Binary_Input_Index_To_Instance, - Binary_Input_Valid_Instance, - Binary_Input_Object_Name, - Binary_Input_Read_Property, - Binary_Input_Write_Property, - Binary_Input_Property_Lists, - NULL /* ReadRangeInfo */ , - NULL /* Iterator */ , - Binary_Input_Encode_Value_List, - Binary_Input_Change_Of_Value, - Binary_Input_Change_Of_Value_Clear, - NULL /* Intrinsic Reporting */ }, - {OBJECT_BINARY_OUTPUT, - Binary_Output_Init, - Binary_Output_Count, - Binary_Output_Index_To_Instance, - Binary_Output_Valid_Instance, - Binary_Output_Object_Name, - Binary_Output_Read_Property, - Binary_Output_Write_Property, - Binary_Output_Property_Lists, - NULL /* ReadRangeInfo */ , - NULL /* Iterator */ , - NULL /* Value_Lists */ , - NULL /* COV */ , - NULL /* COV Clear */ , - NULL /* Intrinsic Reporting */ }, - {MAX_BACNET_OBJECT_TYPE, - NULL /* Init */ , - NULL /* Count */ , - NULL /* Index_To_Instance */ , - NULL /* Valid_Instance */ , - NULL /* Object_Name */ , - NULL /* Read_Property */ , - NULL /* Write_Property */ , - NULL /* Property_Lists */ , - NULL /* ReadRangeInfo */ , - NULL /* Iterator */ , - NULL /* Value_Lists */ , - NULL /* COV */ , - NULL /* COV Clear */ , - NULL /* Intrinsic Reporting */ } -}; + {OBJECT_BINARY_INPUT, Binary_Input_Init, Binary_Input_Count, + Binary_Input_Index_To_Instance, Binary_Input_Valid_Instance, + Binary_Input_Object_Name, Binary_Input_Read_Property, + Binary_Input_Write_Property, Binary_Input_Property_Lists, + NULL /* ReadRangeInfo */, NULL /* Iterator */, + Binary_Input_Encode_Value_List, Binary_Input_Change_Of_Value, + Binary_Input_Change_Of_Value_Clear, NULL /* Intrinsic Reporting */}, + {OBJECT_BINARY_OUTPUT, Binary_Output_Init, Binary_Output_Count, + Binary_Output_Index_To_Instance, Binary_Output_Valid_Instance, + Binary_Output_Object_Name, Binary_Output_Read_Property, + Binary_Output_Write_Property, Binary_Output_Property_Lists, + NULL /* ReadRangeInfo */, NULL /* Iterator */, NULL /* Value_Lists */, + NULL /* COV */, NULL /* COV Clear */, NULL /* Intrinsic Reporting */}, + {MAX_BACNET_OBJECT_TYPE, NULL /* Init */, NULL /* Count */, + NULL /* Index_To_Instance */, NULL /* Valid_Instance */, + NULL /* Object_Name */, NULL /* Read_Property */, + NULL /* Write_Property */, NULL /* Property_Lists */, + NULL /* ReadRangeInfo */, NULL /* Iterator */, NULL /* Value_Lists */, + NULL /* COV */, NULL /* COV Clear */, NULL /* Intrinsic Reporting */}}; /** Glue function to let the Device object, when called by a handler, * lookup which Object type needs to be invoked. * @ingroup ObjHelpers - * @param Object_Type [in] The type of BACnet Object the handler wants to access. + * @param Object_Type [in] The type of BACnet Object the handler wants to + * access. * @return Pointer to the group of object helper functions that implement this * type of Object. */ @@ -167,17 +121,18 @@ static struct object_functions *Device_Objects_Find_Functions( return (NULL); } -/** Try to find a rr_info_function helper function for the requested object type. +/** Try to find a rr_info_function helper function for the requested object + * type. * @ingroup ObjIntf * - * @param object_type [in] The type of BACnet Object the handler wants to access. + * @param object_type [in] The type of BACnet Object the handler wants to + * access. * @return Pointer to the object helper function that implements the * ReadRangeInfo function, Object_RR_Info, for this type of Object on * success, else a NULL pointer if the type of Object isn't supported * or doesn't have a ReadRangeInfo function. */ -rr_info_function Device_Objects_RR_Info( - BACNET_OBJECT_TYPE object_type) +rr_info_function Device_Objects_RR_Info(BACNET_OBJECT_TYPE object_type) { struct object_functions *pObject = NULL; @@ -196,10 +151,9 @@ rr_info_function Device_Objects_RR_Info( * list, separately, the Required, Optional, and Proprietary object * properties with their counts. */ -void Device_Objects_Property_List( - BACNET_OBJECT_TYPE object_type, - uint32_t object_instance, - struct special_property_list_t *pPropertyList) +void Device_Objects_Property_List(BACNET_OBJECT_TYPE object_type, + uint32_t object_instance, + struct special_property_list_t *pPropertyList) { struct object_functions *pObject = NULL; @@ -216,21 +170,25 @@ 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); + &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.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.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.pList == NULL + ? 0 + : property_list_count(pPropertyList->Proprietary.pList); return; } @@ -257,8 +215,7 @@ static const int Device_Properties_Required[] = { PROP_NUMBER_OF_APDU_RETRIES, PROP_DEVICE_ADDRESS_BINDING, PROP_DATABASE_REVISION, - -1 -}; + -1}; static const int Device_Properties_Optional[] = { #if defined(BACDL_MSTP) @@ -272,17 +229,12 @@ static const int Device_Properties_Optional[] = { PROP_DAYLIGHT_SAVINGS_STATUS, PROP_LOCATION, PROP_ACTIVE_COV_SUBSCRIPTIONS, - -1 -}; + -1}; -static const int Device_Properties_Proprietary[] = { - -1 -}; +static const int Device_Properties_Proprietary[] = {-1}; -void Device_Property_Lists( - const int **pRequired, - const int **pOptional, - const int **pProprietary) +void Device_Property_Lists(const int **pRequired, const int **pOptional, + const int **pProprietary) { if (pRequired) *pRequired = Device_Properties_Required; @@ -317,14 +269,14 @@ static char Description[MAX_DEV_DESC_LEN + 1] = "Raspberry PiFace Digital Demo"; /* 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. BACnet UTC offset is expressed in minutes. */ static int32_t UTC_Offset = 5 * 60; -static bool Daylight_Savings_Status = false; /* rely on OS */ +static bool Daylight_Savings_Status = false; /* rely on OS */ /* List_Of_Session_Keys */ /* Time_Synchronization_Recipients */ /* Max_Master - rely on MS/TP subsystem, if there is one */ @@ -356,8 +308,7 @@ static const char *Reinit_Password = "raspberry"; * 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; @@ -400,20 +351,17 @@ bool Device_Reinitialize( return status; } -BACNET_REINITIALIZED_STATE Device_Reinitialized_State( - void) +BACNET_REINITIALIZED_STATE Device_Reinitialized_State(void) { return Reinitialize_State; } -unsigned Device_Count( - void) +unsigned Device_Count(void) { return 1; } -uint32_t Device_Index_To_Instance( - unsigned index) +uint32_t Device_Index_To_Instance(unsigned index) { index = index; return Object_Instance_Number; @@ -427,8 +375,7 @@ uint32_t Device_Index_To_Instance( * @ingroup ObjIntf * @return The Instance number used in the BACNET_OBJECT_ID for the Device. */ -uint32_t Device_Object_Instance_Number( - void) +uint32_t Device_Object_Instance_Number(void) { #ifdef BAC_ROUTING return Routed_Device_Object_Instance_Number(); @@ -437,8 +384,7 @@ uint32_t Device_Object_Instance_Number( #endif } -bool Device_Set_Object_Instance_Number( - uint32_t object_id) +bool Device_Set_Object_Instance_Number(uint32_t object_id) { bool status = true; /* return value */ @@ -452,15 +398,13 @@ bool Device_Set_Object_Instance_Number( return status; } -bool Device_Valid_Object_Instance_Number( - uint32_t object_id) +bool Device_Valid_Object_Instance_Number(uint32_t object_id) { return (Object_Instance_Number == object_id); } -bool Device_Object_Name( - uint32_t object_instance, - BACNET_CHARACTER_STRING * object_name) +bool Device_Object_Name(uint32_t object_instance, + BACNET_CHARACTER_STRING *object_name) { bool status = false; @@ -471,10 +415,9 @@ bool Device_Object_Name( return status; } -bool Device_Set_Object_Name( - BACNET_CHARACTER_STRING * object_name) +bool Device_Set_Object_Name(BACNET_CHARACTER_STRING *object_name) { - bool status = false; /*return value */ + bool status = false; /*return value */ if (!characterstring_same(&My_Object_Name, object_name)) { /* Make the change and update the database revision */ @@ -485,17 +428,14 @@ bool Device_Set_Object_Name( return status; } -BACNET_DEVICE_STATUS Device_System_Status( - void) +BACNET_DEVICE_STATUS Device_System_Status(void) { return System_Status; } -int Device_Set_System_Status( - BACNET_DEVICE_STATUS status, - bool local) +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. */ @@ -556,39 +496,34 @@ int Device_Set_System_Status( return (result); } -const char *Device_Vendor_Name( - void) +const char *Device_Vendor_Name(void) { return Vendor_Name; } /** Returns the Vendor ID for this Device. - * See the assignments at http://www.bacnet.org/VendorID/BACnet%20Vendor%20IDs.htm + * See the assignments at + * http://www.bacnet.org/VendorID/BACnet%20Vendor%20IDs.htm * @return The Vendor ID of this Device. */ -uint16_t Device_Vendor_Identifier( - void) +uint16_t Device_Vendor_Identifier(void) { return Vendor_Identifier; } -void Device_Set_Vendor_Identifier( - uint16_t vendor_id) +void Device_Set_Vendor_Identifier(uint16_t vendor_id) { Vendor_Identifier = vendor_id; } -const char *Device_Model_Name( - void) +const char *Device_Model_Name(void) { return Model_Name; } -bool Device_Set_Model_Name( - const char *name, - size_t length) +bool Device_Set_Model_Name(const char *name, size_t length) { - bool status = false; /*return value */ + bool status = false; /*return value */ if (length < sizeof(Model_Name)) { memmove(Model_Name, name, length); @@ -599,23 +534,19 @@ bool Device_Set_Model_Name( return status; } -const char *Device_Firmware_Revision( - void) +const char *Device_Firmware_Revision(void) { return BACnet_Version; } -const char *Device_Application_Software_Version( - void) +const char *Device_Application_Software_Version(void) { return Application_Software_Version; } -bool Device_Set_Application_Software_Version( - const char *name, - size_t length) +bool Device_Set_Application_Software_Version(const char *name, size_t length) { - bool status = false; /*return value */ + bool status = false; /*return value */ if (length < sizeof(Application_Software_Version)) { memmove(Application_Software_Version, name, length); @@ -626,17 +557,14 @@ bool Device_Set_Application_Software_Version( return status; } -const char *Device_Description( - void) +const char *Device_Description(void) { return Description; } -bool Device_Set_Description( - const char *name, - size_t length) +bool Device_Set_Description(const char *name, size_t length) { - bool status = false; /*return value */ + bool status = false; /*return value */ if (length < sizeof(Description)) { memmove(Description, name, length); @@ -647,17 +575,14 @@ bool Device_Set_Description( return status; } -const char *Device_Location( - void) +const char *Device_Location(void) { return Location; } -bool Device_Set_Location( - const char *name, - size_t length) +bool Device_Set_Location(const char *name, size_t length) { - bool status = false; /*return value */ + bool status = false; /*return value */ if (length < sizeof(Location)) { memmove(Location, name, length); @@ -668,32 +593,27 @@ bool Device_Set_Location( return status; } -uint8_t Device_Protocol_Version( - void) +uint8_t Device_Protocol_Version(void) { return BACNET_PROTOCOL_VERSION; } -uint8_t Device_Protocol_Revision( - void) +uint8_t Device_Protocol_Revision(void) { return BACNET_PROTOCOL_REVISION; } -BACNET_SEGMENTATION Device_Segmentation_Supported( - void) +BACNET_SEGMENTATION Device_Segmentation_Supported(void) { return SEGMENTATION_NONE; } -uint32_t Device_Database_Revision( - void) +uint32_t Device_Database_Revision(void) { return Database_Revision; } -void Device_Set_Database_Revision( - uint32_t revision) +void Device_Set_Database_Revision(uint32_t revision) { Database_Revision = revision; } @@ -703,8 +623,7 @@ void Device_Set_Database_Revision( * the most common operation if changing object names and ids is * implemented. */ -void Device_Inc_Database_Revision( - void) +void Device_Inc_Database_Revision(void) { Database_Revision++; } @@ -714,8 +633,7 @@ void Device_Inc_Database_Revision( * for discovery, it must be consistent! * @return The count of objects, for all supported Object types. */ -unsigned Device_Object_List_Count( - void) +unsigned Device_Object_List_Count(void) { unsigned count = 0; /* number of objects */ struct object_functions *pObject = NULL; @@ -742,10 +660,8 @@ unsigned Device_Object_List_Count( * @param instance [out] The object's instance number, if found. * @return True if found, else false. */ -bool Device_Object_List_Identifier( - uint32_t array_index, - int *object_type, - uint32_t * instance) +bool Device_Object_List_Identifier(uint32_t array_index, int *object_type, + uint32_t *instance) { bool status = false; uint32_t count = 0; @@ -769,19 +685,19 @@ bool Device_Object_List_Identifier( * look for the index to instance to get the ID */ if (pObject->Object_Iterator) { /* First find the first object */ - temp_index = pObject->Object_Iterator(~(unsigned) 0); + temp_index = pObject->Object_Iterator(~(unsigned)0); /* Then step through the objects to find the nth */ while (object_index != 0) { temp_index = pObject->Object_Iterator(temp_index); object_index--; } - /* set the object_index up before falling through to next bit */ + /* 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); + *instance = pObject->Object_Index_To_Instance(object_index); status = true; break; } @@ -798,13 +714,12 @@ bool Device_Object_List_Identifier( * and the lookup succeeds, they will be given the resulting values. * @param object_name [in] The desired Object Name to look for. * @param object_type [out] The BACNET_OBJECT_TYPE of the matching Object. - * @param object_instance [out] The object instance number of the matching Object. + * @param object_instance [out] The object instance number of the matching + * Object. * @return True on success or else False if not found. */ -bool Device_Valid_Object_Name( - BACNET_CHARACTER_STRING * object_name1, - int *object_type, - uint32_t * object_instance) +bool Device_Valid_Object_Name(BACNET_CHARACTER_STRING *object_name1, + int *object_type, uint32_t *object_instance) { bool found = false; int type = 0; @@ -821,7 +736,7 @@ bool Device_Valid_Object_Name( pObject = Device_Objects_Find_Functions(type); if ((pObject != NULL) && (pObject->Object_Name != NULL) && (pObject->Object_Name(instance, &object_name2) && - characterstring_same(object_name1, &object_name2))) { + characterstring_same(object_name1, &object_name2))) { found = true; if (object_type) { *object_type = type; @@ -842,11 +757,9 @@ bool Device_Valid_Object_Name( * @param object_instance [in] The object instance number to be looked up. * @return True if found, else False if no such Object in this device. */ -bool Device_Valid_Object_Id( - int object_type, - uint32_t object_instance) +bool Device_Valid_Object_Id(int object_type, uint32_t object_instance) { - bool status = false; /* return value */ + bool status = false; /* return value */ struct object_functions *pObject = NULL; pObject = Device_Objects_Find_Functions(object_type); @@ -863,10 +776,9 @@ bool Device_Valid_Object_Id( * @param object_name [out] The Object Name found for this child Object. * @return True on success or else False if not found. */ -bool Device_Object_Name_Copy( - BACNET_OBJECT_TYPE object_type, - uint32_t object_instance, - BACNET_CHARACTER_STRING * object_name) +bool Device_Object_Name_Copy(BACNET_OBJECT_TYPE object_type, + uint32_t object_instance, + BACNET_CHARACTER_STRING *object_name) { struct object_functions *pObject = NULL; bool found = false; @@ -879,8 +791,7 @@ bool Device_Object_Name_Copy( return found; } -static void Update_Current_Time( - void) +static void Update_Current_Time(void) { struct tm *tblock = NULL; #if defined(_MSC_VER) @@ -911,15 +822,16 @@ int tm_isdst Daylight Savings flag. #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); + 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)); + 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); + 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; @@ -935,8 +847,7 @@ int tm_isdst Daylight Savings flag. } } -void Device_getCurrentDateTime( - BACNET_DATE_TIME * DateTime) +void Device_getCurrentDateTime(BACNET_DATE_TIME *DateTime) { Update_Current_Time(); @@ -958,13 +869,12 @@ bool Device_Daylight_Savings_Status(void) /* return the length of the apdu encoded or BACNET_STATUS_ERROR for error or BACNET_STATUS_ABORT for abort message */ -int Device_Read_Property_Local( - BACNET_READ_PROPERTY_DATA * rpdata) +int Device_Read_Property_Local(BACNET_READ_PROPERTY_DATA *rpdata) { - int apdu_len = 0; /* return value */ - int len = 0; /* apdu len intermediate value */ - BACNET_BIT_STRING bit_string = { 0 }; - BACNET_CHARACTER_STRING char_string = { 0 }; + int apdu_len = 0; /* return value */ + int len = 0; /* apdu len intermediate value */ + BACNET_BIT_STRING bit_string = {0}; + BACNET_CHARACTER_STRING char_string = {0}; uint32_t i = 0; int object_type = 0; uint32_t instance = 0; @@ -982,9 +892,8 @@ int Device_Read_Property_Local( apdu_max = rpdata->application_data_len; switch (rpdata->object_property) { case PROP_OBJECT_IDENTIFIER: - apdu_len = - encode_application_object_id(&apdu[0], OBJECT_DEVICE, - Object_Instance_Number); + apdu_len = encode_application_object_id(&apdu[0], OBJECT_DEVICE, + Object_Instance_Number); break; case PROP_OBJECT_NAME: apdu_len = @@ -1007,8 +916,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], Vendor_Identifier); + apdu_len = encode_application_unsigned(&apdu[0], Vendor_Identifier); break; case PROP_MODEL_NAME: characterstring_init_ansi(&char_string, Model_Name); @@ -1022,7 +930,7 @@ int Device_Read_Property_Local( break; case PROP_APPLICATION_SOFTWARE_VERSION: characterstring_init_ansi(&char_string, - Application_Software_Version); + Application_Software_Version); apdu_len = encode_application_character_string(&apdu[0], &char_string); break; @@ -1049,22 +957,21 @@ int Device_Read_Property_Local( encode_application_boolean(&apdu[0], Daylight_Savings_Status); break; case PROP_PROTOCOL_VERSION: - apdu_len = - encode_application_unsigned(&apdu[0], - Device_Protocol_Version()); + apdu_len = encode_application_unsigned(&apdu[0], + Device_Protocol_Version()); break; case PROP_PROTOCOL_REVISION: - apdu_len = - encode_application_unsigned(&apdu[0], - Device_Protocol_Revision()); + apdu_len = encode_application_unsigned(&apdu[0], + Device_Protocol_Revision()); break; case PROP_PROTOCOL_SERVICES_SUPPORTED: /* Note: list of services that are executed, not initiated. */ bitstring_init(&bit_string); for (i = 0; i < MAX_BACNET_SERVICES_SUPPORTED; i++) { /* automatic lookup based on handlers set */ - bitstring_set_bit(&bit_string, (uint8_t) i, - apdu_service_supported((BACNET_SERVICES_SUPPORTED) i)); + bitstring_set_bit( + &bit_string, (uint8_t)i, + apdu_service_supported((BACNET_SERVICES_SUPPORTED)i)); } apdu_len = encode_application_bitstring(&apdu[0], &bit_string); break; @@ -1074,7 +981,7 @@ int Device_Read_Property_Local( bitstring_init(&bit_string); for (i = 0; i < MAX_ASHRAE_OBJECT_TYPE; i++) { /* initialize all the object types to not-supported */ - bitstring_set_bit(&bit_string, (uint8_t) i, false); + bitstring_set_bit(&bit_string, (uint8_t)i, false); } /* set the object types with objects to supported */ @@ -1098,16 +1005,15 @@ 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], - object_type, instance); + len = encode_application_object_id( + &apdu[apdu_len], object_type, instance); apdu_len += len; /* assume next one is the same size as this one */ - /* can we all fit into the APDU? Don't check for last entry */ + /* can we all fit into the APDU? Don't check for last + * entry */ if ((i != count) && (apdu_len + len) >= apdu_max) { /* Abort response */ rpdata->error_code = @@ -1124,13 +1030,11 @@ 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, - instance); + apdu_len = encode_application_object_id( + &apdu[0], object_type, instance); } else { rpdata->error_class = ERROR_CLASS_PROPERTY; rpdata->error_code = ERROR_CODE_INVALID_ARRAY_INDEX; @@ -1142,9 +1046,8 @@ int Device_Read_Property_Local( apdu_len = encode_application_unsigned(&apdu[0], MAX_APDU); break; case PROP_SEGMENTATION_SUPPORTED: - apdu_len = - encode_application_enumerated(&apdu[0], - Device_Segmentation_Supported()); + apdu_len = encode_application_enumerated( + &apdu[0], Device_Segmentation_Supported()); break; case PROP_APDU_TIMEOUT: apdu_len = encode_application_unsigned(&apdu[0], apdu_timeout()); @@ -1156,14 +1059,12 @@ int Device_Read_Property_Local( apdu_len = address_list_encode(&apdu[0], apdu_max); break; case PROP_DATABASE_REVISION: - apdu_len = - encode_application_unsigned(&apdu[0], Database_Revision); + apdu_len = encode_application_unsigned(&apdu[0], Database_Revision); break; #if defined(BACDL_MSTP) case PROP_MAX_INFO_FRAMES: apdu_len = - encode_application_unsigned(&apdu[0], - dlmstp_max_info_frames()); + encode_application_unsigned(&apdu[0], dlmstp_max_info_frames()); break; case PROP_MAX_MASTER: apdu_len = @@ -1190,7 +1091,8 @@ int Device_Read_Property_Local( return apdu_len; } -/** Looks up the requested Object and Property, and encodes its Value in an APDU. +/** Looks up the requested Object and Property, and encodes its Value in an + * APDU. * @ingroup ObjIntf * If the Object or Property can't be found, sets the error class and code. * @@ -1198,8 +1100,7 @@ int Device_Read_Property_Local( * on entry, and APDU message on return. * @return The length of the APDU on success, else BACNET_STATUS_ERROR */ -int Device_Read_Property( - BACNET_READ_PROPERTY_DATA * rpdata) +int Device_Read_Property(BACNET_READ_PROPERTY_DATA *rpdata) { int apdu_len = BACNET_STATUS_ERROR; struct object_functions *pObject = NULL; @@ -1221,10 +1122,9 @@ int Device_Read_Property( } /* returns true if successful */ -bool Device_Write_Property_Local( - BACNET_WRITE_PROPERTY_DATA * wp_data) +bool Device_Write_Property_Local(BACNET_WRITE_PROPERTY_DATA *wp_data) { - bool status = false; /* return value */ + bool status = false; /* return value */ int len = 0; BACNET_APPLICATION_DATA_VALUE value; int object_type = 0; @@ -1232,9 +1132,8 @@ bool Device_Write_Property_Local( int temp; /* decode the some of the request */ - len = - bacapp_decode_application_data(wp_data->application_data, - wp_data->application_data_len, &value); + len = bacapp_decode_application_data(wp_data->application_data, + wp_data->application_data_len, &value); if (len < 0) { /* error while decoding - a value larger than we can handle */ wp_data->error_class = ERROR_CLASS_PROPERTY; @@ -1253,12 +1152,13 @@ bool Device_Write_Property_Local( case PROP_OBJECT_IDENTIFIER: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_OBJECT_ID, - &wp_data->error_class, &wp_data->error_code); + &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))) { - /* FIXME: we could send an I-Am broadcast to let the world know */ + (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; wp_data->error_class = ERROR_CLASS_PROPERTY; @@ -1269,38 +1169,37 @@ bool Device_Write_Property_Local( case PROP_NUMBER_OF_APDU_RETRIES: status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { /* FIXME: bounds check? */ - apdu_retries_set((uint8_t) value.type.Unsigned_Int); + 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); + &wp_data->error_class, &wp_data->error_code); if (status) { /* FIXME: bounds check? */ - apdu_timeout_set((uint16_t) value.type.Unsigned_Int); + 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); + &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); + &wp_data->error_class, &wp_data->error_code); if (status) { - temp = Device_Set_System_Status((BACNET_DEVICE_STATUS) - value.type.Enumerated, false); + temp = Device_Set_System_Status( + (BACNET_DEVICE_STATUS)value.type.Enumerated, false); if (temp != 0) { status = false; wp_data->error_class = ERROR_CLASS_PROPERTY; @@ -1314,14 +1213,13 @@ bool Device_Write_Property_Local( } break; case PROP_OBJECT_NAME: - status = - WPValidateString(&value, - characterstring_capacity(&My_Object_Name), false, + status = WPValidateString( + &value, characterstring_capacity(&My_Object_Name), false, &wp_data->error_class, &wp_data->error_code); if (status) { /* All the object names in a device must be unique */ if (Device_Valid_Object_Name(&value.type.Character_String, - &object_type, &object_instance)) { + &object_type, &object_instance)) { if ((object_type == wp_data->object_type) && (object_instance == wp_data->object_instance)) { /* writing same name to same object */ @@ -1339,10 +1237,10 @@ bool Device_Write_Property_Local( case PROP_LOCATION: status = WPValidateString(&value, MAX_DEV_LOC_LEN, true, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { - Device_Set_Location(characterstring_value(&value. - type.Character_String), + Device_Set_Location( + characterstring_value(&value.type.Character_String), characterstring_length(&value.type.Character_String)); } break; @@ -1350,20 +1248,20 @@ bool Device_Write_Property_Local( case PROP_DESCRIPTION: status = WPValidateString(&value, MAX_DEV_DESC_LEN, true, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { - Device_Set_Description(characterstring_value(&value. - type.Character_String), + Device_Set_Description( + characterstring_value(&value.type.Character_String), characterstring_length(&value.type.Character_String)); } break; case PROP_MODEL_NAME: status = WPValidateString(&value, MAX_DEV_MOD_LEN, true, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { - Device_Set_Model_Name(characterstring_value(&value. - type.Character_String), + Device_Set_Model_Name( + characterstring_value(&value.type.Character_String), characterstring_length(&value.type.Character_String)); } break; @@ -1372,11 +1270,11 @@ bool Device_Write_Property_Local( #if defined(BACDL_MSTP) status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, - &wp_data->error_class, &wp_data->error_code); + &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; @@ -1389,11 +1287,11 @@ bool Device_Write_Property_Local( #if defined(BACDL_MSTP) status = WPValidateArgType(&value, BACNET_APPLICATION_TAG_UNSIGNED_INT, - &wp_data->error_class, &wp_data->error_code); + &wp_data->error_class, &wp_data->error_code); if (status) { if ((value.type.Unsigned_Int > 0) && (value.type.Unsigned_Int <= 127)) { - dlmstp_set_max_master((uint8_t) value.type.Unsigned_Int); + dlmstp_set_max_master((uint8_t)value.type.Unsigned_Int); } else { status = false; wp_data->error_class = ERROR_CLASS_PROPERTY; @@ -1441,10 +1339,9 @@ bool Device_Write_Property_Local( * and new Value on entry, and APDU message on return. * @return True on success, else False if there is an error. */ -bool Device_Write_Property( - BACNET_WRITE_PROPERTY_DATA * wp_data) +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 */ @@ -1480,12 +1377,11 @@ bool Device_Write_Property( * @param [out] The value list * @return True if the object instance supports this feature and value changed. */ -bool Device_Encode_Value_List( - BACNET_OBJECT_TYPE object_type, - uint32_t object_instance, - BACNET_PROPERTY_VALUE * value_list) +bool Device_Encode_Value_List(BACNET_OBJECT_TYPE object_type, + uint32_t object_instance, + BACNET_PROPERTY_VALUE *value_list) { - bool status = false; /* Ever the pessamist! */ + bool status = false; /* Ever the pessamist! */ struct object_functions *pObject = NULL; pObject = Device_Objects_Find_Functions(object_type); @@ -1508,11 +1404,9 @@ bool Device_Encode_Value_List( * @param [in] The object instance to be looked up. * @return True if the COV flag is set */ -bool Device_COV( - BACNET_OBJECT_TYPE object_type, - uint32_t object_instance) +bool Device_COV(BACNET_OBJECT_TYPE object_type, uint32_t object_instance) { - bool status = false; /* Ever the pessamist! */ + bool status = false; /* Ever the pessamist! */ struct object_functions *pObject = NULL; pObject = Device_Objects_Find_Functions(object_type); @@ -1533,9 +1427,7 @@ bool Device_COV( * @param [in] The object type to be looked up. * @param [in] The object instance to be looked up. */ -void Device_COV_Clear( - BACNET_OBJECT_TYPE object_type, - uint32_t object_instance) +void Device_COV_Clear(BACNET_OBJECT_TYPE object_type, uint32_t object_instance) { struct object_functions *pObject = NULL; @@ -1551,8 +1443,7 @@ void Device_COV_Clear( } #if defined(INTRINSIC_REPORTING) -void Device_local_reporting( - void) +void Device_local_reporting(void) { struct object_functions *pObject; uint32_t objects_count; @@ -1584,10 +1475,9 @@ void Device_local_reporting( * @param [in] The object type to be looked up. * @return True if the object instance supports this feature. */ -bool Device_Value_List_Supported( - BACNET_OBJECT_TYPE object_type) +bool Device_Value_List_Supported(BACNET_OBJECT_TYPE object_type) { - bool status = false; /* Ever the pessamist! */ + bool status = false; /* Ever the pessamist! */ struct object_functions *pObject = NULL; pObject = Device_Objects_Find_Functions(object_type); @@ -1608,8 +1498,7 @@ bool Device_Value_List_Supported( * Each Child Object must provide some implementation of each of these * functions in order to properly support the default handlers. */ -void Device_Init( - object_functions_t * object_table) +void Device_Init(object_functions_t *object_table) { struct object_functions *pObject = NULL; #if defined(BAC_UCI) @@ -1644,11 +1533,10 @@ 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 */ +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) { case PROP_VT_CLASSES_SUPPORTED: @@ -1684,7 +1572,6 @@ bool DeviceGetRRInfo( return status; } - #ifdef BAC_ROUTING /**************************************************************************** ************* BACnet Routing Functionality (Optional) ********************** @@ -1700,8 +1587,7 @@ bool DeviceGetRRInfo( * @param first_object_instance Set the first (gateway) Device to this instance number. */ -void Routing_Device_Init( - uint32_t first_object_instance) +void Routing_Device_Init(uint32_t first_object_instance) { struct object_functions *pDevObject = NULL; @@ -1720,17 +1606,14 @@ void Routing_Device_Init( #endif /* BAC_ROUTING */ - #ifdef TEST #include #include #include "ctest.h" -bool WPValidateArgType( - BACNET_APPLICATION_DATA_VALUE * pValue, - uint8_t ucExpectedTag, - BACNET_ERROR_CLASS * pErrorClass, - BACNET_ERROR_CODE * pErrorCode) +bool WPValidateArgType(BACNET_APPLICATION_DATA_VALUE *pValue, + uint8_t ucExpectedTag, BACNET_ERROR_CLASS *pErrorClass, + BACNET_ERROR_CODE *pErrorCode) { pValue = pValue; ucExpectedTag = ucExpectedTag; @@ -1740,12 +1623,9 @@ bool WPValidateArgType( return false; } -bool WPValidateString( - BACNET_APPLICATION_DATA_VALUE * pValue, - int iMaxLen, - bool bEmptyAllowed, - BACNET_ERROR_CLASS * pErrorClass, - BACNET_ERROR_CODE * pErrorCode) +bool WPValidateString(BACNET_APPLICATION_DATA_VALUE *pValue, int iMaxLen, + bool bEmptyAllowed, BACNET_ERROR_CLASS *pErrorClass, + BACNET_ERROR_CODE *pErrorCode) { pValue = pValue; iMaxLen = iMaxLen; @@ -1756,9 +1636,7 @@ bool WPValidateString( return false; } -int handler_cov_encode_subscriptions( - uint8_t * apdu, - int max_apdu) +int handler_cov_encode_subscriptions(uint8_t *apdu, int max_apdu) { apdu = apdu; max_apdu = max_apdu; @@ -1766,8 +1644,7 @@ int handler_cov_encode_subscriptions( return 0; } -void testDevice( - Test * pTest) +void testDevice(Test *pTest) { bool status = false; const char *name = "Patricia"; @@ -1780,14 +1657,13 @@ void testDevice( ct_test(pTest, status == true); status = Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE / 2); ct_test(pTest, - Device_Object_Instance_Number() == (BACNET_MAX_INSTANCE / 2)); + Device_Object_Instance_Number() == (BACNET_MAX_INSTANCE / 2)); ct_test(pTest, status == true); status = Device_Set_Object_Instance_Number(BACNET_MAX_INSTANCE + 1); ct_test(pTest, - Device_Object_Instance_Number() != (BACNET_MAX_INSTANCE + 1)); + Device_Object_Instance_Number() != (BACNET_MAX_INSTANCE + 1)); ct_test(pTest, status == false); - Device_Set_System_Status(STATUS_NON_OPERATIONAL, true); ct_test(pTest, Device_System_Status() == STATUS_NON_OPERATIONAL); @@ -1800,8 +1676,7 @@ void testDevice( } #ifdef TEST_DEVICE -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -1813,7 +1688,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/demo/piface/main.c b/demo/piface/main.c index a723c2c9..9cc1de6a 100644 --- a/demo/piface/main.c +++ b/demo/piface/main.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2006 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2006 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -63,13 +63,12 @@ /*@{*/ /** Buffer used for receiving */ -static uint8_t Rx_Buf[MAX_MPDU] = { 0 }; +static uint8_t Rx_Buf[MAX_MPDU] = {0}; /** Initialize the handlers we will utilize. * @see Device_Init, apdu_set_unconfirmed_handler, apdu_set_confirmed_handler */ -static void Init_Service_Handlers( - void) +static void Init_Service_Handlers(void) { Device_Init(NULL); /* we need to handle who-is to support dynamic device binding */ @@ -79,41 +78,40 @@ static void Init_Service_Handlers( apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_I_AM, handler_i_am_bind); /* set the handler for all the services we don't implement */ /* It is required to send the proper reject message... */ - apdu_set_unrecognized_service_handler_handler - (handler_unrecognized_service); + apdu_set_unrecognized_service_handler_handler(handler_unrecognized_service); /* 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, - handler_read_property); + handler_read_property); apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROP_MULTIPLE, - handler_read_property_multiple); + handler_read_property_multiple); apdu_set_confirmed_handler(SERVICE_CONFIRMED_WRITE_PROPERTY, - handler_write_property); + handler_write_property); apdu_set_confirmed_handler(SERVICE_CONFIRMED_WRITE_PROP_MULTIPLE, - handler_write_property_multiple); + handler_write_property_multiple); apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_RANGE, - handler_read_range); + handler_read_range); apdu_set_confirmed_handler(SERVICE_CONFIRMED_REINITIALIZE_DEVICE, - handler_reinitialize_device); + handler_reinitialize_device); apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_UTC_TIME_SYNCHRONIZATION, - handler_timesync_utc); + handler_timesync_utc); apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION, - handler_timesync); + handler_timesync); apdu_set_confirmed_handler(SERVICE_CONFIRMED_SUBSCRIBE_COV, - handler_cov_subscribe); + handler_cov_subscribe); apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_COV_NOTIFICATION, - handler_ucov_notification); + handler_ucov_notification); /* handle communication so we can shutup when asked */ apdu_set_confirmed_handler(SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL, - handler_device_communication_control); + handler_device_communication_control); /* handle the data coming back from private requests */ apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_PRIVATE_TRANSFER, - handler_unconfirmed_private_transfer); + handler_unconfirmed_private_transfer); } static void piface_init(void) { - int hw_addr = 0; /**< PiFaceDigital hardware address */ + int hw_addr = 0; /**< PiFaceDigital hardware address */ #ifdef PIFACE_INTERRUPT_ENABLE int intenable = 1; /**< Whether or not interrupts are enabled */ #endif @@ -130,10 +128,11 @@ static void piface_init(void) * blocking/interrupt methods) */ intenable = pifacedigital_enable_interrupts(); - if ( intenable == 0) { + if (intenable == 0) { printf("Interrupts enabled.\n"); } else { - printf("Could not enable interrupts. " + printf( + "Could not enable interrupts. " "Try running using sudo to enable PiFaceDigital interrupts.\n"); } #endif @@ -142,8 +141,8 @@ static void piface_init(void) /* track the Piface pin state to react on changes only */ static bool PiFace_Pin_Status[MAX_BINARY_INPUTS]; -/** - * Clean up the PiFace interface +/** + * Clean up the PiFace interface */ static void piface_cleanup(void) { @@ -153,7 +152,7 @@ static void piface_cleanup(void) /** * Perform a periodic task for the PiFace card */ -static void piface_task(void) +static void piface_task(void) { unsigned i = 0; BACNET_BINARY_PV present_value = BINARY_INACTIVE; @@ -189,7 +188,7 @@ static void piface_task(void) pifacedigital_digital_write(i, 1); } } - } + } } /** Main function of server demo. @@ -204,30 +203,27 @@ static void piface_task(void) * @param argv [in] Takes one argument: the Device Instance #. * @return 0 on success. */ -int main( - int argc, - char *argv[]) +int main(int argc, char *argv[]) { - BACNET_ADDRESS src = { - 0 - }; /* address where message came from */ + BACNET_ADDRESS src = {0}; /* address where message came from */ uint16_t pdu_len = 0; - unsigned timeout = 1; /* milliseconds */ + unsigned timeout = 1; /* milliseconds */ time_t last_seconds = 0; time_t current_seconds = 0; uint32_t elapsed_seconds = 0; uint32_t elapsed_milliseconds = 0; uint32_t address_binding_tmr = 0; - + /* allow the device ID to be set */ if (argc > 1) { Device_Set_Object_Instance_Number(strtol(argv[1], NULL, 0)); } - printf("BACnet Raspberry Pi PiFace Digital Demo\n" + printf( + "BACnet Raspberry Pi PiFace Digital Demo\n" "BACnet Stack Version %s\n" - "BACnet Device ID: %u\n" - "Max APDU: %d\n", BACnet_Version, - Device_Object_Instance_Number(), MAX_APDU); + "BACnet Device ID: %u\n" + "Max APDU: %d\n", + BACnet_Version, Device_Object_Instance_Number(), MAX_APDU); /* load any static address bindings to show up in our device bindings list */ address_init(); @@ -253,7 +249,7 @@ int main( npdu_handler(&src, &Rx_Buf[0], pdu_len); } /* at least one second has passed */ - elapsed_seconds = (uint32_t) (current_seconds - last_seconds); + elapsed_seconds = (uint32_t)(current_seconds - last_seconds); if (elapsed_seconds) { last_seconds = current_seconds; dcc_timer_seconds(elapsed_seconds); diff --git a/demo/ptransfer/main.c b/demo/ptransfer/main.c index 47e7624c..f2043c35 100644 --- a/demo/ptransfer/main.c +++ b/demo/ptransfer/main.c @@ -1,26 +1,26 @@ /************************************************************************* -* Copyright (C) 2006 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * Copyright (C) 2006 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* command line tool that sends a BACnet service, and displays the reply */ #include @@ -28,8 +28,8 @@ #include #include #include -#include /* for time */ -#include /* for tupper */ +#include /* for time */ +#include /* for tupper */ #if defined(WIN32) || defined(__BORLANDC__) #include #endif @@ -62,15 +62,14 @@ #define _stricmp stricmp #endif -extern uint8_t Send_Private_Transfer_Request( - uint32_t device_id, - uint16_t vendor_id, - uint32_t service_number, - char block_number, - DATABLOCK * block); +extern uint8_t Send_Private_Transfer_Request(uint32_t device_id, + uint16_t vendor_id, + uint32_t service_number, + char block_number, + DATABLOCK *block); /* buffer used for receive */ -static uint8_t Rx_Buf[MAX_MPDU] = { 0 }; +static uint8_t Rx_Buf[MAX_MPDU] = {0}; /* global variables used in this file */ static uint32_t Target_Device_Object_Instance = BACNET_MAX_INSTANCE; @@ -80,51 +79,43 @@ static int Target_Mode = 0; static BACNET_ADDRESS Target_Address; static bool Error_Detected = false; -static void MyErrorHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - BACNET_ERROR_CLASS error_class, - BACNET_ERROR_CODE error_code) +static void MyErrorHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + BACNET_ERROR_CLASS error_class, + BACNET_ERROR_CODE error_code) { /* FIXME: verify src and invoke id */ - (void) src; - (void) invoke_id; + (void)src; + (void)invoke_id; printf("BACnet Error: %s: %s\r\n", - bactext_error_class_name((int) error_class), - bactext_error_code_name((int) error_code)); -/* Error_Detected = true; */ + bactext_error_class_name((int)error_class), + bactext_error_code_name((int)error_code)); + /* Error_Detected = true; */ } -void MyAbortHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t abort_reason, - bool server) +void MyAbortHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t abort_reason, bool server) { /* FIXME: verify src and invoke id */ - (void) src; - (void) invoke_id; - (void) server; + (void)src; + (void)invoke_id; + (void)server; printf("BACnet Abort: %s\r\n", - bactext_abort_reason_name((int) abort_reason)); + bactext_abort_reason_name((int)abort_reason)); Error_Detected = true; } -void MyRejectHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t reject_reason) +void MyRejectHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t reject_reason) { /* FIXME: verify src and invoke id */ - (void) src; - (void) invoke_id; + (void)src; + (void)invoke_id; printf("BACnet Reject: %s\r\n", - bactext_reject_reason_name((int) reject_reason)); + bactext_reject_reason_name((int)reject_reason)); Error_Detected = true; } -static void Init_Service_Handlers( - void) +static void Init_Service_Handlers(void) { Device_Init(NULL); /* we need to handle who-is @@ -134,20 +125,19 @@ static void Init_Service_Handlers( apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_I_AM, handler_i_am_bind); /* set the handler for all the services we don't implement It is required to send the proper reject message... */ - apdu_set_unrecognized_service_handler_handler - (handler_unrecognized_service); + apdu_set_unrecognized_service_handler_handler(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); apdu_set_confirmed_handler(SERVICE_CONFIRMED_PRIVATE_TRANSFER, - handler_conf_private_trans); + handler_conf_private_trans); /* handle the data coming back from confirmed requests */ apdu_set_confirmed_ack_handler(SERVICE_CONFIRMED_READ_PROPERTY, - handler_read_property_ack); + handler_read_property_ack); apdu_set_confirmed_ack_handler(SERVICE_CONFIRMED_PRIVATE_TRANSFER, - handler_conf_private_trans_ack); + handler_conf_private_trans_ack); /* handle any errors coming back */ apdu_set_error_handler(SERVICE_CONFIRMED_READ_PROPERTY, MyErrorHandler); @@ -156,15 +146,11 @@ static void Init_Service_Handlers( apdu_set_reject_handler(MyRejectHandler); } -int main( - int argc, - char *argv[]) +int main(int argc, char *argv[]) { - BACNET_ADDRESS src = { - 0 - }; /* address where message came from */ + BACNET_ADDRESS src = {0}; /* address where message came from */ uint16_t pdu_len = 0; - unsigned timeout = 100; /* milliseconds */ + unsigned timeout = 100; /* milliseconds */ unsigned max_apdu = 0; time_t elapsed_seconds = 0; time_t last_seconds = 0; @@ -177,24 +163,32 @@ int main( int iType = 0; int iKey; - if (((argc != 2) && (argc != 3)) || ((argc >= 2) && - (strcmp(argv[1], "--help") == 0))) { + if (((argc != 2) && (argc != 3)) || + ((argc >= 2) && (strcmp(argv[1], "--help") == 0))) { printf("%s\n", argv[0]); - printf("Usage: %s server local-device-instance\r\n or\r\n" + printf( + "Usage: %s server local-device-instance\r\n or\r\n" " %s remote-device-instance\r\n", filename_remove_path(argv[0]), filename_remove_path(argv[0])); if ((argc > 1) && (strcmp(argv[1], "--help") == 0)) { - printf("\r\nServer mode:\r\n\r\n" - "local-device-instance determins the device id of the application\r\n" + printf( + "\r\nServer mode:\r\n\r\n" + "local-device-instance determins the device id of the " + "application\r\n" "when running as the server end of a test set up.\r\n\r\n" "Non server:\r\n\r\n" - "remote-device-instance indicates the device id of the server\r\n" + "remote-device-instance indicates the device id of the " + "server\r\n" "instance of the application.\r\n" - "The non server application will write a series of blocks to the\r\n" + "The non server application will write a series of blocks to " + "the\r\n" "server and then retrieve them for display locally\r\n" - "First it writes all 8 blocks plus a 9th which should trigger\r\n" - "an out of range error response. Then it reads all the blocks\r\n" - "including the ninth and finally it repeats the read operation\r\n" + "First it writes all 8 blocks plus a 9th which should " + "trigger\r\n" + "an out of range error response. Then it reads all the " + "blocks\r\n" + "including the ninth and finally it repeats the read " + "operation\r\n" "with some deliberate errors to trigger a nack response\r\n"); } return 0; @@ -209,7 +203,7 @@ int main( 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); + Target_Device_Object_Instance, BACNET_MAX_INSTANCE); return 1; } @@ -245,10 +239,10 @@ int main( } /* at least one second has passed */ if (current_seconds != last_seconds) { - putchar('.'); /* Just to show that time is passing... */ + putchar('.'); /* Just to show that time is passing... */ last_seconds = current_seconds; - tsm_timer_milliseconds(((current_seconds - - last_seconds) * 1000)); + tsm_timer_milliseconds( + ((current_seconds - last_seconds) * 1000)); } if (_kbhit()) { @@ -260,14 +254,12 @@ int main( } } } else { - /* try to bind with the device */ - found = - address_bind_request(Target_Device_Object_Instance, &max_apdu, - &Target_Address); + found = address_bind_request(Target_Device_Object_Instance, &max_apdu, + &Target_Address); if (!found) { Send_WhoIs(Target_Device_Object_Instance, - Target_Device_Object_Instance); + Target_Device_Object_Instance); } /* loop forever */ for (;;) { @@ -283,65 +275,63 @@ 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)); if (Error_Detected) break; /* wait until the device is bound, or timeout and quit */ if (!found) - found = - address_bind_request(Target_Device_Object_Instance, - &max_apdu, &Target_Address); + found = address_bind_request(Target_Device_Object_Instance, + &max_apdu, &Target_Address); if (found) { - if (invoke_id == 0) { /* Safe to send a new request */ + if (invoke_id == 0) { /* Safe to send a new request */ switch (iType) { - case 0: /* Write blocks to server */ + case 0: /* Write blocks to server */ NewData.cMyByte1 = iCount; NewData.cMyByte2 = 255 - iCount; - NewData.fMyReal = (float) iCount; - strcpy((char*)NewData.sMyString, "Test Data - [x]"); + NewData.fMyReal = (float)iCount; + strcpy((char *)NewData.sMyString, + "Test Data - [x]"); NewData.sMyString[13] = 'a' + iCount; printf("Sending block %d\n", iCount); - invoke_id = - Send_Private_Transfer_Request - (Target_Device_Object_Instance, - BACNET_VENDOR_ID, 1, iCount, &NewData); + invoke_id = Send_Private_Transfer_Request( + Target_Device_Object_Instance, BACNET_VENDOR_ID, + 1, iCount, &NewData); break; - case 1: /* Read blocks from server */ + case 1: /* Read blocks from server */ printf("Requesting block %d\n", iCount); - invoke_id = - Send_Private_Transfer_Request - (Target_Device_Object_Instance, - BACNET_VENDOR_ID, 0, iCount, &NewData); + invoke_id = Send_Private_Transfer_Request( + Target_Device_Object_Instance, BACNET_VENDOR_ID, + 0, iCount, &NewData); break; - case 2: /* Generate some error responses */ + case 2: /* Generate some error responses */ switch (iCount) { - case 0: /* Bad service number i.e. 2 */ + case 0: /* Bad service number i.e. 2 */ case 2: case 4: case 6: case 8: - printf - ("Requesting block %d with bad service number\n", + printf( + "Requesting block %d with bad service " + "number\n", iCount); - invoke_id = - Send_Private_Transfer_Request - (Target_Device_Object_Instance, + invoke_id = Send_Private_Transfer_Request( + Target_Device_Object_Instance, BACNET_VENDOR_ID, 2, iCount, &NewData); break; - case 1: /* Bad vendor ID number */ + case 1: /* Bad vendor ID number */ case 3: case 5: case 7: - printf - ("Requesting block %d with invalid Vendor ID\n", + printf( + "Requesting block %d with invalid " + "Vendor ID\n", iCount); - invoke_id = - Send_Private_Transfer_Request - (Target_Device_Object_Instance, + invoke_id = Send_Private_Transfer_Request( + Target_Device_Object_Instance, BACNET_VENDOR_ID + 1, 0, iCount, &NewData); break; diff --git a/demo/readbdt/main.c b/demo/readbdt/main.c index 2848647b..8196952f 100644 --- a/demo/readbdt/main.c +++ b/demo/readbdt/main.c @@ -1,36 +1,36 @@ /************************************************************************** -* -* Copyright (C) 2012 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2012 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* command line tool that sends a BACnet BVLC message, and displays the reply */ #include #include #include #include -#include /* for time */ +#include /* for time */ #include -#include /* for toupper */ +#include /* for toupper */ #include "bactext.h" #include "iam.h" #include "address.h" @@ -53,7 +53,7 @@ #include "dlenv.h" /* buffer used for receive */ -static uint8_t Rx_Buf[MAX_MPDU] = { 0 }; +static uint8_t Rx_Buf[MAX_MPDU] = {0}; /* targets interpreted from the command line options */ static uint32_t Target_BBMD_Address; @@ -61,34 +61,28 @@ static uint16_t Target_BBMD_Port; static bool Error_Detected = false; -static void MyAbortHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t abort_reason, - bool server) +static void MyAbortHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t abort_reason, bool server) { /* FIXME: verify src and invoke id */ - (void) src; - (void) invoke_id; - (void) server; + (void)src; + (void)invoke_id; + (void)server; printf("BACnet Abort: %s\r\n", bactext_abort_reason_name(abort_reason)); Error_Detected = true; } -static void MyRejectHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t reject_reason) +static void MyRejectHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t reject_reason) { /* FIXME: verify src and invoke id */ - (void) src; - (void) invoke_id; + (void)src; + (void)invoke_id; printf("BACnet Reject: %s\r\n", bactext_reject_reason_name(reject_reason)); Error_Detected = true; } -static void Init_Service_Handlers( - void) +static void Init_Service_Handlers(void) { Device_Init(NULL); /* we need to handle who-is @@ -96,11 +90,10 @@ static void Init_Service_Handlers( apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, handler_who_is); /* set the handler for all the services we don't implement It is required to send the proper reject message... */ - apdu_set_unrecognized_service_handler_handler - (handler_unrecognized_service); + apdu_set_unrecognized_service_handler_handler(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 reply (request) coming back */ apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_I_AM, handler_i_am_add); /* handle any errors coming back */ @@ -108,15 +101,11 @@ static void Init_Service_Handlers( apdu_set_reject_handler(MyRejectHandler); } -int main( - int argc, - char *argv[]) +int main(int argc, char *argv[]) { - BACNET_ADDRESS src = { - 0 - }; /* address where message came from */ + BACNET_ADDRESS src = {0}; /* address where message came from */ uint16_t pdu_len = 0; - unsigned timeout = 100; /* milliseconds */ + unsigned timeout = 100; /* milliseconds */ time_t total_seconds = 0; time_t elapsed_seconds = 0; time_t last_seconds = 0; @@ -129,14 +118,17 @@ int main( return 0; } if ((argc > 1) && (strcmp(argv[1], "--help") == 0)) { - printf - ("Send a Read-Broadcast-Distribution-Table message to a BBMD.\r\n" - "\r\n" "IP:\r\n" + printf( + "Send a Read-Broadcast-Distribution-Table message to a BBMD.\r\n" + "\r\n" + "IP:\r\n" "IP address of the BBMD in dotted decimal notation\r\n" "[port]\r\n" - "optional BACnet/IP port number (default=47808=0xBAC0)\r\n" "\r\n" + "optional BACnet/IP port number (default=47808=0xBAC0)\r\n" + "\r\n" "To send a Read-Broadcast-Distribution-Table message to a BBMD\r\n" - "at 192.168.0.1 using port 47808:\r\n" "%s 192.168.0.1 47808\r\n", + "at 192.168.0.1 using port 47808:\r\n" + "%s 192.168.0.1 47808\r\n", filename_remove_path(argv[0])); return 0; } @@ -154,7 +146,7 @@ int main( Target_BBMD_Port = htons(port); } else { fprintf(stderr, "port=%ld - port must be between 0-65535.\r\n", - port); + port); return 1; } } else { diff --git a/demo/readfile/main.c b/demo/readfile/main.c index 24f7e8fd..17f292d2 100644 --- a/demo/readfile/main.c +++ b/demo/readfile/main.c @@ -1,34 +1,34 @@ /************************************************************************** -* -* Copyright (C) 2006 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2006 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* command line tool that sends a BACnet service, and displays the reply */ #include #include #include #include -#include /* for time */ +#include /* for time */ #include #include "bactext.h" #include "iam.h" @@ -52,7 +52,7 @@ #include "dlenv.h" /* buffer used for receive */ -static uint8_t Rx_Buf[MAX_MPDU] = { 0 }; +static uint8_t Rx_Buf[MAX_MPDU] = {0}; /* global variables used in this file */ static uint32_t Target_File_Object_Instance = BACNET_MAX_INSTANCE; @@ -65,54 +65,46 @@ static bool End_Of_File_Detected = false; static bool Error_Detected = false; static uint8_t Request_Invoke_ID = 0; -static void Atomic_Read_File_Error_Handler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - BACNET_ERROR_CLASS error_class, - BACNET_ERROR_CODE error_code) +static void Atomic_Read_File_Error_Handler(BACNET_ADDRESS *src, + uint8_t invoke_id, + BACNET_ERROR_CLASS error_class, + BACNET_ERROR_CODE error_code) { if (address_match(&Target_Address, src) && (invoke_id == Request_Invoke_ID)) { printf("BACnet Error: %s: %s\n", - bactext_error_class_name((int) error_class), - bactext_error_code_name((int) error_code)); + bactext_error_class_name((int)error_class), + bactext_error_code_name((int)error_code)); Error_Detected = true; } } -void MyAbortHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t abort_reason, - bool server) +void MyAbortHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t abort_reason, bool server) { - (void) server; + (void)server; if (address_match(&Target_Address, src) && (invoke_id == Request_Invoke_ID)) { printf("BACnet Abort: %s\n", - bactext_abort_reason_name((int) abort_reason)); + bactext_abort_reason_name((int)abort_reason)); Error_Detected = true; } } -void MyRejectHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t reject_reason) +void MyRejectHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t reject_reason) { if (address_match(&Target_Address, src) && (invoke_id == Request_Invoke_ID)) { printf("BACnet Reject: %s\n", - bactext_reject_reason_name((int) reject_reason)); + bactext_reject_reason_name((int)reject_reason)); Error_Detected = true; } } static void AtomicReadFileAckHandler( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src, - BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data) + uint8_t *service_request, uint16_t service_len, BACNET_ADDRESS *src, + BACNET_CONFIRMED_SERVICE_ACK_DATA *service_data) { int len = 0; int result = 0; @@ -122,7 +114,8 @@ static void AtomicReadFileAckHandler( if (address_match(&Target_Address, src) && (service_data->invoke_id == Request_Invoke_ID)) { - len = arf_ack_decode_service_request(service_request, service_len, &data); + len = + arf_ack_decode_service_request(service_request, service_len, &data); if ((len > 0) && (data.access == FILE_STREAM_ACCESS)) { if (data.type.stream.fileStartPosition == 0) { pFile = fopen(Local_File_Name, "wb"); @@ -130,31 +123,30 @@ static void AtomicReadFileAckHandler( pFile = fopen(Local_File_Name, "rb+"); } if (pFile) { - result = fseek(pFile, data.type.stream.fileStartPosition, - SEEK_SET); + result = + fseek(pFile, data.type.stream.fileStartPosition, SEEK_SET); if (result == 0) { /* unit to write in bytes - in our case, an octet is one byte */ - octets_written = fwrite( - octetstring_value(&data.fileData[0]), 1, - octetstring_length(&data.fileData[0]), pFile); + octets_written = + fwrite(octetstring_value(&data.fileData[0]), 1, + octetstring_length(&data.fileData[0]), pFile); if (octets_written != octetstring_length(&data.fileData[0])) { fprintf(stderr, - "Unable to write data to file \"%s\".\n", - Local_File_Name); + "Unable to write data to file \"%s\".\n", + Local_File_Name); } else if (octets_written == 0) { fprintf(stderr, "Received 0 byte octet string!.\n"); } else { Target_File_Start_Position = - data.type.stream.fileStartPosition + - octets_written; + data.type.stream.fileStartPosition + octets_written; printf("\r%d bytes", (int)Target_File_Start_Position); } fflush(pFile); } else { fprintf(stderr, "Unable to seek to %d!\n", - data.type.stream.fileStartPosition); + data.type.stream.fileStartPosition); } fclose(pFile); } @@ -167,14 +159,12 @@ static void AtomicReadFileAckHandler( } } else { fprintf(stderr, "Address & Invoke ID mismatch! Invoke ID=%d\n", - Request_Invoke_ID); + Request_Invoke_ID); } } -static void LocalIAmHandler( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src) +static void LocalIAmHandler(uint8_t *service_request, uint16_t service_len, + BACNET_ADDRESS *src) { int len = 0; uint32_t device_id = 0; @@ -182,11 +172,10 @@ static void LocalIAmHandler( int segmentation = 0; uint16_t vendor_id = 0; - (void) src; - (void) service_len; - len = - iam_decode_service_request(service_request, &device_id, &max_apdu, - &segmentation, &vendor_id); + (void)src; + (void)service_len; + len = iam_decode_service_request(service_request, &device_id, &max_apdu, + &segmentation, &vendor_id); if (len != -1) { address_add(device_id, max_apdu, src); } else @@ -195,8 +184,7 @@ static void LocalIAmHandler( return; } -static void Init_Service_Handlers( - void) +static void Init_Service_Handlers(void) { Device_Init(NULL); /* we need to handle who-is @@ -206,31 +194,30 @@ static void Init_Service_Handlers( apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_I_AM, LocalIAmHandler); /* set the handler for all the services we don't implement It is required to send the proper reject message... */ - apdu_set_unrecognized_service_handler_handler - (handler_unrecognized_service); + apdu_set_unrecognized_service_handler_handler(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_ATOMIC_READ_FILE, - AtomicReadFileAckHandler); + AtomicReadFileAckHandler); /* handle any errors coming back */ apdu_set_error_handler(SERVICE_CONFIRMED_ATOMIC_READ_FILE, - Atomic_Read_File_Error_Handler); + Atomic_Read_File_Error_Handler); apdu_set_abort_handler(MyAbortHandler); apdu_set_reject_handler(MyRejectHandler); } static void print_usage(char *filename) { - printf("Usage: %s device-instance file-instance local-name\n", - filename); + printf("Usage: %s device-instance file-instance local-name\n", filename); printf(" [--version][--help]\n"); } static void print_help(char *filename) { - printf("Read a file from a BACnet device and save it locally.\n" + printf( + "Read a file from a BACnet device and save it locally.\n" "device-instance:\n" "BACnet Device Object Instance number that you are trying to\n" "communicate to. This number will be used to try and bind with\n" @@ -252,15 +239,11 @@ static void print_help(char *filename) filename); } -int main( - int argc, - char *argv[]) +int main(int argc, char *argv[]) { - BACNET_ADDRESS src = { - 0 - }; /* address where message came from */ + BACNET_ADDRESS src = {0}; /* address where message came from */ uint16_t pdu_len = 0; - unsigned timeout = 100; /* milliseconds */ + unsigned timeout = 100; /* milliseconds */ unsigned max_apdu = 0; time_t elapsed_seconds = 0; time_t last_seconds = 0; @@ -282,8 +265,10 @@ int main( } if (strcmp(argv[argi], "--version") == 0) { printf("%s %s\n", filename, BACNET_VERSION_TEXT); - printf("Copyright (C) 2014 by Steve Karg and others.\n" - "This is free software; see the source for copying conditions.\n" + printf( + "Copyright (C) 2014 by Steve Karg and others.\n" + "This is free software; see the source for copying " + "conditions.\n" "There is NO warranty; not even for MERCHANTABILITY or\n" "FITNESS FOR A PARTICULAR PURPOSE.\n"); return 0; @@ -299,12 +284,12 @@ int main( Local_File_Name = argv[3]; if (Target_Device_Object_Instance >= BACNET_MAX_INSTANCE) { fprintf(stderr, "device-instance=%u - it must be less than %u\n", - Target_Device_Object_Instance, BACNET_MAX_INSTANCE); + Target_Device_Object_Instance, BACNET_MAX_INSTANCE); return 1; } if (Target_File_Object_Instance >= BACNET_MAX_INSTANCE) { fprintf(stderr, "file-instance=%u - it must be less than %u\n", - Target_File_Object_Instance, BACNET_MAX_INSTANCE + 1); + Target_File_Object_Instance, BACNET_MAX_INSTANCE + 1); return 1; } /* setup my info */ @@ -317,12 +302,11 @@ int main( last_seconds = time(NULL); timeout_seconds = (apdu_timeout() / 1000) * apdu_retries(); /* try to bind with the device */ - found = - address_bind_request(Target_Device_Object_Instance, &max_apdu, - &Target_Address); + found = address_bind_request(Target_Device_Object_Instance, &max_apdu, + &Target_Address); if (!found) { Send_WhoIs(Target_Device_Object_Instance, - Target_Device_Object_Instance); + Target_Device_Object_Instance); } /* loop forever */ for (;;) { @@ -342,9 +326,8 @@ int main( } /* wait until the device is bound, or timeout and quit */ if (!found) { - found = - address_bind_request(Target_Device_Object_Instance, &max_apdu, - &Target_Address); + found = address_bind_request(Target_Device_Object_Instance, + &max_apdu, &Target_Address); } if (found) { /* calculate the smaller of our APDU size or theirs @@ -375,9 +358,9 @@ int main( /* the ACK will increment the start position if OK */ /* we'll read the file in chunks less than max_apdu to keep unsegmented */ - invoke_id = - Send_Atomic_Read_File_Stream(Target_Device_Object_Instance, - Target_File_Object_Instance, Target_File_Start_Position, + invoke_id = Send_Atomic_Read_File_Stream( + Target_Device_Object_Instance, Target_File_Object_Instance, + Target_File_Start_Position, Target_File_Requested_Octet_Count); Request_Invoke_ID = invoke_id; } else if (tsm_invoke_id_failed(invoke_id)) { diff --git a/demo/readprop/main.c b/demo/readprop/main.c index c5330c57..dc2cba6a 100644 --- a/demo/readprop/main.c +++ b/demo/readprop/main.c @@ -1,26 +1,26 @@ /************************************************************************* -* Copyright (C) 2006 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * Copyright (C) 2006 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* command line tool that sends a BACnet service, and displays the reply */ #include @@ -28,7 +28,7 @@ #include #include #include -#include /* for time */ +#include /* for time */ #define PRINT_ENABLED 1 @@ -55,7 +55,7 @@ #include "dlenv.h" /* buffer used for receive */ -static uint8_t Rx_Buf[MAX_MPDU] = { 0 }; +static uint8_t Rx_Buf[MAX_MPDU] = {0}; /* converted command line arguments */ static uint32_t Target_Device_Object_Instance = BACNET_MAX_INSTANCE; @@ -68,45 +68,38 @@ static uint8_t Request_Invoke_ID = 0; static BACNET_ADDRESS Target_Address; static bool Error_Detected = false; -static void MyErrorHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - BACNET_ERROR_CLASS error_class, - BACNET_ERROR_CODE error_code) +static void MyErrorHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + BACNET_ERROR_CLASS error_class, + BACNET_ERROR_CODE error_code) { if (address_match(&Target_Address, src) && (invoke_id == Request_Invoke_ID)) { printf("BACnet Error: %s: %s\n", - bactext_error_class_name((int) error_class), - bactext_error_code_name((int) error_code)); + bactext_error_class_name((int)error_class), + bactext_error_code_name((int)error_code)); Error_Detected = true; } } -void MyAbortHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t abort_reason, - bool server) +void MyAbortHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t abort_reason, bool server) { - (void) server; + (void)server; if (address_match(&Target_Address, src) && (invoke_id == Request_Invoke_ID)) { printf("BACnet Abort: %s\n", - bactext_abort_reason_name((int) abort_reason)); + bactext_abort_reason_name((int)abort_reason)); Error_Detected = true; } } -void MyRejectHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t reject_reason) +void MyRejectHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t reject_reason) { if (address_match(&Target_Address, src) && (invoke_id == Request_Invoke_ID)) { printf("BACnet Reject: %s\n", - bactext_reject_reason_name((int) reject_reason)); + bactext_reject_reason_name((int)reject_reason)); Error_Detected = true; } } @@ -123,10 +116,8 @@ void MyRejectHandler( * decoded from the APDU header of this message. */ void My_Read_Property_Ack_Handler( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src, - BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data) + uint8_t *service_request, uint16_t service_len, BACNET_ADDRESS *src, + BACNET_CONFIRMED_SERVICE_ACK_DATA *service_data) { int len = 0; BACNET_READ_PROPERTY_DATA data; @@ -143,8 +134,7 @@ void My_Read_Property_Ack_Handler( } } -static void Init_Service_Handlers( - void) +static void Init_Service_Handlers(void) { Device_Init(NULL); /* we need to handle who-is @@ -154,14 +144,13 @@ static void Init_Service_Handlers( apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_I_AM, handler_i_am_bind); /* set the handler for all the services we don't implement It is required to send the proper reject message... */ - apdu_set_unrecognized_service_handler_handler - (handler_unrecognized_service); + apdu_set_unrecognized_service_handler_handler(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, - My_Read_Property_Ack_Handler); + My_Read_Property_Ack_Handler); /* handle any errors coming back */ apdu_set_error_handler(SERVICE_CONFIRMED_READ_PROPERTY, MyErrorHandler); apdu_set_abort_handler(MyAbortHandler); @@ -170,17 +159,21 @@ static void Init_Service_Handlers( static void print_usage(char *filename) { - printf("Usage: %s device-instance object-type object-instance " - "property [index]\n", filename); + printf( + "Usage: %s device-instance object-type object-instance " + "property [index]\n", + filename); printf(" [--dnet][--dadr][--mac]\n"); printf(" [--version][--help]\n"); } static void print_help(char *filename) { - printf("Read a property from an object in a BACnet device\n" + printf( + "Read a property from an object in a BACnet device\n" "and print the value.\n"); - printf("--mac A\n" + printf( + "--mac A\n" "Optional BACnet mac address." "Valid ranges are from 00 to FF (hex) for MS/TP or ARCNET,\n" "or an IP string with optional port number like 10.1.2.3:47808\n" @@ -192,12 +185,14 @@ static void print_help(char *filename) "and 65535 is network broadcast.\n" "\n" "--dadr A\n" - "Optional BACnet mac address on the destination BACnet network number.\n" + "Optional BACnet mac address on the destination BACnet network " + "number.\n" "Valid ranges are from 00 to FF (hex) for MS/TP or ARCNET,\n" "or an IP string with optional port number like 10.1.2.3:47808\n" "or an Ethernet MAC in hex like 00:21:70:7e:32:bb\n" "\n"); - printf("device-instance:\n" + printf( + "device-instance:\n" "BACnet Device Object Instance number that you are\n" "trying to communicate to. This number will be used\n" "to try and bind with the device using Who-Is and\n" @@ -228,18 +223,15 @@ static void print_help(char *filename) "%s 123 1 101 85\n" "If you want read the Priority-Array of Analog Output 101\n" "in Device 123, you could send the following command:\n" - "%s 123 1 101 87\n", filename, filename); + "%s 123 1 101 87\n", + filename, filename); } -int main( - int argc, - char *argv[]) +int main(int argc, char *argv[]) { - BACNET_ADDRESS src = { - 0 - }; /* address where message came from */ + BACNET_ADDRESS src = {0}; /* address where message came from */ uint16_t pdu_len = 0; - unsigned timeout = 100; /* milliseconds */ + unsigned timeout = 100; /* milliseconds */ unsigned max_apdu = 0; time_t elapsed_seconds = 0; time_t last_seconds = 0; @@ -247,9 +239,9 @@ int main( time_t timeout_seconds = 0; bool found = false; long dnet = -1; - BACNET_MAC_ADDRESS mac = { 0 }; - BACNET_MAC_ADDRESS adr = { 0 }; - BACNET_ADDRESS dest = { 0 }; + BACNET_MAC_ADDRESS mac = {0}; + BACNET_MAC_ADDRESS adr = {0}; + BACNET_ADDRESS dest = {0}; bool specific_address = false; int argi = 0; unsigned int target_args = 0; @@ -264,8 +256,10 @@ int main( } if (strcmp(argv[argi], "--version") == 0) { printf("%s %s\n", filename, BACNET_VERSION_TEXT); - printf("Copyright (C) 2015 by Steve Karg and others.\n" - "This is free software; see the source for copying conditions.\n" + printf( + "Copyright (C) 2015 by Steve Karg and others.\n" + "This is free software; see the source for copying " + "conditions.\n" "There is NO warranty; not even for MERCHANTABILITY or\n" "FITNESS FOR A PARTICULAR PURPOSE.\n"); return 0; @@ -317,7 +311,7 @@ int main( } if (Target_Device_Object_Instance > BACNET_MAX_INSTANCE) { fprintf(stderr, "device-instance=%u - it must be less than %u\n", - Target_Device_Object_Instance, BACNET_MAX_INSTANCE); + Target_Device_Object_Instance, BACNET_MAX_INSTANCE); return 1; } address_init(); @@ -361,12 +355,11 @@ int main( last_seconds = time(NULL); timeout_seconds = (apdu_timeout() / 1000) * apdu_retries(); /* try to bind with the device */ - found = - address_bind_request(Target_Device_Object_Instance, &max_apdu, - &Target_Address); + found = address_bind_request(Target_Device_Object_Instance, &max_apdu, + &Target_Address); if (!found) { Send_WhoIs(Target_Device_Object_Instance, - Target_Device_Object_Instance); + Target_Device_Object_Instance); } /* loop forever */ for (;;) { @@ -375,22 +368,21 @@ int main( /* at least one second has passed */ if (current_seconds != last_seconds) - tsm_timer_milliseconds((uint16_t) ((current_seconds - - last_seconds) * 1000)); + tsm_timer_milliseconds( + (uint16_t)((current_seconds - last_seconds) * 1000)); if (Error_Detected) break; /* wait until the device is bound, or timeout and quit */ if (!found) { - found = - address_bind_request(Target_Device_Object_Instance, &max_apdu, - &Target_Address); + found = address_bind_request(Target_Device_Object_Instance, + &max_apdu, &Target_Address); } if (found) { if (Request_Invoke_ID == 0) { - Request_Invoke_ID = - Send_Read_Property_Request(Target_Device_Object_Instance, - Target_Object_Type, Target_Object_Instance, - Target_Object_Property, Target_Object_Index); + Request_Invoke_ID = Send_Read_Property_Request( + Target_Device_Object_Instance, Target_Object_Type, + Target_Object_Instance, Target_Object_Property, + Target_Object_Index); } else if (tsm_invoke_id_free(Request_Invoke_ID)) break; else if (tsm_invoke_id_failed(Request_Invoke_ID)) { diff --git a/demo/readpropm/main.c b/demo/readpropm/main.c index 8f6d77b9..fd52e28f 100644 --- a/demo/readpropm/main.c +++ b/demo/readpropm/main.c @@ -1,26 +1,26 @@ /************************************************************************* -* Copyright (C) 2008 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * Copyright (C) 2008 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* command line tool that sends a BACnet service, and displays the reply */ #include @@ -28,7 +28,7 @@ #include #include #include -#include /* for time */ +#include /* for time */ #define PRINT_ENABLED 1 @@ -56,7 +56,7 @@ #include "dlenv.h" /* buffer used for receive */ -static uint8_t Rx_Buf[MAX_MPDU] = { 0 }; +static uint8_t Rx_Buf[MAX_MPDU] = {0}; /* global variables used in this file */ static uint32_t Target_Device_Object_Instance = BACNET_MAX_INSTANCE; @@ -67,46 +67,39 @@ static BACNET_ADDRESS Target_Address; /* needed for return value of main application */ static bool Error_Detected = false; -static void MyErrorHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - BACNET_ERROR_CLASS error_class, - BACNET_ERROR_CODE error_code) +static void MyErrorHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + BACNET_ERROR_CLASS error_class, + BACNET_ERROR_CODE error_code) { if (address_match(&Target_Address, src) && (invoke_id == Request_Invoke_ID)) { printf("BACnet Error: %s: %s\n", - bactext_error_class_name((int) error_class), - bactext_error_code_name((int) error_code)); + bactext_error_class_name((int)error_class), + bactext_error_code_name((int)error_code)); Error_Detected = true; } } -void MyAbortHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t abort_reason, - bool server) +void MyAbortHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t abort_reason, bool server) { - (void) server; + (void)server; if (address_match(&Target_Address, src) && (invoke_id == Request_Invoke_ID)) { printf("BACnet Abort: %s\n", - bactext_abort_reason_name((int) abort_reason)); + bactext_abort_reason_name((int)abort_reason)); Error_Detected = true; } } -void MyRejectHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t reject_reason) +void MyRejectHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t reject_reason) { /* FIXME: verify src and invoke id */ if (address_match(&Target_Address, src) && (invoke_id == Request_Invoke_ID)) { printf("BACnet Reject: %s\n", - bactext_reject_reason_name((int) reject_reason)); + bactext_reject_reason_name((int)reject_reason)); Error_Detected = true; } } @@ -123,10 +116,8 @@ void MyRejectHandler( * decoded from the APDU header of this message. */ void My_Read_Property_Multiple_Ack_Handler( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src, - BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data) + uint8_t *service_request, uint16_t service_len, BACNET_ADDRESS *src, + BACNET_CONFIRMED_SERVICE_ACK_DATA *service_data) { int len = 0; BACNET_READ_ACCESS_DATA *rpm_data; @@ -140,9 +131,8 @@ void My_Read_Property_Multiple_Ack_Handler( (service_data->invoke_id == Request_Invoke_ID)) { rpm_data = calloc(1, sizeof(BACNET_READ_ACCESS_DATA)); if (rpm_data) { - len = - rpm_ack_decode_service_request(service_request, service_len, - rpm_data); + len = rpm_ack_decode_service_request(service_request, service_len, + rpm_data); } if (len > 0) { while (rpm_data) { @@ -186,8 +176,7 @@ void My_Read_Property_Multiple_Ack_Handler( } } -static void Init_Service_Handlers( - void) +static void Init_Service_Handlers(void) { Device_Init(NULL); /* we need to handle who-is @@ -197,22 +186,20 @@ static void Init_Service_Handlers( apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_I_AM, handler_i_am_bind); /* set the handler for all the services we don't implement It is required to send the proper reject message... */ - apdu_set_unrecognized_service_handler_handler - (handler_unrecognized_service); + apdu_set_unrecognized_service_handler_handler(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_PROP_MULTIPLE, - My_Read_Property_Multiple_Ack_Handler); + My_Read_Property_Multiple_Ack_Handler); /* handle any errors coming back */ apdu_set_error_handler(SERVICE_CONFIRMED_READ_PROPERTY, MyErrorHandler); apdu_set_abort_handler(MyAbortHandler); apdu_set_reject_handler(MyRejectHandler); } -void cleanup( - void) +void cleanup(void) { BACNET_READ_ACCESS_DATA *rpm_object; BACNET_READ_ACCESS_DATA *old_rpm_object; @@ -236,7 +223,8 @@ void cleanup( static void print_usage(char *filename) { - printf("Usage: %s device-instance object-type object-instance " + printf( + "Usage: %s device-instance object-type object-instance " "property[index][,property[index]] [object-type ...]\n", filename); printf(" [--version][--help]\n"); @@ -244,7 +232,8 @@ static void print_usage(char *filename) static void print_help(char *filename) { - printf("Read one or more properties from one or more objects\n" + printf( + "Read one or more properties from one or more objects\n" "in a BACnet device and print the value(s).\n" "device-instance:\n" "BACnet Device Object Instance number that you are\n" @@ -278,7 +267,8 @@ static void print_help(char *filename) "%s 123 1 99 85,87[0],87\n" "If you want read the PRESENT_VALUE property in objects\n" "Analog Input 77 and Analog Input 78 in Device 123\n" - "use the following command:\n" "%s 123 0 77 85 0 78 85\n" + "use the following command:\n" + "%s 123 0 77 85 0 78 85\n" "If you want read the ALL property in\n" "Device object 123, you would use the following command:\n" "%s 123 8 123 8\n" @@ -287,19 +277,15 @@ static void print_help(char *filename) "%s 123 8 123 80\n" "If you want read the REQUIRED property in\n" "Device object 123, you would use the following command:\n" - "%s 123 8 123 105\n", filename, filename, filename, filename, - filename); + "%s 123 8 123 105\n", + filename, filename, filename, filename, filename); } -int main( - int argc, - char *argv[]) +int main(int argc, char *argv[]) { - BACNET_ADDRESS src = { - 0 - }; /* address where message came from */ + BACNET_ADDRESS src = {0}; /* address where message came from */ uint16_t pdu_len = 0; - unsigned timeout = 100; /* milliseconds */ + unsigned timeout = 100; /* milliseconds */ unsigned max_apdu = 0; int args_remaining = 0, tag_value_arg = 0, arg_sets = 0; time_t elapsed_seconds = 0; @@ -307,9 +293,7 @@ int main( time_t current_seconds = 0; time_t timeout_seconds = 0; bool found = false; - uint8_t buffer[MAX_PDU] = { - 0 - }; + uint8_t buffer[MAX_PDU] = {0}; BACNET_READ_ACCESS_DATA *rpm_object; BACNET_PROPERTY_REFERENCE *rpm_property; char *property_token = NULL; @@ -328,8 +312,10 @@ int main( } if (strcmp(argv[argi], "--version") == 0) { printf("%s %s\n", filename, BACNET_VERSION_TEXT); - printf("Copyright (C) 2014 by Steve Karg and others.\n" - "This is free software; see the source for copying conditions.\n" + printf( + "Copyright (C) 2014 by Steve Karg and others.\n" + "This is free software; see the source for copying " + "conditions.\n" "There is NO warranty; not even for MERCHANTABILITY or\n" "FITNESS FOR A PARTICULAR PURPOSE.\n"); return 0; @@ -343,7 +329,7 @@ int main( Target_Device_Object_Instance = strtol(argv[1], NULL, 0); if (Target_Device_Object_Instance >= BACNET_MAX_INSTANCE) { fprintf(stderr, "device-instance=%u - it must be less than %u\n", - Target_Device_Object_Instance, BACNET_MAX_INSTANCE); + Target_Device_Object_Instance, BACNET_MAX_INSTANCE); return 1; } atexit(cleanup); @@ -362,7 +348,7 @@ int main( } if (rpm_object->object_type >= MAX_BACNET_OBJECT_TYPE) { fprintf(stderr, "object-type=%u - it must be less than %u\n", - rpm_object->object_type, MAX_BACNET_OBJECT_TYPE); + rpm_object->object_type, MAX_BACNET_OBJECT_TYPE); return 1; } rpm_object->object_instance = strtol(argv[tag_value_arg], NULL, 0); @@ -374,7 +360,7 @@ int main( } if (rpm_object->object_instance > BACNET_MAX_INSTANCE) { fprintf(stderr, "object-instance=%u - it must be less than %u\n", - rpm_object->object_instance, BACNET_MAX_INSTANCE + 1); + rpm_object->object_instance, BACNET_MAX_INSTANCE + 1); return 1; } rpm_property = calloc(1, sizeof(BACNET_PROPERTY_REFERENCE)); @@ -382,16 +368,14 @@ int main( property_token = strtok(argv[tag_value_arg], ","); /* add all the properties and optional index to our list */ while (rpm_property) { - scan_count = - sscanf(property_token, "%u[%u]", &property_id, - &property_array_index); + scan_count = sscanf(property_token, "%u[%u]", &property_id, + &property_array_index); if (scan_count > 0) { rpm_property->propertyIdentifier = property_id; if (rpm_property->propertyIdentifier > MAX_BACNET_PROPERTY_ID) { - fprintf(stderr, - "property=%u - it must be less than %u\n", - rpm_property->propertyIdentifier, - MAX_BACNET_PROPERTY_ID + 1); + fprintf(stderr, "property=%u - it must be less than %u\n", + rpm_property->propertyIdentifier, + MAX_BACNET_PROPERTY_ID + 1); return 1; } } @@ -432,12 +416,11 @@ int main( last_seconds = time(NULL); timeout_seconds = (apdu_timeout() / 1000) * apdu_retries(); /* try to bind with the device */ - found = - address_bind_request(Target_Device_Object_Instance, &max_apdu, - &Target_Address); + found = address_bind_request(Target_Device_Object_Instance, &max_apdu, + &Target_Address); if (!found) { Send_WhoIs(Target_Device_Object_Instance, - Target_Device_Object_Instance); + Target_Device_Object_Instance); } /* loop forever */ for (;;) { @@ -451,15 +434,13 @@ int main( break; /* wait until the device is bound, or timeout and quit */ if (!found) { - found = - address_bind_request(Target_Device_Object_Instance, &max_apdu, - &Target_Address); + found = address_bind_request(Target_Device_Object_Instance, + &max_apdu, &Target_Address); } if (found) { if (Request_Invoke_ID == 0) { - Request_Invoke_ID = - Send_Read_Property_Multiple_Request(&buffer[0], - sizeof(buffer), Target_Device_Object_Instance, + Request_Invoke_ID = Send_Read_Property_Multiple_Request( + &buffer[0], sizeof(buffer), Target_Device_Object_Instance, Read_Access_Data); } else if (tsm_invoke_id_free(Request_Invoke_ID)) break; diff --git a/demo/readrange/main.c b/demo/readrange/main.c index cdca07a9..81a9d0a2 100644 --- a/demo/readrange/main.c +++ b/demo/readrange/main.c @@ -1,26 +1,26 @@ /************************************************************************* -* Copyright (C) 2006 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * Copyright (C) 2006 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #define PRINT_ENABLED 1 @@ -30,7 +30,7 @@ #include #include #include -#include /* for time */ +#include /* for time */ #include "bacdef.h" #include "config.h" #include "bactext.h" @@ -54,7 +54,7 @@ #include "readrange.h" /* buffer used for receive */ -static uint8_t Rx_Buf[MAX_MPDU] = { 0 }; +static uint8_t Rx_Buf[MAX_MPDU] = {0}; /* converted command line arguments */ static uint32_t Target_Device_Object_Instance = BACNET_MAX_INSTANCE; @@ -71,51 +71,43 @@ static bool Error_Detected = false; /* specific request data */ static BACNET_READ_RANGE_DATA RR_Request; -static void MyErrorHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - BACNET_ERROR_CLASS error_class, - BACNET_ERROR_CODE error_code) +static void MyErrorHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + BACNET_ERROR_CLASS error_class, + BACNET_ERROR_CODE error_code) { if (address_match(&Target_Address, src) && (invoke_id == Request_Invoke_ID)) { printf("BACnet Error: %s: %s\r\n", - bactext_error_class_name((int) error_class), - bactext_error_code_name((int) error_code)); + bactext_error_class_name((int)error_class), + bactext_error_code_name((int)error_code)); Error_Detected = true; } } -void MyAbortHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t abort_reason, - bool server) +void MyAbortHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t abort_reason, bool server) { - (void) server; + (void)server; if (address_match(&Target_Address, src) && (invoke_id == Request_Invoke_ID)) { printf("BACnet Abort: %s\n", - bactext_abort_reason_name((int) abort_reason)); + bactext_abort_reason_name((int)abort_reason)); Error_Detected = true; } } -void MyRejectHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t reject_reason) +void MyRejectHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t reject_reason) { if (address_match(&Target_Address, src) && (invoke_id == Request_Invoke_ID)) { printf("BACnet Reject: %s\n", - bactext_reject_reason_name((int) reject_reason)); + bactext_reject_reason_name((int)reject_reason)); Error_Detected = true; } } -static void Init_Service_Handlers( - void) +static void Init_Service_Handlers(void) { Device_Init(NULL); /* we need to handle who-is @@ -125,14 +117,13 @@ static void Init_Service_Handlers( apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_I_AM, handler_i_am_bind); /* set the handler for all the services we don't implement It is required to send the proper reject message... */ - apdu_set_unrecognized_service_handler_handler - (handler_unrecognized_service); + apdu_set_unrecognized_service_handler_handler(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_RANGE, - handler_read_range_ack); + handler_read_range_ack); /* handle any errors coming back */ apdu_set_error_handler(SERVICE_CONFIRMED_READ_PROPERTY, MyErrorHandler); @@ -144,14 +135,15 @@ static void Init_Service_Handlers( static void print_usage(char *filename) { printf("Usage: %s device-instance object-type object-instance property\n", - filename); + filename); printf(" range-type > count\n"); printf(" [--version][--help]\n"); } static void print_help(char *filename) { - printf("Read a range of properties from an array or list property\n" + printf( + "Read a range of properties from an array or list property\n" "in an object in a BACnet device and print the values.\n" "device-instance:\n" "BACnet Device Object Instance number that you are\n" @@ -186,20 +178,17 @@ static void print_help(char *filename) "If you want read the Log_Buffer of Trend Log 2\n" "in Device 123, from starting position 1 and read 10 entries,\n" "you could send the following command:\n" - "%s 123 20 2 131 1 1 10\n", filename); + "%s 123 20 2 131 1 1 10\n", + filename); printf("%s 123 20 2 131 2 1 10\n", filename); printf("%s 123 20 2 131 3 1/1/2014 00:00:01 10\n", filename); } -int main( - int argc, - char *argv[]) +int main(int argc, char *argv[]) { - BACNET_ADDRESS src = { - 0 - }; /* address where message came from */ + BACNET_ADDRESS src = {0}; /* address where message came from */ uint16_t pdu_len = 0; - unsigned timeout = 100; /* milliseconds */ + unsigned timeout = 100; /* milliseconds */ unsigned max_apdu = 0; time_t elapsed_seconds = 0; time_t last_seconds = 0; @@ -221,8 +210,10 @@ int main( } if (strcmp(argv[argi], "--version") == 0) { printf("%s %s\n", filename, BACNET_VERSION_TEXT); - printf("Copyright (C) 2014 by Steve Karg and others.\n" - "This is free software; see the source for copying conditions.\n" + printf( + "Copyright (C) 2014 by Steve Karg and others.\n" + "This is free software; see the source for copying " + "conditions.\n" "There is NO warranty; not even for MERCHANTABILITY or\n" "FITNESS FOR A PARTICULAR PURPOSE.\n"); return 0; @@ -241,7 +232,7 @@ int main( /* some bounds checking */ 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); + Target_Device_Object_Instance, BACNET_MAX_INSTANCE); return 1; } if (Target_Object_Range_Type == 1) { @@ -270,39 +261,34 @@ int main( return 0; } RR_Request.RequestType = RR_BY_TIME; - count = - sscanf(argv[6], "%4d/%3d/%3d:%3d", &year, &month, &day, - &wday); + count = sscanf(argv[6], "%4d/%3d/%3d:%3d", &year, &month, &day, &wday); if (count == 3) { - datetime_set_date(&RR_Request.Range.RefTime.date, - (uint16_t) year, - (uint8_t) month, - (uint8_t) day); + datetime_set_date(&RR_Request.Range.RefTime.date, (uint16_t)year, + (uint8_t)month, (uint8_t)day); } else if (count == 4) { - RR_Request.Range.RefTime.date.year = (uint16_t) year; - RR_Request.Range.RefTime.date.month = (uint8_t) month; - RR_Request.Range.RefTime.date.day = (uint8_t) day; - RR_Request.Range.RefTime.date.wday = (uint8_t) wday; + RR_Request.Range.RefTime.date.year = (uint16_t)year; + RR_Request.Range.RefTime.date.month = (uint8_t)month; + RR_Request.Range.RefTime.date.day = (uint8_t)day; + RR_Request.Range.RefTime.date.wday = (uint8_t)wday; } else { fprintf(stderr, "Invalid date format!\r\n"); return 1; } count = - sscanf(argv[7], "%3d:%3d:%3d.%3d", &hour, &min, &sec, - &hundredths); + sscanf(argv[7], "%3d:%3d:%3d.%3d", &hour, &min, &sec, &hundredths); if (count == 4) { - RR_Request.Range.RefTime.time.hour = (uint8_t) hour; - RR_Request.Range.RefTime.time.min = (uint8_t) min; - RR_Request.Range.RefTime.time.sec = (uint8_t) sec; - RR_Request.Range.RefTime.time.hundredths = (uint8_t) hundredths; + RR_Request.Range.RefTime.time.hour = (uint8_t)hour; + RR_Request.Range.RefTime.time.min = (uint8_t)min; + RR_Request.Range.RefTime.time.sec = (uint8_t)sec; + RR_Request.Range.RefTime.time.hundredths = (uint8_t)hundredths; } else if (count == 3) { - RR_Request.Range.RefTime.time.hour = (uint8_t) hour; - RR_Request.Range.RefTime.time.min = (uint8_t) min; - RR_Request.Range.RefTime.time.sec = (uint8_t) sec; + RR_Request.Range.RefTime.time.hour = (uint8_t)hour; + RR_Request.Range.RefTime.time.min = (uint8_t)min; + RR_Request.Range.RefTime.time.sec = (uint8_t)sec; RR_Request.Range.RefTime.time.hundredths = 0; } else if (count == 2) { - RR_Request.Range.RefTime.time.hour = (uint8_t) hour; - RR_Request.Range.RefTime.time.min = (uint8_t) min; + RR_Request.Range.RefTime.time.hour = (uint8_t)hour; + RR_Request.Range.RefTime.time.min = (uint8_t)min; RR_Request.Range.RefTime.time.sec = 0; RR_Request.Range.RefTime.time.hundredths = 0; } else { @@ -332,12 +318,11 @@ int main( last_seconds = time(NULL); timeout_seconds = (apdu_timeout() / 1000) * apdu_retries(); /* try to bind with the device */ - found = - address_bind_request(Target_Device_Object_Instance, &max_apdu, - &Target_Address); + found = address_bind_request(Target_Device_Object_Instance, &max_apdu, + &Target_Address); if (!found) { Send_WhoIs(Target_Device_Object_Instance, - Target_Device_Object_Instance); + Target_Device_Object_Instance); } /* loop forever */ for (;;) { @@ -346,21 +331,19 @@ int main( /* at least one second has passed */ if (current_seconds != last_seconds) - tsm_timer_milliseconds((uint16_t) ((current_seconds - - last_seconds) * 1000)); + tsm_timer_milliseconds( + (uint16_t)((current_seconds - last_seconds) * 1000)); if (Error_Detected) break; /* wait until the device is bound, or timeout and quit */ if (!found) { - found = - address_bind_request(Target_Device_Object_Instance, &max_apdu, - &Target_Address); + found = address_bind_request(Target_Device_Object_Instance, + &max_apdu, &Target_Address); } if (found) { if (Request_Invoke_ID == 0) { Request_Invoke_ID = Send_ReadRange_Request( - Target_Device_Object_Instance, - &RR_Request); + Target_Device_Object_Instance, &RR_Request); } else if (tsm_invoke_id_free(Request_Invoke_ID)) break; else if (tsm_invoke_id_failed(Request_Invoke_ID)) { diff --git a/demo/reinit/main.c b/demo/reinit/main.c index 4a7a3068..4b6dcf98 100644 --- a/demo/reinit/main.c +++ b/demo/reinit/main.c @@ -1,34 +1,34 @@ /************************************************************************** -* -* Copyright (C) 2006 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2006 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* command line tool that sends a BACnet service, and displays the reply */ #include #include #include #include -#include /* for time */ +#include /* for time */ #include #include "bactext.h" #include "iam.h" @@ -52,7 +52,7 @@ #include "dlenv.h" /* buffer used for receive */ -static uint8_t Rx_Buf[MAX_MPDU] = { 0 }; +static uint8_t Rx_Buf[MAX_MPDU] = {0}; /* global variables used in this file */ static uint32_t Target_Device_Object_Instance = BACNET_MAX_INSTANCE; @@ -62,57 +62,48 @@ static char *Reinitialize_Password = NULL; static bool Error_Detected = false; -static void MyErrorHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - BACNET_ERROR_CLASS error_class, - BACNET_ERROR_CODE error_code) +static void MyErrorHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + BACNET_ERROR_CLASS error_class, + BACNET_ERROR_CODE error_code) { /* FIXME: verify src and invoke id */ - (void) src; - (void) invoke_id; + (void)src; + (void)invoke_id; printf("BACnet Error: %s: %s\r\n", bactext_error_class_name(error_class), - bactext_error_code_name(error_code)); + bactext_error_code_name(error_code)); Error_Detected = true; } -void MyAbortHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t abort_reason, - bool server) +void MyAbortHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t abort_reason, bool server) { /* FIXME: verify src and invoke id */ - (void) src; - (void) invoke_id; - (void) server; + (void)src; + (void)invoke_id; + (void)server; printf("BACnet Abort: %s\r\n", bactext_abort_reason_name(abort_reason)); Error_Detected = true; } -void MyRejectHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t reject_reason) +void MyRejectHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t reject_reason) { /* FIXME: verify src and invoke id */ - (void) src; - (void) invoke_id; + (void)src; + (void)invoke_id; printf("BACnet Reject: %s\r\n", bactext_reject_reason_name(reject_reason)); Error_Detected = true; } -void MyReinitializeDeviceSimpleAckHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id) +void MyReinitializeDeviceSimpleAckHandler(BACNET_ADDRESS *src, + uint8_t invoke_id) { - (void) src; - (void) invoke_id; + (void)src; + (void)invoke_id; printf("ReinitializeDevice Acknowledged!\r\n"); } -static void Init_Service_Handlers( - void) +static void Init_Service_Handlers(void) { Device_Init(NULL); /* we need to handle who-is @@ -122,31 +113,25 @@ static void Init_Service_Handlers( apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_I_AM, handler_i_am_bind); /* set the handler for all the services we don't implement It is required to send the proper reject message... */ - apdu_set_unrecognized_service_handler_handler - (handler_unrecognized_service); + apdu_set_unrecognized_service_handler_handler(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 ack coming back */ - apdu_set_confirmed_simple_ack_handler - (SERVICE_CONFIRMED_REINITIALIZE_DEVICE, - MyReinitializeDeviceSimpleAckHandler); + apdu_set_confirmed_simple_ack_handler(SERVICE_CONFIRMED_REINITIALIZE_DEVICE, + MyReinitializeDeviceSimpleAckHandler); /* handle any errors coming back */ apdu_set_error_handler(SERVICE_CONFIRMED_REINITIALIZE_DEVICE, - MyErrorHandler); + MyErrorHandler); apdu_set_abort_handler(MyAbortHandler); apdu_set_reject_handler(MyRejectHandler); } -int main( - int argc, - char *argv[]) +int main(int argc, char *argv[]) { - BACNET_ADDRESS src = { - 0 - }; /* address where message came from */ + BACNET_ADDRESS src = {0}; /* address where message came from */ uint16_t pdu_len = 0; - unsigned timeout = 100; /* milliseconds */ + unsigned timeout = 100; /* milliseconds */ unsigned max_apdu = 0; time_t elapsed_seconds = 0; time_t last_seconds = 0; @@ -157,13 +142,21 @@ int main( if (argc < 3) { /* note: priority 16 and 0 should produce the same end results... */ - printf("Usage: %s device-instance state [password]\r\n" - "Send BACnet ReinitializeDevice service to device.\r\n" "\r\n" + printf( + "Usage: %s device-instance state [password]\r\n" + "Send BACnet ReinitializeDevice service to device.\r\n" + "\r\n" "The device-instance can be 0 to %d.\r\n" - "Possible state values:\r\n" " 0=coldstart\r\n" - " 1=warmstart\r\n" " 2=startbackup\r\n" " 3=endbackup\r\n" - " 4=startrestore\r\n" " 5=endrestore\r\n" " 6=abortrestore\r\n" - "The optional password is a character string of 1 to 20 characters.\r\n", + "Possible state values:\r\n" + " 0=coldstart\r\n" + " 1=warmstart\r\n" + " 2=startbackup\r\n" + " 3=endbackup\r\n" + " 4=startrestore\r\n" + " 5=endrestore\r\n" + " 6=abortrestore\r\n" + "The optional password is a character string of 1 to 20 " + "characters.\r\n", filename_remove_path(argv[0]), BACNET_MAX_INSTANCE - 1); return 0; } @@ -176,7 +169,7 @@ int main( 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); + Target_Device_Object_Instance, BACNET_MAX_INSTANCE); return 1; } @@ -190,12 +183,11 @@ int main( last_seconds = time(NULL); timeout_seconds = (apdu_timeout() / 1000) * apdu_retries(); /* try to bind with the device */ - found = - address_bind_request(Target_Device_Object_Instance, &max_apdu, - &Target_Address); + found = address_bind_request(Target_Device_Object_Instance, &max_apdu, + &Target_Address); if (!found) { Send_WhoIs(Target_Device_Object_Instance, - Target_Device_Object_Instance); + Target_Device_Object_Instance); } /* loop forever */ for (;;) { @@ -216,15 +208,13 @@ int main( break; /* wait until the device is bound, or timeout and quit */ if (!found) { - found = - address_bind_request(Target_Device_Object_Instance, &max_apdu, - &Target_Address); + found = address_bind_request(Target_Device_Object_Instance, + &max_apdu, &Target_Address); } if (found) { if (invoke_id == 0) { - invoke_id = - Send_Reinitialize_Device_Request - (Target_Device_Object_Instance, Reinitialize_State, + invoke_id = Send_Reinitialize_Device_Request( + Target_Device_Object_Instance, Reinitialize_State, Reinitialize_Password); } else if (tsm_invoke_id_free(invoke_id)) break; diff --git a/demo/router-ipv6/main.c b/demo/router-ipv6/main.c index 4e580f39..335a54af 100644 --- a/demo/router-ipv6/main.c +++ b/demo/router-ipv6/main.c @@ -1,33 +1,33 @@ /** -* @file -* @author Steve Karg -* @date 2016 -* @brief Simple BACnet/IP to BACnet/IPv6 router -* -* @section LICENSE -* -* Copyright (C) 2016 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*/ + * @file + * @author Steve Karg + * @date 2016 + * @brief Simple BACnet/IP to BACnet/IPv6 router + * + * @section LICENSE + * + * Copyright (C) 2016 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ #include #include #include @@ -60,25 +60,25 @@ #include "bvlc.h" /** -* 6.6.1 Routing Tables -* -* By definition, a router is a device that is connected to at least -* two BACnet networks. Each attachment is through a "port." A -* "routing table" consists of the following information for each port: -* (a) the MAC address of the port's connection to its network; -* (b) the 2-octet network number of the directly connected network; -* (c) a list of network numbers reachable through the port along -* with the MAC address of the next router on the path to each -* network number and the reachability status of each such network. -* -* The "reachability status" is an implementation-dependent value -* that indicates whether the associated network is able to -* receive traffic. The reachability status shall be able to -* distinguish, at a minimum, between "permanent" failures of a route, -* such as might result from the failure of a router, and "temporary" -* unreachability due to the imposition of a congestion control -* restriction. -*/ + * 6.6.1 Routing Tables + * + * By definition, a router is a device that is connected to at least + * two BACnet networks. Each attachment is through a "port." A + * "routing table" consists of the following information for each port: + * (a) the MAC address of the port's connection to its network; + * (b) the 2-octet network number of the directly connected network; + * (c) a list of network numbers reachable through the port along + * with the MAC address of the next router on the path to each + * network number and the reachability status of each such network. + * + * The "reachability status" is an implementation-dependent value + * that indicates whether the associated network is able to + * receive traffic. The reachability status shall be able to + * distinguish, at a minimum, between "permanent" failures of a route, + * such as might result from the failure of a router, and "temporary" + * unreachability due to the imposition of a congestion control + * restriction. + */ typedef struct _dnet { uint8_t mac[MAX_MAC_LEN]; uint8_t mac_len; @@ -111,11 +111,8 @@ static bool Exit_Requested; * The caller will need to compare the sought after net with the * returned port->net to determine if the addr is filled. */ -static DNET *dnet_find( - uint16_t net, - BACNET_ADDRESS * addr) +static DNET *dnet_find(uint16_t net, BACNET_ADDRESS *addr) { - DNET *port = Router_Table_Head; DNET *dnet = NULL; unsigned int i = 0; @@ -146,9 +143,7 @@ static DNET *dnet_find( return NULL; } -static bool port_find( - uint16_t snet, - BACNET_ADDRESS *addr) +static bool port_find(uint16_t snet, BACNET_ADDRESS *addr) { DNET *port = NULL; bool found = false; @@ -178,9 +173,7 @@ static bool port_find( * @param snet - router port SNET * @param addr - address of port at the net to be added */ -static void port_add( - uint16_t snet, - BACNET_ADDRESS *addr) +static void port_add(uint16_t snet, BACNET_ADDRESS *addr) { DNET *port = NULL; DNET *dnet = NULL; @@ -191,7 +184,7 @@ static void port_add( port = Router_Table_Head; if (!port) { /* create first port */ - port = (DNET *) calloc(1, sizeof(DNET)); + port = (DNET *)calloc(1, sizeof(DNET)); assert(port); Router_Table_Head = port; } else { @@ -200,7 +193,7 @@ static void port_add( port = port->next; } else { /* create next port */ - dnet = (DNET *) calloc(1, sizeof(DNET)); + dnet = (DNET *)calloc(1, sizeof(DNET)); assert(dnet); port->next = dnet; port = port->next; @@ -228,12 +221,8 @@ static void port_add( * @param net - net to be added * @param addr - address of router at the net to be added */ -static void dnet_add( - uint16_t snet, - uint16_t net, - BACNET_ADDRESS *addr) +static void dnet_add(uint16_t snet, uint16_t net, BACNET_ADDRESS *addr) { - DNET *dnet = NULL; DNET *port = NULL; DNET *prior_dnet = NULL; @@ -252,7 +241,7 @@ static void dnet_add( dnet = port->dnets; if (dnet == NULL) { /* first DNET to add */ - dnet = (DNET *) calloc(1, sizeof(DNET)); + dnet = (DNET *)calloc(1, sizeof(DNET)); assert(dnet); port->dnets = dnet; if (addr) { @@ -274,7 +263,7 @@ static void dnet_add( dnet = dnet->next; } /* next DNET to add */ - dnet = (DNET *) calloc(1, sizeof(DNET)); + dnet = (DNET *)calloc(1, sizeof(DNET)); if (addr) { dnet->mac_len = addr->mac_len; for (i = 0; i < MAX_MAC_LEN; i++) { @@ -293,8 +282,7 @@ static void dnet_add( * * @param dnets - router info to be freed */ -static void dnet_cleanup( - DNET * dnets) +static void dnet_cleanup(DNET *dnets) { DNET *dnet = dnets; while (dnet != NULL) { @@ -310,8 +298,7 @@ static void dnet_cleanup( * * @param dest - address to be filled with broadcast designator */ -static void datalink_get_broadcast_address( - BACNET_ADDRESS * dest) +static void datalink_get_broadcast_address(BACNET_ADDRESS *dest) { if (dest) { dest->mac_len = 0; @@ -333,12 +320,9 @@ static void datalink_get_broadcast_address( * * @return number of bytes sent */ -static int datalink_send_pdu( - uint16_t snet, - BACNET_ADDRESS * dest, - BACNET_NPDU_DATA * npdu_data, - uint8_t * pdu, - unsigned int pdu_len) +static int datalink_send_pdu(uint16_t snet, BACNET_ADDRESS *dest, + BACNET_NPDU_DATA *npdu_data, uint8_t *pdu, + unsigned int pdu_len) { int bytes_sent = 0; @@ -350,7 +334,7 @@ static int datalink_send_pdu( debug_printf("BVLC Send to DNET %u\n", (unsigned)dest->net); bytes_sent = bvlc_send_pdu(dest, npdu_data, pdu, pdu_len); } else if (snet == BIP6_Net) { - debug_printf("BVLC6 Send to DNET %u\n",(unsigned)dest->net); + debug_printf("BVLC6 Send to DNET %u\n", (unsigned)dest->net); bytes_sent = bip6_send_pdu(dest, npdu_data, pdu, pdu_len); } @@ -364,24 +348,24 @@ static int datalink_send_pdu( * APDU instead of a Network Layer Message. * * @param npdu_data [out] Returns a filled-out structure with information - * provided by the other arguments and good defaults. + * provided by the other arguments and + * good defaults. * @param network_message_type [in] The type of Network Layer Message. * @param data_expecting_reply [in] True if message should have a reply. * @param priority [in] One of the 4 priorities defined in section 6.2.2, * like B'11' = Life Safety message */ static void npdu_encode_npdu_network( - BACNET_NPDU_DATA * npdu_data, - BACNET_NETWORK_MESSAGE_TYPE network_message_type, - bool data_expecting_reply, + BACNET_NPDU_DATA *npdu_data, + BACNET_NETWORK_MESSAGE_TYPE network_message_type, bool data_expecting_reply, BACNET_MESSAGE_PRIORITY priority) { if (npdu_data) { npdu_data->data_expecting_reply = data_expecting_reply; npdu_data->protocol_version = BACNET_PROTOCOL_VERSION; - npdu_data->network_layer_message = true; /* false if APDU */ + npdu_data->network_layer_message = true; /* false if APDU */ npdu_data->network_message_type = network_message_type; /* optional */ - npdu_data->vendor_id = 0; /* optional, if net message type is > 0x80 */ + npdu_data->vendor_id = 0; /* optional, if net message type is > 0x80 */ npdu_data->priority = priority; npdu_data->hop_count = HOP_COUNT_DEFAULT; } @@ -408,13 +392,11 @@ static void send_i_am_router_to_network(uint16_t snet, uint16_t net) DNET *dnet = NULL; datalink_get_broadcast_address(&dest); - npdu_encode_npdu_network(&npdu_data, - NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK, - data_expecting_reply, MESSAGE_PRIORITY_NORMAL); + npdu_encode_npdu_network(&npdu_data, NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK, + data_expecting_reply, MESSAGE_PRIORITY_NORMAL); /* We don't need src information, since a message can't originate from our downstream BACnet network. */ - pdu_len = - npdu_encode_pdu(&Tx_Buffer[0], &dest, NULL, &npdu_data); + pdu_len = npdu_encode_pdu(&Tx_Buffer[0], &dest, NULL, &npdu_data); if (net) { len = encode_unsigned16(&Tx_Buffer[pdu_len], net); pdu_len += len; @@ -431,14 +413,12 @@ static void send_i_am_router_to_network(uint16_t snet, uint16_t net) while (port != NULL) { if (port->net != snet) { debug_printf("%u,", port->net); - len = encode_unsigned16(&Tx_Buffer[pdu_len], - port->net); + len = encode_unsigned16(&Tx_Buffer[pdu_len], port->net); pdu_len += len; dnet = port->dnets; while (dnet != NULL) { debug_printf("%u,", dnet->net); - len = encode_unsigned16(&Tx_Buffer[pdu_len], - dnet->net); + len = encode_unsigned16(&Tx_Buffer[pdu_len], dnet->net); pdu_len += len; dnet = dnet->next; } @@ -463,9 +443,7 @@ static void send_i_am_router_to_network(uint16_t snet, uint16_t net) * Optionally may designate a particular router destination, * especially when ACKing receipt of this message type. */ -void send_initialize_routing_table_ack( - uint8_t snet, - BACNET_ADDRESS * dst) +void send_initialize_routing_table_ack(uint8_t snet, BACNET_ADDRESS *dst) { BACNET_ADDRESS dest; bool data_expecting_reply = false; @@ -481,13 +459,11 @@ void send_initialize_routing_table_ack( } else { datalink_get_broadcast_address(&dest); } - npdu_encode_npdu_network(&npdu_data, - NETWORK_MESSAGE_INIT_RT_TABLE_ACK, - data_expecting_reply, MESSAGE_PRIORITY_NORMAL); + npdu_encode_npdu_network(&npdu_data, NETWORK_MESSAGE_INIT_RT_TABLE_ACK, + data_expecting_reply, MESSAGE_PRIORITY_NORMAL); /* We don't need src information, since a message can't originate from our downstream BACnet network. */ - pdu_len = - npdu_encode_pdu(&Tx_Buffer[0], &dest, NULL, &npdu_data); + pdu_len = npdu_encode_pdu(&Tx_Buffer[0], &dest, NULL, &npdu_data); /* First, count the number of Ports we will encode */ port = Router_Table_Head; while (port != NULL) { @@ -526,11 +502,8 @@ void send_initialize_routing_table_ack( * destination. * @param reject_reason [in] One of the BACNET_NETWORK_REJECT_REASONS codes. */ -void send_reject_message_to_network( - uint16_t snet, - BACNET_ADDRESS * dst, - uint8_t reject_reason, - uint16_t dnet) +void send_reject_message_to_network(uint16_t snet, BACNET_ADDRESS *dst, + uint8_t reject_reason, uint16_t dnet) { BACNET_ADDRESS dest; bool data_expecting_reply = false; @@ -544,12 +517,11 @@ void send_reject_message_to_network( datalink_get_broadcast_address(&dest); } npdu_encode_npdu_network(&npdu_data, - NETWORK_MESSAGE_REJECT_MESSAGE_TO_NETWORK, - data_expecting_reply, MESSAGE_PRIORITY_NORMAL); + NETWORK_MESSAGE_REJECT_MESSAGE_TO_NETWORK, + data_expecting_reply, MESSAGE_PRIORITY_NORMAL); /* We don't need src information, since a message can't originate from our downstream BACnet network. */ - pdu_len = - npdu_encode_pdu(&Tx_Buffer[0], &dest, NULL, &npdu_data); + pdu_len = npdu_encode_pdu(&Tx_Buffer[0], &dest, NULL, &npdu_data); /* encode the reject reason */ Tx_Buffer[pdu_len] = reject_reason; pdu_len++; @@ -566,9 +538,7 @@ void send_reject_message_to_network( * * @param dnet [in] Which BACnet network we are seeking */ -static void send_who_is_router_to_network( - uint16_t snet, - uint16_t dnet) +static void send_who_is_router_to_network(uint16_t snet, uint16_t dnet) { BACNET_ADDRESS dest; bool data_expecting_reply = false; @@ -578,10 +548,9 @@ static void send_who_is_router_to_network( datalink_get_broadcast_address(&dest); npdu_encode_npdu_network(&npdu_data, - NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK, - data_expecting_reply, MESSAGE_PRIORITY_NORMAL); - pdu_len = - npdu_encode_pdu(&Tx_Buffer[0], &dest, NULL, &npdu_data); + NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK, + data_expecting_reply, MESSAGE_PRIORITY_NORMAL); + pdu_len = npdu_encode_pdu(&Tx_Buffer[0], &dest, NULL, &npdu_data); if (dnet) { len = encode_unsigned16(&Tx_Buffer[pdu_len], dnet); pdu_len += len; @@ -646,12 +615,9 @@ static void send_who_is_router_to_network( * bytes that have already been decoded. * @param npdu_len [in] The length of the remaining NPDU message in npdu[]. */ -static void who_is_router_to_network_handler( - uint16_t snet, - BACNET_ADDRESS * src, - BACNET_NPDU_DATA * npdu_data, - uint8_t * npdu, - uint16_t npdu_len) +static void who_is_router_to_network_handler(uint16_t snet, BACNET_ADDRESS *src, + BACNET_NPDU_DATA *npdu_data, + uint8_t *npdu, uint16_t npdu_len) { DNET *port = NULL; uint16_t network = 0; @@ -698,12 +664,9 @@ static void who_is_router_to_network_handler( * bytes that have already been decoded. * @param npdu_len [in] The length of the remaining NPDU message in npdu[]. */ -static void network_control_handler( - uint16_t snet, - BACNET_ADDRESS * src, - BACNET_NPDU_DATA * npdu_data, - uint8_t * npdu, - uint16_t npdu_len) +static void network_control_handler(uint16_t snet, BACNET_ADDRESS *src, + BACNET_NPDU_DATA *npdu_data, uint8_t *npdu, + uint16_t npdu_len) { uint16_t npdu_offset = 0; uint16_t dnet = 0; @@ -714,8 +677,8 @@ static void network_control_handler( fprintf(stderr, "Received %s\n", msg_name); switch (npdu_data->network_message_type) { case NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK: - who_is_router_to_network_handler( - snet, src, npdu_data, npdu, npdu_len); + who_is_router_to_network_handler(snet, src, npdu_data, npdu, + npdu_len); break; case NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK: /* add its DNETs to our routing table */ @@ -750,7 +713,8 @@ static void network_control_handler( fprintf(stderr, "Reason: Network is busy.\n"); break; case 3: - fprintf(stderr, "Reason: Unknown network message type.\n"); + fprintf(stderr, + "Reason: Unknown network message type.\n"); break; case 4: fprintf(stderr, "Reason: Message too long.\n"); @@ -811,8 +775,8 @@ static void network_control_handler( break; default: /* An unrecognized message is bad; send an error response. */ - send_reject_message_to_network(snet, src, - NETWORK_REJECT_UNKNOWN_MESSAGE_TYPE, 0); + send_reject_message_to_network( + snet, src, NETWORK_REJECT_UNKNOWN_MESSAGE_TYPE, 0); break; } } @@ -825,10 +789,8 @@ static void network_control_handler( * @param snet [in] The source network port where the message came from * @param src [in] The BACNET_ADDRESS of the message's original src. */ -static void routed_src_address( - BACNET_ADDRESS * router_src, - uint16_t snet, - BACNET_ADDRESS * src) +static void routed_src_address(BACNET_ADDRESS *router_src, uint16_t snet, + BACNET_ADDRESS *src) { unsigned int i = 0; @@ -870,18 +832,14 @@ static void routed_src_address( * * @param src [in] The BACNET_ADDRESS of the message's source. * @param dest [in] The BACNET_ADDRESS of the message's destination. - * @param DNET_list [in] List of our reachable downstream BACnet Network numbers. - * Normally just one valid entry; terminated with a -1 value. + * @param DNET_list [in] List of our reachable downstream BACnet Network + * numbers. Normally just one valid entry; terminated with a -1 value. * @param apdu [in] The apdu portion of the request, to be processed. * @param apdu_len [in] The total (remaining) length of the apdu. */ -static void routed_apdu_handler( - uint16_t snet, - BACNET_NPDU_DATA * npdu, - BACNET_ADDRESS * src, - BACNET_ADDRESS * dest, - uint8_t * apdu, - uint16_t apdu_len) +static void routed_apdu_handler(uint16_t snet, BACNET_NPDU_DATA *npdu, + BACNET_ADDRESS *src, BACNET_ADDRESS *dest, + uint8_t *apdu, uint16_t apdu_len) { DNET *port = NULL; BACNET_ADDRESS local_dest; @@ -915,8 +873,8 @@ static void routed_apdu_handler( port = Router_Table_Head; while (port != NULL) { if (port->net != snet) { - datalink_send_pdu(port->net, &local_dest, npdu, - &Tx_Buffer[0], npdu_len+apdu_len); + datalink_send_pdu(port->net, &local_dest, npdu, &Tx_Buffer[0], + npdu_len + apdu_len); } port = port->next; } @@ -941,11 +899,11 @@ static void routed_apdu_handler( npdu_len = npdu_encode_pdu(&Tx_Buffer[0], &local_dest, &router_src, npdu); memmove(&Tx_Buffer[npdu_len], apdu, apdu_len); - datalink_send_pdu(port->net, &local_dest, npdu, - &Tx_Buffer[0], npdu_len+apdu_len); + datalink_send_pdu(port->net, &local_dest, npdu, &Tx_Buffer[0], + npdu_len + apdu_len); } else { debug_printf("Routing to another Router %u\n", - (unsigned)remote_dest.net); + (unsigned)remote_dest.net); /* Case 2: the message must be relayed to another router for further transmission */ /* In the second case, if the Hop Count is greater than zero, @@ -958,22 +916,20 @@ static void routed_apdu_handler( npdu_len = npdu_encode_pdu(&Tx_Buffer[0], &remote_dest, &router_src, npdu); memmove(&Tx_Buffer[npdu_len], apdu, apdu_len); - datalink_send_pdu(port->net, &remote_dest, npdu, - &Tx_Buffer[0], npdu_len+apdu_len); + datalink_send_pdu(port->net, &remote_dest, npdu, &Tx_Buffer[0], + npdu_len + apdu_len); } } else if (dest->net) { - debug_printf("Routing to Unknown Route %u\n", - (unsigned)dest->net); + debug_printf("Routing to Unknown Route %u\n", (unsigned)dest->net); /* Case 3: a global broadcast is required. */ dest->mac_len = 0; npdu->hop_count--; /* encode both source and destination */ routed_src_address(&router_src, snet, src); - npdu_len = - npdu_encode_pdu(&Tx_Buffer[0], dest, &router_src, npdu); + npdu_len = npdu_encode_pdu(&Tx_Buffer[0], dest, &router_src, npdu); memmove(&Tx_Buffer[npdu_len], apdu, apdu_len); - datalink_send_pdu(port->net, dest, npdu, - &Tx_Buffer[0], npdu_len+apdu_len); + datalink_send_pdu(port->net, dest, npdu, &Tx_Buffer[0], + npdu_len + apdu_len); /* If the next router is unknown, an attempt shall be made to identify it using a Who-Is-Router-To-Network message. */ send_who_is_router_to_network(0, dest->net); @@ -995,15 +951,12 @@ static void routed_apdu_handler( * @param pdu [in] Buffer containing the NPDU and APDU of the received packet. * @param pdu_len [in] The size of the received message in the pdu[] buffer. */ -static void my_routing_npdu_handler( - uint16_t snet, - BACNET_ADDRESS * src, - uint8_t * pdu, - uint16_t pdu_len) +static void my_routing_npdu_handler(uint16_t snet, BACNET_ADDRESS *src, + uint8_t *pdu, uint16_t pdu_len) { int apdu_offset = 0; - BACNET_ADDRESS dest = { 0 }; - BACNET_NPDU_DATA npdu_data = { 0 }; + BACNET_ADDRESS dest = {0}; + BACNET_NPDU_DATA npdu_data = {0}; if (!pdu) { /* no packet */ @@ -1014,39 +967,39 @@ static void my_routing_npdu_handler( } else if (npdu_data.network_layer_message) { if ((dest.net == 0) || (dest.net == BACNET_BROADCAST_NETWORK)) { network_control_handler(snet, src, &npdu_data, - &pdu[apdu_offset], (uint16_t) (pdu_len - apdu_offset)); + &pdu[apdu_offset], + (uint16_t)(pdu_len - apdu_offset)); } else { /* The DNET is set, but we don't support downstream routers, * so we just silently drop this network layer message, * since only routers can handle it (even if for our DNET) */ } } else if ((apdu_offset > 0) && (apdu_offset <= pdu_len)) { - if ((dest.net == 0) || - (dest.net == BACNET_BROADCAST_NETWORK) || + if ((dest.net == 0) || (dest.net == BACNET_BROADCAST_NETWORK) || (npdu_data.hop_count > 1)) { /* only handle the version that we know how to handle */ /* and we are not a router, so ignore messages with routing information cause they are not for us */ if ((dest.net == BACNET_BROADCAST_NETWORK) && ((pdu[apdu_offset] & 0xF0) == - PDU_TYPE_CONFIRMED_SERVICE_REQUEST)) { + PDU_TYPE_CONFIRMED_SERVICE_REQUEST)) { /* hack for 5.4.5.1 - IDLE */ /* ConfirmedBroadcastReceived */ /* then enter IDLE - ignore the PDU */ } else { routed_apdu_handler(snet, &npdu_data, src, &dest, - &pdu[apdu_offset], - (uint16_t) (pdu_len - apdu_offset)); + &pdu[apdu_offset], + (uint16_t)(pdu_len - apdu_offset)); /* add a Device object and application layer */ if ((dest.net == 0) || (dest.net == BACNET_BROADCAST_NETWORK)) { apdu_handler(src, &pdu[apdu_offset], - (uint16_t) (pdu_len - apdu_offset)); + (uint16_t)(pdu_len - apdu_offset)); } } } else { fprintf(stderr, "NPDU: DNET=%u. Discarded!\n", - (unsigned) dest.net); + (unsigned)dest.net); } } } else { @@ -1069,7 +1022,7 @@ static void datalink_init(void) BIP_Debug = true; pEnv = getenv("BACNET_IP_PORT"); if (pEnv) { - bip_set_port(htons((uint16_t) strtol(pEnv, NULL, 0))); + bip_set_port(htons((uint16_t)strtol(pEnv, NULL, 0))); } else { /* BIP_Port is statically initialized to 0xBAC0, * so if it is different, then it was programmatically altered, @@ -1088,14 +1041,13 @@ static void datalink_init(void) /* BACnet/IPv6 Initialization */ pEnv = getenv("BACNET_BIP6_PORT"); if (pEnv) { - bip6_set_port((uint16_t) strtol(pEnv, NULL, 0)); + bip6_set_port((uint16_t)strtol(pEnv, NULL, 0)); } pEnv = getenv("BACNET_BIP6_BROADCAST"); if (pEnv) { BACNET_IP6_ADDRESS addr; - bvlc6_address_set(&addr, - (uint16_t) strtol(pEnv, NULL, 0), 0, 0, 0, 0, 0, 0, - BIP6_MULTICAST_GROUP_ID); + bvlc6_address_set(&addr, (uint16_t)strtol(pEnv, NULL, 0), 0, 0, 0, 0, 0, + 0, BIP6_MULTICAST_GROUP_ID); bip6_set_broadcast_addr(&addr); } if (!bip6_init(getenv("BACNET_BIP6_IFACE"))) { @@ -1144,8 +1096,7 @@ static void cleanup(void) } #if defined(_WIN32) -static BOOL WINAPI CtrlCHandler( - DWORD dwCtrlType) +static BOOL WINAPI CtrlCHandler(DWORD dwCtrlType) { dwCtrlType = dwCtrlType; @@ -1162,19 +1113,17 @@ static BOOL WINAPI CtrlCHandler( void control_c_hooks(void) { SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), ENABLE_PROCESSED_INPUT); - SetConsoleCtrlHandler((PHANDLER_ROUTINE) CtrlCHandler, TRUE); + SetConsoleCtrlHandler((PHANDLER_ROUTINE)CtrlCHandler, TRUE); } #else -static void sig_int( - int signo) +static void sig_int(int signo) { - (void) signo; + (void)signo; Exit_Requested = true; exit(0); } -void signal_init( - void) +void signal_init(void) { signal(SIGINT, sig_int); signal(SIGHUP, sig_int); @@ -1194,13 +1143,9 @@ void control_c_hooks(void) * @param argv [in] Takes one argument: the Device Instance #. * @return 0 on success. */ -int main( - int argc, - char *argv[]) +int main(int argc, char *argv[]) { - BACNET_ADDRESS src = { - 0 - }; /* address where message came from */ + BACNET_ADDRESS src = {0}; /* address where message came from */ uint16_t pdu_len = 0; time_t last_seconds = 0; time_t current_seconds = 0; @@ -1234,10 +1179,11 @@ int main( /* process */ if (pdu_len) { debug_printf("BACnet/IPv6 Received packet\n"); - my_routing_npdu_handler(BIP6_Net, &src, &BIP6_Rx_Buffer[0], pdu_len); + my_routing_npdu_handler(BIP6_Net, &src, &BIP6_Rx_Buffer[0], + pdu_len); } /* at least one second has passed */ - elapsed_seconds = (uint32_t) (current_seconds - last_seconds); + elapsed_seconds = (uint32_t)(current_seconds - last_seconds); if (elapsed_seconds) { last_seconds = current_seconds; bvlc_maintenance_timer(elapsed_seconds); diff --git a/demo/router/ipmodule.c b/demo/router/ipmodule.c index 6d3dd1ed..9abab181 100644 --- a/demo/router/ipmodule.c +++ b/demo/router/ipmodule.c @@ -1,31 +1,31 @@ /** -* @file -* @author Andriy Sukhynyuk, Vasyl Tkhir, Andriy Ivasiv -* @date 2012 -* @brief Datalink IP module -* -* @section LICENSE -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*/ + * @file + * @author Andriy Sukhynyuk, Vasyl Tkhir, Andriy Ivasiv + * @date 2012 + * @brief Datalink IP module + * + * @section LICENSE + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ #include #include #include @@ -33,26 +33,23 @@ #include "bacint.h" #ifdef TEST_PACKET -uint8_t test_packet[] = { 0x81, 0x0a, 0x00, 0x16, /* BVLC header */ - 0x01, 0x24, 0x00, 0x01, 0x01, 0x0b, 0xff, /* NPDU */ - 0x00, 0x03, 0x01, 0x0c, 0x0c, 0x00, 0x00, 0x00, 0x02, 0x19, 0x55 -}; /* APDU */ +uint8_t test_packet[] = {0x81, 0x0a, 0x00, 0x16, /* BVLC header */ + 0x01, 0x24, 0x00, 0x01, 0x01, 0x0b, 0xff, /* NPDU */ + 0x00, 0x03, 0x01, 0x0c, 0x0c, 0x00, 0x00, + 0x00, 0x02, 0x19, 0x55}; /* APDU */ #endif -extern int get_local_address_ioctl( - char *ifname, - struct in_addr *addr, - int request); +extern int get_local_address_ioctl(char *ifname, struct in_addr *addr, + int request); -void *dl_ip_thread( - void *pArgs) +void *dl_ip_thread(void *pArgs) { MSGBOX_ID msgboxid; BACMSG msg_storage, *bacmsg = NULL; MSG_DATA *msg_data; - ROUTER_PORT *port = (ROUTER_PORT *) pArgs; - IP_DATA ip_data; /* port specific parameters */ - BACNET_ADDRESS address = { 0 }; + ROUTER_PORT *port = (ROUTER_PORT *)pArgs; + IP_DATA ip_data; /* port specific parameters */ + BACNET_ADDRESS address = {0}; int status; uint8_t shutdown = 0; @@ -64,7 +61,7 @@ void *dl_ip_thread( /* allocate buffer */ ip_data.max_buff = MAX_BIP_MPDU; - ip_data.buff = (uint8_t *) malloc(ip_data.max_buff); + ip_data.buff = (uint8_t *)malloc(ip_data.max_buff); if (ip_data.buff == NULL) { port->state = INIT_FAILED; @@ -82,38 +79,37 @@ void *dl_ip_thread( port->state = RUNNING; while (!shutdown) { - /* check for incoming messages */ bacmsg = recv_from_msgbox(port->port_id, &msg_storage); if (bacmsg) { switch (bacmsg->type) { - case DATA:{ - msg_data = (MSG_DATA *) bacmsg->data; - memmove(&address.net, &msg_data->dest.net, 2); - memmove(&address.mac_len, &msg_data->dest.len, 1); - memmove(&address.mac[0], &msg_data->dest.adr[0], + case DATA: { + msg_data = (MSG_DATA *)bacmsg->data; + memmove(&address.net, &msg_data->dest.net, 2); + memmove(&address.mac_len, &msg_data->dest.len, 1); + memmove(&address.mac[0], &msg_data->dest.adr[0], MAX_MAC_LEN); - dl_ip_send(&ip_data, &address, msg_data->pdu, - msg_data->pdu_len); + dl_ip_send(&ip_data, &address, msg_data->pdu, + msg_data->pdu_len); - check_data(msg_data); + check_data(msg_data); - break; - } - - case SERVICE:{ - switch (bacmsg->subtype) { - case SHUTDOWN: - del_msgbox(port->port_id); - shutdown = 1; - break; - default: - break; - } - break; + break; + } + + case SERVICE: { + switch (bacmsg->subtype) { + case SHUTDOWN: + del_msgbox(port->port_id); + shutdown = 1; + break; + default: + break; } + break; + } default: break; @@ -140,28 +136,24 @@ void *dl_ip_thread( return NULL; } -bool dl_ip_init( - ROUTER_PORT * port, - IP_DATA * ip_data) +bool dl_ip_init(ROUTER_PORT *port, IP_DATA *ip_data) { struct sockaddr_in sin; int socket_opt = 0; - int status = 0; /* for error checking */ + int status = 0; /* for error checking */ /* setup port for later use */ ip_data->port = htons(port->params.bip_params.port); /* get local address */ status = - get_local_address_ioctl(port->iface, &ip_data->local_addr, - SIOCGIFADDR); + get_local_address_ioctl(port->iface, &ip_data->local_addr, SIOCGIFADDR); if (status < 0) { return false; } /* get broadcast address */ - status = - get_local_address_ioctl(port->iface, &ip_data->broadcast_addr, - SIOCGIFBRDADDR); + status = get_local_address_ioctl(port->iface, &ip_data->broadcast_addr, + SIOCGIFBRDADDR); if (status < 0) { return false; } @@ -173,17 +165,15 @@ bool dl_ip_init( /* setup socket options */ socket_opt = 1; - status = - setsockopt(ip_data->socket, SOL_SOCKET, SO_REUSEADDR, &socket_opt, - sizeof(socket_opt)); + status = setsockopt(ip_data->socket, SOL_SOCKET, SO_REUSEADDR, &socket_opt, + sizeof(socket_opt)); if (status < 0) { close(ip_data->socket); return false; } - status = - setsockopt(ip_data->socket, SOL_SOCKET, SO_BROADCAST, &socket_opt, - sizeof(socket_opt)); + status = setsockopt(ip_data->socket, SOL_SOCKET, SO_BROADCAST, &socket_opt, + sizeof(socket_opt)); if (status < 0) { close(ip_data->socket); return false; @@ -196,9 +186,8 @@ bool dl_ip_init( memset(&sin.sin_zero, '\0', sizeof(sin.sin_zero)); - status = - bind(ip_data->socket, (const struct sockaddr *) &sin, - sizeof(struct sockaddr)); + status = bind(ip_data->socket, (const struct sockaddr *)&sin, + sizeof(struct sockaddr)); if (status < 0) { close(ip_data->socket); return false; @@ -212,20 +201,17 @@ bool dl_ip_init( PRINT(INFO, "Interface: %s\n", port->iface); PRINT(INFO, "IP Address: %s\n", inet_ntoa(ip_data->local_addr)); PRINT(INFO, "IP Broadcast Address: %s\n", - inet_ntoa(ip_data->broadcast_addr)); + inet_ntoa(ip_data->broadcast_addr)); PRINT(INFO, "UDP Port: 0x%04X [%hu]\n", (port->params.bip_params.port), - (port->params.bip_params.port)); + (port->params.bip_params.port)); return true; } -int dl_ip_send( - IP_DATA * data, - BACNET_ADDRESS * dest, - uint8_t * pdu, - unsigned pdu_len) +int dl_ip_send(IP_DATA *data, BACNET_ADDRESS *dest, uint8_t *pdu, + unsigned pdu_len) { - struct sockaddr_in bip_dest = { 0 }; + struct sockaddr_in bip_dest = {0}; int buff_len = 0; int bytes_sent = 0; @@ -249,33 +235,28 @@ int dl_ip_send( } buff_len = 2; - buff_len += - encode_unsigned16(&data->buff[buff_len], - (uint16_t) (pdu_len + 4 /*inclusive */ )); + buff_len += encode_unsigned16(&data->buff[buff_len], + (uint16_t)(pdu_len + 4 /*inclusive */)); memcpy(&data->buff[buff_len], pdu, pdu_len); buff_len += pdu_len; /* send the packet */ - bytes_sent = - sendto(data->socket, (char *) data->buff, buff_len, 0, - (struct sockaddr *) &bip_dest, sizeof(struct sockaddr)); + bytes_sent = sendto(data->socket, (char *)data->buff, buff_len, 0, + (struct sockaddr *)&bip_dest, sizeof(struct sockaddr)); PRINT(DEBUG, "send to %s\n", inet_ntoa(bip_dest.sin_addr)); return bytes_sent; } -int dl_ip_recv( - IP_DATA * data, - MSG_DATA ** msg_data, - BACNET_ADDRESS * src, - unsigned timeout) +int dl_ip_recv(IP_DATA *data, MSG_DATA **msg_data, BACNET_ADDRESS *src, + unsigned timeout) { int received_bytes = 0; - uint16_t buff_len = 0; /* return value */ + uint16_t buff_len = 0; /* return value */ fd_set read_fds; struct timeval select_timeout; - struct sockaddr_in sin = { 0 }; + struct sockaddr_in sin = {0}; socklen_t sin_len = sizeof(sin); /* make sure the socket is open */ @@ -304,8 +285,8 @@ int dl_ip_recv( /* see if there is a packet for us */ if (ret > 0) received_bytes = - recvfrom(data->socket, (char *) &data->buff[0], data->max_buff, 0, - (struct sockaddr *) &sin, &sin_len); + recvfrom(data->socket, (char *)&data->buff[0], data->max_buff, 0, + (struct sockaddr *)&sin, &sin_len); else return 0; #endif @@ -322,76 +303,69 @@ int dl_ip_recv( switch (data->buff[1]) { case BVLC_ORIGINAL_UNICAST_NPDU: - case BVLC_ORIGINAL_BROADCAST_NPDU:{ - if ((sin.sin_addr.s_addr == data->local_addr.s_addr) && - (sin.sin_port == data->port)) { + case BVLC_ORIGINAL_BROADCAST_NPDU: { + if ((sin.sin_addr.s_addr == data->local_addr.s_addr) && + (sin.sin_port == data->port)) { + buff_len = 0; + + PRINT(DEBUG, "BIP: src is me. Discarded!\n"); + + } else { + src->mac_len = 6; + memcpy(&src->mac[0], &sin.sin_addr.s_addr, 4); + memcpy(&src->mac[4], &sin.sin_port, 2); + + (void)decode_unsigned16(&data->buff[2], &buff_len); + /* subtract off the BVLC header */ + buff_len -= 4; + if (buff_len < data->max_buff) { + /* allocate data message stucture */ + (*msg_data) = (MSG_DATA *)malloc(sizeof(MSG_DATA)); + (*msg_data)->pdu_len = buff_len; + (*msg_data)->pdu = (uint8_t *)malloc((*msg_data)->pdu_len); + /* fill up data message structure */ + memmove(&(*msg_data)->pdu[0], &data->buff[4], + (*msg_data)->pdu_len); + memmove(&(*msg_data)->src, src, sizeof(BACNET_ADDRESS)); + } + /* ignore packets that are too large */ + else { buff_len = 0; - PRINT(DEBUG, "BIP: src is me. Discarded!\n"); + PRINT(ERROR, "BIP: PDU too large. Discarded!.\n"); + } + } + } break; - } else { - src->mac_len = 6; - memcpy(&src->mac[0], &sin.sin_addr.s_addr, 4); - memcpy(&src->mac[4], &sin.sin_port, 2); + case BVLC_FORWARDED_NPDU: { + memcpy(&sin.sin_addr.s_addr, &data->buff[4], 4); + memcpy(&sin.sin_port, &data->buff[8], 2); + if ((sin.sin_addr.s_addr == data->local_addr.s_addr) && + (sin.sin_port == data->port)) { + buff_len = 0; + } else { + src->mac_len = 6; + memcpy(&src->mac[0], &sin.sin_addr.s_addr, 4); + memcpy(&src->mac[4], &sin.sin_port, 2); - (void) decode_unsigned16(&data->buff[2], &buff_len); - /* subtract off the BVLC header */ - buff_len -= 4; - if (buff_len < data->max_buff) { - /* allocate data message stucture */ - (*msg_data) = (MSG_DATA *) malloc(sizeof(MSG_DATA)); - (*msg_data)->pdu_len = buff_len; - (*msg_data)->pdu = - (uint8_t *) malloc((*msg_data)->pdu_len); - /* fill up data message structure */ - memmove(&(*msg_data)->pdu[0], &data->buff[4], + (void)decode_unsigned16(&data->buff[2], &buff_len); + /* subtract off the BVLC header */ + buff_len -= 10; + if (buff_len < data->max_buff) { + /* allocate data message stucture */ + (*msg_data) = (MSG_DATA *)malloc(sizeof(MSG_DATA)); + (*msg_data)->pdu_len = buff_len; + (*msg_data)->pdu = (uint8_t *)malloc((*msg_data)->pdu_len); + /* fill up data message structure */ + memmove(&(*msg_data)->pdu[0], &data->buff[4 + 6], (*msg_data)->pdu_len); - memmove(&(*msg_data)->src, src, - sizeof(BACNET_ADDRESS)); - } + memmove(&(*msg_data)->src, src, sizeof(BACNET_ADDRESS)); + } else { /* ignore packets that are too large */ - else { - buff_len = 0; - - PRINT(ERROR, "BIP: PDU too large. Discarded!.\n"); - - } - } - } - break; - - case BVLC_FORWARDED_NPDU:{ - memcpy(&sin.sin_addr.s_addr, &data->buff[4], 4); - memcpy(&sin.sin_port, &data->buff[8], 2); - if ((sin.sin_addr.s_addr == data->local_addr.s_addr) && - (sin.sin_port == data->port)) { buff_len = 0; - } else { - src->mac_len = 6; - memcpy(&src->mac[0], &sin.sin_addr.s_addr, 4); - memcpy(&src->mac[4], &sin.sin_port, 2); - - (void) decode_unsigned16(&data->buff[2], &buff_len); - /* subtract off the BVLC header */ - buff_len -= 10; - if (buff_len < data->max_buff) { - /* allocate data message stucture */ - (*msg_data) = (MSG_DATA *) malloc(sizeof(MSG_DATA)); - (*msg_data)->pdu_len = buff_len; - (*msg_data)->pdu = - (uint8_t *) malloc((*msg_data)->pdu_len); - /* fill up data message structure */ - memmove(&(*msg_data)->pdu[0], &data->buff[4 + 6], - (*msg_data)->pdu_len); - memmove(&(*msg_data)->src, src, - sizeof(BACNET_ADDRESS)); - } else { - /* ignore packets that are too large */ - buff_len = 0; - } } } - break; + } break; default: PRINT(ERROR, "BIP: BVLC discarded!\n"); @@ -401,8 +375,7 @@ int dl_ip_recv( return buff_len; } -void dl_ip_cleanup( - IP_DATA * ip_data) +void dl_ip_cleanup(IP_DATA *ip_data) { /* free buffer */ if (ip_data->buff) diff --git a/demo/router/main.c b/demo/router/main.c index 89f4e91c..81034a66 100644 --- a/demo/router/main.c +++ b/demo/router/main.c @@ -1,47 +1,47 @@ /** -* @file -* @author Andriy Sukhynyuk, Vasyl Tkhir, Andriy Ivasiv -* @date 2012 -* @brief BACnet/IP to MS/TP Router example application. -* The Router connects two or more BACnet/IP and BACnet MS/TP networks. -* Number of netwoks is limited only by available hardware communication -* devices (or ports for Ethernet). -* -* @section LICENSE -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*/ + * @file + * @author Andriy Sukhynyuk, Vasyl Tkhir, Andriy Ivasiv + * @date 2012 + * @brief BACnet/IP to MS/TP Router example application. + * The Router connects two or more BACnet/IP and BACnet MS/TP networks. + * Number of netwoks is limited only by available hardware communication + * devices (or ports for Ethernet). + * + * @section LICENSE + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ #include #include #include #include #include #include -#include /* for time */ +#include /* for time */ #include #include #include -#include /* read config files */ -#include /* for getopt */ -#include /* used in kbhit() */ +#include /* read config files */ +#include /* for getopt */ +#include /* used in kbhit() */ #include #include #include @@ -55,49 +55,33 @@ #define KEY_ESC 27 -ROUTER_PORT *head = NULL; /* pointer to list of router ports */ +ROUTER_PORT *head = NULL; /* pointer to list of router ports */ int port_count; -void print_help( - ); +void print_help(); -bool read_config( - char *filepath); +bool read_config(char *filepath); -bool parse_cmd( - int argc, - char *argv[]); +bool parse_cmd(int argc, char *argv[]); -void init_port_threads( - ROUTER_PORT * port_list); +void init_port_threads(ROUTER_PORT *port_list); -bool init_router( - ); +bool init_router(); -void cleanup( - ); +void cleanup(); -void print_msg( - BACMSG * msg); +void print_msg(BACMSG *msg); -uint16_t process_msg( - BACMSG * msg, - MSG_DATA * data, - uint8_t ** buff); +uint16_t process_msg(BACMSG *msg, MSG_DATA *data, uint8_t **buff); -uint16_t get_next_free_dnet( - ); +uint16_t get_next_free_dnet(); -int kbhit( - ); +int kbhit(); -inline bool is_network_msg( - BACMSG * msg); +inline bool is_network_msg(BACMSG *msg); -int main( - int argc, - char *argv[]) +int main(int argc, char *argv[]) { printf("I am router\n"); @@ -119,9 +103,8 @@ int main( return -1; } - send_network_message(NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK, msg_data, - &buff, NULL); + &buff, NULL); while (true) { if (kbhit()) { @@ -135,83 +118,78 @@ int main( bacmsg = recv_from_msgbox(head->main_id, &msg_storage); if (bacmsg) { switch (bacmsg->type) { - case DATA: - { - MSGBOX_ID msg_src = bacmsg->origin; + case DATA: { + MSGBOX_ID msg_src = bacmsg->origin; - /* allocate message structure */ - msg_data = malloc(sizeof(MSG_DATA)); - if (!msg_data) { - PRINT(ERROR, "Error: Could not allocate memory\n"); + /* allocate message structure */ + msg_data = malloc(sizeof(MSG_DATA)); + if (!msg_data) { + PRINT(ERROR, "Error: Could not allocate memory\n"); + break; + } + + print_msg(bacmsg); + + if (is_network_msg(bacmsg)) { + buff_len = + process_network_message(bacmsg, msg_data, &buff); + if (buff_len == 0) { + free_data(bacmsg->data); break; } + } else { + buff_len = process_msg(bacmsg, msg_data, &buff); + } + + /* if buff_len */ + /* >0 - form new message and send */ + /* =-1 - try to find next router */ + /* other value - discard message */ + + if (buff_len > 0) { + /* form new message */ + msg_data->pdu = buff; + msg_data->pdu_len = buff_len; + msg_storage.origin = head->main_id; + msg_storage.type = DATA; + msg_storage.data = msg_data; print_msg(bacmsg); if (is_network_msg(bacmsg)) { - buff_len = - process_network_message(bacmsg, msg_data, - &buff); - if (buff_len == 0) { - free_data(bacmsg->data); - break; - } + msg_data->ref_count = 1; + send_to_msgbox(msg_src, &msg_storage); + } else if (msg_data->dest.net != + BACNET_BROADCAST_NETWORK) { + msg_data->ref_count = 1; + port = + find_dnet(msg_data->dest.net, &msg_data->dest); + send_to_msgbox(port->port_id, &msg_storage); } else { - buff_len = process_msg(bacmsg, msg_data, &buff); - } - - /* if buff_len */ - /* >0 - form new message and send */ - /* =-1 - try to find next router */ - /* other value - discard message */ - - if (buff_len > 0) { - /* form new message */ - msg_data->pdu = buff; - msg_data->pdu_len = buff_len; - msg_storage.origin = head->main_id; - msg_storage.type = DATA; - msg_storage.data = msg_data; - - print_msg(bacmsg); - - if (is_network_msg(bacmsg)) { - msg_data->ref_count = 1; - send_to_msgbox(msg_src, &msg_storage); - } else if (msg_data->dest.net != - BACNET_BROADCAST_NETWORK) { - msg_data->ref_count = 1; - port = - find_dnet(msg_data->dest.net, - &msg_data->dest); - send_to_msgbox(port->port_id, &msg_storage); - } else { - port = head; - msg_data->ref_count = port_count - 1; - while (port != NULL) { - if (port->port_id == msg_src || - port->state == FINISHED) { - port = port->next; - continue; - } - send_to_msgbox(port->port_id, - &msg_storage); + port = head; + msg_data->ref_count = port_count - 1; + while (port != NULL) { + if (port->port_id == msg_src || + port->state == FINISHED) { port = port->next; + continue; } + send_to_msgbox(port->port_id, &msg_storage); + port = port->next; } - } else if (buff_len == -1) { - uint16_t net = msg_data->dest.net; /* NET to find */ - PRINT(INFO, "Searching NET...\n"); - send_network_message - (NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK, - msg_data, &buff, &net); - } else { - /* if invalid message send Reject-Message-To-Network */ - PRINT(ERROR, "Error: Invalid message\n"); - free_data(msg_data); } + } else if (buff_len == -1) { + uint16_t net = msg_data->dest.net; /* NET to find */ + PRINT(INFO, "Searching NET...\n"); + send_network_message( + NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK, msg_data, + &buff, &net); + } else { + /* if invalid message send Reject-Message-To-Network */ + PRINT(ERROR, "Error: Invalid message\n"); + free_data(msg_data); } - break; + } break; case SERVICE: default: break; @@ -220,27 +198,29 @@ int main( } return 0; - } -void print_help( - ) +void print_help() { - printf("Usage: router [init_parameters]\n" "\ninit_method:\n" - "-c, --config \n\tinitialize router with a configuration file (.cfg) located at \n" - "-D, --device [params]\n\tinitialize a device using an interface specified with\n\t[params]\n" + printf( + "Usage: router [init_parameters]\n" + "\ninit_method:\n" + "-c, --config \n\tinitialize router with a configuration " + "file (.cfg) located at \n" + "-D, --device [params]\n\tinitialize a " + "device using an interface specified with\n\t[params]\n" "\ninit_parameters:\n" "-n, --network \n\tspecify device network number\n" "-P, --port \n\tspecify udp port for BIP device\n" - "-m, --mac [max_master] [max_frames]\n\tspecify MSTP port parameters\n" + "-m, --mac [max_master] [max_frames]\n\tspecify MSTP " + "port parameters\n" "-b, --baud \n\tspecify MSTP port baud rate\n" "-p, --parity \n\tspecify MSTP port parity\n" "-d, --databits <5|6|7|8>\n\tspecify MSTP port databits\n" "-s, --stopbits <1|2>\n\tspecify MSTP port stopbits\n"); } -bool read_config( - char *filepath) +bool read_config(char *filepath) { config_t cfg; config_setting_t *setting; @@ -252,7 +232,7 @@ bool read_config( /* open configuration file */ if (!config_read_file(&cfg, filepath)) { PRINT(ERROR, "Config file error: %d - %s\n", config_error_line(&cfg), - config_error_text(&cfg)); + config_error_text(&cfg)); config_destroy(&cfg); return false; } @@ -273,13 +253,13 @@ bool read_config( /* create new list node to store port information */ if (head == NULL) { - head = (ROUTER_PORT *) malloc(sizeof(ROUTER_PORT)); + head = (ROUTER_PORT *)malloc(sizeof(ROUTER_PORT)); head->next = NULL; current = head; } else { ROUTER_PORT *tmp = current; current = current->next; - current = (ROUTER_PORT *) malloc(sizeof(ROUTER_PORT)); + current = (ROUTER_PORT *)malloc(sizeof(ROUTER_PORT)); current->next = NULL; tmp->next = current; } @@ -293,7 +273,7 @@ bool read_config( result = config_setting_lookup_string(port, "device", &iface); if (result) { current->iface = - (char *) malloc((strlen(iface) + 1) * sizeof(char)); + (char *)malloc((strlen(iface) + 1) * sizeof(char)); strcpy(current->iface, iface); /* check if interface is valid */ @@ -301,13 +281,13 @@ bool read_config( if (fd) { struct ifreq ifr; strncpy(ifr.ifr_name, current->iface, - sizeof(ifr.ifr_name) - 1); + sizeof(ifr.ifr_name) - 1); result = ioctl(fd, SIOCGIFADDR, &ifr); if (result != -1) { close(fd); } else { PRINT(ERROR, - "Error: Invalid interface for BIP device\n"); + "Error: Invalid interface for BIP device\n"); return false; } } @@ -315,15 +295,14 @@ bool read_config( current->iface = "eth0"; } - result = - config_setting_lookup_int(port, "port", (int *) ¶m); + result = config_setting_lookup_int(port, "port", (int *)¶m); if (result) { current->params.bip_params.port = param; } else { current->params.bip_params.port = 0xBAC0; } result = - config_setting_lookup_int(port, "network", (int *) ¶m); + config_setting_lookup_int(port, "network", (int *)¶m); if (result) { current->route_info.net = param; } else { @@ -336,7 +315,7 @@ bool read_config( result = config_setting_lookup_string(port, "device", &iface); if (result) { current->iface = - (char *) malloc((strlen(iface) + 1) * sizeof(char)); + (char *)malloc((strlen(iface) + 1) * sizeof(char)); strcpy(current->iface, iface); /* check if interface is valid */ @@ -345,14 +324,13 @@ bool read_config( close(fd); } else { PRINT(ERROR, - "Error: Invalid interface for MSTP device\n"); + "Error: Invalid interface for MSTP device\n"); return false; } } else { current->iface = "/dev/ttyS0"; } - result = - config_setting_lookup_int(port, "mac", (int *) ¶m); + result = config_setting_lookup_int(port, "mac", (int *)¶m); if (result) { current->route_info.mac[0] = param; current->route_info.mac_len = 1; @@ -360,24 +338,21 @@ bool read_config( current->route_info.mac[0] = 127; current->route_info.mac_len = 1; } - result = - config_setting_lookup_int(port, "max_master", - (int *) ¶m); + result = config_setting_lookup_int(port, "max_master", + (int *)¶m); if (result) { current->params.mstp_params.max_master = param; } else { current->params.mstp_params.max_master = 127; } - result = - config_setting_lookup_int(port, "max_frames", - (int *) ¶m); + result = config_setting_lookup_int(port, "max_frames", + (int *)¶m); if (result) { current->params.mstp_params.max_frames = param; } else { current->params.mstp_params.max_frames = 1; } - result = - config_setting_lookup_int(port, "baud", (int *) ¶m); + result = config_setting_lookup_int(port, "baud", (int *)¶m); if (result) { current->params.mstp_params.baudrate = param; } else { @@ -401,23 +376,21 @@ bool read_config( current->params.mstp_params.parity = PARITY_NONE; } result = - config_setting_lookup_int(port, "databits", - (int *) ¶m); + config_setting_lookup_int(port, "databits", (int *)¶m); if (result && param >= 5 && param <= 8) { current->params.mstp_params.databits = param; } else { current->params.mstp_params.databits = 8; } result = - config_setting_lookup_int(port, "stopbits", - (int *) ¶m); + config_setting_lookup_int(port, "stopbits", (int *)¶m); if (result && param >= 1 && param <= 2) { current->params.mstp_params.stopbits = param; } else { current->params.mstp_params.stopbits = 1; } result = - config_setting_lookup_int(port, "network", (int *) ¶m); + config_setting_lookup_int(port, "network", (int *)¶m); if (result) { current->route_info.net = param; } else { @@ -439,9 +412,7 @@ bool read_config( return true; } -bool parse_cmd( - int argc, - char *argv[]) +bool parse_cmd(int argc, char *argv[]) { const char *optString = "hc:D:"; const char *bipString = "p:n:D:"; @@ -463,11 +434,10 @@ bool parse_cmd( int opt, dev_opt, index, result, fd; ROUTER_PORT *current = head; - if (argc < 2) - { + if (argc < 2) { print_help(); - return false; - } + return false; + } /* begin checking cmd parameters */ opt = getopt_long(argc, argv, optString, Options, &index); @@ -485,13 +455,13 @@ bool parse_cmd( /* create new list node to store port information */ if (head == NULL) { - head = (ROUTER_PORT *) malloc(sizeof(ROUTER_PORT)); + head = (ROUTER_PORT *)malloc(sizeof(ROUTER_PORT)); head->next = NULL; current = head; } else { ROUTER_PORT *tmp = current; current = current->next; - current = (ROUTER_PORT *) malloc(sizeof(ROUTER_PORT)); + current = (ROUTER_PORT *)malloc(sizeof(ROUTER_PORT)); current->next = NULL; tmp->next = current; } @@ -507,7 +477,7 @@ bool parse_cmd( } /* setup default parameters */ - current->params.bip_params.port = 0xBAC0; /* 47808 */ + current->params.bip_params.port = 0xBAC0; /* 47808 */ current->route_info.net = get_next_free_dnet(); /* check if interface is valid */ @@ -515,13 +485,13 @@ bool parse_cmd( if (fd) { struct ifreq ifr; strncpy(ifr.ifr_name, current->iface, - sizeof(ifr.ifr_name) - 1); + sizeof(ifr.ifr_name) - 1); result = ioctl(fd, SIOCGIFADDR, &ifr); if (result != -1) { close(fd); } else { PRINT(ERROR, - "Error: Invalid interface for BIP device \n"); + "Error: Invalid interface for BIP device \n"); return false; } } @@ -534,24 +504,23 @@ bool parse_cmd( result = atoi(optarg); if (result) { current->params.bip_params.port = - (uint16_t) result; + (uint16_t)result; } else { - current->params.bip_params.port = 0xBAC0; /* 47808 */ + current->params.bip_params.port = + 0xBAC0; /* 47808 */ } break; case 'n': result = atoi(optarg); if (result) { - current->route_info.net = - (uint16_t) result; + current->route_info.net = (uint16_t)result; } else { current->route_info.net = port_count; } break; } dev_opt = - getopt_long(argc, argv, bipString, Options, - &index); + getopt_long(argc, argv, bipString, Options, &index); } opt = dev_opt; } else if (strcmp(optarg, "mstp") == 0) { @@ -569,7 +538,7 @@ bool parse_cmd( close(fd); } else { PRINT(ERROR, - "Error: Invalid interface for MSTP device\n"); + "Error: Invalid interface for MSTP device\n"); return false; } @@ -592,22 +561,19 @@ bool parse_cmd( result = atoi(optarg); if (result) { current->route_info.mac[0] = - (uint8_t) result; + (uint8_t)result; } if (argv[optind][0] != '-') { current->params.mstp_params.max_master = - (uint8_t) atoi(argv[optind]); - if (current->params.mstp_params. - max_master < + (uint8_t)atoi(argv[optind]); + if (current->params.mstp_params.max_master < current->route_info.mac[0]) - current->params.mstp_params. - max_master = + current->params.mstp_params.max_master = current->route_info.mac[0]; if (argv[optind + 1][0] != '-') { - current->params.mstp_params. - max_frames = - (uint8_t) atoi(argv[optind + 1]); + current->params.mstp_params.max_frames = + (uint8_t)atoi(argv[optind + 1]); } } break; @@ -615,7 +581,7 @@ bool parse_cmd( result = atoi(optarg); if (result) { current->params.mstp_params.baudrate = - (uint32_t) result; + (uint32_t)result; } break; case 'p': @@ -638,27 +604,25 @@ bool parse_cmd( result = atoi(optarg); if (result >= 5 && result <= 8) { current->params.mstp_params.databits = - (uint8_t) result; + (uint8_t)result; } break; case 's': result = atoi(optarg); if (result >= 1 && result <= 2) { current->params.mstp_params.stopbits = - (uint8_t) result; + (uint8_t)result; } break; case 'n': result = atoi(optarg); if (result) { - current->route_info.net = - (uint16_t) result; + current->route_info.net = (uint16_t)result; } break; } - dev_opt = - getopt_long(argc, argv, mstpString, Options, - &index); + dev_opt = getopt_long(argc, argv, mstpString, Options, + &index); } opt = dev_opt; } else { @@ -671,8 +635,7 @@ bool parse_cmd( return true; } -void init_port_threads( - ROUTER_PORT * port_list) +void init_port_threads(ROUTER_PORT *port_list) { ROUTER_PORT *port = port_list; pthread_t *thread; @@ -688,17 +651,16 @@ void init_port_threads( } port->state = INIT; - thread = (pthread_t *) malloc(sizeof(pthread_t)); + thread = (pthread_t *)malloc(sizeof(pthread_t)); pthread_create(thread, NULL, port->func, port); - pthread_detach(*thread); /* for proper thread termination */ + pthread_detach(*thread); /* for proper thread termination */ port = port->next; } } -bool init_router( - ) +bool init_router() { MSGBOX_ID msgboxid; ROUTER_PORT *port; @@ -735,8 +697,7 @@ bool init_router( return true; } -void cleanup( - ) +void cleanup() { ROUTER_PORT *port; BACMSG msg; @@ -748,7 +709,7 @@ void cleanup( msg.type = SERVICE; msg.subtype = SHUTDOWN; - del_msgbox(head->main_id); /* close routers message box */ + del_msgbox(head->main_id); /* close routers message box */ /* send shutdown message to all router ports */ port = head; @@ -772,12 +733,11 @@ void cleanup( pthread_mutex_destroy(&msg_lock); } -void print_msg( - BACMSG * msg) +void print_msg(BACMSG *msg) { if (msg->type == DATA) { int i; - MSG_DATA *data = (MSG_DATA *) msg->data; + MSG_DATA *data = (MSG_DATA *)msg->data; if (data->pdu_len) { PRINT(DEBUG, "Message PDU: "); @@ -788,12 +748,8 @@ void print_msg( } } -uint16_t process_msg( - BACMSG * msg, - MSG_DATA * data, - uint8_t ** buff) +uint16_t process_msg(BACMSG *msg, MSG_DATA *data, uint8_t **buff) { - BACNET_ADDRESS addr; BACNET_NPDU_DATA npdu_data; ROUTER_PORT *srcport; @@ -816,12 +772,14 @@ uint16_t process_msg( if (srcport && destport) { data->src.net = srcport->route_info.net; - /* if received from another router save real source address (not other router source address) */ + /* if received from another router save real source address (not other + * router source address) */ if (addr.net > 0 && addr.net < BACNET_BROADCAST_NETWORK && data->src.net != addr.net) memmove(&data->src, &addr, sizeof(BACNET_ADDRESS)); - /* encode both source and destination for broadcast and router-to-router communication */ + /* encode both source and destination for broadcast and router-to-router + * communication */ if (data->dest.net == BACNET_BROADCAST_NETWORK || destport->route_info.net != data->dest.net) { npdu_len = @@ -832,9 +790,10 @@ uint16_t process_msg( buff_len = npdu_len + data->pdu_len - apdu_offset; - *buff = (uint8_t *) malloc(buff_len); + *buff = (uint8_t *)malloc(buff_len); memmove(*buff, npdu, npdu_len); /* copy newly formed NPDU */ - memmove(*buff + npdu_len, &data->pdu[apdu_offset], apdu_len); /* copy APDU */ + memmove(*buff + npdu_len, &data->pdu[apdu_offset], + apdu_len); /* copy APDU */ } else { /* request net search */ @@ -842,13 +801,12 @@ uint16_t process_msg( } /* delete received message */ - free_data((MSG_DATA *) msg->data); + free_data((MSG_DATA *)msg->data); return buff_len; } -int kbhit( - ) +int kbhit() { static const int STDIN = 0; static bool initialized = false; @@ -868,22 +826,18 @@ int kbhit( return bytesWaiting; } -bool is_network_msg( - BACMSG * msg) +bool is_network_msg(BACMSG *msg) { - - uint8_t control_byte; /* NPDU control byte */ - MSG_DATA *data = (MSG_DATA *) msg->data; + uint8_t control_byte; /* NPDU control byte */ + MSG_DATA *data = (MSG_DATA *)msg->data; control_byte = data->pdu[1]; return control_byte & 0x80; /* check 7th bit */ } -uint16_t get_next_free_dnet( - ) +uint16_t get_next_free_dnet() { - ROUTER_PORT *port = head; uint16_t i = 1; while (port) { diff --git a/demo/router/msgqueue.c b/demo/router/msgqueue.c index cb9ed1de..ed460176 100644 --- a/demo/router/msgqueue.c +++ b/demo/router/msgqueue.c @@ -1,31 +1,31 @@ /** -* @file -* @author Andriy Sukhynyuk, Vasyl Tkhir, Andriy Ivasiv -* @date 2012 -* @brief Message queue module -* -* @section LICENSE -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*/ + * @file + * @author Andriy Sukhynyuk, Vasyl Tkhir, Andriy Ivasiv + * @date 2012 + * @brief Message queue module + * + * @section LICENSE + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ #include #include #include @@ -35,8 +35,7 @@ pthread_mutex_t msg_lock = PTHREAD_MUTEX_INITIALIZER; -MSGBOX_ID create_msgbox( - ) +MSGBOX_ID create_msgbox() { MSGBOX_ID msgboxid; @@ -48,28 +47,23 @@ MSGBOX_ID create_msgbox( return msgboxid; } -bool send_to_msgbox( - MSGBOX_ID dest, - BACMSG * msg) +bool send_to_msgbox(MSGBOX_ID dest, BACMSG *msg) { - int err; - err = msgsnd(dest, msg, sizeof(BACMSG)-sizeof(MSGTYPE), 0); + err = msgsnd(dest, msg, sizeof(BACMSG) - sizeof(MSGTYPE), 0); if (err) { return false; } return true; } -BACMSG *recv_from_msgbox( - MSGBOX_ID src, - BACMSG * msg) +BACMSG *recv_from_msgbox(MSGBOX_ID src, BACMSG *msg) { - int recv_bytes; - recv_bytes = msgrcv(src, msg, sizeof(BACMSG)-sizeof(MSGTYPE), 0, IPC_NOWAIT); + recv_bytes = + msgrcv(src, msg, sizeof(BACMSG) - sizeof(MSGTYPE), 0, IPC_NOWAIT); if (recv_bytes > 0) { return msg; } else { @@ -77,20 +71,16 @@ BACMSG *recv_from_msgbox( } } -void del_msgbox( - MSGBOX_ID msgboxid) +void del_msgbox(MSGBOX_ID msgboxid) { - if (msgboxid == INVALID_MSGBOX_ID) return; else msgctl(msgboxid, IPC_RMID, NULL); } -void free_data( - MSG_DATA * data) +void free_data(MSG_DATA *data) { - if (data->pdu) { free(data->pdu); data->pdu = NULL; @@ -101,10 +91,8 @@ void free_data( } } -void check_data( - MSG_DATA * data) +void check_data(MSG_DATA *data) { - /* lock and decrement messages reference count */ pthread_mutex_lock(&msg_lock); if (--data->ref_count == 0) { diff --git a/demo/router/mstpmodule.c b/demo/router/mstpmodule.c index 7e7fa02f..9c36e5e7 100644 --- a/demo/router/mstpmodule.c +++ b/demo/router/mstpmodule.c @@ -1,31 +1,31 @@ /** -* @file -* @author Andriy Sukhynyuk, Vasyl Tkhir, Andriy Ivasiv -* @date 2012 -* @brief Datalink for MS/TP module -* -* @section LICENSE -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*/ + * @file + * @author Andriy Sukhynyuk, Vasyl Tkhir, Andriy Ivasiv + * @date 2012 + * @brief Datalink for MS/TP module + * + * @section LICENSE + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ #include #include #include @@ -36,18 +36,16 @@ #define MSTP_THREAD_PRINT_ENABLED #ifdef MSTP_THREAD_PRINT_ENABLED -#define mstp_thread_debug(...) fprintf(stderr, __VA_ARGS__) +#define mstp_thread_debug(...) fprintf(stderr, __VA_ARGS__) #else -#define mstp_thread_debug(...) +#define mstp_thread_debug(...) #endif -void *dl_mstp_thread( - void *pArgs) +void *dl_mstp_thread(void *pArgs) { - - ROUTER_PORT *port = (ROUTER_PORT *) pArgs; - struct mstp_port_struct_t mstp_port = { (MSTP_RECEIVE_STATE) 0 }; - volatile SHARED_MSTP_DATA shared_port_data = { 0 }; + ROUTER_PORT *port = (ROUTER_PORT *)pArgs; + struct mstp_port_struct_t mstp_port = {(MSTP_RECEIVE_STATE)0}; + volatile SHARED_MSTP_DATA shared_port_data = {0}; uint16_t pdu_len; uint8_t shutdown = 0; @@ -87,11 +85,10 @@ void *dl_mstp_thread( if (port->params.mstp_params.stopbits == 2) shared_port_data.RS485MOD |= CSTOPB; - mstp_port.UserData = (void *) &shared_port_data; + mstp_port.UserData = (void *)&shared_port_data; dlmstp_set_baud_rate(&mstp_port, port->params.mstp_params.baudrate); dlmstp_set_mac_address(&mstp_port, port->route_info.mac[0]); - dlmstp_set_max_info_frames(&mstp_port, - port->params.mstp_params.max_frames); + dlmstp_set_max_info_frames(&mstp_port, port->params.mstp_params.max_frames); dlmstp_set_max_master(&mstp_port, port->params.mstp_params.max_master); if (!dlmstp_init(&mstp_port, port->iface)) printf("MSTP %s init failed. Stop.\n", port->iface); @@ -114,7 +111,7 @@ void *dl_mstp_thread( if (bacmsg) { switch (bacmsg->type) { case DATA: - msg_data = (MSG_DATA *) bacmsg->data; + msg_data = (MSG_DATA *)bacmsg->data; if (msg_data->dest.net == BACNET_BROADCAST_NETWORK) { dlmstp_get_broadcast_address(&(msg_data->dest)); @@ -124,11 +121,10 @@ void *dl_mstp_thread( } dlmstp_send_pdu(&mstp_port, &(msg_data->dest), - msg_data->pdu, msg_data->pdu_len); + msg_data->pdu, msg_data->pdu_len); check_data(msg_data); - break; case SERVICE: switch (bacmsg->subtype) { @@ -147,20 +143,21 @@ void *dl_mstp_thread( pdu_len = dlmstp_receive(&mstp_port, NULL, NULL, 0, 5); if (pdu_len > 0) { - msg_data = (MSG_DATA *) malloc(sizeof(MSG_DATA)); - memmove(&(msg_data->src), - (const void *) &(shared_port_data.Receive_Packet.address), + msg_data = (MSG_DATA *)malloc(sizeof(MSG_DATA)); + memmove( + &(msg_data->src), + (const void *)&(shared_port_data.Receive_Packet.address), sizeof(shared_port_data.Receive_Packet.address)); msg_data->src.adr[0] = msg_data->src.mac[0]; msg_data->src.len = 1; - msg_data->pdu = (uint8_t *) malloc(pdu_len); + msg_data->pdu = (uint8_t *)malloc(pdu_len); memmove(msg_data->pdu, - (const void *) &(shared_port_data.Receive_Packet.pdu), - pdu_len); + (const void *)&(shared_port_data.Receive_Packet.pdu), + pdu_len); msg_data->pdu_len = pdu_len; msg_storage.type = DATA; - msg_storage.subtype = (MSGSUBTYPE) 0; + msg_storage.subtype = (MSGSUBTYPE)0; msg_storage.origin = port->port_id; msg_storage.data = msg_data; @@ -175,5 +172,4 @@ void *dl_mstp_thread( port->state = FINISHED; return NULL; - } diff --git a/demo/router/network_layer.c b/demo/router/network_layer.c index 0f1c3b70..57f1ccc5 100644 --- a/demo/router/network_layer.c +++ b/demo/router/network_layer.c @@ -1,43 +1,39 @@ /** -* @file -* @author Andriy Sukhynyuk, Vasyl Tkhir, Andriy Ivasiv -* @date 2012 -* @brief Network layer for BACnet routing -* -* @section LICENSE -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*/ + * @file + * @author Andriy Sukhynyuk, Vasyl Tkhir, Andriy Ivasiv + * @date 2012 + * @brief Network layer for BACnet routing + * + * @section LICENSE + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ #include #include #include #include "network_layer.h" #include "bacint.h" -uint16_t process_network_message( - BACMSG * msg, - MSG_DATA * data, - uint8_t ** buff) +uint16_t process_network_message(BACMSG *msg, MSG_DATA *data, uint8_t **buff) { - BACNET_NPDU_DATA npdu_data; ROUTER_PORT *srcport; ROUTER_PORT *destport; @@ -56,7 +52,6 @@ uint16_t process_network_message( data->src.net = srcport->route_info.net; switch (npdu_data.network_message_type) { - case NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK: PRINT(INFO, "Recieved Who-Is-Router-To-Network message\n"); if (apdu_len) { @@ -67,83 +62,83 @@ uint16_t process_network_message( return -2; } - destport = find_dnet(net, NULL); /* see if NET can be reached */ + destport = find_dnet(net, NULL); /* see if NET can be reached */ if (destport) { /* if TRUE send reply */ PRINT(INFO, "Sending I-Am-Router-To-Network message\n"); - buff_len = - create_network_message - (NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK, data, buff, + buff_len = create_network_message( + NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK, data, buff, &net); } else { - data->dest.net = net; /* NET to look for */ - return -1; /* else initiate NET search procedure */ + data->dest.net = net; /* NET to look for */ + return -1; /* else initiate NET search procedure */ } } else { /* if NET is omitted (message sent with -1) */ PRINT(INFO, "Sending I-Am-Router-To-Network message\n"); - buff_len = - create_network_message - (NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK, data, buff, NULL); + buff_len = create_network_message( + NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK, data, buff, NULL); } break; - case NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK: - { - PRINT(INFO, "Recieved I-Am-Router-To-Network message\n"); - int net_count = apdu_len / 2; - int i; - for (i = 0; i < net_count; i++) { - decode_unsigned16(&data->pdu[apdu_offset + 2 * i], &net); /* decode received NET values */ - add_dnet(&srcport->route_info, net, data->src); /* and update routing table */ - } - break; + case NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK: { + PRINT(INFO, "Recieved I-Am-Router-To-Network message\n"); + int net_count = apdu_len / 2; + int i; + for (i = 0; i < net_count; i++) { + decode_unsigned16(&data->pdu[apdu_offset + 2 * i], + &net); /* decode received NET values */ + add_dnet(&srcport->route_info, net, + data->src); /* and update routing table */ } - case NETWORK_MESSAGE_REJECT_MESSAGE_TO_NETWORK: - { - /* first octet of the message contains rejection reason */ - /* next two octets contain NET (can be decoded for additional info on error) */ - error_code = data->pdu[apdu_offset]; - switch (error_code) { - case 0: - PRINT(ERROR, "Error!\n"); - break; - case 1: - PRINT(ERROR, "Error: Network unreachable\n"); - break; - case 2: - PRINT(ERROR, "Error: Network is busy\n"); - break; - case 3: - PRINT(ERROR, "Error: Unknown network message type\n"); - break; - case 4: - PRINT(ERROR, "Error: Message too long\n"); - break; - } - break; + break; + } + case NETWORK_MESSAGE_REJECT_MESSAGE_TO_NETWORK: { + /* first octet of the message contains rejection reason */ + /* next two octets contain NET (can be decoded for additional info + * on error) */ + error_code = data->pdu[apdu_offset]; + switch (error_code) { + case 0: + PRINT(ERROR, "Error!\n"); + break; + case 1: + PRINT(ERROR, "Error: Network unreachable\n"); + break; + case 2: + PRINT(ERROR, "Error: Network is busy\n"); + break; + case 3: + PRINT(ERROR, "Error: Unknown network message type\n"); + break; + case 4: + PRINT(ERROR, "Error: Message too long\n"); + break; } + break; + } case NETWORK_MESSAGE_INIT_RT_TABLE: PRINT(INFO, "Recieved Initialize-Routing-Table message\n"); if (data->pdu[apdu_offset] > 0) { int net_count = data->pdu[apdu_offset]; while (net_count--) { int i = 1; - decode_unsigned16(&data->pdu[apdu_offset + i], &net); /* decode received NET values */ - add_dnet(&srcport->route_info, net, data->src); /* and update routing table */ - if (data->pdu[apdu_offset + i + 3] > 0) /* find next NET value */ + decode_unsigned16(&data->pdu[apdu_offset + i], + &net); /* decode received NET values */ + add_dnet(&srcport->route_info, net, + data->src); /* and update routing table */ + if (data->pdu[apdu_offset + i + 3] > + 0) /* find next NET value */ i = data->pdu[apdu_offset + i + 3] + 4; else i = i + 4; } - buff_len = - create_network_message(NETWORK_MESSAGE_INIT_RT_TABLE_ACK, - data, buff, NULL); + buff_len = create_network_message( + NETWORK_MESSAGE_INIT_RT_TABLE_ACK, data, buff, NULL); } else - buff_len = - create_network_message(NETWORK_MESSAGE_INIT_RT_TABLE_ACK, - data, buff, &buff); + buff_len = create_network_message( + NETWORK_MESSAGE_INIT_RT_TABLE_ACK, data, buff, &buff); break; case NETWORK_MESSAGE_INIT_RT_TABLE_ACK: @@ -152,9 +147,12 @@ uint16_t process_network_message( int net_count = data->pdu[apdu_offset]; while (net_count--) { int i = 1; - decode_unsigned16(&data->pdu[apdu_offset + i], &net); /* decode received NET values */ - add_dnet(&srcport->route_info, net, data->src); /* and update routing table */ - if (data->pdu[apdu_offset + i + 3] > 0) /* find next NET value */ + decode_unsigned16(&data->pdu[apdu_offset + i], + &net); /* decode received NET values */ + add_dnet(&srcport->route_info, net, + data->src); /* and update routing table */ + if (data->pdu[apdu_offset + i + 3] > + 0) /* find next NET value */ i = data->pdu[apdu_offset + i + 3] + 4; else i = i + 4; @@ -182,12 +180,10 @@ uint16_t process_network_message( /* security messages */ break; case NETWORK_MESSAGE_WHAT_IS_NETWORK_NUMBER: - buff_len = - create_network_message(NETWORK_MESSAGE_NETWORK_NUMBER_IS, - data, buff, &buff); + buff_len = create_network_message(NETWORK_MESSAGE_NETWORK_NUMBER_IS, + data, buff, &buff); break; - default: PRINT(ERROR, "Error: Message unsupported\n"); break; @@ -197,12 +193,9 @@ uint16_t process_network_message( } uint16_t create_network_message( - BACNET_NETWORK_MESSAGE_TYPE network_message_type, - MSG_DATA * data, - uint8_t ** buff, - void *val) + BACNET_NETWORK_MESSAGE_TYPE network_message_type, MSG_DATA *data, + uint8_t **buff, void *val) { - int16_t buff_len; bool data_expecting_reply = false; BACNET_NPDU_DATA npdu_data; @@ -211,17 +204,16 @@ uint16_t create_network_message( data_expecting_reply = true; init_npdu(&npdu_data, network_message_type, data_expecting_reply); - *buff = (uint8_t *) malloc(128); /* resolve different length */ + *buff = (uint8_t *)malloc(128); /* resolve different length */ /* manual destination setup for Init-RT-Table-Ack message */ data->dest.net = BACNET_BROADCAST_NETWORK; buff_len = npdu_encode_pdu(*buff, &data->dest, NULL, &npdu_data); switch (network_message_type) { - case NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK: if (val != NULL) { - uint8_t *valptr = (uint8_t *) val; + uint8_t *valptr = (uint8_t *)val; uint16_t val16 = (valptr[0]) + (valptr[1] << 8); buff_len += encode_unsigned16(*buff + buff_len, val16); } @@ -229,7 +221,7 @@ uint16_t create_network_message( case NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK: if (val != NULL) { - uint8_t *valptr = (uint8_t *) val; + uint8_t *valptr = (uint8_t *)val; uint16_t val16 = (valptr[0]) + (valptr[1] << 8); buff_len += encode_unsigned16(*buff + buff_len, val16); } else { @@ -237,9 +229,8 @@ uint16_t create_network_message( DNET *dnet; while (port != NULL) { if (port->route_info.net != data->src.net) { - buff_len += - encode_unsigned16(*buff + buff_len, - port->route_info.net); + buff_len += encode_unsigned16(*buff + buff_len, + port->route_info.net); dnet = port->route_info.dnets; while (dnet != NULL) { buff_len += @@ -260,33 +251,31 @@ uint16_t create_network_message( } break; - case NETWORK_MESSAGE_REJECT_MESSAGE_TO_NETWORK: - { - uint8_t *valptr = (uint8_t *) val; - uint16_t val16 = (valptr[0]) + (valptr[1] << 8); - buff_len += encode_unsigned16(*buff + buff_len, val16); - break; - } + case NETWORK_MESSAGE_REJECT_MESSAGE_TO_NETWORK: { + uint8_t *valptr = (uint8_t *)val; + uint16_t val16 = (valptr[0]) + (valptr[1] << 8); + buff_len += encode_unsigned16(*buff + buff_len, val16); + break; + } case NETWORK_MESSAGE_INIT_RT_TABLE: case NETWORK_MESSAGE_INIT_RT_TABLE_ACK: - if ((uint8_t *) val) { - (*buff)[buff_len++] = (uint8_t) port_count; + if ((uint8_t *)val) { + (*buff)[buff_len++] = (uint8_t)port_count; if (port_count > 0) { ROUTER_PORT *port = head; uint8_t portID = 1; while (port != NULL) { - buff_len += - encode_unsigned16(*buff + buff_len, - port->route_info.net); + buff_len += encode_unsigned16(*buff + buff_len, + port->route_info.net); (*buff)[buff_len++] = portID++; (*buff)[buff_len++] = 0; port = port->next; } } } else - (*buff)[buff_len++] = (uint8_t) 0; + (*buff)[buff_len++] = (uint8_t)0; break; case NETWORK_MESSAGE_INVALID: @@ -317,19 +306,15 @@ uint16_t create_network_message( return buff_len; } -void send_network_message( - BACNET_NETWORK_MESSAGE_TYPE network_message_type, - MSG_DATA * data, - uint8_t ** buff, - void *val) +void send_network_message(BACNET_NETWORK_MESSAGE_TYPE network_message_type, + MSG_DATA *data, uint8_t **buff, void *val) { - BACMSG msg; ROUTER_PORT *port = head; int16_t buff_len; if (!data) { - data = (MSG_DATA *) malloc(sizeof(MSG_DATA)); + data = (MSG_DATA *)malloc(sizeof(MSG_DATA)); data->dest.net = BACNET_BROADCAST_NETWORK; data->dest.len = 0; } @@ -354,12 +339,10 @@ void send_network_message( } } -void init_npdu( - BACNET_NPDU_DATA * npdu_data, - BACNET_NETWORK_MESSAGE_TYPE network_message_type, - bool data_expecting_reply) +void init_npdu(BACNET_NPDU_DATA *npdu_data, + BACNET_NETWORK_MESSAGE_TYPE network_message_type, + bool data_expecting_reply) { - if (npdu_data) { npdu_data->data_expecting_reply = data_expecting_reply; npdu_data->protocol_version = BACNET_PROTOCOL_VERSION; diff --git a/demo/router/portthread.c b/demo/router/portthread.c index 9bb3a530..a51e0cb1 100644 --- a/demo/router/portthread.c +++ b/demo/router/portthread.c @@ -1,40 +1,38 @@ /** -* @file -* @author Andriy Sukhynyuk, Vasyl Tkhir, Andriy Ivasiv -* @date 2012 -* @brief Network port storage and handling -* -* @section LICENSE -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*/ + * @file + * @author Andriy Sukhynyuk, Vasyl Tkhir, Andriy Ivasiv + * @date 2012 + * @brief Network port storage and handling + * + * @section LICENSE + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ #include #include #include #include "portthread.h" -ROUTER_PORT *find_snet( - MSGBOX_ID id) +ROUTER_PORT *find_snet(MSGBOX_ID id) { - ROUTER_PORT *port = head; while (port != NULL) { @@ -46,11 +44,8 @@ ROUTER_PORT *find_snet( return NULL; } -ROUTER_PORT *find_dnet( - uint16_t net, - BACNET_ADDRESS * addr) +ROUTER_PORT *find_dnet(uint16_t net, BACNET_ADDRESS *addr) { - ROUTER_PORT *port = head; DNET *dnet; @@ -59,7 +54,6 @@ ROUTER_PORT *find_dnet( return port; while (port != NULL) { - /* check if DNET is directly connected to the router */ if (net == port->route_info.net) return port; @@ -84,32 +78,27 @@ ROUTER_PORT *find_dnet( return NULL; } -void add_dnet( - RT_ENTRY * route_info, - uint16_t net, - BACNET_ADDRESS addr) +void add_dnet(RT_ENTRY *route_info, uint16_t net, BACNET_ADDRESS addr) { - DNET *dnet = route_info->dnets; DNET *tmp; if (dnet == NULL) { - route_info->dnets = (DNET *) malloc(sizeof(DNET)); + route_info->dnets = (DNET *)malloc(sizeof(DNET)); memmove(&route_info->dnets->mac_len, &addr.len, 1); memmove(&route_info->dnets->mac[0], &addr.adr[0], MAX_MAC_LEN); route_info->dnets->net = net; route_info->dnets->state = true; route_info->dnets->next = NULL; } else { - while (dnet != NULL) { - if (dnet->net == net) /* make sure NETs are not repeated */ + if (dnet->net == net) /* make sure NETs are not repeated */ return; tmp = dnet; dnet = dnet->next; } - dnet = (DNET *) malloc(sizeof(DNET)); + dnet = (DNET *)malloc(sizeof(DNET)); memmove(&dnet->mac_len, &addr.len, 1); memmove(&dnet->mac[0], &addr.adr[0], MAX_MAC_LEN); dnet->net = net; @@ -119,10 +108,8 @@ void add_dnet( } } -void cleanup_dnets( - DNET * dnets) +void cleanup_dnets(DNET *dnets) { - DNET *dnet = dnets; while (dnet != NULL) { dnet = dnet->next; diff --git a/demo/scov/main.c b/demo/scov/main.c index c539c5f7..a5505e5b 100644 --- a/demo/scov/main.c +++ b/demo/scov/main.c @@ -1,26 +1,26 @@ /************************************************************************* -* Copyright (C) 2006 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * Copyright (C) 2006 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* command line tool that sends a BACnet service, and displays the reply */ #include @@ -28,8 +28,8 @@ #include #include #include -#include /* for time */ -#include /* for toupper */ +#include /* for time */ +#include /* for toupper */ #define PRINT_ENABLED 1 @@ -55,7 +55,7 @@ #include "dlenv.h" /* buffer used for receive */ -static uint8_t Rx_Buf[MAX_MPDU] = { 0 }; +static uint8_t Rx_Buf[MAX_MPDU] = {0}; /* converted command line arguments */ static uint32_t Target_Device_Object_Instance = BACNET_MAX_INSTANCE; @@ -73,69 +73,57 @@ BACNET_SUBSCRIBE_COV_DATA *COV_Subscribe_Data = NULL; static bool Simple_Ack_Detected = false; static bool Cancel_Requested = false; -static void MyErrorHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - BACNET_ERROR_CLASS error_class, - BACNET_ERROR_CODE error_code) +static void MyErrorHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + BACNET_ERROR_CLASS error_class, + BACNET_ERROR_CODE error_code) { if (address_match(&Target_Address, src) && (invoke_id == Request_Invoke_ID)) { printf("BACnet Error: %s: %s\r\n", - bactext_error_class_name((int) error_class), - bactext_error_code_name((int) error_code)); + bactext_error_class_name((int)error_class), + bactext_error_code_name((int)error_code)); Error_Detected = true; } } -void MyAbortHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t abort_reason, - bool server) +void MyAbortHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t abort_reason, bool server) { - (void) server; + (void)server; if (address_match(&Target_Address, src) && (invoke_id == Request_Invoke_ID)) { printf("BACnet Abort: %s\r\n", - bactext_abort_reason_name((int) abort_reason)); + bactext_abort_reason_name((int)abort_reason)); Error_Detected = true; } } -void MyRejectHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t reject_reason) +void MyRejectHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t reject_reason) { if (address_match(&Target_Address, src) && (invoke_id == Request_Invoke_ID)) { printf("BACnet Reject: %s\r\n", - bactext_reject_reason_name((int) reject_reason)); + bactext_reject_reason_name((int)reject_reason)); Error_Detected = true; } } -void My_Unconfirmed_COV_Notification_Handler( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src) +void My_Unconfirmed_COV_Notification_Handler(uint8_t *service_request, + uint16_t service_len, + BACNET_ADDRESS *src) { handler_ucov_notification(service_request, service_len, src); } void My_Confirmed_COV_Notification_Handler( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src, - BACNET_CONFIRMED_SERVICE_DATA * service_data) + uint8_t *service_request, uint16_t service_len, BACNET_ADDRESS *src, + BACNET_CONFIRMED_SERVICE_DATA *service_data) { handler_ccov_notification(service_request, service_len, src, service_data); } -void MyWritePropertySimpleAckHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id) +void MyWritePropertySimpleAckHandler(BACNET_ADDRESS *src, uint8_t invoke_id) { if (address_match(&Target_Address, src) && (invoke_id == Request_Invoke_ID)) { @@ -144,8 +132,7 @@ void MyWritePropertySimpleAckHandler( } } -static void Init_Service_Handlers( - void) +static void Init_Service_Handlers(void) { Device_Init(NULL); /* we need to handle who-is @@ -155,27 +142,25 @@ static void Init_Service_Handlers( apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_I_AM, handler_i_am_bind); /* set the handler for all the services we don't implement It is required to send the proper reject message... */ - apdu_set_unrecognized_service_handler_handler - (handler_unrecognized_service); + apdu_set_unrecognized_service_handler_handler(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 COV subscriptions */ apdu_set_confirmed_handler(SERVICE_CONFIRMED_COV_NOTIFICATION, - My_Confirmed_COV_Notification_Handler); + My_Confirmed_COV_Notification_Handler); apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_COV_NOTIFICATION, - My_Unconfirmed_COV_Notification_Handler); + My_Unconfirmed_COV_Notification_Handler); /* handle the Simple ack coming back from SubscribeCOV */ apdu_set_confirmed_simple_ack_handler(SERVICE_CONFIRMED_SUBSCRIBE_COV, - MyWritePropertySimpleAckHandler); + MyWritePropertySimpleAckHandler); /* handle any errors coming back */ apdu_set_error_handler(SERVICE_CONFIRMED_SUBSCRIBE_COV, MyErrorHandler); apdu_set_abort_handler(MyAbortHandler); apdu_set_reject_handler(MyRejectHandler); } -void cleanup( - void) +void cleanup(void) { BACNET_SUBSCRIBE_COV_DATA *cov_data = NULL; BACNET_SUBSCRIBE_COV_DATA *cov_data_old = NULL; @@ -188,15 +173,11 @@ void cleanup( } } -int main( - int argc, - char *argv[]) +int main(int argc, char *argv[]) { - BACNET_ADDRESS src = { - 0 - }; /* address where message came from */ + BACNET_ADDRESS src = {0}; /* address where message came from */ uint16_t pdu_len = 0; - unsigned timeout = 100; /* milliseconds */ + unsigned timeout = 100; /* milliseconds */ unsigned max_apdu = 0; time_t elapsed_seconds = 0; time_t last_seconds = 0; @@ -220,31 +201,43 @@ int main( } if (print_usage_terse) { filename = filename_remove_path(argv[0]); - printf("Usage: %s device-id object-type object-instance " - "process-id <[un]confirmed lifetime|cancel>\r\n", filename); + printf( + "Usage: %s device-id object-type object-instance " + "process-id <[un]confirmed lifetime|cancel>\r\n", + filename); if (!print_usage_verbose) { return 0; } } if (print_usage_verbose) { - printf("\r\n" "device-id:\r\n" - "The subscriber BACnet Device Object Instance number.\r\n" "\r\n" + printf( + "\r\n" + "device-id:\r\n" + "The subscriber BACnet Device Object Instance number.\r\n" + "\r\n" "object-type:\r\n" "The monitored object type is the integer value of the\r\n" "enumeration BACNET_OBJECT_TYPE in bacenum.h. For example,\r\n" "if you were monitoring Analog Output 2, the object-type\r\n" - "would be 1.\r\n" "\r\n" "object-instance:\r\n" - "The monitored object instance number.\r\n" "\r\n" + "would be 1.\r\n" + "\r\n" + "object-instance:\r\n" + "The monitored object instance number.\r\n" + "\r\n" "process-id:\r\n" - "Process Identifier for this COV subscription.\r\n" "\r\n" + "Process Identifier for this COV subscription.\r\n" + "\r\n" "confirmed:\r\n" "Optional flag to subscribe using Confirmed notifications.\r\n" - "Use the word \'confirmed\' or \'unconfirmed\'.\r\n" "\r\n" + "Use the word \'confirmed\' or \'unconfirmed\'.\r\n" + "\r\n" "lifetime:\r\n" - "Optional subscription lifetime is conveyed in seconds.\r\n" "\r\n" + "Optional subscription lifetime is conveyed in seconds.\r\n" + "\r\n" "cancel:\r\n" "Use the word \'cancel\' instead of confirm and lifetime.\r\n" - "This shall indicate a cancellation request.\r\n" "\r\n" + "This shall indicate a cancellation request.\r\n" + "\r\n" "Example:\r\n" "If you want subscribe to Device 123 Analog Input 9 object\r\n" "using confirmed COV notifications for 5 minutes,\r\n" @@ -254,7 +247,8 @@ int main( "notifications, send the following command:\r\n" "%s 123 0 9 1 unconfirmed 600\r\n" "To cancel the same COV subscription request,\r\n" - "send the following command:\r\n" "%s 123 0 9 1 cancel\r\n", + "send the following command:\r\n" + "%s 123 0 9 1 cancel\r\n", filename, filename, filename); return 0; } @@ -262,7 +256,7 @@ int main( Target_Device_Object_Instance = strtol(argv[1], 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); + Target_Device_Object_Instance, BACNET_MAX_INSTANCE); return 1; } atexit(cleanup); @@ -271,19 +265,21 @@ int main( argi = 2; while (cov_data) { cov_data->monitoredObjectIdentifier.type = strtol(argv[argi], NULL, 0); - if (cov_data->monitoredObjectIdentifier.type >= MAX_BACNET_OBJECT_TYPE) { + 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; } argi++; cov_data->monitoredObjectIdentifier.instance = strtol(argv[argi], NULL, 0); - if (cov_data->monitoredObjectIdentifier.instance > BACNET_MAX_INSTANCE) { + if (cov_data->monitoredObjectIdentifier.instance > + BACNET_MAX_INSTANCE) { fprintf(stderr, "object-instance=%u - it must be less than %u\r\n", - cov_data->monitoredObjectIdentifier.instance, - BACNET_MAX_INSTANCE + 1); + cov_data->monitoredObjectIdentifier.instance, + BACNET_MAX_INSTANCE + 1); return 1; } argi++; @@ -329,12 +325,11 @@ int main( last_seconds = time(NULL); timeout_seconds = (apdu_timeout() / 1000) * apdu_retries(); /* try to bind with the device */ - found = - address_bind_request(Target_Device_Object_Instance, &max_apdu, - &Target_Address); + found = address_bind_request(Target_Device_Object_Instance, &max_apdu, + &Target_Address); if (!found) { Send_WhoIs(Target_Device_Object_Instance, - Target_Device_Object_Instance); + Target_Device_Object_Instance); } /* start at the beginning of the subscribe list */ cov_data = COV_Subscribe_Data; @@ -356,9 +351,8 @@ int main( } /* wait until the device is bound, or timeout and quit */ if (!found) { - found = - address_bind_request(Target_Device_Object_Instance, &max_apdu, - &Target_Address); + found = address_bind_request(Target_Device_Object_Instance, + &max_apdu, &Target_Address); } if (found) { if (Request_Invoke_ID == 0) { @@ -371,16 +365,16 @@ int main( Target_Device_Process_Identifier = cov_data->subscriberProcessIdentifier; Request_Invoke_ID = - Send_COV_Subscribe(Target_Device_Object_Instance, - cov_data); + Send_COV_Subscribe(Target_Device_Object_Instance, cov_data); if (!cov_data->cancellationRequest && (timeout_seconds < cov_data->lifetime)) { /* increase the timeout to the longest lifetime */ timeout_seconds = cov_data->lifetime; } - printf("Sent SubscribeCOV request. " + printf( + "Sent SubscribeCOV request. " " Waiting up to %u seconds....\r\n", - (unsigned) (timeout_seconds - elapsed_seconds)); + (unsigned)(timeout_seconds - elapsed_seconds)); } else if (tsm_invoke_id_free(Request_Invoke_ID)) { if (cov_data->next) { cov_data = cov_data->next; diff --git a/demo/server/main.c b/demo/server/main.c index ddd153eb..cf06cb47 100644 --- a/demo/server/main.c +++ b/demo/server/main.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2006 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2006 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -64,7 +64,6 @@ #include "ucix.h" #endif /* defined(BAC_UCI) */ - /** @file server/main.c Example server application using the BACnet Stack. */ /* (Doxygen note: The next two lines pull all the following Javadoc @@ -73,13 +72,12 @@ /*@{*/ /** Buffer used for receiving */ -static uint8_t Rx_Buf[MAX_MPDU] = { 0 }; +static uint8_t Rx_Buf[MAX_MPDU] = {0}; /** Initialize the handlers we will utilize. * @see Device_Init, apdu_set_unconfirmed_handler, apdu_set_confirmed_handler */ -static void Init_Service_Handlers( - void) +static void Init_Service_Handlers(void) { Device_Init(NULL); /* we need to handle who-is to support dynamic device binding */ @@ -102,49 +100,48 @@ static void Init_Service_Handlers( /* set the handler for all the services we don't implement */ /* It is required to send the proper reject message... */ - apdu_set_unrecognized_service_handler_handler - (handler_unrecognized_service); + apdu_set_unrecognized_service_handler_handler(handler_unrecognized_service); /* 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, - handler_read_property); + handler_read_property); apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROP_MULTIPLE, - handler_read_property_multiple); + handler_read_property_multiple); apdu_set_confirmed_handler(SERVICE_CONFIRMED_WRITE_PROPERTY, - handler_write_property); + handler_write_property); apdu_set_confirmed_handler(SERVICE_CONFIRMED_WRITE_PROP_MULTIPLE, - handler_write_property_multiple); + handler_write_property_multiple); apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_RANGE, - handler_read_range); + handler_read_range); #if defined(BACFILE) apdu_set_confirmed_handler(SERVICE_CONFIRMED_ATOMIC_READ_FILE, - handler_atomic_read_file); + handler_atomic_read_file); apdu_set_confirmed_handler(SERVICE_CONFIRMED_ATOMIC_WRITE_FILE, - handler_atomic_write_file); + handler_atomic_write_file); #endif apdu_set_confirmed_handler(SERVICE_CONFIRMED_REINITIALIZE_DEVICE, - handler_reinitialize_device); + handler_reinitialize_device); apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_UTC_TIME_SYNCHRONIZATION, - handler_timesync_utc); + handler_timesync_utc); apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION, - handler_timesync); + handler_timesync); apdu_set_confirmed_handler(SERVICE_CONFIRMED_SUBSCRIBE_COV, - handler_cov_subscribe); + handler_cov_subscribe); apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_COV_NOTIFICATION, - handler_ucov_notification); + handler_ucov_notification); /* handle communication so we can shutup when asked */ apdu_set_confirmed_handler(SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL, - handler_device_communication_control); + handler_device_communication_control); /* handle the data coming back from private requests */ apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_PRIVATE_TRANSFER, - handler_unconfirmed_private_transfer); + handler_unconfirmed_private_transfer); #if defined(INTRINSIC_REPORTING) apdu_set_confirmed_handler(SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM, - handler_alarm_ack); + handler_alarm_ack); apdu_set_confirmed_handler(SERVICE_CONFIRMED_GET_EVENT_INFORMATION, - handler_get_event_information); + handler_get_event_information); apdu_set_confirmed_handler(SERVICE_CONFIRMED_GET_ALARM_SUMMARY, - handler_get_alarm_summary); + handler_get_alarm_summary); #endif /* defined(INTRINSIC_REPORTING) */ #if defined(BACNET_TIME_MASTER) handler_timesync_init(); @@ -159,17 +156,22 @@ static void print_usage(const char *filename) static void print_help(const char *filename) { - printf("Simulate a BACnet server device\n" + printf( + "Simulate a BACnet server device\n" "device-instance:\n" "BACnet Device Object Instance number that you are\n" "trying simulate.\n" "device-name:\n" "The Device object-name is the text name for the device.\n" "\nExample:\n"); - printf("To simulate Device 123, use the following command:\n" - "%s 123\n", filename); - printf("To simulate Device 123 named Fred, use following command:\n" - "%s 123 Fred\n", filename); + printf( + "To simulate Device 123, use the following command:\n" + "%s 123\n", + filename); + printf( + "To simulate Device 123 named Fred, use following command:\n" + "%s 123 Fred\n", + filename); } /** Main function of server demo. @@ -184,15 +186,11 @@ static void print_help(const char *filename) * @param argv [in] Takes one argument: the Device Instance #. * @return 0 on success. */ -int main( - int argc, - char *argv[]) +int main(int argc, char *argv[]) { - BACNET_ADDRESS src = { - 0 - }; /* address where message came from */ + BACNET_ADDRESS src = {0}; /* address where message came from */ uint16_t pdu_len = 0; - unsigned timeout = 1; /* milliseconds */ + unsigned timeout = 1; /* milliseconds */ time_t last_seconds = 0; time_t current_seconds = 0; uint32_t elapsed_seconds = 0; @@ -218,8 +216,10 @@ int main( } if (strcmp(argv[argi], "--version") == 0) { printf("%s %s\n", filename, BACNET_VERSION_TEXT); - printf("Copyright (C) 2014 by Steve Karg and others.\n" - "This is free software; see the source for copying conditions.\n" + printf( + "Copyright (C) 2014 by Steve Karg and others.\n" + "This is free software; see the source for copying " + "conditions.\n" "There is NO warranty; not even for MERCHANTABILITY or\n" "FITNESS FOR A PARTICULAR PURPOSE.\n"); return 0; @@ -247,9 +247,12 @@ int main( ucix_cleanup(ctx); #endif /* defined(BAC_UCI) */ - printf("BACnet Server Demo\n" "BACnet Stack Version %s\n" - "BACnet Device ID: %u\n" "Max APDU: %d\n", BACnet_Version, - Device_Object_Instance_Number(), MAX_APDU); + printf( + "BACnet Server Demo\n" + "BACnet Stack Version %s\n" + "BACnet Device ID: %u\n" + "Max APDU: %d\n", + BACnet_Version, Device_Object_Instance_Number(), MAX_APDU); /* load any static address bindings to show up in our device bindings list */ address_init(); @@ -273,7 +276,7 @@ int main( npdu_handler(&src, &Rx_Buf[0], pdu_len); } /* at least one second has passed */ - elapsed_seconds = (uint32_t) (current_seconds - last_seconds); + elapsed_seconds = (uint32_t)(current_seconds - last_seconds); if (elapsed_seconds) { last_seconds = current_seconds; dcc_timer_seconds(elapsed_seconds); diff --git a/demo/timesync/main.c b/demo/timesync/main.c index 1f7d5209..704fdced 100644 --- a/demo/timesync/main.c +++ b/demo/timesync/main.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2006 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2006 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* command line tool that sends a BACnet service, and displays the reply */ #include @@ -29,7 +29,7 @@ #include #include #include -#include /* for time */ +#include /* for time */ #include #include "address.h" #include "bactext.h" @@ -50,38 +50,32 @@ #include "dlenv.h" /* buffer used for receive */ -static uint8_t Rx_Buf[MAX_MPDU] = { 0 }; +static uint8_t Rx_Buf[MAX_MPDU] = {0}; /* error flag */ static bool Error_Detected = false; -void MyAbortHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t abort_reason, - bool server) +void MyAbortHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t abort_reason, bool server) { /* FIXME: verify src and invoke id */ - (void) src; - (void) invoke_id; - (void) server; + (void)src; + (void)invoke_id; + (void)server; printf("BACnet Abort: %s\n", bactext_abort_reason_name(abort_reason)); Error_Detected = true; } -void MyRejectHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t reject_reason) +void MyRejectHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t reject_reason) { /* FIXME: verify src and invoke id */ - (void) src; - (void) invoke_id; + (void)src; + (void)invoke_id; printf("BACnet Reject: %s\n", bactext_reject_reason_name(reject_reason)); Error_Detected = true; } -static void Init_Service_Handlers( - void) +static void Init_Service_Handlers(void) { Device_Init(NULL); /* we need to handle who-is @@ -89,16 +83,15 @@ static void Init_Service_Handlers( apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, handler_who_is); /* set the handler for all the services we don't implement It is required to send the proper reject message... */ - apdu_set_unrecognized_service_handler_handler - (handler_unrecognized_service); + apdu_set_unrecognized_service_handler_handler(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 reply (request) coming in */ apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_UTC_TIME_SYNCHRONIZATION, - handler_timesync_utc); + handler_timesync_utc); apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION, - handler_timesync); + handler_timesync); /* handle any errors coming back */ apdu_set_abort_handler(MyAbortHandler); apdu_set_reject_handler(MyRejectHandler); @@ -112,7 +105,8 @@ static void print_usage(char *filename) static void print_help(char *filename) { - printf("Send BACnet TimeSynchronization request.\n" + printf( + "Send BACnet TimeSynchronization request.\n" "\n" "--mac A\n" "BACnet mac address." @@ -131,13 +125,19 @@ static void print_help(char *filename) "or an IP string with optional port number like 10.1.2.3:47808\n" "or an Ethernet MAC in hex like 00:21:70:7e:32:bb\n" "\n"); - printf("Examples:\n" + printf( + "Examples:\n" "Send a TimeSynchronization request to DNET 123:\n" - "%s --dnet 123\n", filename); - printf("Send a TimeSynchronization request to MAC 10.0.0.1 DNET 123 DADR 5:\n" - "%s --mac 10.0.0.1 --dnet 123 --dadr 5\n", filename); - printf("Send a TimeSynchronization request to MAC 10.1.2.3:47808:\n" - "%s --mac 10.1.2.3:47808\n", filename); + "%s --dnet 123\n", + filename); + printf( + "Send a TimeSynchronization request to MAC 10.0.0.1 DNET 123 DADR 5:\n" + "%s --mac 10.0.0.1 --dnet 123 --dadr 5\n", + filename); + printf( + "Send a TimeSynchronization request to MAC 10.1.2.3:47808:\n" + "%s --mac 10.1.2.3:47808\n", + filename); #if 0 /* FIXME: it would be nice to be able to send arbitrary time values */ "date format: year/month/day:dayofweek (e.g. 2006/4/1:6)\n" @@ -151,15 +151,11 @@ static void print_help(char *filename) #endif } -int main( - int argc, - char *argv[]) +int main(int argc, char *argv[]) { - BACNET_ADDRESS src = { - 0 - }; /* address where message came from */ + BACNET_ADDRESS src = {0}; /* address where message came from */ uint16_t pdu_len = 0; - unsigned timeout = 100; /* milliseconds */ + unsigned timeout = 100; /* milliseconds */ time_t elapsed_seconds = 0; time_t last_seconds = 0; time_t current_seconds = 0; @@ -169,9 +165,9 @@ int main( BACNET_DATE bdate; BACNET_TIME btime; long dnet = -1; - BACNET_MAC_ADDRESS mac = { 0 }; - BACNET_MAC_ADDRESS adr = { 0 }; - BACNET_ADDRESS dest = { 0 }; + BACNET_MAC_ADDRESS mac = {0}; + BACNET_MAC_ADDRESS adr = {0}; + BACNET_ADDRESS dest = {0}; bool global_broadcast = true; int argi = 0; char *filename = NULL; @@ -186,8 +182,10 @@ int main( } if (strcmp(argv[argi], "--version") == 0) { printf("%s %s\n", filename, BACNET_VERSION_TEXT); - printf("Copyright (C) 2014 by Steve Karg and others.\n" - "This is free software; see the source for copying conditions.\n" + printf( + "Copyright (C) 2014 by Steve Karg and others.\n" + "This is free software; see the source for copying " + "conditions.\n" "There is NO warranty; not even for MERCHANTABILITY or\n" "FITNESS FOR A PARTICULAR PURPOSE.\n"); return 0; diff --git a/demo/ucov/main.c b/demo/ucov/main.c index 30a172d1..a8bbb591 100644 --- a/demo/ucov/main.c +++ b/demo/ucov/main.c @@ -1,34 +1,34 @@ /************************************************************************** -* -* Copyright (C) 2006 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2006 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* command line tool that sends a BACnet service */ #include #include #include #include -#include /* for time */ +#include /* for time */ #include #include "bactext.h" #include "iam.h" @@ -50,8 +50,7 @@ #include "txbuf.h" #include "dlenv.h" -static void Init_Service_Handlers( - void) +static void Init_Service_Handlers(void) { Device_Init(NULL); /* we need to handle who-is @@ -61,16 +60,13 @@ static void Init_Service_Handlers( apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_I_AM, handler_i_am_bind); /* set the handler for all the services we don't implement It is required to send the proper reject message... */ - apdu_set_unrecognized_service_handler_handler - (handler_unrecognized_service); + apdu_set_unrecognized_service_handler_handler(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); } -int main( - int argc, - char *argv[]) +int main(int argc, char *argv[]) { char *value_string = NULL; bool status = false; @@ -80,49 +76,85 @@ int main( if (argc < 7) { /* note: priority 16 and 0 should produce the same end results... */ - printf("Usage: %s pid device-id object-type object-instance " - "time property tag value [priority] [index]\r\n" "\r\n" "pid:\r\n" - "Process Identifier for this broadcast.\r\n" "\r\n" + printf( + "Usage: %s pid device-id object-type object-instance " + "time property tag value [priority] [index]\r\n" + "\r\n" + "pid:\r\n" + "Process Identifier for this broadcast.\r\n" + "\r\n" "device-id:\r\n" - "The Initiating BACnet Device Object Instance number.\r\n" "\r\n" + "The Initiating BACnet Device Object Instance number.\r\n" + "\r\n" "object-type:\r\n" "The monitored object type is the integer value of the\r\n" "enumeration BACNET_OBJECT_TYPE in bacenum.h. For example,\r\n" "if you were monitoring Analog Output 2, the object-type\r\n" - "would be 1.\r\n" "\r\n" "object-instance:\r\n" - "The monitored object instance number.\r\n" "\r\n" "time:\r\n" + "would be 1.\r\n" + "\r\n" + "object-instance:\r\n" + "The monitored object instance number.\r\n" + "\r\n" + "time:\r\n" "The subscription time remaining is conveyed in seconds.\r\n" - "\r\n" "property:\r\n" + "\r\n" + "property:\r\n" "The property is an integer value of the enumeration \r\n" "BACNET_PROPERTY_ID in bacenum.h. For example, if you were\r\n" "monitoring the Present Value property, you would use 85\r\n" - "as the property.\r\n" "\r\n" "tag:\r\n" - "Tag is the integer value of the enumeration BACNET_APPLICATION_TAG \r\n" + "as the property.\r\n" + "\r\n" + "tag:\r\n" + "Tag is the integer value of the enumeration " + "BACNET_APPLICATION_TAG \r\n" "in bacenum.h. It is the data type of the value that you are\r\n" - "monitoring. For example, if you were monitoring a REAL value, you would \r\n" - "use a tag of 4." "\r\n" "value:\r\n" - "The value is an ASCII representation of some type of data that you\r\n" - "are monitoring. It is encoded using the tag information provided. For\r\n" - "example, if you were writing a REAL value of 100.0, you would use \r\n" - "100.0 as the value.\r\n" "\r\n" "[priority]:\r\n" - "This optional parameter is used for reporting the priority of the\r\n" + "monitoring. For example, if you were monitoring a REAL value, " + "you would \r\n" + "use a tag of 4." + "\r\n" + "value:\r\n" + "The value is an ASCII representation of some type of data that " + "you\r\n" + "are monitoring. It is encoded using the tag information " + "provided. For\r\n" + "example, if you were writing a REAL value of 100.0, you would use " + "\r\n" + "100.0 as the value.\r\n" + "\r\n" + "[priority]:\r\n" + "This optional parameter is used for reporting the priority of " + "the\r\n" "value. If no priority is given, none is sent, and the BACnet \r\n" "standard requires that the value is reported at the lowest \r\n" "priority (16) if the object property supports priorities.\r\n" - "\r\n" "[index]\r\n" - "This optional integer parameter is the index number of an array.\r\n" - "If the property is an array, individual elements can be reported.\r\n" - "\r\n" "Here is a brief overview of BACnet property and tags:\r\n" + "\r\n" + "[index]\r\n" + "This optional integer parameter is the index number of an " + "array.\r\n" + "If the property is an array, individual elements can be " + "reported.\r\n" + "\r\n" + "Here is a brief overview of BACnet property and tags:\r\n" "Certain properties are expected to be written with certain \r\n" - "application tags, so you probably need to know which ones to use\r\n" - "with each property of each object. It is almost safe to say that\r\n" - "given a property and an object and a table, the tag could be looked\r\n" - "up automatically. There may be a few exceptions to this, such as\r\n" - "the Any property type in the schedule object and the Present Value\r\n" - "accepting REAL, BOOLEAN, NULL, etc. Perhaps it would be simpler for\r\n" - "the demo to use this kind of table - but I also wanted to be able\r\n" - "to do negative testing by passing the wrong tag and have the server\r\n" - "return a reject message.\r\n" "\r\n" "Example:\r\n" + "application tags, so you probably need to know which ones to " + "use\r\n" + "with each property of each object. It is almost safe to say " + "that\r\n" + "given a property and an object and a table, the tag could be " + "looked\r\n" + "up automatically. There may be a few exceptions to this, such " + "as\r\n" + "the Any property type in the schedule object and the Present " + "Value\r\n" + "accepting REAL, BOOLEAN, NULL, etc. Perhaps it would be simpler " + "for\r\n" + "the demo to use this kind of table - but I also wanted to be " + "able\r\n" + "to do negative testing by passing the wrong tag and have the " + "server\r\n" + "return a reject message.\r\n" + "\r\n" + "Example:\r\n" "If you want generate an unconfirmed COV,\r\n" "you could send the following command:\r\n" "%s 1 2 3 4 5 85 4 100.0\r\n" @@ -155,34 +187,34 @@ int main( if (cov_data.initiatingDeviceIdentifier >= BACNET_MAX_INSTANCE) { fprintf(stderr, "device-instance=%u - it must be less than %u\r\n", - cov_data.initiatingDeviceIdentifier, BACNET_MAX_INSTANCE); + cov_data.initiatingDeviceIdentifier, BACNET_MAX_INSTANCE); return 1; } 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) { fprintf(stderr, "object-instance=%u - it must be less than %u\r\n", - cov_data.monitoredObjectIdentifier.instance, - BACNET_MAX_INSTANCE + 1); + cov_data.monitoredObjectIdentifier.instance, + BACNET_MAX_INSTANCE + 1); return 1; } if (cov_data.listOfValues->propertyIdentifier > MAX_BACNET_PROPERTY_ID) { fprintf(stderr, "property-identifier=%u - it must be less than %u\r\n", - cov_data.listOfValues->propertyIdentifier, - MAX_BACNET_PROPERTY_ID + 1); + cov_data.listOfValues->propertyIdentifier, + MAX_BACNET_PROPERTY_ID + 1); return 1; } if (tag >= MAX_BACNET_APPLICATION_TAG) { fprintf(stderr, "tag=%u - it must be less than %u\r\n", tag, - MAX_BACNET_APPLICATION_TAG); + MAX_BACNET_APPLICATION_TAG); return 1; } - status = - bacapp_parse_application_data(tag, value_string, - &cov_data.listOfValues->value); + status = bacapp_parse_application_data(tag, value_string, + &cov_data.listOfValues->value); if (!status) { /* FIXME: show the expected entry format for the tag */ fprintf(stderr, "unable to parse the tag value\r\n"); @@ -194,7 +226,7 @@ int main( dlenv_init(); atexit(datalink_cleanup); Send_UCOV_Notify(&Handler_Transmit_Buffer[0], - sizeof(Handler_Transmit_Buffer), &cov_data); + sizeof(Handler_Transmit_Buffer), &cov_data); return 0; } diff --git a/demo/uevent/main.c b/demo/uevent/main.c index 91be87e3..a5c36590 100644 --- a/demo/uevent/main.c +++ b/demo/uevent/main.c @@ -1,34 +1,34 @@ /************************************************************************** -* -* Copyright (C) 2016 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2016 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* command line tool that sends a BACnet service */ #include #include #include #include -#include /* for time */ +#include /* for time */ #include #include "bactext.h" #include "iam.h" @@ -52,8 +52,7 @@ #include "txbuf.h" #include "dlenv.h" -static void Init_Service_Handlers( - void) +static void Init_Service_Handlers(void) { Device_Init(NULL); /* we need to handle who-is @@ -63,16 +62,16 @@ static void Init_Service_Handlers( apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_I_AM, handler_i_am_bind); /* set the handler for all the services we don't implement It is required to send the proper reject message... */ - apdu_set_unrecognized_service_handler_handler - (handler_unrecognized_service); + apdu_set_unrecognized_service_handler_handler(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); } static void print_usage(char *filename) { - printf("Usage: %s pid object-type object-instance \n" + printf( + "Usage: %s pid object-type object-instance \n" " event-object-type event-object-instance \n" " sequence-number notification-class priority event-type\n" " [reference-bit-string status-flags message notify-type\n" @@ -87,7 +86,8 @@ static void print_usage(char *filename) static void print_help(char *filename) { printf("Send BACnet UnconfirmedEventNotification message for a device.\n"); - printf("--mac A\n" + printf( + "--mac A\n" "Optional BACnet mac address." "Valid ranges are from 00 to FF (hex) for MS/TP or ARCNET,\n" "or an IP string with optional port number like 10.1.2.3:47808\n" @@ -99,25 +99,24 @@ static void print_help(char *filename) "and 65535 is network broadcast.\n" "\n" "--dadr A\n" - "Optional BACnet mac address on the destination BACnet network number.\n" + "Optional BACnet mac address on the destination BACnet network " + "number.\n" "Valid ranges are from 00 to FF (hex) for MS/TP or ARCNET,\n" "or an IP string with optional port number like 10.1.2.3:47808\n" "or an Ethernet MAC in hex like 00:21:70:7e:32:bb\n" "\n"); } -int main( - int argc, - char *argv[]) +int main(int argc, char *argv[]) { BACNET_EVENT_NOTIFICATION_DATA event_data = {0}; BACNET_BIT_STRING *pBitString; BACNET_CHARACTER_STRING bcstring; BACNET_PROPERTY_STATE_TYPE tag = BOOLEAN_VALUE; long dnet = -1; - BACNET_MAC_ADDRESS mac = { 0 }; - BACNET_MAC_ADDRESS adr = { 0 }; - BACNET_ADDRESS dest = { 0 }; + BACNET_MAC_ADDRESS mac = {0}; + BACNET_MAC_ADDRESS adr = {0}; + BACNET_ADDRESS dest = {0}; bool specific_address = false; int argi = 0; unsigned int target_args = 0; @@ -132,8 +131,10 @@ int main( } if (strcmp(argv[argi], "--version") == 0) { printf("%s %s\n", filename, BACNET_VERSION_TEXT); - printf("Copyright (C) 2016 by Steve Karg and others.\n" - "This is free software; see the source for copying conditions.\n" + printf( + "Copyright (C) 2016 by Steve Karg and others.\n" + "This is free software; see the source for copying " + "conditions.\n" "There is NO warranty; not even for MERCHANTABILITY or\n" "FITNESS FOR A PARTICULAR PURPOSE.\n"); return 0; @@ -183,8 +184,7 @@ int main( strtol(argv[argi], NULL, 0); target_args++; } else if (target_args == 6) { - event_data.notificationClass = - strtol(argv[argi], NULL, 0); + event_data.notificationClass = strtol(argv[argi], NULL, 0); target_args++; } else if (target_args == 7) { event_data.priority = strtol(argv[argi], NULL, 0); @@ -195,11 +195,14 @@ int main( } else { if (event_data.eventType == EVENT_CHANGE_OF_BITSTRING) { if (target_args == 9) { - pBitString = &event_data.notificationParams.changeOfBitstring.referencedBitString; + pBitString = + &event_data.notificationParams.changeOfBitstring + .referencedBitString; bitstring_init_ascii(pBitString, argv[argi]); target_args++; } else if (target_args == 10) { - pBitString = &event_data.notificationParams.changeOfBitstring.statusFlags; + pBitString = &event_data.notificationParams + .changeOfBitstring.statusFlags; bitstring_init_ascii(pBitString, argv[argi]); target_args++; } else if (target_args == 11) { @@ -225,50 +228,61 @@ int main( } else if (event_data.eventType == EVENT_CHANGE_OF_STATE) { if (target_args == 9) { tag = strtol(argv[argi], NULL, 0); - event_data.notificationParams.changeOfState.newState.tag = tag; + event_data.notificationParams.changeOfState.newState + .tag = tag; target_args++; } else if (target_args == 10) { if (tag == BOOLEAN_VALUE) { - event_data.notificationParams.changeOfState.newState.state.booleanValue = + event_data.notificationParams.changeOfState.newState + .state.booleanValue = strtol(argv[argi], NULL, 0); } else if (tag == BINARY_VALUE) { - event_data.notificationParams.changeOfState.newState.state.binaryValue = + event_data.notificationParams.changeOfState.newState + .state.binaryValue = strtol(argv[argi], NULL, 0); } else if (tag == EVENT_TYPE) { - event_data.notificationParams.changeOfState.newState.state.eventType = - strtol(argv[argi], NULL, 0); + event_data.notificationParams.changeOfState.newState + .state.eventType = strtol(argv[argi], NULL, 0); } else if (tag == POLARITY) { - event_data.notificationParams.changeOfState.newState.state.polarity = - strtol(argv[argi], NULL, 0); + event_data.notificationParams.changeOfState.newState + .state.polarity = strtol(argv[argi], NULL, 0); } else if (tag == PROGRAM_CHANGE) { - event_data.notificationParams.changeOfState.newState.state.programChange = + event_data.notificationParams.changeOfState.newState + .state.programChange = strtol(argv[argi], NULL, 0); } else if (tag == PROGRAM_STATE) { - event_data.notificationParams.changeOfState.newState.state.programState = + event_data.notificationParams.changeOfState.newState + .state.programState = strtol(argv[argi], NULL, 0); } else if (tag == REASON_FOR_HALT) { - event_data.notificationParams.changeOfState.newState.state.programError = + event_data.notificationParams.changeOfState.newState + .state.programError = strtol(argv[argi], NULL, 0); } else if (tag == RELIABILITY) { - event_data.notificationParams.changeOfState.newState.state.reliability = + event_data.notificationParams.changeOfState.newState + .state.reliability = strtol(argv[argi], NULL, 0); } else if (tag == STATE) { - event_data.notificationParams.changeOfState.newState.state.state = - strtol(argv[argi], NULL, 0); + event_data.notificationParams.changeOfState.newState + .state.state = strtol(argv[argi], NULL, 0); } else if (tag == SYSTEM_STATUS) { - event_data.notificationParams.changeOfState.newState.state.systemStatus = + event_data.notificationParams.changeOfState.newState + .state.systemStatus = strtol(argv[argi], NULL, 0); } else if (tag == UNITS) { - event_data.notificationParams.changeOfState.newState.state.units = - strtol(argv[argi], NULL, 0); + event_data.notificationParams.changeOfState.newState + .state.units = strtol(argv[argi], NULL, 0); } else if (tag == UNSIGNED_VALUE) { - event_data.notificationParams.changeOfState.newState.state.unsignedValue = + event_data.notificationParams.changeOfState.newState + .state.unsignedValue = strtol(argv[argi], NULL, 0); } else if (tag == LIFE_SAFETY_MODE) { - event_data.notificationParams.changeOfState.newState.state.lifeSafetyMode = + event_data.notificationParams.changeOfState.newState + .state.lifeSafetyMode = strtol(argv[argi], NULL, 0); } else if (tag == LIFE_SAFETY_STATE) { - event_data.notificationParams.changeOfState.newState.state.lifeSafetyState = + event_data.notificationParams.changeOfState.newState + .state.lifeSafetyState = strtol(argv[argi], NULL, 0); } else { printf("Invalid Change-Of-State Tag\n"); @@ -276,7 +290,8 @@ int main( } target_args++; } else if (target_args == 11) { - pBitString = &event_data.notificationParams.changeOfBitstring.statusFlags; + pBitString = &event_data.notificationParams + .changeOfBitstring.statusFlags; bitstring_init_ascii(pBitString, argv[argi]); target_args++; } else if (target_args == 12) { @@ -303,7 +318,8 @@ int main( } else if (event_data.eventType == EVENT_COMMAND_FAILURE) { } else if (event_data.eventType == EVENT_FLOATING_LIMIT) { } else if (event_data.eventType == EVENT_OUT_OF_RANGE) { - } else if (event_data.eventType == EVENT_CHANGE_OF_LIFE_SAFETY) { + } else if (event_data.eventType == + EVENT_CHANGE_OF_LIFE_SAFETY) { } else if (event_data.eventType == EVENT_EXTENDED) { } else if (event_data.eventType == EVENT_BUFFER_READY) { } else if (event_data.eventType == EVENT_UNSIGNED_RANGE) { diff --git a/demo/uptransfer/main.c b/demo/uptransfer/main.c index eb720779..b7f5ff20 100644 --- a/demo/uptransfer/main.c +++ b/demo/uptransfer/main.c @@ -1,26 +1,26 @@ /************************************************************************* -* Copyright (C) 2006 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * Copyright (C) 2006 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* command line tool that sends a BACnet service, and displays the reply */ #include @@ -28,8 +28,8 @@ #include #include #include -#include /* for time */ -#include /* for toupper */ +#include /* for time */ +#include /* for toupper */ #define PRINT_ENABLED 1 @@ -55,7 +55,7 @@ #include "dlenv.h" /* buffer used for receive */ -static uint8_t Rx_Buf[MAX_MPDU] = { 0 }; +static uint8_t Rx_Buf[MAX_MPDU] = {0}; /* converted command line arguments */ static bool Target_Broadcast; @@ -76,51 +76,43 @@ static uint8_t Request_Invoke_ID = 0; static BACNET_ADDRESS Target_Address; static bool Error_Detected = false; -static void MyErrorHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - BACNET_ERROR_CLASS error_class, - BACNET_ERROR_CODE error_code) +static void MyErrorHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + BACNET_ERROR_CLASS error_class, + BACNET_ERROR_CODE error_code) { if (address_match(&Target_Address, src) && (invoke_id == Request_Invoke_ID)) { printf("BACnet Error: %s: %s\r\n", - bactext_error_class_name((int) error_class), - bactext_error_code_name((int) error_code)); + bactext_error_class_name((int)error_class), + bactext_error_code_name((int)error_code)); Error_Detected = true; } } -void MyAbortHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t abort_reason, - bool server) +void MyAbortHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t abort_reason, bool server) { - (void) server; + (void)server; if (address_match(&Target_Address, src) && (invoke_id == Request_Invoke_ID)) { printf("BACnet Abort: %s\r\n", - bactext_abort_reason_name((int) abort_reason)); + bactext_abort_reason_name((int)abort_reason)); Error_Detected = true; } } -void MyRejectHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t reject_reason) +void MyRejectHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t reject_reason) { if (address_match(&Target_Address, src) && (invoke_id == Request_Invoke_ID)) { printf("BACnet Reject: %s\r\n", - bactext_reject_reason_name((int) reject_reason)); + bactext_reject_reason_name((int)reject_reason)); Error_Detected = true; } } -static void Init_Service_Handlers( - void) +static void Init_Service_Handlers(void) { Device_Init(NULL); /* we need to handle who-is @@ -130,29 +122,24 @@ static void Init_Service_Handlers( apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_I_AM, handler_i_am_bind); /* set the handler for all the services we don't implement It is required to send the proper reject message... */ - apdu_set_unrecognized_service_handler_handler - (handler_unrecognized_service); + apdu_set_unrecognized_service_handler_handler(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 requests */ apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_PRIVATE_TRANSFER, - handler_unconfirmed_private_transfer); + handler_unconfirmed_private_transfer); /* handle any errors coming back */ apdu_set_error_handler(SERVICE_CONFIRMED_READ_PROPERTY, MyErrorHandler); apdu_set_abort_handler(MyAbortHandler); apdu_set_reject_handler(MyRejectHandler); } -int main( - int argc, - char *argv[]) +int main(int argc, char *argv[]) { - BACNET_ADDRESS src = { - 0 - }; /* address where message came from */ + BACNET_ADDRESS src = {0}; /* address where message came from */ uint16_t pdu_len = 0; - unsigned timeout = 10; /* milliseconds */ + unsigned timeout = 10; /* milliseconds */ unsigned max_apdu = 0; time_t elapsed_seconds = 0; time_t last_seconds = 0; @@ -166,16 +153,19 @@ int main( int args_remaining = 0, tag_value_arg = 0, i = 0; BACNET_APPLICATION_TAG property_tag; uint8_t context_tag = 0; - BACNET_PRIVATE_TRANSFER_DATA private_data = { 0 }; + BACNET_PRIVATE_TRANSFER_DATA private_data = {0}; int len = 0; bool sent_message = false; if (argc < 6) { filename = filename_remove_path(argv[0]); - printf("Usage: %s vendor-id" - " service-number tag value [tag value...]\r\n", filename); + printf( + "Usage: %s vendor-id" + " service-number tag value [tag value...]\r\n", + filename); if ((argc > 1) && (strcmp(argv[1], "--help") == 0)) { - printf("device-instance:\r\n" + printf( + "device-instance:\r\n" "BACnet Device Object Instance number that you are\r\n" "trying to communicate to. This number will be used\r\n" "to try and bind with the device using Who-Is and\r\n" @@ -183,29 +173,43 @@ int main( "Device Object 123, the device-instance would be 123.\r\n" "For Global Broadcast, use the word 'broadcast'.\r\n" "For Local Broadcast to a particular DNET n, use 'dnet=n'.\r\n" - "\r\n" "vendor_id:\r\n" + "\r\n" + "vendor_id:\r\n" "the unique vendor identification code for the type of\r\n" - "vendor proprietary service to be performed.\r\n" "\r\n" + "vendor proprietary service to be performed.\r\n" + "\r\n" "service-number (Unsigned32):\r\n" - "the desired proprietary service to be performed.\r\n" "\r\n" - "tag:\r\n" "Tag is the integer value of the enumeration \r\n" + "the desired proprietary service to be performed.\r\n" + "\r\n" + "tag:\r\n" + "Tag is the integer value of the enumeration \r\n" "BACNET_APPLICATION_TAG in bacenum.h.\r\n" "It is the data type of the value that you are sending.\r\n" - "For example, if you were transfering a REAL value, you would \r\n" + "For example, if you were transfering a REAL value, you would " + "\r\n" "use a tag of 4.\r\n" "Context tags are created using two tags in a row.\r\n" "The context tag is preceded by a C. Ctag tag.\r\n" - "C2 4 creates a context 2 tagged REAL.\r\n" "\r\n" "value:\r\n" + "C2 4 creates a context 2 tagged REAL.\r\n" + "\r\n" + "value:\r\n" "The value is an ASCII representation of some type of data\r\n" "that you are transfering.\r\n" "It is encoded using the tag information provided.\r\n" - "For example, if you were transferring a REAL value of 100.0,\r\n" + "For example, if you were transferring a REAL value of " + "100.0,\r\n" "you would use 100.0 as the value.\r\n" - "If you were transferring an object identifier for Device 123,\r\n" - "you would use 8:123 as the value.\r\n" "\r\n" "Example:\r\n" - "If you want to transfer a REAL value of 1.1 to service 23 of \r\n" - "vendor 260 in Device 99, you could send the following command:\r\n" - "%s 99 260 23 4 1.1\r\n", filename); + "If you were transferring an object identifier for Device " + "123,\r\n" + "you would use 8:123 as the value.\r\n" + "\r\n" + "Example:\r\n" + "If you want to transfer a REAL value of 1.1 to service 23 of " + "\r\n" + "vendor 260 in Device 99, you could send the following " + "command:\r\n" + "%s 99 260 23 4 1.1\r\n", + filename); } return 0; } @@ -224,7 +228,7 @@ int main( if ((!Target_Broadcast) && (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); + Target_Device_Object_Instance, BACNET_MAX_INSTANCE); return 1; } args_remaining = (argc - (6 - 2)); @@ -252,12 +256,11 @@ int main( i, property_tag, i, value_string); */ if (property_tag >= MAX_BACNET_APPLICATION_TAG) { fprintf(stderr, "Error: tag=%u - it must be less than %u\r\n", - property_tag, MAX_BACNET_APPLICATION_TAG); + property_tag, MAX_BACNET_APPLICATION_TAG); return 1; } - status = - bacapp_parse_application_data(property_tag, value_string, - &Target_Object_Property_Value[i]); + status = bacapp_parse_application_data( + property_tag, value_string, &Target_Object_Property_Value[i]); if (!status) { /* FIXME: show the expected entry format for the tag */ fprintf(stderr, "Error: unable to parse the tag value\r\n"); @@ -274,7 +277,7 @@ int main( } if (args_remaining > 0) { fprintf(stderr, "Error: Exceeded %d tag-value pairs.\r\n", - MAX_PROPERTY_VALUES); + MAX_PROPERTY_VALUES); return 1; } /* setup my info */ @@ -293,12 +296,11 @@ int main( } else { timeout_seconds = (apdu_timeout() / 1000) * apdu_retries(); /* try to bind with the device */ - found = - address_bind_request(Target_Device_Object_Instance, &max_apdu, - &Target_Address); + found = address_bind_request(Target_Device_Object_Instance, &max_apdu, + &Target_Address); if (!found) { Send_WhoIs(Target_Device_Object_Instance, - Target_Device_Object_Instance); + Target_Device_Object_Instance); } } /* loop forever */ @@ -316,25 +318,22 @@ int main( break; /* wait until the device is bound, or timeout and quit */ if (!found) { - found = - address_bind_request(Target_Device_Object_Instance, &max_apdu, - &Target_Address); + found = address_bind_request(Target_Device_Object_Instance, + &max_apdu, &Target_Address); } if (!sent_message) { if (found) { - len = - bacapp_encode_data(&Service_Parameters[0], - &Target_Object_Property_Value[0]); + len = bacapp_encode_data(&Service_Parameters[0], + &Target_Object_Property_Value[0]); private_data.serviceParameters = &Service_Parameters[0]; private_data.serviceParametersLen = len; private_data.vendorID = Target_Vendor_Identifier; private_data.serviceNumber = Target_Service_Number; - Send_UnconfirmedPrivateTransfer(&Target_Address, - &private_data); + Send_UnconfirmedPrivateTransfer(&Target_Address, &private_data); printf("Sent PrivateTransfer."); if (timeout_seconds) { printf(" Waiting %u seconds.\r\n", - (unsigned) (timeout_seconds - elapsed_seconds)); + (unsigned)(timeout_seconds - elapsed_seconds)); } else { printf("\r\n"); } diff --git a/demo/whohas/main.c b/demo/whohas/main.c index 735c0f8e..8f9ca51c 100644 --- a/demo/whohas/main.c +++ b/demo/whohas/main.c @@ -1,34 +1,34 @@ /************************************************************************** -* -* Copyright (C) 2006 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2006 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* command line tool that sends a BACnet service, and displays the reply */ #include #include #include #include -#include /* for time */ +#include /* for time */ #include #include "bactext.h" #include "iam.h" @@ -51,7 +51,7 @@ #include "dlenv.h" /* buffer used for receive */ -static uint8_t Rx_Buf[MAX_MPDU] = { 0 }; +static uint8_t Rx_Buf[MAX_MPDU] = {0}; /* global variables used in this file */ static BACNET_OBJECT_TYPE Target_Object_Type = MAX_BACNET_OBJECT_TYPE; @@ -62,34 +62,28 @@ static int32_t Target_Object_Instance_Max = -1; static bool Error_Detected = false; -void MyAbortHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t abort_reason, - bool server) +void MyAbortHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t abort_reason, bool server) { /* FIXME: verify src and invoke id */ - (void) src; - (void) invoke_id; - (void) server; + (void)src; + (void)invoke_id; + (void)server; printf("BACnet Abort: %s\r\n", bactext_abort_reason_name(abort_reason)); Error_Detected = true; } -void MyRejectHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t reject_reason) +void MyRejectHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t reject_reason) { /* FIXME: verify src and invoke id */ - (void) src; - (void) invoke_id; + (void)src; + (void)invoke_id; printf("BACnet Reject: %s\r\n", bactext_reject_reason_name(reject_reason)); Error_Detected = true; } -static void Init_Service_Handlers( - void) +static void Init_Service_Handlers(void) { Device_Init(NULL); /* we need to handle who-is @@ -97,11 +91,10 @@ static void Init_Service_Handlers( apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, handler_who_is); /* set the handler for all the services we don't implement It is required to send the proper reject message... */ - apdu_set_unrecognized_service_handler_handler - (handler_unrecognized_service); + apdu_set_unrecognized_service_handler_handler(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 reply (request) coming back */ apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_I_HAVE, handler_i_have); /* handle any errors coming back */ @@ -109,36 +102,36 @@ static void Init_Service_Handlers( apdu_set_reject_handler(MyRejectHandler); } -static void print_usage( - char *filename) +static void print_usage(char *filename) { - printf("Usage: %s [device-instance-min device-instance-min] " - " [--help]\r\n", filename); + printf( + "Usage: %s [device-instance-min device-instance-min] " + " [--help]\r\n", + filename); } -static void print_help( - char *filename) +static void print_help(char *filename) { print_usage(filename); - printf("Send BACnet WhoHas request to devices, \r\n" + printf( + "Send BACnet WhoHas request to devices, \r\n" "and wait %u milliseconds (BACNET_APDU_TIMEOUT) for responses.\r\n" - "The device-instance-min or max can be 0 to %d.\r\n" "\r\n" - "Use either:\r\n" "The object-type can be 0 to %d.\r\n" - "The object-instance can be 0 to %d.\r\n" "or:\r\n" + "The device-instance-min or max can be 0 to %d.\r\n" + "\r\n" + "Use either:\r\n" + "The object-type can be 0 to %d.\r\n" + "The object-instance can be 0 to %d.\r\n" + "or:\r\n" "The object-name can be any string of characters.\r\n", - BACNET_MAX_INSTANCE, (unsigned) apdu_timeout(), BACNET_MAX_OBJECT, + BACNET_MAX_INSTANCE, (unsigned)apdu_timeout(), BACNET_MAX_OBJECT, BACNET_MAX_INSTANCE); } -int main( - int argc, - char *argv[]) +int main(int argc, char *argv[]) { - BACNET_ADDRESS src = { - 0 - }; /* address where message came from */ + BACNET_ADDRESS src = {0}; /* address where message came from */ uint16_t pdu_len = 0; - unsigned timeout = 100; /* milliseconds */ + unsigned timeout = 100; /* milliseconds */ time_t elapsed_seconds = 0; time_t last_seconds = 0; time_t current_seconds = 0; @@ -188,7 +181,7 @@ int main( if (Target_Object_Name) { if (Target_Object_Name[0] == 0) { fprintf(stderr, - "object-name must be at least 1 character.\r\n"); + "object-name must be at least 1 character.\r\n"); return 1; } } else { @@ -198,23 +191,23 @@ int main( } else { if (Target_Object_Instance > BACNET_MAX_INSTANCE) { fprintf(stderr, "object-instance=%u - it must be less than %u\r\n", - Target_Object_Instance, BACNET_MAX_INSTANCE + 1); + Target_Object_Instance, BACNET_MAX_INSTANCE + 1); return 1; } if (Target_Object_Type > BACNET_MAX_OBJECT) { fprintf(stderr, "object-type=%u - it must be less than %u\r\n", - Target_Object_Type, BACNET_MAX_OBJECT + 1); + Target_Object_Type, BACNET_MAX_OBJECT + 1); return 1; } } if (Target_Object_Instance_Min > BACNET_MAX_INSTANCE) { fprintf(stderr, "object-instance-min=%u - it must be less than %u\r\n", - Target_Object_Instance_Min, BACNET_MAX_INSTANCE + 1); + Target_Object_Instance_Min, BACNET_MAX_INSTANCE + 1); return 1; } if (Target_Object_Instance_Max > BACNET_MAX_INSTANCE) { fprintf(stderr, "object-instance-max=%u - it must be less than %u\r\n", - Target_Object_Instance_Max, BACNET_MAX_INSTANCE + 1); + Target_Object_Instance_Max, BACNET_MAX_INSTANCE + 1); return 1; } /* setup my info */ @@ -227,12 +220,12 @@ int main( timeout_seconds = apdu_timeout() / 1000; /* send the request */ if (by_name) { - Send_WhoHas_Name(Target_Object_Instance_Min, - Target_Object_Instance_Max, Target_Object_Name); + Send_WhoHas_Name(Target_Object_Instance_Min, Target_Object_Instance_Max, + Target_Object_Name); } else { Send_WhoHas_Object(Target_Object_Instance_Min, - Target_Object_Instance_Max, Target_Object_Type, - Target_Object_Instance); + Target_Object_Instance_Max, Target_Object_Type, + Target_Object_Instance); } /* loop forever */ for (;;) { diff --git a/demo/whois/main.c b/demo/whois/main.c index 85de2533..08b22f91 100644 --- a/demo/whois/main.c +++ b/demo/whois/main.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2006 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2006 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* command line tool that sends a BACnet service, and displays the reply */ #include @@ -29,7 +29,7 @@ #include #include #include -#include /* for time */ +#include /* for time */ #include #include "bactext.h" #include "iam.h" @@ -54,7 +54,7 @@ #include "net.h" /* buffer used for receive */ -static uint8_t Rx_Buf[MAX_MPDU] = { 0 }; +static uint8_t Rx_Buf[MAX_MPDU] = {0}; /* global variables used in this file */ static int32_t Target_Object_Instance_Min = -1; @@ -74,15 +74,12 @@ struct address_entry { static struct address_table { struct address_entry *first; struct address_entry *last; -} Address_Table = { -0}; +} Address_Table = {0}; - -struct address_entry *alloc_address_entry( - void) +struct address_entry *alloc_address_entry(void) { struct address_entry *rval; - rval = (struct address_entry *) calloc(1, sizeof(struct address_entry)); + rval = (struct address_entry *)calloc(1, sizeof(struct address_entry)); if (Address_Table.first == 0) { Address_Table.first = Address_Table.last = rval; } else { @@ -92,11 +89,7 @@ struct address_entry *alloc_address_entry( return rval; } - - -bool bacnet_address_matches( - BACNET_ADDRESS * a1, - BACNET_ADDRESS * a2) +bool bacnet_address_matches(BACNET_ADDRESS *a1, BACNET_ADDRESS *a2) { int i = 0; if (a1->net != a2->net) @@ -109,10 +102,8 @@ bool bacnet_address_matches( return true; } -void address_table_add( - uint32_t device_id, - unsigned max_apdu, - BACNET_ADDRESS * src) +void address_table_add(uint32_t device_id, unsigned max_apdu, + BACNET_ADDRESS *src) { struct address_entry *pMatch; uint8_t flags = 0; @@ -138,12 +129,8 @@ void address_table_add( return; } - - -void my_i_am_handler( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src) +void my_i_am_handler(uint8_t *service_request, uint16_t service_len, + BACNET_ADDRESS *src) { int len = 0; uint32_t device_id = 0; @@ -152,25 +139,24 @@ void my_i_am_handler( uint16_t vendor_id = 0; unsigned i = 0; - (void) service_len; - len = - iam_decode_service_request(service_request, &device_id, &max_apdu, - &segmentation, &vendor_id); + (void)service_len; + len = iam_decode_service_request(service_request, &device_id, &max_apdu, + &segmentation, &vendor_id); #if PRINT_ENABLED fprintf(stderr, "Received I-Am Request"); #endif if (len != -1) { #if PRINT_ENABLED - fprintf(stderr, " from %lu, MAC = ", (unsigned long) device_id); + fprintf(stderr, " from %lu, MAC = ", (unsigned long)device_id); if ((src->mac_len == 6) && (src->len == 0)) { - fprintf(stderr, "%u.%u.%u.%u %02X%02X\n", - (unsigned)src->mac[0], (unsigned)src->mac[1], - (unsigned)src->mac[2], (unsigned)src->mac[3], - (unsigned)src->mac[4], (unsigned)src->mac[5]); + fprintf(stderr, "%u.%u.%u.%u %02X%02X\n", (unsigned)src->mac[0], + (unsigned)src->mac[1], (unsigned)src->mac[2], + (unsigned)src->mac[3], (unsigned)src->mac[4], + (unsigned)src->mac[5]); } else { for (i = 0; i < src->mac_len; i++) { fprintf(stderr, "%02X", (unsigned)src->mac[i]); - if (i < (src->mac_len-1)) { + if (i < (src->mac_len - 1)) { fprintf(stderr, ":"); } } @@ -187,47 +173,40 @@ void my_i_am_handler( return; } -void MyAbortHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t abort_reason, - bool server) +void MyAbortHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t abort_reason, bool server) { /* FIXME: verify src and invoke id */ - (void) src; - (void) invoke_id; - (void) server; + (void)src; + (void)invoke_id; + (void)server; fprintf(stderr, "BACnet Abort: %s\n", - bactext_abort_reason_name(abort_reason)); + bactext_abort_reason_name(abort_reason)); Error_Detected = true; } -void MyRejectHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t reject_reason) +void MyRejectHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t reject_reason) { /* FIXME: verify src and invoke id */ - (void) src; - (void) invoke_id; + (void)src; + (void)invoke_id; fprintf(stderr, "BACnet Reject: %s\n", - bactext_reject_reason_name(reject_reason)); + bactext_reject_reason_name(reject_reason)); Error_Detected = true; } -static void init_service_handlers( - void) +static void init_service_handlers(void) { Device_Init(NULL); /* Note: this applications doesn't need to handle who-is it is confusing for the user! */ /* set the handler for all the services we don't implement It is required to send the proper reject message... */ - apdu_set_unrecognized_service_handler_handler - (handler_unrecognized_service); + apdu_set_unrecognized_service_handler_handler(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 reply (request) coming back */ apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_I_AM, my_i_am_handler); /* handle any errors coming back */ @@ -235,9 +214,7 @@ static void init_service_handlers( apdu_set_reject_handler(MyRejectHandler); } -void print_macaddr( - uint8_t * addr, - int len) +void print_macaddr(uint8_t *addr, int len) { int j = 0; @@ -254,8 +231,7 @@ void print_macaddr( } } -static void print_address_cache( - void) +static void print_address_cache(void) { BACNET_ADDRESS address; unsigned total_addresses = 0; @@ -267,10 +243,9 @@ static void print_address_cache( so these must be compatible. */ printf(";%-7s %-20s %-5s %-20s %-4s\n", "Device", "MAC (hex)", "SNET", - "SADR (hex)", "APDU"); + "SADR (hex)", "APDU"); printf(";-------- -------------------- ----- -------------------- ----\n"); - addr = Address_Table.first; while (addr) { bacnet_address_copy(&address, &addr->address); @@ -300,8 +275,7 @@ static void print_address_cache( } } -static void print_usage( - char *filename) +static void print_usage(char *filename) { printf("Usage: %s", filename); printf(" [device-instance-min [device-instance-max]]\n"); @@ -309,10 +283,10 @@ static void print_usage( printf(" [--version][--help]\n"); } -static void print_help( - char *filename) +static void print_help(char *filename) { - printf("Send BACnet WhoIs service request to a device or multiple\n" + printf( + "Send BACnet WhoIs service request to a device or multiple\n" "devices, and wait for responses. Displays any devices found\n" "and their network information.\n" "\n" @@ -322,7 +296,8 @@ static void print_help( "the range of 0 to 4194303. A range of values can also be\n" "specified by using a minimum value and a maximum value.\n" "\n"); - printf("--mac A\n" + printf( + "--mac A\n" "BACnet mac address." "Valid ranges are from 00 to FF (hex) for MS/TP or ARCNET,\n" "or an IP string with optional port number like 10.1.2.3:47808\n" @@ -339,40 +314,50 @@ static void print_help( "or an IP string with optional port number like 10.1.2.3:47808\n" "or an Ethernet MAC in hex like 00:21:70:7e:32:bb\n" "\n"); - printf("Send a WhoIs request to DNET 123:\n" - "%s --dnet 123\n", filename); - printf("Send a WhoIs request to MAC 10.0.0.1 DNET 123 DADR 05h:\n" - "%s --mac 10.0.0.1 --dnet 123 --dadr 05\n", filename); - printf("Send a WhoIs request to MAC 10.1.2.3:47808:\n" - "%s --mac 10.1.2.3:47808\n", filename); - printf("Send a WhoIs request to Device 123:\n" - "%s 123\n", filename); - printf("Send a WhoIs request to Devices from 1000 to 9000:\n" - "%s 1000 9000\n", filename); - printf("Send a WhoIs request to Devices from 1000 to 9000 on DNET 123:\n" - "%s 1000 9000 --dnet 123\n", filename); - printf("Send a WhoIs request to all devices:\n" - "%s\n", filename); + printf( + "Send a WhoIs request to DNET 123:\n" + "%s --dnet 123\n", + filename); + printf( + "Send a WhoIs request to MAC 10.0.0.1 DNET 123 DADR 05h:\n" + "%s --mac 10.0.0.1 --dnet 123 --dadr 05\n", + filename); + printf( + "Send a WhoIs request to MAC 10.1.2.3:47808:\n" + "%s --mac 10.1.2.3:47808\n", + filename); + printf( + "Send a WhoIs request to Device 123:\n" + "%s 123\n", + filename); + printf( + "Send a WhoIs request to Devices from 1000 to 9000:\n" + "%s 1000 9000\n", + filename); + printf( + "Send a WhoIs request to Devices from 1000 to 9000 on DNET 123:\n" + "%s 1000 9000 --dnet 123\n", + filename); + printf( + "Send a WhoIs request to all devices:\n" + "%s\n", + filename); } -int main( - int argc, - char *argv[]) +int main(int argc, char *argv[]) { - BACNET_ADDRESS src = { - 0 - }; /* address where message came from */ + BACNET_ADDRESS src = {0}; /* address where message came from */ uint16_t pdu_len = 0; - unsigned timeout = 100; /* milliseconds */ + unsigned timeout = 100; /* milliseconds */ time_t total_seconds = 0; time_t elapsed_seconds = 0; time_t last_seconds = 0; time_t current_seconds = 0; time_t timeout_seconds = 0; long dnet = -1; - BACNET_MAC_ADDRESS mac = { 0 }; - BACNET_MAC_ADDRESS adr = { 0 }; - BACNET_ADDRESS dest = { 0 }; + BACNET_MAC_ADDRESS mac = {0}; + BACNET_MAC_ADDRESS adr = {0}; + BACNET_ADDRESS dest = {0}; bool global_broadcast = true; int argi = 0; unsigned int target_args = 0; @@ -388,8 +373,10 @@ int main( } if (strcmp(argv[argi], "--version") == 0) { printf("%s %s\n", filename, BACNET_VERSION_TEXT); - printf("Copyright (C) 2014 by Steve Karg and others.\n" - "This is free software; see the source for copying conditions.\n" + printf( + "Copyright (C) 2014 by Steve Karg and others.\n" + "This is free software; see the source for copying " + "conditions.\n" "There is NO warranty; not even for MERCHANTABILITY or\n" "FITNESS FOR A PARTICULAR PURPOSE.\n"); return 0; @@ -461,12 +448,12 @@ int main( } if (Target_Object_Instance_Min > BACNET_MAX_INSTANCE) { fprintf(stderr, "device-instance-min=%u - it must be less than %u\n", - Target_Object_Instance_Min, BACNET_MAX_INSTANCE + 1); + Target_Object_Instance_Min, BACNET_MAX_INSTANCE + 1); return 1; } if (Target_Object_Instance_Max > BACNET_MAX_INSTANCE) { fprintf(stderr, "device-instance-max=%u - it must be less than %u\n", - Target_Object_Instance_Max, BACNET_MAX_INSTANCE + 1); + Target_Object_Instance_Max, BACNET_MAX_INSTANCE + 1); return 1; } /* setup my info */ @@ -480,7 +467,7 @@ int main( timeout_seconds = apdu_timeout() / 1000; /* send the request */ Send_WhoIs_To_Network(&dest, Target_Object_Instance_Min, - Target_Object_Instance_Max); + Target_Object_Instance_Max); /* loop forever */ for (;;) { /* increment timer - exit if timed out */ diff --git a/demo/whoisrouter/main.c b/demo/whoisrouter/main.c index b5fce8d6..d9c34e96 100644 --- a/demo/whoisrouter/main.c +++ b/demo/whoisrouter/main.c @@ -1,34 +1,34 @@ /************************************************************************** -* -* Copyright (C) 2008 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2008 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* command line tool that sends a BACnet service, and displays the reply */ #include #include #include #include -#include /* for time */ +#include /* for time */ #include #include "bactext.h" #include "iam.h" @@ -54,7 +54,7 @@ #include "dlenv.h" /* buffer used for receive */ -static uint8_t Rx_Buf[MAX_MPDU] = { 0 }; +static uint8_t Rx_Buf[MAX_MPDU] = {0}; /* global variables used in this file */ static int32_t Target_Router_Network = 0; @@ -62,37 +62,30 @@ static BACNET_ADDRESS Target_Router_Address; static bool Error_Detected = false; -static void MyAbortHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t abort_reason, - bool server) +static void MyAbortHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t abort_reason, bool server) { /* FIXME: verify src and invoke id */ - (void) src; - (void) invoke_id; - (void) server; + (void)src; + (void)invoke_id; + (void)server; printf("BACnet Abort: %s\r\n", bactext_abort_reason_name(abort_reason)); Error_Detected = true; } -static void MyRejectHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t reject_reason) +static void MyRejectHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t reject_reason) { /* FIXME: verify src and invoke id */ - (void) src; - (void) invoke_id; + (void)src; + (void)invoke_id; printf("BACnet Reject: %s\r\n", bactext_reject_reason_name(reject_reason)); Error_Detected = true; } -static void My_Router_Handler( - BACNET_ADDRESS * src, - BACNET_NPDU_DATA * npdu_data, - uint8_t * npdu, /* PDU data */ - uint16_t npdu_len) +static void My_Router_Handler(BACNET_ADDRESS *src, BACNET_NPDU_DATA *npdu_data, + uint8_t *npdu, /* PDU data */ + uint16_t npdu_len) { uint16_t npdu_offset = 0; uint16_t dnet = 0; @@ -137,19 +130,18 @@ static void My_Router_Handler( } } -void My_NPDU_Handler( - BACNET_ADDRESS * src, /* source address */ - uint8_t * pdu, /* PDU data */ - uint16_t pdu_len) -{ /* length PDU */ +void My_NPDU_Handler(BACNET_ADDRESS *src, /* source address */ + uint8_t *pdu, /* PDU data */ + uint16_t pdu_len) +{ /* length PDU */ int apdu_offset = 0; - BACNET_ADDRESS dest = { 0 }; - BACNET_NPDU_DATA npdu_data = { 0 }; + BACNET_ADDRESS dest = {0}; + BACNET_NPDU_DATA npdu_data = {0}; apdu_offset = npdu_decode(&pdu[0], &dest, src, &npdu_data); if (npdu_data.network_layer_message) { My_Router_Handler(src, &npdu_data, &pdu[apdu_offset], - (uint16_t) (pdu_len - apdu_offset)); + (uint16_t)(pdu_len - apdu_offset)); } else if ((apdu_offset > 0) && (apdu_offset <= pdu_len)) { if ((npdu_data.protocol_version == BACNET_PROTOCOL_VERSION) && ((dest.net == 0) || (dest.net == BACNET_BROADCAST_NETWORK))) { @@ -157,13 +149,13 @@ void My_NPDU_Handler( /* and we are not a router, so ignore messages with routing information cause they are not for us */ apdu_handler(src, &pdu[apdu_offset], - (uint16_t) (pdu_len - apdu_offset)); + (uint16_t)(pdu_len - apdu_offset)); } else { if (dest.net) { debug_printf("NPDU: DNET=%d. Discarded!\n", dest.net); } else { debug_printf("NPDU: BACnet Protocol Version=%d. Discarded!\n", - npdu_data.protocol_version); + npdu_data.protocol_version); } } } @@ -171,8 +163,7 @@ void My_NPDU_Handler( return; } -static void Init_Service_Handlers( - void) +static void Init_Service_Handlers(void) { Device_Init(NULL); /* we need to handle who-is @@ -180,11 +171,10 @@ static void Init_Service_Handlers( apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_WHO_IS, handler_who_is); /* set the handler for all the services we don't implement It is required to send the proper reject message... */ - apdu_set_unrecognized_service_handler_handler - (handler_unrecognized_service); + apdu_set_unrecognized_service_handler_handler(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 reply (request) coming back */ apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_I_AM, handler_i_am_add); /* handle any errors coming back */ @@ -192,11 +182,7 @@ static void Init_Service_Handlers( apdu_set_reject_handler(MyRejectHandler); } - -static void address_parse( - BACNET_ADDRESS * dst, - int argc, - char *argv[]) +static void address_parse(BACNET_ADDRESS *dst, int argc, char *argv[]) { int dnet = 0; unsigned mac[6]; @@ -204,9 +190,8 @@ static void address_parse( int index = 0; if (argc > 0) { - count = - sscanf(argv[0], "%x:%x:%x:%x:%x:%x", &mac[0], &mac[1], &mac[2], - &mac[3], &mac[4], &mac[5]); + count = sscanf(argv[0], "%x:%x:%x:%x:%x:%x", &mac[0], &mac[1], &mac[2], + &mac[3], &mac[4], &mac[5]); dst->mac_len = count; for (index = 0; index < MAX_MAC_LEN; index++) { if (index < count) { @@ -222,9 +207,8 @@ static void address_parse( } if (dnet) { if (argc > 2) { - count = - sscanf(argv[2], "%x:%x:%x:%x:%x:%x", &mac[0], &mac[1], &mac[2], - &mac[3], &mac[4], &mac[5]); + count = sscanf(argv[2], "%x:%x:%x:%x:%x:%x", &mac[0], &mac[1], + &mac[2], &mac[3], &mac[4], &mac[5]); dst->len = count; for (index = 0; index < MAX_MAC_LEN; index++) { if (index < count) { @@ -244,15 +228,11 @@ static void address_parse( } } -int main( - int argc, - char *argv[]) +int main(int argc, char *argv[]) { - BACNET_ADDRESS src = { - 0 - }; /* address where message came from */ + BACNET_ADDRESS src = {0}; /* address where message came from */ uint16_t pdu_len = 0; - unsigned timeout = 100; /* milliseconds */ + unsigned timeout = 100; /* milliseconds */ time_t total_seconds = 0; time_t elapsed_seconds = 0; time_t last_seconds = 0; @@ -264,17 +244,22 @@ int main( return 0; } if ((argc > 1) && (strcmp(argv[1], "--help") == 0)) { - printf("Send BACnet Who-Is-Router-To-Network message to a network.\r\n" - "\r\n" "DNET:\r\n" "BACnet destination network number 0-65535\r\n" + printf( + "Send BACnet Who-Is-Router-To-Network message to a network.\r\n" + "\r\n" + "DNET:\r\n" + "BACnet destination network number 0-65535\r\n" "To omit the BACnet destination network number, use -1.\r\n" - "MAC:\r\n" "Optional MAC address of router for unicast message\r\n" + "MAC:\r\n" + "Optional MAC address of router for unicast message\r\n" "Format: xx[:xx:xx:xx:xx:xx] [dnet xx[:xx:xx:xx:xx:xx]]\r\n" - "Use hexidecimal MAC addresses.\r\n" "\r\n" + "Use hexidecimal MAC addresses.\r\n" + "\r\n" "To send a Who-Is-Router-To-Network request to DNET 86:\r\n" "%s 86\r\n" "To send a Who-Is-Router-To-Network request to all devices:\r\n" - "%s -1\r\n", filename_remove_path(argv[0]), - filename_remove_path(argv[0])); + "%s -1\r\n", + filename_remove_path(argv[0]), filename_remove_path(argv[0])); return 0; } /* decode the command line parameters */ @@ -282,7 +267,7 @@ int main( Target_Router_Network = strtol(argv[1], NULL, 0); if (Target_Router_Network > 65535) { fprintf(stderr, "DNET=%u - it must be 0 to 65535\r\n", - Target_Router_Network); + Target_Router_Network); return 1; } } @@ -302,7 +287,7 @@ int main( timeout_seconds = apdu_timeout() / 1000; /* send the request */ Send_Who_Is_Router_To_Network(&Target_Router_Address, - Target_Router_Network); + Target_Router_Network); /* loop forever */ for (;;) { /* increment timer - exit if timed out */ diff --git a/demo/writefile/main.c b/demo/writefile/main.c index 9a0c096a..e2ff85fe 100644 --- a/demo/writefile/main.c +++ b/demo/writefile/main.c @@ -1,34 +1,34 @@ /************************************************************************** -* -* Copyright (C) 2006 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2006 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* command line tool that sends a BACnet service, and displays the reply */ #include #include #include #include -#include /* for time */ +#include /* for time */ #include #include "bactext.h" #include "iam.h" @@ -51,7 +51,7 @@ #include "dlenv.h" /* buffer used for receive */ -static uint8_t Rx_Buf[MAX_MPDU] = { 0 }; +static uint8_t Rx_Buf[MAX_MPDU] = {0}; /* global variables used in this file */ static uint32_t Target_File_Object_Instance = 4194303; @@ -64,11 +64,10 @@ static bool End_Of_File_Detected = false; static bool Error_Detected = false; static uint8_t Current_Invoke_ID = 0; -static void Atomic_Write_File_Error_Handler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - BACNET_ERROR_CLASS error_class, - BACNET_ERROR_CODE error_code) +static void Atomic_Write_File_Error_Handler(BACNET_ADDRESS *src, + uint8_t invoke_id, + BACNET_ERROR_CLASS error_class, + BACNET_ERROR_CODE error_code) { if (address_match(&Target_Address, src) && (invoke_id == Current_Invoke_ID)) { @@ -79,38 +78,31 @@ static void Atomic_Write_File_Error_Handler( } } -void MyAbortHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t abort_reason, - bool server) +void MyAbortHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t abort_reason, bool server) { - (void) server; + (void)server; if (address_match(&Target_Address, src) && (invoke_id == Current_Invoke_ID)) { printf("BACnet Abort: %s\r\n", - bactext_abort_reason_name((int) abort_reason)); + bactext_abort_reason_name((int)abort_reason)); Error_Detected = true; } } -void MyRejectHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t reject_reason) +void MyRejectHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t reject_reason) { if (address_match(&Target_Address, src) && (invoke_id == Current_Invoke_ID)) { printf("BACnet Reject: %s\r\n", - bactext_reject_reason_name((int) reject_reason)); + bactext_reject_reason_name((int)reject_reason)); Error_Detected = true; } } -static void LocalIAmHandler( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src) +static void LocalIAmHandler(uint8_t *service_request, uint16_t service_len, + BACNET_ADDRESS *src) { int len = 0; uint32_t device_id = 0; @@ -118,11 +110,10 @@ static void LocalIAmHandler( int segmentation = 0; uint16_t vendor_id = 0; - (void) src; - (void) service_len; - len = - iam_decode_service_request(service_request, &device_id, &max_apdu, - &segmentation, &vendor_id); + (void)src; + (void)service_len; + len = iam_decode_service_request(service_request, &device_id, &max_apdu, + &segmentation, &vendor_id); if (len != -1) { address_add(device_id, max_apdu, src); } else @@ -131,8 +122,7 @@ static void LocalIAmHandler( return; } -static void Init_Service_Handlers( - void) +static void Init_Service_Handlers(void) { Device_Init(NULL); /* we need to handle who-is @@ -142,27 +132,22 @@ static void Init_Service_Handlers( apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_I_AM, LocalIAmHandler); /* set the handler for all the services we don't implement It is required to send the proper reject message... */ - apdu_set_unrecognized_service_handler_handler - (handler_unrecognized_service); + apdu_set_unrecognized_service_handler_handler(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 any errors coming back */ apdu_set_error_handler(SERVICE_CONFIRMED_ATOMIC_WRITE_FILE, - Atomic_Write_File_Error_Handler); + Atomic_Write_File_Error_Handler); apdu_set_abort_handler(MyAbortHandler); apdu_set_reject_handler(MyRejectHandler); } -int main( - int argc, - char *argv[]) +int main(int argc, char *argv[]) { - BACNET_ADDRESS src = { - 0 - }; /* address where message came from */ + BACNET_ADDRESS src = {0}; /* address where message came from */ uint16_t pdu_len = 0; - unsigned timeout = 100; /* milliseconds */ + unsigned timeout = 100; /* milliseconds */ unsigned max_apdu = 0; time_t elapsed_seconds = 0; time_t last_seconds = 0; @@ -180,8 +165,9 @@ int main( if (argc < 4) { /* FIXME: what about access method - record or stream? */ - printf - ("%s device-instance file-instance local-name [octet count] [pad value]\r\n", + printf( + "%s device-instance file-instance local-name [octet count] [pad " + "value]\r\n", filename_remove_path(argv[0])); return 0; } @@ -191,12 +177,12 @@ int main( Local_File_Name = argv[3]; 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); + Target_Device_Object_Instance, BACNET_MAX_INSTANCE); return 1; } if (Target_File_Object_Instance >= BACNET_MAX_INSTANCE) { fprintf(stderr, "file-instance=%u - it must be less than %u\r\n", - Target_File_Object_Instance, BACNET_MAX_INSTANCE + 1); + Target_File_Object_Instance, BACNET_MAX_INSTANCE + 1); return 1; } if (argc > 4) { @@ -216,12 +202,11 @@ int main( last_seconds = time(NULL); timeout_seconds = (apdu_timeout() / 1000) * apdu_retries(); /* try to bind with the device */ - found = - address_bind_request(Target_Device_Object_Instance, &max_apdu, - &Target_Address); + found = address_bind_request(Target_Device_Object_Instance, &max_apdu, + &Target_Address); if (!found) { Send_WhoIs(Target_Device_Object_Instance, - Target_Device_Object_Instance); + Target_Device_Object_Instance); } /* loop forever */ for (;;) { @@ -241,17 +226,16 @@ int main( } /* wait until the device is bound, or timeout and quit */ if (!found) { - found = - address_bind_request(Target_Device_Object_Instance, &max_apdu, - &Target_Address); + found = address_bind_request(Target_Device_Object_Instance, + &max_apdu, &Target_Address); } if (found) { if (Target_File_Requested_Octet_Count) { requestedOctetCount = Target_File_Requested_Octet_Count; } else { /* calculate the smaller of our APDU size or theirs - and remove the overhead of the APDU (varies depending on size). - note: we could fail if there is a bottle neck (router) + and remove the overhead of the APDU (varies depending on + size). note: we could fail if there is a bottle neck (router) and smaller MPDU in betweeen. */ if (max_apdu < MAX_APDU) { my_max_apdu = max_apdu; @@ -283,16 +267,15 @@ int main( less than max_apdu to keep unsegmented */ pFile = fopen(Local_File_Name, "rb"); if (pFile) { - (void) fseek(pFile, fileStartPosition, SEEK_SET); - len = - fread(octetstring_value(&fileData), 1, - requestedOctetCount, pFile); + (void)fseek(pFile, fileStartPosition, SEEK_SET); + len = fread(octetstring_value(&fileData), 1, + requestedOctetCount, pFile); if (len < requestedOctetCount) { End_Of_File_Detected = true; if (pad_byte) { memset(octetstring_value(&fileData) + len + 1, - (int) Target_File_Requested_Octet_Pad_Byte, - requestedOctetCount - len); + (int)Target_File_Requested_Octet_Pad_Byte, + requestedOctetCount - len); len = requestedOctetCount; } } @@ -302,10 +285,9 @@ int main( End_Of_File_Detected = true; } printf("\rSending %d bytes", (int)(fileStartPosition + len)); - invoke_id = - Send_Atomic_Write_File_Stream - (Target_Device_Object_Instance, - Target_File_Object_Instance, fileStartPosition, &fileData); + invoke_id = Send_Atomic_Write_File_Stream( + Target_Device_Object_Instance, Target_File_Object_Instance, + fileStartPosition, &fileData); Current_Invoke_ID = invoke_id; } else if (tsm_invoke_id_failed(invoke_id)) { fprintf(stderr, "\rError: TSM Timeout!\r\n"); diff --git a/demo/writeprop/main.c b/demo/writeprop/main.c index 4447cb52..69f61a41 100644 --- a/demo/writeprop/main.c +++ b/demo/writeprop/main.c @@ -1,37 +1,37 @@ /************************************************************************** -* -* Copyright (C) 2006-2007 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2006-2007 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* command line tool that sends a BACnet service, and displays the response */ #include #include #include #include -#include /* for time */ +#include /* for time */ #include #include -#include /* toupper */ +#include /* toupper */ #include "bactext.h" #include "iam.h" #include "arf.h" @@ -58,7 +58,7 @@ #endif /* buffer used for receive */ -static uint8_t Rx_Buf[MAX_MPDU] = { 0 }; +static uint8_t Rx_Buf[MAX_MPDU] = {0}; /* global variables used in this file */ static uint32_t Target_Device_Object_Instance = BACNET_MAX_INSTANCE; @@ -79,52 +79,43 @@ static BACNET_ADDRESS Target_Address; /* needed for return value of main application */ static bool Error_Detected = false; -static void MyErrorHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - BACNET_ERROR_CLASS error_class, - BACNET_ERROR_CODE error_code) +static void MyErrorHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + BACNET_ERROR_CLASS error_class, + BACNET_ERROR_CODE error_code) { if (address_match(&Target_Address, src) && (invoke_id == Request_Invoke_ID)) { printf("BACnet Error: %s: %s\n", - bactext_error_class_name((int) error_class), - bactext_error_code_name((int) error_code)); + bactext_error_class_name((int)error_class), + bactext_error_code_name((int)error_code)); Error_Detected = true; } } -void MyAbortHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t abort_reason, - bool server) +void MyAbortHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t abort_reason, bool server) { - (void) server; + (void)server; if (address_match(&Target_Address, src) && (invoke_id == Request_Invoke_ID)) { printf("BACnet Abort: %s\n", - bactext_abort_reason_name((int) abort_reason)); + bactext_abort_reason_name((int)abort_reason)); Error_Detected = true; } } -void MyRejectHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t reject_reason) +void MyRejectHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t reject_reason) { if (address_match(&Target_Address, src) && (invoke_id == Request_Invoke_ID)) { printf("BACnet Reject: %s\n", - bactext_reject_reason_name((int) reject_reason)); + bactext_reject_reason_name((int)reject_reason)); Error_Detected = true; } } -void MyWritePropertySimpleAckHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id) +void MyWritePropertySimpleAckHandler(BACNET_ADDRESS *src, uint8_t invoke_id) { if (address_match(&Target_Address, src) && (invoke_id == Request_Invoke_ID)) { @@ -132,8 +123,7 @@ void MyWritePropertySimpleAckHandler( } } -static void Init_Service_Handlers( - void) +static void Init_Service_Handlers(void) { Device_Init(NULL); /* we need to handle who-is @@ -143,14 +133,13 @@ static void Init_Service_Handlers( apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_I_AM, handler_i_am_bind); /* set the handler for all the services we don't implement It is required to send the proper reject message... */ - apdu_set_unrecognized_service_handler_handler - (handler_unrecognized_service); + apdu_set_unrecognized_service_handler_handler(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 ack coming back */ apdu_set_confirmed_simple_ack_handler(SERVICE_CONFIRMED_WRITE_PROPERTY, - MyWritePropertySimpleAckHandler); + MyWritePropertySimpleAckHandler); /* handle any errors coming back */ apdu_set_error_handler(SERVICE_CONFIRMED_WRITE_PROPERTY, MyErrorHandler); apdu_set_abort_handler(MyAbortHandler); @@ -159,51 +148,64 @@ static void Init_Service_Handlers( static void print_usage(char *filename) { - printf("Usage: %s device-instance object-type object-instance " + printf( + "Usage: %s device-instance object-type object-instance " "property priority index tag value [tag value...]\n", filename); } static void print_help(char *filename) { - printf("device-instance:\n" + printf( + "device-instance:\n" "BACnet Device Object Instance number that you are trying to\n" "communicate to. This number will be used to try and bind with\n" "the device using Who-Is and I-Am services. For example, if you were\n" "writing to Device Object 123, the device-instance would be 123.\n" - "\n" "object-type:\n" + "\n" + "object-type:\n" "The object type is the integer value of the enumeration\n" "BACNET_OBJECT_TYPE in bacenum.h. It is the object that you are\n" "writing to. For example if you were writing to Analog Output 2, \n" - "the object-type would be 1.\n" "\n" "object-instance:\n" + "the object-type would be 1.\n" + "\n" + "object-instance:\n" "This is the object instance number of the object that you are \n" "writing to. For example, if you were writing to Analog Output 2, \n" - "the object-instance would be 2.\n" "\n" "property:\n" + "the object-instance would be 2.\n" + "\n" + "property:\n" "The property is an integer value of the enumeration \n" "BACNET_PROPERTY_ID in bacenum.h. It is the property you are \n" "writing to. For example, if you were writing to the Present Value\n" - "property, you would use 85 as the property.\n" "\n" + "property, you would use 85 as the property.\n" + "\n" "priority:\n" "This parameter is used for setting the priority of the\n" "write. If Priority 0 is given, no priority is sent. The BACnet \n" "standard states that the value is written at the lowest \n" "priority (16) if the object property supports priorities\n" - "when no priority is sent.\n" "\n" "index\n" + "when no priority is sent.\n" + "\n" + "index\n" "This integer parameter is the index number of an array.\n" "If the property is an array, individual elements can be written\n" "to if supported. If this parameter is -1, the index is ignored.\n" - "\n" "tag:\n" + "\n" + "tag:\n" "Tag is the integer value of the enumeration BACNET_APPLICATION_TAG \n" "in bacenum.h. It is the data type of the value that you are\n" "writing. For example, if you were writing a REAL value, you would \n" "use a tag of 4.\n" "Context tags are created using two tags in a row. The context tag\n" "is preceded by a C. Ctag tag. C2 4 creates a context 2 tagged REAL.\n" - "\n" "value:\n" + "\n" + "value:\n" "The value is an ASCII representation of some type of data that you\n" "are writing. It is encoded using the tag information provided. For\n" "example, if you were writing a REAL value of 100.0, you would use \n" - "100.0 as the value.\n" "\n" + "100.0 as the value.\n" + "\n" "Here is a brief overview of BACnet property and tags:\n" "Certain properties are expected to be written with certain \n" "application tags, so you probably need to know which ones to use\n" @@ -214,24 +216,22 @@ static void print_help(char *filename) "accepting REAL, BOOLEAN, NULL, etc. Perhaps it would be simpler for\n" "the demo to use this kind of table - but I also wanted to be able\n" "to do negative testing by passing the wrong tag and have the server\n" - "return a reject message.\n" "\nExample:\n" + "return a reject message.\n" + "\nExample:\n" "If you want send a value of 100 to the Present-Value in\n" "Analog Output 0 of Device 123 at priority 16,\n" "send the following command:\n" "%s 123 1 0 85 16 -1 4 100\n" "To send a relinquish command to the same object:\n" - "%s 123 1 0 85 16 -1 0 0\n", filename, filename); + "%s 123 1 0 85 16 -1 0 0\n", + filename, filename); } -int main( - int argc, - char *argv[]) +int main(int argc, char *argv[]) { - BACNET_ADDRESS src = { - 0 - }; /* address where message came from */ + BACNET_ADDRESS src = {0}; /* address where message came from */ uint16_t pdu_len = 0; - unsigned timeout = 100; /* milliseconds */ + unsigned timeout = 100; /* milliseconds */ unsigned max_apdu = 0; time_t elapsed_seconds = 0; time_t last_seconds = 0; @@ -253,11 +253,12 @@ int main( return 0; } if (strcmp(argv[argi], "--version") == 0) { - printf("%s %s\n", - filename_remove_path(argv[0]), - BACNET_VERSION_TEXT); - printf("Copyright (C) 2014 by Steve Karg\n" - "This is free software; see the source for copying conditions.\n" + printf("%s %s\n", filename_remove_path(argv[0]), + BACNET_VERSION_TEXT); + printf( + "Copyright (C) 2014 by Steve Karg\n" + "This is free software; see the source for copying " + "conditions.\n" "There is NO warranty; not even for MERCHANTABILITY or\n" "FITNESS FOR A PARTICULAR PURPOSE.\n"); return 0; @@ -272,28 +273,28 @@ int main( Target_Object_Type = strtol(argv[2], NULL, 0); Target_Object_Instance = strtol(argv[3], NULL, 0); Target_Object_Property = strtol(argv[4], NULL, 0); - Target_Object_Property_Priority = (uint8_t) strtol(argv[5], NULL, 0); + Target_Object_Property_Priority = (uint8_t)strtol(argv[5], NULL, 0); Target_Object_Property_Index = strtol(argv[6], NULL, 0); if (Target_Object_Property_Index == -1) Target_Object_Property_Index = BACNET_ARRAY_ALL; if (Target_Device_Object_Instance > BACNET_MAX_INSTANCE) { fprintf(stderr, "device-instance=%u - it must be less than %u\n", - Target_Device_Object_Instance, BACNET_MAX_INSTANCE + 1); + Target_Device_Object_Instance, BACNET_MAX_INSTANCE + 1); return 1; } if (Target_Object_Type > MAX_BACNET_OBJECT_TYPE) { fprintf(stderr, "object-type=%u - it must be less than %u\n", - Target_Object_Type, MAX_BACNET_OBJECT_TYPE + 1); + Target_Object_Type, MAX_BACNET_OBJECT_TYPE + 1); return 1; } if (Target_Object_Instance > BACNET_MAX_INSTANCE) { fprintf(stderr, "object-instance=%u - it must be less than %u\n", - Target_Object_Instance, BACNET_MAX_INSTANCE + 1); + Target_Object_Instance, BACNET_MAX_INSTANCE + 1); return 1; } if (Target_Object_Property > MAX_BACNET_PROPERTY_ID) { fprintf(stderr, "property=%u - it must be less than %u\n", - Target_Object_Property, MAX_BACNET_PROPERTY_ID + 1); + Target_Object_Property, MAX_BACNET_PROPERTY_ID + 1); return 1; } args_remaining = (argc - 7); @@ -302,7 +303,7 @@ int main( for (i = 0; i < MAX_PROPERTY_VALUES; i++) { /* special case for context tagged values */ if (toupper(argv[tag_value_arg][0]) == 'C') { - context_tag = (uint8_t) strtol(&argv[tag_value_arg][1], NULL, 0); + context_tag = (uint8_t)strtol(&argv[tag_value_arg][1], NULL, 0); tag_value_arg++; args_remaining--; Target_Object_Property_Value[i].context_tag = context_tag; @@ -324,12 +325,11 @@ int main( i, property_tag, i, value_string); */ if (property_tag >= MAX_BACNET_APPLICATION_TAG) { fprintf(stderr, "Error: tag=%u - it must be less than %u\n", - property_tag, MAX_BACNET_APPLICATION_TAG); + property_tag, MAX_BACNET_APPLICATION_TAG); return 1; } - status = - bacapp_parse_application_data(property_tag, value_string, - &Target_Object_Property_Value[i]); + status = bacapp_parse_application_data( + property_tag, value_string, &Target_Object_Property_Value[i]); if (!status) { /* FIXME: show the expected entry format for the tag */ fprintf(stderr, "Error: unable to parse the tag value\n"); @@ -346,7 +346,7 @@ int main( } if (args_remaining > 0) { fprintf(stderr, "Error: Exceeded %d tag-value pairs.\n", - MAX_PROPERTY_VALUES); + MAX_PROPERTY_VALUES); return 1; } /* setup my info */ @@ -359,12 +359,11 @@ int main( last_seconds = time(NULL); timeout_seconds = (apdu_timeout() / 1000) * apdu_retries(); /* try to bind with the device */ - found = - address_bind_request(Target_Device_Object_Instance, &max_apdu, - &Target_Address); + found = address_bind_request(Target_Device_Object_Instance, &max_apdu, + &Target_Address); if (!found) { Send_WhoIs(Target_Device_Object_Instance, - Target_Device_Object_Instance); + Target_Device_Object_Instance); } /* loop forever */ for (;;) { @@ -373,22 +372,21 @@ int main( /* at least one second has passed */ if (current_seconds != last_seconds) - tsm_timer_milliseconds((uint16_t) ((current_seconds - - last_seconds) * 1000)); + tsm_timer_milliseconds( + (uint16_t)((current_seconds - last_seconds) * 1000)); if (Error_Detected) break; /* wait until the device is bound, or timeout and quit */ if (!found) { - found = - address_bind_request(Target_Device_Object_Instance, &max_apdu, - &Target_Address); + found = address_bind_request(Target_Device_Object_Instance, + &max_apdu, &Target_Address); } if (found) { if (Request_Invoke_ID == 0) { - Request_Invoke_ID = - Send_Write_Property_Request(Target_Device_Object_Instance, - Target_Object_Type, Target_Object_Instance, - Target_Object_Property, &Target_Object_Property_Value[0], + Request_Invoke_ID = Send_Write_Property_Request( + Target_Device_Object_Instance, Target_Object_Type, + Target_Object_Instance, Target_Object_Property, + &Target_Object_Property_Value[0], Target_Object_Property_Priority, Target_Object_Property_Index); } else if (tsm_invoke_id_free(Request_Invoke_ID)) diff --git a/demo/writepropm/main.c b/demo/writepropm/main.c index cb93fa8e..55286e5b 100644 --- a/demo/writepropm/main.c +++ b/demo/writepropm/main.c @@ -1,26 +1,26 @@ /************************************************************************* -* Copyright (C) 2017 Steve Karg -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * Copyright (C) 2017 Steve Karg + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ /* command line tool that sends a BACnet service, and displays the reply */ #include @@ -29,7 +29,7 @@ #include #include #include -#include /* for time */ +#include /* for time */ #define PRINT_ENABLED 1 @@ -57,7 +57,7 @@ #include "dlenv.h" /* buffer used for receive */ -static uint8_t Rx_Buf[MAX_MPDU] = { 0 }; +static uint8_t Rx_Buf[MAX_MPDU] = {0}; /* global variables used in this file */ static uint32_t Target_Device_Object_Instance = BACNET_MAX_INSTANCE; @@ -70,54 +70,46 @@ static bool Error_Detected = false; /* Used for verbose */ static bool Verbose = false; -static void MyErrorHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - BACNET_ERROR_CLASS error_class, - BACNET_ERROR_CODE error_code) +static void MyErrorHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + BACNET_ERROR_CLASS error_class, + BACNET_ERROR_CODE error_code) { if (address_match(&Target_Address, src) && (invoke_id == Request_Invoke_ID)) { printf("BACnet Error: %s: %s\n", - bactext_error_class_name((int) error_class), - bactext_error_code_name((int) error_code)); + bactext_error_class_name((int)error_class), + bactext_error_code_name((int)error_code)); Error_Detected = true; /* FIXME: WPM error has extra data for first failed write. */ } } -void MyAbortHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t abort_reason, - bool server) +void MyAbortHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t abort_reason, bool server) { - (void) server; + (void)server; if (address_match(&Target_Address, src) && (invoke_id == Request_Invoke_ID)) { printf("BACnet Abort: %s\n", - bactext_abort_reason_name((int) abort_reason)); + bactext_abort_reason_name((int)abort_reason)); Error_Detected = true; } } -void MyRejectHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id, - uint8_t reject_reason) +void MyRejectHandler(BACNET_ADDRESS *src, uint8_t invoke_id, + uint8_t reject_reason) { /* FIXME: verify src and invoke id */ if (address_match(&Target_Address, src) && (invoke_id == Request_Invoke_ID)) { printf("BACnet Reject: %s\n", - bactext_reject_reason_name((int) reject_reason)); + bactext_reject_reason_name((int)reject_reason)); Error_Detected = true; } } -void MyWritePropertyMultipleSimpleAckHandler( - BACNET_ADDRESS * src, - uint8_t invoke_id) +void MyWritePropertyMultipleSimpleAckHandler(BACNET_ADDRESS *src, + uint8_t invoke_id) { if (address_match(&Target_Address, src) && (invoke_id == Request_Invoke_ID)) { @@ -125,8 +117,7 @@ void MyWritePropertyMultipleSimpleAckHandler( } } -static void Init_Service_Handlers( - void) +static void Init_Service_Handlers(void) { Device_Init(NULL); /* we need to handle who-is @@ -136,13 +127,13 @@ static void Init_Service_Handlers( apdu_set_unconfirmed_handler(SERVICE_UNCONFIRMED_I_AM, handler_i_am_bind); /* set the handler for all the services we don't implement It is required to send the proper reject message... */ - apdu_set_unrecognized_service_handler_handler - (handler_unrecognized_service); + apdu_set_unrecognized_service_handler_handler(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_simple_ack_handler(SERVICE_CONFIRMED_WRITE_PROP_MULTIPLE, + apdu_set_confirmed_simple_ack_handler( + SERVICE_CONFIRMED_WRITE_PROP_MULTIPLE, MyWritePropertyMultipleSimpleAckHandler); /* handle any errors coming back */ apdu_set_error_handler(SERVICE_CONFIRMED_READ_PROPERTY, MyErrorHandler); @@ -150,8 +141,7 @@ static void Init_Service_Handlers( apdu_set_reject_handler(MyRejectHandler); } -void cleanup( - void) +void cleanup(void) { BACNET_WRITE_ACCESS_DATA *wpm_object; BACNET_WRITE_ACCESS_DATA *old_wpm_object; @@ -175,15 +165,18 @@ void cleanup( static void print_usage(char *filename) { - printf("Usage: %s device-instance object-type object-instance " - "property[index] priority tag value [property[index] priority tag value]\n", + printf( + "Usage: %s device-instance object-type object-instance " + "property[index] priority tag value [property[index] priority tag " + "value]\n", filename); printf(" [--version][--help]\n"); } static void print_help(char *filename) { - printf("Write one or more properties to one or more objects\n" + printf( + "Write one or more properties to one or more objects\n" "in a BACnet device.\n" "device-instance:\n" "BACnet Device Object Instance number that you are\n" @@ -210,23 +203,27 @@ static void print_help(char *filename) "write. If Priority 0 is given, no priority is sent. The BACnet \n" "standard states that the value is written at the lowest \n" "priority (16) if the object property supports priorities\n" - "when no priority is sent.\n" "\n" + "when no priority is sent.\n" + "\n" "index\n" "This integer parameter is the index number of an array.\n" "If the property is an array, individual elements can be written\n" "to if supported. If this parameter is -1, the index is ignored.\n" - "\n" "tag:\n" + "\n" + "tag:\n" "Tag is the integer value of the enumeration BACNET_APPLICATION_TAG \n" "in bacenum.h. It is the data type of the value that you are\n" "writing. For example, if you were writing a REAL value, you would \n" "use a tag of 4.\n" "Context tags are created using two tags in a row. The context tag\n" "is preceded by a C. Ctag tag. C2 4 creates a context 2 tagged REAL.\n" - "\n" "value:\n" + "\n" + "value:\n" "The value is an ASCII representation of some type of data that you\n" "are writing. It is encoded using the tag information provided. For\n" "example, if you were writing a REAL value of 100.0, you would use \n" - "100.0 as the value.\n" "\n" + "100.0 as the value.\n" + "\n" "Here is a brief overview of BACnet property and tags:\n" "Certain properties are expected to be written with certain \n" "application tags, so you probably need to know which ones to use\n" @@ -237,8 +234,9 @@ static void print_help(char *filename) "accepting REAL, BOOLEAN, NULL, etc. Perhaps it would be simpler for\n" "the demo to use this kind of table - but I also wanted to be able\n" "to do negative testing by passing the wrong tag and have the server\n" - "return a reject message.\n\n" ); - printf("Example:\n" + "return a reject message.\n\n"); + printf( + "Example:\n" "If you want send a value of 100 to the Present-Value in\n" "Analog Output 44 and 45 of Device 123 at priority 16,\n" "send the following command:\n" @@ -246,15 +244,11 @@ static void print_help(char *filename) filename); } -int main( - int argc, - char *argv[]) +int main(int argc, char *argv[]) { - BACNET_ADDRESS src = { - 0 - }; /* address where message came from */ + BACNET_ADDRESS src = {0}; /* address where message came from */ uint16_t pdu_len = 0; - unsigned timeout = 100; /* milliseconds */ + unsigned timeout = 100; /* milliseconds */ unsigned max_apdu = 0; int args_remaining = 0, tag_value_arg = 0, arg_sets = 0; time_t elapsed_seconds = 0; @@ -262,9 +256,7 @@ int main( time_t current_seconds = 0; time_t timeout_seconds = 0; bool found = false; - uint8_t buffer[MAX_PDU] = { - 0 - }; + uint8_t buffer[MAX_PDU] = {0}; BACNET_WRITE_ACCESS_DATA *wpm_object; BACNET_PROPERTY_VALUE *wpm_property; char *value_string = NULL; @@ -286,8 +278,10 @@ int main( } if (strcmp(argv[argi], "--version") == 0) { printf("%s %s\n", filename, BACNET_VERSION_TEXT); - printf("Copyright (C) 2017 by Steve Karg and others.\n" - "This is free software; see the source for copying conditions.\n" + printf( + "Copyright (C) 2017 by Steve Karg and others.\n" + "This is free software; see the source for copying " + "conditions.\n" "There is NO warranty; not even for MERCHANTABILITY or\n" "FITNESS FOR A PARTICULAR PURPOSE.\n"); return 0; @@ -301,7 +295,7 @@ int main( Target_Device_Object_Instance = strtol(argv[1], NULL, 0); if (Target_Device_Object_Instance >= BACNET_MAX_INSTANCE) { fprintf(stderr, "device-instance=%u - it must be less than %u\n", - Target_Device_Object_Instance, BACNET_MAX_INSTANCE); + Target_Device_Object_Instance, BACNET_MAX_INSTANCE); return 1; } atexit(cleanup); @@ -323,7 +317,7 @@ int main( } if (wpm_object->object_type >= MAX_BACNET_OBJECT_TYPE) { fprintf(stderr, "object-type=%u - it must be less than %u\n", - wpm_object->object_type, MAX_BACNET_OBJECT_TYPE); + wpm_object->object_type, MAX_BACNET_OBJECT_TYPE); return 1; } wpm_object->object_instance = strtol(argv[tag_value_arg], NULL, 0); @@ -338,7 +332,7 @@ int main( } if (wpm_object->object_instance > BACNET_MAX_INSTANCE) { fprintf(stderr, "object-instance=%u - it must be less than %u\n", - wpm_object->object_instance, BACNET_MAX_INSTANCE + 1); + wpm_object->object_instance, BACNET_MAX_INSTANCE + 1); return 1; } do { @@ -346,22 +340,22 @@ int main( wpm_object->listOfProperties = wpm_property; if (wpm_property) { /* Property[index] */ - scan_count = - sscanf(argv[tag_value_arg], "%u[%u]", &property_id, - &property_array_index); + scan_count = sscanf(argv[tag_value_arg], "%u[%u]", &property_id, + &property_array_index); tag_value_arg++; args_remaining--; if (scan_count > 0) { wpm_property->propertyIdentifier = property_id; if (Verbose) { printf("property-identifier=%u, array-index=%u\n", - property_id, property_array_index); + property_id, property_array_index); } - if (wpm_property->propertyIdentifier > MAX_BACNET_PROPERTY_ID) { + if (wpm_property->propertyIdentifier > + MAX_BACNET_PROPERTY_ID) { fprintf(stderr, - "property=%u - it must be less than %u\n", - wpm_property->propertyIdentifier, - MAX_BACNET_PROPERTY_ID + 1); + "property=%u - it must be less than %u\n", + wpm_property->propertyIdentifier, + MAX_BACNET_PROPERTY_ID + 1); return 1; } } @@ -372,26 +366,26 @@ int main( } if (args_remaining <= 0) { fprintf(stderr, - "Error: missing priority and tag value pair.\n"); + "Error: missing priority and tag value pair.\n"); return 1; } /* Priority */ - wpm_property->priority = (uint8_t) - strtol(argv[tag_value_arg], NULL, 0); + wpm_property->priority = + (uint8_t)strtol(argv[tag_value_arg], NULL, 0); tag_value_arg++; args_remaining--; if (Verbose) { printf("priority=%u\n", wpm_property->priority); } if (args_remaining <= 0) { - fprintf(stderr, - "Error: missing tag value pair.\n"); + fprintf(stderr, "Error: missing tag value pair.\n"); return 1; } /* Tag + Value */ /* special case for context tagged values */ if (toupper(argv[tag_value_arg][0]) == 'C') { - context_tag = (uint8_t) strtol(&argv[tag_value_arg][1], NULL, 0); + context_tag = + (uint8_t)strtol(&argv[tag_value_arg][1], NULL, 0); tag_value_arg++; args_remaining--; wpm_property->value.context_tag = context_tag; @@ -403,7 +397,8 @@ int main( tag_value_arg++; args_remaining--; if (args_remaining <= 0) { - fprintf(stderr, "Error: missing value for tag-value pair\n"); + fprintf(stderr, + "Error: missing value for tag-value pair\n"); return 1; } value_string = argv[tag_value_arg]; @@ -414,12 +409,11 @@ int main( } if (property_tag >= MAX_BACNET_APPLICATION_TAG) { fprintf(stderr, "Error: tag=%u - it must be less than %u\n", - property_tag, MAX_BACNET_APPLICATION_TAG); + property_tag, MAX_BACNET_APPLICATION_TAG); return 1; } - status = - bacapp_parse_application_data(property_tag, value_string, - &wpm_property->value); + status = bacapp_parse_application_data( + property_tag, value_string, &wpm_property->value); if (!status) { /* FIXME: show the expected entry format for the tag */ fprintf(stderr, "Error: unable to parse the tag value\n"); @@ -448,17 +442,16 @@ int main( last_seconds = time(NULL); timeout_seconds = (apdu_timeout() / 1000) * apdu_retries(); /* try to bind with the device */ - found = - address_bind_request(Target_Device_Object_Instance, &max_apdu, - &Target_Address); + found = address_bind_request(Target_Device_Object_Instance, &max_apdu, + &Target_Address); if (found) { if (Verbose) { printf("Found Device %u in address_cache.\n", - Target_Device_Object_Instance); + Target_Device_Object_Instance); } } else { Send_WhoIs(Target_Device_Object_Instance, - Target_Device_Object_Instance); + Target_Device_Object_Instance); } /* loop forever */ for (;;) { @@ -472,19 +465,17 @@ int main( break; /* wait until the device is bound, or timeout and quit */ if (!found) { - found = - address_bind_request(Target_Device_Object_Instance, &max_apdu, - &Target_Address); + found = address_bind_request(Target_Device_Object_Instance, + &max_apdu, &Target_Address); } if (found) { if (Request_Invoke_ID == 0) { if (Verbose) { printf("Sending WritePropertyMultiple to Device %u.\n", - Target_Device_Object_Instance); + Target_Device_Object_Instance); } - Request_Invoke_ID = - Send_Write_Property_Multiple_Request(&buffer[0], - sizeof(buffer), Target_Device_Object_Instance, + Request_Invoke_ID = Send_Write_Property_Multiple_Request( + &buffer[0], sizeof(buffer), Target_Device_Object_Instance, Write_Access_Data); } else if (tsm_invoke_id_free(Request_Invoke_ID)) { break; diff --git a/src/abort.c b/src/abort.c index 2774f006..199b5650 100644 --- a/src/abort.c +++ b/src/abort.c @@ -38,14 +38,12 @@ #include "abort.h" /** @file abort.c Abort Encoding/Decoding */ -/* Helper function to avoid needing additional entries in service data structures - * when passing back abort status. - * Convert from error code to abort code. - * Anything not defined converts to ABORT_REASON_OTHER. - * Will need reworking if it is required to return proprietary abort codes. +/* Helper function to avoid needing additional entries in service data + * structures when passing back abort status. Convert from error code to abort + * code. Anything not defined converts to ABORT_REASON_OTHER. Will need + * reworking if it is required to return proprietary abort codes. */ -BACNET_ABORT_REASON abort_convert_error_code( - BACNET_ERROR_CODE error_code) +BACNET_ABORT_REASON abort_convert_error_code(BACNET_ERROR_CODE error_code) { BACNET_ABORT_REASON abort_code = ABORT_REASON_OTHER; @@ -75,13 +73,10 @@ BACNET_ABORT_REASON abort_convert_error_code( } /* encode service */ -int abort_encode_apdu( - uint8_t * apdu, - uint8_t invoke_id, - uint8_t abort_reason, - bool server) +int abort_encode_apdu(uint8_t *apdu, uint8_t invoke_id, uint8_t abort_reason, + bool server) { - int apdu_len = 0; /* total length of the apdu, return value */ + int apdu_len = 0; /* total length of the apdu, return value */ if (apdu) { if (server) @@ -98,11 +93,8 @@ int abort_encode_apdu( #if !BACNET_SVC_SERVER /* decode the service request only */ -int abort_decode_service_request( - uint8_t * apdu, - unsigned apdu_len, - uint8_t * invoke_id, - uint8_t * abort_reason) +int abort_decode_service_request(uint8_t *apdu, unsigned apdu_len, + uint8_t *invoke_id, uint8_t *abort_reason) { int len = 0; @@ -123,12 +115,8 @@ int abort_decode_service_request( #include "ctest.h" /* decode the whole APDU - mainly used for unit testing */ -int abort_decode_apdu( - uint8_t * apdu, - unsigned apdu_len, - uint8_t * invoke_id, - uint8_t * abort_reason, - bool * server) +int abort_decode_apdu(uint8_t *apdu, unsigned apdu_len, uint8_t *invoke_id, + uint8_t *abort_reason, bool *server) { int len = 0; @@ -143,22 +131,18 @@ int abort_decode_apdu( else *server = false; if (apdu_len > 1) { - len = - abort_decode_service_request(&apdu[1], apdu_len - 1, invoke_id, - abort_reason); + len = abort_decode_service_request(&apdu[1], apdu_len - 1, + invoke_id, abort_reason); } } return len; } -void testAbortAPDU( - Test * pTest, - uint8_t invoke_id, - uint8_t abort_reason, - bool server) +void testAbortAPDU(Test *pTest, uint8_t invoke_id, uint8_t abort_reason, + bool server) { - uint8_t apdu[480] = { 0 }; + uint8_t apdu[480] = {0}; int len = 0; int apdu_len = 0; uint8_t test_invoke_id = 0; @@ -168,9 +152,8 @@ void testAbortAPDU( len = abort_encode_apdu(&apdu[0], invoke_id, abort_reason, server); apdu_len = len; ct_test(pTest, len != 0); - len = - abort_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, - &test_abort_reason, &test_server); + len = abort_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, + &test_abort_reason, &test_server); ct_test(pTest, len != -1); ct_test(pTest, test_invoke_id == invoke_id); ct_test(pTest, test_abort_reason == abort_reason); @@ -179,11 +162,9 @@ void testAbortAPDU( return; } - -void testAbort( - Test * pTest) +void testAbort(Test *pTest) { - uint8_t apdu[480] = { 0 }; + uint8_t apdu[480] = {0}; int len = 0; int apdu_len = 0; uint8_t invoke_id = 0; @@ -196,9 +177,8 @@ void testAbort( len = abort_encode_apdu(&apdu[0], invoke_id, abort_reason, server); ct_test(pTest, len != 0); apdu_len = len; - len = - abort_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, - &test_abort_reason, &test_server); + len = abort_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, + &test_abort_reason, &test_server); ct_test(pTest, len != -1); ct_test(pTest, test_invoke_id == invoke_id); ct_test(pTest, test_abort_reason == abort_reason); @@ -206,21 +186,18 @@ void testAbort( /* change type to get negative response */ apdu[0] = PDU_TYPE_REJECT; - len = - abort_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, - &test_abort_reason, &test_server); + len = abort_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, + &test_abort_reason, &test_server); ct_test(pTest, len == -1); /* test NULL APDU */ - len = - abort_decode_apdu(NULL, apdu_len, &test_invoke_id, &test_abort_reason, - &test_server); + len = abort_decode_apdu(NULL, apdu_len, &test_invoke_id, &test_abort_reason, + &test_server); ct_test(pTest, len == -1); /* force a zero length */ - len = - abort_decode_apdu(&apdu[0], 0, &test_invoke_id, &test_abort_reason, - &test_server); + len = abort_decode_apdu(&apdu[0], 0, &test_invoke_id, &test_abort_reason, + &test_server); ct_test(pTest, len == 0); /* check them all... */ @@ -233,8 +210,7 @@ void testAbort( } #ifdef TEST_ABORT -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -246,7 +222,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/src/access_rule.c b/src/access_rule.c index 0e21f060..b5957a19 100644 --- a/src/access_rule.c +++ b/src/access_rule.c @@ -1,36 +1,34 @@ /************************************************************************** -* -* Copyright (C) 2015 Nikola Jelic -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2015 Nikola Jelic + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include "access_rule.h" #include "bacdcode.h" -int bacapp_encode_access_rule( - uint8_t * apdu, - BACNET_ACCESS_RULE * rule) +int bacapp_encode_access_rule(uint8_t* apdu, BACNET_ACCESS_RULE* rule) { int len; int apdu_len = 0; @@ -39,9 +37,8 @@ int bacapp_encode_access_rule( apdu_len += len; if (rule->time_range_specifier == TIME_RANGE_SPECIFIER_SPECIFIED) { - len = - bacapp_encode_context_device_obj_property_ref(&apdu[apdu_len], 1, - &rule->time_range); + len = bacapp_encode_context_device_obj_property_ref(&apdu[apdu_len], 1, + &rule->time_range); if (len > 0) apdu_len += len; else @@ -49,14 +46,12 @@ int bacapp_encode_access_rule( } len = - encode_context_enumerated(&apdu[apdu_len], 2, - rule->location_specifier); + encode_context_enumerated(&apdu[apdu_len], 2, rule->location_specifier); apdu_len += len; if (rule->location_specifier == LOCATION_SPECIFIER_SPECIFIED) { - len = - bacapp_encode_context_device_obj_property_ref(&apdu[apdu_len], 3, - &rule->location); + len = bacapp_encode_context_device_obj_property_ref(&apdu[apdu_len], 3, + &rule->location); if (len > 0) apdu_len += len; else @@ -69,10 +64,8 @@ int bacapp_encode_access_rule( return apdu_len; } -int bacapp_encode_context_access_rule( - uint8_t * apdu, - uint8_t tag_number, - BACNET_ACCESS_RULE * rule) +int bacapp_encode_context_access_rule(uint8_t* apdu, uint8_t tag_number, + BACNET_ACCESS_RULE* rule) { int len; int apdu_len = 0; @@ -89,17 +82,14 @@ int bacapp_encode_context_access_rule( return apdu_len; } -int bacapp_decode_access_rule( - uint8_t * apdu, - BACNET_ACCESS_RULE * rule) +int bacapp_decode_access_rule(uint8_t* apdu, BACNET_ACCESS_RULE* rule) { int len; int apdu_len = 0; if (decode_is_context_tag(&apdu[apdu_len], 0)) { - len = - decode_context_enumerated(&apdu[apdu_len], 0, - &rule->time_range_specifier); + len = decode_context_enumerated(&apdu[apdu_len], 0, + &rule->time_range_specifier); if (len < 0) return -1; else @@ -109,9 +99,8 @@ int bacapp_decode_access_rule( if (rule->time_range_specifier == TIME_RANGE_SPECIFIER_SPECIFIED) { if (decode_is_context_tag(&apdu[apdu_len], 1)) { - len = - bacapp_decode_context_device_obj_property_ref(&apdu[apdu_len], - 1, &rule->time_range); + len = bacapp_decode_context_device_obj_property_ref( + &apdu[apdu_len], 1, &rule->time_range); if (len < 0) return -1; else @@ -121,9 +110,8 @@ int bacapp_decode_access_rule( } if (decode_is_context_tag(&apdu[apdu_len], 2)) { - len = - decode_context_enumerated(&apdu[apdu_len], 2, - &rule->location_specifier); + len = decode_context_enumerated(&apdu[apdu_len], 2, + &rule->location_specifier); if (len < 0) return -1; else @@ -133,9 +121,8 @@ int bacapp_decode_access_rule( if (rule->location_specifier == LOCATION_SPECIFIER_SPECIFIED) { if (decode_is_context_tag(&apdu[apdu_len], 3)) { - len = - bacapp_decode_context_device_obj_property_ref(&apdu[apdu_len], - 3, &rule->location); + len = bacapp_decode_context_device_obj_property_ref( + &apdu[apdu_len], 3, &rule->location); if (len < 0) return -1; else @@ -156,10 +143,8 @@ int bacapp_decode_access_rule( return apdu_len; } -int bacapp_decode_context_access_rule( - uint8_t * apdu, - uint8_t tag_number, - BACNET_ACCESS_RULE * rule) +int bacapp_decode_context_access_rule(uint8_t* apdu, uint8_t tag_number, + BACNET_ACCESS_RULE* rule) { int len = 0; int section_length; diff --git a/src/address.c b/src/address.c index 3645992e..f1e30b9f 100644 --- a/src/address.c +++ b/src/address.c @@ -69,19 +69,20 @@ static struct Address_Cache_Entry { /* State flags for cache entries */ -#define BAC_ADDR_IN_USE 1 /* Address cache entry in use */ -#define BAC_ADDR_BIND_REQ 2 /* Bind request outstanding for entry */ -#define BAC_ADDR_STATIC 4 /* Static address mapping - does not expire */ -#define BAC_ADDR_SHORT_TTL 8 /* Oppertunistaclly added address with short TTL */ -#define BAC_ADDR_RESERVED 128 /* Freed up but held for caller to fill */ +#define BAC_ADDR_IN_USE 1 /* Address cache entry in use */ +#define BAC_ADDR_BIND_REQ 2 /* Bind request outstanding for entry */ +#define BAC_ADDR_STATIC 4 /* Static address mapping - does not expire */ +#define BAC_ADDR_SHORT_TTL \ + 8 /* Oppertunistaclly added address with short TTL \ + */ +#define BAC_ADDR_RESERVED 128 /* Freed up but held for caller to fill */ -#define BAC_ADDR_SECS_1HOUR 3600 /* 60x60 */ -#define BAC_ADDR_SECS_1DAY 86400 /* 60x60x24 */ +#define BAC_ADDR_SECS_1HOUR 3600 /* 60x60 */ +#define BAC_ADDR_SECS_1DAY 86400 /* 60x60x24 */ -#define BAC_ADDR_LONG_TIME BAC_ADDR_SECS_1DAY +#define BAC_ADDR_LONG_TIME BAC_ADDR_SECS_1DAY #define BAC_ADDR_SHORT_TIME BAC_ADDR_SECS_1HOUR -#define BAC_ADDR_FOREVER 0xFFFFFFFF /* Permenant entry */ - +#define BAC_ADDR_FOREVER 0xFFFFFFFF /* Permenant entry */ void address_protected_entry_index_set(uint32_t top_protected_entry_index) { @@ -93,9 +94,7 @@ void address_own_device_id_set(uint32_t own_id) Own_Device_ID = own_id; } -bool address_match( - BACNET_ADDRESS * dest, - BACNET_ADDRESS * src) +bool address_match(BACNET_ADDRESS *dest, BACNET_ADDRESS *src) { uint8_t i = 0; uint8_t max_len = 0; @@ -129,8 +128,7 @@ bool address_match( return true; } -void address_remove_device( - uint32_t device_id) +void address_remove_device(uint32_t device_id) { struct Address_Cache_Entry *pMatch; uint32_t index = 0; @@ -160,9 +158,7 @@ void address_remove_device( * assumed we are calling this due to the lack of those. * *****************************************************************************/ - -static struct Address_Cache_Entry *address_remove_oldest( - void) +static struct Address_Cache_Entry *address_remove_oldest(void) { struct Address_Cache_Entry *pMatch; struct Address_Cache_Entry *pCandidate; @@ -170,17 +166,17 @@ static struct Address_Cache_Entry *address_remove_oldest( pCandidate = NULL; if (Top_Protected_Entry > (MAX_ADDRESS_CACHE - 1)) { - return pCandidate; + return pCandidate; } - ulTime = BAC_ADDR_FOREVER - 1; /* Longest possible non static time to live */ + ulTime = + BAC_ADDR_FOREVER - 1; /* Longest possible non static time to live */ /* First pass - try only in use and bound entries */ pMatch = &Address_Cache[Top_Protected_Entry]; while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) { - if ((pMatch-> - Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ | - BAC_ADDR_STATIC)) == BAC_ADDR_IN_USE) { + 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; pCandidate = pMatch; @@ -189,19 +185,19 @@ static struct Address_Cache_Entry *address_remove_oldest( pMatch++; } - if (pCandidate != NULL) { /* Found something to free up */ + if (pCandidate != NULL) { /* Found something to free up */ pCandidate->Flags = BAC_ADDR_RESERVED; - pCandidate->TimeToLive = BAC_ADDR_SHORT_TIME; /* only reserve it for a short while */ + pCandidate->TimeToLive = + BAC_ADDR_SHORT_TIME; /* only reserve it for a short while */ return (pCandidate); } /* 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 | - BAC_ADDR_STATIC)) == - ((uint8_t) (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ))) { + if ((pMatch->Flags & + (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ | BAC_ADDR_STATIC)) == + ((uint8_t)(BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ))) { if (pMatch->TimeToLive <= ulTime) { /* Shorter lived entry found */ ulTime = pMatch->TimeToLive; pCandidate = pMatch; @@ -210,9 +206,10 @@ static struct Address_Cache_Entry *address_remove_oldest( pMatch++; } - if (pCandidate != NULL) { /* Found something to free up */ + if (pCandidate != NULL) { /* Found something to free up */ pCandidate->Flags = BAC_ADDR_RESERVED; - pCandidate->TimeToLive = BAC_ADDR_SHORT_TIME; /* only reserve it for a short while */ + pCandidate->TimeToLive = + BAC_ADDR_SHORT_TIME; /* only reserve it for a short while */ } return (pCandidate); @@ -224,10 +221,7 @@ static struct Address_Cache_Entry *address_remove_oldest( * @param adr [in] address to initialize, null if empty * @param len [in] length of address in bytes */ -void address_mac_init( - BACNET_MAC_ADDRESS *mac, - uint8_t *adr, - uint8_t len) +void address_mac_init(BACNET_MAC_ADDRESS *mac, uint8_t *adr, uint8_t len) { uint8_t i = 0; @@ -248,9 +242,7 @@ void address_mac_init( * * @return true if the address was parsed */ -bool address_mac_from_ascii( - BACNET_MAC_ADDRESS *mac, - char *arg) +bool address_mac_from_ascii(BACNET_MAC_ADDRESS *mac, char *arg) { unsigned a[6] = {0}, p = 0; uint16_t port = 0; @@ -260,7 +252,7 @@ bool address_mac_from_ascii( if (!(mac && arg)) { return false; } - c = sscanf(arg, "%3u.%3u.%3u.%3u:%5u", &a[0],&a[1],&a[2],&a[3],&p); + c = sscanf(arg, "%3u.%3u.%3u.%3u:%5u", &a[0], &a[1], &a[2], &a[3], &p); if ((c == 4) || (c == 5)) { mac->adr[0] = a[0]; mac->adr[1] = a[1]; @@ -275,8 +267,8 @@ bool address_mac_from_ascii( mac->len = 6; status = true; } else { - c = sscanf(arg, "%2x:%2x:%2x:%2x:%2x:%2x", - &a[0],&a[1],&a[2],&a[3],&a[4],&a[5]); + c = sscanf(arg, "%2x:%2x:%2x:%2x:%2x:%2x", &a[0], &a[1], &a[2], &a[3], + &a[4], &a[5]); if (c == 6) { mac->adr[0] = a[0]; mac->adr[1] = a[1]; @@ -307,35 +299,33 @@ note: useful for MS/TP Slave static binding */ static const char *Address_Cache_Filename = "address_cache"; -static void address_file_init( - const char *pFilename) +static void address_file_init(const char *pFilename) { - FILE *pFile = NULL; /* stream pointer */ - char line[256] = { "" }; /* holds line from file */ + FILE *pFile = NULL; /* stream pointer */ + char line[256] = {""}; /* holds line from file */ long device_id = 0; unsigned snet = 0; unsigned max_apdu = 0; - char mac_string[80] = { "" }, sadr_string[80] = { - ""}; - BACNET_ADDRESS src = { 0 }; - BACNET_MAC_ADDRESS mac = { 0 }; + char mac_string[80] = {""}, sadr_string[80] = {""}; + BACNET_ADDRESS src = {0}; + BACNET_MAC_ADDRESS mac = {0}; int index = 0; pFile = fopen(pFilename, "r"); if (pFile) { - while (fgets(line, (int) sizeof(line), pFile) != NULL) { + while (fgets(line, (int)sizeof(line), pFile) != NULL) { /* ignore comments */ if (line[0] != ';') { if (sscanf(line, "%7ld %79s %5u %79s %4u", &device_id, - &mac_string[0], &snet, &sadr_string[0], - &max_apdu) == 5) { + &mac_string[0], &snet, &sadr_string[0], + &max_apdu) == 5) { if (address_mac_from_ascii(&mac, mac_string)) { src.mac_len = mac.len; for (index = 0; index < MAX_MAC_LEN; index++) { src.mac[index] = mac.adr[index]; } } - src.net = (uint16_t) snet; + src.net = (uint16_t)snet; if (snet) { if (address_mac_from_ascii(&mac, sadr_string)) { src.len = mac.len; @@ -349,8 +339,9 @@ static void address_file_init( src.adr[index] = 0; } } - address_add((uint32_t) device_id, max_apdu, &src); - address_set_device_TTL((uint32_t) device_id, 0, true); /* Mark as static entry */ + address_add((uint32_t)device_id, max_apdu, &src); + address_set_device_TTL((uint32_t)device_id, 0, + true); /* Mark as static entry */ } } } @@ -366,12 +357,11 @@ static void address_file_init( * available. Assume no persistance of memory. * ****************************************************************************/ -void address_init( - void) +void address_init(void) { struct Address_Cache_Entry *pMatch; - Top_Protected_Entry = 0; + Top_Protected_Entry = 0; pMatch = Address_Cache; while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) { @@ -392,33 +382,33 @@ void address_init( * of its entries intact. * ****************************************************************************/ -void address_init_partial( - void) +void address_init_partial(void) { struct Address_Cache_Entry *pMatch; pMatch = Address_Cache; while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) { - if ((pMatch->Flags & BAC_ADDR_IN_USE) != 0) { /* It's in use so let's check further */ + if ((pMatch->Flags & BAC_ADDR_IN_USE) != + 0) { /* It's in use so let's check further */ if (((pMatch->Flags & BAC_ADDR_BIND_REQ) != 0) || (pMatch->TimeToLive == 0)) pMatch->Flags = 0; } - if ((pMatch->Flags & BAC_ADDR_RESERVED) != 0) { /* Reserved entries should be cleared */ + if ((pMatch->Flags & BAC_ADDR_RESERVED) != + 0) { /* Reserved entries should be cleared */ pMatch->Flags = 0; } pMatch++; } - #ifdef BACNET_ADDRESS_CACHE_FILE +#ifdef BACNET_ADDRESS_CACHE_FILE address_file_init(Address_Cache_Filename); #endif return; } - /**************************************************************************** * Set the TTL info for the given device entry. If it is a bound entry we * * set it to static or normal and can change the TTL. If it is unbound we * @@ -426,10 +416,8 @@ void address_init_partial( * to avoid breaking the current API. * ****************************************************************************/ -void address_set_device_TTL( - uint32_t device_id, - uint32_t TimeOut, - bool StaticFlag) +void address_set_device_TTL(uint32_t device_id, uint32_t TimeOut, + bool StaticFlag) { struct Address_Cache_Entry *pMatch; @@ -437,7 +425,8 @@ void address_set_device_TTL( while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) { if (((pMatch->Flags & BAC_ADDR_IN_USE) != 0) && (pMatch->device_id == device_id)) { - if ((pMatch->Flags & BAC_ADDR_BIND_REQ) == 0) { /* If bound then we have either static or normaal */ + if ((pMatch->Flags & BAC_ADDR_BIND_REQ) == + 0) { /* If bound then we have either static or normaal */ if (StaticFlag) { pMatch->Flags |= BAC_ADDR_STATIC; pMatch->TimeToLive = BAC_ADDR_FOREVER; @@ -446,19 +435,17 @@ void address_set_device_TTL( pMatch->TimeToLive = TimeOut; } } else { - pMatch->TimeToLive = TimeOut; /* For unbound we can only set the time to live */ + pMatch->TimeToLive = + TimeOut; /* For unbound we can only set the time to live */ } - break; /* Exit now if found at all - bound or unbound */ + break; /* Exit now if found at all - bound or unbound */ } pMatch++; } } - -bool address_get_by_device( - uint32_t device_id, - unsigned *max_apdu, - BACNET_ADDRESS * src) +bool address_get_by_device(uint32_t device_id, unsigned *max_apdu, + BACNET_ADDRESS *src) { struct Address_Cache_Entry *pMatch; bool found = false; /* return value */ @@ -467,12 +454,13 @@ bool address_get_by_device( while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) { if (((pMatch->Flags & BAC_ADDR_IN_USE) != 0) && (pMatch->device_id == device_id)) { - if ((pMatch->Flags & BAC_ADDR_BIND_REQ) == 0) { /* If bound then fetch data */ + if ((pMatch->Flags & BAC_ADDR_BIND_REQ) == + 0) { /* If bound then fetch data */ bacnet_address_copy(src, &pMatch->address); *max_apdu = pMatch->max_apdu; - found = true; /* Prove we found it */ + found = true; /* Prove we found it */ } - break; /* Exit now if found at all - bound or unbound */ + break; /* Exit now if found at all - bound or unbound */ } pMatch++; } @@ -482,16 +470,15 @@ bool address_get_by_device( /* find a device id from a given MAC address */ -bool address_get_device_id( - BACNET_ADDRESS * src, - uint32_t * device_id) +bool address_get_device_id(BACNET_ADDRESS *src, uint32_t *device_id) { struct Address_Cache_Entry *pMatch; bool found = false; /* return value */ pMatch = Address_Cache; while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) { - if ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ)) == BAC_ADDR_IN_USE) { /* If bound */ + if ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ)) == + BAC_ADDR_IN_USE) { /* If bound */ if (bacnet_address_same(&pMatch->address, src)) { if (device_id) { *device_id = pMatch->device_id; @@ -506,10 +493,7 @@ bool address_get_device_id( return found; } -void address_add( - uint32_t device_id, - unsigned max_apdu, - BACNET_ADDRESS * src) +void address_add(uint32_t device_id, unsigned max_apdu, BACNET_ADDRESS *src) { bool found = false; /* return value */ struct Address_Cache_Entry *pMatch; @@ -534,16 +518,21 @@ void address_add( /* Pick the right time to live */ - if ((pMatch->Flags & BAC_ADDR_BIND_REQ) != 0) /* Bind requested so long time */ + if ((pMatch->Flags & BAC_ADDR_BIND_REQ) != + 0) /* Bind requested so long time */ pMatch->TimeToLive = BAC_ADDR_LONG_TIME; - else if ((pMatch->Flags & BAC_ADDR_STATIC) != 0) /* Static already so make sure it never expires */ + else if ((pMatch->Flags & BAC_ADDR_STATIC) != + 0) /* Static already so make sure it never expires */ pMatch->TimeToLive = BAC_ADDR_FOREVER; - else if ((pMatch->Flags & BAC_ADDR_SHORT_TTL) != 0) /* Opportunistic entry so leave on short fuse */ + else if ((pMatch->Flags & BAC_ADDR_SHORT_TTL) != + 0) /* Opportunistic entry so leave on short fuse */ pMatch->TimeToLive = BAC_ADDR_SHORT_TIME; else - pMatch->TimeToLive = BAC_ADDR_LONG_TIME; /* Renewing existing entry */ + pMatch->TimeToLive = + BAC_ADDR_LONG_TIME; /* Renewing existing entry */ - pMatch->Flags &= ~BAC_ADDR_BIND_REQ; /* Clear bind request flag just in case */ + pMatch->Flags &= + ~BAC_ADDR_BIND_REQ; /* Clear bind request flag just in case */ found = true; break; } @@ -559,7 +548,9 @@ void address_add( pMatch->device_id = device_id; pMatch->max_apdu = max_apdu; bacnet_address_copy(&pMatch->address, src); - pMatch->TimeToLive = BAC_ADDR_SHORT_TIME; /* Opportunistic entry so leave on short fuse */ + pMatch->TimeToLive = + BAC_ADDR_SHORT_TIME; /* Opportunistic entry so leave on + short fuse */ found = true; break; } @@ -575,7 +566,8 @@ void address_add( pMatch->device_id = device_id; pMatch->max_apdu = max_apdu; bacnet_address_copy(&pMatch->address, src); - pMatch->TimeToLive = BAC_ADDR_SHORT_TIME; /* Opportunistic entry so leave on short fuse */ + pMatch->TimeToLive = BAC_ADDR_SHORT_TIME; /* Opportunistic entry so + leave on short fuse */ } } return; @@ -583,11 +575,8 @@ void address_add( /* returns true if device is already bound */ /* also returns the address and max apdu if already bound */ -bool address_device_bind_request( - uint32_t device_id, - uint32_t * device_ttl, - unsigned *max_apdu, - BACNET_ADDRESS * src) +bool address_device_bind_request(uint32_t device_id, uint32_t *device_ttl, + unsigned *max_apdu, BACNET_ADDRESS *src) { bool found = false; /* return value */ struct Address_Cache_Entry *pMatch; @@ -597,7 +586,7 @@ bool address_device_bind_request( while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) { if (((pMatch->Flags & BAC_ADDR_IN_USE) != 0) && (pMatch->device_id == device_id)) { - if ((pMatch->Flags & BAC_ADDR_BIND_REQ) == 0) { /* Already bound */ + if ((pMatch->Flags & BAC_ADDR_BIND_REQ) == 0) { /* Already bound */ found = true; if (src) { bacnet_address_copy(src, &pMatch->address); @@ -608,12 +597,17 @@ bool address_device_bind_request( if (device_ttl) { *device_ttl = pMatch->TimeToLive; } - if ((pMatch->Flags & BAC_ADDR_SHORT_TTL) != 0) { /* Was picked up opportunistacilly */ - pMatch->Flags &= ~BAC_ADDR_SHORT_TTL; /* Convert to normal entry */ - pMatch->TimeToLive = BAC_ADDR_LONG_TIME; /* And give it a decent time to live */ + if ((pMatch->Flags & BAC_ADDR_SHORT_TTL) != + 0) { /* Was picked up opportunistacilly */ + pMatch->Flags &= + ~BAC_ADDR_SHORT_TTL; /* Convert to normal entry */ + pMatch->TimeToLive = + BAC_ADDR_LONG_TIME; /* And give it a decent time to live + */ } } - return (found); /* True if bound, false if bind request outstanding */ + return ( + found); /* True if bound, false if bind request outstanding */ } pMatch++; } @@ -623,7 +617,7 @@ bool address_device_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; @@ -633,10 +627,11 @@ bool address_device_bind_request( pMatch++; } - /* No free entries, See if we can squeeze it in by dropping an existing one */ + /* 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; @@ -646,18 +641,14 @@ bool address_device_bind_request( /* returns true if device is already bound */ /* also returns the address and max apdu if already bound */ -bool address_bind_request( - uint32_t device_id, - unsigned *max_apdu, - BACNET_ADDRESS * src) +bool address_bind_request(uint32_t device_id, unsigned *max_apdu, + BACNET_ADDRESS *src) { return address_device_bind_request(device_id, NULL, max_apdu, src); } -void address_add_binding( - uint32_t device_id, - unsigned max_apdu, - BACNET_ADDRESS * src) +void address_add_binding(uint32_t device_id, unsigned max_apdu, + BACNET_ADDRESS *src) { struct Address_Cache_Entry *pMatch; @@ -682,12 +673,9 @@ void address_add_binding( return; } -bool address_device_get_by_index( - unsigned index, - uint32_t * device_id, - uint32_t * device_ttl, - unsigned *max_apdu, - BACNET_ADDRESS * src) +bool address_device_get_by_index(unsigned index, uint32_t *device_id, + uint32_t *device_ttl, unsigned *max_apdu, + BACNET_ADDRESS *src) { struct Address_Cache_Entry *pMatch; bool found = false; /* return value */ @@ -715,17 +703,13 @@ bool address_device_get_by_index( return found; } -bool address_get_by_index( - unsigned index, - uint32_t * device_id, - unsigned *max_apdu, - BACNET_ADDRESS * src) +bool address_get_by_index(unsigned index, uint32_t *device_id, + unsigned *max_apdu, BACNET_ADDRESS *src) { return address_device_get_by_index(index, device_id, NULL, max_apdu, src); } -unsigned address_count( - void) +unsigned address_count(void) { struct Address_Cache_Entry *pMatch; unsigned count = 0; /* return value */ @@ -748,9 +732,7 @@ unsigned address_count( * property. * ****************************************************************************/ -int address_list_encode( - uint8_t * apdu, - unsigned apdu_len) +int address_list_encode(uint8_t *apdu, unsigned apdu_len) { int iLen = 0; struct Address_Cache_Entry *pMatch; @@ -765,9 +747,8 @@ int address_list_encode( while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) { if ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ)) == BAC_ADDR_IN_USE) { - iLen += - encode_application_object_id(&apdu[iLen], OBJECT_DEVICE, - pMatch->device_id); + iLen += encode_application_object_id(&apdu[iLen], OBJECT_DEVICE, + pMatch->device_id); iLen += encode_application_unsigned(&apdu[iLen], pMatch->address.net); @@ -775,12 +756,12 @@ int address_list_encode( if (pMatch->address.len != 0) { octetstring_init(&MAC_Address, pMatch->address.adr, - pMatch->address.len); + pMatch->address.len); iLen += encode_application_octet_string(&apdu[iLen], &MAC_Address); } else { octetstring_init(&MAC_Address, pMatch->address.mac, - pMatch->address.mac_len); + pMatch->address.mac_len); iLen += encode_application_octet_string(&apdu[iLen], &MAC_Address); } @@ -814,22 +795,20 @@ 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) +int rr_address_list_encode(uint8_t *apdu, BACNET_READ_RANGE_DATA *pRequest) { int iLen = 0; int32_t iTemp = 0; 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); @@ -837,11 +816,11 @@ int rr_address_list_encode( 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 */ + 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 (pRequest->RequestType == RR_READ_ALL) { @@ -850,11 +829,12 @@ int rr_address_list_encode( * 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 @@ -868,12 +848,14 @@ int rr_address_list_encode( * 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; } @@ -881,28 +863,32 @@ int rr_address_list_encode( /* 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 */ + 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 = 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; 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 */ + if ((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_BIND_REQ)) == + BAC_ADDR_IN_USE) { /* Only count bound entries */ pMatch++; uiIndex++; } else pMatch++; } - uiFirst = uiIndex; /* Record where we started from */ + uiFirst = uiIndex; /* Record where we started from */ while (uiIndex <= uiTarget) { if (uiRemaining < ACACHE_MAX_ENC) { /* @@ -910,49 +896,45 @@ int rr_address_list_encode( * was more and drop out of the loop early */ bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_MORE_ITEMS, - true); + true); break; } - iTemp = - (int32_t) encode_application_object_id(&apdu[iLen], OBJECT_DEVICE, - pMatch->device_id); - iTemp += - encode_application_unsigned(&apdu[iLen + iTemp], - pMatch->address.net); + iTemp = (int32_t)encode_application_object_id( + &apdu[iLen], OBJECT_DEVICE, pMatch->device_id); + 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); + 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); + 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 */ + uiLast = uiIndex; /* Record the last entry encoded */ + uiIndex++; /* and get ready for next one */ pMatch++; - pRequest->ItemCount++; /* Chalk up another one for the response count */ + 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); + bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_FIRST_ITEM, true); if (uiLast == uiTotal) bitstring_set_bit(&pRequest->ResultFlags, RESULT_FLAG_LAST_ITEM, true); @@ -967,15 +949,15 @@ int rr_address_list_encode( * entries never expire unless explictely deleted. * ****************************************************************************/ -void address_cache_timer( - uint16_t uSeconds) -{ /* Approximate number of seconds since last call to this function */ +void address_cache_timer(uint16_t uSeconds) +{ /* Approximate number of seconds since last call to this function */ struct Address_Cache_Entry *pMatch; pMatch = Address_Cache; while (pMatch <= &Address_Cache[MAX_ADDRESS_CACHE - 1]) { - if (((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_RESERVED)) != 0) - && ((pMatch->Flags & BAC_ADDR_STATIC) == 0)) { /* Check all entries holding a slot except statics */ + if (((pMatch->Flags & (BAC_ADDR_IN_USE | BAC_ADDR_RESERVED)) != 0) && + ((pMatch->Flags & BAC_ADDR_STATIC) == + 0)) { /* Check all entries holding a slot except statics */ if (pMatch->TimeToLive >= uSeconds) pMatch->TimeToLive -= uSeconds; else @@ -986,16 +968,12 @@ void address_cache_timer( } } - - #ifdef TEST #include #include #include "ctest.h" -static void set_address( - unsigned index, - BACNET_ADDRESS * dest) +static void set_address(unsigned index, BACNET_ADDRESS *dest) { unsigned i; @@ -1010,11 +988,8 @@ static void set_address( } } -static void set_file_address( - const char *pFilename, - uint32_t device_id, - BACNET_ADDRESS * dest, - uint16_t max_apdu) +static void set_file_address(const char *pFilename, uint32_t device_id, + BACNET_ADDRESS *dest, uint16_t max_apdu) { unsigned i; FILE *pFile = NULL; @@ -1022,7 +997,7 @@ static void set_file_address( pFile = fopen(pFilename, "w"); if (pFile) { - fprintf(pFile, "%lu ", (long unsigned int) device_id); + fprintf(pFile, "%lu ", (long unsigned int)device_id); for (i = 0; i < dest->mac_len; i++) { fprintf(pFile, "%02x", dest->mac[i]); if ((i + 1) < dest->mac_len) { @@ -1046,13 +1021,12 @@ static void set_file_address( } #ifdef BACNET_ADDRESS_CACHE_FILE -void testAddressFile( - Test * pTest) +void testAddressFile(Test *pTest) { - BACNET_ADDRESS src = { 0 }; + BACNET_ADDRESS src = {0}; uint32_t device_id = 0; unsigned max_apdu = 480; - BACNET_ADDRESS test_address = { 0 }; + BACNET_ADDRESS test_address = {0}; unsigned test_max_apdu = 0; /* create a fake address */ @@ -1065,8 +1039,8 @@ void testAddressFile( set_file_address(Address_Cache_Filename, device_id, &src, max_apdu); /* retrieve it from the file, and see if we can find it */ address_file_init(Address_Cache_Filename); - ct_test(pTest, address_get_by_device(device_id, &test_max_apdu, - &test_address)); + ct_test(pTest, + address_get_by_device(device_id, &test_max_apdu, &test_address)); ct_test(pTest, test_max_apdu == max_apdu); ct_test(pTest, bacnet_address_same(&test_address, &src)); @@ -1086,16 +1060,14 @@ void testAddressFile( set_file_address(Address_Cache_Filename, device_id, &src, max_apdu); /* retrieve it from the file, and see if we can find it */ address_file_init(Address_Cache_Filename); - ct_test(pTest, address_get_by_device(device_id, &test_max_apdu, - &test_address)); + ct_test(pTest, + address_get_by_device(device_id, &test_max_apdu, &test_address)); ct_test(pTest, test_max_apdu == max_apdu); ct_test(pTest, bacnet_address_same(&test_address, &src)); - } #endif -void testAddress( - Test * pTest) +void testAddress(Test *pTest) { unsigned i, count; BACNET_ADDRESS src; @@ -1119,11 +1091,11 @@ void testAddress( set_address(i, &src); /* test the lookup by device id */ ct_test(pTest, address_get_by_device(device_id, &test_max_apdu, - &test_address)); + &test_address)); ct_test(pTest, test_max_apdu == max_apdu); ct_test(pTest, bacnet_address_same(&test_address, &src)); ct_test(pTest, address_get_by_index(i, &test_device_id, &test_max_apdu, - &test_address)); + &test_address)); ct_test(pTest, test_device_id == device_id); ct_test(pTest, test_max_apdu == max_apdu); ct_test(pTest, bacnet_address_same(&test_address, &src)); @@ -1137,15 +1109,14 @@ void testAddress( device_id = i * 255; address_remove_device(device_id); ct_test(pTest, !address_get_by_device(device_id, &test_max_apdu, - &test_address)); + &test_address)); count = address_count(); ct_test(pTest, count == (MAX_ADDRESS_CACHE - i - 1)); } } #ifdef TEST_ADDRESS -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -1159,10 +1130,9 @@ int main( assert(rc); #endif - ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/src/alarm_ack.c b/src/alarm_ack.c index b68f1ef9..57048dc0 100644 --- a/src/alarm_ack.c +++ b/src/alarm_ack.c @@ -41,19 +41,17 @@ ** Creates an Unconfirmed Event Notification APDU ** ****************************************************/ -int alarm_ack_encode_apdu( - uint8_t * apdu, - uint8_t invoke_id, - BACNET_ALARM_ACK_DATA * data) +int alarm_ack_encode_apdu(uint8_t *apdu, uint8_t invoke_id, + BACNET_ALARM_ACK_DATA *data) { - int len = 0; /* length of each encoding */ - int apdu_len = 0; /* total length of the apdu, return value */ + int len = 0; /* length of each encoding */ + int apdu_len = 0; /* total length of the apdu, return value */ if (apdu) { apdu[0] = PDU_TYPE_CONFIRMED_SERVICE_REQUEST; apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU); apdu[2] = invoke_id; - apdu[3] = SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM; /* service choice */ + apdu[3] = SERVICE_CONFIRMED_ACKNOWLEDGE_ALARM; /* service choice */ apdu_len = 4; len = alarm_ack_encode_service_request(&apdu[apdu_len], data); @@ -63,65 +61,53 @@ int alarm_ack_encode_apdu( return apdu_len; } - /*************************************************** ** ** Encodes the service data part of Event Notification ** ****************************************************/ -int alarm_ack_encode_service_request( - uint8_t * apdu, - BACNET_ALARM_ACK_DATA * data) +int alarm_ack_encode_service_request(uint8_t *apdu, BACNET_ALARM_ACK_DATA *data) { - int len = 0; /* length of each encoding */ - int apdu_len = 0; /* total length of the apdu, return value */ + int len = 0; /* length of each encoding */ + int apdu_len = 0; /* total length of the apdu, return value */ if (apdu) { - len = - encode_context_unsigned(&apdu[apdu_len], 0, - data->ackProcessIdentifier); + len = encode_context_unsigned(&apdu[apdu_len], 0, + data->ackProcessIdentifier); apdu_len += len; - len = - encode_context_object_id(&apdu[apdu_len], 1, - (int) data->eventObjectIdentifier.type, - data->eventObjectIdentifier.instance); + len = encode_context_object_id(&apdu[apdu_len], 1, + (int)data->eventObjectIdentifier.type, + data->eventObjectIdentifier.instance); apdu_len += len; - len = - encode_context_enumerated(&apdu[apdu_len], 2, - data->eventStateAcked); + len = encode_context_enumerated(&apdu[apdu_len], 2, + data->eventStateAcked); apdu_len += len; - len = - bacapp_encode_context_timestamp(&apdu[apdu_len], 3, - &data->eventTimeStamp); + len = bacapp_encode_context_timestamp(&apdu[apdu_len], 3, + &data->eventTimeStamp); apdu_len += len; - len = - encode_context_character_string(&apdu[apdu_len], 4, - &data->ackSource); + len = encode_context_character_string(&apdu[apdu_len], 4, + &data->ackSource); apdu_len += len; - len = - bacapp_encode_context_timestamp(&apdu[apdu_len], 5, - &data->ackTimeStamp); + len = bacapp_encode_context_timestamp(&apdu[apdu_len], 5, + &data->ackTimeStamp); apdu_len += len; } return apdu_len; } - /*************************************************** ** ** Decodes the service data part of Event Notification ** ****************************************************/ -int alarm_ack_decode_service_request( - uint8_t * apdu, - unsigned apdu_len, - BACNET_ALARM_ACK_DATA * data) +int alarm_ack_decode_service_request(uint8_t *apdu, unsigned apdu_len, + BACNET_ALARM_ACK_DATA *data) { int len = 0; int section_len; @@ -130,45 +116,40 @@ int alarm_ack_decode_service_request( /* unused parameter */ apdu_len = apdu_len; - if (-1 == (section_len = - decode_context_unsigned(&apdu[len], 0, - &data->ackProcessIdentifier))) { + if (-1 == (section_len = decode_context_unsigned( + &apdu[len], 0, &data->ackProcessIdentifier))) { return -1; } len += section_len; - if (-1 == (section_len = - decode_context_object_id(&apdu[len], 1, - &data->eventObjectIdentifier.type, - &data->eventObjectIdentifier.instance))) { + if (-1 == (section_len = decode_context_object_id( + &apdu[len], 1, &data->eventObjectIdentifier.type, + &data->eventObjectIdentifier.instance))) { return -1; } len += section_len; - if (-1 == (section_len = - decode_context_enumerated(&apdu[len], 2, &enumValue))) { + if (-1 == + (section_len = 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 = - bacapp_decode_context_timestamp(&apdu[len], 3, - &data->eventTimeStamp))) { + if (-1 == (section_len = bacapp_decode_context_timestamp( + &apdu[len], 3, &data->eventTimeStamp))) { return -1; } len += section_len; - if (-1 == (section_len = - decode_context_character_string(&apdu[len], 4, - &data->ackSource))) { + if (-1 == (section_len = decode_context_character_string( + &apdu[len], 4, &data->ackSource))) { return -1; } len += section_len; - if (-1 == (section_len = - bacapp_decode_context_timestamp(&apdu[len], 5, - &data->ackTimeStamp))) { + if (-1 == (section_len = bacapp_decode_context_timestamp( + &apdu[len], 5, &data->ackTimeStamp))) { return -1; } len += section_len; @@ -182,9 +163,7 @@ int alarm_ack_decode_service_request( #include #include "ctest.h" - -void testAlarmAck( - Test * pTest) +void testAlarmAck(Test *pTest) { BACNET_ALARM_ACK_DATA testAlarmAckIn; BACNET_ALARM_ACK_DATA testAlarmAckOut; @@ -208,58 +187,44 @@ void testAlarmAck( memset(&testAlarmAckOut, 0, sizeof(testAlarmAckOut)); - inLen = alarm_ack_encode_service_request(buffer, &testAlarmAckIn); outLen = alarm_ack_decode_service_request(buffer, inLen, &testAlarmAckOut); ct_test(pTest, inLen == outLen); - ct_test(pTest, - testAlarmAckIn.ackProcessIdentifier == - testAlarmAckOut.ackProcessIdentifier); + ct_test(pTest, testAlarmAckIn.ackProcessIdentifier == + testAlarmAckOut.ackProcessIdentifier); + + ct_test(pTest, testAlarmAckIn.ackTimeStamp.tag == + testAlarmAckOut.ackTimeStamp.tag); + ct_test(pTest, testAlarmAckIn.ackTimeStamp.value.sequenceNum == + testAlarmAckOut.ackTimeStamp.value.sequenceNum); + + ct_test(pTest, testAlarmAckIn.ackProcessIdentifier == + testAlarmAckOut.ackProcessIdentifier); + + ct_test(pTest, testAlarmAckIn.eventObjectIdentifier.instance == + testAlarmAckOut.eventObjectIdentifier.instance); + ct_test(pTest, testAlarmAckIn.eventObjectIdentifier.type == + testAlarmAckOut.eventObjectIdentifier.type); + + ct_test(pTest, testAlarmAckIn.eventTimeStamp.tag == + testAlarmAckOut.eventTimeStamp.tag); + ct_test(pTest, testAlarmAckIn.eventTimeStamp.value.time.hour == + testAlarmAckOut.eventTimeStamp.value.time.hour); + ct_test(pTest, testAlarmAckIn.eventTimeStamp.value.time.min == + testAlarmAckOut.eventTimeStamp.value.time.min); + ct_test(pTest, testAlarmAckIn.eventTimeStamp.value.time.sec == + testAlarmAckOut.eventTimeStamp.value.time.sec); + ct_test(pTest, testAlarmAckIn.eventTimeStamp.value.time.hundredths == + testAlarmAckOut.eventTimeStamp.value.time.hundredths); ct_test(pTest, - testAlarmAckIn.ackTimeStamp.tag == testAlarmAckOut.ackTimeStamp.tag); - ct_test(pTest, - testAlarmAckIn.ackTimeStamp.value.sequenceNum == - testAlarmAckOut.ackTimeStamp.value.sequenceNum); - - ct_test(pTest, - testAlarmAckIn.ackProcessIdentifier == - testAlarmAckOut.ackProcessIdentifier); - - ct_test(pTest, - testAlarmAckIn.eventObjectIdentifier.instance == - testAlarmAckOut.eventObjectIdentifier.instance); - ct_test(pTest, - testAlarmAckIn.eventObjectIdentifier.type == - testAlarmAckOut.eventObjectIdentifier.type); - - ct_test(pTest, - testAlarmAckIn.eventTimeStamp.tag == - testAlarmAckOut.eventTimeStamp.tag); - ct_test(pTest, - testAlarmAckIn.eventTimeStamp.value.time.hour == - testAlarmAckOut.eventTimeStamp.value.time.hour); - ct_test(pTest, - testAlarmAckIn.eventTimeStamp.value.time.min == - testAlarmAckOut.eventTimeStamp.value.time.min); - ct_test(pTest, - testAlarmAckIn.eventTimeStamp.value.time.sec == - testAlarmAckOut.eventTimeStamp.value.time.sec); - ct_test(pTest, - testAlarmAckIn.eventTimeStamp.value.time.hundredths == - testAlarmAckOut.eventTimeStamp.value.time.hundredths); - - ct_test(pTest, - testAlarmAckIn.eventStateAcked == testAlarmAckOut.eventStateAcked); - + testAlarmAckIn.eventStateAcked == testAlarmAckOut.eventStateAcked); } - #ifdef TEST_ALARM_ACK -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -271,7 +236,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/src/apdu.c b/src/apdu.c index 9dc93e67..ef3bfe4f 100644 --- a/src/apdu.c +++ b/src/apdu.c @@ -45,12 +45,10 @@ /** @file apdu.c Handles APDU services */ -extern int Routed_Device_Service_Approval( - BACNET_CONFIRMED_SERVICE service, - int service_argument, - uint8_t * apdu_buff, - uint8_t invoke_id); - +extern int Routed_Device_Service_Approval(BACNET_CONFIRMED_SERVICE service, + int service_argument, + uint8_t *apdu_buff, + uint8_t invoke_id); /* APDU Timeout in Milliseconds */ static uint16_t Timeout_Milliseconds = 3000; @@ -60,60 +58,57 @@ static uint8_t Number_Of_Retries = 3; /* a simple table for crossing the services supported */ static BACNET_SERVICES_SUPPORTED confirmed_service_supported[MAX_BACNET_CONFIRMED_SERVICE] = { - SERVICE_SUPPORTED_ACKNOWLEDGE_ALARM, - SERVICE_SUPPORTED_CONFIRMED_COV_NOTIFICATION, - SERVICE_SUPPORTED_CONFIRMED_EVENT_NOTIFICATION, - SERVICE_SUPPORTED_GET_ALARM_SUMMARY, - SERVICE_SUPPORTED_GET_ENROLLMENT_SUMMARY, - SERVICE_SUPPORTED_SUBSCRIBE_COV, - SERVICE_SUPPORTED_ATOMIC_READ_FILE, - SERVICE_SUPPORTED_ATOMIC_WRITE_FILE, - SERVICE_SUPPORTED_ADD_LIST_ELEMENT, - SERVICE_SUPPORTED_REMOVE_LIST_ELEMENT, - SERVICE_SUPPORTED_CREATE_OBJECT, - SERVICE_SUPPORTED_DELETE_OBJECT, - SERVICE_SUPPORTED_READ_PROPERTY, - SERVICE_SUPPORTED_READ_PROP_CONDITIONAL, - SERVICE_SUPPORTED_READ_PROP_MULTIPLE, - SERVICE_SUPPORTED_WRITE_PROPERTY, - SERVICE_SUPPORTED_WRITE_PROP_MULTIPLE, - SERVICE_SUPPORTED_DEVICE_COMMUNICATION_CONTROL, - SERVICE_SUPPORTED_PRIVATE_TRANSFER, - SERVICE_SUPPORTED_TEXT_MESSAGE, - SERVICE_SUPPORTED_REINITIALIZE_DEVICE, - SERVICE_SUPPORTED_VT_OPEN, - SERVICE_SUPPORTED_VT_CLOSE, - SERVICE_SUPPORTED_VT_DATA, - SERVICE_SUPPORTED_AUTHENTICATE, - SERVICE_SUPPORTED_REQUEST_KEY, - SERVICE_SUPPORTED_READ_RANGE, - SERVICE_SUPPORTED_LIFE_SAFETY_OPERATION, - SERVICE_SUPPORTED_SUBSCRIBE_COV_PROPERTY, - SERVICE_SUPPORTED_GET_EVENT_INFORMATION -}; + SERVICE_SUPPORTED_ACKNOWLEDGE_ALARM, + SERVICE_SUPPORTED_CONFIRMED_COV_NOTIFICATION, + SERVICE_SUPPORTED_CONFIRMED_EVENT_NOTIFICATION, + SERVICE_SUPPORTED_GET_ALARM_SUMMARY, + SERVICE_SUPPORTED_GET_ENROLLMENT_SUMMARY, + SERVICE_SUPPORTED_SUBSCRIBE_COV, + SERVICE_SUPPORTED_ATOMIC_READ_FILE, + SERVICE_SUPPORTED_ATOMIC_WRITE_FILE, + SERVICE_SUPPORTED_ADD_LIST_ELEMENT, + SERVICE_SUPPORTED_REMOVE_LIST_ELEMENT, + SERVICE_SUPPORTED_CREATE_OBJECT, + SERVICE_SUPPORTED_DELETE_OBJECT, + SERVICE_SUPPORTED_READ_PROPERTY, + SERVICE_SUPPORTED_READ_PROP_CONDITIONAL, + SERVICE_SUPPORTED_READ_PROP_MULTIPLE, + SERVICE_SUPPORTED_WRITE_PROPERTY, + SERVICE_SUPPORTED_WRITE_PROP_MULTIPLE, + SERVICE_SUPPORTED_DEVICE_COMMUNICATION_CONTROL, + SERVICE_SUPPORTED_PRIVATE_TRANSFER, + SERVICE_SUPPORTED_TEXT_MESSAGE, + SERVICE_SUPPORTED_REINITIALIZE_DEVICE, + SERVICE_SUPPORTED_VT_OPEN, + SERVICE_SUPPORTED_VT_CLOSE, + SERVICE_SUPPORTED_VT_DATA, + SERVICE_SUPPORTED_AUTHENTICATE, + SERVICE_SUPPORTED_REQUEST_KEY, + SERVICE_SUPPORTED_READ_RANGE, + SERVICE_SUPPORTED_LIFE_SAFETY_OPERATION, + SERVICE_SUPPORTED_SUBSCRIBE_COV_PROPERTY, + SERVICE_SUPPORTED_GET_EVENT_INFORMATION}; /* a simple table for crossing the services supported */ static BACNET_SERVICES_SUPPORTED unconfirmed_service_supported[MAX_BACNET_UNCONFIRMED_SERVICE] = { - SERVICE_SUPPORTED_I_AM, - SERVICE_SUPPORTED_I_HAVE, - SERVICE_SUPPORTED_UNCONFIRMED_COV_NOTIFICATION, - SERVICE_SUPPORTED_UNCONFIRMED_EVENT_NOTIFICATION, - SERVICE_SUPPORTED_UNCONFIRMED_PRIVATE_TRANSFER, - SERVICE_SUPPORTED_UNCONFIRMED_TEXT_MESSAGE, - SERVICE_SUPPORTED_TIME_SYNCHRONIZATION, - SERVICE_SUPPORTED_WHO_HAS, - SERVICE_SUPPORTED_WHO_IS, - SERVICE_SUPPORTED_UTC_TIME_SYNCHRONIZATION -}; + SERVICE_SUPPORTED_I_AM, + SERVICE_SUPPORTED_I_HAVE, + SERVICE_SUPPORTED_UNCONFIRMED_COV_NOTIFICATION, + SERVICE_SUPPORTED_UNCONFIRMED_EVENT_NOTIFICATION, + SERVICE_SUPPORTED_UNCONFIRMED_PRIVATE_TRANSFER, + SERVICE_SUPPORTED_UNCONFIRMED_TEXT_MESSAGE, + SERVICE_SUPPORTED_TIME_SYNCHRONIZATION, + SERVICE_SUPPORTED_WHO_HAS, + SERVICE_SUPPORTED_WHO_IS, + SERVICE_SUPPORTED_UTC_TIME_SYNCHRONIZATION}; /* Confirmed Function Handlers */ /* If they are not set, they are handled by a reject message */ static confirmed_function Confirmed_Function[MAX_BACNET_CONFIRMED_SERVICE]; -void apdu_set_confirmed_handler( - BACNET_CONFIRMED_SERVICE service_choice, - confirmed_function pFunction) +void apdu_set_confirmed_handler(BACNET_CONFIRMED_SERVICE service_choice, + confirmed_function pFunction) { if (service_choice < MAX_BACNET_CONFIRMED_SERVICE) Confirmed_Function[service_choice] = pFunction; @@ -122,8 +117,7 @@ void apdu_set_confirmed_handler( /* Allow the APDU handler to automatically reject */ static confirmed_function Unrecognized_Service_Handler; -void apdu_set_unrecognized_service_handler_handler( - confirmed_function pFunction) +void apdu_set_unrecognized_service_handler_handler(confirmed_function pFunction) { Unrecognized_Service_Handler = pFunction; } @@ -133,16 +127,14 @@ void apdu_set_unrecognized_service_handler_handler( static unconfirmed_function Unconfirmed_Function[MAX_BACNET_UNCONFIRMED_SERVICE]; -void apdu_set_unconfirmed_handler( - BACNET_UNCONFIRMED_SERVICE service_choice, - unconfirmed_function pFunction) +void apdu_set_unconfirmed_handler(BACNET_UNCONFIRMED_SERVICE service_choice, + unconfirmed_function pFunction) { if (service_choice < MAX_BACNET_UNCONFIRMED_SERVICE) Unconfirmed_Function[service_choice] = pFunction; } -bool apdu_service_supported( - BACNET_SERVICES_SUPPORTED service_supported) +bool apdu_service_supported(BACNET_SERVICES_SUPPORTED service_supported) { int i = 0; bool status = false; @@ -155,12 +147,12 @@ bool apdu_service_supported( found = true; if (Confirmed_Function[i] != NULL) { #if BAC_ROUTING - /* Check to see if the current Device supports this service. */ - int len = - Routed_Device_Service_Approval(service_supported, 0, - NULL, 0); + /* Check to see if the current Device supports this service. + */ + int len = Routed_Device_Service_Approval(service_supported, + 0, NULL, 0); if (len > 0) - break; /* Not supported - return false */ + break; /* Not supported - return false */ #endif status = true; @@ -194,9 +186,8 @@ bool apdu_service_supported( * @return True if a match was found and index and bIsConfirmed are valid. */ bool apdu_service_supported_to_index( - BACNET_SERVICES_SUPPORTED service_supported, - size_t * index, - bool * bIsConfirmed) + BACNET_SERVICES_SUPPORTED service_supported, size_t *index, + bool *bIsConfirmed) { int i = 0; bool found = false; @@ -207,7 +198,7 @@ bool apdu_service_supported_to_index( for (i = 0; i < MAX_BACNET_CONFIRMED_SERVICE; i++) { if (confirmed_service_supported[i] == service_supported) { found = true; - *index = (size_t) i; + *index = (size_t)i; *bIsConfirmed = true; break; } @@ -218,7 +209,7 @@ bool apdu_service_supported_to_index( for (i = 0; i < MAX_BACNET_UNCONFIRMED_SERVICE; i++) { if (unconfirmed_service_supported[i] == service_supported) { found = true; - *index = (size_t) i; + *index = (size_t)i; break; } } @@ -257,16 +248,15 @@ void apdu_set_confirmed_simple_ack_handler( /* Security Services */ case SERVICE_CONFIRMED_REQUEST_KEY: Confirmed_ACK_Function[service_choice] = - (confirmed_ack_function) pFunction; + (confirmed_ack_function)pFunction; break; default: break; } } -void apdu_set_confirmed_ack_handler( - BACNET_CONFIRMED_SERVICE service_choice, - confirmed_ack_function pFunction) +void apdu_set_confirmed_ack_handler(BACNET_CONFIRMED_SERVICE service_choice, + confirmed_ack_function pFunction) { switch (service_choice) { case SERVICE_CONFIRMED_GET_ALARM_SUMMARY: @@ -297,9 +287,8 @@ void apdu_set_confirmed_ack_handler( static error_function Error_Function[MAX_BACNET_CONFIRMED_SERVICE]; -void apdu_set_error_handler( - BACNET_CONFIRMED_SERVICE service_choice, - error_function pFunction) +void apdu_set_error_handler(BACNET_CONFIRMED_SERVICE service_choice, + error_function pFunction) { if (service_choice < MAX_BACNET_CONFIRMED_SERVICE) Error_Function[service_choice] = pFunction; @@ -307,29 +296,25 @@ void apdu_set_error_handler( static abort_function Abort_Function; -void apdu_set_abort_handler( - abort_function pFunction) +void apdu_set_abort_handler(abort_function pFunction) { Abort_Function = pFunction; } static reject_function Reject_Function; -void apdu_set_reject_handler( - reject_function pFunction) +void apdu_set_reject_handler(reject_function pFunction) { Reject_Function = pFunction; } uint16_t apdu_decode_confirmed_service_request( - uint8_t * apdu, /* APDU data */ - uint16_t apdu_len, - BACNET_CONFIRMED_SERVICE_DATA * service_data, - uint8_t * service_choice, - uint8_t ** service_request, - uint16_t * service_request_len) + uint8_t *apdu, /* APDU data */ + uint16_t apdu_len, BACNET_CONFIRMED_SERVICE_DATA *service_data, + uint8_t *service_choice, uint8_t **service_request, + uint16_t *service_request_len) { - uint16_t len = 0; /* counts where we are in PDU */ + uint16_t len = 0; /* counts where we are in PDU */ service_data->segmented_message = (apdu[0] & BIT(3)) ? true : false; service_data->more_follows = (apdu[0] & BIT(2)) ? true : false; @@ -350,39 +335,33 @@ uint16_t apdu_decode_confirmed_service_request( return len; } -uint16_t apdu_timeout( - void) +uint16_t apdu_timeout(void) { return Timeout_Milliseconds; } -void apdu_timeout_set( - uint16_t milliseconds) +void apdu_timeout_set(uint16_t milliseconds) { Timeout_Milliseconds = milliseconds; } -uint8_t apdu_retries( - void) +uint8_t apdu_retries(void) { return Number_Of_Retries; } -void apdu_retries_set( - uint8_t value) +void apdu_retries_set(uint8_t value) { Number_Of_Retries = value; } - /* When network communications are completely disabled, only DeviceCommunicationControl and ReinitializeDevice APDUs shall be processed and no messages shall be initiated. When the initiation of communications is disabled, all APDUs shall be processed and responses returned as required... */ -static bool apdu_confirmed_dcc_disabled( - uint8_t service_choice) +static bool apdu_confirmed_dcc_disabled(uint8_t service_choice) { bool status = false; @@ -407,8 +386,7 @@ static bool apdu_confirmed_dcc_disabled( DISABLE_INITIATION, the responding BACnet-user shall discontinue the initiation of messages except for I-Am requests issued in accordance with the Who-Is service procedure.*/ -static bool apdu_unconfirmed_dcc_disabled( - uint8_t service_choice) +static bool apdu_unconfirmed_dcc_disabled(uint8_t service_choice) { bool status = false; @@ -439,18 +417,16 @@ static bool apdu_unconfirmed_dcc_disabled( * @param apdu [in] The apdu portion of the request, to be processed. * @param apdu_len [in] The total (remaining) length of the apdu. */ -void apdu_handler( - BACNET_ADDRESS * src, - uint8_t * apdu, /* APDU data */ - uint16_t apdu_len) +void apdu_handler(BACNET_ADDRESS *src, uint8_t *apdu, /* APDU data */ + uint16_t apdu_len) { - BACNET_CONFIRMED_SERVICE_DATA service_data = { 0 }; - BACNET_CONFIRMED_SERVICE_ACK_DATA service_ack_data = { 0 }; + BACNET_CONFIRMED_SERVICE_DATA service_data = {0}; + BACNET_CONFIRMED_SERVICE_ACK_DATA service_ack_data = {0}; uint8_t invoke_id = 0; uint8_t service_choice = 0; uint8_t *service_request = NULL; uint16_t service_request_len = 0; - int len = 0; /* counts where we are in PDU */ + int len = 0; /* counts where we are in PDU */ uint8_t tag_number = 0; uint32_t len_value = 0; uint32_t error_code = 0; @@ -462,22 +438,25 @@ void apdu_handler( /* PDU Type */ switch (apdu[0] & 0xF0) { case PDU_TYPE_CONFIRMED_SERVICE_REQUEST: - (void)apdu_decode_confirmed_service_request(&apdu[0], - apdu_len, &service_data, &service_choice, &service_request, - &service_request_len); + (void)apdu_decode_confirmed_service_request( + &apdu[0], apdu_len, &service_data, &service_choice, + &service_request, &service_request_len); if (apdu_confirmed_dcc_disabled(service_choice)) { /* When network communications are completely disabled, - only DeviceCommunicationControl and ReinitializeDevice APDUs - shall be processed and no messages shall be initiated. */ + only DeviceCommunicationControl and ReinitializeDevice + APDUs shall be processed and no messages shall be + initiated. */ break; } if ((service_choice < MAX_BACNET_CONFIRMED_SERVICE) && (Confirmed_Function[service_choice])) - Confirmed_Function[service_choice] (service_request, - service_request_len, src, &service_data); + Confirmed_Function[service_choice](service_request, + service_request_len, src, + &service_data); else if (Unrecognized_Service_Handler) Unrecognized_Service_Handler(service_request, - service_request_len, src, &service_data); + service_request_len, src, + &service_data); break; case PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST: service_choice = apdu[1]; @@ -485,16 +464,16 @@ void apdu_handler( service_request_len = apdu_len - 2; if (apdu_unconfirmed_dcc_disabled(service_choice)) { /* When network communications are disabled, - only DeviceCommunicationControl and ReinitializeDevice APDUs - shall be processed and no messages shall be initiated. - If communications have been initiation disabled, then - WhoIs may be processed. */ + only DeviceCommunicationControl and ReinitializeDevice + APDUs shall be processed and no messages shall be + initiated. If communications have been initiation + disabled, then WhoIs may be processed. */ break; } if (service_choice < MAX_BACNET_UNCONFIRMED_SERVICE) { if (Unconfirmed_Function[service_choice]) - Unconfirmed_Function[service_choice] (service_request, - service_request_len, src); + Unconfirmed_Function[service_choice]( + service_request, service_request_len, src); } break; case PDU_TYPE_SIMPLE_ACK: @@ -523,8 +502,8 @@ void apdu_handler( case SERVICE_CONFIRMED_REQUEST_KEY: if (Confirmed_ACK_Function[service_choice] != NULL) { ((confirmed_simple_ack_function) - Confirmed_ACK_Function[service_choice]) (src, - invoke_id); + Confirmed_ACK_Function[service_choice])( + src, invoke_id); } tsm_free_invoke_id(invoke_id); break; @@ -545,7 +524,7 @@ void apdu_handler( } service_choice = apdu[len++]; service_request = &apdu[len]; - service_request_len = apdu_len - (uint16_t) len; + service_request_len = apdu_len - (uint16_t)len; switch (service_choice) { case SERVICE_CONFIRMED_GET_ALARM_SUMMARY: case SERVICE_CONFIRMED_GET_ENROLLMENT_SUMMARY: @@ -566,8 +545,8 @@ void apdu_handler( /* Security Services */ case SERVICE_CONFIRMED_AUTHENTICATE: if (Confirmed_ACK_Function[service_choice] != NULL) { - (Confirmed_ACK_Function[service_choice]) - (service_request, service_request_len, src, + (Confirmed_ACK_Function[service_choice])( + service_request, service_request_len, src, &service_ack_data); } tsm_free_invoke_id(invoke_id); @@ -586,37 +565,42 @@ void apdu_handler( service_choice = apdu[2]; len = 3; - /* FIXME: Currently special case for C_P_T but there are others which may - need consideration such as ChangeList-Error, CreateObject-Error, - WritePropertyMultiple-Error and VTClose_Error but they may be left as - is for now until support for these services is added */ + /* FIXME: Currently special case for C_P_T but there are others + which may need consideration such as ChangeList-Error, + CreateObject-Error, WritePropertyMultiple-Error and + VTClose_Error but they may be left as is for now until + support for these services is added */ - if (service_choice == SERVICE_CONFIRMED_PRIVATE_TRANSFER) { /* skip over opening tag 0 */ + if (service_choice == + SERVICE_CONFIRMED_PRIVATE_TRANSFER) { /* skip over opening + tag 0 */ if (decode_is_opening_tag_number(&apdu[len], 0)) { - len++; /* a tag number of 0 is not extended so only one octet */ + len++; /* a tag number of 0 is not extended so only one + octet */ } } - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value); /* FIXME: we could validate that the tag is enumerated... */ len += decode_enumerated(&apdu[len], len_value, &error_class); - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value); /* FIXME: we could validate that the tag is enumerated... */ len += decode_enumerated(&apdu[len], len_value, &error_code); - if (service_choice == SERVICE_CONFIRMED_PRIVATE_TRANSFER) { /* skip over closing tag 0 */ + if (service_choice == + SERVICE_CONFIRMED_PRIVATE_TRANSFER) { /* skip over closing + tag 0 */ if (decode_is_closing_tag_number(&apdu[len], 0)) { - len++; /* a tag number of 0 is not extended so only one octet */ + len++; /* a tag number of 0 is not extended so only one + octet */ } } if (service_choice < MAX_BACNET_CONFIRMED_SERVICE) { if (Error_Function[service_choice]) - Error_Function[service_choice] (src, invoke_id, - (BACNET_ERROR_CLASS) error_class, - (BACNET_ERROR_CODE) error_code); + Error_Function[service_choice]( + src, invoke_id, (BACNET_ERROR_CLASS)error_class, + (BACNET_ERROR_CODE)error_code); } tsm_free_invoke_id(invoke_id); break; diff --git a/src/arf.c b/src/arf.c index 5b0c8b69..eb7cc939 100644 --- a/src/arf.c +++ b/src/arf.c @@ -40,41 +40,34 @@ /** @file arf.c Atomic Read File */ /* encode service */ -int arf_encode_apdu( - uint8_t * apdu, - uint8_t invoke_id, - BACNET_ATOMIC_READ_FILE_DATA * data) +int arf_encode_apdu(uint8_t *apdu, uint8_t invoke_id, + BACNET_ATOMIC_READ_FILE_DATA *data) { - 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; apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU); apdu[2] = invoke_id; - apdu[3] = SERVICE_CONFIRMED_ATOMIC_READ_FILE; /* service choice */ + apdu[3] = SERVICE_CONFIRMED_ATOMIC_READ_FILE; /* service choice */ apdu_len = 4; - apdu_len += - encode_application_object_id(&apdu[apdu_len], data->object_type, - data->object_instance); + apdu_len += encode_application_object_id( + &apdu[apdu_len], data->object_type, data->object_instance); switch (data->access) { case FILE_STREAM_ACCESS: apdu_len += encode_opening_tag(&apdu[apdu_len], 0); - apdu_len += - encode_application_signed(&apdu[apdu_len], - data->type.stream.fileStartPosition); - apdu_len += - encode_application_unsigned(&apdu[apdu_len], - data->type.stream.requestedOctetCount); + apdu_len += encode_application_signed( + &apdu[apdu_len], data->type.stream.fileStartPosition); + apdu_len += encode_application_unsigned( + &apdu[apdu_len], data->type.stream.requestedOctetCount); apdu_len += encode_closing_tag(&apdu[apdu_len], 0); break; case FILE_RECORD_ACCESS: apdu_len += encode_opening_tag(&apdu[apdu_len], 1); - apdu_len += - encode_application_signed(&apdu[apdu_len], - data->type.record.fileStartRecord); - apdu_len += - encode_application_unsigned(&apdu[apdu_len], - data->type.record.RecordCount); + apdu_len += encode_application_signed( + &apdu[apdu_len], data->type.record.fileStartRecord); + apdu_len += encode_application_unsigned( + &apdu[apdu_len], data->type.record.RecordCount); apdu_len += encode_closing_tag(&apdu[apdu_len], 1); break; default: @@ -86,50 +79,43 @@ int arf_encode_apdu( } /* decode the service request only */ -int arf_decode_service_request( - uint8_t * apdu, - unsigned apdu_len, - BACNET_ATOMIC_READ_FILE_DATA * data) +int arf_decode_service_request(uint8_t *apdu, unsigned apdu_len, + BACNET_ATOMIC_READ_FILE_DATA *data) { int len = 0; int tag_len = 0; uint8_t tag_number = 0; uint32_t len_value_type = 0; - uint16_t type = 0; /* for decoding */ + uint16_t type = 0; /* for decoding */ /* check for value pointers */ if (apdu_len && data) { len = - decode_tag_number_and_value(&apdu[0], &tag_number, - &len_value_type); + decode_tag_number_and_value(&apdu[0], &tag_number, &len_value_type); if (tag_number != BACNET_APPLICATION_TAG_OBJECT_ID) return -1; len += decode_object_id(&apdu[len], &type, &data->object_instance); - data->object_type = (BACNET_OBJECT_TYPE) type; + data->object_type = (BACNET_OBJECT_TYPE)type; if (decode_is_opening_tag_number(&apdu[len], 0)) { data->access = FILE_STREAM_ACCESS; /* a tag number is not extended so only one octet */ len++; /* fileStartPosition */ - tag_len = - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value_type); + tag_len = decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value_type); len += tag_len; if (tag_number != BACNET_APPLICATION_TAG_SIGNED_INT) return -1; - len += - decode_signed(&apdu[len], len_value_type, - &data->type.stream.fileStartPosition); + len += decode_signed(&apdu[len], len_value_type, + &data->type.stream.fileStartPosition); /* requestedOctetCount */ - tag_len = - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value_type); + tag_len = decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value_type); len += tag_len; if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT) return -1; - len += - decode_unsigned(&apdu[len], len_value_type, - &data->type.stream.requestedOctetCount); + len += decode_unsigned(&apdu[len], len_value_type, + &data->type.stream.requestedOctetCount); if (!decode_is_closing_tag_number(&apdu[len], 0)) return -1; /* a tag number is not extended so only one octet */ @@ -139,25 +125,21 @@ int arf_decode_service_request( /* a tag number is not extended so only one octet */ len++; /* fileStartRecord */ - tag_len = - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value_type); + tag_len = decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value_type); len += tag_len; if (tag_number != BACNET_APPLICATION_TAG_SIGNED_INT) return -1; - len += - decode_signed(&apdu[len], len_value_type, - &data->type.record.fileStartRecord); + len += decode_signed(&apdu[len], len_value_type, + &data->type.record.fileStartRecord); /* RecordCount */ - tag_len = - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value_type); + tag_len = decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value_type); len += tag_len; if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT) return -1; - len += - decode_unsigned(&apdu[len], len_value_type, - &data->type.record.RecordCount); + len += decode_unsigned(&apdu[len], len_value_type, + &data->type.record.RecordCount); if (!decode_is_closing_tag_number(&apdu[len], 1)) return -1; /* a tag number is not extended so only one octet */ @@ -169,11 +151,8 @@ int arf_decode_service_request( return len; } -int arf_decode_apdu( - uint8_t * apdu, - unsigned apdu_len, - uint8_t * invoke_id, - BACNET_ATOMIC_READ_FILE_DATA * data) +int arf_decode_apdu(uint8_t *apdu, unsigned apdu_len, uint8_t *invoke_id, + BACNET_ATOMIC_READ_FILE_DATA *data) { int len = 0; unsigned offset = 0; @@ -184,7 +163,7 @@ int arf_decode_apdu( if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST) return -1; /* apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU); */ - *invoke_id = apdu[2]; /* invoke id - filled in by net layer */ + *invoke_id = apdu[2]; /* invoke id - filled in by net layer */ if (apdu[3] != SERVICE_CONFIRMED_ATOMIC_READ_FILE) return -1; offset = 4; @@ -198,18 +177,16 @@ int arf_decode_apdu( } /* encode service */ -int arf_ack_encode_apdu( - uint8_t * apdu, - uint8_t invoke_id, - BACNET_ATOMIC_READ_FILE_DATA * data) +int arf_ack_encode_apdu(uint8_t *apdu, uint8_t invoke_id, + BACNET_ATOMIC_READ_FILE_DATA *data) { - int apdu_len = 0; /* total length of the apdu, return value */ + int apdu_len = 0; /* total length of the apdu, return value */ uint32_t i = 0; if (apdu) { apdu[0] = PDU_TYPE_COMPLEX_ACK; apdu[1] = invoke_id; - apdu[2] = SERVICE_CONFIRMED_ATOMIC_READ_FILE; /* service choice */ + apdu[2] = SERVICE_CONFIRMED_ATOMIC_READ_FILE; /* service choice */ apdu_len = 3; /* endOfFile */ apdu_len += @@ -217,26 +194,21 @@ int arf_ack_encode_apdu( switch (data->access) { case FILE_STREAM_ACCESS: apdu_len += encode_opening_tag(&apdu[apdu_len], 0); - apdu_len += - encode_application_signed(&apdu[apdu_len], - data->type.stream.fileStartPosition); - apdu_len += - encode_application_octet_string(&apdu[apdu_len], - &data->fileData[0]); + apdu_len += encode_application_signed( + &apdu[apdu_len], data->type.stream.fileStartPosition); + apdu_len += encode_application_octet_string(&apdu[apdu_len], + &data->fileData[0]); apdu_len += encode_closing_tag(&apdu[apdu_len], 0); break; case FILE_RECORD_ACCESS: apdu_len += encode_opening_tag(&apdu[apdu_len], 1); - apdu_len += - encode_application_signed(&apdu[apdu_len], - data->type.record.fileStartRecord); - apdu_len += - encode_application_unsigned(&apdu[apdu_len], - data->type.record.RecordCount); + apdu_len += encode_application_signed( + &apdu[apdu_len], data->type.record.fileStartRecord); + apdu_len += encode_application_unsigned( + &apdu[apdu_len], data->type.record.RecordCount); for (i = 0; i < data->type.record.RecordCount; i++) { - apdu_len += - encode_application_octet_string(&apdu[apdu_len], - &data->fileData[i]); + apdu_len += encode_application_octet_string( + &apdu[apdu_len], &data->fileData[i]); } apdu_len += encode_closing_tag(&apdu[apdu_len], 1); break; @@ -249,10 +221,8 @@ int arf_ack_encode_apdu( } /* decode the service request only */ -int arf_ack_decode_service_request( - uint8_t * apdu, - unsigned apdu_len, - BACNET_ATOMIC_READ_FILE_DATA * data) +int arf_ack_decode_service_request(uint8_t *apdu, unsigned apdu_len, + BACNET_ATOMIC_READ_FILE_DATA *data) { int len = 0; int tag_len = 0; @@ -264,8 +234,7 @@ int arf_ack_decode_service_request( /* check for value pointers */ if (apdu_len && data) { len = - decode_tag_number_and_value(&apdu[0], &tag_number, - &len_value_type); + decode_tag_number_and_value(&apdu[0], &tag_number, &len_value_type); if (tag_number != BACNET_APPLICATION_TAG_BOOLEAN) { return -1; } @@ -275,27 +244,23 @@ int arf_ack_decode_service_request( /* a tag number is not extended so only one octet */ len++; /* fileStartPosition */ - tag_len = - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value_type); + tag_len = decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value_type); len += tag_len; if (tag_number != BACNET_APPLICATION_TAG_SIGNED_INT) { return -1; } - len += - decode_signed(&apdu[len], len_value_type, - &data->type.stream.fileStartPosition); + len += decode_signed(&apdu[len], len_value_type, + &data->type.stream.fileStartPosition); /* fileData */ - tag_len = - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value_type); + tag_len = decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value_type); len += tag_len; if (tag_number != BACNET_APPLICATION_TAG_OCTET_STRING) { return -1; } - decoded_len = - decode_octet_string(&apdu[len], len_value_type, - &data->fileData[0]); + decoded_len = decode_octet_string(&apdu[len], len_value_type, + &data->fileData[0]); if ((uint32_t)decoded_len != len_value_type) { return -1; } @@ -310,39 +275,33 @@ int arf_ack_decode_service_request( /* a tag number is not extended so only one octet */ len++; /* fileStartRecord */ - tag_len = - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value_type); + tag_len = decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value_type); len += tag_len; if (tag_number != BACNET_APPLICATION_TAG_SIGNED_INT) { return -1; } - len += - decode_signed(&apdu[len], len_value_type, - &data->type.record.fileStartRecord); + len += decode_signed(&apdu[len], len_value_type, + &data->type.record.fileStartRecord); /* returnedRecordCount */ - tag_len = - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value_type); + tag_len = decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value_type); len += tag_len; if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT) { return -1; } - len += - decode_unsigned(&apdu[len], len_value_type, - &data->type.record.RecordCount); + len += decode_unsigned(&apdu[len], len_value_type, + &data->type.record.RecordCount); for (i = 0; i < data->type.record.RecordCount; i++) { /* fileData */ - tag_len = - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value_type); + tag_len = decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value_type); len += tag_len; if (tag_number != BACNET_APPLICATION_TAG_OCTET_STRING) { return -1; } - decoded_len = - decode_octet_string(&apdu[len], len_value_type, - &data->fileData[i]); + decoded_len = decode_octet_string(&apdu[len], len_value_type, + &data->fileData[i]); if ((uint32_t)decoded_len != len_value_type) { return -1; } @@ -361,11 +320,8 @@ int arf_ack_decode_service_request( return len; } -int arf_ack_decode_apdu( - uint8_t * apdu, - unsigned apdu_len, - uint8_t * invoke_id, - BACNET_ATOMIC_READ_FILE_DATA * data) +int arf_ack_decode_apdu(uint8_t *apdu, unsigned apdu_len, uint8_t *invoke_id, + BACNET_ATOMIC_READ_FILE_DATA *data) { int len = 0; unsigned offset = 0; @@ -375,32 +331,29 @@ int arf_ack_decode_apdu( /* optional checking - most likely was already done prior to this call */ if (apdu[0] != PDU_TYPE_COMPLEX_ACK) return -1; - *invoke_id = apdu[1]; /* invoke id - filled in by net layer */ + *invoke_id = apdu[1]; /* invoke id - filled in by net layer */ if (apdu[2] != SERVICE_CONFIRMED_ATOMIC_READ_FILE) return -1; offset = 3; if (apdu_len > offset) { - len = - arf_ack_decode_service_request(&apdu[offset], apdu_len - offset, - data); + len = arf_ack_decode_service_request(&apdu[offset], apdu_len - offset, + data); } return len; } - #ifdef TEST #include #include #include "ctest.h" -void testAtomicReadFileAckAccess( - Test * pTest, - BACNET_ATOMIC_READ_FILE_DATA * data) +void testAtomicReadFileAckAccess(Test *pTest, + BACNET_ATOMIC_READ_FILE_DATA *data) { - BACNET_ATOMIC_READ_FILE_DATA test_data = { 0 }; - uint8_t apdu[480] = { 0 }; + BACNET_ATOMIC_READ_FILE_DATA test_data = {0}; + uint8_t apdu[480] = {0}; int len = 0; int apdu_len = 0; uint8_t invoke_id = 128; @@ -416,37 +369,32 @@ void testAtomicReadFileAckAccess( ct_test(pTest, test_data.endOfFile == data->endOfFile); ct_test(pTest, test_data.access == data->access); if (test_data.access == FILE_STREAM_ACCESS) { - ct_test(pTest, - test_data.type.stream.fileStartPosition == - data->type.stream.fileStartPosition); - ct_test(pTest, - octetstring_length(&test_data.fileData[0]) == - octetstring_length(&data->fileData[0])); + ct_test(pTest, test_data.type.stream.fileStartPosition == + data->type.stream.fileStartPosition); + ct_test(pTest, octetstring_length(&test_data.fileData[0]) == + octetstring_length(&data->fileData[0])); ct_test(pTest, memcmp(octetstring_value(&test_data.fileData[0]), - octetstring_value(&data->fileData[0]), - octetstring_length(&test_data.fileData[0])) == 0); + octetstring_value(&data->fileData[0]), + octetstring_length(&test_data.fileData[0])) == 0); } else if (test_data.access == FILE_RECORD_ACCESS) { - ct_test(pTest, - test_data.type.record.fileStartRecord == - data->type.record.fileStartRecord); - ct_test(pTest, - test_data.type.record.RecordCount == - data->type.record.RecordCount); + ct_test(pTest, test_data.type.record.fileStartRecord == + data->type.record.fileStartRecord); + ct_test(pTest, test_data.type.record.RecordCount == + data->type.record.RecordCount); for (i = 0; i < data->type.record.RecordCount; i++) { + ct_test(pTest, octetstring_length(&test_data.fileData[i]) == + octetstring_length(&data->fileData[i])); ct_test(pTest, - octetstring_length(&test_data.fileData[i]) == - octetstring_length(&data->fileData[i])); - ct_test(pTest, memcmp(octetstring_value(&test_data.fileData[i]), - octetstring_value(&data->fileData[i]), - octetstring_length(&test_data.fileData[i])) == 0); + memcmp(octetstring_value(&test_data.fileData[i]), + octetstring_value(&data->fileData[i]), + octetstring_length(&test_data.fileData[i])) == 0); } } } -void testAtomicReadFileAck( - Test * pTest) +void testAtomicReadFileAck(Test *pTest) { - BACNET_ATOMIC_READ_FILE_DATA data = { 0 }; + BACNET_ATOMIC_READ_FILE_DATA data = {0}; uint8_t test_octet_string[32] = "Joshua-Mary-Anna-Christopher"; unsigned int i = 0; @@ -454,7 +402,7 @@ void testAtomicReadFileAck( data.access = FILE_STREAM_ACCESS; data.type.stream.fileStartPosition = 0; octetstring_init(&data.fileData[0], test_octet_string, - sizeof(test_octet_string)); + sizeof(test_octet_string)); testAtomicReadFileAckAccess(pTest, &data); data.endOfFile = false; @@ -463,19 +411,17 @@ void testAtomicReadFileAck( data.type.record.RecordCount = BACNET_READ_FILE_RECORD_COUNT; for (i = 0; i < data.type.record.RecordCount; i++) { octetstring_init(&data.fileData[i], test_octet_string, - sizeof(test_octet_string)); + sizeof(test_octet_string)); } testAtomicReadFileAckAccess(pTest, &data); return; } -void testAtomicReadFileAccess( - Test * pTest, - BACNET_ATOMIC_READ_FILE_DATA * data) +void testAtomicReadFileAccess(Test *pTest, BACNET_ATOMIC_READ_FILE_DATA *data) { - BACNET_ATOMIC_READ_FILE_DATA test_data = { 0 }; - uint8_t apdu[480] = { 0 }; + BACNET_ATOMIC_READ_FILE_DATA test_data = {0}; + uint8_t apdu[480] = {0}; int len = 0; int apdu_len = 0; uint8_t invoke_id = 128; @@ -491,26 +437,21 @@ void testAtomicReadFileAccess( ct_test(pTest, test_data.object_instance == data->object_instance); ct_test(pTest, test_data.access == data->access); if (test_data.access == FILE_STREAM_ACCESS) { - ct_test(pTest, - test_data.type.stream.fileStartPosition == - data->type.stream.fileStartPosition); - ct_test(pTest, - test_data.type.stream.requestedOctetCount == - data->type.stream.requestedOctetCount); + ct_test(pTest, test_data.type.stream.fileStartPosition == + data->type.stream.fileStartPosition); + ct_test(pTest, test_data.type.stream.requestedOctetCount == + data->type.stream.requestedOctetCount); } else if (test_data.access == FILE_RECORD_ACCESS) { - ct_test(pTest, - test_data.type.record.fileStartRecord == - data->type.record.fileStartRecord); - ct_test(pTest, - test_data.type.record.RecordCount == - data->type.record.RecordCount); + ct_test(pTest, test_data.type.record.fileStartRecord == + data->type.record.fileStartRecord); + ct_test(pTest, test_data.type.record.RecordCount == + data->type.record.RecordCount); } } -void testAtomicReadFile( - Test * pTest) +void testAtomicReadFile(Test *pTest) { - BACNET_ATOMIC_READ_FILE_DATA data = { 0 }; + BACNET_ATOMIC_READ_FILE_DATA data = {0}; data.object_type = OBJECT_FILE; data.object_instance = 1; @@ -530,8 +471,7 @@ void testAtomicReadFile( } #ifdef TEST_ATOMIC_READ_FILE -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -545,7 +485,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/src/assigned_access_rights.c b/src/assigned_access_rights.c index c1cabd4c..35495f33 100644 --- a/src/assigned_access_rights.c +++ b/src/assigned_access_rights.c @@ -1,42 +1,39 @@ /************************************************************************** -* -* Copyright (C) 2015 Nikola Jelic -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2015 Nikola Jelic + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include "assigned_access_rights.h" #include "bacdcode.h" - -int bacapp_encode_assigned_access_rights( - uint8_t * apdu, - BACNET_ASSIGNED_ACCESS_RIGHTS * aar) +int bacapp_encode_assigned_access_rights(uint8_t* apdu, + BACNET_ASSIGNED_ACCESS_RIGHTS* aar) { int len; int apdu_len = 0; - len = - bacapp_encode_context_device_obj_ref(&apdu[apdu_len], 0, - &aar->assigned_access_rights); + len = bacapp_encode_context_device_obj_ref(&apdu[apdu_len], 0, + &aar->assigned_access_rights); if (len < 0) return -1; else @@ -52,9 +49,7 @@ int bacapp_encode_assigned_access_rights( } int bacapp_encode_context_assigned_access_rights( - uint8_t * apdu, - uint8_t tag, - BACNET_ASSIGNED_ACCESS_RIGHTS * aar) + uint8_t* apdu, uint8_t tag, BACNET_ASSIGNED_ACCESS_RIGHTS* aar) { int len; int apdu_len = 0; @@ -69,20 +64,17 @@ int bacapp_encode_context_assigned_access_rights( apdu_len += len; return apdu_len; - } -int bacapp_decode_assigned_access_rights( - uint8_t * apdu, - BACNET_ASSIGNED_ACCESS_RIGHTS * aar) +int bacapp_decode_assigned_access_rights(uint8_t* apdu, + BACNET_ASSIGNED_ACCESS_RIGHTS* aar) { int len; int apdu_len = 0; if (decode_is_context_tag(&apdu[apdu_len], 0)) { - len = - bacapp_decode_context_device_obj_ref(&apdu[apdu_len], 0, - &aar->assigned_access_rights); + len = bacapp_decode_context_device_obj_ref( + &apdu[apdu_len], 0, &aar->assigned_access_rights); if (len < 0) return -1; else @@ -103,9 +95,7 @@ int bacapp_decode_assigned_access_rights( } int bacapp_decode_context_assigned_access_rights( - uint8_t * apdu, - uint8_t tag, - BACNET_ASSIGNED_ACCESS_RIGHTS * aar) + uint8_t* apdu, uint8_t tag, BACNET_ASSIGNED_ACCESS_RIGHTS* aar) { int len = 0; int section_length; diff --git a/src/authentication_factor.c b/src/authentication_factor.c index 3ba77e15..28b6ac0e 100644 --- a/src/authentication_factor.c +++ b/src/authentication_factor.c @@ -1,35 +1,33 @@ /************************************************************************** -* -* Copyright (C) 2015 Nikola Jelic -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2015 Nikola Jelic + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include "authentication_factor.h" #include "bacdcode.h" - -int bacapp_encode_authentication_factor( - uint8_t * apdu, - BACNET_AUTHENTICATION_FACTOR * af) +int bacapp_encode_authentication_factor(uint8_t* apdu, + BACNET_AUTHENTICATION_FACTOR* af) { int len; int apdu_len = 0; @@ -56,9 +54,7 @@ int bacapp_encode_authentication_factor( } int bacapp_encode_context_authentication_factor( - uint8_t * apdu, - uint8_t tag, - BACNET_AUTHENTICATION_FACTOR * af) + uint8_t* apdu, uint8_t tag, BACNET_AUTHENTICATION_FACTOR* af) { int len; int apdu_len = 0; @@ -73,12 +69,10 @@ int bacapp_encode_context_authentication_factor( apdu_len += len; return apdu_len; - } -int bacapp_decode_authentication_factor( - uint8_t * apdu, - BACNET_AUTHENTICATION_FACTOR * af) +int bacapp_decode_authentication_factor(uint8_t* apdu, + BACNET_AUTHENTICATION_FACTOR* af) { int len; int apdu_len = 0; @@ -109,14 +103,12 @@ int bacapp_decode_authentication_factor( apdu_len += len; } else return -1; - + return apdu_len; } int bacapp_decode_context_authentication_factor( - uint8_t * apdu, - uint8_t tag, - BACNET_AUTHENTICATION_FACTOR * af) + uint8_t* apdu, uint8_t tag, BACNET_AUTHENTICATION_FACTOR* af) { int len = 0; int section_length; diff --git a/src/authentication_factor_format.c b/src/authentication_factor_format.c index 007f1491..69edb404 100644 --- a/src/authentication_factor_format.c +++ b/src/authentication_factor_format.c @@ -1,35 +1,33 @@ /************************************************************************** -* -* Copyright (C) 2015 Nikola Jelic -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2015 Nikola Jelic + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include "bacdcode.h" #include "authentication_factor_format.h" - int bacapp_encode_authentication_factor_format( - uint8_t * apdu, - BACNET_AUTHENTICATION_FACTOR_FORMAT * aff) + uint8_t* apdu, BACNET_AUTHENTICATION_FACTOR_FORMAT* aff) { int len; int apdu_len = 0; @@ -57,9 +55,7 @@ int bacapp_encode_authentication_factor_format( } int bacapp_encode_context_authentication_factor_format( - uint8_t * apdu, - uint8_t tag, - BACNET_AUTHENTICATION_FACTOR_FORMAT * aff) + uint8_t* apdu, uint8_t tag, BACNET_AUTHENTICATION_FACTOR_FORMAT* aff) { int len; int apdu_len = 0; @@ -74,20 +70,16 @@ int bacapp_encode_context_authentication_factor_format( apdu_len += len; return apdu_len; - } int bacapp_decode_authentication_factor_format( - uint8_t * apdu, - BACNET_AUTHENTICATION_FACTOR_FORMAT * aff) + uint8_t* apdu, BACNET_AUTHENTICATION_FACTOR_FORMAT* aff) { int len; int apdu_len = 0; if (decode_is_context_tag(&apdu[apdu_len], 0)) { - len = - decode_context_enumerated(&apdu[apdu_len], 0, - &aff->format_type); + len = decode_context_enumerated(&apdu[apdu_len], 0, &aff->format_type); if (len < 0) return -1; else @@ -101,8 +93,8 @@ int bacapp_decode_authentication_factor_format( return -1; else apdu_len += len; - if ((aff->format_type != AUTHENTICATION_FACTOR_CUSTOM) - && (aff->vendor_id != 0)) + if ((aff->format_type != AUTHENTICATION_FACTOR_CUSTOM) && + (aff->vendor_id != 0)) return -1; } @@ -112,8 +104,8 @@ int bacapp_decode_authentication_factor_format( return -1; else apdu_len += len; - if ((aff->format_type != AUTHENTICATION_FACTOR_CUSTOM) - && (aff->vendor_format != 0)) + if ((aff->format_type != AUTHENTICATION_FACTOR_CUSTOM) && + (aff->vendor_format != 0)) return -1; } @@ -121,9 +113,7 @@ int bacapp_decode_authentication_factor_format( } int bacapp_decode_context_authentication_factor_format( - uint8_t * apdu, - uint8_t tag, - BACNET_AUTHENTICATION_FACTOR_FORMAT * aff) + uint8_t* apdu, uint8_t tag, BACNET_AUTHENTICATION_FACTOR_FORMAT* aff) { int len = 0; int section_length; @@ -147,5 +137,4 @@ int bacapp_decode_context_authentication_factor_format( len = -1; } return len; - } diff --git a/src/awf.c b/src/awf.c index 0fe449cb..4d7e1bfd 100644 --- a/src/awf.c +++ b/src/awf.c @@ -40,46 +40,38 @@ /** @file awf.c Atomic Write File */ /* encode service */ -int awf_encode_apdu( - uint8_t * apdu, - uint8_t invoke_id, - BACNET_ATOMIC_WRITE_FILE_DATA * data) +int awf_encode_apdu(uint8_t *apdu, uint8_t invoke_id, + BACNET_ATOMIC_WRITE_FILE_DATA *data) { - int apdu_len = 0; /* total length of the apdu, return value */ + int apdu_len = 0; /* total length of the apdu, return value */ uint32_t i = 0; if (apdu) { apdu[0] = PDU_TYPE_CONFIRMED_SERVICE_REQUEST; apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU); apdu[2] = invoke_id; - apdu[3] = SERVICE_CONFIRMED_ATOMIC_WRITE_FILE; /* service choice */ + apdu[3] = SERVICE_CONFIRMED_ATOMIC_WRITE_FILE; /* service choice */ apdu_len = 4; - apdu_len += - encode_application_object_id(&apdu[apdu_len], data->object_type, - data->object_instance); + apdu_len += encode_application_object_id( + &apdu[apdu_len], data->object_type, data->object_instance); switch (data->access) { case FILE_STREAM_ACCESS: apdu_len += encode_opening_tag(&apdu[apdu_len], 0); - apdu_len += - encode_application_signed(&apdu[apdu_len], - data->type.stream.fileStartPosition); - apdu_len += - encode_application_octet_string(&apdu[apdu_len], - &data->fileData[0]); + apdu_len += encode_application_signed( + &apdu[apdu_len], data->type.stream.fileStartPosition); + apdu_len += encode_application_octet_string(&apdu[apdu_len], + &data->fileData[0]); apdu_len += encode_closing_tag(&apdu[apdu_len], 0); break; case FILE_RECORD_ACCESS: apdu_len += encode_opening_tag(&apdu[apdu_len], 1); - apdu_len += - encode_application_signed(&apdu[apdu_len], - data->type.record.fileStartRecord); - apdu_len += - encode_application_unsigned(&apdu[apdu_len], - data->type.record.returnedRecordCount); + apdu_len += encode_application_signed( + &apdu[apdu_len], data->type.record.fileStartRecord); + apdu_len += encode_application_unsigned( + &apdu[apdu_len], data->type.record.returnedRecordCount); for (i = 0; i < data->type.record.returnedRecordCount; i++) { - apdu_len += - encode_application_octet_string(&apdu[apdu_len], - &data->fileData[i]); + apdu_len += encode_application_octet_string( + &apdu[apdu_len], &data->fileData[i]); } apdu_len += encode_closing_tag(&apdu[apdu_len], 1); break; @@ -92,10 +84,8 @@ int awf_encode_apdu( } /* decode the service request only */ -int awf_decode_service_request( - uint8_t * apdu, - unsigned apdu_len, - BACNET_ATOMIC_WRITE_FILE_DATA * data) +int awf_decode_service_request(uint8_t *apdu, unsigned apdu_len, + BACNET_ATOMIC_WRITE_FILE_DATA *data) { int len = 0; int tag_len = 0; @@ -104,41 +94,37 @@ int awf_decode_service_request( uint32_t len_value_type = 0; int32_t signed_value = 0; uint32_t unsigned_value = 0; - uint16_t type = 0; /* for decoding */ + uint16_t type = 0; /* for decoding */ uint32_t i = 0; /* check for value pointers */ if (apdu_len && data) { len = - decode_tag_number_and_value(&apdu[0], &tag_number, - &len_value_type); + decode_tag_number_and_value(&apdu[0], &tag_number, &len_value_type); if (tag_number != BACNET_APPLICATION_TAG_OBJECT_ID) return -1; len += decode_object_id(&apdu[len], &type, &data->object_instance); - data->object_type = (BACNET_OBJECT_TYPE) type; + data->object_type = (BACNET_OBJECT_TYPE)type; if (decode_is_opening_tag_number(&apdu[len], 0)) { data->access = FILE_STREAM_ACCESS; /* a tag number of 2 is not extended so only one octet */ len++; /* fileStartPosition */ - tag_len = - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value_type); + tag_len = decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value_type); len += tag_len; if (tag_number != BACNET_APPLICATION_TAG_SIGNED_INT) return -1; len += decode_signed(&apdu[len], len_value_type, &signed_value); data->type.stream.fileStartPosition = signed_value; /* fileData */ - tag_len = - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value_type); + tag_len = decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value_type); len += tag_len; if (tag_number != BACNET_APPLICATION_TAG_OCTET_STRING) return -1; - decoded_len = - decode_octet_string(&apdu[len], len_value_type, - &data->fileData[0]); + decoded_len = decode_octet_string(&apdu[len], len_value_type, + &data->fileData[0]); if ((uint32_t)decoded_len != len_value_type) { return -1; } @@ -152,35 +138,30 @@ int awf_decode_service_request( /* a tag number is not extended so only one octet */ len++; /* fileStartRecord */ - tag_len = - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value_type); + tag_len = decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value_type); len += tag_len; if (tag_number != BACNET_APPLICATION_TAG_SIGNED_INT) return -1; len += decode_signed(&apdu[len], len_value_type, &signed_value); data->type.record.fileStartRecord = signed_value; /* returnedRecordCount */ - tag_len = - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value_type); + tag_len = decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value_type); len += tag_len; if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT) return -1; - len += - decode_unsigned(&apdu[len], len_value_type, &unsigned_value); + len += decode_unsigned(&apdu[len], len_value_type, &unsigned_value); data->type.record.returnedRecordCount = unsigned_value; /* fileData */ for (i = 0; i < data->type.record.returnedRecordCount; i++) { - tag_len = - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value_type); + tag_len = decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value_type); len += tag_len; if (tag_number != BACNET_APPLICATION_TAG_OCTET_STRING) return -1; - decoded_len = - decode_octet_string(&apdu[len], len_value_type, - &data->fileData[i]); + decoded_len = decode_octet_string(&apdu[len], len_value_type, + &data->fileData[i]); if ((uint32_t)decoded_len != len_value_type) { return -1; } @@ -197,11 +178,8 @@ int awf_decode_service_request( return len; } -int awf_decode_apdu( - uint8_t * apdu, - unsigned apdu_len, - uint8_t * invoke_id, - BACNET_ATOMIC_WRITE_FILE_DATA * data) +int awf_decode_apdu(uint8_t *apdu, unsigned apdu_len, uint8_t *invoke_id, + BACNET_ATOMIC_WRITE_FILE_DATA *data) { int len = 0; unsigned offset = 0; @@ -212,7 +190,7 @@ int awf_decode_apdu( if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST) return -1; /* apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU); */ - *invoke_id = apdu[2]; /* invoke id - filled in by net layer */ + *invoke_id = apdu[2]; /* invoke id - filled in by net layer */ if (apdu[3] != SERVICE_CONFIRMED_ATOMIC_WRITE_FILE) return -1; offset = 4; @@ -225,28 +203,24 @@ int awf_decode_apdu( return len; } -int awf_ack_encode_apdu( - uint8_t * apdu, - uint8_t invoke_id, - BACNET_ATOMIC_WRITE_FILE_DATA * data) +int awf_ack_encode_apdu(uint8_t *apdu, uint8_t invoke_id, + BACNET_ATOMIC_WRITE_FILE_DATA *data) { - 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; apdu[1] = invoke_id; - apdu[2] = SERVICE_CONFIRMED_ATOMIC_WRITE_FILE; /* service choice */ + apdu[2] = SERVICE_CONFIRMED_ATOMIC_WRITE_FILE; /* service choice */ apdu_len = 3; switch (data->access) { case FILE_STREAM_ACCESS: - apdu_len += - encode_context_signed(&apdu[apdu_len], 0, - data->type.stream.fileStartPosition); + apdu_len += encode_context_signed( + &apdu[apdu_len], 0, data->type.stream.fileStartPosition); break; case FILE_RECORD_ACCESS: - apdu_len += - encode_context_signed(&apdu[apdu_len], 1, - data->type.record.fileStartRecord); + apdu_len += encode_context_signed( + &apdu[apdu_len], 1, data->type.record.fileStartRecord); break; default: break; @@ -257,10 +231,8 @@ int awf_ack_encode_apdu( } /* decode the service request only */ -int awf_ack_decode_service_request( - uint8_t * apdu, - unsigned apdu_len, - BACNET_ATOMIC_WRITE_FILE_DATA * data) +int awf_ack_decode_service_request(uint8_t *apdu, unsigned apdu_len, + BACNET_ATOMIC_WRITE_FILE_DATA *data) { int len = 0; uint8_t tag_number = 0; @@ -269,18 +241,15 @@ int awf_ack_decode_service_request( /* check for value pointers */ if (apdu_len && data) { len = - decode_tag_number_and_value(&apdu[0], &tag_number, - &len_value_type); + decode_tag_number_and_value(&apdu[0], &tag_number, &len_value_type); if (tag_number == 0) { data->access = FILE_STREAM_ACCESS; - len += - decode_signed(&apdu[len], len_value_type, - &data->type.stream.fileStartPosition); + len += decode_signed(&apdu[len], len_value_type, + &data->type.stream.fileStartPosition); } else if (tag_number == 1) { data->access = FILE_RECORD_ACCESS; - len += - decode_signed(&apdu[len], len_value_type, - &data->type.record.fileStartRecord); + len += decode_signed(&apdu[len], len_value_type, + &data->type.record.fileStartRecord); } else return -1; } @@ -288,11 +257,8 @@ int awf_ack_decode_service_request( return len; } -int awf_ack_decode_apdu( - uint8_t * apdu, - unsigned apdu_len, - uint8_t * invoke_id, - BACNET_ATOMIC_WRITE_FILE_DATA * data) +int awf_ack_decode_apdu(uint8_t *apdu, unsigned apdu_len, uint8_t *invoke_id, + BACNET_ATOMIC_WRITE_FILE_DATA *data) { int len = 0; unsigned offset = 0; @@ -302,15 +268,14 @@ int awf_ack_decode_apdu( /* optional checking - most likely was already done prior to this call */ if (apdu[0] != PDU_TYPE_COMPLEX_ACK) return -1; - *invoke_id = apdu[1]; /* invoke id - filled in by net layer */ + *invoke_id = apdu[1]; /* invoke id - filled in by net layer */ if (apdu[2] != SERVICE_CONFIRMED_ATOMIC_WRITE_FILE) return -1; offset = 3; if (apdu_len > offset) { - len = - awf_ack_decode_service_request(&apdu[offset], apdu_len - offset, - data); + len = awf_ack_decode_service_request(&apdu[offset], apdu_len - offset, + data); } return len; @@ -321,12 +286,10 @@ int awf_ack_decode_apdu( #include #include "ctest.h" -void testAtomicWriteFileAccess( - Test * pTest, - BACNET_ATOMIC_WRITE_FILE_DATA * data) +void testAtomicWriteFileAccess(Test *pTest, BACNET_ATOMIC_WRITE_FILE_DATA *data) { - BACNET_ATOMIC_WRITE_FILE_DATA test_data = { 0 }; - uint8_t apdu[480] = { 0 }; + BACNET_ATOMIC_WRITE_FILE_DATA test_data = {0}; + uint8_t apdu[480] = {0}; int len = 0; int apdu_len = 0; uint8_t invoke_id = 128; @@ -342,29 +305,24 @@ void testAtomicWriteFileAccess( ct_test(pTest, test_data.object_instance == data->object_instance); ct_test(pTest, test_data.access == data->access); if (test_data.access == FILE_STREAM_ACCESS) { - ct_test(pTest, - test_data.type.stream.fileStartPosition == - data->type.stream.fileStartPosition); + ct_test(pTest, test_data.type.stream.fileStartPosition == + data->type.stream.fileStartPosition); } else if (test_data.access == FILE_RECORD_ACCESS) { - ct_test(pTest, - test_data.type.record.fileStartRecord == - data->type.record.fileStartRecord); - ct_test(pTest, - test_data.type.record.returnedRecordCount == - data->type.record.returnedRecordCount); + ct_test(pTest, test_data.type.record.fileStartRecord == + data->type.record.fileStartRecord); + ct_test(pTest, test_data.type.record.returnedRecordCount == + data->type.record.returnedRecordCount); } - ct_test(pTest, - octetstring_length(&test_data.fileData[0]) == - octetstring_length(&data->fileData[0])); + ct_test(pTest, octetstring_length(&test_data.fileData[0]) == + octetstring_length(&data->fileData[0])); ct_test(pTest, memcmp(octetstring_value(&test_data.fileData[0]), - octetstring_value(&data->fileData[0]), - octetstring_length(&test_data.fileData[0])) == 0); + octetstring_value(&data->fileData[0]), + octetstring_length(&test_data.fileData[0])) == 0); } -void testAtomicWriteFile( - Test * pTest) +void testAtomicWriteFile(Test *pTest) { - BACNET_ATOMIC_WRITE_FILE_DATA data = { 0 }; + BACNET_ATOMIC_WRITE_FILE_DATA data = {0}; uint8_t test_octet_string[32] = "Joshua-Mary-Anna-Christopher"; data.object_type = OBJECT_FILE; @@ -372,7 +330,7 @@ void testAtomicWriteFile( data.access = FILE_STREAM_ACCESS; data.type.stream.fileStartPosition = 0; octetstring_init(&data.fileData[0], test_octet_string, - sizeof(test_octet_string)); + sizeof(test_octet_string)); testAtomicWriteFileAccess(pTest, &data); data.object_type = OBJECT_FILE; @@ -381,18 +339,17 @@ void testAtomicWriteFile( data.type.record.fileStartRecord = 1; data.type.record.returnedRecordCount = 1; octetstring_init(&data.fileData[0], test_octet_string, - sizeof(test_octet_string)); + sizeof(test_octet_string)); testAtomicWriteFileAccess(pTest, &data); return; } -void testAtomicWriteFileAckAccess( - Test * pTest, - BACNET_ATOMIC_WRITE_FILE_DATA * data) +void testAtomicWriteFileAckAccess(Test *pTest, + BACNET_ATOMIC_WRITE_FILE_DATA *data) { - BACNET_ATOMIC_WRITE_FILE_DATA test_data = { 0 }; - uint8_t apdu[480] = { 0 }; + BACNET_ATOMIC_WRITE_FILE_DATA test_data = {0}; + uint8_t apdu[480] = {0}; int len = 0; int apdu_len = 0; uint8_t invoke_id = 128; @@ -406,20 +363,17 @@ void testAtomicWriteFileAckAccess( ct_test(pTest, len != -1); ct_test(pTest, test_data.access == data->access); if (test_data.access == FILE_STREAM_ACCESS) { - ct_test(pTest, - test_data.type.stream.fileStartPosition == - data->type.stream.fileStartPosition); + ct_test(pTest, test_data.type.stream.fileStartPosition == + data->type.stream.fileStartPosition); } else if (test_data.access == FILE_RECORD_ACCESS) { - ct_test(pTest, - test_data.type.record.fileStartRecord == - data->type.record.fileStartRecord); + ct_test(pTest, test_data.type.record.fileStartRecord == + data->type.record.fileStartRecord); } } -void testAtomicWriteFileAck( - Test * pTest) +void testAtomicWriteFileAck(Test *pTest) { - BACNET_ATOMIC_WRITE_FILE_DATA data = { 0 }; + BACNET_ATOMIC_WRITE_FILE_DATA data = {0}; data.access = FILE_STREAM_ACCESS; data.type.stream.fileStartPosition = 42; @@ -433,8 +387,7 @@ void testAtomicWriteFileAck( } #ifdef TEST_ATOMIC_WRITE_FILE -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -448,7 +401,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/src/bacaddr.c b/src/bacaddr.c index 8cc6a8ae..dce11874 100644 --- a/src/bacaddr.c +++ b/src/bacaddr.c @@ -40,9 +40,7 @@ /** @file bacaddr.c BACnet Address structure utilities */ -void bacnet_address_copy( - BACNET_ADDRESS * dest, - BACNET_ADDRESS * src) +void bacnet_address_copy(BACNET_ADDRESS* dest, BACNET_ADDRESS* src) { int i = 0; @@ -59,14 +57,12 @@ void bacnet_address_copy( } } -bool bacnet_address_same( - BACNET_ADDRESS * dest, - BACNET_ADDRESS * src) +bool bacnet_address_same(BACNET_ADDRESS* dest, BACNET_ADDRESS* src) { - uint8_t i = 0; /* loop counter */ - uint8_t max_len = 0; /* used for dynamic max */ + uint8_t i = 0; /* loop counter */ + uint8_t max_len = 0; /* used for dynamic max */ - if (dest == src) /* same ? */ + if (dest == src) /* same ? */ return true; if (dest->net != src->net) diff --git a/src/bacapp.c b/src/bacapp.c index 16e1222d..a457c884 100644 --- a/src/bacapp.c +++ b/src/bacapp.c @@ -54,112 +54,100 @@ #define snprintf _snprintf #endif -int bacapp_encode_application_data( - uint8_t * apdu, - BACNET_APPLICATION_DATA_VALUE * value) +int bacapp_encode_application_data(uint8_t *apdu, + BACNET_APPLICATION_DATA_VALUE *value) { - int apdu_len = 0; /* total length of the apdu, return value */ + int apdu_len = 0; /* total length of the apdu, return value */ if (value && apdu) { switch (value->tag) { -#if defined (BACAPP_NULL) +#if defined(BACAPP_NULL) case BACNET_APPLICATION_TAG_NULL: apdu[0] = value->tag; apdu_len++; break; #endif -#if defined (BACAPP_BOOLEAN) +#if defined(BACAPP_BOOLEAN) case BACNET_APPLICATION_TAG_BOOLEAN: apdu_len = encode_application_boolean(&apdu[0], value->type.Boolean); break; #endif -#if defined (BACAPP_UNSIGNED) +#if defined(BACAPP_UNSIGNED) case BACNET_APPLICATION_TAG_UNSIGNED_INT: - apdu_len = - encode_application_unsigned(&apdu[0], - value->type.Unsigned_Int); + apdu_len = encode_application_unsigned( + &apdu[0], value->type.Unsigned_Int); break; #endif -#if defined (BACAPP_SIGNED) +#if defined(BACAPP_SIGNED) case BACNET_APPLICATION_TAG_SIGNED_INT: apdu_len = - encode_application_signed(&apdu[0], - value->type.Signed_Int); + encode_application_signed(&apdu[0], value->type.Signed_Int); break; #endif -#if defined (BACAPP_REAL) +#if defined(BACAPP_REAL) case BACNET_APPLICATION_TAG_REAL: apdu_len = encode_application_real(&apdu[0], value->type.Real); break; #endif -#if defined (BACAPP_DOUBLE) +#if defined(BACAPP_DOUBLE) case BACNET_APPLICATION_TAG_DOUBLE: apdu_len = encode_application_double(&apdu[0], value->type.Double); break; #endif -#if defined (BACAPP_OCTET_STRING) +#if defined(BACAPP_OCTET_STRING) case BACNET_APPLICATION_TAG_OCTET_STRING: - apdu_len = - encode_application_octet_string(&apdu[0], - &value->type.Octet_String); + apdu_len = encode_application_octet_string( + &apdu[0], &value->type.Octet_String); break; #endif -#if defined (BACAPP_CHARACTER_STRING) +#if defined(BACAPP_CHARACTER_STRING) case BACNET_APPLICATION_TAG_CHARACTER_STRING: - apdu_len = - encode_application_character_string(&apdu[0], - &value->type.Character_String); + apdu_len = encode_application_character_string( + &apdu[0], &value->type.Character_String); break; #endif -#if defined (BACAPP_BIT_STRING) +#if defined(BACAPP_BIT_STRING) case BACNET_APPLICATION_TAG_BIT_STRING: - apdu_len = - encode_application_bitstring(&apdu[0], - &value->type.Bit_String); + apdu_len = encode_application_bitstring( + &apdu[0], &value->type.Bit_String); break; #endif -#if defined (BACAPP_ENUMERATED) +#if defined(BACAPP_ENUMERATED) case BACNET_APPLICATION_TAG_ENUMERATED: - apdu_len = - encode_application_enumerated(&apdu[0], - value->type.Enumerated); + apdu_len = encode_application_enumerated( + &apdu[0], value->type.Enumerated); break; #endif -#if defined (BACAPP_DATE) +#if defined(BACAPP_DATE) case BACNET_APPLICATION_TAG_DATE: - apdu_len = - encode_application_date(&apdu[0], &value->type.Date); + apdu_len = encode_application_date(&apdu[0], &value->type.Date); break; #endif -#if defined (BACAPP_TIME) +#if defined(BACAPP_TIME) case BACNET_APPLICATION_TAG_TIME: - apdu_len = - encode_application_time(&apdu[0], &value->type.Time); + apdu_len = encode_application_time(&apdu[0], &value->type.Time); break; #endif -#if defined (BACAPP_OBJECT_ID) +#if defined(BACAPP_OBJECT_ID) case BACNET_APPLICATION_TAG_OBJECT_ID: - apdu_len = - encode_application_object_id(&apdu[0], - (int) value->type.Object_Id.type, + apdu_len = encode_application_object_id( + &apdu[0], (int)value->type.Object_Id.type, value->type.Object_Id.instance); break; #endif -#if defined (BACAPP_LIGHTING_COMMAND) +#if defined(BACAPP_LIGHTING_COMMAND) case BACNET_APPLICATION_TAG_LIGHTING_COMMAND: - apdu_len = - lighting_command_encode(&apdu[0], - &value->type.Lighting_Command); + apdu_len = lighting_command_encode( + &apdu[0], &value->type.Lighting_Command); break; #endif -#if defined (BACAPP_DEVICE_OBJECT_PROP_REF) +#if defined(BACAPP_DEVICE_OBJECT_PROP_REF) case BACNET_APPLICATION_TAG_DEVICE_OBJECT_PROPERTY_REFERENCE: /* BACnetDeviceObjectPropertyReference */ - apdu_len = - bacapp_encode_device_obj_property_ref(&apdu[0], - &value->type.Device_Object_Property_Reference); + apdu_len = bacapp_encode_device_obj_property_ref( + &apdu[0], &value->type.Device_Object_Property_Reference); break; #endif default: @@ -172,115 +160,98 @@ int bacapp_encode_application_data( /* decode the data and store it into value. Return the number of octets consumed. */ -int bacapp_decode_data( - uint8_t * apdu, - uint8_t tag_data_type, - uint32_t len_value_type, - BACNET_APPLICATION_DATA_VALUE * value) +int bacapp_decode_data(uint8_t *apdu, uint8_t tag_data_type, + uint32_t len_value_type, + BACNET_APPLICATION_DATA_VALUE *value) { int len = 0; if (apdu && value) { switch (tag_data_type) { -#if defined (BACAPP_NULL) +#if defined(BACAPP_NULL) case BACNET_APPLICATION_TAG_NULL: /* nothing else to do */ break; #endif -#if defined (BACAPP_BOOLEAN) +#if defined(BACAPP_BOOLEAN) case BACNET_APPLICATION_TAG_BOOLEAN: value->type.Boolean = decode_boolean(len_value_type); break; #endif -#if defined (BACAPP_UNSIGNED) +#if defined(BACAPP_UNSIGNED) case BACNET_APPLICATION_TAG_UNSIGNED_INT: - len = - decode_unsigned(&apdu[0], len_value_type, - &value->type.Unsigned_Int); + len = decode_unsigned(&apdu[0], len_value_type, + &value->type.Unsigned_Int); break; #endif -#if defined (BACAPP_SIGNED) +#if defined(BACAPP_SIGNED) case BACNET_APPLICATION_TAG_SIGNED_INT: - len = - decode_signed(&apdu[0], len_value_type, - &value->type.Signed_Int); + len = decode_signed(&apdu[0], len_value_type, + &value->type.Signed_Int); break; #endif -#if defined (BACAPP_REAL) +#if defined(BACAPP_REAL) case BACNET_APPLICATION_TAG_REAL: - len = - decode_real_safe(&apdu[0], len_value_type, - &(value->type.Real)); + len = decode_real_safe(&apdu[0], len_value_type, + &(value->type.Real)); break; #endif -#if defined (BACAPP_DOUBLE) +#if defined(BACAPP_DOUBLE) case BACNET_APPLICATION_TAG_DOUBLE: - len = - decode_double_safe(&apdu[0], len_value_type, - &(value->type.Double)); + len = decode_double_safe(&apdu[0], len_value_type, + &(value->type.Double)); break; #endif -#if defined (BACAPP_OCTET_STRING) +#if defined(BACAPP_OCTET_STRING) case BACNET_APPLICATION_TAG_OCTET_STRING: - len = - decode_octet_string(&apdu[0], len_value_type, - &value->type.Octet_String); + len = decode_octet_string(&apdu[0], len_value_type, + &value->type.Octet_String); break; #endif -#if defined (BACAPP_CHARACTER_STRING) +#if defined(BACAPP_CHARACTER_STRING) case BACNET_APPLICATION_TAG_CHARACTER_STRING: - len = - decode_character_string(&apdu[0], len_value_type, - &value->type.Character_String); + len = decode_character_string(&apdu[0], len_value_type, + &value->type.Character_String); break; #endif -#if defined (BACAPP_BIT_STRING) +#if defined(BACAPP_BIT_STRING) case BACNET_APPLICATION_TAG_BIT_STRING: - len = - decode_bitstring(&apdu[0], len_value_type, - &value->type.Bit_String); + len = decode_bitstring(&apdu[0], len_value_type, + &value->type.Bit_String); break; #endif -#if defined (BACAPP_ENUMERATED) +#if defined(BACAPP_ENUMERATED) case BACNET_APPLICATION_TAG_ENUMERATED: - len = - decode_enumerated(&apdu[0], len_value_type, - &value->type.Enumerated); + len = decode_enumerated(&apdu[0], len_value_type, + &value->type.Enumerated); break; #endif -#if defined (BACAPP_DATE) +#if defined(BACAPP_DATE) case BACNET_APPLICATION_TAG_DATE: - len = - decode_date_safe(&apdu[0], len_value_type, - &value->type.Date); + len = decode_date_safe(&apdu[0], len_value_type, + &value->type.Date); break; #endif -#if defined (BACAPP_TIME) +#if defined(BACAPP_TIME) case BACNET_APPLICATION_TAG_TIME: - len = - decode_bacnet_time_safe(&apdu[0], len_value_type, - &value->type.Time); + len = decode_bacnet_time_safe(&apdu[0], len_value_type, + &value->type.Time); break; #endif -#if defined (BACAPP_OBJECT_ID) - case BACNET_APPLICATION_TAG_OBJECT_ID: - { - uint16_t object_type = 0; - uint32_t instance = 0; - len = - decode_object_id_safe(&apdu[0], len_value_type, - &object_type, &instance); - value->type.Object_Id.type = object_type; - value->type.Object_Id.instance = instance; - } - break; +#if defined(BACAPP_OBJECT_ID) + case BACNET_APPLICATION_TAG_OBJECT_ID: { + uint16_t object_type = 0; + uint32_t instance = 0; + len = decode_object_id_safe(&apdu[0], len_value_type, + &object_type, &instance); + value->type.Object_Id.type = object_type; + value->type.Object_Id.instance = instance; + } break; #endif -#if defined (BACAPP_LIGHTING_COMMAND) +#if defined(BACAPP_LIGHTING_COMMAND) case BACNET_APPLICATION_TAG_LIGHTING_COMMAND: - len = - lighting_command_decode( - &apdu[0], len_value_type, - &value->type.Lighting_Command); + len = lighting_command_decode(&apdu[0], len_value_type, + &value->type.Lighting_Command); break; #endif default: @@ -299,10 +270,8 @@ int bacapp_decode_data( return len; } -int bacapp_decode_application_data( - uint8_t * apdu, - unsigned max_apdu_len, - BACNET_APPLICATION_DATA_VALUE * value) +int bacapp_decode_application_data(uint8_t *apdu, unsigned max_apdu_len, + BACNET_APPLICATION_DATA_VALUE *value) { int len = 0; int tag_len = 0; @@ -315,14 +284,12 @@ int bacapp_decode_application_data( if (apdu && value && !IS_CONTEXT_SPECIFIC(*apdu)) { value->context_specific = false; tag_len = - decode_tag_number_and_value(&apdu[0], &tag_number, - &len_value_type); + decode_tag_number_and_value(&apdu[0], &tag_number, &len_value_type); if (tag_len) { len += tag_len; value->tag = tag_number; - decode_len = - bacapp_decode_data(&apdu[len], tag_number, len_value_type, - value); + decode_len = bacapp_decode_data(&apdu[len], tag_number, + len_value_type, value); if (value->tag != MAX_BACNET_APPLICATION_TAG) { len += decode_len; } else { @@ -336,7 +303,8 @@ int bacapp_decode_application_data( } /* -** Usage: Similar to strtok. Call function the first time with new_apdu and new_adu_len set to apdu buffer +** Usage: Similar to strtok. Call function the first time with new_apdu and +*new_adu_len set to apdu buffer ** to be processed. Subsequent calls should pass in NULL. ** ** Returns true if a application message is correctly parsed. @@ -344,14 +312,14 @@ int bacapp_decode_application_data( ** ** This function is NOT thread safe. ** -** Notes: The _safe suffix is there because the function should be relatively safe against buffer overruns. +** Notes: The _safe suffix is there because the function should be relatively +*safe against buffer overruns. ** */ -bool bacapp_decode_application_data_safe( - uint8_t * new_apdu, - uint32_t new_apdu_len, - BACNET_APPLICATION_DATA_VALUE * value) +bool bacapp_decode_application_data_safe(uint8_t *new_apdu, + uint32_t new_apdu_len, + BACNET_APPLICATION_DATA_VALUE *value) { /* The static variables that store the apdu buffer between function calls */ static uint8_t *apdu = NULL; @@ -373,21 +341,20 @@ bool bacapp_decode_application_data_safe( if (value && apdu_len_remaining > 0 && !IS_CONTEXT_SPECIFIC(apdu[apdu_len])) { value->context_specific = false; - tag_len = - decode_tag_number_and_value_safe(&apdu[apdu_len], - apdu_len_remaining, &tag_number, &len_value_type); + tag_len = decode_tag_number_and_value_safe( + &apdu[apdu_len], apdu_len_remaining, &tag_number, &len_value_type); /* If tag_len is zero, then the tag information is truncated */ if (tag_len) { apdu_len += tag_len; apdu_len_remaining -= tag_len; - /* The tag is boolean then len_value_type is interpreted as value, not length, so dont bother + /* The tag is boolean then len_value_type is interpreted as value, + *not length, so dont bother ** checking with apdu_len_remaining */ if (tag_number == BACNET_APPLICATION_TAG_BOOLEAN || len_value_type <= apdu_len_remaining) { value->tag = tag_number; - len = - bacapp_decode_data(&apdu[apdu_len], tag_number, - len_value_type, value); + len = bacapp_decode_data(&apdu[apdu_len], tag_number, + len_value_type, value); apdu_len += len; apdu_len_remaining -= len; @@ -397,16 +364,13 @@ bool bacapp_decode_application_data_safe( value->next = NULL; } - return ret; } /* Decode the data and return the number of octets consumed. */ -int bacapp_decode_data_len( - uint8_t * apdu, - uint8_t tag_data_type, - uint32_t len_value_type) +int bacapp_decode_data_len(uint8_t *apdu, uint8_t tag_data_type, + uint32_t len_value_type) { int len = 0; @@ -427,7 +391,7 @@ int bacapp_decode_data_len( case BACNET_APPLICATION_TAG_DATE: case BACNET_APPLICATION_TAG_TIME: case BACNET_APPLICATION_TAG_OBJECT_ID: - len = (int) len_value_type; + len = (int)len_value_type; break; default: break; @@ -437,9 +401,7 @@ int bacapp_decode_data_len( return len; } -int bacapp_decode_application_data_len( - uint8_t * apdu, - unsigned max_apdu_len) +int bacapp_decode_application_data_len(uint8_t *apdu, unsigned max_apdu_len) { int len = 0; int tag_len = 0; @@ -451,8 +413,7 @@ int bacapp_decode_application_data_len( (void)max_apdu_len; if (apdu && !IS_CONTEXT_SPECIFIC(*apdu)) { tag_len = - decode_tag_number_and_value(&apdu[0], &tag_number, - &len_value_type); + decode_tag_number_and_value(&apdu[0], &tag_number, &len_value_type); if (tag_len) { len += tag_len; decode_len = @@ -464,109 +425,96 @@ int bacapp_decode_application_data_len( return len; } -int bacapp_encode_context_data_value( - uint8_t * apdu, - uint8_t context_tag_number, - BACNET_APPLICATION_DATA_VALUE * value) +int bacapp_encode_context_data_value(uint8_t *apdu, uint8_t context_tag_number, + BACNET_APPLICATION_DATA_VALUE *value) { - int apdu_len = 0; /* total length of the apdu, return value */ + int apdu_len = 0; /* total length of the apdu, return value */ if (value && apdu) { switch (value->tag) { -#if defined (BACAPP_NULL) +#if defined(BACAPP_NULL) case BACNET_APPLICATION_TAG_NULL: apdu_len = encode_context_null(&apdu[0], context_tag_number); break; #endif -#if defined (BACAPP_BOOLEAN) +#if defined(BACAPP_BOOLEAN) case BACNET_APPLICATION_TAG_BOOLEAN: - apdu_len = - encode_context_boolean(&apdu[0], context_tag_number, - value->type.Boolean); + apdu_len = encode_context_boolean(&apdu[0], context_tag_number, + value->type.Boolean); break; #endif -#if defined (BACAPP_UNSIGNED) +#if defined(BACAPP_UNSIGNED) case BACNET_APPLICATION_TAG_UNSIGNED_INT: - apdu_len = - encode_context_unsigned(&apdu[0], context_tag_number, - value->type.Unsigned_Int); + apdu_len = encode_context_unsigned(&apdu[0], context_tag_number, + value->type.Unsigned_Int); break; #endif -#if defined (BACAPP_SIGNED) +#if defined(BACAPP_SIGNED) case BACNET_APPLICATION_TAG_SIGNED_INT: - apdu_len = - encode_context_signed(&apdu[0], context_tag_number, - value->type.Signed_Int); + apdu_len = encode_context_signed(&apdu[0], context_tag_number, + value->type.Signed_Int); break; #endif -#if defined (BACAPP_REAL) +#if defined(BACAPP_REAL) case BACNET_APPLICATION_TAG_REAL: - apdu_len = - encode_context_real(&apdu[0], context_tag_number, - value->type.Real); + apdu_len = encode_context_real(&apdu[0], context_tag_number, + value->type.Real); break; #endif -#if defined (BACAPP_DOUBLE) +#if defined(BACAPP_DOUBLE) case BACNET_APPLICATION_TAG_DOUBLE: - apdu_len = - encode_context_double(&apdu[0], context_tag_number, - value->type.Double); + apdu_len = encode_context_double(&apdu[0], context_tag_number, + value->type.Double); break; #endif -#if defined (BACAPP_OCTET_STRING) +#if defined(BACAPP_OCTET_STRING) case BACNET_APPLICATION_TAG_OCTET_STRING: - apdu_len = - encode_context_octet_string(&apdu[0], context_tag_number, - &value->type.Octet_String); + apdu_len = encode_context_octet_string( + &apdu[0], context_tag_number, &value->type.Octet_String); break; #endif -#if defined (BACAPP_CHARACTER_STRING) +#if defined(BACAPP_CHARACTER_STRING) case BACNET_APPLICATION_TAG_CHARACTER_STRING: - apdu_len = - encode_context_character_string(&apdu[0], - context_tag_number, &value->type.Character_String); + apdu_len = encode_context_character_string( + &apdu[0], context_tag_number, + &value->type.Character_String); break; #endif -#if defined (BACAPP_BIT_STRING) +#if defined(BACAPP_BIT_STRING) case BACNET_APPLICATION_TAG_BIT_STRING: - apdu_len = - encode_context_bitstring(&apdu[0], context_tag_number, - &value->type.Bit_String); + apdu_len = encode_context_bitstring( + &apdu[0], context_tag_number, &value->type.Bit_String); break; #endif -#if defined (BACAPP_ENUMERATED) +#if defined(BACAPP_ENUMERATED) case BACNET_APPLICATION_TAG_ENUMERATED: - apdu_len = - encode_context_enumerated(&apdu[0], context_tag_number, - value->type.Enumerated); + apdu_len = encode_context_enumerated( + &apdu[0], context_tag_number, value->type.Enumerated); break; #endif -#if defined (BACAPP_DATE) +#if defined(BACAPP_DATE) case BACNET_APPLICATION_TAG_DATE: - apdu_len = - encode_context_date(&apdu[0], context_tag_number, - &value->type.Date); + apdu_len = encode_context_date(&apdu[0], context_tag_number, + &value->type.Date); break; #endif -#if defined (BACAPP_TIME) +#if defined(BACAPP_TIME) case BACNET_APPLICATION_TAG_TIME: - apdu_len = - encode_context_time(&apdu[0], context_tag_number, - &value->type.Time); + apdu_len = encode_context_time(&apdu[0], context_tag_number, + &value->type.Time); break; #endif -#if defined (BACAPP_OBJECT_ID) +#if defined(BACAPP_OBJECT_ID) case BACNET_APPLICATION_TAG_OBJECT_ID: apdu_len = encode_context_object_id(&apdu[0], context_tag_number, - (int) value->type.Object_Id.type, - value->type.Object_Id.instance); + (int)value->type.Object_Id.type, + value->type.Object_Id.instance); break; #endif -#if defined (BACAPP_LIGHTING_COMMAND) +#if defined(BACAPP_LIGHTING_COMMAND) case BACNET_APPLICATION_TAG_LIGHTING_COMMAND: - apdu_len = - lighting_command_encode_context( + apdu_len = lighting_command_encode_context( &apdu[0], context_tag_number, &value->type.Lighting_Command); break; @@ -580,9 +528,8 @@ int bacapp_encode_context_data_value( } /* returns the fixed tag type for certain context tagged properties */ -BACNET_APPLICATION_TAG bacapp_context_tag_type( - BACNET_PROPERTY_ID property, - uint8_t tag_number) +BACNET_APPLICATION_TAG bacapp_context_tag_type(BACNET_PROPERTY_ID property, + uint8_t tag_number) { BACNET_APPLICATION_TAG tag = MAX_BACNET_APPLICATION_TAG; @@ -620,7 +567,7 @@ BACNET_APPLICATION_TAG bacapp_context_tag_type( case 8: tag = BACNET_APPLICATION_TAG_BOOLEAN; break; - case 4: /* propertyValue: abstract syntax */ + case 4: /* propertyValue: abstract syntax */ default: break; } @@ -643,22 +590,22 @@ BACNET_APPLICATION_TAG bacapp_context_tag_type( case 3: tag = BACNET_APPLICATION_TAG_UNSIGNED_INT; break; - case 0: /* calendarEntry: abstract syntax + context */ - case 2: /* list of BACnetTimeValue: abstract syntax */ + case 0: /* calendarEntry: abstract syntax + context */ + case 2: /* list of BACnetTimeValue: abstract syntax */ default: break; } break; case PROP_LOG_DEVICE_OBJECT_PROPERTY: switch (tag_number) { - case 0: /* Object ID */ - case 3: /* Device 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: @@ -668,8 +615,8 @@ BACNET_APPLICATION_TAG bacapp_context_tag_type( case PROP_SUBORDINATE_LIST: /* BACnetARRAY[N] of BACnetDeviceObjectReference */ switch (tag_number) { - case 0: /* Optional Device ID */ - case 1: /* Object ID */ + case 0: /* Optional Device ID */ + case 1: /* Object ID */ tag = BACNET_APPLICATION_TAG_OBJECT_ID; break; default: @@ -680,15 +627,14 @@ BACNET_APPLICATION_TAG bacapp_context_tag_type( case PROP_RECIPIENT_LIST: /* List of BACnetDestination */ switch (tag_number) { - case 0: /* Device Object ID */ + case 0: /* Device Object ID */ tag = BACNET_APPLICATION_TAG_OBJECT_ID; break; case 1: /* 2015.08.22 EKH 135-2012 pg 708 - todo - Context 1 in Recipient list would be a BACnetAddress, not coded yet... - BACnetRecipient::= CHOICE { - device [0] BACnetObjectIdentifier, - address [1] BACnetAddress + todo - Context 1 in Recipient list would be a BACnetAddress, + not coded yet... BACnetRecipient::= CHOICE { device [0] + BACnetObjectIdentifier, address [1] BACnetAddress } */ break; @@ -699,16 +645,16 @@ BACNET_APPLICATION_TAG bacapp_context_tag_type( case PROP_ACTIVE_COV_SUBSCRIPTIONS: /* BACnetCOVSubscription */ switch (tag_number) { - case 0: /* BACnetRecipientProcess */ - case 1: /* BACnetObjectPropertyReference */ + case 0: /* BACnetRecipientProcess */ + case 1: /* BACnetObjectPropertyReference */ break; - case 2: /* issueConfirmedNotifications */ + case 2: /* issueConfirmedNotifications */ tag = BACNET_APPLICATION_TAG_BOOLEAN; break; - case 3: /* timeRemaining */ + case 3: /* timeRemaining */ tag = BACNET_APPLICATION_TAG_UNSIGNED_INT; break; - case 4: /* covIncrement */ + case 4: /* covIncrement */ tag = BACNET_APPLICATION_TAG_REAL; break; default: @@ -722,10 +668,9 @@ BACNET_APPLICATION_TAG bacapp_context_tag_type( return tag; } -int bacapp_encode_context_data( - uint8_t * apdu, - BACNET_APPLICATION_DATA_VALUE * value, - BACNET_PROPERTY_ID property) +int bacapp_encode_context_data(uint8_t *apdu, + BACNET_APPLICATION_DATA_VALUE *value, + BACNET_PROPERTY_ID property) { int apdu_len = 0; BACNET_APPLICATION_TAG tag_data_type; @@ -733,9 +678,8 @@ int bacapp_encode_context_data( if (value && apdu) { tag_data_type = bacapp_context_tag_type(property, value->context_tag); if (tag_data_type < MAX_BACNET_APPLICATION_TAG) { - apdu_len = - bacapp_encode_context_data_value(&apdu[0], value->context_tag, - value); + apdu_len = bacapp_encode_context_data_value( + &apdu[0], value->context_tag, value); } else { /* FIXME: what now? */ apdu_len = 0; @@ -746,11 +690,9 @@ int bacapp_encode_context_data( return apdu_len; } -int bacapp_decode_context_data( - uint8_t * apdu, - unsigned max_apdu_len, - BACNET_APPLICATION_DATA_VALUE * value, - BACNET_PROPERTY_ID property) +int bacapp_decode_context_data(uint8_t *apdu, unsigned max_apdu_len, + BACNET_APPLICATION_DATA_VALUE *value, + BACNET_PROPERTY_ID property) { int apdu_len = 0, len = 0; int tag_len = 0; @@ -761,37 +703,34 @@ int bacapp_decode_context_data( value->context_specific = true; value->next = NULL; tag_len = - decode_tag_number_and_value(&apdu[0], &tag_number, - &len_value_type); + decode_tag_number_and_value(&apdu[0], &tag_number, &len_value_type); apdu_len = tag_len; /* Empty construct : (closing tag) => returns NULL value */ - if (tag_len && ((unsigned) tag_len <= max_apdu_len) && + if (tag_len && ((unsigned)tag_len <= max_apdu_len) && !decode_is_closing_tag_number(&apdu[0], tag_number)) { value->context_tag = tag_number; value->tag = bacapp_context_tag_type(property, tag_number); if (value->tag < MAX_BACNET_APPLICATION_TAG) { - len = - bacapp_decode_data(&apdu[apdu_len], value->tag, - len_value_type, value); + len = bacapp_decode_data(&apdu[apdu_len], value->tag, + len_value_type, value); apdu_len += len; } else if (len_value_type) { /* Unknown value : non null size (elementary type) */ apdu_len += len_value_type; - /* SHOULD NOT HAPPEN, EXCEPTED WHEN READING UNKNOWN CONTEXTUAL PROPERTY */ + /* SHOULD NOT HAPPEN, EXCEPTED WHEN READING UNKNOWN CONTEXTUAL + * PROPERTY */ } else { apdu_len = BACNET_STATUS_ERROR; } - } else if (tag_len == 1) /* and is a Closing tag */ - apdu_len = 0; /* Don't advance over that closing tag. */ + } else if (tag_len == 1) /* and is a Closing tag */ + apdu_len = 0; /* Don't advance over that closing tag. */ } return apdu_len; } -int bacapp_decode_context_data_len( - uint8_t * apdu, - unsigned max_apdu_len, - BACNET_PROPERTY_ID property) +int bacapp_decode_context_data_len(uint8_t *apdu, unsigned max_apdu_len, + BACNET_PROPERTY_ID property) { int apdu_len = 0, len = 0; int tag_len = 0; @@ -803,15 +742,13 @@ int bacapp_decode_context_data_len( (void)max_apdu_len; if (apdu && IS_CONTEXT_SPECIFIC(*apdu)) { tag_len = - decode_tag_number_and_value(&apdu[0], &tag_number, - &len_value_type); + decode_tag_number_and_value(&apdu[0], &tag_number, &len_value_type); if (tag_len) { apdu_len = tag_len; tag = bacapp_context_tag_type(property, tag_number); if (tag < MAX_BACNET_APPLICATION_TAG) { - len = - bacapp_decode_data_len(&apdu[apdu_len], tag, - len_value_type); + len = bacapp_decode_data_len(&apdu[apdu_len], tag, + len_value_type); apdu_len += len; } else { apdu_len += len_value_type; @@ -822,17 +759,14 @@ int bacapp_decode_context_data_len( return apdu_len; } -int bacapp_encode_data( - uint8_t * apdu, - BACNET_APPLICATION_DATA_VALUE * value) +int bacapp_encode_data(uint8_t *apdu, BACNET_APPLICATION_DATA_VALUE *value) { - int apdu_len = 0; /* total length of the apdu, return value */ + int apdu_len = 0; /* total length of the apdu, return value */ if (value && apdu) { if (value->context_specific) { - apdu_len = - bacapp_encode_context_data_value(&apdu[0], value->context_tag, - value); + apdu_len = bacapp_encode_context_data_value( + &apdu[0], value->context_tag, value); } else { apdu_len = bacapp_encode_application_data(&apdu[0], value); } @@ -841,81 +775,79 @@ int bacapp_encode_data( return apdu_len; } - -bool bacapp_copy( - BACNET_APPLICATION_DATA_VALUE * dest_value, - BACNET_APPLICATION_DATA_VALUE * src_value) +bool bacapp_copy(BACNET_APPLICATION_DATA_VALUE *dest_value, + BACNET_APPLICATION_DATA_VALUE *src_value) { bool status = true; /*return value */ if (dest_value && src_value) { dest_value->tag = src_value->tag; switch (src_value->tag) { -#if defined (BACAPP_NULL) +#if defined(BACAPP_NULL) case BACNET_APPLICATION_TAG_NULL: break; #endif -#if defined (BACAPP_BOOLEAN) +#if defined(BACAPP_BOOLEAN) case BACNET_APPLICATION_TAG_BOOLEAN: dest_value->type.Boolean = src_value->type.Boolean; break; #endif -#if defined (BACAPP_UNSIGNED) +#if defined(BACAPP_UNSIGNED) case BACNET_APPLICATION_TAG_UNSIGNED_INT: dest_value->type.Unsigned_Int = src_value->type.Unsigned_Int; break; #endif -#if defined (BACAPP_SIGNED) +#if defined(BACAPP_SIGNED) case BACNET_APPLICATION_TAG_SIGNED_INT: dest_value->type.Signed_Int = src_value->type.Signed_Int; break; #endif -#if defined (BACAPP_REAL) +#if defined(BACAPP_REAL) case BACNET_APPLICATION_TAG_REAL: dest_value->type.Real = src_value->type.Real; break; #endif -#if defined (BACAPP_DOUBLE) +#if defined(BACAPP_DOUBLE) case BACNET_APPLICATION_TAG_DOUBLE: dest_value->type.Double = src_value->type.Double; break; #endif -#if defined (BACAPP_OCTET_STRING) +#if defined(BACAPP_OCTET_STRING) case BACNET_APPLICATION_TAG_OCTET_STRING: octetstring_copy(&dest_value->type.Octet_String, - &src_value->type.Octet_String); + &src_value->type.Octet_String); break; #endif -#if defined (BACAPP_CHARACTER_STRING) +#if defined(BACAPP_CHARACTER_STRING) case BACNET_APPLICATION_TAG_CHARACTER_STRING: characterstring_copy(&dest_value->type.Character_String, - &src_value->type.Character_String); + &src_value->type.Character_String); break; #endif -#if defined (BACAPP_BIT_STRING) +#if defined(BACAPP_BIT_STRING) case BACNET_APPLICATION_TAG_BIT_STRING: bitstring_copy(&dest_value->type.Bit_String, - &src_value->type.Bit_String); + &src_value->type.Bit_String); break; #endif -#if defined (BACAPP_ENUMERATED) +#if defined(BACAPP_ENUMERATED) case BACNET_APPLICATION_TAG_ENUMERATED: dest_value->type.Enumerated = src_value->type.Enumerated; break; #endif -#if defined (BACAPP_DATE) +#if defined(BACAPP_DATE) case BACNET_APPLICATION_TAG_DATE: datetime_copy_date(&dest_value->type.Date, - &src_value->type.Date); + &src_value->type.Date); break; #endif -#if defined (BACAPP_TIME) +#if defined(BACAPP_TIME) case BACNET_APPLICATION_TAG_TIME: datetime_copy_time(&dest_value->type.Time, - &src_value->type.Time); + &src_value->type.Time); break; #endif -#if defined (BACAPP_OBJECT_ID) +#if defined(BACAPP_OBJECT_ID) case BACNET_APPLICATION_TAG_OBJECT_ID: dest_value->type.Object_Id.type = src_value->type.Object_Id.type; @@ -923,11 +855,11 @@ bool bacapp_copy( src_value->type.Object_Id.instance; break; #endif -#if defined (BACAPP_LIGHTING_COMMAND) +#if defined(BACAPP_LIGHTING_COMMAND) case BACNET_APPLICATION_TAG_LIGHTING_COMMAND: - status = lighting_command_copy( - &dest_value->type.Lighting_Command, - &src_value->type.Lighting_Command); + status = + lighting_command_copy(&dest_value->type.Lighting_Command, + &src_value->type.Lighting_Command); break; #endif default: @@ -944,10 +876,8 @@ bool bacapp_copy( Expects that the first octet contain the opening tag. Include a value property identifier for context specific data such as the value received in a WriteProperty request */ -int bacapp_data_len( - uint8_t * apdu, - unsigned max_apdu_len, - BACNET_PROPERTY_ID property) +int bacapp_data_len(uint8_t *apdu, unsigned max_apdu_len, + BACNET_PROPERTY_ID property) { int len = 0; int total_len = 0; @@ -958,34 +888,29 @@ int bacapp_data_len( uint32_t value = 0; if (IS_OPENING_TAG(apdu[0])) { - len = - decode_tag_number_and_value(&apdu[apdu_len], &tag_number, &value); + len = decode_tag_number_and_value(&apdu[apdu_len], &tag_number, &value); apdu_len += len; opening_tag_number = tag_number; opening_tag_number_counter = 1; while (opening_tag_number_counter) { if (IS_OPENING_TAG(apdu[apdu_len])) { - len = - decode_tag_number_and_value(&apdu[apdu_len], &tag_number, - &value); + len = decode_tag_number_and_value(&apdu[apdu_len], &tag_number, + &value); if (tag_number == opening_tag_number) opening_tag_number_counter++; } else if (IS_CLOSING_TAG(apdu[apdu_len])) { - len = - decode_tag_number_and_value(&apdu[apdu_len], &tag_number, - &value); + len = decode_tag_number_and_value(&apdu[apdu_len], &tag_number, + &value); if (tag_number == opening_tag_number) opening_tag_number_counter--; } else if (IS_CONTEXT_SPECIFIC(apdu[apdu_len])) { /* context-specific tagged data */ - len = - bacapp_decode_context_data_len(&apdu[apdu_len], - max_apdu_len - apdu_len, property); + len = bacapp_decode_context_data_len( + &apdu[apdu_len], max_apdu_len - apdu_len, property); } else { /* application tagged data */ - len = - bacapp_decode_application_data_len(&apdu[apdu_len], - max_apdu_len - apdu_len); + len = bacapp_decode_application_data_len( + &apdu[apdu_len], max_apdu_len - apdu_len); } apdu_len += len; if (opening_tag_number_counter) { @@ -997,7 +922,7 @@ int bacapp_data_len( break; } } - if ((unsigned) apdu_len > max_apdu_len) { + if ((unsigned)apdu_len > max_apdu_len) { /* error: exceeding our buffer limit */ total_len = BACNET_STATUS_ERROR; break; @@ -1009,10 +934,7 @@ int bacapp_data_len( } #ifdef BACAPP_SNPRINTF_ENABLED -static bool append_str( - char **str, - size_t * rem_str_len, - const char *add_str) +static bool append_str(char **str, size_t *rem_str_len, const char *add_str) { bool retval; int bytes_written; @@ -1040,10 +962,8 @@ static bool append_str( * to the output string. If output was truncated due to string size, * then the returned value is greater than str_len (a la snprintf() ). */ -int bacapp_snprintf_value( - char *str, - size_t str_len, - BACNET_OBJECT_PROPERTY_VALUE * object_value) +int bacapp_snprintf_value(char *str, size_t str_len, + BACNET_OBJECT_PROPERTY_VALUE *object_value) { size_t len = 0, i = 0; char *char_str; @@ -1065,25 +985,23 @@ int bacapp_snprintf_value( ret_val = snprintf(str, str_len, "Null"); break; case BACNET_APPLICATION_TAG_BOOLEAN: - ret_val = - (value->type.Boolean) ? snprintf(str, str_len, - "TRUE") : snprintf(str, str_len, "FALSE"); + ret_val = (value->type.Boolean) + ? snprintf(str, str_len, "TRUE") + : snprintf(str, str_len, "FALSE"); break; case BACNET_APPLICATION_TAG_UNSIGNED_INT: - ret_val = - snprintf(str, str_len, "%lu", - (unsigned long) value->type.Unsigned_Int); + ret_val = snprintf(str, str_len, "%lu", + (unsigned long)value->type.Unsigned_Int); break; case BACNET_APPLICATION_TAG_SIGNED_INT: ret_val = - snprintf(str, str_len, "%ld", - (long) value->type.Signed_Int); + snprintf(str, str_len, "%ld", (long)value->type.Signed_Int); break; case BACNET_APPLICATION_TAG_REAL: ret_val = - snprintf(str, str_len, "%f", (double) value->type.Real); + snprintf(str, str_len, "%f", (double)value->type.Real); break; -#if defined (BACAPP_DOUBLE) +#if defined(BACAPP_DOUBLE) case BACNET_APPLICATION_TAG_DOUBLE: ret_val = snprintf(str, str_len, "%f", value->type.Double); break; @@ -1104,12 +1022,11 @@ int bacapp_snprintf_value( break; case BACNET_APPLICATION_TAG_CHARACTER_STRING: len = characterstring_length(&value->type.Character_String); - char_str = - characterstring_value(&value->type.Character_String); + char_str = characterstring_value(&value->type.Character_String); if (!append_str(&p_str, &rem_str_len, "\"")) break; for (i = 0; i < len; i++) { - if (isprint(*((unsigned char *) char_str))) { + if (isprint(*((unsigned char *)char_str))) { snprintf(temp_str, sizeof(temp_str), "%c", *char_str); } else { snprintf(temp_str, sizeof(temp_str), "%c", '.'); @@ -1118,8 +1035,7 @@ int bacapp_snprintf_value( break; char_str++; } - if ((i == len) && append_str(&p_str, &rem_str_len, "\"") - ) { + if ((i == len) && append_str(&p_str, &rem_str_len, "\"")) { /* Everything is fine. Indicate how many bytes were */ /* written */ ret_val = str_len - rem_str_len; @@ -1131,8 +1047,9 @@ int bacapp_snprintf_value( break; for (i = 0; i < len; i++) { snprintf(temp_str, sizeof(temp_str), "%s", - bitstring_bit(&value->type.Bit_String, - (uint8_t) i) ? "true" : "false"); + bitstring_bit(&value->type.Bit_String, (uint8_t)i) + ? "true" + : "false"); if (!append_str(&p_str, &rem_str_len, temp_str)) break; if (i < len - 1) { @@ -1140,8 +1057,7 @@ int bacapp_snprintf_value( break; } } - if ((i == len) && append_str(&p_str, &rem_str_len, "}") - ) { + if ((i == len) && append_str(&p_str, &rem_str_len, "}")) { /* Everything is fine. Indicate how many bytes were */ /* written */ ret_val = str_len - rem_str_len; @@ -1150,116 +1066,109 @@ int bacapp_snprintf_value( case BACNET_APPLICATION_TAG_ENUMERATED: switch (property) { case PROP_PROPERTY_LIST: - char_str = (char *) bactext_property_name_default( + char_str = (char *)bactext_property_name_default( value->type.Enumerated, NULL); if (char_str) { ret_val = snprintf(str, str_len, "%s", char_str); } else { ret_val = snprintf(str, str_len, "%lu", - (unsigned long) value->type.Enumerated); + (unsigned long)value->type.Enumerated); } break; case PROP_OBJECT_TYPE: if (value->type.Enumerated < MAX_ASHRAE_OBJECT_TYPE) { - ret_val = - snprintf(str, str_len, "%s", - bactext_object_type_name(value->type. - Enumerated)); + ret_val = snprintf(str, str_len, "%s", + bactext_object_type_name( + value->type.Enumerated)); } else if (value->type.Enumerated < 128) { ret_val = snprintf(str, str_len, "reserved %lu", - (unsigned long) value->type.Enumerated); + (unsigned long)value->type.Enumerated); } else { ret_val = snprintf(str, str_len, "proprietary %lu", - (unsigned long) value->type.Enumerated); + (unsigned long)value->type.Enumerated); } break; case PROP_EVENT_STATE: - ret_val = - snprintf(str, str_len, "%s", + ret_val = snprintf( + str, str_len, "%s", bactext_event_state_name(value->type.Enumerated)); break; case PROP_UNITS: if (value->type.Enumerated < 256) { - ret_val = - snprintf(str, str_len, "%s", - bactext_engineering_unit_name(value-> - type.Enumerated)); + ret_val = snprintf(str, str_len, "%s", + bactext_engineering_unit_name( + value->type.Enumerated)); } else { ret_val = snprintf(str, str_len, "proprietary %lu", - (unsigned long) value->type.Enumerated); + (unsigned long)value->type.Enumerated); } break; case PROP_POLARITY: - ret_val = - snprintf(str, str_len, "%s", - bactext_binary_polarity_name(value-> - type.Enumerated)); + ret_val = snprintf(str, str_len, "%s", + bactext_binary_polarity_name( + value->type.Enumerated)); break; case PROP_PRESENT_VALUE: case PROP_RELINQUISH_DEFAULT: if (object_type < OBJECT_PROPRIETARY_MIN) { ret_val = snprintf(str, str_len, "%s", - bactext_binary_present_value_name(value->type. - Enumerated)); + bactext_binary_present_value_name( + value->type.Enumerated)); } else { ret_val = snprintf(str, str_len, "%lu", - (unsigned long) value->type.Enumerated); + (unsigned long)value->type.Enumerated); } break; case PROP_RELIABILITY: - ret_val = - snprintf(str, str_len, "%s", + ret_val = snprintf( + str, str_len, "%s", bactext_reliability_name(value->type.Enumerated)); break; case PROP_SYSTEM_STATUS: - ret_val = - snprintf(str, str_len, "%s", - bactext_device_status_name(value-> - type.Enumerated)); + ret_val = snprintf( + str, str_len, "%s", + bactext_device_status_name(value->type.Enumerated)); break; case PROP_SEGMENTATION_SUPPORTED: - ret_val = - snprintf(str, str_len, "%s", + ret_val = snprintf( + str, str_len, "%s", bactext_segmentation_name(value->type.Enumerated)); break; case PROP_NODE_TYPE: - ret_val = - snprintf(str, str_len, "%s", + ret_val = snprintf( + str, str_len, "%s", bactext_node_type_name(value->type.Enumerated)); break; default: ret_val = snprintf(str, str_len, "%lu", - (unsigned long) value->type.Enumerated); + (unsigned long)value->type.Enumerated); break; } break; case BACNET_APPLICATION_TAG_DATE: - if (!append_str(&p_str, &rem_str_len, - bactext_day_of_week_name(value->type.Date.wday) - ) - ) + if (!append_str( + &p_str, &rem_str_len, + bactext_day_of_week_name(value->type.Date.wday))) break; if (!append_str(&p_str, &rem_str_len, ", ")) break; if (!append_str(&p_str, &rem_str_len, - bactext_month_name(value->type.Date.month) - ) - ) + bactext_month_name(value->type.Date.month))) break; if (value->type.Date.day == 255) { if (!append_str(&p_str, &rem_str_len, " (unspecified), ")) break; } else { snprintf(temp_str, sizeof(temp_str), " %u, ", - (unsigned) value->type.Date.day); + (unsigned)value->type.Date.day); if (!append_str(&p_str, &rem_str_len, temp_str)) break; } @@ -1268,7 +1177,7 @@ int bacapp_snprintf_value( break; } else { snprintf(temp_str, sizeof(temp_str), "%u", - (unsigned) value->type.Date.year); + (unsigned)value->type.Date.year); if (!append_str(&p_str, &rem_str_len, temp_str)) break; } @@ -1281,8 +1190,8 @@ int bacapp_snprintf_value( if (!append_str(&p_str, &rem_str_len, "**:")) break; } else { - snprintf(temp_str, sizeof(temp_str), "%02u:", - (unsigned) value->type.Time.hour); + snprintf(temp_str, sizeof(temp_str), + "%02u:", (unsigned)value->type.Time.hour); if (!append_str(&p_str, &rem_str_len, temp_str)) break; } @@ -1290,8 +1199,8 @@ int bacapp_snprintf_value( if (!append_str(&p_str, &rem_str_len, "**:")) break; } else { - snprintf(temp_str, sizeof(temp_str), "%02u:", - (unsigned) value->type.Time.min); + snprintf(temp_str, sizeof(temp_str), + "%02u:", (unsigned)value->type.Time.min); if (!append_str(&p_str, &rem_str_len, temp_str)) break; } @@ -1300,7 +1209,7 @@ int bacapp_snprintf_value( break; } else { snprintf(temp_str, sizeof(temp_str), "%02u.", - (unsigned) value->type.Time.sec); + (unsigned)value->type.Time.sec); if (!append_str(&p_str, &rem_str_len, temp_str)) break; } @@ -1309,7 +1218,7 @@ int bacapp_snprintf_value( break; } else { snprintf(temp_str, sizeof(temp_str), "%02u", - (unsigned) value->type.Time.hundredths); + (unsigned)value->type.Time.hundredths); if (!append_str(&p_str, &rem_str_len, temp_str)) break; } @@ -1322,35 +1231,33 @@ int bacapp_snprintf_value( break; if (value->type.Object_Id.type < MAX_ASHRAE_OBJECT_TYPE) { if (!append_str(&p_str, &rem_str_len, - bactext_object_type_name(value->type. - Object_Id.type) - ) - ) + bactext_object_type_name( + value->type.Object_Id.type))) break; snprintf(temp_str, sizeof(temp_str), ", %lu", - (unsigned long) value->type.Object_Id.instance); + (unsigned long)value->type.Object_Id.instance); if (!append_str(&p_str, &rem_str_len, temp_str)) break; } else if (value->type.Object_Id.type < 128) { if (!append_str(&p_str, &rem_str_len, "reserved ")) break; snprintf(temp_str, sizeof(temp_str), "%u, ", - (unsigned) value->type.Object_Id.type); + (unsigned)value->type.Object_Id.type); if (!append_str(&p_str, &rem_str_len, temp_str)) break; snprintf(temp_str, sizeof(temp_str), "%lu", - (unsigned long) value->type.Object_Id.instance); + (unsigned long)value->type.Object_Id.instance); if (!append_str(&p_str, &rem_str_len, temp_str)) break; } else { if (!append_str(&p_str, &rem_str_len, "proprietary ")) break; snprintf(temp_str, sizeof(temp_str), "%u, ", - (unsigned) value->type.Object_Id.type); + (unsigned)value->type.Object_Id.type); if (!append_str(&p_str, &rem_str_len, temp_str)) break; snprintf(temp_str, sizeof(temp_str), "%lu", - (unsigned long) value->type.Object_Id.instance); + (unsigned long)value->type.Object_Id.instance); if (!append_str(&p_str, &rem_str_len, temp_str)) break; } @@ -1364,8 +1271,8 @@ int bacapp_snprintf_value( if (!append_str(&p_str, &rem_str_len, "(")) break; if (!append_str(&p_str, &rem_str_len, - bactext_lighting_operation_name(value->type. - Lighting_Command.operation))) { + bactext_lighting_operation_name( + value->type.Lighting_Command.operation))) { break; } /* FIXME: add the Lighting Command optional values */ @@ -1390,9 +1297,8 @@ int bacapp_snprintf_value( * specified stream. If stream is NULL, do not print anything. If extraction * failed, do not print anything. Return the status of the extraction. */ -bool bacapp_print_value( - FILE * stream, - BACNET_OBJECT_PROPERTY_VALUE * object_value) +bool bacapp_print_value(FILE *stream, + BACNET_OBJECT_PROPERTY_VALUE *object_value) { char *str; bool retval = false; @@ -1401,11 +1307,12 @@ bool bacapp_print_value( while (true) { /* Try to allocate memory for the output string. Give up if unable. */ - str = (char *) calloc(sizeof(char), str_len); + str = (char *)calloc(sizeof(char), str_len); if (!str) break; - /* Try to extract the value into allocated memory. If unable, try again */ + /* Try to extract the value into allocated memory. If unable, try again + */ /* another time with a string that is twice as large. */ status = bacapp_snprintf_value(str, str_len, object_value); if ((status < 0) || ((size_t)status >= str_len)) { @@ -1429,10 +1336,9 @@ bool bacapp_print_value( #ifdef BACAPP_PRINT_ENABLED /* used to load the app data struct with the proper data converted from a command line argument */ -bool bacapp_parse_application_data( - BACNET_APPLICATION_TAG tag_number, - const char *argv, - BACNET_APPLICATION_DATA_VALUE * value) +bool bacapp_parse_application_data(BACNET_APPLICATION_TAG tag_number, + const char *argv, + BACNET_APPLICATION_DATA_VALUE *value) { int hour, min, sec, hundredths; int year, month, day, wday; @@ -1465,25 +1371,23 @@ bool bacapp_parse_application_data( break; case BACNET_APPLICATION_TAG_REAL: double_value = strtod(argv, NULL); - value->type.Real = (float) double_value; + value->type.Real = (float)double_value; break; -#if defined (BACAPP_DOUBLE) +#if defined(BACAPP_DOUBLE) case BACNET_APPLICATION_TAG_DOUBLE: double_value = strtod(argv, NULL); value->type.Double = double_value; break; #endif case BACNET_APPLICATION_TAG_OCTET_STRING: -#if PRINT_ENABLED /* Apparently ain't necessarily so. */ +#if PRINT_ENABLED /* Apparently ain't necessarily so. */ status = - octetstring_init_ascii_hex(&value->type.Octet_String, - argv); + octetstring_init_ascii_hex(&value->type.Octet_String, argv); #endif break; case BACNET_APPLICATION_TAG_CHARACTER_STRING: - status = - characterstring_init_ansi(&value->type.Character_String, - (char *) argv); + status = characterstring_init_ansi( + &value->type.Character_String, (char *)argv); break; case BACNET_APPLICATION_TAG_BIT_STRING: #if PRINT_ENABLED @@ -1496,37 +1400,35 @@ bool bacapp_parse_application_data( break; case BACNET_APPLICATION_TAG_DATE: count = - sscanf(argv, "%4d/%3d/%3d:%3d", &year, &month, &day, - &wday); + sscanf(argv, "%4d/%3d/%3d:%3d", &year, &month, &day, &wday); if (count == 3) { - datetime_set_date(&value->type.Date, (uint16_t) year, - (uint8_t) month, (uint8_t) day); + datetime_set_date(&value->type.Date, (uint16_t)year, + (uint8_t)month, (uint8_t)day); } else if (count == 4) { - value->type.Date.year = (uint16_t) year; - value->type.Date.month = (uint8_t) month; - value->type.Date.day = (uint8_t) day; - value->type.Date.wday = (uint8_t) wday; + value->type.Date.year = (uint16_t)year; + value->type.Date.month = (uint8_t)month; + value->type.Date.day = (uint8_t)day; + value->type.Date.wday = (uint8_t)wday; } else { status = false; } break; case BACNET_APPLICATION_TAG_TIME: - count = - sscanf(argv, "%3d:%3d:%3d.%3d", &hour, &min, &sec, - &hundredths); + count = sscanf(argv, "%3d:%3d:%3d.%3d", &hour, &min, &sec, + &hundredths); if (count == 4) { - value->type.Time.hour = (uint8_t) hour; - value->type.Time.min = (uint8_t) min; - value->type.Time.sec = (uint8_t) sec; - value->type.Time.hundredths = (uint8_t) hundredths; + value->type.Time.hour = (uint8_t)hour; + value->type.Time.min = (uint8_t)min; + value->type.Time.sec = (uint8_t)sec; + value->type.Time.hundredths = (uint8_t)hundredths; } else if (count == 3) { - value->type.Time.hour = (uint8_t) hour; - value->type.Time.min = (uint8_t) min; - value->type.Time.sec = (uint8_t) sec; + value->type.Time.hour = (uint8_t)hour; + value->type.Time.min = (uint8_t)min; + value->type.Time.sec = (uint8_t)sec; value->type.Time.hundredths = 0; } else if (count == 2) { - value->type.Time.hour = (uint8_t) hour; - value->type.Time.min = (uint8_t) min; + value->type.Time.hour = (uint8_t)hour; + value->type.Time.min = (uint8_t)min; value->type.Time.sec = 0; value->type.Time.hundredths = 0; } else { @@ -1536,7 +1438,7 @@ bool bacapp_parse_application_data( case BACNET_APPLICATION_TAG_OBJECT_ID: count = sscanf(argv, "%4d:%7d", &object_type, &instance); if (count == 2) { - value->type.Object_Id.type = (uint16_t) object_type; + value->type.Object_Id.type = (uint16_t)object_type; value->type.Object_Id.instance = instance; } else { status = false; @@ -1561,9 +1463,7 @@ bool bacapp_parse_application_data( * @param value - one or more #BACNET_APPLICATION_DATA_VALUE elements * @param count - number of #BACNET_APPLICATION_DATA_VALUE elements */ -void bacapp_value_list_init( - BACNET_APPLICATION_DATA_VALUE *value, - size_t count) +void bacapp_value_list_init(BACNET_APPLICATION_DATA_VALUE *value, size_t count) { size_t i = 0; @@ -1572,7 +1472,7 @@ void bacapp_value_list_init( value->tag = BACNET_APPLICATION_TAG_NULL; value->context_specific = 0; value->context_tag = 0; - if ((i+1) < count) { + if ((i + 1) < count) { value->next = value + 1; } else { value->next = NULL; @@ -1588,9 +1488,7 @@ void bacapp_value_list_init( * @param value - one or more #BACNET_PROPERTY_VALUE elements * @param count - number of #BACNET_PROPERTY_VALUE elements */ -void bacapp_property_value_list_init( - BACNET_PROPERTY_VALUE *value, - size_t count) +void bacapp_property_value_list_init(BACNET_PROPERTY_VALUE *value, size_t count) { size_t i = 0; @@ -1600,7 +1498,7 @@ void bacapp_property_value_list_init( value->propertyArrayIndex = BACNET_ARRAY_ALL; value->priority = BACNET_NO_PRIORITY; bacapp_value_list_init(&value->value, 1); - if ((i+1) < count) { + if ((i + 1) < count) { value->next = value + 1; } else { value->next = NULL; @@ -1615,16 +1513,14 @@ void bacapp_property_value_list_init( #include #include "ctest.h" - #include /* generic - can be used by other unit tests returns true if matching or same, false if different */ -bool bacapp_same_value( - BACNET_APPLICATION_DATA_VALUE * value, - BACNET_APPLICATION_DATA_VALUE * test_value) +bool bacapp_same_value(BACNET_APPLICATION_DATA_VALUE *value, + BACNET_APPLICATION_DATA_VALUE *test_value) { - bool status = false; /*return value */ + bool status = false; /*return value */ /* does the tag match? */ if (test_value->tag == value->tag) @@ -1634,97 +1530,95 @@ bool bacapp_same_value( status = false; /* does the value match? */ switch (test_value->tag) { -#if defined (BACAPP_NULL) +#if defined(BACAPP_NULL) case BACNET_APPLICATION_TAG_NULL: status = true; break; #endif -#if defined (BACAPP_BOOLEAN) +#if defined(BACAPP_BOOLEAN) case BACNET_APPLICATION_TAG_BOOLEAN: if (test_value->type.Boolean == value->type.Boolean) status = true; break; #endif -#if defined (BACAPP_UNSIGNED) +#if defined(BACAPP_UNSIGNED) case BACNET_APPLICATION_TAG_UNSIGNED_INT: if (test_value->type.Unsigned_Int == value->type.Unsigned_Int) status = true; break; #endif -#if defined (BACAPP_SIGNED) +#if defined(BACAPP_SIGNED) case BACNET_APPLICATION_TAG_SIGNED_INT: if (test_value->type.Signed_Int == value->type.Signed_Int) status = true; break; #endif -#if defined (BACAPP_REAL) +#if defined(BACAPP_REAL) case BACNET_APPLICATION_TAG_REAL: if (test_value->type.Real == value->type.Real) status = true; break; #endif -#if defined (BACAPP_DOUBLE) +#if defined(BACAPP_DOUBLE) case BACNET_APPLICATION_TAG_DOUBLE: if (test_value->type.Double == value->type.Double) status = true; break; #endif -#if defined (BACAPP_ENUMERATED) +#if defined(BACAPP_ENUMERATED) case BACNET_APPLICATION_TAG_ENUMERATED: if (test_value->type.Enumerated == value->type.Enumerated) status = true; break; #endif -#if defined (BACAPP_DATE) +#if defined(BACAPP_DATE) case BACNET_APPLICATION_TAG_DATE: if (datetime_compare_date(&test_value->type.Date, - &value->type.Date) == 0) + &value->type.Date) == 0) status = true; break; #endif -#if defined (BACAPP_TIME) +#if defined(BACAPP_TIME) case BACNET_APPLICATION_TAG_TIME: if (datetime_compare_time(&test_value->type.Time, - &value->type.Time) == 0) + &value->type.Time) == 0) status = true; break; #endif -#if defined (BACAPP_OBJECT_ID) +#if defined(BACAPP_OBJECT_ID) case BACNET_APPLICATION_TAG_OBJECT_ID: if ((test_value->type.Object_Id.type == - value->type.Object_Id.type) && + value->type.Object_Id.type) && (test_value->type.Object_Id.instance == - value->type.Object_Id.instance)) { + value->type.Object_Id.instance)) { status = true; } break; #endif -#if defined (BACAPP_CHARACTER_STRING) +#if defined(BACAPP_CHARACTER_STRING) case BACNET_APPLICATION_TAG_CHARACTER_STRING: status = characterstring_same(&value->type.Character_String, - &test_value->type.Character_String); + &test_value->type.Character_String); break; #endif -#if defined (BACAPP_OCTET_STRING) +#if defined(BACAPP_OCTET_STRING) case BACNET_APPLICATION_TAG_OCTET_STRING: - status = - octetstring_value_same(&value->type.Octet_String, - &test_value->type.Octet_String); + status = octetstring_value_same(&value->type.Octet_String, + &test_value->type.Octet_String); break; #endif -#if defined (BACAPP_BIT_STRING) +#if defined(BACAPP_BIT_STRING) case BACNET_APPLICATION_TAG_BIT_STRING: - status = - bitstring_same(&value->type.Bit_String, - &test_value->type.Bit_String); + status = bitstring_same(&value->type.Bit_String, + &test_value->type.Bit_String); break; #endif -#if defined (BACAPP_LIGHTING_COMMAND) +#if defined(BACAPP_LIGHTING_COMMAND) case BACNET_APPLICATION_TAG_LIGHTING_COMMAND: - status = lighting_command_same( - &value->type.Lighting_Command, - &test_value->type.Lighting_Command); + status = + lighting_command_same(&value->type.Lighting_Command, + &test_value->type.Lighting_Command); break; #endif default: @@ -1735,8 +1629,7 @@ bool bacapp_same_value( return status; } -void testBACnetApplicationData_Safe( - Test * pTest) +void testBACnetApplicationData_Safe(Test *pTest) { int i; uint8_t apdu[MAX_APDU]; @@ -1747,9 +1640,8 @@ void testBACnetApplicationData_Safe( uint32_t single_length_segment; BACNET_APPLICATION_DATA_VALUE value; - for (i = 0; i < 13; i++) { - input_value[i].tag = (BACNET_APPLICATION_TAG) i; + input_value[i].tag = (BACNET_APPLICATION_TAG)i; input_value[i].context_specific = 0; input_value[i].context_tag = 0; input_value[i].next = NULL; @@ -1776,17 +1668,15 @@ void testBACnetApplicationData_Safe( input_value[i].type.Double = 2.32323232323; break; - case BACNET_APPLICATION_TAG_OCTET_STRING: - { - uint8_t test_octet[5] = { "Karg" }; - octetstring_init(&input_value[i].type.Octet_String, - test_octet, sizeof(test_octet)); - } - break; + case BACNET_APPLICATION_TAG_OCTET_STRING: { + 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: @@ -1826,8 +1716,8 @@ void testBACnetApplicationData_Safe( default: break; } - single_length_segment = - bacapp_encode_data(&apdu[len], &input_value[i]);; + single_length_segment = bacapp_encode_data(&apdu[len], &input_value[i]); + ; assert(single_length_segment > 0); /* len_segment is accumulated length */ if (i == 0) { @@ -1848,16 +1738,14 @@ void testBACnetApplicationData_Safe( if (i == 13) { expected_status = false; } else { - if (apdu_len < len_segment[i]) { expected_status = false; } else { expected_status = true; } } - status = - bacapp_decode_application_data_safe(i == 0 ? apdu : NULL, - apdu_len, &value); + status = bacapp_decode_application_data_safe(i == 0 ? apdu : NULL, + apdu_len, &value); ct_test(pTest, status == expected_status); if (status) { @@ -1872,14 +1760,12 @@ void testBACnetApplicationData_Safe( } } - -void testBACnetApplicationDataLength( - Test * pTest) +void testBACnetApplicationDataLength(Test *pTest) { - int apdu_len = 0; /* total length of the apdu, return value */ - int len = 0; /* total length of the apdu, return value */ - int test_len = 0; /* length of the data */ - uint8_t apdu[480] = { 0 }; + int apdu_len = 0; /* total length of the apdu, return value */ + int len = 0; /* total length of the apdu, return value */ + int test_len = 0; /* length of the data */ + uint8_t apdu[480] = {0}; BACNET_TIME local_time; BACNET_DATE local_date; @@ -1892,9 +1778,8 @@ void testBACnetApplicationDataLength( len = encode_closing_tag(&apdu[apdu_len], 3); apdu_len += len; /* verify the length of the data inside the opening/closing tags */ - len = - bacapp_data_len(&apdu[0], apdu_len, - PROP_LIST_OF_OBJECT_PROPERTY_REFERENCES); + len = bacapp_data_len(&apdu[0], apdu_len, + PROP_LIST_OF_OBJECT_PROPERTY_REFERENCES); ct_test(pTest, test_len == len); /* 2. application tagged data, one element */ @@ -1978,10 +1863,10 @@ void testBACnetApplicationDataLength( len = encode_opening_tag(&apdu[apdu_len], 3); test_len += len; apdu_len += len; - local_date.year = 2006; /* AD */ - local_date.month = 4; /* 1=Jan */ - local_date.day = 1; /* 1..31 */ - local_date.wday = 6; /* 1=Monday */ + local_date.year = 2006; /* AD */ + local_date.month = 4; /* 1=Jan */ + local_date.day = 1; /* 1..31 */ + local_date.wday = 6; /* 1=Monday */ len = encode_application_date(&apdu[apdu_len], &local_date); test_len += len; apdu_len += len; @@ -2003,8 +1888,6 @@ void testBACnetApplicationDataLength( /* 5. complex datatype - multiple elements */ - - /* 6. context tagged data, one element */ test_len = 0; apdu_len = 0; @@ -2020,10 +1903,9 @@ void testBACnetApplicationDataLength( ct_test(pTest, test_len == len); } -static bool testBACnetApplicationDataValue( - BACNET_APPLICATION_DATA_VALUE * value) +static bool testBACnetApplicationDataValue(BACNET_APPLICATION_DATA_VALUE *value) { - uint8_t apdu[480] = { 0 }; + uint8_t apdu[480] = {0}; int apdu_len = 0; BACNET_APPLICATION_DATA_VALUE test_value; @@ -2033,126 +1915,105 @@ static bool testBACnetApplicationDataValue( return bacapp_same_value(value, &test_value); } -void testBACnetApplicationData( - Test * pTest) +void testBACnetApplicationData(Test *pTest) { BACNET_APPLICATION_DATA_VALUE value; bool status = false; - - status = - bacapp_parse_application_data(BACNET_APPLICATION_TAG_NULL, NULL, - &value); + status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_NULL, NULL, + &value); ct_test(pTest, status == true); status = testBACnetApplicationDataValue(&value); ct_test(pTest, status == true); - status = - bacapp_parse_application_data(BACNET_APPLICATION_TAG_BOOLEAN, "1", - &value); + status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_BOOLEAN, "1", + &value); ct_test(pTest, status == true); ct_test(pTest, value.type.Boolean == true); ct_test(pTest, testBACnetApplicationDataValue(&value)); - status = - bacapp_parse_application_data(BACNET_APPLICATION_TAG_BOOLEAN, "0", - &value); + status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_BOOLEAN, "0", + &value); ct_test(pTest, status == true); ct_test(pTest, value.type.Boolean == false); ct_test(pTest, testBACnetApplicationDataValue(&value)); - status = - bacapp_parse_application_data(BACNET_APPLICATION_TAG_UNSIGNED_INT, "0", - &value); + status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_UNSIGNED_INT, + "0", &value); ct_test(pTest, status == true); ct_test(pTest, value.type.Unsigned_Int == 0); ct_test(pTest, testBACnetApplicationDataValue(&value)); - status = - bacapp_parse_application_data(BACNET_APPLICATION_TAG_UNSIGNED_INT, - "0xFFFF", &value); + status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_UNSIGNED_INT, + "0xFFFF", &value); ct_test(pTest, status == true); ct_test(pTest, value.type.Unsigned_Int == 0xFFFF); ct_test(pTest, testBACnetApplicationDataValue(&value)); - status = - bacapp_parse_application_data(BACNET_APPLICATION_TAG_UNSIGNED_INT, - "0xFFFFFFFF", &value); + status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_UNSIGNED_INT, + "0xFFFFFFFF", &value); ct_test(pTest, status == true); ct_test(pTest, value.type.Unsigned_Int == 0xFFFFFFFF); ct_test(pTest, testBACnetApplicationDataValue(&value)); - status = - bacapp_parse_application_data(BACNET_APPLICATION_TAG_SIGNED_INT, "0", - &value); + status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_SIGNED_INT, + "0", &value); ct_test(pTest, status == true); ct_test(pTest, value.type.Signed_Int == 0); ct_test(pTest, testBACnetApplicationDataValue(&value)); - status = - bacapp_parse_application_data(BACNET_APPLICATION_TAG_SIGNED_INT, "-1", - &value); + status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_SIGNED_INT, + "-1", &value); ct_test(pTest, status == true); ct_test(pTest, value.type.Signed_Int == -1); ct_test(pTest, testBACnetApplicationDataValue(&value)); - status = - bacapp_parse_application_data(BACNET_APPLICATION_TAG_SIGNED_INT, - "32768", &value); + status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_SIGNED_INT, + "32768", &value); ct_test(pTest, status == true); ct_test(pTest, value.type.Signed_Int == 32768); ct_test(pTest, testBACnetApplicationDataValue(&value)); - status = - bacapp_parse_application_data(BACNET_APPLICATION_TAG_SIGNED_INT, - "-32768", &value); + status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_SIGNED_INT, + "-32768", &value); ct_test(pTest, status == true); ct_test(pTest, value.type.Signed_Int == -32768); ct_test(pTest, testBACnetApplicationDataValue(&value)); - status = - bacapp_parse_application_data(BACNET_APPLICATION_TAG_REAL, "0.0", - &value); + status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_REAL, "0.0", + &value); ct_test(pTest, status == true); ct_test(pTest, testBACnetApplicationDataValue(&value)); - status = - bacapp_parse_application_data(BACNET_APPLICATION_TAG_REAL, "-1.0", - &value); + status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_REAL, "-1.0", + &value); ct_test(pTest, status == true); ct_test(pTest, testBACnetApplicationDataValue(&value)); - status = - bacapp_parse_application_data(BACNET_APPLICATION_TAG_REAL, "1.0", - &value); + status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_REAL, "1.0", + &value); ct_test(pTest, status == true); ct_test(pTest, testBACnetApplicationDataValue(&value)); - status = - bacapp_parse_application_data(BACNET_APPLICATION_TAG_REAL, "3.14159", - &value); + status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_REAL, + "3.14159", &value); ct_test(pTest, status == true); ct_test(pTest, testBACnetApplicationDataValue(&value)); - status = - bacapp_parse_application_data(BACNET_APPLICATION_TAG_REAL, "-3.14159", - &value); + status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_REAL, + "-3.14159", &value); ct_test(pTest, status == true); ct_test(pTest, testBACnetApplicationDataValue(&value)); - status = - bacapp_parse_application_data(BACNET_APPLICATION_TAG_ENUMERATED, "0", - &value); + status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_ENUMERATED, + "0", &value); ct_test(pTest, status == true); ct_test(pTest, value.type.Enumerated == 0); ct_test(pTest, testBACnetApplicationDataValue(&value)); - status = - bacapp_parse_application_data(BACNET_APPLICATION_TAG_ENUMERATED, - "0xFFFF", &value); + status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_ENUMERATED, + "0xFFFF", &value); ct_test(pTest, status == true); ct_test(pTest, value.type.Enumerated == 0xFFFF); ct_test(pTest, testBACnetApplicationDataValue(&value)); - status = - bacapp_parse_application_data(BACNET_APPLICATION_TAG_ENUMERATED, - "0xFFFFFFFF", &value); + status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_ENUMERATED, + "0xFFFFFFFF", &value); ct_test(pTest, status == true); ct_test(pTest, value.type.Enumerated == 0xFFFFFFFF); ct_test(pTest, testBACnetApplicationDataValue(&value)); - status = - bacapp_parse_application_data(BACNET_APPLICATION_TAG_DATE, - "2005/5/22:1", &value); + status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_DATE, + "2005/5/22:1", &value); ct_test(pTest, status == true); ct_test(pTest, value.type.Date.year == 2005); ct_test(pTest, value.type.Date.month == 5); @@ -2161,9 +2022,8 @@ void testBACnetApplicationData( ct_test(pTest, testBACnetApplicationDataValue(&value)); /* Happy Valentines Day! */ - status = - bacapp_parse_application_data(BACNET_APPLICATION_TAG_DATE, "2007/2/14", - &value); + status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_DATE, + "2007/2/14", &value); ct_test(pTest, status == true); ct_test(pTest, value.type.Date.year == 2007); ct_test(pTest, value.type.Date.month == 2); @@ -2172,9 +2032,8 @@ void testBACnetApplicationData( ct_test(pTest, testBACnetApplicationDataValue(&value)); /* Wildcard Values */ - status = - bacapp_parse_application_data(BACNET_APPLICATION_TAG_DATE, - "2155/255/255:255", &value); + status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_DATE, + "2155/255/255:255", &value); ct_test(pTest, status == true); ct_test(pTest, value.type.Date.year == 2155); ct_test(pTest, value.type.Date.month == 255); @@ -2182,9 +2041,8 @@ void testBACnetApplicationData( ct_test(pTest, value.type.Date.wday == 255); ct_test(pTest, testBACnetApplicationDataValue(&value)); - status = - bacapp_parse_application_data(BACNET_APPLICATION_TAG_TIME, - "23:59:59.12", &value); + status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_TIME, + "23:59:59.12", &value); ct_test(pTest, status == true); ct_test(pTest, value.type.Time.hour == 23); ct_test(pTest, value.type.Time.min == 59); @@ -2192,9 +2050,8 @@ void testBACnetApplicationData( ct_test(pTest, value.type.Time.hundredths == 12); ct_test(pTest, testBACnetApplicationDataValue(&value)); - status = - bacapp_parse_application_data(BACNET_APPLICATION_TAG_TIME, "23:59:59", - &value); + status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_TIME, + "23:59:59", &value); ct_test(pTest, status == true); ct_test(pTest, value.type.Time.hour == 23); ct_test(pTest, value.type.Time.min == 59); @@ -2202,9 +2059,8 @@ void testBACnetApplicationData( ct_test(pTest, value.type.Time.hundredths == 0); ct_test(pTest, testBACnetApplicationDataValue(&value)); - status = - bacapp_parse_application_data(BACNET_APPLICATION_TAG_TIME, "23:59", - &value); + status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_TIME, "23:59", + &value); ct_test(pTest, status == true); ct_test(pTest, value.type.Time.hour == 23); ct_test(pTest, value.type.Time.min == 59); @@ -2213,9 +2069,8 @@ void testBACnetApplicationData( ct_test(pTest, testBACnetApplicationDataValue(&value)); /* Wildcard Values */ - status = - bacapp_parse_application_data(BACNET_APPLICATION_TAG_TIME, - "255:255:255.255", &value); + status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_TIME, + "255:255:255.255", &value); ct_test(pTest, status == true); ct_test(pTest, value.type.Time.hour == 255); ct_test(pTest, value.type.Time.min == 255); @@ -2223,55 +2078,46 @@ void testBACnetApplicationData( ct_test(pTest, value.type.Time.hundredths == 255); ct_test(pTest, testBACnetApplicationDataValue(&value)); - status = - bacapp_parse_application_data(BACNET_APPLICATION_TAG_OBJECT_ID, - "0:100", &value); + status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_OBJECT_ID, + "0:100", &value); ct_test(pTest, status == true); ct_test(pTest, value.type.Object_Id.type == 0); ct_test(pTest, value.type.Object_Id.instance == 100); ct_test(pTest, testBACnetApplicationDataValue(&value)); - status = - bacapp_parse_application_data(BACNET_APPLICATION_TAG_CHARACTER_STRING, - "Karg!", &value); + status = bacapp_parse_application_data( + BACNET_APPLICATION_TAG_CHARACTER_STRING, "Karg!", &value); ct_test(pTest, status == true); ct_test(pTest, testBACnetApplicationDataValue(&value)); /* test empty string */ - status = - bacapp_parse_application_data(BACNET_APPLICATION_TAG_CHARACTER_STRING, - "", &value); + status = bacapp_parse_application_data( + BACNET_APPLICATION_TAG_CHARACTER_STRING, "", &value); ct_test(pTest, status == true); ct_test(pTest, testBACnetApplicationDataValue(&value)); - status = - bacapp_parse_application_data(BACNET_APPLICATION_TAG_OCTET_STRING, - "1234567890ABCDEF", &value); + status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_OCTET_STRING, + "1234567890ABCDEF", &value); ct_test(pTest, status == true); ct_test(pTest, testBACnetApplicationDataValue(&value)); - status = - bacapp_parse_application_data(BACNET_APPLICATION_TAG_OCTET_STRING, - "12-34-56-78-90-AB-CD-EF", &value); + status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_OCTET_STRING, + "12-34-56-78-90-AB-CD-EF", &value); ct_test(pTest, status == true); ct_test(pTest, testBACnetApplicationDataValue(&value)); - status = - bacapp_parse_application_data(BACNET_APPLICATION_TAG_OCTET_STRING, - "12 34 56 78 90 AB CD EF", &value); + status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_OCTET_STRING, + "12 34 56 78 90 AB CD EF", &value); ct_test(pTest, status == true); ct_test(pTest, testBACnetApplicationDataValue(&value)); /* test empty string */ - status = - bacapp_parse_application_data(BACNET_APPLICATION_TAG_OCTET_STRING, "", - &value); + status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_OCTET_STRING, + "", &value); ct_test(pTest, status == true); ct_test(pTest, testBACnetApplicationDataValue(&value)); return; } - #ifdef TEST_BACNET_APPLICATION_DATA -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -2287,7 +2133,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/src/bacdcode.c b/src/bacdcode.c index 799b4d91..60c6a8c7 100644 --- a/src/bacdcode.c +++ b/src/bacdcode.c @@ -44,7 +44,6 @@ /** @file bacdcode.c Functions to encode/decode BACnet data types */ - /* max-segments-accepted B'000' Unspecified number of segments accepted. B'001' 2 segments accepted. @@ -91,13 +90,10 @@ B'111' interpreted as Type = Closing Tag */ - /* from clause 20.1.2.4 max-segments-accepted */ /* and clause 20.1.2.5 max-APDU-length-accepted */ /* returns the encoded octet */ -uint8_t encode_max_segs_max_apdu( - int max_segs, - int max_apdu) +uint8_t encode_max_segs_max_apdu(int max_segs, int max_apdu) { uint8_t octet = 0; @@ -141,8 +137,7 @@ uint8_t encode_max_segs_max_apdu( /* from clause 20.1.2.4 max-segments-accepted */ /* and clause 20.1.2.5 max-APDU-length-accepted */ /* returns the encoded octet */ -int decode_max_segs( - uint8_t octet) +int decode_max_segs(uint8_t octet) { int max_segs = 0; @@ -178,8 +173,7 @@ int decode_max_segs( return max_segs; } -int decode_max_apdu( - uint8_t octet) +int decode_max_apdu(uint8_t octet) { int max_apdu = 0; @@ -211,13 +205,10 @@ int decode_max_apdu( /* from clause 20.2.1 General Rules for Encoding BACnet Tags */ /* returns the number of apdu bytes consumed */ -int encode_tag( - uint8_t * apdu, - uint8_t tag_number, - bool context_specific, - uint32_t len_value_type) +int encode_tag(uint8_t *apdu, uint8_t tag_number, bool context_specific, + uint32_t len_value_type) { - int len = 1; /* return value */ + int len = 1; /* return value */ apdu[0] = 0; if (context_specific) @@ -240,10 +231,10 @@ int encode_tag( } else { apdu[0] |= 5; if (len_value_type <= 253) { - apdu[len++] = (uint8_t) len_value_type; + apdu[len++] = (uint8_t)len_value_type; } else if (len_value_type <= 65535) { apdu[len++] = 254; - len += encode_unsigned16(&apdu[len], (uint16_t) len_value_type); + len += encode_unsigned16(&apdu[len], (uint16_t)len_value_type); } else { apdu[len++] = 255; len += encode_unsigned32(&apdu[len], len_value_type); @@ -255,9 +246,7 @@ int encode_tag( /* from clause 20.2.1.3.2 Constructed Data */ /* returns the number of apdu bytes consumed */ -int encode_opening_tag( - uint8_t * apdu, - uint8_t tag_number) +int encode_opening_tag(uint8_t *apdu, uint8_t tag_number) { int len = 1; @@ -279,9 +268,7 @@ int encode_opening_tag( /* from clause 20.2.1.3.2 Constructed Data */ /* returns the number of apdu bytes consumed */ -int encode_closing_tag( - uint8_t * apdu, - uint8_t tag_number) +int encode_closing_tag(uint8_t *apdu, uint8_t tag_number) { int len = 1; @@ -301,13 +288,9 @@ int encode_closing_tag( return len; } - - -int decode_tag_number( - uint8_t * apdu, - uint8_t * tag_number) +int decode_tag_number(uint8_t *apdu, uint8_t *tag_number) { - int len = 1; /* return value */ + int len = 1; /* return value */ /* decode the tag number first */ if (IS_EXTENDED_TAG_NUMBER(apdu[0])) { @@ -318,7 +301,7 @@ int decode_tag_number( len++; } else { if (tag_number) { - *tag_number = (uint8_t) (apdu[0] >> 4); + *tag_number = (uint8_t)(apdu[0] >> 4); } } @@ -326,12 +309,10 @@ int decode_tag_number( } /* Same as function above, but will safely fail if packet has been truncated */ -int decode_tag_number_safe( - uint8_t * apdu, - uint32_t apdu_len_remaining, - uint8_t * tag_number) +int decode_tag_number_safe(uint8_t *apdu, uint32_t apdu_len_remaining, + uint8_t *tag_number) { - int len = 0; /* return value */ + int len = 0; /* return value */ /* decode the tag number first */ if (apdu_len_remaining >= 1) { @@ -343,7 +324,7 @@ int decode_tag_number_safe( len = 2; } else { if (tag_number) { - *tag_number = (uint8_t) (apdu[0] >> 4); + *tag_number = (uint8_t)(apdu[0] >> 4); } len = 1; } @@ -351,26 +332,22 @@ int decode_tag_number_safe( return len; } -bool decode_is_opening_tag( - uint8_t * apdu) +bool decode_is_opening_tag(uint8_t *apdu) { - return (bool) ((apdu[0] & 0x07) == 6); + return (bool)((apdu[0] & 0x07) == 6); } /* from clause 20.2.1.3.2 Constructed Data */ /* returns the number of apdu bytes consumed */ -bool decode_is_closing_tag( - uint8_t * apdu) +bool decode_is_closing_tag(uint8_t *apdu) { - return (bool) ((apdu[0] & 0x07) == 7); + return (bool)((apdu[0] & 0x07) == 7); } /* from clause 20.2.1.3.2 Constructed Data */ /* returns the number of apdu bytes consumed */ -int decode_tag_number_and_value( - uint8_t * apdu, - uint8_t * tag_number, - uint32_t * value) +int decode_tag_number_and_value(uint8_t *apdu, uint8_t *tag_number, + uint32_t *value) { int len = 1; uint16_t value16; @@ -415,11 +392,8 @@ int decode_tag_number_and_value( } /* Same as function above, but will safely fail is packet has been truncated */ -int decode_tag_number_and_value_safe( - uint8_t * apdu, - uint32_t apdu_len_remaining, - uint8_t * tag_number, - uint32_t * value) +int decode_tag_number_and_value_safe(uint8_t *apdu, uint32_t apdu_len_remaining, + uint8_t *tag_number, uint32_t *value) { int len = 0; @@ -471,60 +445,48 @@ int decode_tag_number_and_value_safe( /* from clause 20.2.1.3.2 Constructed Data */ /* returns true if the tag is context specific and matches */ -bool decode_is_context_tag( - uint8_t * apdu, - uint8_t tag_number) +bool decode_is_context_tag(uint8_t *apdu, uint8_t tag_number) { uint8_t my_tag_number = 0; decode_tag_number(apdu, &my_tag_number); - return (bool) (IS_CONTEXT_SPECIFIC(*apdu) && - (my_tag_number == tag_number)); + return (bool)(IS_CONTEXT_SPECIFIC(*apdu) && (my_tag_number == tag_number)); } -bool decode_is_context_tag_with_length( - uint8_t * apdu, - uint8_t tag_number, - int *tag_length) +bool decode_is_context_tag_with_length(uint8_t *apdu, uint8_t tag_number, + int *tag_length) { uint8_t my_tag_number = 0; *tag_length = decode_tag_number(apdu, &my_tag_number); - return (bool) (IS_CONTEXT_SPECIFIC(*apdu) && - (my_tag_number == tag_number)); + return (bool)(IS_CONTEXT_SPECIFIC(*apdu) && (my_tag_number == tag_number)); } /* from clause 20.2.1.3.2 Constructed Data */ /* returns the true if the tag matches */ -bool decode_is_opening_tag_number( - uint8_t * apdu, - uint8_t tag_number) +bool decode_is_opening_tag_number(uint8_t *apdu, uint8_t tag_number) { uint8_t my_tag_number = 0; decode_tag_number(apdu, &my_tag_number); - return (bool) (IS_OPENING_TAG(apdu[0]) && (my_tag_number == tag_number)); + return (bool)(IS_OPENING_TAG(apdu[0]) && (my_tag_number == tag_number)); } /* from clause 20.2.1.3.2 Constructed Data */ /* returns the number of apdu bytes consumed */ -bool decode_is_closing_tag_number( - uint8_t * apdu, - uint8_t tag_number) +bool decode_is_closing_tag_number(uint8_t *apdu, uint8_t tag_number) { uint8_t my_tag_number = 0; decode_tag_number(apdu, &my_tag_number); - return (bool) (IS_CLOSING_TAG(apdu[0]) && (my_tag_number == tag_number)); + return (bool)(IS_CLOSING_TAG(apdu[0]) && (my_tag_number == tag_number)); } /* from clause 20.2.3 Encoding of a Boolean Value */ /* and 20.2.1 General Rules for Encoding BACnet Tags */ /* returns the number of apdu bytes consumed */ -int encode_application_boolean( - uint8_t * apdu, - bool boolean_value) +int encode_application_boolean(uint8_t *apdu, bool boolean_value) { int len = 0; uint32_t len_value = 0; @@ -539,22 +501,19 @@ int encode_application_boolean( } /* context tagged is encoded differently */ -int encode_context_boolean( - uint8_t * apdu, - uint8_t tag_number, - bool boolean_value) +int encode_context_boolean(uint8_t *apdu, uint8_t tag_number, + bool boolean_value) { - int len = 0; /* return value */ + int len = 0; /* return value */ - len = encode_tag(&apdu[0], (uint8_t) tag_number, true, 1); - apdu[len] = (bool) (boolean_value ? 1 : 0); + len = encode_tag(&apdu[0], (uint8_t)tag_number, true, 1); + apdu[len] = (bool)(boolean_value ? 1 : 0); len++; return len; } -bool decode_context_boolean( - uint8_t * apdu) +bool decode_context_boolean(uint8_t *apdu) { bool boolean_value = false; @@ -565,10 +524,8 @@ bool decode_context_boolean( return boolean_value; } -int decode_context_boolean2( - uint8_t * apdu, - uint8_t tag_number, - bool * boolean_value) +int decode_context_boolean2(uint8_t *apdu, uint8_t tag_number, + bool *boolean_value) { int len = 0; if (decode_is_context_tag_with_length(&apdu[len], tag_number, &len)) { @@ -587,8 +544,7 @@ int decode_context_boolean2( /* from clause 20.2.3 Encoding of a Boolean Value */ /* and 20.2.1 General Rules for Encoding BACnet Tags */ /* returns the number of apdu bytes consumed */ -bool decode_boolean( - uint32_t len_value) +bool decode_boolean(uint32_t len_value) { bool boolean_value = false; @@ -602,21 +558,17 @@ bool decode_boolean( /* from clause 20.2.2 Encoding of a Null Value */ /* and 20.2.1 General Rules for Encoding BACnet Tags */ /* returns the number of apdu bytes consumed */ -int encode_application_null( - uint8_t * apdu) +int encode_application_null(uint8_t *apdu) { return encode_tag(&apdu[0], BACNET_APPLICATION_TAG_NULL, false, 0); } -int encode_context_null( - uint8_t * apdu, - uint8_t tag_number) +int encode_context_null(uint8_t *apdu, uint8_t tag_number) { return encode_tag(&apdu[0], tag_number, true, 0); } -static uint8_t byte_reverse_bits( - uint8_t in_byte) +static uint8_t byte_reverse_bits(uint8_t in_byte) { uint8_t out_byte = 0; @@ -650,17 +602,14 @@ static uint8_t byte_reverse_bits( /* from clause 20.2.10 Encoding of a Bit String Value */ /* returns the number of apdu bytes consumed */ -int decode_bitstring( - uint8_t * apdu, - uint32_t len_value, - BACNET_BIT_STRING * bit_string) +int decode_bitstring(uint8_t *apdu, uint32_t len_value, + BACNET_BIT_STRING *bit_string) { int len = 0; uint8_t unused_bits = 0; uint32_t i = 0; uint32_t bytes_used = 0; - bitstring_init(bit_string); if (len_value) { /* the first octet contains the unused bits */ @@ -668,30 +617,27 @@ int decode_bitstring( if (bytes_used <= MAX_BITSTRING_BYTES) { len = 1; for (i = 0; i < bytes_used; i++) { - bitstring_set_octet(bit_string, (uint8_t) i, - byte_reverse_bits(apdu[len++])); + bitstring_set_octet(bit_string, (uint8_t)i, + byte_reverse_bits(apdu[len++])); } - unused_bits = (uint8_t) (apdu[0] & 0x07); - bitstring_set_bits_used(bit_string, (uint8_t) bytes_used, - unused_bits); + unused_bits = (uint8_t)(apdu[0] & 0x07); + bitstring_set_bits_used(bit_string, (uint8_t)bytes_used, + unused_bits); } } return len; } -int decode_context_bitstring( - uint8_t * apdu, - uint8_t tag_number, - BACNET_BIT_STRING * bit_string) +int decode_context_bitstring(uint8_t *apdu, uint8_t tag_number, + BACNET_BIT_STRING *bit_string) { uint32_t len_value; int len = 0; if (decode_is_context_tag(&apdu[len], tag_number) && !decode_is_closing_tag(&apdu[len])) { - len += - decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); len += decode_bitstring(&apdu[len], len_value, bit_string); } else { len = BACNET_STATUS_ERROR; @@ -699,12 +645,9 @@ int decode_context_bitstring( return len; } - /* from clause 20.2.10 Encoding of a Bit String Value */ /* returns the number of apdu bytes consumed */ -int encode_bitstring( - uint8_t * apdu, - BACNET_BIT_STRING * bit_string) +int encode_bitstring(uint8_t *apdu, BACNET_BIT_STRING *bit_string) { int len = 0; uint8_t remaining_used_bits = 0; @@ -717,10 +660,9 @@ int encode_bitstring( } else { used_bytes = bitstring_bytes_used(bit_string); remaining_used_bits = - (uint8_t) (bitstring_bits_used(bit_string) - ((used_bytes - - 1) * 8)); + (uint8_t)(bitstring_bits_used(bit_string) - ((used_bytes - 1) * 8)); /* number of unused bits in the subsequent final octet */ - apdu[len++] = (uint8_t) (8 - remaining_used_bits); + apdu[len++] = (uint8_t)(8 - remaining_used_bits); for (i = 0; i < used_bytes; i++) { apdu[len++] = byte_reverse_bits(bitstring_octet(bit_string, i)); } @@ -729,30 +671,25 @@ int encode_bitstring( return len; } -int encode_application_bitstring( - uint8_t * apdu, - BACNET_BIT_STRING * bit_string) +int encode_application_bitstring(uint8_t *apdu, BACNET_BIT_STRING *bit_string) { int len = 0; - uint32_t bit_string_encoded_length = 1; /* 1 for the bits remaining octet */ + uint32_t bit_string_encoded_length = 1; /* 1 for the bits remaining octet */ /* bit string may use more than 1 octet for the tag, so find out how many */ bit_string_encoded_length += bitstring_bytes_used(bit_string); - len = - encode_tag(&apdu[0], BACNET_APPLICATION_TAG_BIT_STRING, false, - bit_string_encoded_length); + len = encode_tag(&apdu[0], BACNET_APPLICATION_TAG_BIT_STRING, false, + bit_string_encoded_length); len += encode_bitstring(&apdu[len], bit_string); return len; } -int encode_context_bitstring( - uint8_t * apdu, - uint8_t tag_number, - BACNET_BIT_STRING * bit_string) +int encode_context_bitstring(uint8_t *apdu, uint8_t tag_number, + BACNET_BIT_STRING *bit_string) { int len = 0; - uint32_t bit_string_encoded_length = 1; /* 1 for the bits remaining octet */ + uint32_t bit_string_encoded_length = 1; /* 1 for the bits remaining octet */ /* bit string may use more than 1 octet for the tag, so find out how many */ bit_string_encoded_length += bitstring_bytes_used(bit_string); @@ -764,27 +701,21 @@ int encode_context_bitstring( /* from clause 20.2.14 Encoding of an Object Identifier Value */ /* returns the number of apdu bytes consumed */ -int decode_object_id( - uint8_t * apdu, - uint16_t * object_type, - uint32_t * instance) +int decode_object_id(uint8_t *apdu, uint16_t *object_type, uint32_t *instance) { uint32_t value = 0; int len = 0; len = decode_unsigned32(apdu, &value); *object_type = - (uint16_t) (((value >> BACNET_INSTANCE_BITS) & BACNET_MAX_OBJECT)); + (uint16_t)(((value >> BACNET_INSTANCE_BITS) & BACNET_MAX_OBJECT)); *instance = (value & BACNET_MAX_INSTANCE); return len; } -int decode_object_id_safe( - uint8_t * apdu, - uint32_t len_value, - uint16_t * object_type, - uint32_t * instance) +int decode_object_id_safe(uint8_t *apdu, uint32_t len_value, + uint16_t *object_type, uint32_t *instance) { if (len_value != 4) { return 0; @@ -793,11 +724,8 @@ int decode_object_id_safe( } } -int decode_context_object_id( - uint8_t * apdu, - uint8_t tag_number, - uint16_t * object_type, - uint32_t * instance) +int decode_context_object_id(uint8_t *apdu, uint8_t tag_number, + uint16_t *object_type, uint32_t *instance) { int len = 0; @@ -812,19 +740,15 @@ int decode_context_object_id( /* from clause 20.2.14 Encoding of an Object Identifier Value */ /* returns the number of apdu bytes consumed */ -int encode_bacnet_object_id( - uint8_t * apdu, - int object_type, - uint32_t instance) +int encode_bacnet_object_id(uint8_t *apdu, int object_type, uint32_t instance) { uint32_t value = 0; uint32_t type = 0; int len = 0; - type = (uint32_t) object_type; - value = - ((type & BACNET_MAX_OBJECT) << BACNET_INSTANCE_BITS) | (instance & - BACNET_MAX_INSTANCE); + type = (uint32_t)object_type; + value = ((type & BACNET_MAX_OBJECT) << BACNET_INSTANCE_BITS) | + (instance & BACNET_MAX_INSTANCE); len = encode_unsigned32(apdu, value); return len; @@ -833,11 +757,8 @@ int encode_bacnet_object_id( /* from clause 20.2.14 Encoding of an Object Identifier Value */ /* and 20.2.1 General Rules for Encoding BACnet Tags */ /* returns the number of apdu bytes consumed */ -int encode_context_object_id( - uint8_t * apdu, - uint8_t tag_number, - int object_type, - uint32_t instance) +int encode_context_object_id(uint8_t *apdu, uint8_t tag_number, int object_type, + uint32_t instance) { int len = 0; @@ -852,18 +773,15 @@ int encode_context_object_id( /* from clause 20.2.14 Encoding of an Object Identifier Value */ /* and 20.2.1 General Rules for Encoding BACnet Tags */ /* returns the number of apdu bytes consumed */ -int encode_application_object_id( - uint8_t * apdu, - int object_type, - uint32_t instance) +int encode_application_object_id(uint8_t *apdu, int object_type, + uint32_t instance) { int len = 0; /* assumes that the tag only consumes 1 octet */ len = encode_bacnet_object_id(&apdu[1], object_type, instance); - len += - encode_tag(&apdu[0], BACNET_APPLICATION_TAG_OBJECT_ID, false, - (uint32_t) len); + len += encode_tag(&apdu[0], BACNET_APPLICATION_TAG_OBJECT_ID, false, + (uint32_t)len); return len; } @@ -872,18 +790,16 @@ int encode_application_object_id( /* from clause 20.2.8 Encoding of an Octet String Value */ /* returns the number of apdu bytes consumed */ -int encode_octet_string( - uint8_t * apdu, - BACNET_OCTET_STRING * octet_string) +int encode_octet_string(uint8_t *apdu, BACNET_OCTET_STRING *octet_string) { - int len = 0; /* return value */ + int len = 0; /* return value */ uint8_t *value; - int i = 0; /* loop counter */ + int i = 0; /* loop counter */ if (octet_string) { /* FIXME: might need to pass in the length of the APDU to bounds check since it might not be the only data chunk */ - len = (int) octetstring_length(octet_string); + len = (int)octetstring_length(octet_string); value = octetstring_value(octet_string); if (value) { for (i = 0; i < len; i++) { @@ -898,16 +814,14 @@ int encode_octet_string( /* from clause 20.2.8 Encoding of an Octet String Value */ /* and 20.2.1 General Rules for Encoding BACnet Tags */ /* returns the number of apdu bytes consumed */ -int encode_application_octet_string( - uint8_t * apdu, - BACNET_OCTET_STRING * octet_string) +int encode_application_octet_string(uint8_t *apdu, + BACNET_OCTET_STRING *octet_string) { int apdu_len = 0; if (octet_string) { - apdu_len = - encode_tag(&apdu[0], BACNET_APPLICATION_TAG_OCTET_STRING, false, - octetstring_length(octet_string)); + apdu_len = encode_tag(&apdu[0], BACNET_APPLICATION_TAG_OCTET_STRING, + false, octetstring_length(octet_string)); /* FIXME: probably need to pass in the length of the APDU to bounds check since it might not be the only data chunk */ if ((apdu_len + octetstring_length(octet_string)) < MAX_APDU) { @@ -923,17 +837,14 @@ int encode_application_octet_string( /* from clause 20.2.8 Encoding of an Octet String Value */ /* and 20.2.1 General Rules for Encoding BACnet Tags */ /* returns the number of apdu bytes consumed */ -int encode_context_octet_string( - uint8_t * apdu, - uint8_t tag_number, - BACNET_OCTET_STRING * octet_string) +int encode_context_octet_string(uint8_t *apdu, uint8_t tag_number, + BACNET_OCTET_STRING *octet_string) { int apdu_len = 0; if (apdu && octet_string) { - apdu_len = - encode_tag(&apdu[0], tag_number, true, - octetstring_length(octet_string)); + apdu_len = encode_tag(&apdu[0], tag_number, true, + octetstring_length(octet_string)); if ((apdu_len + octetstring_length(octet_string)) < MAX_APDU) { apdu_len += encode_octet_string(&apdu[apdu_len], octet_string); } else { @@ -947,35 +858,30 @@ int encode_context_octet_string( /* from clause 20.2.8 Encoding of an Octet String Value */ /* and 20.2.1 General Rules for Encoding BACnet Tags */ /* returns the number of apdu bytes consumed */ -int decode_octet_string( - uint8_t * apdu, - uint32_t len_value, - BACNET_OCTET_STRING * octet_string) +int decode_octet_string(uint8_t *apdu, uint32_t len_value, + BACNET_OCTET_STRING *octet_string) { - int len = 0; /* return value */ + int len = 0; /* return value */ bool status = false; status = octetstring_init(octet_string, &apdu[0], len_value); if (status) { - len = (int) len_value; + len = (int)len_value; } return len; } -int decode_context_octet_string( - uint8_t * apdu, - uint8_t tag_number, - BACNET_OCTET_STRING * octet_string) +int decode_context_octet_string(uint8_t *apdu, uint8_t tag_number, + BACNET_OCTET_STRING *octet_string) { - int len = 0; /* return value */ + int len = 0; /* return value */ bool status = false; uint32_t len_value = 0; if (decode_is_context_tag(&apdu[len], tag_number) && !decode_is_closing_tag(&apdu[len])) { - len += - decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); status = octetstring_init(octet_string, &apdu[len], len_value); @@ -992,21 +898,18 @@ int decode_context_octet_string( /* from clause 20.2.9 Encoding of a Character String Value */ /* returns the number of apdu bytes consumed, or zero if failed */ -uint32_t encode_bacnet_character_string_safe( - uint8_t * apdu, - uint32_t max_apdu, - uint8_t encoding, - char *pString, - uint32_t length) +uint32_t encode_bacnet_character_string_safe(uint8_t *apdu, uint32_t max_apdu, + uint8_t encoding, char *pString, + uint32_t length) { - uint32_t apdu_len = 1 /*encoding */ ; + uint32_t apdu_len = 1 /*encoding */; uint32_t i; apdu_len += length; if (apdu && (apdu_len <= max_apdu)) { apdu[0] = encoding; for (i = 0; i < length; i++) { - apdu[1 + i] = (uint8_t) pString[i]; + apdu[1 + i] = (uint8_t)pString[i]; } } else { apdu_len = 0; @@ -1015,12 +918,11 @@ uint32_t encode_bacnet_character_string_safe( return apdu_len; } -int encode_bacnet_character_string( - uint8_t * apdu, - BACNET_CHARACTER_STRING * char_string) +int encode_bacnet_character_string(uint8_t *apdu, + BACNET_CHARACTER_STRING *char_string) { - return (int) encode_bacnet_character_string_safe(apdu, MAX_APDU, - characterstring_encoding(char_string), + return (int)encode_bacnet_character_string_safe( + apdu, MAX_APDU, characterstring_encoding(char_string), characterstring_value(char_string), characterstring_length(char_string)); } @@ -1028,18 +930,16 @@ int encode_bacnet_character_string( /* from clause 20.2.9 Encoding of a Character String Value */ /* and 20.2.1 General Rules for Encoding BACnet Tags */ /* returns the number of apdu bytes consumed */ -int encode_application_character_string( - uint8_t * apdu, - BACNET_CHARACTER_STRING * char_string) +int encode_application_character_string(uint8_t *apdu, + BACNET_CHARACTER_STRING *char_string) { int len = 0; int string_len = 0; string_len = - (int) characterstring_length(char_string) + 1 /* for encoding */ ; - len = - encode_tag(&apdu[0], BACNET_APPLICATION_TAG_CHARACTER_STRING, false, - (uint32_t) string_len); + (int)characterstring_length(char_string) + 1 /* for encoding */; + len = encode_tag(&apdu[0], BACNET_APPLICATION_TAG_CHARACTER_STRING, false, + (uint32_t)string_len); if ((len + string_len) < MAX_APDU) { len += encode_bacnet_character_string(&apdu[len], char_string); } else { @@ -1049,17 +949,15 @@ int encode_application_character_string( return len; } -int encode_context_character_string( - uint8_t * apdu, - uint8_t tag_number, - BACNET_CHARACTER_STRING * char_string) +int encode_context_character_string(uint8_t *apdu, uint8_t tag_number, + BACNET_CHARACTER_STRING *char_string) { int len = 0; int string_len = 0; string_len = - (int) characterstring_length(char_string) + 1 /* for encoding */ ; - len += encode_tag(&apdu[0], tag_number, true, (uint32_t) string_len); + (int)characterstring_length(char_string) + 1 /* for encoding */; + len += encode_tag(&apdu[0], tag_number, true, (uint32_t)string_len); if ((len + string_len) < MAX_APDU) { len += encode_bacnet_character_string(&apdu[len], char_string); } else { @@ -1072,41 +970,34 @@ int encode_context_character_string( /* from clause 20.2.9 Encoding of a Character String Value */ /* and 20.2.1 General Rules for Encoding BACnet Tags */ /* returns the number of apdu bytes consumed */ -int decode_character_string( - uint8_t * apdu, - uint32_t len_value, - BACNET_CHARACTER_STRING * char_string) +int decode_character_string(uint8_t *apdu, uint32_t len_value, + BACNET_CHARACTER_STRING *char_string) { - int len = 0; /* return value */ + int len = 0; /* return value */ bool status = false; - status = - characterstring_init(char_string, apdu[0], (char *) &apdu[1], - len_value - 1); + status = characterstring_init(char_string, apdu[0], (char *)&apdu[1], + len_value - 1); if (status) { - len = (int) len_value; + len = (int)len_value; } return len; } -int decode_context_character_string( - uint8_t * apdu, - uint8_t tag_number, - BACNET_CHARACTER_STRING * char_string) +int decode_context_character_string(uint8_t *apdu, uint8_t tag_number, + BACNET_CHARACTER_STRING *char_string) { - int len = 0; /* return value */ + int len = 0; /* return value */ bool status = false; uint32_t len_value = 0; if (decode_is_context_tag(&apdu[len], tag_number) && !decode_is_closing_tag(&apdu[len])) { - len += - decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); - status = - characterstring_init(char_string, apdu[len], - (char *) &apdu[len + 1], len_value - 1); + status = characterstring_init(char_string, apdu[len], + (char *)&apdu[len + 1], len_value - 1); if (status) { len += len_value; } @@ -1120,10 +1011,7 @@ int decode_context_character_string( /* from clause 20.2.4 Encoding of an Unsigned Integer Value */ /* and 20.2.1 General Rules for Encoding BACnet Tags */ /* returns the number of apdu bytes consumed */ -int decode_unsigned( - uint8_t * apdu, - uint32_t len_value, - uint32_t * value) +int decode_unsigned(uint8_t *apdu, uint32_t len_value, uint32_t *value) { uint16_t unsigned16_value = 0; @@ -1148,21 +1036,17 @@ int decode_unsigned( } } - return (int) len_value; + return (int)len_value; } -int decode_context_unsigned( - uint8_t * apdu, - uint8_t tag_number, - uint32_t * value) +int decode_context_unsigned(uint8_t *apdu, uint8_t tag_number, uint32_t *value) { uint32_t len_value; int len = 0; if (decode_is_context_tag(&apdu[len], tag_number) && !decode_is_closing_tag(&apdu[len])) { - len += - decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); len += decode_unsigned(&apdu[len], len_value, value); } else { len = BACNET_STATUS_ERROR; @@ -1170,21 +1054,18 @@ int decode_context_unsigned( return len; } - /* from clause 20.2.4 Encoding of an Unsigned Integer Value */ /* and 20.2.1 General Rules for Encoding BACnet Tags */ /* returns the number of apdu bytes consumed */ -int encode_bacnet_unsigned( - uint8_t * apdu, - uint32_t value) +int encode_bacnet_unsigned(uint8_t *apdu, uint32_t value) { - int len = 0; /* return value */ + int len = 0; /* return value */ if (value < 0x100) { - apdu[0] = (uint8_t) value; + apdu[0] = (uint8_t)value; len = 1; } else if (value < 0x10000) { - len = encode_unsigned16(&apdu[0], (uint16_t) value); + len = encode_unsigned16(&apdu[0], (uint16_t)value); } else if (value < 0x1000000) { len = encode_unsigned24(&apdu[0], value); } else { @@ -1197,10 +1078,7 @@ int encode_bacnet_unsigned( /* from clause 20.2.4 Encoding of an Unsigned Integer Value */ /* and 20.2.1 General Rules for Encoding BACnet Tags */ /* returns the number of apdu bytes consumed */ -int encode_context_unsigned( - uint8_t * apdu, - uint8_t tag_number, - uint32_t value) +int encode_context_unsigned(uint8_t *apdu, uint8_t tag_number, uint32_t value) { int len = 0; @@ -1215,7 +1093,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; @@ -1224,16 +1102,13 @@ int encode_context_unsigned( /* from clause 20.2.4 Encoding of an Unsigned Integer Value */ /* and 20.2.1 General Rules for Encoding BACnet Tags */ /* returns the number of apdu bytes consumed */ -int encode_application_unsigned( - uint8_t * apdu, - uint32_t value) +int encode_application_unsigned(uint8_t *apdu, uint32_t value) { int len = 0; len = encode_bacnet_unsigned(&apdu[1], value); - len += - encode_tag(&apdu[0], BACNET_APPLICATION_TAG_UNSIGNED_INT, false, - (uint32_t) len); + len += encode_tag(&apdu[0], BACNET_APPLICATION_TAG_UNSIGNED_INT, false, + (uint32_t)len); return len; } @@ -1241,10 +1116,7 @@ int encode_application_unsigned( /* from clause 20.2.11 Encoding of an Enumerated Value */ /* and 20.2.1 General Rules for Encoding BACnet Tags */ /* returns the number of apdu bytes consumed */ -int decode_enumerated( - uint8_t * apdu, - uint32_t len_value, - uint32_t * value) +int decode_enumerated(uint8_t *apdu, uint32_t len_value, uint32_t *value) { uint32_t unsigned_value = 0; int len; @@ -1257,10 +1129,7 @@ int decode_enumerated( return len; } -int decode_context_enumerated( - uint8_t * apdu, - uint8_t tag_value, - uint32_t * value) +int decode_context_enumerated(uint8_t *apdu, uint8_t tag_value, uint32_t *value) { int len = 0; uint8_t tag_number; @@ -1268,8 +1137,7 @@ int decode_context_enumerated( if (decode_is_context_tag(&apdu[len], tag_value) && !decode_is_closing_tag(&apdu[len])) { - len += - decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); len += decode_enumerated(&apdu[len], len_value, value); } else { len = BACNET_STATUS_ERROR; @@ -1280,9 +1148,7 @@ int decode_context_enumerated( /* from clause 20.2.11 Encoding of an Enumerated Value */ /* and 20.2.1 General Rules for Encoding BACnet Tags */ /* returns the number of apdu bytes consumed */ -int encode_bacnet_enumerated( - uint8_t * apdu, - uint32_t value) +int encode_bacnet_enumerated(uint8_t *apdu, uint32_t value) { return encode_bacnet_unsigned(apdu, value); } @@ -1290,17 +1156,14 @@ int encode_bacnet_enumerated( /* from clause 20.2.11 Encoding of an Enumerated Value */ /* and 20.2.1 General Rules for Encoding BACnet Tags */ /* returns the number of apdu bytes consumed */ -int encode_application_enumerated( - uint8_t * apdu, - uint32_t value) +int encode_application_enumerated(uint8_t *apdu, uint32_t value) { - int len = 0; /* return value */ + int len = 0; /* return value */ /* assumes that the tag only consumes 1 octet */ len = encode_bacnet_enumerated(&apdu[1], value); - len += - encode_tag(&apdu[0], BACNET_APPLICATION_TAG_ENUMERATED, false, - (uint32_t) len); + len += encode_tag(&apdu[0], BACNET_APPLICATION_TAG_ENUMERATED, false, + (uint32_t)len); return len; } @@ -1308,12 +1171,9 @@ int encode_application_enumerated( /* from clause 20.2.11 Encoding of an Enumerated Value */ /* and 20.2.1 General Rules for Encoding BACnet Tags */ /* returns the number of apdu bytes consumed */ -int encode_context_enumerated( - uint8_t * apdu, - uint8_t tag_number, - uint32_t value) +int encode_context_enumerated(uint8_t *apdu, uint8_t tag_number, uint32_t value) { - int len = 0; /* return value */ + int len = 0; /* return value */ /* length of enumerated is variable, as per 20.2.11 */ if (value < 0x100) { @@ -1326,7 +1186,7 @@ int encode_context_enumerated( 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_enumerated(&apdu[len], value); return len; @@ -1336,10 +1196,7 @@ int encode_context_enumerated( /* from clause 20.2.5 Encoding of a Signed Integer Value */ /* and 20.2.1 General Rules for Encoding BACnet Tags */ /* returns the number of apdu bytes consumed */ -int decode_signed( - uint8_t * apdu, - uint32_t len_value, - int32_t * value) +int decode_signed(uint8_t *apdu, uint32_t len_value, int32_t *value) { if (value) { switch (len_value) { @@ -1361,21 +1218,17 @@ int decode_signed( } } - return (int) len_value; + return (int)len_value; } -int decode_context_signed( - uint8_t * apdu, - uint8_t tag_number, - int32_t * value) +int decode_context_signed(uint8_t *apdu, uint8_t tag_number, int32_t *value) { uint32_t len_value; int len = 0; if (decode_is_context_tag(&apdu[len], tag_number) && !decode_is_closing_tag(&apdu[len])) { - len += - decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); len += decode_signed(&apdu[len], len_value, value); } else { len = BACNET_STATUS_ERROR; @@ -1386,11 +1239,9 @@ int decode_context_signed( /* from clause 20.2.5 Encoding of a Signed Integer Value */ /* and 20.2.1 General Rules for Encoding BACnet Tags */ /* returns the number of apdu bytes consumed */ -int encode_bacnet_signed( - uint8_t * apdu, - int32_t value) +int encode_bacnet_signed(uint8_t *apdu, int32_t value) { - int len = 0; /* return value */ + int len = 0; /* return value */ /* don't encode the leading X'FF' or X'00' of the two's compliment. That is, the first octet of any multi-octet encoded value shall @@ -1398,9 +1249,9 @@ int encode_bacnet_signed( octet is 0, and the first octet shall not be X'FF' if the most significant bit of the second octet is 1. */ if ((value >= -128) && (value < 128)) { - len = encode_signed8(&apdu[0], (int8_t) value); + len = encode_signed8(&apdu[0], (int8_t)value); } else if ((value >= -32768) && (value < 32768)) { - len = encode_signed16(&apdu[0], (int16_t) value); + len = encode_signed16(&apdu[0], (int16_t)value); } else if ((value > -8388608) && (value < 8388608)) { len = encode_signed24(&apdu[0], value); } else { @@ -1413,17 +1264,14 @@ int encode_bacnet_signed( /* from clause 20.2.5 Encoding of a Signed Integer Value */ /* and 20.2.1 General Rules for Encoding BACnet Tags */ /* returns the number of apdu bytes consumed */ -int encode_application_signed( - uint8_t * apdu, - int32_t value) +int encode_application_signed(uint8_t *apdu, int32_t value) { - int len = 0; /* return value */ + int len = 0; /* return value */ /* assumes that the tag only consumes 1 octet */ len = encode_bacnet_signed(&apdu[1], value); - len += - encode_tag(&apdu[0], BACNET_APPLICATION_TAG_SIGNED_INT, false, - (uint32_t) len); + len += encode_tag(&apdu[0], BACNET_APPLICATION_TAG_SIGNED_INT, false, + (uint32_t)len); return len; } @@ -1431,12 +1279,9 @@ int encode_application_signed( /* from clause 20.2.5 Encoding of a Signed Integer Value */ /* and 20.2.1 General Rules for Encoding BACnet Tags */ /* returns the number of apdu bytes consumed */ -int encode_context_signed( - uint8_t * apdu, - uint8_t tag_number, - int32_t value) +int encode_context_signed(uint8_t *apdu, uint8_t tag_number, int32_t value) { - int len = 0; /* return value */ + int len = 0; /* return value */ /* length of signed int is variable, as per 20.2.11 */ if ((value >= -128) && (value < 128)) { @@ -1449,7 +1294,7 @@ int encode_context_signed( 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_signed(&apdu[len], value); return len; @@ -1459,25 +1304,19 @@ int encode_context_signed( /* from clause 20.2.6 Encoding of a Real Number Value */ /* and 20.2.1 General Rules for Encoding BACnet Tags */ /* returns the number of apdu bytes consumed */ -int encode_application_real( - uint8_t * apdu, - float value) +int encode_application_real(uint8_t *apdu, float value) { int len = 0; /* assumes that the tag only consumes 1 octet */ len = encode_bacnet_real(value, &apdu[1]); len += - encode_tag(&apdu[0], BACNET_APPLICATION_TAG_REAL, false, - (uint32_t) len); + encode_tag(&apdu[0], BACNET_APPLICATION_TAG_REAL, false, (uint32_t)len); return len; } -int encode_context_real( - uint8_t * apdu, - uint8_t tag_number, - float value) +int encode_context_real(uint8_t *apdu, uint8_t tag_number, float value) { int len = 0; @@ -1491,26 +1330,20 @@ int encode_context_real( /* from clause 20.2.7 Encoding of a Double Precision Real Number Value */ /* and 20.2.1 General Rules for Encoding BACnet Tags */ /* returns the number of apdu bytes consumed */ -int encode_application_double( - uint8_t * apdu, - double value) +int encode_application_double(uint8_t *apdu, double value) { int len = 0; /* assumes that the tag only consumes 2 octet */ len = encode_bacnet_double(value, &apdu[2]); - len += - encode_tag(&apdu[0], BACNET_APPLICATION_TAG_DOUBLE, false, - (uint32_t) len); + len += encode_tag(&apdu[0], BACNET_APPLICATION_TAG_DOUBLE, false, + (uint32_t)len); return len; } -int encode_context_double( - uint8_t * apdu, - uint8_t tag_number, - double value) +int encode_context_double(uint8_t *apdu, uint8_t tag_number, double value) { int len = 0; @@ -1525,9 +1358,7 @@ int encode_context_double( /* from clause 20.2.13 Encoding of a Time Value */ /* and 20.2.1 General Rules for Encoding BACnet Tags */ /* returns the number of apdu bytes consumed */ -int encode_bacnet_time( - uint8_t * apdu, - BACNET_TIME * btime) +int encode_bacnet_time(uint8_t *apdu, BACNET_TIME *btime) { apdu[0] = btime->hour; apdu[1] = btime->min; @@ -1540,27 +1371,21 @@ int encode_bacnet_time( /* from clause 20.2.13 Encoding of a Time Value */ /* and 20.2.1 General Rules for Encoding BACnet Tags */ /* returns the number of apdu bytes consumed */ -int encode_application_time( - uint8_t * apdu, - BACNET_TIME * btime) +int encode_application_time(uint8_t *apdu, BACNET_TIME *btime) { int len = 0; /* assumes that the tag only consumes 1 octet */ len = encode_bacnet_time(&apdu[1], btime); len += - encode_tag(&apdu[0], BACNET_APPLICATION_TAG_TIME, false, - (uint32_t) len); + encode_tag(&apdu[0], BACNET_APPLICATION_TAG_TIME, false, (uint32_t)len); return len; } -int encode_context_time( - uint8_t * apdu, - uint8_t tag_number, - BACNET_TIME * btime) +int encode_context_time(uint8_t *apdu, uint8_t tag_number, BACNET_TIME *btime) { - int len = 0; /* return value */ + int len = 0; /* return value */ /* length of time is 4 octets, as per 20.2.13 */ len = encode_tag(&apdu[0], tag_number, true, 4); @@ -1572,9 +1397,7 @@ int encode_context_time( /* from clause 20.2.13 Encoding of a Time Value */ /* and 20.2.1 General Rules for Encoding BACnet Tags */ /* returns the number of apdu bytes consumed */ -int decode_bacnet_time( - uint8_t * apdu, - BACNET_TIME * btime) +int decode_bacnet_time(uint8_t *apdu, BACNET_TIME *btime) { btime->hour = apdu[0]; btime->min = apdu[1]; @@ -1584,25 +1407,21 @@ int decode_bacnet_time( return 4; } -int decode_bacnet_time_safe( - uint8_t * apdu, - uint32_t len_value, - BACNET_TIME * btime) +int decode_bacnet_time_safe(uint8_t *apdu, uint32_t len_value, + BACNET_TIME *btime) { if (len_value != 4) { btime->hour = 0; btime->hundredths = 0; btime->min = 0; btime->sec = 0; - return (int) len_value; + return (int)len_value; } else { return decode_bacnet_time(apdu, btime); } } -int decode_application_time( - uint8_t * apdu, - BACNET_TIME * btime) +int decode_application_time(uint8_t *apdu, BACNET_TIME *btime) { int len = 0; uint8_t tag_number; @@ -1618,11 +1437,8 @@ int decode_application_time( return len; } - -int decode_context_bacnet_time( - uint8_t * apdu, - uint8_t tag_number, - BACNET_TIME * btime) +int decode_context_bacnet_time(uint8_t *apdu, uint8_t tag_number, + BACNET_TIME *btime) { int len = 0; @@ -1635,7 +1451,6 @@ int decode_context_bacnet_time( return len; } - /* BACnet Date */ /* year = years since 1900, wildcard=1900+255 */ /* month 1=Jan */ @@ -1645,16 +1460,14 @@ int decode_context_bacnet_time( /* from clause 20.2.12 Encoding of a Date Value */ /* and 20.2.1 General Rules for Encoding BACnet Tags */ /* returns the number of apdu bytes consumed */ -int encode_bacnet_date( - uint8_t * apdu, - BACNET_DATE * bdate) +int encode_bacnet_date(uint8_t *apdu, BACNET_DATE *bdate) { if (bdate->year >= 1900) { /* normal encoding, including wildcard */ - apdu[0] = (uint8_t) (bdate->year - 1900); + apdu[0] = (uint8_t)(bdate->year - 1900); } else if (bdate->year < 0x100) { /* allow 2 digit years */ - apdu[0] = (uint8_t) bdate->year; + apdu[0] = (uint8_t)bdate->year; } else { /* ** Don't try and guess what the user meant here. Just fail @@ -1668,32 +1481,24 @@ int encode_bacnet_date( return 4; } - /* from clause 20.2.12 Encoding of a Date Value */ /* and 20.2.1 General Rules for Encoding BACnet Tags */ /* returns the number of apdu bytes consumed */ -int encode_application_date( - uint8_t * apdu, - BACNET_DATE * bdate) +int encode_application_date(uint8_t *apdu, BACNET_DATE *bdate) { int len = 0; /* assumes that the tag only consumes 1 octet */ len = encode_bacnet_date(&apdu[1], bdate); len += - encode_tag(&apdu[0], BACNET_APPLICATION_TAG_DATE, false, - (uint32_t) len); + encode_tag(&apdu[0], BACNET_APPLICATION_TAG_DATE, false, (uint32_t)len); return len; - } -int encode_context_date( - uint8_t * apdu, - uint8_t tag_number, - BACNET_DATE * bdate) +int encode_context_date(uint8_t *apdu, uint8_t tag_number, BACNET_DATE *bdate) { - int len = 0; /* return value */ + int len = 0; /* return value */ /* length of date is 4 octets, as per 20.2.12 */ len = encode_tag(&apdu[0], tag_number, true, 4); @@ -1705,11 +1510,8 @@ int encode_context_date( /* from clause 20.2.12 Encoding of a Date Value */ /* and 20.2.1 General Rules for Encoding BACnet Tags */ /* returns the number of apdu bytes consumed */ -int decode_date( - uint8_t * apdu, - BACNET_DATE * bdate) +int decode_date(uint8_t *apdu, BACNET_DATE *bdate) { - bdate->year = (uint16_t)apdu[0] + 1900; bdate->month = apdu[1]; bdate->day = apdu[2]; @@ -1718,26 +1520,20 @@ int decode_date( return 4; } -int decode_date_safe( - uint8_t * apdu, - uint32_t len_value, - BACNET_DATE * bdate) +int decode_date_safe(uint8_t *apdu, uint32_t len_value, BACNET_DATE *bdate) { if (len_value != 4) { bdate->day = 0; bdate->month = 0; bdate->wday = 0; bdate->year = 0; - return (int) len_value; + return (int)len_value; } else { return decode_date(apdu, bdate); } } - -int decode_application_date( - uint8_t * apdu, - BACNET_DATE * bdate) +int decode_application_date(uint8_t *apdu, BACNET_DATE *bdate) { int len = 0; uint8_t tag_number; @@ -1752,10 +1548,7 @@ int decode_application_date( return len; } -int decode_context_date( - uint8_t * apdu, - uint8_t tag_number, - BACNET_DATE * bdate) +int decode_context_date(uint8_t *apdu, uint8_t tag_number, BACNET_DATE *bdate) { int len = 0; @@ -1767,13 +1560,8 @@ int decode_context_date( return len; } - - /* returns the number of apdu bytes consumed */ -int encode_simple_ack( - uint8_t * apdu, - uint8_t invoke_id, - uint8_t service_choice) +int encode_simple_ack(uint8_t *apdu, uint8_t invoke_id, uint8_t service_choice) { apdu[0] = PDU_TYPE_SIMPLE_ACK; apdu[1] = invoke_id; @@ -1783,9 +1571,7 @@ int encode_simple_ack( } /* BACnetAddress */ -int encode_bacnet_address( - uint8_t * apdu, - BACNET_ADDRESS * destination) +int encode_bacnet_address(uint8_t *apdu, BACNET_ADDRESS *destination) { int apdu_len = 0; BACNET_OCTET_STRING mac_addr; @@ -1801,9 +1587,7 @@ int encode_bacnet_address( } /* BACnetAddress */ -int decode_bacnet_address( - uint8_t * apdu, - BACNET_ADDRESS * destination) +int decode_bacnet_address(uint8_t *apdu, BACNET_ADDRESS *destination) { int len = 0; int tag_len = 0; @@ -1844,10 +1628,8 @@ int decode_bacnet_address( } /* BACnetAddress */ -int encode_context_bacnet_address( - uint8_t * apdu, - uint8_t tag_number, - BACNET_ADDRESS * destination) +int encode_context_bacnet_address(uint8_t *apdu, uint8_t tag_number, + BACNET_ADDRESS *destination) { int apdu_len = 0; apdu_len += encode_opening_tag(&apdu[apdu_len], tag_number); @@ -1857,10 +1639,8 @@ int encode_context_bacnet_address( } /* BACnetAddress */ -int decode_context_bacnet_address( - uint8_t * apdu, - uint8_t tag_number, - BACNET_ADDRESS * destination) +int decode_context_bacnet_address(uint8_t *apdu, uint8_t tag_number, + BACNET_ADDRESS *destination) { int len = 0; int section_length; @@ -1891,9 +1671,7 @@ int decode_context_bacnet_address( #include #include "ctest.h" -static int get_apdu_len( - bool extended_tag, - uint32_t value) +static int get_apdu_len(bool extended_tag, uint32_t value) { int test_len = 1; @@ -1901,7 +1679,7 @@ static int get_apdu_len( test_len++; } if (value <= 4) { - test_len += 0; /* do nothing... */ + test_len += 0; /* do nothing... */ } else if (value <= 253) { test_len += 1; } else if (value <= 65535) { @@ -1913,19 +1691,17 @@ static int get_apdu_len( return test_len; } -static void print_apdu( - uint8_t * pBlock, - uint32_t num) +static void print_apdu(uint8_t *pBlock, uint32_t num) { - size_t lines = 0; /* number of lines to print */ - size_t line = 0; /* line of text counter */ - size_t last_line = 0; /* line on which the last text resided */ - unsigned long count = 0; /* address to print */ - unsigned int i = 0; /* counter */ + size_t lines = 0; /* number of lines to print */ + size_t line = 0; /* line of text counter */ + size_t last_line = 0; /* line on which the last text resided */ + unsigned long count = 0; /* address to print */ + unsigned int i = 0; /* counter */ if (pBlock && num) { /* how many lines to print? */ - num--; /* adjust */ + num--; /* adjust */ lines = (num / 16) + 1; last_line = num % 16; @@ -1937,7 +1713,7 @@ static void print_apdu( for (i = 0; i < 16; i++) { if (((line == (lines - 1)) && (i <= last_line)) || (line != (lines - 1))) { - printf("%02X ", (unsigned) (0x00FF & pBlock[i])); + printf("%02X ", (unsigned)(0x00FF & pBlock[i])); } else { printf("-- "); } @@ -1965,10 +1741,9 @@ static void print_apdu( return; } -static void testBACDCodeTags( - Test * pTest) +static void testBACDCodeTags(Test *pTest) { - uint8_t apdu[MAX_APDU] = { 0 }; + uint8_t apdu[MAX_APDU] = {0}; uint8_t tag_number = 0, test_tag_number = 0; int len = 0, test_len = 0; uint32_t value = 0, test_value = 0; @@ -1994,9 +1769,8 @@ static void testBACDCodeTags( /* test the len-value-type portion */ for (value = 1;; value = value << 1) { len = encode_tag(&apdu[0], tag_number, false, value); - len = - decode_tag_number_and_value(&apdu[0], &test_tag_number, - &test_value); + len = decode_tag_number_and_value(&apdu[0], &test_tag_number, + &test_value); ct_test(pTest, tag_number == test_tag_number); ct_test(pTest, value == test_value); test_len = get_apdu_len(IS_EXTENDED_TAG_NUMBER(apdu[0]), value); @@ -2015,16 +1789,15 @@ static void testBACDCodeTags( return; } -static void testBACDCodeEnumerated( - Test * pTest) +static void testBACDCodeEnumerated(Test *pTest) { - uint8_t array[5] = { 0 }; - uint8_t encoded_array[5] = { 0 }; + uint8_t array[5] = {0}; + uint8_t encoded_array[5] = {0}; uint32_t value = 1; uint32_t decoded_value = 0; int i = 0, apdu_len = 0; int len = 0; - uint8_t apdu[MAX_APDU] = { 0 }; + uint8_t apdu[MAX_APDU] = {0}; uint8_t tag_number = 0; uint32_t len_value = 0; @@ -2037,8 +1810,8 @@ static void testBACDCodeEnumerated( ct_test(pTest, len == apdu_len); /* encode back the value */ encode_application_enumerated(&encoded_array[0], decoded_value); - ct_test(pTest, memcmp(&array[0], &encoded_array[0], - sizeof(array)) == 0); + ct_test(pTest, + memcmp(&array[0], &encoded_array[0], sizeof(array)) == 0); /* an enumerated will take up to 4 octects */ /* plus a one octet for the tag */ apdu_len = encode_application_enumerated(&apdu[0], value); @@ -2059,14 +1832,13 @@ static void testBACDCodeEnumerated( return; } -static void testBACDCodeReal( - Test * pTest) +static void testBACDCodeReal(Test *pTest) { - uint8_t real_array[4] = { 0 }; - uint8_t encoded_array[4] = { 0 }; + uint8_t real_array[4] = {0}; + uint8_t encoded_array[4] = {0}; float value = 42.123F; float decoded_value = 0.0F; - uint8_t apdu[MAX_APDU] = { 0 }; + uint8_t apdu[MAX_APDU] = {0}; int len = 0, apdu_len = 0; uint8_t tag_number = 0; uint32_t long_value = 0; @@ -2075,8 +1847,8 @@ static void testBACDCodeReal( decode_real(&real_array[0], &decoded_value); ct_test(pTest, decoded_value == value); encode_bacnet_real(value, &encoded_array[0]); - ct_test(pTest, memcmp(&real_array, &encoded_array, - sizeof(real_array)) == 0); + ct_test(pTest, + memcmp(&real_array, &encoded_array, sizeof(real_array)) == 0); /* a real will take up 4 octects plus a one octet tag */ apdu_len = encode_application_real(&apdu[0], value); @@ -2093,14 +1865,13 @@ static void testBACDCodeReal( return; } -static void testBACDCodeDouble( - Test * pTest) +static void testBACDCodeDouble(Test *pTest) { - uint8_t double_array[8] = { 0 }; - uint8_t encoded_array[8] = { 0 }; + uint8_t double_array[8] = {0}; + uint8_t encoded_array[8] = {0}; double value = 42.123; double decoded_value = 0.0; - uint8_t apdu[MAX_APDU] = { 0 }; + uint8_t apdu[MAX_APDU] = {0}; int len = 0, apdu_len = 0; uint8_t tag_number = 0; uint32_t long_value = 0; @@ -2109,8 +1880,8 @@ static void testBACDCodeDouble( decode_double(&double_array[0], &decoded_value); ct_test(pTest, decoded_value == value); encode_bacnet_double(value, &encoded_array[0]); - ct_test(pTest, memcmp(&double_array, &encoded_array, - sizeof(double_array)) == 0); + ct_test(pTest, + memcmp(&double_array, &encoded_array, sizeof(double_array)) == 0); /* a real will take up 4 octects plus a one octet tag */ apdu_len = encode_application_double(&apdu[0], value); @@ -2127,15 +1898,13 @@ static void testBACDCodeDouble( return; } -static void testBACDCodeUnsignedValue( - Test * pTest, - uint32_t value) +static void testBACDCodeUnsignedValue(Test *pTest, uint32_t value) { - uint8_t array[5] = { 0 }; - uint8_t encoded_array[5] = { 0 }; + uint8_t array[5] = {0}; + uint8_t encoded_array[5] = {0}; uint32_t decoded_value = 0; int len; - uint8_t apdu[MAX_APDU] = { 0 }; + uint8_t apdu[MAX_APDU] = {0}; uint8_t tag_number = 0; uint32_t len_value = 0; @@ -2144,8 +1913,8 @@ static 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); @@ -2160,8 +1929,7 @@ static void testBACDCodeUnsignedValue( ct_test(pTest, IS_CONTEXT_SPECIFIC(apdu[0]) == false); } -static void testBACDCodeUnsigned( - Test * pTest) +static void testBACDCodeUnsigned(Test *pTest) { uint32_t value = 1; int i; @@ -2176,10 +1944,9 @@ static void testBACDCodeUnsigned( return; } -static void testBACnetUnsigned( - Test * pTest) +static void testBACnetUnsigned(Test *pTest) { - uint8_t apdu[32] = { 0 }; + uint8_t apdu[32] = {0}; uint32_t value = 0, test_value = 0; int len = 0, test_len = 0; @@ -2193,15 +1960,13 @@ static void testBACnetUnsigned( } } -static void testBACDCodeSignedValue( - Test * pTest, - int32_t value) +static void testBACDCodeSignedValue(Test *pTest, int32_t value) { - uint8_t array[5] = { 0 }; - uint8_t encoded_array[5] = { 0 }; + uint8_t array[5] = {0}; + uint8_t encoded_array[5] = {0}; int32_t decoded_value = 0; int len = 0; - uint8_t apdu[MAX_APDU] = { 0 }; + uint8_t apdu[MAX_APDU] = {0}; uint8_t tag_number = 0; uint32_t len_value = 0; int diff = 0; @@ -2212,16 +1977,16 @@ static 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)); } @@ -2235,8 +2000,7 @@ static void testBACDCodeSignedValue( return; } -static void testBACDCodeSigned( - Test * pTest) +static void testBACDCodeSigned(Test *pTest) { int value = 1; int i = 0; @@ -2260,10 +2024,9 @@ static void testBACDCodeSigned( return; } -static void testBACnetSigned( - Test * pTest) +static void testBACnetSigned(Test *pTest) { - uint8_t apdu[32] = { 0 }; + uint8_t apdu[32] = {0}; int32_t value = 0, test_value = 0; int len = 0, test_len = 0; @@ -2281,21 +2044,20 @@ static void testBACnetSigned( } } -static void testBACDCodeOctetString( - Test * pTest) +static void testBACDCodeOctetString(Test *pTest) { - uint8_t array[MAX_APDU] = { 0 }; - uint8_t encoded_array[MAX_APDU] = { 0 }; + uint8_t array[MAX_APDU] = {0}; + uint8_t encoded_array[MAX_APDU] = {0}; BACNET_OCTET_STRING octet_string; BACNET_OCTET_STRING test_octet_string; - uint8_t test_value[MAX_APDU] = { "" }; - int i; /* for loop counter */ + uint8_t test_value[MAX_APDU] = {""}; + int i; /* for loop counter */ int apdu_len; int len; uint8_t tag_number = 0; uint32_t len_value = 0; bool status = false; - int diff = 0; /* for memcmp */ + int diff = 0; /* for memcmp */ status = octetstring_init(&octet_string, NULL, 0); ct_test(pTest, status == true); @@ -2304,9 +2066,8 @@ static void testBACDCodeOctetString( ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OCTET_STRING); len += decode_octet_string(&array[len], len_value, &test_octet_string); ct_test(pTest, apdu_len == len); - diff = - memcmp(octetstring_value(&octet_string), &test_value[0], - octetstring_length(&octet_string)); + diff = memcmp(octetstring_value(&octet_string), &test_value[0], + octetstring_length(&octet_string)); ct_test(pTest, diff == 0); for (i = 0; i < (MAX_APDU - 6); i++) { @@ -2315,20 +2076,17 @@ static void testBACDCodeOctetString( ct_test(pTest, status == true); apdu_len = encode_application_octet_string(&encoded_array[0], &octet_string); - len = - decode_tag_number_and_value(&encoded_array[0], &tag_number, - &len_value); + len = decode_tag_number_and_value(&encoded_array[0], &tag_number, + &len_value); ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_OCTET_STRING); - len += - decode_octet_string(&encoded_array[len], len_value, - &test_octet_string); + len += decode_octet_string(&encoded_array[len], len_value, + &test_octet_string); if (apdu_len != len) { printf("test octet string=#%d\n", i); } ct_test(pTest, apdu_len == len); - diff = - memcmp(octetstring_value(&octet_string), &test_value[0], - octetstring_length(&octet_string)); + diff = memcmp(octetstring_value(&octet_string), &test_value[0], + octetstring_length(&octet_string)); if (diff) { printf("test octet string=#%d\n", i); } @@ -2338,20 +2096,19 @@ static void testBACDCodeOctetString( return; } -static void testBACDCodeCharacterString( - Test * pTest) +static void testBACDCodeCharacterString(Test *pTest) { - uint8_t array[MAX_APDU] = { 0 }; - uint8_t encoded_array[MAX_APDU] = { 0 }; + uint8_t array[MAX_APDU] = {0}; + uint8_t encoded_array[MAX_APDU] = {0}; BACNET_CHARACTER_STRING char_string; BACNET_CHARACTER_STRING test_char_string; - char test_value[MAX_APDU] = { "" }; - int i; /* for loop counter */ + char test_value[MAX_APDU] = {""}; + int i; /* for loop counter */ int apdu_len; int len; uint8_t tag_number = 0; uint32_t len_value = 0; - int diff = 0; /* for comparison */ + int diff = 0; /* for comparison */ bool status = false; status = characterstring_init(&char_string, CHARACTER_ANSI_X34, NULL, 0); @@ -2361,32 +2118,27 @@ static void testBACDCodeCharacterString( ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_CHARACTER_STRING); len += decode_character_string(&array[len], len_value, &test_char_string); ct_test(pTest, apdu_len == len); - diff = - memcmp(characterstring_value(&char_string), &test_value[0], - characterstring_length(&char_string)); + diff = memcmp(characterstring_value(&char_string), &test_value[0], + characterstring_length(&char_string)); ct_test(pTest, diff == 0); for (i = 0; i < MAX_CHARACTER_STRING_BYTES - 1; i++) { test_value[i] = 'S'; test_value[i + 1] = '\0'; status = characterstring_init_ansi(&char_string, test_value); ct_test(pTest, status == true); - apdu_len = - encode_application_character_string(&encoded_array[0], - &char_string); - len = - decode_tag_number_and_value(&encoded_array[0], &tag_number, - &len_value); + apdu_len = encode_application_character_string(&encoded_array[0], + &char_string); + len = decode_tag_number_and_value(&encoded_array[0], &tag_number, + &len_value); ct_test(pTest, tag_number == BACNET_APPLICATION_TAG_CHARACTER_STRING); - len += - decode_character_string(&encoded_array[len], len_value, - &test_char_string); + len += decode_character_string(&encoded_array[len], len_value, + &test_char_string); if (apdu_len != len) { printf("test string=#%d apdu_len=%d len=%d\n", i, apdu_len, len); } ct_test(pTest, apdu_len == len); - diff = - memcmp(characterstring_value(&char_string), &test_value[0], - characterstring_length(&char_string)); + diff = memcmp(characterstring_value(&char_string), &test_value[0], + characterstring_length(&char_string)); if (diff) { printf("test string=#%d\n", i); } @@ -2396,15 +2148,10 @@ static void testBACDCodeCharacterString( return; } -static void testBACDCodeObject( - Test * pTest) +static void testBACDCodeObject(Test *pTest) { - uint8_t object_array[4] = { - 0 - }; - uint8_t encoded_array[4] = { - 0 - }; + uint8_t object_array[4] = {0}; + uint8_t encoded_array[4] = {0}; uint16_t type = OBJECT_BINARY_INPUT; uint16_t decoded_type = OBJECT_ANALOG_OUTPUT; uint32_t instance = 123; @@ -2416,28 +2163,27 @@ static void testBACDCodeObject( ct_test(pTest, decoded_instance == instance); encode_bacnet_object_id(&object_array[0], type, instance); ct_test(pTest, memcmp(&object_array[0], &encoded_array[0], - sizeof(object_array)) == 0); + sizeof(object_array)) == 0); for (type = 0; type < 1024; type++) { for (instance = 0; instance <= BACNET_MAX_INSTANCE; instance += 1024) { encode_bacnet_object_id(&encoded_array[0], type, instance); decode_object_id(&encoded_array[0], &decoded_type, - &decoded_instance); + &decoded_instance); ct_test(pTest, decoded_type == type); ct_test(pTest, decoded_instance == instance); encode_bacnet_object_id(&object_array[0], type, instance); ct_test(pTest, memcmp(&object_array[0], &encoded_array[0], - sizeof(object_array)) == 0); + sizeof(object_array)) == 0); } } return; } -static void testBACDCodeMaxSegsApdu( - Test * pTest) +static void testBACDCodeMaxSegsApdu(Test *pTest) { - int max_segs[8] = { 0, 2, 4, 8, 16, 32, 64, 65 }; - int max_apdu[6] = { 50, 128, 206, 480, 1024, 1476 }; + int max_segs[8] = {0, 2, 4, 8, 16, 32, 64, 65}; + int max_apdu[6] = {50, 128, 206, 480, 1024, 1476}; int i = 0; int j = 0; uint8_t octet = 0; @@ -2452,13 +2198,12 @@ static void testBACDCodeMaxSegsApdu( } } -static void testBACDCodeBitString( - Test * pTest) +static void testBACDCodeBitString(Test *pTest) { uint8_t bit = 0; BACNET_BIT_STRING bit_string; BACNET_BIT_STRING decoded_bit_string; - uint8_t apdu[MAX_APDU] = { 0 }; + uint8_t apdu[MAX_APDU] = {0}; uint32_t len_value = 0; uint8_t tag_number = 0; int len = 0; @@ -2500,8 +2245,7 @@ static void testBACDCodeBitString( } } -static void testUnsignedContextDecodes( - Test * pTest) +static void testUnsignedContextDecodes(Test *pTest) { uint8_t apdu[MAX_APDU]; int inLen; @@ -2591,11 +2335,9 @@ static void testUnsignedContextDecodes( ct_test(pTest, inLen == outLen); ct_test(pTest, in == out); ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); - } -static void testSignedContextDecodes( - Test * pTest) +static void testSignedContextDecodes(Test *pTest) { uint8_t apdu[MAX_APDU]; int inLen; @@ -2603,7 +2345,6 @@ static void testSignedContextDecodes( int outLen2; uint8_t large_context_tag = 0xfe; - /* 32 bit number */ int32_t in = 0xdeadbeef; int32_t out; @@ -2689,11 +2430,9 @@ static void testSignedContextDecodes( ct_test(pTest, inLen == outLen); ct_test(pTest, in == out); ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); - } -static void testEnumeratedContextDecodes( - Test * pTest) +static void testEnumeratedContextDecodes(Test *pTest) { uint8_t apdu[MAX_APDU]; int inLen; @@ -2785,8 +2524,7 @@ static void testEnumeratedContextDecodes( ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); } -static void testFloatContextDecodes( - Test * pTest) +static void testFloatContextDecodes(Test *pTest) { uint8_t apdu[MAX_APDU]; int inLen; @@ -2798,7 +2536,6 @@ static void testFloatContextDecodes( float in; float out; - in = 0.1234f; inLen = encode_context_real(apdu, 10, in); outLen = decode_context_real(apdu, 10, &out); @@ -2833,8 +2570,7 @@ static void testFloatContextDecodes( ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); } -static void testDoubleContextDecodes( - Test * pTest) +static void testDoubleContextDecodes(Test *pTest) { uint8_t apdu[MAX_APDU]; int inLen; @@ -2846,7 +2582,6 @@ static void testDoubleContextDecodes( double in; double out; - in = 0.1234; inLen = encode_context_double(apdu, 10, in); outLen = decode_context_double(apdu, 10, &out); @@ -2881,8 +2616,7 @@ static void testDoubleContextDecodes( ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); } -static void testObjectIDContextDecodes( - Test * pTest) +static void testObjectIDContextDecodes(Test *pTest) { uint8_t apdu[MAX_APDU]; int inLen; @@ -2912,9 +2646,8 @@ static void testObjectIDContextDecodes( inLen = encode_context_object_id(apdu, large_context_tag, in_type, in_id); outLen = decode_context_object_id(apdu, large_context_tag, &out_type, &out_id); - outLen2 = - decode_context_object_id(apdu, large_context_tag - 1, &out_type, - &out_id); + outLen2 = decode_context_object_id(apdu, large_context_tag - 1, &out_type, + &out_id); ct_test(pTest, inLen == outLen); ct_test(pTest, in_type == out_type); @@ -2922,8 +2655,7 @@ static void testObjectIDContextDecodes( ct_test(pTest, outLen2 == BACNET_STATUS_ERROR); } -static void testCharacterStringContextDecodes( - Test * pTest) +static void testCharacterStringContextDecodes(Test *pTest) { uint8_t apdu[MAX_APDU]; int inLen; @@ -2931,7 +2663,6 @@ static void testCharacterStringContextDecodes( int outLen2; uint8_t large_context_tag = 0xfe; - BACNET_CHARACTER_STRING in; BACNET_CHARACTER_STRING out; @@ -2959,8 +2690,7 @@ static void testCharacterStringContextDecodes( ct_test(pTest, strcmp(in.value, out.value) == 0); } -static void testBitStringContextDecodes( - Test * pTest) +static void testBitStringContextDecodes(Test *pTest) { uint8_t apdu[MAX_APDU]; int inLen; @@ -2998,8 +2728,7 @@ static void testBitStringContextDecodes( ct_test(pTest, memcmp(in.value, out.value, MAX_BITSTRING_BYTES) == 0); } -static void testOctetStringContextDecodes( - Test * pTest) +static void testOctetStringContextDecodes(Test *pTest) { uint8_t apdu[MAX_APDU]; int inLen; @@ -3007,11 +2736,10 @@ static void testOctetStringContextDecodes( int outLen2; uint8_t large_context_tag = 0xfe; - BACNET_OCTET_STRING in; BACNET_OCTET_STRING out; - uint8_t initData[] = { 0xde, 0xad, 0xbe, 0xef }; + uint8_t initData[] = {0xde, 0xad, 0xbe, 0xef}; octetstring_init(&in, initData, sizeof(initData)); @@ -3032,11 +2760,9 @@ static void testOctetStringContextDecodes( ct_test(pTest, inLen == outLen); ct_test(pTest, in.length == out.length); ct_test(pTest, octetstring_value_same(&in, &out)); - } -static void testTimeContextDecodes( - Test * pTest) +static void testTimeContextDecodes(Test *pTest) { uint8_t apdu[MAX_APDU]; int inLen; @@ -3073,12 +2799,9 @@ static void testTimeContextDecodes( ct_test(pTest, in.hundredths == out.hundredths); ct_test(pTest, in.min == out.min); ct_test(pTest, in.sec == out.sec); - - } -static void testDateContextDecodes( - Test * pTest) +static void testDateContextDecodes(Test *pTest) { uint8_t apdu[MAX_APDU]; int inLen; @@ -3086,7 +2809,6 @@ static void testDateContextDecodes( int outLen2; uint8_t large_context_tag = 0xfe; - BACNET_DATE in; BACNET_DATE out; @@ -3118,8 +2840,7 @@ static void testDateContextDecodes( ct_test(pTest, in.year == out.year); } -void test_BACDCode( - Test * pTest) +void test_BACDCode(Test *pTest) { bool rc; @@ -3175,8 +2896,7 @@ void test_BACDCode( } #ifdef TEST_DECODE -int main( - void) +int main(void) { Test *pTest; @@ -3186,7 +2906,7 @@ int main( /* configure output */ ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/src/bacdevobjpropref.c b/src/bacdevobjpropref.c index 33899ae8..2ef221f1 100644 --- a/src/bacdevobjpropref.c +++ b/src/bacdevobjpropref.c @@ -38,12 +38,12 @@ #include "timestamp.h" #include "bacdevobjpropref.h" -/** @file bacdevobjpropref.c BACnet Application Device Object (Property) Reference */ +/** @file bacdevobjpropref.c BACnet Application Device Object (Property) + * Reference */ int bacapp_encode_context_device_obj_property_ref( - uint8_t * apdu, - uint8_t tag_number, - BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE * value) + uint8_t *apdu, uint8_t tag_number, + BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE *value) { int len; int apdu_len = 0; @@ -71,21 +71,19 @@ int bacapp_encode_context_device_obj_property_ref( } */ int bacapp_encode_device_obj_property_ref( - uint8_t * apdu, - BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE * value) + uint8_t *apdu, BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE *value) { int len; int apdu_len = 0; /* object-identifier [0] BACnetObjectIdentifier */ - len = - encode_context_object_id(&apdu[apdu_len], 0, - (int) value->objectIdentifier.type, value->objectIdentifier.instance); + len = encode_context_object_id(&apdu[apdu_len], 0, + (int)value->objectIdentifier.type, + value->objectIdentifier.instance); apdu_len += len; /* property-identifier [1] BACnetPropertyIdentifier */ - len = - encode_context_enumerated(&apdu[apdu_len], 1, - value->propertyIdentifier); + len = encode_context_enumerated(&apdu[apdu_len], 1, + value->propertyIdentifier); apdu_len += len; /* property-array-index [2] Unsigned OPTIONAL */ /* Check if needed before inserting */ @@ -96,12 +94,11 @@ int bacapp_encode_device_obj_property_ref( /* device-identifier [3] BACnetObjectIdentifier OPTIONAL */ /* Likewise, device id is optional so see if needed * (set type to BACNET_NO_DEV_TYPE or something other than OBJECT_DEVICE to - * omit */ + * omit */ if (value->deviceIdentifier.type == OBJECT_DEVICE) { - len = - encode_context_object_id(&apdu[apdu_len], 3, - (int) value->deviceIdentifier.type, - value->deviceIdentifier.instance); + len = encode_context_object_id(&apdu[apdu_len], 3, + (int)value->deviceIdentifier.type, + value->deviceIdentifier.instance); apdu_len += len; } return apdu_len; @@ -118,34 +115,31 @@ int bacapp_encode_device_obj_property_ref( } */ int bacapp_decode_device_obj_property_ref( - uint8_t * apdu, - BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE * value) + uint8_t *apdu, BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE *value) { int len; int apdu_len = 0; uint32_t enumValue; /* object-identifier [0] BACnetObjectIdentifier */ - if (-1 == (len = - decode_context_object_id(&apdu[apdu_len], 0, - &value->objectIdentifier.type, - &value->objectIdentifier.instance))) { + if (-1 == (len = decode_context_object_id( + &apdu[apdu_len], 0, &value->objectIdentifier.type, + &value->objectIdentifier.instance))) { return -1; } apdu_len += len; /* property-identifier [1] BACnetPropertyIdentifier */ - if (-1 == (len = - decode_context_enumerated(&apdu[apdu_len], 1, &enumValue))) { + if (-1 == + (len = decode_context_enumerated(&apdu[apdu_len], 1, &enumValue))) { return -1; } - value->propertyIdentifier = (BACNET_PROPERTY_ID) enumValue; + value->propertyIdentifier = (BACNET_PROPERTY_ID)enumValue; apdu_len += len; /* property-array-index [2] Unsigned OPTIONAL */ if (decode_is_context_tag(&apdu[apdu_len], 2) && !decode_is_closing_tag(&apdu[apdu_len])) { - if (-1 == (len = - decode_context_unsigned(&apdu[apdu_len], 2, - &value->arrayIndex))) { + if (-1 == (len = decode_context_unsigned(&apdu[apdu_len], 2, + &value->arrayIndex))) { return -1; } apdu_len += len; @@ -155,25 +149,23 @@ int bacapp_decode_device_obj_property_ref( /* device-identifier [3] BACnetObjectIdentifier OPTIONAL */ if (decode_is_context_tag(&apdu[apdu_len], 3) && !decode_is_closing_tag(&apdu[apdu_len])) { - if (-1 == (len = - decode_context_object_id(&apdu[apdu_len], 3, - &value->deviceIdentifier.type, - &value->deviceIdentifier.instance))) { + if (-1 == (len = decode_context_object_id( + &apdu[apdu_len], 3, &value->deviceIdentifier.type, + &value->deviceIdentifier.instance))) { return -1; } apdu_len += len; } else { - value->deviceIdentifier.type = BACNET_NO_DEV_TYPE; - value->deviceIdentifier.instance = BACNET_NO_DEV_ID; + value->deviceIdentifier.type = BACNET_NO_DEV_TYPE; + value->deviceIdentifier.instance = BACNET_NO_DEV_ID; } return apdu_len; } int bacapp_decode_context_device_obj_property_ref( - uint8_t * apdu, - uint8_t tag_number, - BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE * value) + uint8_t *apdu, uint8_t tag_number, + BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE *value) { int len = 0; int section_length; @@ -199,15 +191,12 @@ int bacapp_decode_context_device_obj_property_ref( return len; } - /* BACnetDeviceObjectReference ::= SEQUENCE { device-identifier [0] BACnetObjectIdentifier OPTIONAL, object-identifier [1] BACnetObjectIdentifier }*/ -int bacapp_encode_context_device_obj_ref( - uint8_t * apdu, - uint8_t tag_number, - BACNET_DEVICE_OBJECT_REFERENCE * value) +int bacapp_encode_context_device_obj_ref(uint8_t *apdu, uint8_t tag_number, + BACNET_DEVICE_OBJECT_REFERENCE *value) { int len; int apdu_len = 0; @@ -228,9 +217,8 @@ int bacapp_encode_context_device_obj_ref( device-identifier [0] BACnetObjectIdentifier OPTIONAL, object-identifier [1] BACnetObjectIdentifier }*/ -int bacapp_encode_device_obj_ref( - uint8_t * apdu, - BACNET_DEVICE_OBJECT_REFERENCE * value) +int bacapp_encode_device_obj_ref(uint8_t *apdu, + BACNET_DEVICE_OBJECT_REFERENCE *value) { int len; int apdu_len = 0; @@ -238,18 +226,17 @@ int bacapp_encode_device_obj_ref( /* device-identifier [0] BACnetObjectIdentifier OPTIONAL */ /* Device id is optional so see if needed * (set type to BACNET_NO_DEV_TYPE or something other than OBJECT_DEVICE to - * omit */ + * omit */ if (value->deviceIdentifier.type == OBJECT_DEVICE) { - len = - encode_context_object_id(&apdu[apdu_len], 0, - (int) value->deviceIdentifier.type, - value->deviceIdentifier.instance); + len = encode_context_object_id(&apdu[apdu_len], 0, + (int)value->deviceIdentifier.type, + value->deviceIdentifier.instance); apdu_len += len; } /* object-identifier [1] BACnetObjectIdentifier */ - len = - encode_context_object_id(&apdu[apdu_len], 1, - (int) value->objectIdentifier.type, value->objectIdentifier.instance); + len = encode_context_object_id(&apdu[apdu_len], 1, + (int)value->objectIdentifier.type, + value->objectIdentifier.instance); apdu_len += len; return apdu_len; @@ -259,9 +246,8 @@ int bacapp_encode_device_obj_ref( device-identifier [0] BACnetObjectIdentifier OPTIONAL, object-identifier [1] BACnetObjectIdentifier }*/ -int bacapp_decode_device_obj_ref( - uint8_t * apdu, - BACNET_DEVICE_OBJECT_REFERENCE * value) +int bacapp_decode_device_obj_ref(uint8_t *apdu, + BACNET_DEVICE_OBJECT_REFERENCE *value) { int len; int apdu_len = 0; @@ -269,22 +255,20 @@ int bacapp_decode_device_obj_ref( /* device-identifier [0] BACnetObjectIdentifier OPTIONAL */ if (decode_is_context_tag(&apdu[apdu_len], 0) && !decode_is_closing_tag(&apdu[apdu_len])) { - if (-1 == (len = - decode_context_object_id(&apdu[apdu_len], 0, - &value->deviceIdentifier.type, - &value->deviceIdentifier.instance))) { + if (-1 == (len = decode_context_object_id( + &apdu[apdu_len], 0, &value->deviceIdentifier.type, + &value->deviceIdentifier.instance))) { return -1; } apdu_len += len; } else { - value->deviceIdentifier.type = BACNET_NO_DEV_TYPE; - value->deviceIdentifier.instance = BACNET_NO_DEV_ID; + value->deviceIdentifier.type = BACNET_NO_DEV_TYPE; + value->deviceIdentifier.instance = BACNET_NO_DEV_ID; } /* object-identifier [1] BACnetObjectIdentifier */ - if (-1 == (len = - decode_context_object_id(&apdu[apdu_len], 1, - &value->objectIdentifier.type, - &value->objectIdentifier.instance))) { + if (-1 == (len = decode_context_object_id( + &apdu[apdu_len], 1, &value->objectIdentifier.type, + &value->objectIdentifier.instance))) { return -1; } apdu_len += len; @@ -292,10 +276,8 @@ int bacapp_decode_device_obj_ref( return apdu_len; } -int bacapp_decode_context_device_obj_ref( - uint8_t * apdu, - uint8_t tag_number, - BACNET_DEVICE_OBJECT_REFERENCE * value) +int bacapp_decode_context_device_obj_ref(uint8_t *apdu, uint8_t tag_number, + BACNET_DEVICE_OBJECT_REFERENCE *value) { int len = 0; int section_length; @@ -324,9 +306,8 @@ int bacapp_decode_context_device_obj_ref( #include #include #include "ctest.h" -static void testDevObjPropRef( - Test * pTest, - BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE *inData) +static void testDevObjPropRef(Test *pTest, + BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE *inData) { BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE outData; uint8_t buffer[MAX_APDU] = {0}; @@ -341,10 +322,10 @@ static void testDevObjPropRef( /* decode */ outLen = bacapp_decode_device_obj_property_ref(buffer, &outData); ct_test(pTest, outLen == inLen); + ct_test(pTest, inData->objectIdentifier.instance == + outData.objectIdentifier.instance); ct_test(pTest, - inData->objectIdentifier.instance == outData.objectIdentifier.instance); - ct_test(pTest, - inData->objectIdentifier.type == outData.objectIdentifier.type); + inData->objectIdentifier.type == outData.objectIdentifier.type); ct_test(pTest, inData->propertyIdentifier == outData.propertyIdentifier); if (inData->arrayIndex != BACNET_ARRAY_ALL) { ct_test(pTest, inData->arrayIndex == outData.arrayIndex); @@ -352,19 +333,17 @@ static void testDevObjPropRef( ct_test(pTest, outData.arrayIndex == BACNET_ARRAY_ALL); } if (inData->deviceIdentifier.type == OBJECT_DEVICE) { + ct_test(pTest, inData->deviceIdentifier.instance == + outData.deviceIdentifier.instance); ct_test(pTest, - inData->deviceIdentifier.instance == - outData.deviceIdentifier.instance); - ct_test(pTest, - inData->deviceIdentifier.type == outData.deviceIdentifier.type); + inData->deviceIdentifier.type == outData.deviceIdentifier.type); } else { - ct_test(pTest,outData.deviceIdentifier.instance == BACNET_NO_DEV_ID); - ct_test(pTest,outData.deviceIdentifier.type == BACNET_NO_DEV_TYPE); + ct_test(pTest, outData.deviceIdentifier.instance == BACNET_NO_DEV_ID); + ct_test(pTest, outData.deviceIdentifier.type == BACNET_NO_DEV_TYPE); } } -static void testDevIdPropRef( - Test * pTest) +static void testDevIdPropRef(Test *pTest) { BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE inData; @@ -402,8 +381,7 @@ static void testDevIdPropRef( testDevObjPropRef(pTest, &inData); } -static void testDevIdRef( - Test * pTest) +static void testDevIdRef(Test *pTest) { BACNET_DEVICE_OBJECT_REFERENCE inData; BACNET_DEVICE_OBJECT_REFERENCE outData; @@ -416,15 +394,13 @@ static void testDevIdRef( inLen = bacapp_encode_device_obj_ref(buffer, &inData); outLen = bacapp_decode_device_obj_ref(buffer, &outData); ct_test(pTest, outLen == inLen); + ct_test(pTest, inData.deviceIdentifier.instance == + outData.deviceIdentifier.instance); ct_test(pTest, - inData.deviceIdentifier.instance == - outData.deviceIdentifier.instance); - ct_test(pTest, - inData.deviceIdentifier.type == outData.deviceIdentifier.type); + inData.deviceIdentifier.type == outData.deviceIdentifier.type); } -void testBACnetDeviceObjectPropertyReference( - Test * pTest) +void testBACnetDeviceObjectPropertyReference(Test *pTest) { bool rc; @@ -437,8 +413,7 @@ void testBACnetDeviceObjectPropertyReference( #ifdef TEST_DEV_ID_PROP_REF #include -int main( - void) +int main(void) { Test *pTest; @@ -447,7 +422,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/src/bacerror.c b/src/bacerror.c index b0cfb4fa..65be30f6 100644 --- a/src/bacerror.c +++ b/src/bacerror.c @@ -40,14 +40,12 @@ /** @file bacerror.c Encode/Decode BACnet Errors */ /* encode service */ -int bacerror_encode_apdu( - uint8_t * apdu, - uint8_t invoke_id, - BACNET_CONFIRMED_SERVICE service, - BACNET_ERROR_CLASS error_class, - BACNET_ERROR_CODE error_code) +int bacerror_encode_apdu(uint8_t *apdu, uint8_t invoke_id, + BACNET_CONFIRMED_SERVICE service, + BACNET_ERROR_CLASS error_class, + BACNET_ERROR_CODE error_code) { - 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_ERROR; @@ -55,8 +53,7 @@ int bacerror_encode_apdu( apdu[2] = service; apdu_len = 3; /* service parameters */ - apdu_len += - encode_application_enumerated(&apdu[apdu_len], error_class); + apdu_len += encode_application_enumerated(&apdu[apdu_len], error_class); apdu_len += encode_application_enumerated(&apdu[apdu_len], error_code); } @@ -65,11 +62,9 @@ int bacerror_encode_apdu( #if !BACNET_SVC_SERVER /* decode the application class and code */ -int bacerror_decode_error_class_and_code( - uint8_t * apdu, - unsigned apdu_len, - BACNET_ERROR_CLASS * error_class, - BACNET_ERROR_CODE * error_code) +int bacerror_decode_error_class_and_code(uint8_t *apdu, unsigned apdu_len, + BACNET_ERROR_CLASS *error_class, + BACNET_ERROR_CODE *error_code) { int len = 0; uint8_t tag_number = 0; @@ -78,36 +73,32 @@ int bacerror_decode_error_class_and_code( if (apdu_len) { /* error class */ - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value_type); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value_type); if (tag_number != BACNET_APPLICATION_TAG_ENUMERATED) return 0; len += decode_enumerated(&apdu[len], len_value_type, &decoded_value); if (error_class) - *error_class = (BACNET_ERROR_CLASS) decoded_value; + *error_class = (BACNET_ERROR_CLASS)decoded_value; /* error code */ - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value_type); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value_type); if (tag_number != BACNET_APPLICATION_TAG_ENUMERATED) return 0; len += decode_enumerated(&apdu[len], len_value_type, &decoded_value); if (error_code) - *error_code = (BACNET_ERROR_CODE) decoded_value; + *error_code = (BACNET_ERROR_CODE)decoded_value; } return len; } /* decode the service request only */ -int bacerror_decode_service_request( - uint8_t * apdu, - unsigned apdu_len, - uint8_t * invoke_id, - BACNET_CONFIRMED_SERVICE * service, - BACNET_ERROR_CLASS * error_class, - BACNET_ERROR_CODE * error_code) +int bacerror_decode_service_request(uint8_t *apdu, unsigned apdu_len, + uint8_t *invoke_id, + BACNET_CONFIRMED_SERVICE *service, + BACNET_ERROR_CLASS *error_class, + BACNET_ERROR_CODE *error_code) { int len = 0; @@ -115,11 +106,10 @@ int bacerror_decode_service_request( if (invoke_id) *invoke_id = apdu[0]; if (service) - *service = (BACNET_CONFIRMED_SERVICE) apdu[1]; + *service = (BACNET_CONFIRMED_SERVICE)apdu[1]; /* decode the application class and code */ - len = - bacerror_decode_error_class_and_code(&apdu[2], apdu_len - 2, - error_class, error_code); + len = bacerror_decode_error_class_and_code(&apdu[2], apdu_len - 2, + error_class, error_code); } return len; @@ -132,13 +122,10 @@ int bacerror_decode_service_request( #include "ctest.h" /* decode the whole APDU - mainly used for unit testing */ -int bacerror_decode_apdu( - uint8_t * apdu, - unsigned apdu_len, - uint8_t * invoke_id, - BACNET_CONFIRMED_SERVICE * service, - BACNET_ERROR_CLASS * error_class, - BACNET_ERROR_CODE * error_code) +int bacerror_decode_apdu(uint8_t *apdu, unsigned apdu_len, uint8_t *invoke_id, + BACNET_CONFIRMED_SERVICE *service, + BACNET_ERROR_CLASS *error_class, + BACNET_ERROR_CODE *error_code) { int len = 0; @@ -149,19 +136,18 @@ int bacerror_decode_apdu( if (apdu[0] != PDU_TYPE_ERROR) return -1; if (apdu_len > 1) { - len = - bacerror_decode_service_request(&apdu[1], apdu_len - 1, - invoke_id, service, error_class, error_code); + len = bacerror_decode_service_request(&apdu[1], apdu_len - 1, + invoke_id, service, + error_class, error_code); } } return len; } -void testBACError( - Test * pTest) +void testBACError(Test *pTest) { - uint8_t apdu[480] = { 0 }; + uint8_t apdu[480] = {0}; int len = 0; int apdu_len = 0; uint8_t invoke_id = 0; @@ -173,15 +159,14 @@ void testBACError( BACNET_ERROR_CLASS test_error_class = 0; BACNET_ERROR_CODE test_error_code = 0; - len = - bacerror_encode_apdu(&apdu[0], invoke_id, service, error_class, - error_code); + len = bacerror_encode_apdu(&apdu[0], invoke_id, service, error_class, + error_code); ct_test(pTest, len != 0); apdu_len = len; len = - bacerror_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, - &test_service, &test_error_class, &test_error_code); + bacerror_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, &test_service, + &test_error_class, &test_error_code); ct_test(pTest, len != -1); ct_test(pTest, test_invoke_id == invoke_id); ct_test(pTest, test_service == service); @@ -191,37 +176,33 @@ void testBACError( /* change type to get negative response */ apdu[0] = PDU_TYPE_ABORT; len = - bacerror_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, - &test_service, &test_error_class, &test_error_code); + bacerror_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, &test_service, + &test_error_class, &test_error_code); ct_test(pTest, len == -1); /* test NULL APDU */ - len = - bacerror_decode_apdu(NULL, apdu_len, &test_invoke_id, &test_service, - &test_error_class, &test_error_code); + len = bacerror_decode_apdu(NULL, apdu_len, &test_invoke_id, &test_service, + &test_error_class, &test_error_code); ct_test(pTest, len == -1); /* force a zero length */ - len = - bacerror_decode_apdu(&apdu[0], 0, &test_invoke_id, &test_service, - &test_error_class, &test_error_code); + len = bacerror_decode_apdu(&apdu[0], 0, &test_invoke_id, &test_service, + &test_error_class, &test_error_code); ct_test(pTest, len == 0); - /* check them all... */ for (service = 0; service < MAX_BACNET_CONFIRMED_SERVICE; service++) { for (error_class = 0; error_class < ERROR_CLASS_PROPRIETARY_FIRST; - error_class++) { + error_class++) { for (error_code = 0; error_code < ERROR_CODE_PROPRIETARY_FIRST; - error_code++) { - len = - bacerror_encode_apdu(&apdu[0], invoke_id, service, - error_class, error_code); + error_code++) { + len = bacerror_encode_apdu(&apdu[0], invoke_id, service, + error_class, error_code); apdu_len = len; ct_test(pTest, len != 0); - len = - bacerror_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, - &test_service, &test_error_class, &test_error_code); + len = bacerror_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, + &test_service, &test_error_class, + &test_error_code); ct_test(pTest, len != -1); ct_test(pTest, test_invoke_id == invoke_id); ct_test(pTest, test_service == service); @@ -235,25 +216,22 @@ void testBACError( service = 255; error_class = ERROR_CLASS_PROPRIETARY_LAST; error_code = ERROR_CODE_PROPRIETARY_LAST; - len = - bacerror_encode_apdu(&apdu[0], invoke_id, service, error_class, - error_code); + len = bacerror_encode_apdu(&apdu[0], invoke_id, service, error_class, + error_code); apdu_len = len; ct_test(pTest, len != 0); len = - bacerror_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, - &test_service, &test_error_class, &test_error_code); + bacerror_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, &test_service, + &test_error_class, &test_error_code); ct_test(pTest, len != -1); ct_test(pTest, test_invoke_id == invoke_id); ct_test(pTest, test_service == service); ct_test(pTest, test_error_class == error_class); ct_test(pTest, test_error_code == error_code); - } #ifdef TEST_BACERROR -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -265,7 +243,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/src/bacint.c b/src/bacint.c index 242338eb..a7256968 100644 --- a/src/bacint.c +++ b/src/bacint.c @@ -41,73 +41,61 @@ /** @file bacint.c Encode/Decode Integer Types */ -int encode_unsigned16( - uint8_t * apdu, - uint16_t value) +int encode_unsigned16(uint8_t *apdu, uint16_t value) { - apdu[0] = (uint8_t) ((value & 0xff00) >> 8); - apdu[1] = (uint8_t) (value & 0x00ff); + apdu[0] = (uint8_t)((value & 0xff00) >> 8); + apdu[1] = (uint8_t)(value & 0x00ff); return 2; } -int decode_unsigned16( - uint8_t * apdu, - uint16_t * value) +int decode_unsigned16(uint8_t *apdu, uint16_t *value) { if (value) { - *value = (uint16_t) ((((uint16_t) apdu[0]) << 8) & 0xff00); - *value |= ((uint16_t) (((uint16_t) apdu[1]) & 0x00ff)); + *value = (uint16_t)((((uint16_t)apdu[0]) << 8) & 0xff00); + *value |= ((uint16_t)(((uint16_t)apdu[1]) & 0x00ff)); } return 2; } -int encode_unsigned24( - uint8_t * apdu, - uint32_t value) +int encode_unsigned24(uint8_t *apdu, uint32_t value) { - apdu[0] = (uint8_t) ((value & 0xff0000) >> 16); - apdu[1] = (uint8_t) ((value & 0x00ff00) >> 8); - apdu[2] = (uint8_t) (value & 0x0000ff); + apdu[0] = (uint8_t)((value & 0xff0000) >> 16); + apdu[1] = (uint8_t)((value & 0x00ff00) >> 8); + apdu[2] = (uint8_t)(value & 0x0000ff); return 3; } -int decode_unsigned24( - uint8_t * apdu, - uint32_t * value) +int decode_unsigned24(uint8_t *apdu, uint32_t *value) { if (value) { - *value = ((uint32_t) ((((uint32_t) apdu[0]) << 16) & 0x00ff0000)); - *value |= (uint32_t) ((((uint32_t) apdu[1]) << 8) & 0x0000ff00); - *value |= ((uint32_t) (((uint32_t) apdu[2]) & 0x000000ff)); + *value = ((uint32_t)((((uint32_t)apdu[0]) << 16) & 0x00ff0000)); + *value |= (uint32_t)((((uint32_t)apdu[1]) << 8) & 0x0000ff00); + *value |= ((uint32_t)(((uint32_t)apdu[2]) & 0x000000ff)); } return 3; } -int encode_unsigned32( - uint8_t * apdu, - uint32_t value) +int encode_unsigned32(uint8_t *apdu, uint32_t value) { - apdu[0] = (uint8_t) ((value & 0xff000000) >> 24); - apdu[1] = (uint8_t) ((value & 0x00ff0000) >> 16); - apdu[2] = (uint8_t) ((value & 0x0000ff00) >> 8); - apdu[3] = (uint8_t) (value & 0x000000ff); + apdu[0] = (uint8_t)((value & 0xff000000) >> 24); + apdu[1] = (uint8_t)((value & 0x00ff0000) >> 16); + apdu[2] = (uint8_t)((value & 0x0000ff00) >> 8); + apdu[3] = (uint8_t)(value & 0x000000ff); return 4; } -int decode_unsigned32( - uint8_t * apdu, - uint32_t * value) +int decode_unsigned32(uint8_t *apdu, uint32_t *value) { if (value) { - *value = ((uint32_t) ((((uint32_t) apdu[0]) << 24) & 0xff000000)); - *value |= ((uint32_t) ((((uint32_t) apdu[1]) << 16) & 0x00ff0000)); - *value |= ((uint32_t) ((((uint32_t) apdu[2]) << 8) & 0x0000ff00)); - *value |= ((uint32_t) (((uint32_t) apdu[3]) & 0x000000ff)); + *value = ((uint32_t)((((uint32_t)apdu[0]) << 24) & 0xff000000)); + *value |= ((uint32_t)((((uint32_t)apdu[1]) << 16) & 0x00ff0000)); + *value |= ((uint32_t)((((uint32_t)apdu[2]) << 8) & 0x0000ff00)); + *value |= ((uint32_t)(((uint32_t)apdu[3]) & 0x000000ff)); } return 4; @@ -120,18 +108,16 @@ int decode_unsigned32( * @param value - 16-bit value to encode * @return Returns the number of bytes encoded */ -int encode_unsigned64( - uint8_t * buffer, - uint64_t value) +int encode_unsigned64(uint8_t *buffer, uint64_t value) { - buffer[0] = (uint8_t) ((value & 0xff00000000000000) >> 56); - buffer[1] = (uint8_t) ((value & 0x00ff000000000000) >> 48); - buffer[2] = (uint8_t) ((value & 0x0000ff0000000000) >> 40); - buffer[3] = (uint8_t) ((value & 0x000000ff00000000) >> 32); - buffer[4] = (uint8_t) ((value & 0x00000000ff000000) >> 24); - buffer[5] = (uint8_t) ((value & 0x0000000000ff0000) >> 16); - buffer[6] = (uint8_t) ((value & 0x000000000000ff00) >> 8); - buffer[7] = (uint8_t) (value & 0x00000000000000ff); + buffer[0] = (uint8_t)((value & 0xff00000000000000) >> 56); + buffer[1] = (uint8_t)((value & 0x00ff000000000000) >> 48); + buffer[2] = (uint8_t)((value & 0x0000ff0000000000) >> 40); + buffer[3] = (uint8_t)((value & 0x000000ff00000000) >> 32); + buffer[4] = (uint8_t)((value & 0x00000000ff000000) >> 24); + buffer[5] = (uint8_t)((value & 0x0000000000ff0000) >> 16); + buffer[6] = (uint8_t)((value & 0x000000000000ff00) >> 8); + buffer[7] = (uint8_t)(value & 0x00000000000000ff); return 8; } @@ -142,19 +128,24 @@ int encode_unsigned64( * @param value - pointer to 64-bit value to store the decoded value * @return Returns the number of bytes decoded */ -int decode_unsigned64( - uint8_t * buffer, - uint64_t * value) +int decode_unsigned64(uint8_t *buffer, uint64_t *value) { if (value) { - *value = ((uint64_t) ((((uint64_t) buffer[0]) << 56) & 0xff00000000000000)); - *value |= ((uint64_t) ((((uint64_t) buffer[1]) << 48) & 0x00ff000000000000)); - *value |= ((uint64_t) ((((uint64_t) buffer[2]) << 40) & 0x0000ff0000000000)); - *value |= ((uint64_t) ((((uint64_t) buffer[3]) << 32) & 0x000000ff00000000)); - *value |= ((uint64_t) ((((uint64_t) buffer[4]) << 24) & 0x00000000ff000000)); - *value |= ((uint64_t) ((((uint64_t) buffer[5]) << 16) & 0x0000000000ff0000)); - *value |= ((uint64_t) ((((uint64_t) buffer[6]) << 8) & 0x000000000000ff00)); - *value |= ((uint64_t) (((uint64_t) buffer[7]) & 0x00000000000000ff)); + *value = + ((uint64_t)((((uint64_t)buffer[0]) << 56) & 0xff00000000000000)); + *value |= + ((uint64_t)((((uint64_t)buffer[1]) << 48) & 0x00ff000000000000)); + *value |= + ((uint64_t)((((uint64_t)buffer[2]) << 40) & 0x0000ff0000000000)); + *value |= + ((uint64_t)((((uint64_t)buffer[3]) << 32) & 0x000000ff00000000)); + *value |= + ((uint64_t)((((uint64_t)buffer[4]) << 24) & 0x00000000ff000000)); + *value |= + ((uint64_t)((((uint64_t)buffer[5]) << 16) & 0x0000000000ff0000)); + *value |= + ((uint64_t)((((uint64_t)buffer[6]) << 8) & 0x000000000000ff00)); + *value |= ((uint64_t)(((uint64_t)buffer[7]) & 0x00000000000000ff)); } return 8; @@ -162,18 +153,14 @@ int decode_unsigned64( #endif #if BACNET_USE_SIGNED -int encode_signed8( - uint8_t * apdu, - int8_t value) +int encode_signed8(uint8_t *apdu, int8_t value) { - apdu[0] = (uint8_t) value; + apdu[0] = (uint8_t)value; return 1; } -int decode_signed8( - uint8_t * apdu, - int32_t * value) +int decode_signed8(uint8_t *apdu, int32_t *value) { if (value) { /* negative - bit 7 is set */ @@ -181,25 +168,21 @@ int decode_signed8( *value = 0xFFFFFF00; else *value = 0; - *value |= ((int32_t) (((int32_t) apdu[0]) & 0x000000ff)); + *value |= ((int32_t)(((int32_t)apdu[0]) & 0x000000ff)); } return 1; } -int encode_signed16( - uint8_t * apdu, - int16_t value) +int encode_signed16(uint8_t *apdu, int16_t value) { - apdu[0] = (uint8_t) ((value & 0xff00) >> 8); - apdu[1] = (uint8_t) (value & 0x00ff); + apdu[0] = (uint8_t)((value & 0xff00) >> 8); + apdu[1] = (uint8_t)(value & 0x00ff); return 2; } -int decode_signed16( - uint8_t * apdu, - int32_t * value) +int decode_signed16(uint8_t *apdu, int32_t *value) { if (value) { /* negative - bit 7 is set */ @@ -207,27 +190,23 @@ int decode_signed16( *value = 0xFFFF0000; else *value = 0; - *value |= ((int32_t) ((((int32_t) apdu[0]) << 8) & 0x0000ff00)); - *value |= ((int32_t) (((int32_t) apdu[1]) & 0x000000ff)); + *value |= ((int32_t)((((int32_t)apdu[0]) << 8) & 0x0000ff00)); + *value |= ((int32_t)(((int32_t)apdu[1]) & 0x000000ff)); } return 2; } -int encode_signed24( - uint8_t * apdu, - int32_t value) +int encode_signed24(uint8_t *apdu, int32_t value) { - apdu[0] = (uint8_t) ((value & 0xff0000) >> 16); - apdu[1] = (uint8_t) ((value & 0x00ff00) >> 8); - apdu[2] = (uint8_t) (value & 0x0000ff); + apdu[0] = (uint8_t)((value & 0xff0000) >> 16); + apdu[1] = (uint8_t)((value & 0x00ff00) >> 8); + apdu[2] = (uint8_t)(value & 0x0000ff); return 3; } -int decode_signed24( - uint8_t * apdu, - int32_t * value) +int decode_signed24(uint8_t *apdu, int32_t *value) { if (value) { /* negative - bit 7 is set */ @@ -235,35 +214,31 @@ int decode_signed24( *value = 0xFF000000; else *value = 0; - *value |= ((int32_t) ((((int32_t) apdu[0]) << 16) & 0x00ff0000)); - *value |= ((int32_t) ((((int32_t) apdu[1]) << 8) & 0x0000ff00)); - *value |= ((int32_t) (((int32_t) apdu[2]) & 0x000000ff)); + *value |= ((int32_t)((((int32_t)apdu[0]) << 16) & 0x00ff0000)); + *value |= ((int32_t)((((int32_t)apdu[1]) << 8) & 0x0000ff00)); + *value |= ((int32_t)(((int32_t)apdu[2]) & 0x000000ff)); } return 3; } -int encode_signed32( - uint8_t * apdu, - int32_t value) +int encode_signed32(uint8_t *apdu, int32_t value) { - apdu[0] = (uint8_t) ((value & 0xff000000) >> 24); - apdu[1] = (uint8_t) ((value & 0x00ff0000) >> 16); - apdu[2] = (uint8_t) ((value & 0x0000ff00) >> 8); - apdu[3] = (uint8_t) (value & 0x000000ff); + apdu[0] = (uint8_t)((value & 0xff000000) >> 24); + apdu[1] = (uint8_t)((value & 0x00ff0000) >> 16); + apdu[2] = (uint8_t)((value & 0x0000ff00) >> 8); + apdu[3] = (uint8_t)(value & 0x000000ff); return 4; } -int decode_signed32( - uint8_t * apdu, - int32_t * value) +int decode_signed32(uint8_t *apdu, int32_t *value) { if (value) { - *value = ((int32_t) ((((int32_t) apdu[0]) << 24) & 0xff000000)); - *value |= ((int32_t) ((((int32_t) apdu[1]) << 16) & 0x00ff0000)); - *value |= ((int32_t) ((((int32_t) apdu[2]) << 8) & 0x0000ff00)); - *value |= ((int32_t) (((int32_t) apdu[3]) & 0x000000ff)); + *value = ((int32_t)((((int32_t)apdu[0]) << 24) & 0xff000000)); + *value |= ((int32_t)((((int32_t)apdu[1]) << 16) & 0x00ff0000)); + *value |= ((int32_t)((((int32_t)apdu[2]) << 8) & 0x0000ff00)); + *value |= ((int32_t)(((int32_t)apdu[3]) & 0x000000ff)); } return 4; @@ -276,10 +251,9 @@ int decode_signed32( #include #include "ctest.h" -static void testBACnetUnsigned16( - Test * pTest) +static void testBACnetUnsigned16(Test *pTest) { - uint8_t apdu[32] = { 0 }; + uint8_t apdu[32] = {0}; uint16_t value = 0, test_value = 0; int len = 0; @@ -293,10 +267,9 @@ static void testBACnetUnsigned16( } } -static void testBACnetUnsigned24( - Test * pTest) +static void testBACnetUnsigned24(Test *pTest) { - uint8_t apdu[32] = { 0 }; + uint8_t apdu[32] = {0}; uint32_t value = 0, test_value = 0; int len = 0; @@ -310,10 +283,9 @@ static void testBACnetUnsigned24( } } -static void testBACnetUnsigned32( - Test * pTest) +static void testBACnetUnsigned32(Test *pTest) { - uint8_t apdu[32] = { 0 }; + uint8_t apdu[32] = {0}; uint32_t value = 0, test_value = 0; int len = 0; @@ -327,10 +299,9 @@ static void testBACnetUnsigned32( } } -static void testBACnetSigned8( - Test * pTest) +static void testBACnetSigned8(Test *pTest) { - uint8_t apdu[32] = { 0 }; + uint8_t apdu[32] = {0}; int32_t value = 0, test_value = 0; int len = 0; @@ -344,10 +315,9 @@ static void testBACnetSigned8( } } -static void testBACnetSigned16( - Test * pTest) +static void testBACnetSigned16(Test *pTest) { - uint8_t apdu[32] = { 0 }; + uint8_t apdu[32] = {0}; int32_t value = 0, test_value = 0; int len = 0; @@ -361,10 +331,9 @@ static void testBACnetSigned16( } } -static void testBACnetSigned24( - Test * pTest) +static void testBACnetSigned24(Test *pTest) { - uint8_t apdu[32] = { 0 }; + uint8_t apdu[32] = {0}; int32_t value = 0, test_value = 0; int len = 0; @@ -376,10 +345,9 @@ static void testBACnetSigned24( } } -static void testBACnetSigned32( - Test * pTest) +static void testBACnetSigned32(Test *pTest) { - uint8_t apdu[32] = { 0 }; + uint8_t apdu[32] = {0}; int32_t value = 0, test_value = 0; int len = 0; @@ -397,8 +365,7 @@ static void testBACnetSigned32( } } -void testBACnetIntegers( - Test * pTest) +void testBACnetIntegers(Test *pTest) { bool rc; @@ -421,8 +388,7 @@ void testBACnetIntegers( } #ifdef TEST_BACINT -int main( - void) +int main(void) { Test *pTest; @@ -431,7 +397,7 @@ int main( /* configure output */ ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/src/bacprop.c b/src/bacprop.c index 1131ff11..01e77385 100644 --- a/src/bacprop.c +++ b/src/bacprop.c @@ -13,9 +13,9 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to + along with this program; if not, write to The Free Software Foundation, Inc. - 59 Temple Place - Suite 330 + 59 Temple Place - Suite 330 Boston, MA 02111-1307, USA. As a special exception, if other files instantiate templates or @@ -41,49 +41,28 @@ /** @file bacprop.c Lookup BACnet Property Tags */ PROP_TAG_DATA bacnet_object_device_property_tag_map[] = { - {PROP_OBJECT_IDENTIFIER, BACNET_APPLICATION_TAG_OBJECT_ID} - , - {PROP_OBJECT_NAME, BACNET_APPLICATION_TAG_CHARACTER_STRING} - , - {PROP_OBJECT_TYPE, BACNET_APPLICATION_TAG_ENUMERATED} - , - {PROP_SYSTEM_STATUS, BACNET_APPLICATION_TAG_ENUMERATED} - , - {PROP_VENDOR_NAME, BACNET_APPLICATION_TAG_CHARACTER_STRING} - , - {PROP_VENDOR_IDENTIFIER, BACNET_APPLICATION_TAG_UNSIGNED_INT} - , - {PROP_MODEL_NAME, BACNET_APPLICATION_TAG_CHARACTER_STRING} - , - {PROP_FIRMWARE_REVISION, BACNET_APPLICATION_TAG_CHARACTER_STRING} - , + {PROP_OBJECT_IDENTIFIER, BACNET_APPLICATION_TAG_OBJECT_ID}, + {PROP_OBJECT_NAME, BACNET_APPLICATION_TAG_CHARACTER_STRING}, + {PROP_OBJECT_TYPE, BACNET_APPLICATION_TAG_ENUMERATED}, + {PROP_SYSTEM_STATUS, BACNET_APPLICATION_TAG_ENUMERATED}, + {PROP_VENDOR_NAME, BACNET_APPLICATION_TAG_CHARACTER_STRING}, + {PROP_VENDOR_IDENTIFIER, BACNET_APPLICATION_TAG_UNSIGNED_INT}, + {PROP_MODEL_NAME, BACNET_APPLICATION_TAG_CHARACTER_STRING}, + {PROP_FIRMWARE_REVISION, BACNET_APPLICATION_TAG_CHARACTER_STRING}, {PROP_APPLICATION_SOFTWARE_VERSION, - BACNET_APPLICATION_TAG_CHARACTER_STRING} - , - {PROP_PROTOCOL_VERSION, BACNET_APPLICATION_TAG_UNSIGNED_INT} - , - {PROP_PROTOCOL_CONFORMANCE_CLASS, BACNET_APPLICATION_TAG_UNSIGNED_INT} - , - {PROP_PROTOCOL_SERVICES_SUPPORTED, BACNET_APPLICATION_TAG_BIT_STRING} - , - {PROP_PROTOCOL_OBJECT_TYPES_SUPPORTED, - BACNET_APPLICATION_TAG_BIT_STRING} - , - {PROP_MAX_APDU_LENGTH_ACCEPTED, BACNET_APPLICATION_TAG_UNSIGNED_INT} - , - {PROP_SEGMENTATION_SUPPORTED, BACNET_APPLICATION_TAG_ENUMERATED} - , - {PROP_APDU_TIMEOUT, BACNET_APPLICATION_TAG_UNSIGNED_INT} - , - {PROP_NUMBER_OF_APDU_RETRIES, BACNET_APPLICATION_TAG_UNSIGNED_INT} - , - {-1, -1} -}; + BACNET_APPLICATION_TAG_CHARACTER_STRING}, + {PROP_PROTOCOL_VERSION, BACNET_APPLICATION_TAG_UNSIGNED_INT}, + {PROP_PROTOCOL_CONFORMANCE_CLASS, BACNET_APPLICATION_TAG_UNSIGNED_INT}, + {PROP_PROTOCOL_SERVICES_SUPPORTED, BACNET_APPLICATION_TAG_BIT_STRING}, + {PROP_PROTOCOL_OBJECT_TYPES_SUPPORTED, BACNET_APPLICATION_TAG_BIT_STRING}, + {PROP_MAX_APDU_LENGTH_ACCEPTED, BACNET_APPLICATION_TAG_UNSIGNED_INT}, + {PROP_SEGMENTATION_SUPPORTED, BACNET_APPLICATION_TAG_ENUMERATED}, + {PROP_APDU_TIMEOUT, BACNET_APPLICATION_TAG_UNSIGNED_INT}, + {PROP_NUMBER_OF_APDU_RETRIES, BACNET_APPLICATION_TAG_UNSIGNED_INT}, + {-1, -1}}; -signed bacprop_tag_by_index_default( - PROP_TAG_DATA * data_list, - signed index, - signed default_ret) +signed bacprop_tag_by_index_default(PROP_TAG_DATA* data_list, signed index, + signed default_ret) { signed pUnsigned = 0; @@ -100,16 +79,12 @@ signed bacprop_tag_by_index_default( return pUnsigned ? pUnsigned : default_ret; } - -signed bacprop_property_tag( - BACNET_OBJECT_TYPE type, - signed prop) +signed bacprop_property_tag(BACNET_OBJECT_TYPE type, signed prop) { switch (type) { case OBJECT_DEVICE: - return - bacprop_tag_by_index_default - (bacnet_object_device_property_tag_map, prop, -1); + return bacprop_tag_by_index_default( + bacnet_object_device_property_tag_map, prop, -1); default: #if PRINT_ENABLED fprintf(stderr, "Unsupported object type"); diff --git a/src/bacpropstates.c b/src/bacpropstates.c index daeefc6f..43c7b410 100644 --- a/src/bacpropstates.c +++ b/src/bacpropstates.c @@ -39,9 +39,7 @@ /** @file bacpropstates.c Encode/Decode BACnet Application Property States */ -int bacapp_decode_property_state( - uint8_t * apdu, - BACNET_PROPERTY_STATE * value) +int bacapp_decode_property_state(uint8_t *apdu, BACNET_PROPERTY_STATE *value) { int len = 0; uint32_t len_value_type; @@ -63,120 +61,107 @@ int bacapp_decode_property_state( break; case BINARY_VALUE: - if (-1 == (section_length = - decode_enumerated(&apdu[len], len_value_type, - &enumValue))) { + if (-1 == (section_length = decode_enumerated( + &apdu[len], len_value_type, &enumValue))) { return -1; } - value->state.binaryValue = (BACNET_BINARY_PV) enumValue; + value->state.binaryValue = (BACNET_BINARY_PV)enumValue; break; case EVENT_TYPE: - if (-1 == (section_length = - decode_enumerated(&apdu[len], len_value_type, - &enumValue))) { + if (-1 == (section_length = decode_enumerated( + &apdu[len], len_value_type, &enumValue))) { return -1; } - value->state.eventType = (BACNET_EVENT_TYPE) enumValue; + value->state.eventType = (BACNET_EVENT_TYPE)enumValue; break; case POLARITY: - if (-1 == (section_length = - decode_enumerated(&apdu[len], len_value_type, - &enumValue))) { + if (-1 == (section_length = decode_enumerated( + &apdu[len], len_value_type, &enumValue))) { return -1; } - value->state.polarity = (BACNET_POLARITY) enumValue; + value->state.polarity = (BACNET_POLARITY)enumValue; break; case PROGRAM_CHANGE: - if (-1 == (section_length = - decode_enumerated(&apdu[len], len_value_type, - &enumValue))) { + if (-1 == (section_length = decode_enumerated( + &apdu[len], len_value_type, &enumValue))) { return -1; } - value->state.programChange = (BACNET_PROGRAM_REQUEST) enumValue; + value->state.programChange = (BACNET_PROGRAM_REQUEST)enumValue; break; case PROGRAM_STATE: - if (-1 == (section_length = - decode_enumerated(&apdu[len], len_value_type, - &enumValue))) { + if (-1 == (section_length = decode_enumerated( + &apdu[len], len_value_type, &enumValue))) { return -1; } - value->state.programState = (BACNET_PROGRAM_STATE) enumValue; + value->state.programState = (BACNET_PROGRAM_STATE)enumValue; break; case REASON_FOR_HALT: - if (-1 == (section_length = - decode_enumerated(&apdu[len], len_value_type, - &enumValue))) { + if (-1 == (section_length = decode_enumerated( + &apdu[len], len_value_type, &enumValue))) { return -1; } - value->state.programError = (BACNET_PROGRAM_ERROR) enumValue; + value->state.programError = (BACNET_PROGRAM_ERROR)enumValue; break; case RELIABILITY: - if (-1 == (section_length = - decode_enumerated(&apdu[len], len_value_type, - &enumValue))) { + if (-1 == (section_length = decode_enumerated( + &apdu[len], len_value_type, &enumValue))) { return -1; } - value->state.reliability = (BACNET_RELIABILITY) enumValue; + value->state.reliability = (BACNET_RELIABILITY)enumValue; break; case STATE: - if (-1 == (section_length = - decode_enumerated(&apdu[len], len_value_type, - &enumValue))) { + if (-1 == (section_length = decode_enumerated( + &apdu[len], len_value_type, &enumValue))) { return -1; } - value->state.state = (BACNET_EVENT_STATE) enumValue; + value->state.state = (BACNET_EVENT_STATE)enumValue; break; case SYSTEM_STATUS: - if (-1 == (section_length = - decode_enumerated(&apdu[len], len_value_type, - &enumValue))) { + if (-1 == (section_length = decode_enumerated( + &apdu[len], len_value_type, &enumValue))) { return -1; } - value->state.systemStatus = (BACNET_DEVICE_STATUS) enumValue; + value->state.systemStatus = (BACNET_DEVICE_STATUS)enumValue; break; case UNITS: - if (-1 == (section_length = - decode_enumerated(&apdu[len], len_value_type, - &enumValue))) { + if (-1 == (section_length = decode_enumerated( + &apdu[len], len_value_type, &enumValue))) { return -1; } - value->state.units = (BACNET_ENGINEERING_UNITS) enumValue; + value->state.units = (BACNET_ENGINEERING_UNITS)enumValue; break; case UNSIGNED_VALUE: if (-1 == (section_length = - decode_unsigned(&apdu[len], len_value_type, - &value->state.unsignedValue))) { + decode_unsigned(&apdu[len], len_value_type, + &value->state.unsignedValue))) { return -1; } break; case LIFE_SAFETY_MODE: - if (-1 == (section_length = - decode_enumerated(&apdu[len], len_value_type, - &enumValue))) { + if (-1 == (section_length = decode_enumerated( + &apdu[len], len_value_type, &enumValue))) { return -1; } - value->state.lifeSafetyMode = (BACNET_LIFE_SAFETY_MODE) enumValue; + value->state.lifeSafetyMode = (BACNET_LIFE_SAFETY_MODE)enumValue; break; case LIFE_SAFETY_STATE: - if (-1 == (section_length = - decode_enumerated(&apdu[len], len_value_type, - &enumValue))) { + if (-1 == (section_length = decode_enumerated( + &apdu[len], len_value_type, &enumValue))) { return -1; } - value->state.lifeSafetyState = - (BACNET_LIFE_SAFETY_STATE) enumValue; + value->state.lifeSafetyState = (BACNET_LIFE_SAFETY_STATE)enumValue; break; default: @@ -187,10 +172,8 @@ int bacapp_decode_property_state( return len; } -int bacapp_decode_context_property_state( - uint8_t * apdu, - uint8_t tag_number, - BACNET_PROPERTY_STATE * value) +int bacapp_decode_context_property_state(uint8_t *apdu, uint8_t tag_number, + BACNET_PROPERTY_STATE *value) { int len = 0; int section_length; @@ -215,59 +198,49 @@ int bacapp_decode_context_property_state( return len; } -int bacapp_encode_property_state( - uint8_t * apdu, - BACNET_PROPERTY_STATE * value) +int bacapp_encode_property_state(uint8_t *apdu, BACNET_PROPERTY_STATE *value) { - int len = 0; /* length of each encoding */ + int len = 0; /* length of each encoding */ if (value && apdu) { switch (value->tag) { case BOOLEAN_VALUE: - len = - encode_context_boolean(&apdu[0], 0, - value->state.booleanValue); + len = encode_context_boolean(&apdu[0], 0, + value->state.booleanValue); break; case BINARY_VALUE: - len = - encode_context_enumerated(&apdu[0], 1, - value->state.binaryValue); + len = encode_context_enumerated(&apdu[0], 1, + value->state.binaryValue); break; case EVENT_TYPE: - len = - encode_context_enumerated(&apdu[0], 2, - value->state.eventType); + len = encode_context_enumerated(&apdu[0], 2, + value->state.eventType); break; case POLARITY: - len = - encode_context_enumerated(&apdu[0], 3, - value->state.polarity); + len = encode_context_enumerated(&apdu[0], 3, + value->state.polarity); break; case PROGRAM_CHANGE: - len = - encode_context_enumerated(&apdu[0], 4, - value->state.programChange); + len = encode_context_enumerated(&apdu[0], 4, + value->state.programChange); break; case PROGRAM_STATE: - len = - encode_context_enumerated(&apdu[0], 5, - value->state.programState); + len = encode_context_enumerated(&apdu[0], 5, + value->state.programState); break; case REASON_FOR_HALT: - len = - encode_context_enumerated(&apdu[0], 6, - value->state.programError); + len = encode_context_enumerated(&apdu[0], 6, + value->state.programError); break; case RELIABILITY: - len = - encode_context_enumerated(&apdu[0], 7, - value->state.reliability); + len = encode_context_enumerated(&apdu[0], 7, + value->state.reliability); break; case STATE: @@ -276,33 +249,28 @@ int bacapp_encode_property_state( break; case SYSTEM_STATUS: - len = - encode_context_enumerated(&apdu[0], 9, - value->state.systemStatus); + len = encode_context_enumerated(&apdu[0], 9, + value->state.systemStatus); break; case UNITS: len = - encode_context_enumerated(&apdu[0], 10, - value->state.units); + encode_context_enumerated(&apdu[0], 10, value->state.units); break; case UNSIGNED_VALUE: - len = - encode_context_unsigned(&apdu[0], 11, - value->state.unsignedValue); + len = encode_context_unsigned(&apdu[0], 11, + value->state.unsignedValue); break; case LIFE_SAFETY_MODE: - len = - encode_context_enumerated(&apdu[0], 12, - value->state.lifeSafetyMode); + len = encode_context_enumerated(&apdu[0], 12, + value->state.lifeSafetyMode); break; case LIFE_SAFETY_STATE: - len = - encode_context_enumerated(&apdu[0], 13, - value->state.lifeSafetyState); + len = encode_context_enumerated(&apdu[0], 13, + value->state.lifeSafetyState); break; default: @@ -314,10 +282,9 @@ int bacapp_encode_property_state( } #ifdef TEST -#include /* for memset */ +#include /* for memset */ -void testPropStates( - Test * pTest) +void testPropStates(Test *pTest) { BACNET_PROPERTY_STATE inData; BACNET_PROPERTY_STATE outData; @@ -338,9 +305,9 @@ void testPropStates( ct_test(pTest, inData.tag == outData.tag); ct_test(pTest, inData.state.booleanValue == outData.state.booleanValue); - /**************** - ***************** - ****************/ + /**************** + ***************** + ****************/ inData.tag = BINARY_VALUE; inData.state.binaryValue = BINARY_ACTIVE; @@ -354,9 +321,9 @@ void testPropStates( ct_test(pTest, inData.tag == outData.tag); ct_test(pTest, inData.state.binaryValue == outData.state.binaryValue); - /**************** - ***************** - ****************/ + /**************** + ***************** + ****************/ inData.tag = EVENT_TYPE; inData.state.eventType = EVENT_BUFFER_READY; @@ -370,9 +337,9 @@ void testPropStates( ct_test(pTest, inData.tag == outData.tag); ct_test(pTest, inData.state.eventType == outData.state.eventType); - /**************** - ***************** - ****************/ + /**************** + ***************** + ****************/ inData.tag = POLARITY; inData.state.polarity = POLARITY_REVERSE; @@ -386,9 +353,9 @@ void testPropStates( ct_test(pTest, inData.tag == outData.tag); ct_test(pTest, inData.state.polarity == outData.state.polarity); - /**************** - ***************** - ****************/ + /**************** + ***************** + ****************/ inData.tag = PROGRAM_CHANGE; inData.state.programChange = PROGRAM_REQUEST_RESTART; @@ -402,9 +369,9 @@ void testPropStates( ct_test(pTest, inData.tag == outData.tag); ct_test(pTest, inData.state.programChange == outData.state.programChange); - /**************** - ***************** - ****************/ + /**************** + ***************** + ****************/ inData.tag = UNSIGNED_VALUE; inData.state.unsignedValue = 0xdeadbeef; @@ -417,13 +384,11 @@ void testPropStates( ct_test(pTest, outLen == inLen); ct_test(pTest, inData.tag == outData.tag); ct_test(pTest, inData.state.unsignedValue == outData.state.unsignedValue); - } #ifdef TEST_PROP_STATES #include -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -435,7 +400,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/src/bacreal.c b/src/bacreal.c index 87cd2006..17df92ee 100644 --- a/src/bacreal.c +++ b/src/bacreal.c @@ -52,9 +52,7 @@ /* from clause 20.2.6 Encoding of a Real Number Value */ /* returns the number of apdu bytes consumed */ -int decode_real( - uint8_t * apdu, - float *real_value) +int decode_real(uint8_t *apdu, float *real_value) { union { uint8_t byte[4]; @@ -79,30 +77,23 @@ int decode_real( return 4; } -int decode_real_safe( - uint8_t * apdu, - uint32_t len_value, - float *real_value) +int decode_real_safe(uint8_t *apdu, uint32_t len_value, float *real_value) { if (len_value != 4) { *real_value = 0.0f; - return (int) len_value; + return (int)len_value; } else { return decode_real(apdu, real_value); } } -int decode_context_real( - uint8_t * apdu, - uint8_t tag_number, - float *real_value) +int decode_context_real(uint8_t *apdu, uint8_t tag_number, float *real_value) { uint32_t len_value; int len = 0; if (decode_is_context_tag(&apdu[len], tag_number)) { - len += - decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); len += decode_real(&apdu[len], real_value); } else { len = -1; @@ -112,9 +103,7 @@ int decode_context_real( /* from clause 20.2.6 Encoding of a Real Number Value */ /* returns the number of apdu bytes consumed */ -int encode_bacnet_real( - float value, - uint8_t * apdu) +int encode_bacnet_real(float value, uint8_t *apdu) { union { uint8_t byte[4]; @@ -142,9 +131,7 @@ int encode_bacnet_real( /* from clause 20.2.7 Encoding of a Double Precision Real Number Value */ /* returns the number of apdu bytes consumed */ -int decode_double( - uint8_t * apdu, - double *double_value) +int decode_double(uint8_t *apdu, double *double_value) { union { uint8_t byte[8]; @@ -177,14 +164,11 @@ int decode_double( return 8; } -int decode_double_safe( - uint8_t * apdu, - uint32_t len_value, - double *double_value) +int decode_double_safe(uint8_t *apdu, uint32_t len_value, double *double_value) { if (len_value != 8) { *double_value = 0.0; - return (int) len_value; + return (int)len_value; } else { return decode_double(apdu, double_value); } @@ -192,9 +176,7 @@ int decode_double_safe( /* from clause 20.2.7 Encoding of a Double Precision Real Number Value */ /* returns the number of apdu bytes consumed */ -int encode_bacnet_double( - double value, - uint8_t * apdu) +int encode_bacnet_double(double value, uint8_t *apdu) { union { uint8_t byte[8]; @@ -226,17 +208,14 @@ int encode_bacnet_double( return 8; } -int decode_context_double( - uint8_t * apdu, - uint8_t tag_number, - double *double_value) +int decode_context_double(uint8_t *apdu, uint8_t tag_number, + double *double_value) { uint32_t len_value; int len = 0; if (decode_is_context_tag(&apdu[len], tag_number)) { - len += - decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); len += decode_double(&apdu[len], double_value); } else { len = -1; @@ -252,11 +231,10 @@ int decode_context_double( #include #include "ctest.h" -void testBACreal( - Test * pTest) +void testBACreal(Test *pTest) { float real_value = 3.14159F, test_real_value = 0.0; - uint8_t apdu[MAX_APDU] = { 0 }; + uint8_t apdu[MAX_APDU] = {0}; int len = 0, test_len = 0; len = encode_bacnet_real(real_value, &apdu[0]); @@ -266,11 +244,10 @@ void testBACreal( ct_test(pTest, test_real_value == real_value); } -void testBACdouble( - Test * pTest) +void testBACdouble(Test *pTest) { double double_value = 3.1415927, test_double_value = 0.0; - uint8_t apdu[MAX_APDU] = { 0 }; + uint8_t apdu[MAX_APDU] = {0}; int len = 0, test_len = 0; len = encode_bacnet_double(double_value, &apdu[0]); @@ -281,8 +258,7 @@ void testBACdouble( } #ifdef TEST_BACNET_REAL -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -297,7 +273,7 @@ int main( /* configure output */ ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/src/bacsec.c b/src/bacsec.c index b9e33857..d8565d6b 100644 --- a/src/bacsec.c +++ b/src/bacsec.c @@ -1,27 +1,27 @@ /************************************************************************** -* -* Copyright (C) 2015 Nikola Jelic -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2015 Nikola Jelic + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include #include @@ -30,17 +30,16 @@ BACNET_KEY_IDENTIFIER_ALGORITHM key_algorithm(uint16_t id) { - return (BACNET_KEY_IDENTIFIER_ALGORITHM) ((id >> 8) & 0xFF); + return (BACNET_KEY_IDENTIFIER_ALGORITHM)((id >> 8) & 0xFF); } BACNET_KEY_IDENTIFIER_KEY_NUMBER key_number(uint16_t id) { - return (BACNET_KEY_IDENTIFIER_KEY_NUMBER) (id & 0xFF); + return (BACNET_KEY_IDENTIFIER_KEY_NUMBER)(id & 0xFF); } -int encode_security_wrapper(int bytes_before, - uint8_t * apdu, - BACNET_SECURITY_WRAPPER * wrapper) +int encode_security_wrapper(int bytes_before, uint8_t* apdu, + BACNET_SECURITY_WRAPPER* wrapper) { int curr = 0; int enc_begin = 0; @@ -115,19 +114,17 @@ int encode_security_wrapper(int bytes_before, apdu[curr++] = wrapper->user_role; if ((wrapper->authentication_mechanism >= 1) && (wrapper->authentication_mechanism <= 199)) { - curr += - encode_unsigned16(&apdu[curr], - wrapper->authentication_data_length + 5); + curr += encode_unsigned16(&apdu[curr], + wrapper->authentication_data_length + 5); memcpy(&apdu[curr], wrapper->authentication_data, - wrapper->authentication_data_length); + wrapper->authentication_data_length); curr += wrapper->authentication_data_length; } else if (wrapper->authentication_mechanism >= 200) { - curr += - encode_unsigned16(&apdu[curr], - wrapper->authentication_data_length + 7); + curr += encode_unsigned16(&apdu[curr], + wrapper->authentication_data_length + 7); curr += encode_unsigned16(&apdu[curr], wrapper->vendor_id); memcpy(&apdu[curr], wrapper->authentication_data, - wrapper->authentication_data_length); + wrapper->authentication_data_length); curr += wrapper->authentication_data_length; } } @@ -135,14 +132,14 @@ int encode_security_wrapper(int bytes_before, curr += wrapper->service_data_len; /* signature calculation */ key_sign_msg(&key, &apdu[-bytes_before], (uint32_t)(bytes_before + curr), - wrapper->signature); + wrapper->signature); /* padding and encryption */ if (wrapper->encrypted_flag) { /* set encryption flag, signing is done */ apdu[0] |= 1 << 6; /* handle padding */ key_set_padding(&key, curr - enc_begin, &wrapper->padding_len, - wrapper->padding); + wrapper->padding); if (wrapper->padding_len > 2) { memcpy(&apdu[curr], wrapper->padding, wrapper->padding_len - 2); curr += wrapper->padding_len - 2; @@ -150,7 +147,7 @@ int encode_security_wrapper(int bytes_before, curr += encode_unsigned16(&apdu[curr], wrapper->padding_len); /* encryption */ key_encrypt_msg(&key, &apdu[enc_begin], (uint32_t)(curr - enc_begin), - wrapper->signature); + wrapper->signature); } memcpy(&apdu[curr], wrapper->signature, SIGNATURE_LEN); curr += SIGNATURE_LEN; @@ -158,8 +155,7 @@ int encode_security_wrapper(int bytes_before, return curr; } -int encode_challenge_request(uint8_t * apdu, - BACNET_CHALLENGE_REQUEST * bc_req) +int encode_challenge_request(uint8_t* apdu, BACNET_CHALLENGE_REQUEST* bc_req) { int curr = 0; @@ -170,8 +166,7 @@ int encode_challenge_request(uint8_t * apdu, return curr; } -int encode_security_payload(uint8_t * apdu, - BACNET_SECURITY_PAYLOAD * payload) +int encode_security_payload(uint8_t* apdu, BACNET_SECURITY_PAYLOAD* payload) { encode_unsigned16(&apdu[0], payload->payload_length); memcpy(&apdu[2], payload->payload, payload->payload_length); @@ -179,8 +174,7 @@ int encode_security_payload(uint8_t * apdu, return (int)(2 + payload->payload_length); } -int encode_security_response(uint8_t * apdu, - BACNET_SECURITY_RESPONSE * resp) +int encode_security_response(uint8_t* apdu, BACNET_SECURITY_RESPONSE* resp) { int curr = 0; int i; @@ -188,37 +182,33 @@ int encode_security_response(uint8_t * apdu, apdu[curr++] = resp->response_code; curr += encode_unsigned32(&apdu[curr], resp->orig_message_id); curr += encode_unsigned32(&apdu[curr], resp->orig_timestamp); - switch ((BACNET_SECURITY_RESPONSE_CODE) resp->response_code) { + switch ((BACNET_SECURITY_RESPONSE_CODE)resp->response_code) { case SEC_RESP_BAD_TIMESTAMP: - curr += - encode_unsigned32(&apdu[curr], - resp->response.bad_timestamp.expected_timestamp); + curr += encode_unsigned32( + &apdu[curr], resp->response.bad_timestamp.expected_timestamp); break; case SEC_RESP_CANNOT_USE_KEY: - curr += - encode_unsigned16(&apdu[curr], - resp->response.cannot_use_key.key); + curr += encode_unsigned16(&apdu[curr], + resp->response.cannot_use_key.key); break; case SEC_RESP_INCORRECT_KEY: apdu[curr++] = resp->response.incorrect_key.number_of_keys; - for (i = 0; i < (int)resp->response.incorrect_key.number_of_keys; i++) { - curr += - encode_unsigned16(&apdu[curr], - resp->response.incorrect_key.keys[i]); + for (i = 0; i < (int)resp->response.incorrect_key.number_of_keys; + i++) { + curr += encode_unsigned16(&apdu[curr], + resp->response.incorrect_key.keys[i]); } break; case SEC_RESP_UNKNOWN_AUTHENTICATION_TYPE: - apdu[curr++] = - resp->response.unknown_authentication_type. - original_authentication_type; - curr += - encode_unsigned16(&apdu[curr], + apdu[curr++] = resp->response.unknown_authentication_type + .original_authentication_type; + curr += encode_unsigned16( + &apdu[curr], resp->response.unknown_authentication_type.vendor_id); break; case SEC_RESP_UNKNOWN_KEY: - curr += - encode_unsigned16(&apdu[curr], - resp->response.unknown_key.original_key); + curr += encode_unsigned16(&apdu[curr], + resp->response.unknown_key.original_key); break; case SEC_RESP_UNKNOWN_KEY_REVISION: apdu[curr++] = @@ -228,9 +218,8 @@ int encode_security_response(uint8_t * apdu, apdu[curr++] = resp->response.too_many_keys.max_num_of_keys; break; case SEC_RESP_INVALID_KEY_DATA: - curr += - encode_unsigned16(&apdu[curr], - resp->response.invalid_key_data.key); + curr += encode_unsigned16(&apdu[curr], + resp->response.invalid_key_data.key); break; case SEC_RESP_SUCCESS: case SEC_RESP_ACCESS_DENIED: @@ -252,14 +241,13 @@ int encode_security_response(uint8_t * apdu, case SEC_RESP_UNKNOWN_SOURCE_MESSAGE: break; default: - return -1; /* unknown message type */ + return -1; /* unknown message type */ } return curr; } -int encode_request_key_update(uint8_t * apdu, - BACNET_REQUEST_KEY_UPDATE * req) +int encode_request_key_update(uint8_t* apdu, BACNET_REQUEST_KEY_UPDATE* req) { int curr = 0; @@ -274,8 +262,7 @@ int encode_request_key_update(uint8_t * apdu, return curr; } -int encode_key_entry(uint8_t * apdu, - BACNET_KEY_ENTRY * entry) +int encode_key_entry(uint8_t* apdu, BACNET_KEY_ENTRY* entry) { int curr = 0; @@ -287,8 +274,7 @@ int encode_key_entry(uint8_t * apdu, return curr; } -int encode_update_key_set(uint8_t * apdu, - BACNET_UPDATE_KEY_SET * key_set) +int encode_update_key_set(uint8_t* apdu, BACNET_UPDATE_KEY_SET* key_set) { int curr = 0; int i, res; @@ -321,10 +307,8 @@ int encode_update_key_set(uint8_t * apdu, curr++; if (key_set->set_rae[0]) { apdu[curr++] = key_set->set_key_revision[0]; - curr += - encode_unsigned32(&apdu[curr], key_set->set_activation_time[0]); - curr += - encode_unsigned32(&apdu[curr], key_set->set_expiration_time[0]); + curr += encode_unsigned32(&apdu[curr], key_set->set_activation_time[0]); + curr += encode_unsigned32(&apdu[curr], key_set->set_expiration_time[0]); } if (key_set->set_ck[0]) { apdu[curr++] = key_set->set_key_count[0]; @@ -341,10 +325,8 @@ int encode_update_key_set(uint8_t * apdu, } if (key_set->set_rae[1]) { apdu[curr++] = key_set->set_key_revision[1]; - curr += - encode_unsigned32(&apdu[curr], key_set->set_activation_time[1]); - curr += - encode_unsigned32(&apdu[curr], key_set->set_expiration_time[1]); + curr += encode_unsigned32(&apdu[curr], key_set->set_activation_time[1]); + curr += encode_unsigned32(&apdu[curr], key_set->set_expiration_time[1]); } if (key_set->set_ck[1]) { apdu[curr++] = key_set->set_key_count[1]; @@ -362,8 +344,8 @@ int encode_update_key_set(uint8_t * apdu, return curr; } -int encode_update_distribution_key(uint8_t * apdu, - BACNET_UPDATE_DISTRIBUTION_KEY * dist_key) +int encode_update_distribution_key(uint8_t* apdu, + BACNET_UPDATE_DISTRIBUTION_KEY* dist_key) { int curr = 0; int res; @@ -377,28 +359,26 @@ int encode_update_distribution_key(uint8_t * apdu, return curr + res; } -int encode_request_master_key(uint8_t * apdu, - BACNET_REQUEST_MASTER_KEY * req_master_key) +int encode_request_master_key(uint8_t* apdu, + BACNET_REQUEST_MASTER_KEY* req_master_key) { int curr = 0; apdu[curr++] = req_master_key->no_supported_algorithms; memcpy(&apdu[curr], req_master_key->es_algorithms, - req_master_key->no_supported_algorithms); + req_master_key->no_supported_algorithms); return (int)(curr + req_master_key->no_supported_algorithms); } -int encode_set_master_key(uint8_t * apdu, - BACNET_SET_MASTER_KEY * set_master_key) +int encode_set_master_key(uint8_t* apdu, BACNET_SET_MASTER_KEY* set_master_key) { return encode_key_entry(apdu, &set_master_key->key); } -int decode_security_wrapper_safe(int bytes_before, - uint8_t * apdu, - uint32_t apdu_len_remaining, - BACNET_SECURITY_WRAPPER * wrapper) +int decode_security_wrapper_safe(int bytes_before, uint8_t* apdu, + uint32_t apdu_len_remaining, + BACNET_SECURITY_WRAPPER* wrapper) { int curr = 0; int enc_begin = 0; @@ -424,7 +404,7 @@ int decode_security_wrapper_safe(int bytes_before, return -SEC_RESP_MALFORMED_MESSAGE; } /* remove encryption flag for signature validation */ - apdu[curr] &= ~((uint8_t) (1 << 6)); + apdu[curr] &= ~((uint8_t)(1 << 6)); curr++; /* key */ wrapper->key_revision = apdu[curr++]; @@ -447,13 +427,14 @@ int decode_security_wrapper_safe(int bytes_before, memcpy(wrapper->signature, &apdu[real_len], SIGNATURE_LEN); if (wrapper->encrypted_flag) { if (!key_decrypt_msg(&key, &apdu[enc_begin], - (uint32_t)(real_len - enc_begin), wrapper->signature)) { + (uint32_t)(real_len - enc_begin), + wrapper->signature)) { return -SEC_RESP_MALFORMED_MESSAGE; } curr += decode_unsigned16(&apdu[real_len - 2], &wrapper->padding_len); real_len -= wrapper->padding_len; memcpy(wrapper->padding, &apdu[wrapper->padding_len], - wrapper->padding_len - 2); + wrapper->padding_len - 2); } /* destination device instance */ curr += @@ -476,21 +457,19 @@ int decode_security_wrapper_safe(int bytes_before, wrapper->user_role = apdu[curr++]; if ((wrapper->authentication_mechanism >= 1) && (wrapper->authentication_mechanism <= 199)) { - curr += - decode_unsigned16(&apdu[curr], - &wrapper->authentication_data_length); + curr += decode_unsigned16(&apdu[curr], + &wrapper->authentication_data_length); wrapper->authentication_data_length -= 5; memcpy(wrapper->authentication_data, &apdu[curr], - wrapper->authentication_data_length); + wrapper->authentication_data_length); curr += wrapper->authentication_data_length; } else if (wrapper->authentication_mechanism >= 200) { - curr += - decode_unsigned16(&apdu[curr], - &wrapper->authentication_data_length); + curr += decode_unsigned16(&apdu[curr], + &wrapper->authentication_data_length); wrapper->authentication_data_length -= 7; curr += decode_unsigned16(&apdu[curr], &wrapper->vendor_id); memcpy(wrapper->authentication_data, &apdu[curr], - wrapper->authentication_data_length); + wrapper->authentication_data_length); curr += wrapper->authentication_data_length; } } @@ -498,16 +477,16 @@ int decode_security_wrapper_safe(int bytes_before, memcpy(wrapper->service_data, &apdu[curr], wrapper->service_data_len); curr += wrapper->service_data_len; if (!key_verify_sign_msg(&key, &apdu[-bytes_before], - (uint32_t)(bytes_before + real_len), wrapper->signature)) { + (uint32_t)(bytes_before + real_len), + wrapper->signature)) { return -SEC_RESP_BAD_SIGNATURE; } return curr; } -int decode_challenge_request_safe(uint8_t * apdu, - uint32_t apdu_len_remaining, - BACNET_CHALLENGE_REQUEST * bc_req) +int decode_challenge_request_safe(uint8_t* apdu, uint32_t apdu_len_remaining, + BACNET_CHALLENGE_REQUEST* bc_req) { int curr = 0; @@ -518,12 +497,11 @@ int decode_challenge_request_safe(uint8_t * apdu, curr += decode_unsigned32(&apdu[curr], &bc_req->orig_message_id); curr += decode_unsigned32(&apdu[curr], &bc_req->orig_timestamp); - return curr; /* always 9! */ + return curr; /* always 9! */ } -int decode_security_payload_safe(uint8_t * apdu, - uint32_t apdu_len_remaining, - BACNET_SECURITY_PAYLOAD * payload) +int decode_security_payload_safe(uint8_t* apdu, uint32_t apdu_len_remaining, + BACNET_SECURITY_PAYLOAD* payload) { if (apdu_len_remaining < 2) { return -1; @@ -536,9 +514,8 @@ int decode_security_payload_safe(uint8_t * apdu, return (int)(2 + payload->payload_length); } -int decode_security_response_safe(uint8_t * apdu, - uint32_t apdu_len_remaining, - BACNET_SECURITY_RESPONSE * resp) +int decode_security_response_safe(uint8_t* apdu, uint32_t apdu_len_remaining, + BACNET_SECURITY_RESPONSE* resp) { int curr = 0; int i; @@ -549,22 +526,20 @@ int decode_security_response_safe(uint8_t * apdu, resp->response_code = apdu[curr++]; curr += decode_unsigned32(&apdu[curr], &resp->orig_message_id); curr += decode_unsigned32(&apdu[curr], &resp->orig_timestamp); - switch ((BACNET_SECURITY_RESPONSE_CODE) resp->response_code) { + switch ((BACNET_SECURITY_RESPONSE_CODE)resp->response_code) { case SEC_RESP_BAD_TIMESTAMP: if (apdu_len_remaining < 13) { return -1; } - curr += - decode_unsigned32(&apdu[curr], - &resp->response.bad_timestamp.expected_timestamp); + curr += decode_unsigned32( + &apdu[curr], &resp->response.bad_timestamp.expected_timestamp); break; case SEC_RESP_CANNOT_USE_KEY: if (apdu_len_remaining < 11) { return -1; } - curr += - decode_unsigned16(&apdu[curr], - &resp->response.cannot_use_key.key); + curr += decode_unsigned16(&apdu[curr], + &resp->response.cannot_use_key.key); break; case SEC_RESP_INCORRECT_KEY: if (apdu_len_remaining < 10) { @@ -575,23 +550,23 @@ int decode_security_response_safe(uint8_t * apdu, resp->response.incorrect_key.number_of_keys * 2) { return -1; } - for (i = 0; i < (int)resp->response.incorrect_key.number_of_keys; i++) { - curr += - decode_unsigned16(&apdu[curr], - &resp->response.incorrect_key.keys[i]); + for (i = 0; i < (int)resp->response.incorrect_key.number_of_keys; + i++) { + curr += decode_unsigned16( + &apdu[curr], &resp->response.incorrect_key.keys[i]); } break; case SEC_RESP_UNKNOWN_AUTHENTICATION_TYPE: if (apdu_len_remaining < 12) { return -1; } - resp->response.unknown_authentication_type. - original_authentication_type = apdu[curr++]; - curr += - decode_unsigned16(&apdu[curr], + resp->response.unknown_authentication_type + .original_authentication_type = apdu[curr++]; + curr += decode_unsigned16( + &apdu[curr], &resp->response.unknown_authentication_type.vendor_id); - if (resp->response.unknown_authentication_type. - original_authentication_type < 200 && + if (resp->response.unknown_authentication_type + .original_authentication_type < 200 && resp->response.unknown_authentication_type.vendor_id != 0) { return -1; } @@ -600,9 +575,8 @@ int decode_security_response_safe(uint8_t * apdu, if (apdu_len_remaining < 11) { return -1; } - curr += - decode_unsigned16(&apdu[curr], - &resp->response.unknown_key.original_key); + curr += decode_unsigned16(&apdu[curr], + &resp->response.unknown_key.original_key); break; case SEC_RESP_UNKNOWN_KEY_REVISION: if (apdu_len_remaining < 10) { @@ -621,9 +595,8 @@ int decode_security_response_safe(uint8_t * apdu, if (apdu_len_remaining < 11) { return -1; } - curr += - decode_unsigned16(&apdu[curr], - &resp->response.invalid_key_data.key); + curr += decode_unsigned16(&apdu[curr], + &resp->response.invalid_key_data.key); break; case SEC_RESP_SUCCESS: case SEC_RESP_ACCESS_DENIED: @@ -645,14 +618,13 @@ int decode_security_response_safe(uint8_t * apdu, case SEC_RESP_UNKNOWN_SOURCE_MESSAGE: break; default: - return -1; /* unknown message type */ + return -1; /* unknown message type */ } return curr; } -int decode_request_key_update_safe(uint8_t * apdu, - uint32_t apdu_len_remaining, - BACNET_REQUEST_KEY_UPDATE * req) +int decode_request_key_update_safe(uint8_t* apdu, uint32_t apdu_len_remaining, + BACNET_REQUEST_KEY_UPDATE* req) { int curr = 0; @@ -670,9 +642,8 @@ int decode_request_key_update_safe(uint8_t * apdu, return curr; } -int decode_key_entry_safe(uint8_t * apdu, - uint32_t apdu_len_remaining, - BACNET_KEY_ENTRY * entry) +int decode_key_entry_safe(uint8_t* apdu, uint32_t apdu_len_remaining, + BACNET_KEY_ENTRY* entry) { int curr = 0; @@ -691,9 +662,8 @@ int decode_key_entry_safe(uint8_t * apdu, return curr; } -int decode_update_key_set_safe(uint8_t * apdu, - uint32_t apdu_len_remaining, - BACNET_UPDATE_KEY_SET * key_set) +int decode_update_key_set_safe(uint8_t* apdu, uint32_t apdu_len_remaining, + BACNET_UPDATE_KEY_SET* key_set) { int curr = 0; int i, res; @@ -745,9 +715,8 @@ int decode_update_key_set_safe(uint8_t * apdu, return -1; } for (i = 0; i < (int)key_set->set_key_count[0]; i++) { - res = - decode_key_entry_safe(apdu + curr, apdu_len_remaining - curr, - &key_set->set_keys[0][i]); + res = decode_key_entry_safe(apdu + curr, apdu_len_remaining - curr, + &key_set->set_keys[0][i]); if (res < 0) { return -1; } @@ -773,9 +742,8 @@ int decode_update_key_set_safe(uint8_t * apdu, return -1; } for (i = 0; i < (int)key_set->set_key_count[1]; i++) { - res = - decode_key_entry_safe(apdu + curr, apdu_len_remaining - curr, - &key_set->set_keys[1][i]); + res = decode_key_entry_safe(apdu + curr, apdu_len_remaining - curr, + &key_set->set_keys[1][i]); if (res < 0) { return -1; } @@ -786,9 +754,9 @@ int decode_update_key_set_safe(uint8_t * apdu, return curr; } -int decode_update_distribution_key_safe(uint8_t * apdu, - uint32_t apdu_len_remaining, - BACNET_UPDATE_DISTRIBUTION_KEY * dist_key) +int decode_update_distribution_key_safe( + uint8_t* apdu, uint32_t apdu_len_remaining, + BACNET_UPDATE_DISTRIBUTION_KEY* dist_key) { int curr = 0; int res; @@ -796,9 +764,8 @@ int decode_update_distribution_key_safe(uint8_t * apdu, return -1; } dist_key->key_revision = apdu[curr++]; - res = - decode_key_entry_safe(&apdu[curr], apdu_len_remaining - curr, - &dist_key->key); + res = decode_key_entry_safe(&apdu[curr], apdu_len_remaining - curr, + &dist_key->key); if (res < 0) { return -1; } @@ -806,9 +773,8 @@ int decode_update_distribution_key_safe(uint8_t * apdu, return curr + res; } -int decode_request_master_key_safe(uint8_t * apdu, - uint32_t apdu_len_remaining, - BACNET_REQUEST_MASTER_KEY * req_master_key) +int decode_request_master_key_safe(uint8_t* apdu, uint32_t apdu_len_remaining, + BACNET_REQUEST_MASTER_KEY* req_master_key) { uint32_t curr = 0; @@ -820,15 +786,14 @@ int decode_request_master_key_safe(uint8_t * apdu, return -1; } memcpy(req_master_key->es_algorithms, &apdu[curr], - req_master_key->no_supported_algorithms); + req_master_key->no_supported_algorithms); return (int)(curr + req_master_key->no_supported_algorithms); } -int decode_set_master_key_safe(uint8_t * apdu, - uint32_t apdu_len_remaining, - BACNET_SET_MASTER_KEY * set_master_key) +int decode_set_master_key_safe(uint8_t* apdu, uint32_t apdu_len_remaining, + BACNET_SET_MASTER_KEY* set_master_key) { return decode_key_entry_safe(apdu, apdu_len_remaining, - &set_master_key->key); + &set_master_key->key); } diff --git a/src/bacstr.c b/src/bacstr.c index e922b4c7..e5ed0e07 100644 --- a/src/bacstr.c +++ b/src/bacstr.c @@ -34,19 +34,18 @@ #include #include -#include /* for strlen */ +#include /* for strlen */ #include "config.h" #include "bacstr.h" #include "bits.h" #if PRINT_ENABLED -#include /* for strtol */ -#include /* for isalnum */ +#include /* for strtol */ +#include /* for isalnum */ #endif /** @file bacstr.c Manipulate Bit/Char/Octet Strings */ -void bitstring_init( - BACNET_BIT_STRING * bit_string) +void bitstring_init(BACNET_BIT_STRING *bit_string) { int i; @@ -56,10 +55,8 @@ void bitstring_init( } } -void bitstring_set_bit( - BACNET_BIT_STRING * bit_string, - uint8_t bit_number, - bool value) +void bitstring_set_bit(BACNET_BIT_STRING *bit_string, uint8_t bit_number, + bool value) { uint8_t byte_number = bit_number / 8; uint8_t bit_mask = 1; @@ -78,9 +75,7 @@ void bitstring_set_bit( } } -bool bitstring_bit( - BACNET_BIT_STRING * bit_string, - uint8_t bit_number) +bool bitstring_bit(BACNET_BIT_STRING *bit_string, uint8_t bit_number) { bool value = false; uint8_t byte_number = bit_number / 8; @@ -96,17 +91,15 @@ bool bitstring_bit( return value; } -uint8_t bitstring_bits_used( - BACNET_BIT_STRING * bit_string) +uint8_t bitstring_bits_used(BACNET_BIT_STRING *bit_string) { return bit_string->bits_used; } /* returns the number of bytes that a bit string is using */ -uint8_t bitstring_bytes_used( - BACNET_BIT_STRING * bit_string) +uint8_t bitstring_bytes_used(BACNET_BIT_STRING *bit_string) { - uint8_t len = 0; /* return value */ + uint8_t len = 0; /* return value */ uint8_t used_bytes = 0; uint8_t last_bit = 0; @@ -121,9 +114,7 @@ uint8_t bitstring_bytes_used( return len; } -uint8_t bitstring_octet( - BACNET_BIT_STRING * bit_string, - uint8_t octet_index) +uint8_t bitstring_octet(BACNET_BIT_STRING *bit_string, uint8_t octet_index) { uint8_t octet = 0; @@ -136,10 +127,8 @@ uint8_t bitstring_octet( return octet; } -bool bitstring_set_octet( - BACNET_BIT_STRING * bit_string, - uint8_t index, - uint8_t octet) +bool bitstring_set_octet(BACNET_BIT_STRING *bit_string, uint8_t index, + uint8_t octet) { bool status = false; @@ -153,10 +142,8 @@ bool bitstring_set_octet( return status; } -bool bitstring_set_bits_used( - BACNET_BIT_STRING * bit_string, - uint8_t bytes_used, - uint8_t unused_bits) +bool bitstring_set_bits_used(BACNET_BIT_STRING *bit_string, uint8_t bytes_used, + uint8_t unused_bits) { bool status = false; @@ -170,8 +157,7 @@ bool bitstring_set_bits_used( return status; } -uint8_t bitstring_bits_capacity( - BACNET_BIT_STRING * bit_string) +uint8_t bitstring_bits_capacity(BACNET_BIT_STRING *bit_string) { if (bit_string) { return (MAX_BITSTRING_BYTES * 8); @@ -180,9 +166,7 @@ uint8_t bitstring_bits_capacity( } } -bool bitstring_copy( - BACNET_BIT_STRING * dest, - BACNET_BIT_STRING * src) +bool bitstring_copy(BACNET_BIT_STRING *dest, BACNET_BIT_STRING *src) { unsigned i; bool status = false; @@ -199,18 +183,17 @@ bool bitstring_copy( } /* returns true if the same length and contents */ -bool bitstring_same( - BACNET_BIT_STRING * bitstring1, - BACNET_BIT_STRING * bitstring2) +bool bitstring_same(BACNET_BIT_STRING *bitstring1, + BACNET_BIT_STRING *bitstring2) { - int i = 0; /* loop counter */ + int i = 0; /* loop counter */ int bytes_used = 0; uint8_t compare_mask = 0; if (bitstring1 && bitstring2) { 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++) { @@ -234,12 +217,10 @@ bool bitstring_same( /* converts an null terminated ASCII string to an bitstring. Expects "1,0,1,0,1,1" or "101011" as the bits returns true if successfully converted and fits; false if too long */ -bool bitstring_init_ascii( - BACNET_BIT_STRING * bit_string, - const char *ascii) +bool bitstring_init_ascii(BACNET_BIT_STRING *bit_string, const char *ascii) { - bool status = false; /* return value */ - unsigned index = 0; /* offset into buffer */ + bool status = false; /* return value */ + unsigned index = 0; /* offset into buffer */ uint8_t bit_number = 0; if (bit_string) { @@ -280,14 +261,11 @@ bool bitstring_init_ascii( #define CHARACTER_STRING_CAPACITY (MAX_CHARACTER_STRING_BYTES - 1) /* returns false if the string exceeds capacity initialize by using value=NULL */ -bool characterstring_init( - BACNET_CHARACTER_STRING * char_string, - uint8_t encoding, - const char *value, - size_t length) +bool characterstring_init(BACNET_CHARACTER_STRING *char_string, + uint8_t encoding, const char *value, size_t length) { - bool status = false; /* return value */ - size_t i; /* counter */ + bool status = false; /* return value */ + size_t i; /* counter */ if (char_string) { char_string->length = 0; @@ -316,28 +294,25 @@ bool characterstring_init( return status; } -bool characterstring_init_ansi( - BACNET_CHARACTER_STRING * char_string, - const char *value) +bool characterstring_init_ansi(BACNET_CHARACTER_STRING *char_string, + const char *value) { return characterstring_init(char_string, CHARACTER_ANSI_X34, value, - value ? strlen(value) : 0); + value ? strlen(value) : 0); } -bool characterstring_copy( - BACNET_CHARACTER_STRING * dest, - BACNET_CHARACTER_STRING * src) +bool characterstring_copy(BACNET_CHARACTER_STRING *dest, + BACNET_CHARACTER_STRING *src) { return characterstring_init(dest, characterstring_encoding(src), - characterstring_value(src), characterstring_length(src)); + characterstring_value(src), + characterstring_length(src)); } -bool characterstring_ansi_copy( - char *dest, - size_t dest_max_len, - BACNET_CHARACTER_STRING * src) +bool characterstring_ansi_copy(char *dest, size_t dest_max_len, + BACNET_CHARACTER_STRING *src) { - size_t i; /* counter */ + size_t i; /* counter */ if (dest && src && (src->encoding == CHARACTER_ANSI_X34) && (src->length < dest_max_len)) { @@ -355,15 +330,15 @@ bool characterstring_ansi_copy( } /* returns true if the character encoding and string contents are the same */ -bool characterstring_same( - BACNET_CHARACTER_STRING * dest, - BACNET_CHARACTER_STRING * src) +bool characterstring_same(BACNET_CHARACTER_STRING *dest, + BACNET_CHARACTER_STRING *src) { - size_t i; /* counter */ + size_t i; /* counter */ bool same_status = false; if (src && dest) { - if ((src->length == dest->length) && (src->encoding == dest->encoding)) { + if ((src->length == dest->length) && + (src->encoding == dest->encoding)) { same_status = true; for (i = 0; (i < src->length) && same_status; i++) { if (src->value[i] != dest->value[i]) { @@ -384,11 +359,9 @@ bool characterstring_same( return same_status; } -bool characterstring_ansi_same( - BACNET_CHARACTER_STRING * dest, - const char *src) +bool characterstring_ansi_same(BACNET_CHARACTER_STRING *dest, const char *src) { - size_t i; /* counter */ + size_t i; /* counter */ bool same_status = false; if (src && dest) { @@ -417,13 +390,11 @@ bool characterstring_ansi_same( } /* returns false if the string exceeds capacity */ -bool characterstring_append( - BACNET_CHARACTER_STRING * char_string, - const char *value, - size_t length) +bool characterstring_append(BACNET_CHARACTER_STRING *char_string, + const char *value, size_t length) { - size_t i; /* counter */ - bool status = false; /* return value */ + size_t i; /* counter */ + bool status = false; /* return value */ if (char_string) { if ((length + char_string->length) <= CHARACTER_STRING_CAPACITY) { @@ -441,11 +412,10 @@ bool characterstring_append( /* This function sets a new length without changing the value. If length exceeds capacity, no modification happens and function returns false. */ -bool characterstring_truncate( - BACNET_CHARACTER_STRING * char_string, - size_t length) +bool characterstring_truncate(BACNET_CHARACTER_STRING *char_string, + size_t length) { - bool status = false; /* return value */ + bool status = false; /* return value */ if (char_string) { if (length <= CHARACTER_STRING_CAPACITY) { @@ -458,8 +428,7 @@ bool characterstring_truncate( } /* Returns the value. */ -char *characterstring_value( - BACNET_CHARACTER_STRING * char_string) +char *characterstring_value(BACNET_CHARACTER_STRING *char_string) { char *value = NULL; @@ -471,8 +440,7 @@ char *characterstring_value( } /* returns the length. */ -size_t characterstring_length( - BACNET_CHARACTER_STRING * char_string) +size_t characterstring_length(BACNET_CHARACTER_STRING *char_string) { size_t length = 0; @@ -484,8 +452,7 @@ size_t characterstring_length( return length; } -size_t characterstring_capacity( - BACNET_CHARACTER_STRING * char_string) +size_t characterstring_capacity(BACNET_CHARACTER_STRING *char_string) { size_t length = 0; @@ -497,8 +464,7 @@ size_t characterstring_capacity( } /* returns the encoding. */ -uint8_t characterstring_encoding( - BACNET_CHARACTER_STRING * char_string) +uint8_t characterstring_encoding(BACNET_CHARACTER_STRING *char_string) { uint8_t encoding = 0; @@ -510,9 +476,8 @@ uint8_t characterstring_encoding( } /* returns the encoding. */ -bool characterstring_set_encoding( - BACNET_CHARACTER_STRING * char_string, - uint8_t encoding) +bool characterstring_set_encoding(BACNET_CHARACTER_STRING *char_string, + uint8_t encoding) { bool status = false; @@ -535,11 +500,10 @@ punctuation marks, and mathematical symbols. The exact set depends upon the character set being used. In ANSI X3.4 the printable characters are represented by single octets in the range X'20' - X'7E'.*/ -bool characterstring_printable( - BACNET_CHARACTER_STRING * char_string) +bool characterstring_printable(BACNET_CHARACTER_STRING *char_string) { - bool status = false; /* return value */ - size_t i; /* counter */ + bool status = false; /* return value */ + size_t i; /* counter */ if (char_string) { if (char_string->encoding == CHARACTER_ANSI_X34) { @@ -566,32 +530,24 @@ bool characterstring_printable( by Jeff Bezanson placed in the public domain Fall 2005 */ static const char trailingBytesForUTF8[256] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, - 4, 4, 4, 5, 5, 5, 5 -}; + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5}; /* based on the valid_utf8 routine from the PCRE library by Philip Hazel length is in bytes, since without knowing whether the string is valid it's hard to know how many characters there are! */ -bool utf8_isvalid( - const char *str, - size_t length) +bool utf8_isvalid(const char *str, size_t length) { - const unsigned char *p, *pend = (unsigned char *) str + length; + const unsigned char *p, *pend = (unsigned char *)str + length; unsigned char c; size_t ab; @@ -599,7 +555,7 @@ bool utf8_isvalid( if (length == 0) { return true; } - for (p = (const unsigned char *) str; p < pend; p++) { + for (p = (const unsigned char *)str; p < pend; p++) { c = *p; /* null in middle of string */ if (c == 0) { @@ -612,7 +568,7 @@ bool utf8_isvalid( if ((c & 0xc0) != 0xc0) { return false; } - ab = (size_t) trailingBytesForUTF8[c]; + ab = (size_t)trailingBytesForUTF8[c]; if (length < ab) { return false; } @@ -629,7 +585,7 @@ bool utf8_isvalid( case 1: if ((c & 0x3e) == 0) return false; - continue; /* We know there aren't any more bytes to check */ + continue; /* We know there aren't any more bytes to check */ /* Check for 1110 0000, xx0x xxxx */ case 2: @@ -667,8 +623,7 @@ bool utf8_isvalid( return true; } -bool characterstring_valid( - BACNET_CHARACTER_STRING * char_string) +bool characterstring_valid(BACNET_CHARACTER_STRING *char_string) { bool valid = false; /* return value */ @@ -688,13 +643,11 @@ bool characterstring_valid( #if BACNET_USE_OCTETSTRING /* returns false if the string exceeds capacity initialize by using value=NULL */ -bool octetstring_init( - BACNET_OCTET_STRING * octet_string, - uint8_t * value, - size_t length) +bool octetstring_init(BACNET_OCTET_STRING *octet_string, uint8_t *value, + size_t length) { - bool status = false; /* return value */ - size_t i; /* counter */ + bool status = false; /* return value */ + size_t i; /* counter */ if (octet_string && (length <= MAX_OCTET_STRING_BYTES)) { octet_string->length = 0; @@ -721,12 +674,11 @@ bool octetstring_init( #if PRINT_ENABLED /* converts an null terminated ASCII Hex string to an octet string. returns true if successfully converted and fits; false if too long */ -bool octetstring_init_ascii_hex( - BACNET_OCTET_STRING * octet_string, - const char *ascii_hex) +bool octetstring_init_ascii_hex(BACNET_OCTET_STRING *octet_string, + const char *ascii_hex) { - bool status = false; /* return value */ - unsigned index = 0; /* offset into buffer */ + bool status = false; /* return value */ + unsigned index = 0; /* offset into buffer */ uint8_t value = 0; char hex_pair_string[3] = ""; @@ -747,7 +699,7 @@ bool octetstring_init_ascii_hex( } hex_pair_string[0] = ascii_hex[index]; hex_pair_string[1] = ascii_hex[index + 1]; - value = (uint8_t) strtol(hex_pair_string, NULL, 16); + value = (uint8_t)strtol(hex_pair_string, NULL, 16); if (octet_string->length <= MAX_OCTET_STRING_BYTES) { octet_string->value[octet_string->length] = value; octet_string->length++; @@ -767,23 +719,19 @@ bool octetstring_init_ascii_hex( } #endif -bool octetstring_copy( - BACNET_OCTET_STRING * dest, - BACNET_OCTET_STRING * src) +bool octetstring_copy(BACNET_OCTET_STRING *dest, BACNET_OCTET_STRING *src) { return octetstring_init(dest, octetstring_value(src), - octetstring_length(src)); + octetstring_length(src)); } /* returns the number of bytes copied, or 0 if the dest cannot hold entire octetstring value */ -size_t octetstring_copy_value( - uint8_t * dest, - size_t length, - BACNET_OCTET_STRING * src) +size_t octetstring_copy_value(uint8_t *dest, size_t length, + BACNET_OCTET_STRING *src) { size_t bytes_copied = 0; - size_t i; /* counter */ + size_t i; /* counter */ if (src && dest) { if (length <= src->length) { @@ -798,13 +746,11 @@ size_t octetstring_copy_value( } /* returns false if the string exceeds capacity */ -bool octetstring_append( - BACNET_OCTET_STRING * octet_string, - uint8_t * value, - size_t length) +bool octetstring_append(BACNET_OCTET_STRING *octet_string, uint8_t *value, + size_t length) { - size_t i; /* counter */ - bool status = false; /* return value */ + size_t i; /* counter */ + bool status = false; /* return value */ if (octet_string) { if ((length + octet_string->length) <= MAX_OCTET_STRING_BYTES) { @@ -822,11 +768,9 @@ bool octetstring_append( /* This function sets a new length without changing the value. If length exceeds capacity, no modification happens and function returns false. */ -bool octetstring_truncate( - BACNET_OCTET_STRING * octet_string, - size_t length) +bool octetstring_truncate(BACNET_OCTET_STRING *octet_string, size_t length) { - bool status = false; /* return value */ + bool status = false; /* return value */ if (octet_string) { if (length <= MAX_OCTET_STRING_BYTES) { @@ -839,8 +783,7 @@ bool octetstring_truncate( } /* returns a pointer to the value. */ -uint8_t *octetstring_value( - BACNET_OCTET_STRING * octet_string) +uint8_t *octetstring_value(BACNET_OCTET_STRING *octet_string) { uint8_t *value = NULL; @@ -852,8 +795,7 @@ uint8_t *octetstring_value( } /* returns the length. */ -size_t octetstring_length( - BACNET_OCTET_STRING * octet_string) +size_t octetstring_length(BACNET_OCTET_STRING *octet_string) { size_t length = 0; @@ -866,8 +808,7 @@ size_t octetstring_length( } /* returns the maximum capacity. */ -size_t octetstring_capacity( - BACNET_OCTET_STRING * octet_string) +size_t octetstring_capacity(BACNET_OCTET_STRING *octet_string) { size_t length = 0; @@ -880,11 +821,10 @@ size_t octetstring_capacity( } /* returns true if the same length and contents */ -bool octetstring_value_same( - BACNET_OCTET_STRING * octet_string1, - BACNET_OCTET_STRING * octet_string2) +bool octetstring_value_same(BACNET_OCTET_STRING *octet_string1, + BACNET_OCTET_STRING *octet_string2) { - size_t i = 0; /* loop counter */ + size_t i = 0; /* loop counter */ if (octet_string1 && octet_string2) { if ((octet_string1->length == octet_string2->length) && @@ -909,8 +849,7 @@ bool octetstring_value_same( #include #include "ctest.h" -void testBitString( - Test * pTest) +void testBitString(Test *pTest) { uint8_t bit = 0; int max_bit; @@ -962,17 +901,17 @@ void testBitString( bitstring_set_bit(&bit_string2, bit, bit_value); bitstring_set_bit(&bit_string3, bit, bit_value); } - /* Set the first bit of bit_string2 and the last bit of bit_string3 to be different */ + /* Set the first bit of bit_string2 and the last bit of bit_string3 to + * be different */ bitstring_set_bit(&bit_string2, 0, !bitstring_bit(&bit_string, 0)); bitstring_set_bit(&bit_string3, max_bit - 1, - !bitstring_bit(&bit_string, max_bit - 1)); + !bitstring_bit(&bit_string, max_bit - 1)); ct_test(pTest, !bitstring_same(&bit_string, &bit_string2)); ct_test(pTest, !bitstring_same(&bit_string, &bit_string3)); } } -void testCharacterString( - Test * pTest) +void testCharacterString(Test *pTest) { BACNET_CHARACTER_STRING bacnet_string; char *value = "Joshua,Mary,Anna,Christopher"; @@ -989,25 +928,21 @@ void testCharacterString( ct_test(pTest, status == true); ct_test(pTest, characterstring_length(&bacnet_string) == 0); ct_test(pTest, - characterstring_encoding(&bacnet_string) == CHARACTER_ANSI_X34); + characterstring_encoding(&bacnet_string) == CHARACTER_ANSI_X34); /* bounds check */ - status = - characterstring_init(&bacnet_string, CHARACTER_ANSI_X34, NULL, - characterstring_capacity(&bacnet_string) + 1); + status = characterstring_init(&bacnet_string, CHARACTER_ANSI_X34, NULL, + characterstring_capacity(&bacnet_string) + 1); ct_test(pTest, status == false); - status = - characterstring_truncate(&bacnet_string, - characterstring_capacity(&bacnet_string) + 1); + status = characterstring_truncate( + &bacnet_string, characterstring_capacity(&bacnet_string) + 1); ct_test(pTest, status == false); - status = - characterstring_truncate(&bacnet_string, - characterstring_capacity(&bacnet_string)); + status = characterstring_truncate(&bacnet_string, + characterstring_capacity(&bacnet_string)); ct_test(pTest, status == true); test_length = strlen(test_value); - status = - characterstring_init(&bacnet_string, CHARACTER_ANSI_X34, - &test_value[0], test_length); + status = characterstring_init(&bacnet_string, CHARACTER_ANSI_X34, + &test_value[0], test_length); ct_test(pTest, status == true); value = characterstring_value(&bacnet_string); length = characterstring_length(&bacnet_string); @@ -1016,9 +951,8 @@ void testCharacterString( ct_test(pTest, value[i] == test_value[i]); } test_length = strlen(test_append_value); - status = - characterstring_append(&bacnet_string, &test_append_value[0], - test_length); + status = characterstring_append(&bacnet_string, &test_append_value[0], + test_length); strcat(test_append_string, test_value); strcat(test_append_string, test_append_value); test_length = strlen(test_append_string); @@ -1031,8 +965,7 @@ void testCharacterString( } } -void testOctetString( - Test * pTest) +void testOctetString(Test *pTest) { BACNET_OCTET_STRING bacnet_string; uint8_t *value = NULL; @@ -1053,24 +986,20 @@ void testOctetString( ct_test(pTest, value[i] == 0); } /* bounds check */ - status = - octetstring_init(&bacnet_string, NULL, - octetstring_capacity(&bacnet_string) + 1); + status = octetstring_init(&bacnet_string, NULL, + octetstring_capacity(&bacnet_string) + 1); ct_test(pTest, status == false); - status = - octetstring_init(&bacnet_string, NULL, - octetstring_capacity(&bacnet_string)); + status = octetstring_init(&bacnet_string, NULL, + octetstring_capacity(&bacnet_string)); ct_test(pTest, status == true); - status = - octetstring_truncate(&bacnet_string, - octetstring_capacity(&bacnet_string) + 1); + status = octetstring_truncate(&bacnet_string, + octetstring_capacity(&bacnet_string) + 1); ct_test(pTest, status == false); - status = - octetstring_truncate(&bacnet_string, - octetstring_capacity(&bacnet_string)); + status = octetstring_truncate(&bacnet_string, + octetstring_capacity(&bacnet_string)); ct_test(pTest, status == true); - test_length = strlen((char *) test_value); + test_length = strlen((char *)test_value); status = octetstring_init(&bacnet_string, &test_value[0], test_length); ct_test(pTest, status == true); length = octetstring_length(&bacnet_string); @@ -1080,12 +1009,12 @@ void testOctetString( ct_test(pTest, value[i] == test_value[i]); } - test_length = strlen((char *) test_append_value); + test_length = strlen((char *)test_append_value); status = octetstring_append(&bacnet_string, &test_append_value[0], test_length); - strcat((char *) test_append_string, (char *) test_value); - strcat((char *) test_append_string, (char *) test_append_value); - test_length = strlen((char *) test_append_string); + strcat((char *)test_append_string, (char *)test_value); + strcat((char *)test_append_string, (char *)test_append_value); + test_length = strlen((char *)test_append_string); ct_test(pTest, status == true); length = octetstring_length(&bacnet_string); value = octetstring_value(&bacnet_string); @@ -1096,8 +1025,7 @@ void testOctetString( } #ifdef TEST_BACSTR -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -1113,7 +1041,7 @@ int main( /* configure output */ ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/src/bactext.c b/src/bactext.c index b0801ee9..54524559 100644 --- a/src/bactext.c +++ b/src/bactext.c @@ -56,13 +56,12 @@ INDTEXT_DATA bacnet_confirmed_service_names[] = { {SERVICE_CONFIRMED_CREATE_OBJECT, "Create-Object"}, {SERVICE_CONFIRMED_DELETE_OBJECT, "Delete-Object"}, {SERVICE_CONFIRMED_READ_PROPERTY, "Read-Property"}, - {SERVICE_CONFIRMED_READ_PROP_CONDITIONAL, - "Read-Property-Conditional"}, + {SERVICE_CONFIRMED_READ_PROP_CONDITIONAL, "Read-Property-Conditional"}, {SERVICE_CONFIRMED_READ_PROP_MULTIPLE, "Read-Property-Multiple"}, {SERVICE_CONFIRMED_WRITE_PROPERTY, "Write-Property"}, {SERVICE_CONFIRMED_WRITE_PROP_MULTIPLE, "Write-Property-Multiple"}, {SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL, - "Device-Communication-Control"}, + "Device-Communication-Control"}, {SERVICE_CONFIRMED_PRIVATE_TRANSFER, "Private-Transfer"}, {SERVICE_CONFIRMED_TEXT_MESSAGE, "Text-Message"}, {SERVICE_CONFIRMED_REINITIALIZE_DEVICE, "Reinitialize-Device"}, @@ -75,967 +74,510 @@ INDTEXT_DATA bacnet_confirmed_service_names[] = { {SERVICE_CONFIRMED_LIFE_SAFETY_OPERATION, "Life-Safety_Operation"}, {SERVICE_CONFIRMED_SUBSCRIBE_COV_PROPERTY, "Subscribe-COV-Property"}, {SERVICE_CONFIRMED_GET_EVENT_INFORMATION, "Get-Event-Information"}, - {0, NULL} -}; + {0, NULL}}; -const char *bactext_confirmed_service_name( - unsigned index) +const char *bactext_confirmed_service_name(unsigned index) { return indtext_by_index_default(bacnet_confirmed_service_names, index, - ASHRAE_Reserved_String); + ASHRAE_Reserved_String); } INDTEXT_DATA bacnet_unconfirmed_service_names[] = { - {SERVICE_UNCONFIRMED_I_AM, "I-Am"} - , - {SERVICE_UNCONFIRMED_I_HAVE, "I-Have"} - , - {SERVICE_UNCONFIRMED_COV_NOTIFICATION, "COV-Notification"} - , - {SERVICE_UNCONFIRMED_EVENT_NOTIFICATION, "Event-Notification"} - , - {SERVICE_UNCONFIRMED_PRIVATE_TRANSFER, "Private-Transfer"} - , - {SERVICE_UNCONFIRMED_TEXT_MESSAGE, "Text-Message"} - , - {SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION, "Time-Synchronization"} - , - {SERVICE_UNCONFIRMED_WHO_HAS, "Who-Has"} - , - {SERVICE_UNCONFIRMED_WHO_IS, "Who-Is"} - , - {SERVICE_UNCONFIRMED_UTC_TIME_SYNCHRONIZATION, - "UTC-Time-Synchronization"} - , - {SERVICE_UNCONFIRMED_WRITE_GROUP, - "Write-Group"} - , - {0, NULL} -}; + {SERVICE_UNCONFIRMED_I_AM, "I-Am"}, + {SERVICE_UNCONFIRMED_I_HAVE, "I-Have"}, + {SERVICE_UNCONFIRMED_COV_NOTIFICATION, "COV-Notification"}, + {SERVICE_UNCONFIRMED_EVENT_NOTIFICATION, "Event-Notification"}, + {SERVICE_UNCONFIRMED_PRIVATE_TRANSFER, "Private-Transfer"}, + {SERVICE_UNCONFIRMED_TEXT_MESSAGE, "Text-Message"}, + {SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION, "Time-Synchronization"}, + {SERVICE_UNCONFIRMED_WHO_HAS, "Who-Has"}, + {SERVICE_UNCONFIRMED_WHO_IS, "Who-Is"}, + {SERVICE_UNCONFIRMED_UTC_TIME_SYNCHRONIZATION, "UTC-Time-Synchronization"}, + {SERVICE_UNCONFIRMED_WRITE_GROUP, "Write-Group"}, + {0, NULL}}; -const char *bactext_unconfirmed_service_name( - unsigned index) +const char *bactext_unconfirmed_service_name(unsigned index) { return indtext_by_index_default(bacnet_unconfirmed_service_names, index, - ASHRAE_Reserved_String); + ASHRAE_Reserved_String); } INDTEXT_DATA bacnet_application_tag_names[] = { - {BACNET_APPLICATION_TAG_NULL, "Null"} - , - {BACNET_APPLICATION_TAG_BOOLEAN, "Boolean"} - , - {BACNET_APPLICATION_TAG_UNSIGNED_INT, "Unsigned Int"} - , - {BACNET_APPLICATION_TAG_SIGNED_INT, "Signed Int"} - , - {BACNET_APPLICATION_TAG_REAL, "Real"} - , - {BACNET_APPLICATION_TAG_DOUBLE, "Double"} - , - {BACNET_APPLICATION_TAG_OCTET_STRING, "Octet String"} - , - {BACNET_APPLICATION_TAG_CHARACTER_STRING, "Character String"} - , - {BACNET_APPLICATION_TAG_BIT_STRING, "Bit String"} - , - {BACNET_APPLICATION_TAG_ENUMERATED, "Enumerated"} - , - {BACNET_APPLICATION_TAG_DATE, "Date"} - , - {BACNET_APPLICATION_TAG_TIME, "Time"} - , - {BACNET_APPLICATION_TAG_OBJECT_ID, "Object ID"} - , - {BACNET_APPLICATION_TAG_RESERVE1, "Reserved 1"} - , - {BACNET_APPLICATION_TAG_RESERVE2, "Reserved 2"} - , - {BACNET_APPLICATION_TAG_RESERVE3, "Reserved 3"} - , - {0, NULL} -}; + {BACNET_APPLICATION_TAG_NULL, "Null"}, + {BACNET_APPLICATION_TAG_BOOLEAN, "Boolean"}, + {BACNET_APPLICATION_TAG_UNSIGNED_INT, "Unsigned Int"}, + {BACNET_APPLICATION_TAG_SIGNED_INT, "Signed Int"}, + {BACNET_APPLICATION_TAG_REAL, "Real"}, + {BACNET_APPLICATION_TAG_DOUBLE, "Double"}, + {BACNET_APPLICATION_TAG_OCTET_STRING, "Octet String"}, + {BACNET_APPLICATION_TAG_CHARACTER_STRING, "Character String"}, + {BACNET_APPLICATION_TAG_BIT_STRING, "Bit String"}, + {BACNET_APPLICATION_TAG_ENUMERATED, "Enumerated"}, + {BACNET_APPLICATION_TAG_DATE, "Date"}, + {BACNET_APPLICATION_TAG_TIME, "Time"}, + {BACNET_APPLICATION_TAG_OBJECT_ID, "Object ID"}, + {BACNET_APPLICATION_TAG_RESERVE1, "Reserved 1"}, + {BACNET_APPLICATION_TAG_RESERVE2, "Reserved 2"}, + {BACNET_APPLICATION_TAG_RESERVE3, "Reserved 3"}, + {0, NULL}}; -const char *bactext_application_tag_name( - unsigned index) +const char *bactext_application_tag_name(unsigned index) { return indtext_by_index_default(bacnet_application_tag_names, index, - ASHRAE_Reserved_String); + ASHRAE_Reserved_String); } -bool bactext_application_tag_index( - const char *search_name, - unsigned *found_index) +bool bactext_application_tag_index(const char *search_name, + unsigned *found_index) { return indtext_by_istring(bacnet_application_tag_names, search_name, - found_index); + found_index); } INDTEXT_DATA bacnet_object_type_names[] = { - {OBJECT_ANALOG_INPUT, "analog-input"} - , - {OBJECT_ANALOG_OUTPUT, "analog-output"} - , - {OBJECT_ANALOG_VALUE, "analog-value"} - , - {OBJECT_BINARY_INPUT, "binary-input"} - , - {OBJECT_BINARY_OUTPUT, "binary-output"} - , - {OBJECT_BINARY_VALUE, "binary-value"} - , - {OBJECT_CALENDAR, "calendar"} - , - {OBJECT_COMMAND, "command"} - , - {OBJECT_DEVICE, "device"} - , - {OBJECT_EVENT_ENROLLMENT, "event-enrollment"} - , - {OBJECT_FILE, "file"} - , - {OBJECT_GROUP, "group"} - , - {OBJECT_LOOP, "loop"} - , - {OBJECT_MULTI_STATE_INPUT, "multi-state-input"} - , - {OBJECT_MULTI_STATE_OUTPUT, "multi-state-output"} - , - {OBJECT_NOTIFICATION_CLASS, "notification-class"} - , - {OBJECT_PROGRAM, "program"} - , - {OBJECT_SCHEDULE, "schedule"} - , - {OBJECT_AVERAGING, "averaging"} - , - {OBJECT_MULTI_STATE_VALUE, "multi-state-value"} - , - {OBJECT_TRENDLOG, "trend-log"} - , - {OBJECT_LIFE_SAFETY_POINT, "life-safety-point"} - , - {OBJECT_LIFE_SAFETY_ZONE, "life-safety-zone"} - , - {OBJECT_ACCUMULATOR, "accumulator"} - , - {OBJECT_PULSE_CONVERTER, "pulse-converter"} - , - {OBJECT_EVENT_LOG, "event-log"} - , - {OBJECT_GLOBAL_GROUP, "global-group"} - , - {OBJECT_TREND_LOG_MULTIPLE, "trend-log-multiple"} - , - {OBJECT_LOAD_CONTROL, "load-control"} - , - {OBJECT_STRUCTURED_VIEW, "structured-view"} - , - {OBJECT_ACCESS_DOOR, "access-door"} - , - {OBJECT_LIGHTING_OUTPUT, "lighting-output"} - , - {OBJECT_ACCESS_CREDENTIAL, "access-credential"} - , - {OBJECT_ACCESS_POINT, "access-point"} - , - {OBJECT_ACCESS_RIGHTS, "access-rights"} - , - {OBJECT_ACCESS_USER, "access-user"} - , - {OBJECT_ACCESS_ZONE, "access-zone"} - , - {OBJECT_CREDENTIAL_DATA_INPUT, "credential-data-input"} - , - {OBJECT_NETWORK_SECURITY, "network-security"} - , - {OBJECT_BITSTRING_VALUE, "bitstring-value"} - , - {OBJECT_CHARACTERSTRING_VALUE, "characterstring-value"} - , - {OBJECT_DATE_PATTERN_VALUE, "date-pattern-value"} - , - {OBJECT_DATE_VALUE, "date-value"} - , - {OBJECT_DATETIME_PATTERN_VALUE, "datetime-pattern-value"} - , - {OBJECT_DATETIME_VALUE, "datetime-value"} - , - {OBJECT_INTEGER_VALUE, "integer-value"} - , - {OBJECT_LARGE_ANALOG_VALUE, "large-analog-value"} - , - {OBJECT_OCTETSTRING_VALUE, "octetstring-value"} - , - {OBJECT_POSITIVE_INTEGER_VALUE, "positive-integer-value"} - , - {OBJECT_TIME_PATTERN_VALUE, "time-pattern-value"} - , - {OBJECT_TIME_VALUE, "time-value"} - , - {OBJECT_NOTIFICATION_FORWARDER, "notification-forwarder"} - , - {OBJECT_ALERT_ENROLLMENT, "alert-enrollment"} - , - {OBJECT_CHANNEL, "channel"} - , - {OBJECT_LIGHTING_OUTPUT, "lighting-output"} - , - {OBJECT_BINARY_LIGHTING_OUTPUT, "binary-lighting-output"} - , - {OBJECT_NETWORK_PORT, "network-port"} - , + {OBJECT_ANALOG_INPUT, "analog-input"}, + {OBJECT_ANALOG_OUTPUT, "analog-output"}, + {OBJECT_ANALOG_VALUE, "analog-value"}, + {OBJECT_BINARY_INPUT, "binary-input"}, + {OBJECT_BINARY_OUTPUT, "binary-output"}, + {OBJECT_BINARY_VALUE, "binary-value"}, + {OBJECT_CALENDAR, "calendar"}, + {OBJECT_COMMAND, "command"}, + {OBJECT_DEVICE, "device"}, + {OBJECT_EVENT_ENROLLMENT, "event-enrollment"}, + {OBJECT_FILE, "file"}, + {OBJECT_GROUP, "group"}, + {OBJECT_LOOP, "loop"}, + {OBJECT_MULTI_STATE_INPUT, "multi-state-input"}, + {OBJECT_MULTI_STATE_OUTPUT, "multi-state-output"}, + {OBJECT_NOTIFICATION_CLASS, "notification-class"}, + {OBJECT_PROGRAM, "program"}, + {OBJECT_SCHEDULE, "schedule"}, + {OBJECT_AVERAGING, "averaging"}, + {OBJECT_MULTI_STATE_VALUE, "multi-state-value"}, + {OBJECT_TRENDLOG, "trend-log"}, + {OBJECT_LIFE_SAFETY_POINT, "life-safety-point"}, + {OBJECT_LIFE_SAFETY_ZONE, "life-safety-zone"}, + {OBJECT_ACCUMULATOR, "accumulator"}, + {OBJECT_PULSE_CONVERTER, "pulse-converter"}, + {OBJECT_EVENT_LOG, "event-log"}, + {OBJECT_GLOBAL_GROUP, "global-group"}, + {OBJECT_TREND_LOG_MULTIPLE, "trend-log-multiple"}, + {OBJECT_LOAD_CONTROL, "load-control"}, + {OBJECT_STRUCTURED_VIEW, "structured-view"}, + {OBJECT_ACCESS_DOOR, "access-door"}, + {OBJECT_LIGHTING_OUTPUT, "lighting-output"}, + {OBJECT_ACCESS_CREDENTIAL, "access-credential"}, + {OBJECT_ACCESS_POINT, "access-point"}, + {OBJECT_ACCESS_RIGHTS, "access-rights"}, + {OBJECT_ACCESS_USER, "access-user"}, + {OBJECT_ACCESS_ZONE, "access-zone"}, + {OBJECT_CREDENTIAL_DATA_INPUT, "credential-data-input"}, + {OBJECT_NETWORK_SECURITY, "network-security"}, + {OBJECT_BITSTRING_VALUE, "bitstring-value"}, + {OBJECT_CHARACTERSTRING_VALUE, "characterstring-value"}, + {OBJECT_DATE_PATTERN_VALUE, "date-pattern-value"}, + {OBJECT_DATE_VALUE, "date-value"}, + {OBJECT_DATETIME_PATTERN_VALUE, "datetime-pattern-value"}, + {OBJECT_DATETIME_VALUE, "datetime-value"}, + {OBJECT_INTEGER_VALUE, "integer-value"}, + {OBJECT_LARGE_ANALOG_VALUE, "large-analog-value"}, + {OBJECT_OCTETSTRING_VALUE, "octetstring-value"}, + {OBJECT_POSITIVE_INTEGER_VALUE, "positive-integer-value"}, + {OBJECT_TIME_PATTERN_VALUE, "time-pattern-value"}, + {OBJECT_TIME_VALUE, "time-value"}, + {OBJECT_NOTIFICATION_FORWARDER, "notification-forwarder"}, + {OBJECT_ALERT_ENROLLMENT, "alert-enrollment"}, + {OBJECT_CHANNEL, "channel"}, + {OBJECT_LIGHTING_OUTPUT, "lighting-output"}, + {OBJECT_BINARY_LIGHTING_OUTPUT, "binary-lighting-output"}, + {OBJECT_NETWORK_PORT, "network-port"}, {0, NULL} /* Enumerated values 0-127 are reserved for definition by ASHRAE. Enumerated values 128-1023 may be used by others subject to the procedures and constraints described in Clause 23. */ }; -const char *bactext_object_type_name( - unsigned index) +const char *bactext_object_type_name(unsigned index) { return indtext_by_index_split_default(bacnet_object_type_names, index, 128, - ASHRAE_Reserved_String, Vendor_Proprietary_String); + ASHRAE_Reserved_String, + Vendor_Proprietary_String); } -bool bactext_object_type_index( - const char *search_name, - unsigned *found_index) +bool bactext_object_type_index(const char *search_name, unsigned *found_index) { return indtext_by_istring(bacnet_object_type_names, search_name, - found_index); + found_index); } INDTEXT_DATA bacnet_property_names[] = { -/* FIXME: use the enumerations from bacenum.h */ - {PROP_ACKED_TRANSITIONS, "acked-transitions"} - , - {PROP_ACK_REQUIRED, "ack-required"} - , - {PROP_ACTION, "action"} - , - {PROP_ACTION_TEXT, "action-text"} - , - {PROP_ACTIVE_TEXT, "active-text"} - , - {PROP_ACTIVE_VT_SESSIONS, "active-vt-sessions"} - , - {PROP_ALARM_VALUE, "alarm-value"} - , - {PROP_ALARM_VALUES, "alarm-values"} - , - {PROP_ALL, "all"} - , - {PROP_ALL_WRITES_SUCCESSFUL, "all-writes-successful"} - , - {PROP_APDU_SEGMENT_TIMEOUT, "apdu-segment-timeout"} - , - {PROP_APDU_TIMEOUT, "apdu-timeout"} - , - {PROP_APPLICATION_SOFTWARE_VERSION, "application-software-version"} - , - {PROP_ARCHIVE, "archive"} - , - {PROP_BIAS, "bias"} - , - {PROP_CHANGE_OF_STATE_COUNT, "change-of-state-count"} - , - {PROP_CHANGE_OF_STATE_TIME, "change-of-state-time"} - , - {PROP_NOTIFICATION_CLASS, "notification-class"} - , - {PROP_BLANK_1, "(deleted in 135-2001)"} - , - {PROP_CONTROLLED_VARIABLE_REFERENCE, "controlled-variable-reference"} - , - {PROP_CONTROLLED_VARIABLE_UNITS, "controlled-variable-units"} - , - {PROP_CONTROLLED_VARIABLE_VALUE, "controlled-variable-value"} - , - {PROP_COV_INCREMENT, "COV-increment"} - , - {PROP_DATE_LIST, "datelist"} - , - {PROP_DAYLIGHT_SAVINGS_STATUS, "daylight-savings-status"} - , - {PROP_DEADBAND, "deadband"} - , - {PROP_DERIVATIVE_CONSTANT, "derivative-constant"} - , - {PROP_DERIVATIVE_CONSTANT_UNITS, "derivative-constant-units"} - , - {PROP_DESCRIPTION, "description"} - , - {PROP_DESCRIPTION_OF_HALT, "description-of-halt"} - , - {PROP_DEVICE_ADDRESS_BINDING, "device-address-binding"} - , - {PROP_DEVICE_TYPE, "device-type"} - , - {PROP_EFFECTIVE_PERIOD, "effective-period"} - , - {PROP_ELAPSED_ACTIVE_TIME, "elapsed-active-time"} - , - {PROP_ERROR_LIMIT, "error-limit"} - , - {PROP_EVENT_ENABLE, "event-enable"} - , - {PROP_EVENT_STATE, "event-state"} - , - {PROP_EVENT_TYPE, "event-type"} - , - {PROP_EXCEPTION_SCHEDULE, "exception-schedule"} - , - {PROP_FAULT_VALUES, "fault-values"} - , - {PROP_FEEDBACK_VALUE, "feedback-value"} - , - {PROP_FILE_ACCESS_METHOD, "file-access-method"} - , - {PROP_FILE_SIZE, "file-size"} - , - {PROP_FILE_TYPE, "file-type"} - , - {PROP_FIRMWARE_REVISION, "firmware-revision"} - , /* VTS wants "revision", not "version" */ - {PROP_HIGH_LIMIT, "high-limit"} - , - {PROP_INACTIVE_TEXT, "inactive-text"} - , - {PROP_IN_PROCESS, "in-process"} - , - {PROP_INSTANCE_OF, "instance-of"} - , - {PROP_INTEGRAL_CONSTANT, "integral-constant"} - , - {PROP_INTEGRAL_CONSTANT_UNITS, "integral-constant-units"} - , - {PROP_ISSUE_CONFIRMED_NOTIFICATIONS, "issue-confirmednotifications"} - , - {PROP_LIMIT_ENABLE, "limit-enable"} - , - {PROP_LIST_OF_GROUP_MEMBERS, "list-of-group-members"} - , + /* FIXME: use the enumerations from bacenum.h */ + {PROP_ACKED_TRANSITIONS, "acked-transitions"}, + {PROP_ACK_REQUIRED, "ack-required"}, + {PROP_ACTION, "action"}, + {PROP_ACTION_TEXT, "action-text"}, + {PROP_ACTIVE_TEXT, "active-text"}, + {PROP_ACTIVE_VT_SESSIONS, "active-vt-sessions"}, + {PROP_ALARM_VALUE, "alarm-value"}, + {PROP_ALARM_VALUES, "alarm-values"}, + {PROP_ALL, "all"}, + {PROP_ALL_WRITES_SUCCESSFUL, "all-writes-successful"}, + {PROP_APDU_SEGMENT_TIMEOUT, "apdu-segment-timeout"}, + {PROP_APDU_TIMEOUT, "apdu-timeout"}, + {PROP_APPLICATION_SOFTWARE_VERSION, "application-software-version"}, + {PROP_ARCHIVE, "archive"}, + {PROP_BIAS, "bias"}, + {PROP_CHANGE_OF_STATE_COUNT, "change-of-state-count"}, + {PROP_CHANGE_OF_STATE_TIME, "change-of-state-time"}, + {PROP_NOTIFICATION_CLASS, "notification-class"}, + {PROP_BLANK_1, "(deleted in 135-2001)"}, + {PROP_CONTROLLED_VARIABLE_REFERENCE, "controlled-variable-reference"}, + {PROP_CONTROLLED_VARIABLE_UNITS, "controlled-variable-units"}, + {PROP_CONTROLLED_VARIABLE_VALUE, "controlled-variable-value"}, + {PROP_COV_INCREMENT, "COV-increment"}, + {PROP_DATE_LIST, "datelist"}, + {PROP_DAYLIGHT_SAVINGS_STATUS, "daylight-savings-status"}, + {PROP_DEADBAND, "deadband"}, + {PROP_DERIVATIVE_CONSTANT, "derivative-constant"}, + {PROP_DERIVATIVE_CONSTANT_UNITS, "derivative-constant-units"}, + {PROP_DESCRIPTION, "description"}, + {PROP_DESCRIPTION_OF_HALT, "description-of-halt"}, + {PROP_DEVICE_ADDRESS_BINDING, "device-address-binding"}, + {PROP_DEVICE_TYPE, "device-type"}, + {PROP_EFFECTIVE_PERIOD, "effective-period"}, + {PROP_ELAPSED_ACTIVE_TIME, "elapsed-active-time"}, + {PROP_ERROR_LIMIT, "error-limit"}, + {PROP_EVENT_ENABLE, "event-enable"}, + {PROP_EVENT_STATE, "event-state"}, + {PROP_EVENT_TYPE, "event-type"}, + {PROP_EXCEPTION_SCHEDULE, "exception-schedule"}, + {PROP_FAULT_VALUES, "fault-values"}, + {PROP_FEEDBACK_VALUE, "feedback-value"}, + {PROP_FILE_ACCESS_METHOD, "file-access-method"}, + {PROP_FILE_SIZE, "file-size"}, + {PROP_FILE_TYPE, "file-type"}, + {PROP_FIRMWARE_REVISION, + "firmware-revision"}, /* VTS wants "revision", not "version" */ + {PROP_HIGH_LIMIT, "high-limit"}, + {PROP_INACTIVE_TEXT, "inactive-text"}, + {PROP_IN_PROCESS, "in-process"}, + {PROP_INSTANCE_OF, "instance-of"}, + {PROP_INTEGRAL_CONSTANT, "integral-constant"}, + {PROP_INTEGRAL_CONSTANT_UNITS, "integral-constant-units"}, + {PROP_ISSUE_CONFIRMED_NOTIFICATIONS, "issue-confirmednotifications"}, + {PROP_LIMIT_ENABLE, "limit-enable"}, + {PROP_LIST_OF_GROUP_MEMBERS, "list-of-group-members"}, {PROP_LIST_OF_OBJECT_PROPERTY_REFERENCES, - "list-of-object-property-references"} - , - {PROP_LIST_OF_SESSION_KEYS, "list-of-session-keys"} - , - {PROP_LOCAL_DATE, "local-date"} - , - {PROP_LOCAL_TIME, "local-time"} - , - {PROP_LOCATION, "location"} - , - {PROP_LOW_LIMIT, "low-limit"} - , - {PROP_MANIPULATED_VARIABLE_REFERENCE, "manipulated-variable-reference"} - , - {PROP_MAXIMUM_OUTPUT, "maximum-output"} - , - {PROP_MAX_APDU_LENGTH_ACCEPTED, "max-apdu-length-accepted"} - , - {PROP_MAX_INFO_FRAMES, "max-info-frames"} - , - {PROP_MAX_MASTER, "max-master"} - , - {PROP_MAX_PRES_VALUE, "max-pres-value"} - , - {PROP_MINIMUM_OFF_TIME, "minimum-off-time"} - , - {PROP_MINIMUM_ON_TIME, "minimum-on-time"} - , - {PROP_MINIMUM_OUTPUT, "minimum-output"} - , - {PROP_MIN_PRES_VALUE, "min-pres-value"} - , - {PROP_MODEL_NAME, "model-name"} - , - {PROP_MODIFICATION_DATE, "modification-date"} - , - {PROP_NOTIFY_TYPE, "notify-type"} - , - {PROP_NUMBER_OF_APDU_RETRIES, "number-of-APDU-retries"} - , - {PROP_NUMBER_OF_STATES, "number-of-states"} - , - {PROP_OBJECT_IDENTIFIER, "object-identifier"} - , - {PROP_OBJECT_LIST, "object-list"} - , - {PROP_OBJECT_NAME, "object-name"} - , - {PROP_OBJECT_PROPERTY_REFERENCE, "object-property-reference"} - , - {PROP_OBJECT_TYPE, "object-type"} - , - {PROP_OPTIONAL, "optional"} - , - {PROP_OUT_OF_SERVICE, "out-of-service"} - , - {PROP_OUTPUT_UNITS, "output-units"} - , - {PROP_EVENT_PARAMETERS, "event-parameters"} - , - {PROP_POLARITY, "polarity"} - , - {PROP_PRESENT_VALUE, "present-value"} - , - {PROP_PRIORITY, "priority"} - , - {PROP_PRIORITY_ARRAY, "priority-array"} - , - {PROP_PRIORITY_FOR_WRITING, "priority-for-writing"} - , - {PROP_PROCESS_IDENTIFIER, "process-identifier"} - , - {PROP_PROGRAM_CHANGE, "program-change"} - , - {PROP_PROGRAM_LOCATION, "program-location"} - , - {PROP_PROGRAM_STATE, "program-state"} - , - {PROP_PROPORTIONAL_CONSTANT, "proportional-constant"} - , - {PROP_PROPORTIONAL_CONSTANT_UNITS, "proportional-constant-units"} - , - {PROP_PROTOCOL_CONFORMANCE_CLASS, "protocol-conformance-class"} - , - {PROP_PROTOCOL_OBJECT_TYPES_SUPPORTED, - "protocol-object-types-supported"} - , - {PROP_PROTOCOL_SERVICES_SUPPORTED, "protocol-services-supported"} - , - {PROP_PROTOCOL_VERSION, "protocol-version"} - , - {PROP_READ_ONLY, "read-only"} - , - {PROP_REASON_FOR_HALT, "reason-for-halt"} - , - {PROP_RECIPIENT, "recipient"} - , - {PROP_RECIPIENT_LIST, "recipient-list"} - , - {PROP_RELIABILITY, "reliability"} - , - {PROP_RELINQUISH_DEFAULT, "relinquish-default"} - , - {PROP_REQUIRED, "required"} - , - {PROP_RESOLUTION, "resolution"} - , - {PROP_SEGMENTATION_SUPPORTED, "segmentation-supported"} - , - {PROP_SETPOINT, "setpoint"} - , - {PROP_SETPOINT_REFERENCE, "setpoint-reference"} - , - {PROP_STATE_TEXT, "state-text"} - , - {PROP_STATUS_FLAGS, "status-flags"} - , - {PROP_SYSTEM_STATUS, "system-status"} - , - {PROP_TIME_DELAY, "time-delay"} - , - {PROP_TIME_OF_ACTIVE_TIME_RESET, "time-of-active-time-reset"} - , - {PROP_TIME_OF_STATE_COUNT_RESET, "time-of-state-count-reset"} - , - {PROP_TIME_SYNCHRONIZATION_RECIPIENTS, - "time-synchronization-recipients"} - , - {PROP_UNITS, "units"} - , - {PROP_UPDATE_INTERVAL, "update-interval"} - , - {PROP_UTC_OFFSET, "utc-offset"} - , - {PROP_VENDOR_IDENTIFIER, "vendor-identifier"} - , - {PROP_VENDOR_NAME, "vendor-name"} - , - {PROP_VT_CLASSES_SUPPORTED, "vt-classes-supported"} - , - {PROP_WEEKLY_SCHEDULE, "weekly-schedule"} - , - {PROP_ATTEMPTED_SAMPLES, "attempted-samples"} - , - {PROP_AVERAGE_VALUE, "average-value"} - , - {PROP_BUFFER_SIZE, "buffer-size"} - , - {PROP_CLIENT_COV_INCREMENT, "client-cov-increment"} - , - {PROP_COV_RESUBSCRIPTION_INTERVAL, "cov-resubscription-interval"} - , - {PROP_CURRENT_NOTIFY_TIME, "current-notify-time"} - , - {PROP_EVENT_TIME_STAMPS, "event-time-stamps"} - , - {PROP_LOG_BUFFER, "log-buffer"} - , - {PROP_LOG_DEVICE_OBJECT_PROPERTY, "log-device-object-property"} - , - {PROP_ENABLE, "enable"} - , - {PROP_LOG_INTERVAL, "log-interval"} - , - {PROP_MAXIMUM_VALUE, "maximum-value"} - , - {PROP_MINIMUM_VALUE, "minimum-value"} - , - {PROP_NOTIFICATION_THRESHOLD, "notification-threshold"} - , - {PROP_PREVIOUS_NOTIFY_TIME, "previous-notify-time"} - , - {PROP_PROTOCOL_REVISION, "protocol-revision"} - , - {PROP_RECORDS_SINCE_NOTIFICATION, "records-since-notification"} - , - {PROP_RECORD_COUNT, "record-count"} - , - {PROP_START_TIME, "start-time"} - , - {PROP_STOP_TIME, "stop-time"} - , - {PROP_STOP_WHEN_FULL, "stop-when-full"} - , - {PROP_TOTAL_RECORD_COUNT, "total-record-count"} - , - {PROP_VALID_SAMPLES, "valid-samples"} - , - {PROP_WINDOW_INTERVAL, "window-interval"} - , - {PROP_WINDOW_SAMPLES, "window-samples"} - , - {PROP_MAXIMUM_VALUE_TIMESTAMP, "maximum-value-timestamp"} - , - {PROP_MINIMUM_VALUE_TIMESTAMP, "minimum-value-timestamp"} - , - {PROP_VARIANCE_VALUE, "variance-value"} - , - {PROP_ACTIVE_COV_SUBSCRIPTIONS, "active-cov-subscriptions"} - , - {PROP_BACKUP_FAILURE_TIMEOUT, "backup-failure-timeout"} - , - {PROP_CONFIGURATION_FILES, "configuration-files"} - , - {PROP_DATABASE_REVISION, "database-revision"} - , - {PROP_DIRECT_READING, "direct-reading"} - , - {PROP_LAST_RESTORE_TIME, "last-restore-time"} - , - {PROP_MAINTENANCE_REQUIRED, "maintenance-required"} - , - {PROP_MEMBER_OF, "member-of"} - , - {PROP_MODE, "mode"} - , - {PROP_OPERATION_EXPECTED, "operation-expected"} - , - {PROP_SETTING, "setting"} - , - {PROP_SILENCED, "silenced"} - , - {PROP_TRACKING_VALUE, "tracking-value"} - , - {PROP_ZONE_MEMBERS, "zone-members"} - , - {PROP_LIFE_SAFETY_ALARM_VALUES, "life-safety-alarm-values"} - , - {PROP_MAX_SEGMENTS_ACCEPTED, "max-segments-accepted"} - , - {PROP_PROFILE_NAME, "profile-name"} - , - {PROP_AUTO_SLAVE_DISCOVERY, "auto-slave-discovery"} - , - {PROP_MANUAL_SLAVE_ADDRESS_BINDING, "manual-slave-address-binding"} - , - {PROP_SLAVE_ADDRESS_BINDING, "slave-address-binding"} - , - {PROP_SLAVE_PROXY_ENABLE, "slave-proxy-enable"} - , - {PROP_LAST_NOTIFY_RECORD, "last-notify-record"} - , - {PROP_SCHEDULE_DEFAULT, "schedule-default"} - , - {PROP_ACCEPTED_MODES, "accepted-modes"} - , - {PROP_ADJUST_VALUE, "adjust-value"} - , - {PROP_COUNT, "count"} - , - {PROP_COUNT_BEFORE_CHANGE, "count-before-change"} - , - {PROP_COUNT_CHANGE_TIME, "count-change-time"} - , - {PROP_COV_PERIOD, "COV-period"} - , - {PROP_INPUT_REFERENCE, "input-reference"} - , - {PROP_LIMIT_MONITORING_INTERVAL, "limit-monitoring-interval"} - , - {PROP_LOGGING_OBJECT, "logging-object"} - , - {PROP_LOGGING_RECORD, "logging-record"} - , - {PROP_PRESCALE, "prescale"} - , - {PROP_PULSE_RATE, "pulse-rate"} - , - {PROP_SCALE, "scale"} - , - {PROP_SCALE_FACTOR, "scale-factor"} - , - {PROP_UPDATE_TIME, "update-time"} - , - {PROP_VALUE_BEFORE_CHANGE, "value-before-change"} - , - {PROP_VALUE_SET, "value-set"} - , - {PROP_VALUE_CHANGE_TIME, "value-change-time"} - , - {PROP_ALIGN_INTERVALS, "align-intervals"} - , - {PROP_INTERVAL_OFFSET, "interval-offset"} - , - {PROP_LAST_RESTART_REASON, "last-restart-reason"} - , - {PROP_LOGGING_TYPE, "logging-type"} - , - {PROP_TIME_OF_DEVICE_RESTART, "time-of-device-restart"} - , - {PROP_TIME_SYNCHRONIZATION_INTERVAL, "time-synchronization-interval"} - , - {PROP_TRIGGER, "trigger"} - , + "list-of-object-property-references"}, + {PROP_LIST_OF_SESSION_KEYS, "list-of-session-keys"}, + {PROP_LOCAL_DATE, "local-date"}, + {PROP_LOCAL_TIME, "local-time"}, + {PROP_LOCATION, "location"}, + {PROP_LOW_LIMIT, "low-limit"}, + {PROP_MANIPULATED_VARIABLE_REFERENCE, "manipulated-variable-reference"}, + {PROP_MAXIMUM_OUTPUT, "maximum-output"}, + {PROP_MAX_APDU_LENGTH_ACCEPTED, "max-apdu-length-accepted"}, + {PROP_MAX_INFO_FRAMES, "max-info-frames"}, + {PROP_MAX_MASTER, "max-master"}, + {PROP_MAX_PRES_VALUE, "max-pres-value"}, + {PROP_MINIMUM_OFF_TIME, "minimum-off-time"}, + {PROP_MINIMUM_ON_TIME, "minimum-on-time"}, + {PROP_MINIMUM_OUTPUT, "minimum-output"}, + {PROP_MIN_PRES_VALUE, "min-pres-value"}, + {PROP_MODEL_NAME, "model-name"}, + {PROP_MODIFICATION_DATE, "modification-date"}, + {PROP_NOTIFY_TYPE, "notify-type"}, + {PROP_NUMBER_OF_APDU_RETRIES, "number-of-APDU-retries"}, + {PROP_NUMBER_OF_STATES, "number-of-states"}, + {PROP_OBJECT_IDENTIFIER, "object-identifier"}, + {PROP_OBJECT_LIST, "object-list"}, + {PROP_OBJECT_NAME, "object-name"}, + {PROP_OBJECT_PROPERTY_REFERENCE, "object-property-reference"}, + {PROP_OBJECT_TYPE, "object-type"}, + {PROP_OPTIONAL, "optional"}, + {PROP_OUT_OF_SERVICE, "out-of-service"}, + {PROP_OUTPUT_UNITS, "output-units"}, + {PROP_EVENT_PARAMETERS, "event-parameters"}, + {PROP_POLARITY, "polarity"}, + {PROP_PRESENT_VALUE, "present-value"}, + {PROP_PRIORITY, "priority"}, + {PROP_PRIORITY_ARRAY, "priority-array"}, + {PROP_PRIORITY_FOR_WRITING, "priority-for-writing"}, + {PROP_PROCESS_IDENTIFIER, "process-identifier"}, + {PROP_PROGRAM_CHANGE, "program-change"}, + {PROP_PROGRAM_LOCATION, "program-location"}, + {PROP_PROGRAM_STATE, "program-state"}, + {PROP_PROPORTIONAL_CONSTANT, "proportional-constant"}, + {PROP_PROPORTIONAL_CONSTANT_UNITS, "proportional-constant-units"}, + {PROP_PROTOCOL_CONFORMANCE_CLASS, "protocol-conformance-class"}, + {PROP_PROTOCOL_OBJECT_TYPES_SUPPORTED, "protocol-object-types-supported"}, + {PROP_PROTOCOL_SERVICES_SUPPORTED, "protocol-services-supported"}, + {PROP_PROTOCOL_VERSION, "protocol-version"}, + {PROP_READ_ONLY, "read-only"}, + {PROP_REASON_FOR_HALT, "reason-for-halt"}, + {PROP_RECIPIENT, "recipient"}, + {PROP_RECIPIENT_LIST, "recipient-list"}, + {PROP_RELIABILITY, "reliability"}, + {PROP_RELINQUISH_DEFAULT, "relinquish-default"}, + {PROP_REQUIRED, "required"}, + {PROP_RESOLUTION, "resolution"}, + {PROP_SEGMENTATION_SUPPORTED, "segmentation-supported"}, + {PROP_SETPOINT, "setpoint"}, + {PROP_SETPOINT_REFERENCE, "setpoint-reference"}, + {PROP_STATE_TEXT, "state-text"}, + {PROP_STATUS_FLAGS, "status-flags"}, + {PROP_SYSTEM_STATUS, "system-status"}, + {PROP_TIME_DELAY, "time-delay"}, + {PROP_TIME_OF_ACTIVE_TIME_RESET, "time-of-active-time-reset"}, + {PROP_TIME_OF_STATE_COUNT_RESET, "time-of-state-count-reset"}, + {PROP_TIME_SYNCHRONIZATION_RECIPIENTS, "time-synchronization-recipients"}, + {PROP_UNITS, "units"}, + {PROP_UPDATE_INTERVAL, "update-interval"}, + {PROP_UTC_OFFSET, "utc-offset"}, + {PROP_VENDOR_IDENTIFIER, "vendor-identifier"}, + {PROP_VENDOR_NAME, "vendor-name"}, + {PROP_VT_CLASSES_SUPPORTED, "vt-classes-supported"}, + {PROP_WEEKLY_SCHEDULE, "weekly-schedule"}, + {PROP_ATTEMPTED_SAMPLES, "attempted-samples"}, + {PROP_AVERAGE_VALUE, "average-value"}, + {PROP_BUFFER_SIZE, "buffer-size"}, + {PROP_CLIENT_COV_INCREMENT, "client-cov-increment"}, + {PROP_COV_RESUBSCRIPTION_INTERVAL, "cov-resubscription-interval"}, + {PROP_CURRENT_NOTIFY_TIME, "current-notify-time"}, + {PROP_EVENT_TIME_STAMPS, "event-time-stamps"}, + {PROP_LOG_BUFFER, "log-buffer"}, + {PROP_LOG_DEVICE_OBJECT_PROPERTY, "log-device-object-property"}, + {PROP_ENABLE, "enable"}, + {PROP_LOG_INTERVAL, "log-interval"}, + {PROP_MAXIMUM_VALUE, "maximum-value"}, + {PROP_MINIMUM_VALUE, "minimum-value"}, + {PROP_NOTIFICATION_THRESHOLD, "notification-threshold"}, + {PROP_PREVIOUS_NOTIFY_TIME, "previous-notify-time"}, + {PROP_PROTOCOL_REVISION, "protocol-revision"}, + {PROP_RECORDS_SINCE_NOTIFICATION, "records-since-notification"}, + {PROP_RECORD_COUNT, "record-count"}, + {PROP_START_TIME, "start-time"}, + {PROP_STOP_TIME, "stop-time"}, + {PROP_STOP_WHEN_FULL, "stop-when-full"}, + {PROP_TOTAL_RECORD_COUNT, "total-record-count"}, + {PROP_VALID_SAMPLES, "valid-samples"}, + {PROP_WINDOW_INTERVAL, "window-interval"}, + {PROP_WINDOW_SAMPLES, "window-samples"}, + {PROP_MAXIMUM_VALUE_TIMESTAMP, "maximum-value-timestamp"}, + {PROP_MINIMUM_VALUE_TIMESTAMP, "minimum-value-timestamp"}, + {PROP_VARIANCE_VALUE, "variance-value"}, + {PROP_ACTIVE_COV_SUBSCRIPTIONS, "active-cov-subscriptions"}, + {PROP_BACKUP_FAILURE_TIMEOUT, "backup-failure-timeout"}, + {PROP_CONFIGURATION_FILES, "configuration-files"}, + {PROP_DATABASE_REVISION, "database-revision"}, + {PROP_DIRECT_READING, "direct-reading"}, + {PROP_LAST_RESTORE_TIME, "last-restore-time"}, + {PROP_MAINTENANCE_REQUIRED, "maintenance-required"}, + {PROP_MEMBER_OF, "member-of"}, + {PROP_MODE, "mode"}, + {PROP_OPERATION_EXPECTED, "operation-expected"}, + {PROP_SETTING, "setting"}, + {PROP_SILENCED, "silenced"}, + {PROP_TRACKING_VALUE, "tracking-value"}, + {PROP_ZONE_MEMBERS, "zone-members"}, + {PROP_LIFE_SAFETY_ALARM_VALUES, "life-safety-alarm-values"}, + {PROP_MAX_SEGMENTS_ACCEPTED, "max-segments-accepted"}, + {PROP_PROFILE_NAME, "profile-name"}, + {PROP_AUTO_SLAVE_DISCOVERY, "auto-slave-discovery"}, + {PROP_MANUAL_SLAVE_ADDRESS_BINDING, "manual-slave-address-binding"}, + {PROP_SLAVE_ADDRESS_BINDING, "slave-address-binding"}, + {PROP_SLAVE_PROXY_ENABLE, "slave-proxy-enable"}, + {PROP_LAST_NOTIFY_RECORD, "last-notify-record"}, + {PROP_SCHEDULE_DEFAULT, "schedule-default"}, + {PROP_ACCEPTED_MODES, "accepted-modes"}, + {PROP_ADJUST_VALUE, "adjust-value"}, + {PROP_COUNT, "count"}, + {PROP_COUNT_BEFORE_CHANGE, "count-before-change"}, + {PROP_COUNT_CHANGE_TIME, "count-change-time"}, + {PROP_COV_PERIOD, "COV-period"}, + {PROP_INPUT_REFERENCE, "input-reference"}, + {PROP_LIMIT_MONITORING_INTERVAL, "limit-monitoring-interval"}, + {PROP_LOGGING_OBJECT, "logging-object"}, + {PROP_LOGGING_RECORD, "logging-record"}, + {PROP_PRESCALE, "prescale"}, + {PROP_PULSE_RATE, "pulse-rate"}, + {PROP_SCALE, "scale"}, + {PROP_SCALE_FACTOR, "scale-factor"}, + {PROP_UPDATE_TIME, "update-time"}, + {PROP_VALUE_BEFORE_CHANGE, "value-before-change"}, + {PROP_VALUE_SET, "value-set"}, + {PROP_VALUE_CHANGE_TIME, "value-change-time"}, + {PROP_ALIGN_INTERVALS, "align-intervals"}, + {PROP_INTERVAL_OFFSET, "interval-offset"}, + {PROP_LAST_RESTART_REASON, "last-restart-reason"}, + {PROP_LOGGING_TYPE, "logging-type"}, + {PROP_TIME_OF_DEVICE_RESTART, "time-of-device-restart"}, + {PROP_TIME_SYNCHRONIZATION_INTERVAL, "time-synchronization-interval"}, + {PROP_TRIGGER, "trigger"}, {PROP_UTC_TIME_SYNCHRONIZATION_RECIPIENTS, - "utc-time-synchronization-recipients"} - , - {PROP_NODE_SUBTYPE, "node-subtype"} - , - {PROP_NODE_TYPE, "node-type"} - , - {PROP_STRUCTURED_OBJECT_LIST, "structured-object-list"} - , - {PROP_SUBORDINATE_ANNOTATIONS, "subordinate-annotations"} - , - {PROP_SUBORDINATE_LIST, "subordinate-list"} - , - {PROP_ACTUAL_SHED_LEVEL, "actual-shed-level"} - , - {PROP_DUTY_WINDOW, "duty-window"} - , - {PROP_EXPECTED_SHED_LEVEL, "expected-shed-level"} - , - {PROP_FULL_DUTY_BASELINE, "full-duty-baseline"} - , - {PROP_REQUESTED_SHED_LEVEL, "requested-shed-level"} - , - {PROP_SHED_DURATION, "shed-duration"} - , - {PROP_SHED_LEVEL_DESCRIPTIONS, "shed-level-descriptions"} - , - {PROP_SHED_LEVELS, "shed-levels"} - , - {PROP_STATE_DESCRIPTION, "state-description"} - , - {PROP_DOOR_ALARM_STATE, "door-alarm-state"} - , - {PROP_DOOR_EXTENDED_PULSE_TIME, "door-extended-pulse-time"} - , - {PROP_DOOR_MEMBERS, "door-members"} - , - {PROP_DOOR_OPEN_TOO_LONG_TIME, "door-open-too-long-time"} - , - {PROP_DOOR_PULSE_TIME, "door-pulse-time"} - , - {PROP_DOOR_STATUS, "door-status"} - , - {PROP_DOOR_UNLOCK_DELAY_TIME, "door-unlock-delay-time"} - , - {PROP_LOCK_STATUS, "lock-status"} - , - {PROP_MASKED_ALARM_VALUES, "masked-alarm-values"} - , - {PROP_SECURED_STATUS, "secured-status"} - , - {PROP_ABSENTEE_LIMIT, "absentee-limit"} - , - {PROP_ACCESS_ALARM_EVENTS, "access-alarm-events"} - , - {PROP_ACCESS_DOORS, "access-doors"} - , - {PROP_ACCESS_EVENT, "access-event"} - , + "utc-time-synchronization-recipients"}, + {PROP_NODE_SUBTYPE, "node-subtype"}, + {PROP_NODE_TYPE, "node-type"}, + {PROP_STRUCTURED_OBJECT_LIST, "structured-object-list"}, + {PROP_SUBORDINATE_ANNOTATIONS, "subordinate-annotations"}, + {PROP_SUBORDINATE_LIST, "subordinate-list"}, + {PROP_ACTUAL_SHED_LEVEL, "actual-shed-level"}, + {PROP_DUTY_WINDOW, "duty-window"}, + {PROP_EXPECTED_SHED_LEVEL, "expected-shed-level"}, + {PROP_FULL_DUTY_BASELINE, "full-duty-baseline"}, + {PROP_REQUESTED_SHED_LEVEL, "requested-shed-level"}, + {PROP_SHED_DURATION, "shed-duration"}, + {PROP_SHED_LEVEL_DESCRIPTIONS, "shed-level-descriptions"}, + {PROP_SHED_LEVELS, "shed-levels"}, + {PROP_STATE_DESCRIPTION, "state-description"}, + {PROP_DOOR_ALARM_STATE, "door-alarm-state"}, + {PROP_DOOR_EXTENDED_PULSE_TIME, "door-extended-pulse-time"}, + {PROP_DOOR_MEMBERS, "door-members"}, + {PROP_DOOR_OPEN_TOO_LONG_TIME, "door-open-too-long-time"}, + {PROP_DOOR_PULSE_TIME, "door-pulse-time"}, + {PROP_DOOR_STATUS, "door-status"}, + {PROP_DOOR_UNLOCK_DELAY_TIME, "door-unlock-delay-time"}, + {PROP_LOCK_STATUS, "lock-status"}, + {PROP_MASKED_ALARM_VALUES, "masked-alarm-values"}, + {PROP_SECURED_STATUS, "secured-status"}, + {PROP_ABSENTEE_LIMIT, "absentee-limit"}, + {PROP_ACCESS_ALARM_EVENTS, "access-alarm-events"}, + {PROP_ACCESS_DOORS, "access-doors"}, + {PROP_ACCESS_EVENT, "access-event"}, {PROP_ACCESS_EVENT_AUTHENTICATION_FACTOR, - "access-event-authentication-factor"} - , - {PROP_ACCESS_EVENT_CREDENTIAL, "access-event-credential"} - , - {PROP_ACCESS_EVENT_TIME, "access-event-time"} - , - {PROP_ACCESS_TRANSACTION_EVENTS, "access-transaction-events"} - , - {PROP_ACCOMPANIMENT, "accompaniment"} - , - {PROP_ACCOMPANIMENT_TIME, "accompaniment-time"} - , - {PROP_ACTIVATION_TIME, "activation-time"} - , - {PROP_ACTIVE_AUTHENTICATION_POLICY, "active-authentication-policy"} - , - {PROP_ASSIGNED_ACCESS_RIGHTS, "assigned-access-rights"} - , - {PROP_AUTHENTICATION_FACTORS, "authentication-factors"} - , - {PROP_AUTHENTICATION_POLICY_LIST, "authentication-policy-list"} - , - {PROP_AUTHENTICATION_POLICY_NAMES, "authentication-policy-names"} - , - {PROP_AUTHENTICATION_STATUS, "authentication-status"} - , - {PROP_AUTHORIZATION_MODE, "authorization-mode"} - , - {PROP_BELONGS_TO, "belongs-to"} - , - {PROP_CREDENTIAL_DISABLE, "credential-disable"} - , - {PROP_CREDENTIAL_STATUS, "credential-status"} - , - {PROP_CREDENTIALS, "credentials"} - , - {PROP_CREDENTIALS_IN_ZONE, "credentials-in-zone"} - , - {PROP_DAYS_REMAINING, "days-remaining"} - , - {PROP_ENTRY_POINTS, "entry-points"} - , - {PROP_EXIT_POINTS, "exit-points"} - , - {PROP_EXPIRATION_TIME, "expiration-time"} - , - {PROP_EXTENDED_TIME_ENABLE, "extended-time-enable"} - , - {PROP_FAILED_ATTEMPT_EVENTS, "failed-attempt-events"} - , - {PROP_FAILED_ATTEMPTS, "failed-attempts"} - , - {PROP_FAILED_ATTEMPTS_TIME, "failed-attempts-time"} - , - {PROP_LAST_ACCESS_EVENT, "last-access-event"} - , - {PROP_LAST_ACCESS_POINT, "last-access-point"} - , - {PROP_LAST_CREDENTIAL_ADDED, "last-credential-added"} - , - {PROP_LAST_CREDENTIAL_ADDED_TIME, "last-credential-added-time"} - , - {PROP_LAST_CREDENTIAL_REMOVED, "last-credential-removed"} - , - {PROP_LAST_CREDENTIAL_REMOVED_TIME, "last-credential-removed-time"} - , - {PROP_LAST_USE_TIME, "last-use-time"} - , - {PROP_LOCKOUT, "lockout"} - , - {PROP_LOCKOUT_RELINQUISH_TIME, "lockout-relinquish-time"} - , - {PROP_MASTER_EXEMPTION, "master-exemption"} - , - {PROP_MAX_FAILED_ATTEMPTS, "max-failed-attempts"} - , - {PROP_MEMBERS, "members"} - , - {PROP_MUSTER_POINT, "muster-point"} - , - {PROP_NEGATIVE_ACCESS_RULES, "negative-access-rules"} - , + "access-event-authentication-factor"}, + {PROP_ACCESS_EVENT_CREDENTIAL, "access-event-credential"}, + {PROP_ACCESS_EVENT_TIME, "access-event-time"}, + {PROP_ACCESS_TRANSACTION_EVENTS, "access-transaction-events"}, + {PROP_ACCOMPANIMENT, "accompaniment"}, + {PROP_ACCOMPANIMENT_TIME, "accompaniment-time"}, + {PROP_ACTIVATION_TIME, "activation-time"}, + {PROP_ACTIVE_AUTHENTICATION_POLICY, "active-authentication-policy"}, + {PROP_ASSIGNED_ACCESS_RIGHTS, "assigned-access-rights"}, + {PROP_AUTHENTICATION_FACTORS, "authentication-factors"}, + {PROP_AUTHENTICATION_POLICY_LIST, "authentication-policy-list"}, + {PROP_AUTHENTICATION_POLICY_NAMES, "authentication-policy-names"}, + {PROP_AUTHENTICATION_STATUS, "authentication-status"}, + {PROP_AUTHORIZATION_MODE, "authorization-mode"}, + {PROP_BELONGS_TO, "belongs-to"}, + {PROP_CREDENTIAL_DISABLE, "credential-disable"}, + {PROP_CREDENTIAL_STATUS, "credential-status"}, + {PROP_CREDENTIALS, "credentials"}, + {PROP_CREDENTIALS_IN_ZONE, "credentials-in-zone"}, + {PROP_DAYS_REMAINING, "days-remaining"}, + {PROP_ENTRY_POINTS, "entry-points"}, + {PROP_EXIT_POINTS, "exit-points"}, + {PROP_EXPIRATION_TIME, "expiration-time"}, + {PROP_EXTENDED_TIME_ENABLE, "extended-time-enable"}, + {PROP_FAILED_ATTEMPT_EVENTS, "failed-attempt-events"}, + {PROP_FAILED_ATTEMPTS, "failed-attempts"}, + {PROP_FAILED_ATTEMPTS_TIME, "failed-attempts-time"}, + {PROP_LAST_ACCESS_EVENT, "last-access-event"}, + {PROP_LAST_ACCESS_POINT, "last-access-point"}, + {PROP_LAST_CREDENTIAL_ADDED, "last-credential-added"}, + {PROP_LAST_CREDENTIAL_ADDED_TIME, "last-credential-added-time"}, + {PROP_LAST_CREDENTIAL_REMOVED, "last-credential-removed"}, + {PROP_LAST_CREDENTIAL_REMOVED_TIME, "last-credential-removed-time"}, + {PROP_LAST_USE_TIME, "last-use-time"}, + {PROP_LOCKOUT, "lockout"}, + {PROP_LOCKOUT_RELINQUISH_TIME, "lockout-relinquish-time"}, + {PROP_MASTER_EXEMPTION, "master-exemption"}, + {PROP_MAX_FAILED_ATTEMPTS, "max-failed-attempts"}, + {PROP_MEMBERS, "members"}, + {PROP_MUSTER_POINT, "muster-point"}, + {PROP_NEGATIVE_ACCESS_RULES, "negative-access-rules"}, {PROP_NUMBER_OF_AUTHENTICATION_POLICIES, - "number-of-authentication-policies"} - , - {PROP_OCCUPANCY_COUNT, "occupancy-count"} - , - {PROP_OCCUPANCY_COUNT_ADJUST, "occupancy-count-adjust"} - , - {PROP_OCCUPANCY_COUNT_ENABLE, "occupancy-count-enable"} - , - {PROP_OCCUPANCY_EXEMPTION, "occupancy-exemption"} - , - {PROP_OCCUPANCY_LOWER_LIMIT, "occupancy-lower-limit"} - , - {PROP_OCCUPANCY_LOWER_LIMIT_ENFORCED, - "occupancy-lower-limit-enforced"} - , - {PROP_OCCUPANCY_STATE, "occupancy-state"} - , - {PROP_OCCUPANCY_UPPER_LIMIT, "occupancy-upper-limit"} - , - {PROP_OCCUPANCY_UPPER_LIMIT_ENFORCED, "occupancy-upper-limit-enforced"} - , - {PROP_PASSBACK_EXEMPTION, "passback-exemption"} - , - {PROP_PASSBACK_MODE, "passback-mode"} - , - {PROP_PASSBACK_TIMEOUT, "passback-timeout"} - , - {PROP_POSITIVE_ACCESS_RULES, "positive-access-rules"} - , - {PROP_REASON_FOR_DISABLE, "reason-for-disable"} - , - {PROP_SUPPORTED_FORMATS, "supported-formats"} - , - {PROP_SUPPORTED_FORMAT_CLASSES, "supported-format-classes"} - , - {PROP_THREAT_AUTHORITY, "threat-authority"} - , - {PROP_THREAT_LEVEL, "threat-level"} - , - {PROP_TRACE_FLAG, "trace-flag"} - , - {PROP_TRANSACTION_NOTIFICATION_CLASS, "transaction-notification-class"} - , - {PROP_USER_EXTERNAL_IDENTIFIER, "user-external-identifier"} - , - {PROP_USER_INFORMATION_REFERENCE, "user-information-reference"} - , - {PROP_USER_INFORMATION_REFERENCE, "user-information-reference"} - , - {PROP_USER_NAME, "user-name"} - , - {PROP_USER_TYPE, "user-type"} - , - {PROP_USES_REMAINING, "uses-remaining"} - , - {PROP_ZONE_FROM, "zone-from"} - , - {PROP_ZONE_TO, "zone-to"} - , - {PROP_VERIFICATION_TIME, "verification-time"} - , - {PROP_BASE_DEVICE_SECURITY_POLICY, "base-device-security-policy"} - , - {PROP_DISTRIBUTION_KEY_REVISION, "distribution-key-revision"} - , - {PROP_DO_NOT_HIDE, "do-not-hide"} - , - {PROP_KEY_SETS, "key-sets"} - , - {PROP_LAST_KEY_SERVER, "last-key-server"} - , - {PROP_NETWORK_ACCESS_SECURITY_POLICIES, - "network-access-security-policies"} - , - {PROP_PACKET_REORDER_TIME, "packet-reorder-time"} - , - {PROP_SECURITY_PDU_TIMEOUT, "security-pdu-timeout"} - , - {PROP_SECURITY_TIME_WINDOW, "security-time-window"} - , - {PROP_SUPPORTED_SECURITY_ALGORITHM, "supported-security-algorithm"} - , - {PROP_UPDATE_KEY_SET_TIMEOUT, "update-key-set-timeout"} - , - {PROP_BACKUP_AND_RESTORE_STATE, "backup-and-restore-state"} - , - {PROP_BACKUP_PREPARATION_TIME, "backup-preparation-time"} - , - {PROP_RESTORE_COMPLETION_TIME, "restore-completion-time"} - , - {PROP_RESTORE_PREPARATION_TIME, "restore-preparation-time"} - , - {PROP_BIT_MASK, "bit-mask"} - , - {PROP_BIT_TEXT, "bit-text"} - , - {PROP_IS_UTC, "is-utc"} - , - {PROP_GROUP_MEMBERS, "group-members"} - , - {PROP_GROUP_MEMBER_NAMES, "group-member-names"} - , - {PROP_MEMBER_STATUS_FLAGS, "member-status-flags"} - , - {PROP_REQUESTED_UPDATE_INTERVAL, "requested-update-interval"} - , - {PROP_COVU_PERIOD, "covu-period"} - , - {PROP_COVU_RECIPIENTS, "covu-recipients"} - , - {PROP_EVENT_MESSAGE_TEXTS, "event-message-texts"} - , - {PROP_EVENT_MESSAGE_TEXTS_CONFIG, "event-message-texts-config"} - , - {PROP_EVENT_DETECTION_ENABLE, "event-detection-enable"} - , - {PROP_EVENT_ALGORITHM_INHIBIT, "event-algorithm-inhibit"} - , - {PROP_EVENT_ALGORITHM_INHIBIT_REF, "event-algorithm-inhibit-ref"} - , - {PROP_TIME_DELAY_NORMAL, "time-delay-normal"} - , - {PROP_RELIABILITY_EVALUATION_INHIBIT, "reliability-evaluation-inhibit"} - , - {PROP_FAULT_PARAMETERS, "fault-parameters"} - , - {PROP_FAULT_TYPE, "fault-type"} - , - {PROP_LOCAL_FORWARDING_ONLY, "local-forwarding-only"} - , - {PROP_PROCESS_IDENTIFIER_FILTER, "process-identifier-filter"} - , - {PROP_SUBSCRIBED_RECIPIENTS, "subscribed-recipients"} - , - {PROP_PORT_FILTER, "port-filter"} - , - {PROP_AUTHORIZATION_EXEMPTIONS, "authorization-exemptions"} - , - {PROP_ALLOW_GROUP_DELAY_INHIBIT, "allow-group-delay-inhibit"} - , - {PROP_CHANNEL_NUMBER, "channel-number"} - , - {PROP_CONTROL_GROUPS, "control-groups"} - , - {PROP_EXECUTION_DELAY, "execution-delay"} - , - {PROP_LAST_PRIORITY, "last-priority"} - , - {PROP_WRITE_STATUS, "write-status"} - , - {PROP_PROPERTY_LIST, "property-list"} - , - {PROP_SERIAL_NUMBER, "serial-number"} - , - {PROP_BLINK_WARN_ENABLE, "blink-warn-enable"} - , - {PROP_DEFAULT_FADE_TIME, "default-fade-time"} - , - {PROP_DEFAULT_RAMP_RATE, "default-ramp-rate"} - , - {PROP_DEFAULT_STEP_INCREMENT, "default-step-increment"} - , - {PROP_EGRESS_TIME, "egress-time"} - , - {PROP_IN_PROGRESS, "in-progress"} - , - {PROP_INSTANTANEOUS_POWER, "instantaneous-power"} - , - {PROP_LIGHTING_COMMAND, "lighting-command"} - , + "number-of-authentication-policies"}, + {PROP_OCCUPANCY_COUNT, "occupancy-count"}, + {PROP_OCCUPANCY_COUNT_ADJUST, "occupancy-count-adjust"}, + {PROP_OCCUPANCY_COUNT_ENABLE, "occupancy-count-enable"}, + {PROP_OCCUPANCY_EXEMPTION, "occupancy-exemption"}, + {PROP_OCCUPANCY_LOWER_LIMIT, "occupancy-lower-limit"}, + {PROP_OCCUPANCY_LOWER_LIMIT_ENFORCED, "occupancy-lower-limit-enforced"}, + {PROP_OCCUPANCY_STATE, "occupancy-state"}, + {PROP_OCCUPANCY_UPPER_LIMIT, "occupancy-upper-limit"}, + {PROP_OCCUPANCY_UPPER_LIMIT_ENFORCED, "occupancy-upper-limit-enforced"}, + {PROP_PASSBACK_EXEMPTION, "passback-exemption"}, + {PROP_PASSBACK_MODE, "passback-mode"}, + {PROP_PASSBACK_TIMEOUT, "passback-timeout"}, + {PROP_POSITIVE_ACCESS_RULES, "positive-access-rules"}, + {PROP_REASON_FOR_DISABLE, "reason-for-disable"}, + {PROP_SUPPORTED_FORMATS, "supported-formats"}, + {PROP_SUPPORTED_FORMAT_CLASSES, "supported-format-classes"}, + {PROP_THREAT_AUTHORITY, "threat-authority"}, + {PROP_THREAT_LEVEL, "threat-level"}, + {PROP_TRACE_FLAG, "trace-flag"}, + {PROP_TRANSACTION_NOTIFICATION_CLASS, "transaction-notification-class"}, + {PROP_USER_EXTERNAL_IDENTIFIER, "user-external-identifier"}, + {PROP_USER_INFORMATION_REFERENCE, "user-information-reference"}, + {PROP_USER_INFORMATION_REFERENCE, "user-information-reference"}, + {PROP_USER_NAME, "user-name"}, + {PROP_USER_TYPE, "user-type"}, + {PROP_USES_REMAINING, "uses-remaining"}, + {PROP_ZONE_FROM, "zone-from"}, + {PROP_ZONE_TO, "zone-to"}, + {PROP_VERIFICATION_TIME, "verification-time"}, + {PROP_BASE_DEVICE_SECURITY_POLICY, "base-device-security-policy"}, + {PROP_DISTRIBUTION_KEY_REVISION, "distribution-key-revision"}, + {PROP_DO_NOT_HIDE, "do-not-hide"}, + {PROP_KEY_SETS, "key-sets"}, + {PROP_LAST_KEY_SERVER, "last-key-server"}, + {PROP_NETWORK_ACCESS_SECURITY_POLICIES, "network-access-security-policies"}, + {PROP_PACKET_REORDER_TIME, "packet-reorder-time"}, + {PROP_SECURITY_PDU_TIMEOUT, "security-pdu-timeout"}, + {PROP_SECURITY_TIME_WINDOW, "security-time-window"}, + {PROP_SUPPORTED_SECURITY_ALGORITHM, "supported-security-algorithm"}, + {PROP_UPDATE_KEY_SET_TIMEOUT, "update-key-set-timeout"}, + {PROP_BACKUP_AND_RESTORE_STATE, "backup-and-restore-state"}, + {PROP_BACKUP_PREPARATION_TIME, "backup-preparation-time"}, + {PROP_RESTORE_COMPLETION_TIME, "restore-completion-time"}, + {PROP_RESTORE_PREPARATION_TIME, "restore-preparation-time"}, + {PROP_BIT_MASK, "bit-mask"}, + {PROP_BIT_TEXT, "bit-text"}, + {PROP_IS_UTC, "is-utc"}, + {PROP_GROUP_MEMBERS, "group-members"}, + {PROP_GROUP_MEMBER_NAMES, "group-member-names"}, + {PROP_MEMBER_STATUS_FLAGS, "member-status-flags"}, + {PROP_REQUESTED_UPDATE_INTERVAL, "requested-update-interval"}, + {PROP_COVU_PERIOD, "covu-period"}, + {PROP_COVU_RECIPIENTS, "covu-recipients"}, + {PROP_EVENT_MESSAGE_TEXTS, "event-message-texts"}, + {PROP_EVENT_MESSAGE_TEXTS_CONFIG, "event-message-texts-config"}, + {PROP_EVENT_DETECTION_ENABLE, "event-detection-enable"}, + {PROP_EVENT_ALGORITHM_INHIBIT, "event-algorithm-inhibit"}, + {PROP_EVENT_ALGORITHM_INHIBIT_REF, "event-algorithm-inhibit-ref"}, + {PROP_TIME_DELAY_NORMAL, "time-delay-normal"}, + {PROP_RELIABILITY_EVALUATION_INHIBIT, "reliability-evaluation-inhibit"}, + {PROP_FAULT_PARAMETERS, "fault-parameters"}, + {PROP_FAULT_TYPE, "fault-type"}, + {PROP_LOCAL_FORWARDING_ONLY, "local-forwarding-only"}, + {PROP_PROCESS_IDENTIFIER_FILTER, "process-identifier-filter"}, + {PROP_SUBSCRIBED_RECIPIENTS, "subscribed-recipients"}, + {PROP_PORT_FILTER, "port-filter"}, + {PROP_AUTHORIZATION_EXEMPTIONS, "authorization-exemptions"}, + {PROP_ALLOW_GROUP_DELAY_INHIBIT, "allow-group-delay-inhibit"}, + {PROP_CHANNEL_NUMBER, "channel-number"}, + {PROP_CONTROL_GROUPS, "control-groups"}, + {PROP_EXECUTION_DELAY, "execution-delay"}, + {PROP_LAST_PRIORITY, "last-priority"}, + {PROP_WRITE_STATUS, "write-status"}, + {PROP_PROPERTY_LIST, "property-list"}, + {PROP_SERIAL_NUMBER, "serial-number"}, + {PROP_BLINK_WARN_ENABLE, "blink-warn-enable"}, + {PROP_DEFAULT_FADE_TIME, "default-fade-time"}, + {PROP_DEFAULT_RAMP_RATE, "default-ramp-rate"}, + {PROP_DEFAULT_STEP_INCREMENT, "default-step-increment"}, + {PROP_EGRESS_TIME, "egress-time"}, + {PROP_IN_PROGRESS, "in-progress"}, + {PROP_INSTANTANEOUS_POWER, "instantaneous-power"}, + {PROP_LIGHTING_COMMAND, "lighting-command"}, {PROP_LIGHTING_COMMAND_DEFAULT_PRIORITY, - "lighting-command-default-priority"} - , - {PROP_MAX_ACTUAL_VALUE, "max-actual-value"} - , - {PROP_MIN_ACTUAL_VALUE, "min-actual-value"} - , - {PROP_POWER, "power"} - , - {PROP_TRANSITION, "transition"} - , + "lighting-command-default-priority"}, + {PROP_MAX_ACTUAL_VALUE, "max-actual-value"}, + {PROP_MIN_ACTUAL_VALUE, "min-actual-value"}, + {PROP_POWER, "power"}, + {PROP_TRANSITION, "transition"}, {PROP_EGRESS_ACTIVE, "egress-active"}, {PROP_INTERFACE_VALUE, "inteface-value"}, {PROP_FAULT_HIGH_LIMIT, "fault-high-limit"}, @@ -1064,7 +606,8 @@ INDTEXT_DATA bacnet_property_names[] = { {PROP_IP_SUBNET_MASK, "ip-subnet-mask"}, {PROP_BACNET_IP_UDP_PORT, "bacnet-ip-udp-port"}, {PROP_BBMD_ACCEPT_FD_REGISTRATIONS, "bbmd-accept-fd-registrations"}, - {PROP_BBMD_BROADCAST_DISTRIBUTION_TABLE, "bbmd-broadcast-distribution-table"}, + {PROP_BBMD_BROADCAST_DISTRIBUTION_TABLE, + "bbmd-broadcast-distribution-table"}, {PROP_BBMD_FOREIGN_DEVICE_TABLE, "bbmd-foreign-device-table"}, {PROP_CHANGES_PENDING, "changes-pending"}, {PROP_COMMAND, "command"}, @@ -1130,7 +673,8 @@ INDTEXT_DATA bacnet_property_names[] = { {PROP_PASSENGER_ALARM, "passenger-alarm"}, {PROP_POWER_MODE, "power-mode"}, {PROP_REGISTERED_CAR_CALL, "registered-car-call"}, - {PROP_ACTIVE_COV_MULTIPLE_SUBSCRIPTIONS, "active-cov-multiple-subscriptions"}, + {PROP_ACTIVE_COV_MULTIPLE_SUBSCRIPTIONS, + "active-cov-multiple-subscriptions"}, {PROP_PROTOCOL_LEVEL, "protocol-level"}, {PROP_REFERENCE_PORT, "reference-port"}, {PROP_DEPLOYED_PROFILE_LOCATION, "deployed-profile-location"}, @@ -1147,1260 +691,739 @@ INDTEXT_DATA bacnet_property_names[] = { procedures and constraints described in Clause 23. */ }; -const char *bactext_property_name( - unsigned index) +const char *bactext_property_name(unsigned index) { return indtext_by_index_split_default(bacnet_property_names, index, 512, - ASHRAE_Reserved_String, Vendor_Proprietary_String); + ASHRAE_Reserved_String, + Vendor_Proprietary_String); } -const char *bactext_property_name_default( - unsigned index, - const char *default_string) +const char *bactext_property_name_default(unsigned index, + const char *default_string) { return indtext_by_index_default(bacnet_property_names, index, - default_string); + default_string); } -unsigned bactext_property_id( - const char *name) +unsigned bactext_property_id(const char *name) { return indtext_by_istring_default(bacnet_property_names, name, 0); } -bool bactext_property_index( - const char *search_name, - unsigned *found_index) +bool bactext_property_index(const char *search_name, unsigned *found_index) { return indtext_by_istring(bacnet_property_names, search_name, found_index); } INDTEXT_DATA bacnet_engineering_unit_names[] = { - {UNITS_SQUARE_METERS, "square-meters"} - , - {UNITS_SQUARE_FEET, "square-feet"} - , - {UNITS_MILLIAMPERES, "milliamperes"} - , - {UNITS_AMPERES, "amperes"} - , - {UNITS_OHMS, "ohms"} - , - {UNITS_VOLTS, "volts"} - , - {UNITS_KILOVOLTS, "kilovolts"} - , - {UNITS_MEGAVOLTS, "megavolts"} - , - {UNITS_VOLT_AMPERES, "volt-amperes"} - , - {UNITS_KILOVOLT_AMPERES, "kilovolt-amperes"} - , - {UNITS_MEGAVOLT_AMPERES, "megavolt-amperes"} - , - {UNITS_VOLT_AMPERES_REACTIVE, "volt-amperes-reactive"} - , - {UNITS_KILOVOLT_AMPERES_REACTIVE, "kilovolt-amperes-reactive"} - , - {UNITS_MEGAVOLT_AMPERES_REACTIVE, "megavolt-amperes-reactive"} - , - {UNITS_DEGREES_PHASE, "degrees-phase"} - , - {UNITS_POWER_FACTOR, "power-factor"} - , - {UNITS_JOULES, "joules"} - , - {UNITS_KILOJOULES, "kilojoules"} - , - {UNITS_WATT_HOURS, "watt-hours"} - , - {UNITS_KILOWATT_HOURS, "kilowatt-hours"} - , - {UNITS_BTUS, "btus"} - , - {UNITS_THERMS, "therms"} - , - {UNITS_TON_HOURS, "ton-hours"} - , - {UNITS_JOULES_PER_KILOGRAM_DRY_AIR, "joules-per-kilogram-dry-air"} - , - {UNITS_BTUS_PER_POUND_DRY_AIR, "btus-per-pound-dry-air"} - , - {UNITS_CYCLES_PER_HOUR, "cycles-per-hour"} - , - {UNITS_CYCLES_PER_MINUTE, "cycles-per-minute"} - , - {UNITS_HERTZ, "hertz"} - , + {UNITS_SQUARE_METERS, "square-meters"}, + {UNITS_SQUARE_FEET, "square-feet"}, + {UNITS_MILLIAMPERES, "milliamperes"}, + {UNITS_AMPERES, "amperes"}, + {UNITS_OHMS, "ohms"}, + {UNITS_VOLTS, "volts"}, + {UNITS_KILOVOLTS, "kilovolts"}, + {UNITS_MEGAVOLTS, "megavolts"}, + {UNITS_VOLT_AMPERES, "volt-amperes"}, + {UNITS_KILOVOLT_AMPERES, "kilovolt-amperes"}, + {UNITS_MEGAVOLT_AMPERES, "megavolt-amperes"}, + {UNITS_VOLT_AMPERES_REACTIVE, "volt-amperes-reactive"}, + {UNITS_KILOVOLT_AMPERES_REACTIVE, "kilovolt-amperes-reactive"}, + {UNITS_MEGAVOLT_AMPERES_REACTIVE, "megavolt-amperes-reactive"}, + {UNITS_DEGREES_PHASE, "degrees-phase"}, + {UNITS_POWER_FACTOR, "power-factor"}, + {UNITS_JOULES, "joules"}, + {UNITS_KILOJOULES, "kilojoules"}, + {UNITS_WATT_HOURS, "watt-hours"}, + {UNITS_KILOWATT_HOURS, "kilowatt-hours"}, + {UNITS_BTUS, "btus"}, + {UNITS_THERMS, "therms"}, + {UNITS_TON_HOURS, "ton-hours"}, + {UNITS_JOULES_PER_KILOGRAM_DRY_AIR, "joules-per-kilogram-dry-air"}, + {UNITS_BTUS_PER_POUND_DRY_AIR, "btus-per-pound-dry-air"}, + {UNITS_CYCLES_PER_HOUR, "cycles-per-hour"}, + {UNITS_CYCLES_PER_MINUTE, "cycles-per-minute"}, + {UNITS_HERTZ, "hertz"}, {UNITS_GRAMS_OF_WATER_PER_KILOGRAM_DRY_AIR, - "grams-of-water-per-kilogram-dry-air"} - , - {UNITS_PERCENT_RELATIVE_HUMIDITY, "percent-relative-humidity"} - , - {UNITS_MILLIMETERS, "millimeters"} - , - {UNITS_METERS, "meters"} - , - {UNITS_INCHES, "inches"} - , - {UNITS_FEET, "feet"} - , - {UNITS_WATTS_PER_SQUARE_FOOT, "watts-per-square-foot"} - , - {UNITS_WATTS_PER_SQUARE_METER, "watts-per-square-meter"} - , - {UNITS_LUMENS, "lumens"} - , - {UNITS_LUXES, "luxes"} - , - {UNITS_FOOT_CANDLES, "foot-candles"} - , - {UNITS_KILOGRAMS, "kilograms"} - , - {UNITS_POUNDS_MASS, "pounds-mass"} - , - {UNITS_TONS, "tons"} - , - {UNITS_KILOGRAMS_PER_SECOND, "kilograms-per-second"} - , - {UNITS_KILOGRAMS_PER_MINUTE, "kilograms-per-minute"} - , - {UNITS_KILOGRAMS_PER_HOUR, "kilograms-per-hour"} - , - {UNITS_POUNDS_MASS_PER_MINUTE, "pounds-mass-per-minute"} - , - {UNITS_POUNDS_MASS_PER_HOUR, "pounds-mass-per-hour"} - , - {UNITS_WATTS, "watts"} - , - {UNITS_KILOWATTS, "kilowatts"} - , - {UNITS_MEGAWATTS, "megawatts"} - , - {UNITS_BTUS_PER_HOUR, "btus-per-hour"} - , - {UNITS_HORSEPOWER, "horsepower"} - , - {UNITS_TONS_REFRIGERATION, "tons-refrigeration"} - , - {UNITS_PASCALS, "pascals"} - , - {UNITS_KILOPASCALS, "kilopascals"} - , - {UNITS_BARS, "bars"} - , - {UNITS_POUNDS_FORCE_PER_SQUARE_INCH, "pounds-force-per-square-inch"} - , - {UNITS_CENTIMETERS_OF_WATER, "centimeters-of-water"} - , - {UNITS_INCHES_OF_WATER, "inches-of-water"} - , - {UNITS_MILLIMETERS_OF_MERCURY, "millimeters-of-mercury"} - , - {UNITS_CENTIMETERS_OF_MERCURY, "centimeters-of-mercury"} - , - {UNITS_INCHES_OF_MERCURY, "inches-of-mercury"} - , - {UNITS_DEGREES_CELSIUS, "degrees-celsius"} - , - {UNITS_DEGREES_KELVIN, "degrees-kelvin"} - , - {UNITS_DEGREES_FAHRENHEIT, "degrees-fahrenheit"} - , - {UNITS_DEGREE_DAYS_CELSIUS, "degree-days-celsius"} - , - {UNITS_DEGREE_DAYS_FAHRENHEIT, "degree-days-fahrenheit"} - , - {UNITS_YEARS, "years"} - , - {UNITS_MONTHS, "months"} - , - {UNITS_WEEKS, "weeks"} - , - {UNITS_DAYS, "days"} - , - {UNITS_HOURS, "hours"} - , - {UNITS_MINUTES, "minutes"} - , - {UNITS_SECONDS, "seconds"} - , - {UNITS_METERS_PER_SECOND, "meters-per-second"} - , - {UNITS_KILOMETERS_PER_HOUR, "kilometers-per-hour"} - , - {UNITS_FEET_PER_SECOND, "feet-per-second"} - , - {UNITS_FEET_PER_MINUTE, "feet-per-minute"} - , - {UNITS_MILES_PER_HOUR, "miles-per-hour"} - , - {UNITS_CUBIC_FEET, "cubic-feet"} - , - {UNITS_CUBIC_METERS, "cubic-meters"} - , - {UNITS_IMPERIAL_GALLONS, "imperial-gallons"} - , - {UNITS_LITERS, "liters"} - , - {UNITS_US_GALLONS, "us-gallons"} - , - {UNITS_CUBIC_FEET_PER_MINUTE, "cubic-feet-per-minute"} - , - {UNITS_CUBIC_METERS_PER_SECOND, "cubic-meters-per-second"} - , - {UNITS_IMPERIAL_GALLONS_PER_MINUTE, "imperial-gallons-per-minute"} - , - {UNITS_LITERS_PER_SECOND, "liters-per-second"} - , - {UNITS_LITERS_PER_MINUTE, "liters-per-minute"} - , - {UNITS_US_GALLONS_PER_MINUTE, "us-gallons-per-minute"} - , - {UNITS_DEGREES_ANGULAR, "degrees-angular"} - , - {UNITS_DEGREES_CELSIUS_PER_HOUR, "degrees-celsius-per-hour"} - , - {UNITS_DEGREES_CELSIUS_PER_MINUTE, "degrees-celsius-per-minute"} - , - {UNITS_DEGREES_FAHRENHEIT_PER_HOUR, "degrees-fahrenheit-per-hour"} - , - {UNITS_DEGREES_FAHRENHEIT_PER_MINUTE, "degrees-fahrenheit-per-minute"} - , - {UNITS_NO_UNITS, "no-units"} - , - {UNITS_PARTS_PER_MILLION, "parts-per-million"} - , - {UNITS_PARTS_PER_BILLION, "parts-per-billion"} - , - {UNITS_PERCENT, "percent"} - , - {UNITS_PERCENT_PER_SECOND, "percent-per-second"} - , - {UNITS_PER_MINUTE, "per-minute"} - , - {UNITS_PER_SECOND, "per-second"} - , - {UNITS_PSI_PER_DEGREE_FAHRENHEIT, "psi-per-degree-fahrenheit"} - , - {UNITS_RADIANS, "radians"} - , - {UNITS_REVOLUTIONS_PER_MINUTE, "revolutions-per-minute"} - , - {UNITS_CURRENCY1, "currency1"} - , - {UNITS_CURRENCY2, "currency2"} - , - {UNITS_CURRENCY3, "currency3"} - , - {UNITS_CURRENCY4, "currency4"} - , - {UNITS_CURRENCY5, "currency5"} - , - {UNITS_CURRENCY6, "currency6"} - , - {UNITS_CURRENCY7, "currency7"} - , - {UNITS_CURRENCY8, "currency8"} - , - {UNITS_CURRENCY9, "currency9"} - , - {UNITS_CURRENCY10, "currency10"} - , - {UNITS_SQUARE_INCHES, "square-inches"} - , - {UNITS_SQUARE_CENTIMETERS, "square-centimeters"} - , - {UNITS_BTUS_PER_POUND, "btus_per-pound"} - , - {UNITS_CENTIMETERS, "centimeters"} - , - {UNITS_POUNDS_MASS_PER_SECOND, "pounds-mass-per-second"} - , - {UNITS_DELTA_DEGREES_FAHRENHEIT, "delta-degrees-fahrenheit"} - , - {UNITS_DELTA_DEGREES_KELVIN, "delta-degrees-kelvin"} - , - {UNITS_KILOHMS, "kilohms"} - , - {UNITS_MEGOHMS, "megohms"} - , - {UNITS_MILLIVOLTS, "millivolts"} - , - {UNITS_KILOJOULES_PER_KILOGRAM, "kilojoules-per-kilogram"} - , - {UNITS_MEGAJOULES, "megajoules"} - , - {UNITS_JOULES_PER_DEGREE_KELVIN, "joules-per-degree-kelvin"} - , + "grams-of-water-per-kilogram-dry-air"}, + {UNITS_PERCENT_RELATIVE_HUMIDITY, "percent-relative-humidity"}, + {UNITS_MILLIMETERS, "millimeters"}, + {UNITS_METERS, "meters"}, + {UNITS_INCHES, "inches"}, + {UNITS_FEET, "feet"}, + {UNITS_WATTS_PER_SQUARE_FOOT, "watts-per-square-foot"}, + {UNITS_WATTS_PER_SQUARE_METER, "watts-per-square-meter"}, + {UNITS_LUMENS, "lumens"}, + {UNITS_LUXES, "luxes"}, + {UNITS_FOOT_CANDLES, "foot-candles"}, + {UNITS_KILOGRAMS, "kilograms"}, + {UNITS_POUNDS_MASS, "pounds-mass"}, + {UNITS_TONS, "tons"}, + {UNITS_KILOGRAMS_PER_SECOND, "kilograms-per-second"}, + {UNITS_KILOGRAMS_PER_MINUTE, "kilograms-per-minute"}, + {UNITS_KILOGRAMS_PER_HOUR, "kilograms-per-hour"}, + {UNITS_POUNDS_MASS_PER_MINUTE, "pounds-mass-per-minute"}, + {UNITS_POUNDS_MASS_PER_HOUR, "pounds-mass-per-hour"}, + {UNITS_WATTS, "watts"}, + {UNITS_KILOWATTS, "kilowatts"}, + {UNITS_MEGAWATTS, "megawatts"}, + {UNITS_BTUS_PER_HOUR, "btus-per-hour"}, + {UNITS_HORSEPOWER, "horsepower"}, + {UNITS_TONS_REFRIGERATION, "tons-refrigeration"}, + {UNITS_PASCALS, "pascals"}, + {UNITS_KILOPASCALS, "kilopascals"}, + {UNITS_BARS, "bars"}, + {UNITS_POUNDS_FORCE_PER_SQUARE_INCH, "pounds-force-per-square-inch"}, + {UNITS_CENTIMETERS_OF_WATER, "centimeters-of-water"}, + {UNITS_INCHES_OF_WATER, "inches-of-water"}, + {UNITS_MILLIMETERS_OF_MERCURY, "millimeters-of-mercury"}, + {UNITS_CENTIMETERS_OF_MERCURY, "centimeters-of-mercury"}, + {UNITS_INCHES_OF_MERCURY, "inches-of-mercury"}, + {UNITS_DEGREES_CELSIUS, "degrees-celsius"}, + {UNITS_DEGREES_KELVIN, "degrees-kelvin"}, + {UNITS_DEGREES_FAHRENHEIT, "degrees-fahrenheit"}, + {UNITS_DEGREE_DAYS_CELSIUS, "degree-days-celsius"}, + {UNITS_DEGREE_DAYS_FAHRENHEIT, "degree-days-fahrenheit"}, + {UNITS_YEARS, "years"}, + {UNITS_MONTHS, "months"}, + {UNITS_WEEKS, "weeks"}, + {UNITS_DAYS, "days"}, + {UNITS_HOURS, "hours"}, + {UNITS_MINUTES, "minutes"}, + {UNITS_SECONDS, "seconds"}, + {UNITS_METERS_PER_SECOND, "meters-per-second"}, + {UNITS_KILOMETERS_PER_HOUR, "kilometers-per-hour"}, + {UNITS_FEET_PER_SECOND, "feet-per-second"}, + {UNITS_FEET_PER_MINUTE, "feet-per-minute"}, + {UNITS_MILES_PER_HOUR, "miles-per-hour"}, + {UNITS_CUBIC_FEET, "cubic-feet"}, + {UNITS_CUBIC_METERS, "cubic-meters"}, + {UNITS_IMPERIAL_GALLONS, "imperial-gallons"}, + {UNITS_LITERS, "liters"}, + {UNITS_US_GALLONS, "us-gallons"}, + {UNITS_CUBIC_FEET_PER_MINUTE, "cubic-feet-per-minute"}, + {UNITS_CUBIC_METERS_PER_SECOND, "cubic-meters-per-second"}, + {UNITS_IMPERIAL_GALLONS_PER_MINUTE, "imperial-gallons-per-minute"}, + {UNITS_LITERS_PER_SECOND, "liters-per-second"}, + {UNITS_LITERS_PER_MINUTE, "liters-per-minute"}, + {UNITS_US_GALLONS_PER_MINUTE, "us-gallons-per-minute"}, + {UNITS_DEGREES_ANGULAR, "degrees-angular"}, + {UNITS_DEGREES_CELSIUS_PER_HOUR, "degrees-celsius-per-hour"}, + {UNITS_DEGREES_CELSIUS_PER_MINUTE, "degrees-celsius-per-minute"}, + {UNITS_DEGREES_FAHRENHEIT_PER_HOUR, "degrees-fahrenheit-per-hour"}, + {UNITS_DEGREES_FAHRENHEIT_PER_MINUTE, "degrees-fahrenheit-per-minute"}, + {UNITS_NO_UNITS, "no-units"}, + {UNITS_PARTS_PER_MILLION, "parts-per-million"}, + {UNITS_PARTS_PER_BILLION, "parts-per-billion"}, + {UNITS_PERCENT, "percent"}, + {UNITS_PERCENT_PER_SECOND, "percent-per-second"}, + {UNITS_PER_MINUTE, "per-minute"}, + {UNITS_PER_SECOND, "per-second"}, + {UNITS_PSI_PER_DEGREE_FAHRENHEIT, "psi-per-degree-fahrenheit"}, + {UNITS_RADIANS, "radians"}, + {UNITS_REVOLUTIONS_PER_MINUTE, "revolutions-per-minute"}, + {UNITS_CURRENCY1, "currency1"}, + {UNITS_CURRENCY2, "currency2"}, + {UNITS_CURRENCY3, "currency3"}, + {UNITS_CURRENCY4, "currency4"}, + {UNITS_CURRENCY5, "currency5"}, + {UNITS_CURRENCY6, "currency6"}, + {UNITS_CURRENCY7, "currency7"}, + {UNITS_CURRENCY8, "currency8"}, + {UNITS_CURRENCY9, "currency9"}, + {UNITS_CURRENCY10, "currency10"}, + {UNITS_SQUARE_INCHES, "square-inches"}, + {UNITS_SQUARE_CENTIMETERS, "square-centimeters"}, + {UNITS_BTUS_PER_POUND, "btus_per-pound"}, + {UNITS_CENTIMETERS, "centimeters"}, + {UNITS_POUNDS_MASS_PER_SECOND, "pounds-mass-per-second"}, + {UNITS_DELTA_DEGREES_FAHRENHEIT, "delta-degrees-fahrenheit"}, + {UNITS_DELTA_DEGREES_KELVIN, "delta-degrees-kelvin"}, + {UNITS_KILOHMS, "kilohms"}, + {UNITS_MEGOHMS, "megohms"}, + {UNITS_MILLIVOLTS, "millivolts"}, + {UNITS_KILOJOULES_PER_KILOGRAM, "kilojoules-per-kilogram"}, + {UNITS_MEGAJOULES, "megajoules"}, + {UNITS_JOULES_PER_DEGREE_KELVIN, "joules-per-degree-kelvin"}, {UNITS_JOULES_PER_KILOGRAM_DEGREE_KELVIN, - "joules-per-kilogram-degree-kelvin"} - , - {UNITS_KILOHERTZ, "kilohertz"} - , - {UNITS_MEGAHERTZ, "megahertz"} - , - {UNITS_PER_HOUR, "per-hour"} - , - {UNITS_MILLIWATTS, "milliwatts"} - , - {UNITS_HECTOPASCALS, "hectopascals"} - , - {UNITS_MILLIBARS, "millibars"} - , - {UNITS_CUBIC_METERS_PER_HOUR, "cubic-meters-per-hour"} - , - {UNITS_LITERS_PER_HOUR, "liters-per-hour"} - , - {UNITS_KW_HOURS_PER_SQUARE_METER, - "kilowatt-hours-per-square-meter"} - , - {UNITS_KW_HOURS_PER_SQUARE_FOOT, "kilowatt-hours-per-square-foot"} - , - {UNITS_MEGAJOULES_PER_SQUARE_METER, "megajoules-per-square-meter"} - , - {UNITS_MEGAJOULES_PER_SQUARE_FOOT, "megajoules-per-square-foot"} - , - {UNITS_CUBIC_FEET_PER_SECOND, "cubic-feet-per-second"} - , + "joules-per-kilogram-degree-kelvin"}, + {UNITS_KILOHERTZ, "kilohertz"}, + {UNITS_MEGAHERTZ, "megahertz"}, + {UNITS_PER_HOUR, "per-hour"}, + {UNITS_MILLIWATTS, "milliwatts"}, + {UNITS_HECTOPASCALS, "hectopascals"}, + {UNITS_MILLIBARS, "millibars"}, + {UNITS_CUBIC_METERS_PER_HOUR, "cubic-meters-per-hour"}, + {UNITS_LITERS_PER_HOUR, "liters-per-hour"}, + {UNITS_KW_HOURS_PER_SQUARE_METER, "kilowatt-hours-per-square-meter"}, + {UNITS_KW_HOURS_PER_SQUARE_FOOT, "kilowatt-hours-per-square-foot"}, + {UNITS_MEGAJOULES_PER_SQUARE_METER, "megajoules-per-square-meter"}, + {UNITS_MEGAJOULES_PER_SQUARE_FOOT, "megajoules-per-square-foot"}, + {UNITS_CUBIC_FEET_PER_SECOND, "cubic-feet-per-second"}, {UNITS_WATTS_PER_SQUARE_METER_DEGREE_KELVIN, - "watts-per-square-meter-degree-kelvin"} - , - {UNITS_PERCENT_OBSCURATION_PER_FOOT, "percent-obscuration-per-foot"} - , - {UNITS_PERCENT_OBSCURATION_PER_METER, "percent-obscuration-per-meter"} - , - {UNITS_MILLIOHMS, "milliohms"} - , - {UNITS_MEGAWATT_HOURS, "megawatt-hours"} - , - {UNITS_KILO_BTUS, "kilo-btus"} - , - {UNITS_MEGA_BTUS, "mega-btus"} - , - {UNITS_KILOJOULES_PER_KILOGRAM_DRY_AIR, - "kilojoules-per-kilogram-dry-air"} - , - {UNITS_MEGAJOULES_PER_KILOGRAM_DRY_AIR, - "megajoules-per-kilogram-dry-air"} - , - {UNITS_KILOJOULES_PER_DEGREE_KELVIN, "kilojoules-per-degree-Kelvin"} - , - {UNITS_MEGAJOULES_PER_DEGREE_KELVIN, "megajoules-per-degree-Kelvin"} - , - {UNITS_NEWTON, "newton"} - , - {UNITS_GRAMS_PER_SECOND, "grams-per-second"} - , - {UNITS_GRAMS_PER_MINUTE, "grams-per-minute"} - , - {UNITS_TONS_PER_HOUR, "tons-per-hour"} - , - {UNITS_KILO_BTUS_PER_HOUR, "kilo-btus-per-hour"} - , - {UNITS_HUNDREDTHS_SECONDS, "hundredths-seconds"} - , - {UNITS_MILLISECONDS, "milliseconds"} - , - {UNITS_NEWTON_METERS, "newton-meters"} - , - {UNITS_MILLIMETERS_PER_SECOND, "millimeters-per-second"} - , - {UNITS_MILLIMETERS_PER_MINUTE, "millimeters-per-minute"} - , - {UNITS_METERS_PER_MINUTE, "meters-per-minute"} - , - {UNITS_METERS_PER_HOUR, "meters-per-hour"} - , - {UNITS_CUBIC_METERS_PER_MINUTE, "cubic-meters-per-minute"} - , - {UNITS_METERS_PER_SECOND_PER_SECOND, "meters-per-second-per-second"} - , - {UNITS_AMPERES_PER_METER, "amperes-per-meter"} - , - {UNITS_AMPERES_PER_SQUARE_METER, "amperes-per-square-meter"} - , - {UNITS_AMPERE_SQUARE_METERS, "ampere-square-meters"} - , - {UNITS_FARADS, "farads"} - , - {UNITS_HENRYS, "henrys"} - , - {UNITS_OHM_METERS, "ohm-meters"} - , - {UNITS_SIEMENS, "siemens"} - , - {UNITS_SIEMENS_PER_METER, "siemens-per-meter"} - , - {UNITS_TESLAS, "teslas"} - , - {UNITS_VOLTS_PER_DEGREE_KELVIN, "volts-per-degree-Kelvin"} - , - {UNITS_VOLTS_PER_METER, "volts-per-meter"} - , - {UNITS_WEBERS, "webers"} - , - {UNITS_CANDELAS, "candelas"} - , - {UNITS_CANDELAS_PER_SQUARE_METER, "candelas-per-square-meter"} - , - {UNITS_DEGREES_KELVIN_PER_HOUR, "degrees-Kelvin-per-hour"} - , - {UNITS_DEGREES_KELVIN_PER_MINUTE, "degrees-Kelvin-per-minute"} - , - {UNITS_JOULE_SECONDS, "joule-seconds"} - , - {UNITS_RADIANS_PER_SECOND, "radians-per-second"} - , - {UNITS_SQUARE_METERS_PER_NEWTON, "square-meters-per-Newton"} - , - {UNITS_KILOGRAMS_PER_CUBIC_METER, "kilograms-per-cubic-meter"} - , - {UNITS_NEWTON_SECONDS, "newton-seconds"} - , - {UNITS_NEWTONS_PER_METER, "newtons-per-meter"} - , + "watts-per-square-meter-degree-kelvin"}, + {UNITS_PERCENT_OBSCURATION_PER_FOOT, "percent-obscuration-per-foot"}, + {UNITS_PERCENT_OBSCURATION_PER_METER, "percent-obscuration-per-meter"}, + {UNITS_MILLIOHMS, "milliohms"}, + {UNITS_MEGAWATT_HOURS, "megawatt-hours"}, + {UNITS_KILO_BTUS, "kilo-btus"}, + {UNITS_MEGA_BTUS, "mega-btus"}, + {UNITS_KILOJOULES_PER_KILOGRAM_DRY_AIR, "kilojoules-per-kilogram-dry-air"}, + {UNITS_MEGAJOULES_PER_KILOGRAM_DRY_AIR, "megajoules-per-kilogram-dry-air"}, + {UNITS_KILOJOULES_PER_DEGREE_KELVIN, "kilojoules-per-degree-Kelvin"}, + {UNITS_MEGAJOULES_PER_DEGREE_KELVIN, "megajoules-per-degree-Kelvin"}, + {UNITS_NEWTON, "newton"}, + {UNITS_GRAMS_PER_SECOND, "grams-per-second"}, + {UNITS_GRAMS_PER_MINUTE, "grams-per-minute"}, + {UNITS_TONS_PER_HOUR, "tons-per-hour"}, + {UNITS_KILO_BTUS_PER_HOUR, "kilo-btus-per-hour"}, + {UNITS_HUNDREDTHS_SECONDS, "hundredths-seconds"}, + {UNITS_MILLISECONDS, "milliseconds"}, + {UNITS_NEWTON_METERS, "newton-meters"}, + {UNITS_MILLIMETERS_PER_SECOND, "millimeters-per-second"}, + {UNITS_MILLIMETERS_PER_MINUTE, "millimeters-per-minute"}, + {UNITS_METERS_PER_MINUTE, "meters-per-minute"}, + {UNITS_METERS_PER_HOUR, "meters-per-hour"}, + {UNITS_CUBIC_METERS_PER_MINUTE, "cubic-meters-per-minute"}, + {UNITS_METERS_PER_SECOND_PER_SECOND, "meters-per-second-per-second"}, + {UNITS_AMPERES_PER_METER, "amperes-per-meter"}, + {UNITS_AMPERES_PER_SQUARE_METER, "amperes-per-square-meter"}, + {UNITS_AMPERE_SQUARE_METERS, "ampere-square-meters"}, + {UNITS_FARADS, "farads"}, + {UNITS_HENRYS, "henrys"}, + {UNITS_OHM_METERS, "ohm-meters"}, + {UNITS_SIEMENS, "siemens"}, + {UNITS_SIEMENS_PER_METER, "siemens-per-meter"}, + {UNITS_TESLAS, "teslas"}, + {UNITS_VOLTS_PER_DEGREE_KELVIN, "volts-per-degree-Kelvin"}, + {UNITS_VOLTS_PER_METER, "volts-per-meter"}, + {UNITS_WEBERS, "webers"}, + {UNITS_CANDELAS, "candelas"}, + {UNITS_CANDELAS_PER_SQUARE_METER, "candelas-per-square-meter"}, + {UNITS_DEGREES_KELVIN_PER_HOUR, "degrees-Kelvin-per-hour"}, + {UNITS_DEGREES_KELVIN_PER_MINUTE, "degrees-Kelvin-per-minute"}, + {UNITS_JOULE_SECONDS, "joule-seconds"}, + {UNITS_RADIANS_PER_SECOND, "radians-per-second"}, + {UNITS_SQUARE_METERS_PER_NEWTON, "square-meters-per-Newton"}, + {UNITS_KILOGRAMS_PER_CUBIC_METER, "kilograms-per-cubic-meter"}, + {UNITS_NEWTON_SECONDS, "newton-seconds"}, + {UNITS_NEWTONS_PER_METER, "newtons-per-meter"}, {UNITS_WATTS_PER_METER_PER_DEGREE_KELVIN, - "watts-per-meter-per-degree-Kelvin"} - , - {UNITS_PER_MILLE,"per-mille"}, - {UNITS_GRAMS_PER_GRAM,"grams-per-gram"}, - {UNITS_KILOGRAMS_PER_KILOGRAM,"kilograms-per-kilogram"}, - {UNITS_GRAMS_PER_KILOGRAM,"grams-per-kilogram"}, - {UNITS_MILLIGRAMS_PER_GRAM,"milligrams-per-gram"}, - {UNITS_MILLIGRAMS_PER_KILOGRAM,"milligrams-per-kilogram"}, - {UNITS_GRAMS_PER_MILLILITER,"grams-per-milliliter"}, - {UNITS_GRAMS_PER_LITER,"grams-per-liter"}, - {UNITS_MILLIGRAMS_PER_LITER,"milligrams-per-liter"}, - {UNITS_MICROGRAMS_PER_LITER,"micrograms-per-liter"}, - {UNITS_GRAMS_PER_CUBIC_METER,"grams-per-cubic-meter"}, - {UNITS_MILLIGRAMS_PER_CUBIC_METER,"milligrams-per-cubic-meter"}, - {UNITS_MICROGRAMS_PER_CUBIC_METER,"micrograms-per-cubic-meter"}, - {UNITS_NANOGRAMS_PER_CUBIC_METER,"nanograms-per-cubic-meter"}, - {UNITS_GRAMS_PER_CUBIC_CENTIMETER,"grams-per-cubic-centimeter"}, - {UNITS_BECQUERELS,"becquerels"}, - {UNITS_MEGABECQUERELS,"megabecquerels"}, - {UNITS_GRAY,"gray"}, - {UNITS_MILLIGRAY,"milligray"}, - {UNITS_MICROGRAY,"microgray"}, - {UNITS_SIEVERTS,"sieverts"}, - {UNITS_MILLISIEVERTS,"millisieverts"}, - {UNITS_MICROSIEVERTS,"microsieverts"}, - {UNITS_MICROSIEVERTS_PER_HOUR,"microsieverts-per-hour"}, - {UNITS_DECIBELS_A,"decibels-a"}, - {UNITS_NEPHELOMETRIC_TURBIDITY_UNIT,"nephelometric-turbidity-unit"}, - {UNITS_PH,"pH"}, - {UNITS_GRAMS_PER_SQUARE_METER,"grams-per-square-meter"}, - {UNITS_MINUTES_PER_DEGREE_KELVIN,"minutes-per-degree-kelvin"}, - {UNITS_OHM_METER_SQUARED_PER_METER,"ohm-meter-squared-per-meter"}, - {UNITS_AMPERE_SECONDS,"ampere-seconds"}, - {UNITS_VOLT_AMPERE_HOURS,"volt-ampere-hours"}, - {UNITS_KILOVOLT_AMPERE_HOURS,"kilovolt-ampere-hours"}, - {UNITS_MEGAVOLT_AMPERE_HOURS,"megavolt-ampere-hours"}, - {UNITS_VOLT_AMPERE_HOURS_REACTIVE,"volt-ampere-hours-reactive"}, - {UNITS_KILOVOLT_AMPERE_HOURS_REACTIVE,"kilovolt-ampere-hours-reactive"}, - {UNITS_MEGAVOLT_AMPERE_HOURS_REACTIVE,"megavolt-ampere-hours-reactive"}, - {UNITS_VOLT_SQUARE_HOURS,"volt-square-hours"}, - {UNITS_AMPERE_SQUARE_HOURS,"ampere-square-hours"}, - {UNITS_JOULE_PER_HOURS,"joule-per-hours"}, - {UNITS_CUBIC_FEET_PER_DAY,"cubic-feet-per-day"}, - {UNITS_CUBIC_METERS_PER_DAY,"cubic-meters-per-day"}, - {UNITS_WATT_HOURS_PER_CUBIC_METER,"watt-hours-per-cubic-meter"}, - {UNITS_JOULES_PER_CUBIC_METER,"joules-per-cubic-meter"}, - {UNITS_MOLE_PERCENT,"mole-percent"}, - {UNITS_PASCAL_SECONDS,"pascal-seconds"}, - {UNITS_MILLION_STANDARD_CUBIC_FEET_PER_MINUTE,"million-standard-cubic-feet-per-minute"}, - {UNITS_STANDARD_CUBIC_FEET_PER_DAY,"standard-cubic-feet-per-day"}, - {UNITS_MILLION_STANDARD_CUBIC_FEET_PER_DAY,"million-standard-cubic-feet-per-day"}, - {UNITS_THOUSAND_CUBIC_FEET_PER_DAY,"thousand-cubic-feet-per-day"}, - {UNITS_THOUSAND_STANDARD_CUBIC_FEET_PER_DAY,"thousand-standard-cubic-feet-per-day"}, - {UNITS_POUNDS_MASS_PER_DAY,"pounds-mass-per-day"}, - {UNITS_MILLIREMS,"millirems"}, - {UNITS_MILLIREMS_PER_HOUR,"millirems-per-hour"}, + "watts-per-meter-per-degree-Kelvin"}, + {UNITS_PER_MILLE, "per-mille"}, + {UNITS_GRAMS_PER_GRAM, "grams-per-gram"}, + {UNITS_KILOGRAMS_PER_KILOGRAM, "kilograms-per-kilogram"}, + {UNITS_GRAMS_PER_KILOGRAM, "grams-per-kilogram"}, + {UNITS_MILLIGRAMS_PER_GRAM, "milligrams-per-gram"}, + {UNITS_MILLIGRAMS_PER_KILOGRAM, "milligrams-per-kilogram"}, + {UNITS_GRAMS_PER_MILLILITER, "grams-per-milliliter"}, + {UNITS_GRAMS_PER_LITER, "grams-per-liter"}, + {UNITS_MILLIGRAMS_PER_LITER, "milligrams-per-liter"}, + {UNITS_MICROGRAMS_PER_LITER, "micrograms-per-liter"}, + {UNITS_GRAMS_PER_CUBIC_METER, "grams-per-cubic-meter"}, + {UNITS_MILLIGRAMS_PER_CUBIC_METER, "milligrams-per-cubic-meter"}, + {UNITS_MICROGRAMS_PER_CUBIC_METER, "micrograms-per-cubic-meter"}, + {UNITS_NANOGRAMS_PER_CUBIC_METER, "nanograms-per-cubic-meter"}, + {UNITS_GRAMS_PER_CUBIC_CENTIMETER, "grams-per-cubic-centimeter"}, + {UNITS_BECQUERELS, "becquerels"}, + {UNITS_MEGABECQUERELS, "megabecquerels"}, + {UNITS_GRAY, "gray"}, + {UNITS_MILLIGRAY, "milligray"}, + {UNITS_MICROGRAY, "microgray"}, + {UNITS_SIEVERTS, "sieverts"}, + {UNITS_MILLISIEVERTS, "millisieverts"}, + {UNITS_MICROSIEVERTS, "microsieverts"}, + {UNITS_MICROSIEVERTS_PER_HOUR, "microsieverts-per-hour"}, + {UNITS_DECIBELS_A, "decibels-a"}, + {UNITS_NEPHELOMETRIC_TURBIDITY_UNIT, "nephelometric-turbidity-unit"}, + {UNITS_PH, "pH"}, + {UNITS_GRAMS_PER_SQUARE_METER, "grams-per-square-meter"}, + {UNITS_MINUTES_PER_DEGREE_KELVIN, "minutes-per-degree-kelvin"}, + {UNITS_OHM_METER_SQUARED_PER_METER, "ohm-meter-squared-per-meter"}, + {UNITS_AMPERE_SECONDS, "ampere-seconds"}, + {UNITS_VOLT_AMPERE_HOURS, "volt-ampere-hours"}, + {UNITS_KILOVOLT_AMPERE_HOURS, "kilovolt-ampere-hours"}, + {UNITS_MEGAVOLT_AMPERE_HOURS, "megavolt-ampere-hours"}, + {UNITS_VOLT_AMPERE_HOURS_REACTIVE, "volt-ampere-hours-reactive"}, + {UNITS_KILOVOLT_AMPERE_HOURS_REACTIVE, "kilovolt-ampere-hours-reactive"}, + {UNITS_MEGAVOLT_AMPERE_HOURS_REACTIVE, "megavolt-ampere-hours-reactive"}, + {UNITS_VOLT_SQUARE_HOURS, "volt-square-hours"}, + {UNITS_AMPERE_SQUARE_HOURS, "ampere-square-hours"}, + {UNITS_JOULE_PER_HOURS, "joule-per-hours"}, + {UNITS_CUBIC_FEET_PER_DAY, "cubic-feet-per-day"}, + {UNITS_CUBIC_METERS_PER_DAY, "cubic-meters-per-day"}, + {UNITS_WATT_HOURS_PER_CUBIC_METER, "watt-hours-per-cubic-meter"}, + {UNITS_JOULES_PER_CUBIC_METER, "joules-per-cubic-meter"}, + {UNITS_MOLE_PERCENT, "mole-percent"}, + {UNITS_PASCAL_SECONDS, "pascal-seconds"}, + {UNITS_MILLION_STANDARD_CUBIC_FEET_PER_MINUTE, + "million-standard-cubic-feet-per-minute"}, + {UNITS_STANDARD_CUBIC_FEET_PER_DAY, "standard-cubic-feet-per-day"}, + {UNITS_MILLION_STANDARD_CUBIC_FEET_PER_DAY, + "million-standard-cubic-feet-per-day"}, + {UNITS_THOUSAND_CUBIC_FEET_PER_DAY, "thousand-cubic-feet-per-day"}, + {UNITS_THOUSAND_STANDARD_CUBIC_FEET_PER_DAY, + "thousand-standard-cubic-feet-per-day"}, + {UNITS_POUNDS_MASS_PER_DAY, "pounds-mass-per-day"}, + {UNITS_MILLIREMS, "millirems"}, + {UNITS_MILLIREMS_PER_HOUR, "millirems-per-hour"}, {0, NULL} -/* 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. */ + /* 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. */ }; -const char *bactext_engineering_unit_name( - unsigned index) +const char *bactext_engineering_unit_name(unsigned index) { return indtext_by_index_split_default(bacnet_engineering_unit_names, index, - 256, ASHRAE_Reserved_String, Vendor_Proprietary_String); + 256, ASHRAE_Reserved_String, + Vendor_Proprietary_String); } -bool bactext_engineering_unit_index( - const char *search_name, - unsigned *found_index) +bool bactext_engineering_unit_index(const char *search_name, + unsigned *found_index) { return indtext_by_istring(bacnet_engineering_unit_names, search_name, - found_index); + found_index); } INDTEXT_DATA bacnet_reject_reason_names[] = { - {REJECT_REASON_OTHER, "Other"} - , - {REJECT_REASON_BUFFER_OVERFLOW, "Buffer Overflow"} - , - {REJECT_REASON_INCONSISTENT_PARAMETERS, "Inconsistent Parameters"} - , - {REJECT_REASON_INVALID_PARAMETER_DATA_TYPE, - "Invalid Parameter Data Type"} - , - {REJECT_REASON_INVALID_TAG, "Invalid Tag"} - , - {REJECT_REASON_MISSING_REQUIRED_PARAMETER, "Missing Required Parameter"} - , - {REJECT_REASON_PARAMETER_OUT_OF_RANGE, "Parameter Out of Range"} - , - {REJECT_REASON_TOO_MANY_ARGUMENTS, "Too Many Arguments"} - , - {REJECT_REASON_UNDEFINED_ENUMERATION, "Undefined Enumeration"} - , - {REJECT_REASON_UNRECOGNIZED_SERVICE, "Unrecognized Service"} - , - {REJECT_REASON_PROPRIETARY_FIRST, "Proprietary"} - , - {0, NULL} -}; + {REJECT_REASON_OTHER, "Other"}, + {REJECT_REASON_BUFFER_OVERFLOW, "Buffer Overflow"}, + {REJECT_REASON_INCONSISTENT_PARAMETERS, "Inconsistent Parameters"}, + {REJECT_REASON_INVALID_PARAMETER_DATA_TYPE, "Invalid Parameter Data Type"}, + {REJECT_REASON_INVALID_TAG, "Invalid Tag"}, + {REJECT_REASON_MISSING_REQUIRED_PARAMETER, "Missing Required Parameter"}, + {REJECT_REASON_PARAMETER_OUT_OF_RANGE, "Parameter Out of Range"}, + {REJECT_REASON_TOO_MANY_ARGUMENTS, "Too Many Arguments"}, + {REJECT_REASON_UNDEFINED_ENUMERATION, "Undefined Enumeration"}, + {REJECT_REASON_UNRECOGNIZED_SERVICE, "Unrecognized Service"}, + {REJECT_REASON_PROPRIETARY_FIRST, "Proprietary"}, + {0, NULL}}; -const char *bactext_reject_reason_name( - unsigned index) +const char *bactext_reject_reason_name(unsigned index) { - return indtext_by_index_split_default(bacnet_reject_reason_names, index, - REJECT_REASON_PROPRIETARY_FIRST, ASHRAE_Reserved_String, - Vendor_Proprietary_String); + return indtext_by_index_split_default( + bacnet_reject_reason_names, index, REJECT_REASON_PROPRIETARY_FIRST, + ASHRAE_Reserved_String, Vendor_Proprietary_String); } INDTEXT_DATA bacnet_abort_reason_names[] = { - {ABORT_REASON_OTHER, "Other"} - , - {ABORT_REASON_BUFFER_OVERFLOW, "Buffer Overflow"} - , - {ABORT_REASON_INVALID_APDU_IN_THIS_STATE, "Invalid APDU in this State"} - , + {ABORT_REASON_OTHER, "Other"}, + {ABORT_REASON_BUFFER_OVERFLOW, "Buffer Overflow"}, + {ABORT_REASON_INVALID_APDU_IN_THIS_STATE, "Invalid APDU in this State"}, {ABORT_REASON_PREEMPTED_BY_HIGHER_PRIORITY_TASK, - "Preempted by Higher Priority Task"} - , - {ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, "Segmentation Not Supported"} - , - {ABORT_REASON_PROPRIETARY_FIRST, "Proprietary"} - , - {0, NULL} -}; + "Preempted by Higher Priority Task"}, + {ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, "Segmentation Not Supported"}, + {ABORT_REASON_PROPRIETARY_FIRST, "Proprietary"}, + {0, NULL}}; -const char *bactext_abort_reason_name( - unsigned index) +const char *bactext_abort_reason_name(unsigned index) { - return indtext_by_index_split_default(bacnet_abort_reason_names, index, - ABORT_REASON_PROPRIETARY_FIRST, ASHRAE_Reserved_String, - Vendor_Proprietary_String); + return indtext_by_index_split_default( + bacnet_abort_reason_names, index, ABORT_REASON_PROPRIETARY_FIRST, + ASHRAE_Reserved_String, Vendor_Proprietary_String); } -INDTEXT_DATA bacnet_error_class_names[] = { - {ERROR_CLASS_DEVICE, "device"} - , - {ERROR_CLASS_OBJECT, "object"} - , - {ERROR_CLASS_PROPERTY, "property"} - , - {ERROR_CLASS_RESOURCES, "resources"} - , - {ERROR_CLASS_SECURITY, "security"} - , - {ERROR_CLASS_SERVICES, "services"} - , - {ERROR_CLASS_VT, "vt"} - , - {0, NULL} -}; +INDTEXT_DATA bacnet_error_class_names[] = {{ERROR_CLASS_DEVICE, "device"}, + {ERROR_CLASS_OBJECT, "object"}, + {ERROR_CLASS_PROPERTY, "property"}, + {ERROR_CLASS_RESOURCES, "resources"}, + {ERROR_CLASS_SECURITY, "security"}, + {ERROR_CLASS_SERVICES, "services"}, + {ERROR_CLASS_VT, "vt"}, + {0, NULL}}; -const char *bactext_error_class_name( - unsigned index) +const char *bactext_error_class_name(unsigned index) { - return indtext_by_index_split_default(bacnet_error_class_names, index, - ERROR_CLASS_PROPRIETARY_FIRST, ASHRAE_Reserved_String, - Vendor_Proprietary_String); + return indtext_by_index_split_default( + bacnet_error_class_names, index, ERROR_CLASS_PROPRIETARY_FIRST, + ASHRAE_Reserved_String, Vendor_Proprietary_String); } INDTEXT_DATA bacnet_error_code_names[] = { - {ERROR_CODE_OTHER, "other"} - , - {ERROR_CODE_AUTHENTICATION_FAILED, "authentication-failed"} - , - {ERROR_CODE_CHARACTER_SET_NOT_SUPPORTED, "character-set-not-supported"} - , - {ERROR_CODE_CONFIGURATION_IN_PROGRESS, "configuration-in-progress"} - , - {ERROR_CODE_DATATYPE_NOT_SUPPORTED, "datatype-not-supported"} - , - {ERROR_CODE_DEVICE_BUSY, "device-busy"} - , - {ERROR_CODE_DUPLICATE_NAME, "duplicate-name"} - , - {ERROR_CODE_DUPLICATE_OBJECT_ID, "duplicate-object-id"} - , + {ERROR_CODE_OTHER, "other"}, + {ERROR_CODE_AUTHENTICATION_FAILED, "authentication-failed"}, + {ERROR_CODE_CHARACTER_SET_NOT_SUPPORTED, "character-set-not-supported"}, + {ERROR_CODE_CONFIGURATION_IN_PROGRESS, "configuration-in-progress"}, + {ERROR_CODE_DATATYPE_NOT_SUPPORTED, "datatype-not-supported"}, + {ERROR_CODE_DEVICE_BUSY, "device-busy"}, + {ERROR_CODE_DUPLICATE_NAME, "duplicate-name"}, + {ERROR_CODE_DUPLICATE_OBJECT_ID, "duplicate-object-id"}, {ERROR_CODE_DYNAMIC_CREATION_NOT_SUPPORTED, - "dynamic-creation-not-supported"} - , - {ERROR_CODE_FILE_ACCESS_DENIED, "file-access-denied"} - , - {ERROR_CODE_INCOMPATIBLE_SECURITY_LEVELS, - "incompatible-security-levels"} - , - {ERROR_CODE_INCONSISTENT_PARAMETERS, "inconsistent-parameters"} - , + "dynamic-creation-not-supported"}, + {ERROR_CODE_FILE_ACCESS_DENIED, "file-access-denied"}, + {ERROR_CODE_INCOMPATIBLE_SECURITY_LEVELS, "incompatible-security-levels"}, + {ERROR_CODE_INCONSISTENT_PARAMETERS, "inconsistent-parameters"}, {ERROR_CODE_INCONSISTENT_SELECTION_CRITERION, - "inconsistent-selection-criterion"} - , - {ERROR_CODE_INVALID_ARRAY_INDEX, "invalid-array-index"} - , - {ERROR_CODE_INVALID_CONFIGURATION_DATA, "invalid-configuration-data"} - , - {ERROR_CODE_INVALID_DATA_TYPE, "invalid-data-type"} - , - {ERROR_CODE_INVALID_FILE_ACCESS_METHOD, "invalid-file-access-method"} - , + "inconsistent-selection-criterion"}, + {ERROR_CODE_INVALID_ARRAY_INDEX, "invalid-array-index"}, + {ERROR_CODE_INVALID_CONFIGURATION_DATA, "invalid-configuration-data"}, + {ERROR_CODE_INVALID_DATA_TYPE, "invalid-data-type"}, + {ERROR_CODE_INVALID_FILE_ACCESS_METHOD, "invalid-file-access-method"}, {ERROR_CODE_INVALID_FILE_START_POSITION, - "error-code-invalid-file-start-position"} - , - {ERROR_CODE_INVALID_OPERATOR_NAME, "invalid-operator-name"} - , - {ERROR_CODE_INVALID_PARAMETER_DATA_TYPE, "invalid-parameter-data-type"} - , - {ERROR_CODE_INVALID_TIME_STAMP, "invalid-time-stamp"} - , - {ERROR_CODE_KEY_GENERATION_ERROR, "key-generation-error"} - , - {ERROR_CODE_MISSING_REQUIRED_PARAMETER, "missing-required-parameter"} - , - {ERROR_CODE_NO_OBJECTS_OF_SPECIFIED_TYPE, - "no-objects-of-specified-type"} - , - {ERROR_CODE_NO_SPACE_FOR_OBJECT, "no-space-for-object"} - , - {ERROR_CODE_NO_SPACE_TO_ADD_LIST_ELEMENT, - "no-space-to-add-list-element"} - , - {ERROR_CODE_NO_SPACE_TO_WRITE_PROPERTY, "no-space-to-write-property"} - , - {ERROR_CODE_NO_VT_SESSIONS_AVAILABLE, "no-vt-sessions-available"} - , - {ERROR_CODE_OBJECT_DELETION_NOT_PERMITTED, - "object-deletion-not-permitted"} - , + "error-code-invalid-file-start-position"}, + {ERROR_CODE_INVALID_OPERATOR_NAME, "invalid-operator-name"}, + {ERROR_CODE_INVALID_PARAMETER_DATA_TYPE, "invalid-parameter-data-type"}, + {ERROR_CODE_INVALID_TIME_STAMP, "invalid-time-stamp"}, + {ERROR_CODE_KEY_GENERATION_ERROR, "key-generation-error"}, + {ERROR_CODE_MISSING_REQUIRED_PARAMETER, "missing-required-parameter"}, + {ERROR_CODE_NO_OBJECTS_OF_SPECIFIED_TYPE, "no-objects-of-specified-type"}, + {ERROR_CODE_NO_SPACE_FOR_OBJECT, "no-space-for-object"}, + {ERROR_CODE_NO_SPACE_TO_ADD_LIST_ELEMENT, "no-space-to-add-list-element"}, + {ERROR_CODE_NO_SPACE_TO_WRITE_PROPERTY, "no-space-to-write-property"}, + {ERROR_CODE_NO_VT_SESSIONS_AVAILABLE, "no-vt-sessions-available"}, + {ERROR_CODE_OBJECT_DELETION_NOT_PERMITTED, "object-deletion-not-permitted"}, {ERROR_CODE_OBJECT_IDENTIFIER_ALREADY_EXISTS, - "object-identifier-already-exists"} - , - {ERROR_CODE_OPERATIONAL_PROBLEM, "operational-problem"} - , + "object-identifier-already-exists"}, + {ERROR_CODE_OPERATIONAL_PROBLEM, "operational-problem"}, {ERROR_CODE_OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED, - "optional-functionality-not-supported"} - , - {ERROR_CODE_PASSWORD_FAILURE, "password-failure"} - , - {ERROR_CODE_PROPERTY_IS_NOT_A_LIST, "property-is-not-a-list"} - , - {ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY, "property-is-not-an-array"} - , - {ERROR_CODE_READ_ACCESS_DENIED, "read-access-denied"} - , - {ERROR_CODE_SECURITY_NOT_SUPPORTED, "security-not-supported"} - , - {ERROR_CODE_SERVICE_REQUEST_DENIED, "service-request-denied"} - , - {ERROR_CODE_TIMEOUT, "timeout"} - , - {ERROR_CODE_UNKNOWN_OBJECT, "unknown-object"} - , - {ERROR_CODE_UNKNOWN_PROPERTY, "unknown-property"} - , - {ERROR_CODE_RESERVED1, "reserved1"} - , - {ERROR_CODE_UNKNOWN_VT_CLASS, "unknown-vt-class"} - , - {ERROR_CODE_UNKNOWN_VT_SESSION, "unknown-vt-session"} - , - {ERROR_CODE_UNSUPPORTED_OBJECT_TYPE, "unsupported-object-type"} - , - {ERROR_CODE_VALUE_OUT_OF_RANGE, "value-out-of-range"} - , - {ERROR_CODE_VT_SESSION_ALREADY_CLOSED, "vt-session-already-closed"} - , + "optional-functionality-not-supported"}, + {ERROR_CODE_PASSWORD_FAILURE, "password-failure"}, + {ERROR_CODE_PROPERTY_IS_NOT_A_LIST, "property-is-not-a-list"}, + {ERROR_CODE_PROPERTY_IS_NOT_AN_ARRAY, "property-is-not-an-array"}, + {ERROR_CODE_READ_ACCESS_DENIED, "read-access-denied"}, + {ERROR_CODE_SECURITY_NOT_SUPPORTED, "security-not-supported"}, + {ERROR_CODE_SERVICE_REQUEST_DENIED, "service-request-denied"}, + {ERROR_CODE_TIMEOUT, "timeout"}, + {ERROR_CODE_UNKNOWN_OBJECT, "unknown-object"}, + {ERROR_CODE_UNKNOWN_PROPERTY, "unknown-property"}, + {ERROR_CODE_RESERVED1, "reserved1"}, + {ERROR_CODE_UNKNOWN_VT_CLASS, "unknown-vt-class"}, + {ERROR_CODE_UNKNOWN_VT_SESSION, "unknown-vt-session"}, + {ERROR_CODE_UNSUPPORTED_OBJECT_TYPE, "unsupported-object-type"}, + {ERROR_CODE_VALUE_OUT_OF_RANGE, "value-out-of-range"}, + {ERROR_CODE_VT_SESSION_ALREADY_CLOSED, "vt-session-already-closed"}, {ERROR_CODE_VT_SESSION_TERMINATION_FAILURE, - "vt-session-termination-failure"} - , - {ERROR_CODE_WRITE_ACCESS_DENIED, "write-access-denied"} - , - {ERROR_CODE_COV_SUBSCRIPTION_FAILED, "cov-subscription-failed"} - , - {ERROR_CODE_NOT_COV_PROPERTY, "not-cov-property"} - , - {ERROR_CODE_ABORT_BUFFER_OVERFLOW, "abort-buffer-overflow"} - , + "vt-session-termination-failure"}, + {ERROR_CODE_WRITE_ACCESS_DENIED, "write-access-denied"}, + {ERROR_CODE_COV_SUBSCRIPTION_FAILED, "cov-subscription-failed"}, + {ERROR_CODE_NOT_COV_PROPERTY, "not-cov-property"}, + {ERROR_CODE_ABORT_BUFFER_OVERFLOW, "abort-buffer-overflow"}, {ERROR_CODE_ABORT_INVALID_APDU_IN_THIS_STATE, - "abort-invalid-apdu-in-this-state"} - , + "abort-invalid-apdu-in-this-state"}, {ERROR_CODE_ABORT_PREEMPTED_BY_HIGHER_PRIORITY_TASK, - "abort-preempted-by-higher-priority-task"} - , + "abort-preempted-by-higher-priority-task"}, {ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED, - "abort-segmentation-not-supported"} - , - {ERROR_CODE_ABORT_PROPRIETARY, "abort-proprietary"} - , - {ERROR_CODE_ABORT_OTHER, "abort-other"} - , - {ERROR_CODE_INVALID_TAG, "invalid-tag"} - , - {ERROR_CODE_NETWORK_DOWN, "network-down"} - , - {ERROR_CODE_REJECT_BUFFER_OVERFLOW, "reject-buffer-overflow"} - , + "abort-segmentation-not-supported"}, + {ERROR_CODE_ABORT_PROPRIETARY, "abort-proprietary"}, + {ERROR_CODE_ABORT_OTHER, "abort-other"}, + {ERROR_CODE_INVALID_TAG, "invalid-tag"}, + {ERROR_CODE_NETWORK_DOWN, "network-down"}, + {ERROR_CODE_REJECT_BUFFER_OVERFLOW, "reject-buffer-overflow"}, {ERROR_CODE_REJECT_INCONSISTENT_PARAMETERS, - "reject-inconsistent-parameters"} - , + "reject-inconsistent-parameters"}, {ERROR_CODE_REJECT_INVALID_PARAMETER_DATA_TYPE, - "reject-invalid-parameter-data-type"} - , - {ERROR_CODE_REJECT_INVALID_TAG, "reject-invalid-tag"} - , + "reject-invalid-parameter-data-type"}, + {ERROR_CODE_REJECT_INVALID_TAG, "reject-invalid-tag"}, {ERROR_CODE_REJECT_MISSING_REQUIRED_PARAMETER, - "reject-missing-required-parameter"} - , - {ERROR_CODE_REJECT_PARAMETER_OUT_OF_RANGE, "reject-parameter-out-of-range"} - , - {ERROR_CODE_REJECT_TOO_MANY_ARGUMENTS, "reject-too-many-arguments"} - , - {ERROR_CODE_REJECT_UNDEFINED_ENUMERATION, "reject-undefined-enumeration"} - , - {ERROR_CODE_REJECT_UNRECOGNIZED_SERVICE, "reject-unrecognized-service"} - , - {ERROR_CODE_REJECT_PROPRIETARY, "reject-proprietary"} - , - {ERROR_CODE_REJECT_OTHER, "reject-other"} - , - {ERROR_CODE_UNKNOWN_DEVICE, "unknown-device"} - , - {ERROR_CODE_UNKNOWN_ROUTE, "unknown-route"} - , - {ERROR_CODE_VALUE_NOT_INITIALIZED, "value-not-initialized"} - , - {ERROR_CODE_INVALID_EVENT_STATE, "invalid-event-state"} - , - {ERROR_CODE_NO_ALARM_CONFIGURED, "no-alarm-configured"} - , - {ERROR_CODE_LOG_BUFFER_FULL, "log-buffer-full"} - , - {ERROR_CODE_LOGGED_VALUE_PURGED, "logged-value-purged"} - , - {ERROR_CODE_NO_PROPERTY_SPECIFIED, "no-property-specified"} - , + "reject-missing-required-parameter"}, + {ERROR_CODE_REJECT_PARAMETER_OUT_OF_RANGE, "reject-parameter-out-of-range"}, + {ERROR_CODE_REJECT_TOO_MANY_ARGUMENTS, "reject-too-many-arguments"}, + {ERROR_CODE_REJECT_UNDEFINED_ENUMERATION, "reject-undefined-enumeration"}, + {ERROR_CODE_REJECT_UNRECOGNIZED_SERVICE, "reject-unrecognized-service"}, + {ERROR_CODE_REJECT_PROPRIETARY, "reject-proprietary"}, + {ERROR_CODE_REJECT_OTHER, "reject-other"}, + {ERROR_CODE_UNKNOWN_DEVICE, "unknown-device"}, + {ERROR_CODE_UNKNOWN_ROUTE, "unknown-route"}, + {ERROR_CODE_VALUE_NOT_INITIALIZED, "value-not-initialized"}, + {ERROR_CODE_INVALID_EVENT_STATE, "invalid-event-state"}, + {ERROR_CODE_NO_ALARM_CONFIGURED, "no-alarm-configured"}, + {ERROR_CODE_LOG_BUFFER_FULL, "log-buffer-full"}, + {ERROR_CODE_LOGGED_VALUE_PURGED, "logged-value-purged"}, + {ERROR_CODE_NO_PROPERTY_SPECIFIED, "no-property-specified"}, {ERROR_CODE_NOT_CONFIGURED_FOR_TRIGGERED_LOGGING, - "not-configured-for-triggered-logging"} - , - {ERROR_CODE_UNKNOWN_SUBSCRIPTION, "unknown-subscription"} - , - {ERROR_CODE_PARAMETER_OUT_OF_RANGE, "parameter-out-of-range"} - , - {ERROR_CODE_LIST_ELEMENT_NOT_FOUND, "list-element-not-found"} - , - {ERROR_CODE_BUSY, "busy"} - , - {ERROR_CODE_COMMUNICATION_DISABLED, "communication-disabled"} - , - {ERROR_CODE_COMMUNICATION_DISABLED, "access-denied"} - , - {ERROR_CODE_SUCCESS, "success"} - , - {ERROR_CODE_ACCESS_DENIED, "access-denied"} - , - {ERROR_CODE_BAD_DESTINATION_ADDRESS, "bad-destination-address"} - , - {ERROR_CODE_BAD_DESTINATION_DEVICE_ID, "bad-destination-device-id"} - , - {ERROR_CODE_BAD_SIGNATURE, "bad-signature"} - , - {ERROR_CODE_BAD_SOURCE_ADDRESS, "bad-source-address"} - , - {ERROR_CODE_BAD_TIMESTAMP, "bad-timestamp"} - , - {ERROR_CODE_CANNOT_USE_KEY, "cannot-use-key"} - , - {ERROR_CODE_CANNOT_VERIFY_MESSAGE_ID, "cannot-verify-message-id"} - , - {ERROR_CODE_CORRECT_KEY_REVISION, "correct-key-revision"} - , + "not-configured-for-triggered-logging"}, + {ERROR_CODE_UNKNOWN_SUBSCRIPTION, "unknown-subscription"}, + {ERROR_CODE_PARAMETER_OUT_OF_RANGE, "parameter-out-of-range"}, + {ERROR_CODE_LIST_ELEMENT_NOT_FOUND, "list-element-not-found"}, + {ERROR_CODE_BUSY, "busy"}, + {ERROR_CODE_COMMUNICATION_DISABLED, "communication-disabled"}, + {ERROR_CODE_COMMUNICATION_DISABLED, "access-denied"}, + {ERROR_CODE_SUCCESS, "success"}, + {ERROR_CODE_ACCESS_DENIED, "access-denied"}, + {ERROR_CODE_BAD_DESTINATION_ADDRESS, "bad-destination-address"}, + {ERROR_CODE_BAD_DESTINATION_DEVICE_ID, "bad-destination-device-id"}, + {ERROR_CODE_BAD_SIGNATURE, "bad-signature"}, + {ERROR_CODE_BAD_SOURCE_ADDRESS, "bad-source-address"}, + {ERROR_CODE_BAD_TIMESTAMP, "bad-timestamp"}, + {ERROR_CODE_CANNOT_USE_KEY, "cannot-use-key"}, + {ERROR_CODE_CANNOT_VERIFY_MESSAGE_ID, "cannot-verify-message-id"}, + {ERROR_CODE_CORRECT_KEY_REVISION, "correct-key-revision"}, {ERROR_CODE_DESTINATION_DEVICE_ID_REQUIRED, - "destination-device-id-required"} - , - {ERROR_CODE_DUPLICATE_MESSAGE, "duplicate-message"} - , - {ERROR_CODE_ENCRYPTION_NOT_CONFIGURED, "encryption-not-configured"} - , - {ERROR_CODE_ENCRYPTION_REQUIRED, "encryption-required"} - , - {ERROR_CODE_INCORRECT_KEY, "incorrect-key"} - , - {ERROR_CODE_INVALID_KEY_DATA, "invalid-key-data"} - , - {ERROR_CODE_KEY_UPDATE_IN_PROGRESS, "key-update-in-progress"} - , - {ERROR_CODE_MALFORMED_MESSAGE, "malformed-message"} - , - {ERROR_CODE_NOT_KEY_SERVER, "not-key-server"} - , - {ERROR_CODE_SECURITY_NOT_CONFIGURED, "security-not-configured"} - , - {ERROR_CODE_SOURCE_SECURITY_REQUIRED, "source-security-required"} - , - {ERROR_CODE_TOO_MANY_KEYS, "too-many-keys"} - , - {ERROR_CODE_UNKNOWN_AUTHENTICATION_TYPE, "unknown-authentication-type"} - , - {ERROR_CODE_UNKNOWN_KEY, "unknown-key"} - , - {ERROR_CODE_UNKNOWN_KEY_REVISION, "unknown-key-revision"} - , - {ERROR_CODE_UNKNOWN_SOURCE_MESSAGE, "unknown-source-message"} - , - {ERROR_CODE_NOT_ROUTER_TO_DNET, "not-router-to-dnet"} - , - {ERROR_CODE_ROUTER_BUSY, "router-busy"} - , - {ERROR_CODE_UNKNOWN_NETWORK_MESSAGE, "unknown-network-message"} - , - {ERROR_CODE_MESSAGE_TOO_LONG, "message-too-long"} - , - {ERROR_CODE_SECURITY_ERROR, "security-error"} - , - {ERROR_CODE_ADDRESSING_ERROR, "addressing-error"} - , - {ERROR_CODE_WRITE_BDT_FAILED, "write-bdt-failed"} - , - {ERROR_CODE_READ_BDT_FAILED, "read-bdt-failed"} - , + "destination-device-id-required"}, + {ERROR_CODE_DUPLICATE_MESSAGE, "duplicate-message"}, + {ERROR_CODE_ENCRYPTION_NOT_CONFIGURED, "encryption-not-configured"}, + {ERROR_CODE_ENCRYPTION_REQUIRED, "encryption-required"}, + {ERROR_CODE_INCORRECT_KEY, "incorrect-key"}, + {ERROR_CODE_INVALID_KEY_DATA, "invalid-key-data"}, + {ERROR_CODE_KEY_UPDATE_IN_PROGRESS, "key-update-in-progress"}, + {ERROR_CODE_MALFORMED_MESSAGE, "malformed-message"}, + {ERROR_CODE_NOT_KEY_SERVER, "not-key-server"}, + {ERROR_CODE_SECURITY_NOT_CONFIGURED, "security-not-configured"}, + {ERROR_CODE_SOURCE_SECURITY_REQUIRED, "source-security-required"}, + {ERROR_CODE_TOO_MANY_KEYS, "too-many-keys"}, + {ERROR_CODE_UNKNOWN_AUTHENTICATION_TYPE, "unknown-authentication-type"}, + {ERROR_CODE_UNKNOWN_KEY, "unknown-key"}, + {ERROR_CODE_UNKNOWN_KEY_REVISION, "unknown-key-revision"}, + {ERROR_CODE_UNKNOWN_SOURCE_MESSAGE, "unknown-source-message"}, + {ERROR_CODE_NOT_ROUTER_TO_DNET, "not-router-to-dnet"}, + {ERROR_CODE_ROUTER_BUSY, "router-busy"}, + {ERROR_CODE_UNKNOWN_NETWORK_MESSAGE, "unknown-network-message"}, + {ERROR_CODE_MESSAGE_TOO_LONG, "message-too-long"}, + {ERROR_CODE_SECURITY_ERROR, "security-error"}, + {ERROR_CODE_ADDRESSING_ERROR, "addressing-error"}, + {ERROR_CODE_WRITE_BDT_FAILED, "write-bdt-failed"}, + {ERROR_CODE_READ_BDT_FAILED, "read-bdt-failed"}, {ERROR_CODE_REGISTER_FOREIGN_DEVICE_FAILED, - "register-foreign-device-failed"} - , - {ERROR_CODE_READ_FDT_FAILED, "read-fdt-failed"} - , - {ERROR_CODE_DELETE_FDT_ENTRY_FAILED, "delete-fdt-entry-failed"} - , - {ERROR_CODE_DISTRIBUTE_BROADCAST_FAILED, "distribute-broadcast-failed"} - , - {ERROR_CODE_UNKNOWN_FILE_SIZE, "unknown-file-size"} - , - {ERROR_CODE_ABORT_APDU_TOO_LONG, "abort-apdu-too-long"} - , + "register-foreign-device-failed"}, + {ERROR_CODE_READ_FDT_FAILED, "read-fdt-failed"}, + {ERROR_CODE_DELETE_FDT_ENTRY_FAILED, "delete-fdt-entry-failed"}, + {ERROR_CODE_DISTRIBUTE_BROADCAST_FAILED, "distribute-broadcast-failed"}, + {ERROR_CODE_UNKNOWN_FILE_SIZE, "unknown-file-size"}, + {ERROR_CODE_ABORT_APDU_TOO_LONG, "abort-apdu-too-long"}, {ERROR_CODE_ABORT_APPLICATION_EXCEEDED_REPLY_TIME, - "abort-application-exceeded-reply-time"} - , - {ERROR_CODE_ABORT_OUT_OF_RESOURCES, "abort-out-of-resources"} - , - {ERROR_CODE_ABORT_TSM_TIMEOUT, "abort-tsm-timeout"} - , + "abort-application-exceeded-reply-time"}, + {ERROR_CODE_ABORT_OUT_OF_RESOURCES, "abort-out-of-resources"}, + {ERROR_CODE_ABORT_TSM_TIMEOUT, "abort-tsm-timeout"}, {ERROR_CODE_ABORT_WINDOW_SIZE_OUT_OF_RANGE, - "abort-window-size-out-of-range"} - , - {ERROR_CODE_FILE_FULL, "file-full"} - , - {ERROR_CODE_INCONSISTENT_CONFIGURATION, "inconsistent-configuration"} - , - {ERROR_CODE_INCONSISTENT_OBJECT_TYPE, "inconsistent-object-type"} - , - {ERROR_CODE_INTERNAL_ERROR, "internal-error"} - , - {ERROR_CODE_NOT_CONFIGURED, "not-configured"} - , - {ERROR_CODE_OUT_OF_MEMORY, "out-of-memory"} - , - {ERROR_CODE_VALUE_TOO_LONG, "value-too-long"} - , - {ERROR_CODE_ABORT_INSUFFICIENT_SECURITY, "abort-insufficient-security"} - , - {ERROR_CODE_ABORT_SECURITY_ERROR, "abort-security-error"} - , - {0, NULL} -}; + "abort-window-size-out-of-range"}, + {ERROR_CODE_FILE_FULL, "file-full"}, + {ERROR_CODE_INCONSISTENT_CONFIGURATION, "inconsistent-configuration"}, + {ERROR_CODE_INCONSISTENT_OBJECT_TYPE, "inconsistent-object-type"}, + {ERROR_CODE_INTERNAL_ERROR, "internal-error"}, + {ERROR_CODE_NOT_CONFIGURED, "not-configured"}, + {ERROR_CODE_OUT_OF_MEMORY, "out-of-memory"}, + {ERROR_CODE_VALUE_TOO_LONG, "value-too-long"}, + {ERROR_CODE_ABORT_INSUFFICIENT_SECURITY, "abort-insufficient-security"}, + {ERROR_CODE_ABORT_SECURITY_ERROR, "abort-security-error"}, + {0, NULL}}; -const char *bactext_error_code_name( - unsigned index) +const char *bactext_error_code_name(unsigned index) { - return indtext_by_index_split_default(bacnet_error_code_names, index, - ERROR_CODE_PROPRIETARY_FIRST, ASHRAE_Reserved_String, - Vendor_Proprietary_String); + return indtext_by_index_split_default( + bacnet_error_code_names, index, ERROR_CODE_PROPRIETARY_FIRST, + ASHRAE_Reserved_String, Vendor_Proprietary_String); } INDTEXT_DATA bacnet_month_names[] = { - {1, "January"} - , - {2, "February"} - , - {3, "March"} - , - {4, "April"} - , - {5, "May"} - , - {6, "June"} - , - {7, "July"} - , - {8, "August"} - , - {9, "September"} - , - {10, "October"} - , - {11, "November"} - , - {12, "December"} - , - {13, "Odd Months"} - , - {14, "Even Months"} - , - {255, "Any Month"} - , - {0, NULL} -}; + {1, "January"}, {2, "February"}, {3, "March"}, + {4, "April"}, {5, "May"}, {6, "June"}, + {7, "July"}, {8, "August"}, {9, "September"}, + {10, "October"}, {11, "November"}, {12, "December"}, + {13, "Odd Months"}, {14, "Even Months"}, {255, "Any Month"}, + {0, NULL}}; -const char *bactext_month_name( - unsigned index) +const char *bactext_month_name(unsigned index) { return indtext_by_index_default(bacnet_month_names, index, - ASHRAE_Reserved_String); + ASHRAE_Reserved_String); } INDTEXT_DATA bacnet_week_of_month_names[] = { - {1, "days numbered 1-7"} - , - {2, "days numbered 8-14"} - , - {3, "days numbered 15-21"} - , - {4, "days numbered 22-28"} - , - {5, "days numbered 29-31"} - , - {6, "last 7 days of this month"} - , - {255, "any week of this month"} - , - {0, NULL} -}; + {1, "days numbered 1-7"}, {2, "days numbered 8-14"}, + {3, "days numbered 15-21"}, {4, "days numbered 22-28"}, + {5, "days numbered 29-31"}, {6, "last 7 days of this month"}, + {255, "any week of this month"}, {0, NULL}}; -const char *bactext_week_of_month_name( - unsigned index) +const char *bactext_week_of_month_name(unsigned index) { return indtext_by_index_default(bacnet_week_of_month_names, index, - ASHRAE_Reserved_String); + ASHRAE_Reserved_String); } /* note: different than DaysOfWeek bit string where 0=monday */ INDTEXT_DATA bacnet_day_of_week_names[] = { - {1, "Monday"} - , - {2, "Tuesday"} - , - {3, "Wednesday"} - , - {4, "Thursday"} - , - {5, "Friday"} - , - {6, "Saturday"} - , - {7, "Sunday"} - , - {255, "any day of week"} - , - {0, NULL} -}; + {1, "Monday"}, {2, "Tuesday"}, {3, "Wednesday"}, {4, "Thursday"}, + {5, "Friday"}, {6, "Saturday"}, {7, "Sunday"}, {255, "any day of week"}, + {0, NULL}}; -const char *bactext_day_of_week_name( - unsigned index) +const char *bactext_day_of_week_name(unsigned index) { return indtext_by_index_default(bacnet_day_of_week_names, index, - ASHRAE_Reserved_String); + ASHRAE_Reserved_String); } /* note: different than DayOfWeek bit string where 1=monday */ INDTEXT_DATA bacnet_days_of_week_names[] = { - {BACNET_DAYS_OF_WEEK_MONDAY, "Monday"} - , - {BACNET_DAYS_OF_WEEK_TUESDAY, "Tuesday"} - , - {BACNET_DAYS_OF_WEEK_WEDNESDAY, "Wednesday"} - , - {BACNET_DAYS_OF_WEEK_THURSDAY, "Thursday"} - , - {BACNET_DAYS_OF_WEEK_FRIDAY, "Friday"} - , - {BACNET_DAYS_OF_WEEK_SATURDAY, "Saturday"} - , - {BACNET_DAYS_OF_WEEK_SUNDAY, "Sunday"} - , - {0, NULL} -}; + {BACNET_DAYS_OF_WEEK_MONDAY, "Monday"}, + {BACNET_DAYS_OF_WEEK_TUESDAY, "Tuesday"}, + {BACNET_DAYS_OF_WEEK_WEDNESDAY, "Wednesday"}, + {BACNET_DAYS_OF_WEEK_THURSDAY, "Thursday"}, + {BACNET_DAYS_OF_WEEK_FRIDAY, "Friday"}, + {BACNET_DAYS_OF_WEEK_SATURDAY, "Saturday"}, + {BACNET_DAYS_OF_WEEK_SUNDAY, "Sunday"}, + {0, NULL}}; -const char *bactext_days_of_week_name( - unsigned index) +const char *bactext_days_of_week_name(unsigned index) { return indtext_by_index_default(bacnet_days_of_week_names, index, - ASHRAE_Reserved_String); + ASHRAE_Reserved_String); } -bool bactext_days_of_week_index( - const char *search_name, - unsigned *found_index) +bool bactext_days_of_week_index(const char *search_name, unsigned *found_index) { return indtext_by_istring(bacnet_days_of_week_names, search_name, - found_index); + found_index); } INDTEXT_DATA bacnet_event_transition_names[] = { - {TRANSITION_TO_OFFNORMAL, "offnormal"} - , - {TRANSITION_TO_NORMAL, "normal"} - , - {TRANSITION_TO_FAULT, "fault"} - , - {0, NULL} -}; + {TRANSITION_TO_OFFNORMAL, "offnormal"}, + {TRANSITION_TO_NORMAL, "normal"}, + {TRANSITION_TO_FAULT, "fault"}, + {0, NULL}}; -const char *bactext_event_transition_name( - unsigned index) +const char *bactext_event_transition_name(unsigned index) { return indtext_by_index_default(bacnet_event_transition_names, index, - ASHRAE_Reserved_String); + ASHRAE_Reserved_String); } -bool bactext_event_transition_index( - const char *search_name, - unsigned *found_index) +bool bactext_event_transition_index(const char *search_name, + unsigned *found_index) { return indtext_by_istring(bacnet_event_transition_names, search_name, - found_index); + found_index); } INDTEXT_DATA bacnet_event_state_names[] = { - {EVENT_STATE_NORMAL, "normal"} - , - {EVENT_STATE_FAULT, "fault"} - , - {EVENT_STATE_OFFNORMAL, "offnormal"} - , - {EVENT_STATE_HIGH_LIMIT, "high limit"} - , - {EVENT_STATE_LOW_LIMIT, "low limit"} - , - {0, NULL} -}; + {EVENT_STATE_NORMAL, "normal"}, + {EVENT_STATE_FAULT, "fault"}, + {EVENT_STATE_OFFNORMAL, "offnormal"}, + {EVENT_STATE_HIGH_LIMIT, "high limit"}, + {EVENT_STATE_LOW_LIMIT, "low limit"}, + {0, NULL}}; -const char *bactext_event_state_name( - unsigned index) +const char *bactext_event_state_name(unsigned index) { return indtext_by_index_default(bacnet_event_state_names, index, - ASHRAE_Reserved_String); + ASHRAE_Reserved_String); } INDTEXT_DATA bacnet_binary_present_value_names[] = { - {BINARY_INACTIVE, "inactive"} - , - {BINARY_ACTIVE, "active"} - , - {0, NULL} -}; + {BINARY_INACTIVE, "inactive"}, {BINARY_ACTIVE, "active"}, {0, NULL}}; -const char *bactext_binary_present_value_name( - unsigned index) +const char *bactext_binary_present_value_name(unsigned index) { return indtext_by_index_default(bacnet_binary_present_value_names, index, - ASHRAE_Reserved_String); + ASHRAE_Reserved_String); } -bool bactext_binary_present_value_index( - const char *search_name, - unsigned *found_index) +bool bactext_binary_present_value_index(const char *search_name, + unsigned *found_index) { return indtext_by_istring(bacnet_binary_present_value_names, search_name, - found_index); + found_index); } INDTEXT_DATA bacnet_binary_polarity_names[] = { - {POLARITY_NORMAL, "normal"} - , - {POLARITY_REVERSE, "reverse"} - , - {0, NULL} -}; + {POLARITY_NORMAL, "normal"}, {POLARITY_REVERSE, "reverse"}, {0, NULL}}; -const char *bactext_binary_polarity_name( - unsigned index) +const char *bactext_binary_polarity_name(unsigned index) { return indtext_by_index_default(bacnet_binary_polarity_names, index, - ASHRAE_Reserved_String); + ASHRAE_Reserved_String); } - INDTEXT_DATA bacnet_reliability_names[] = { - {RELIABILITY_NO_FAULT_DETECTED, "no-fault-detected"} - , - {RELIABILITY_NO_SENSOR, "no-sensor"} - , - {RELIABILITY_OVER_RANGE, "over-range"} - , - {RELIABILITY_UNDER_RANGE, "under-range"} - , - {RELIABILITY_OPEN_LOOP, "open-loop"} - , - {RELIABILITY_SHORTED_LOOP, "shorted-loop"} - , - {RELIABILITY_NO_OUTPUT, "no-output"} - , - {RELIABILITY_UNRELIABLE_OTHER, "unreliable-other"} - , - {RELIABILITY_PROCESS_ERROR, "process-error"} - , - {RELIABILITY_MULTI_STATE_FAULT, "mult-state-fault"} - , - {RELIABILITY_CONFIGURATION_ERROR, "configuration-error"} - , - {RELIABILITY_MEMBER_FAULT, "member-fault"} - , - {RELIABILITY_COMMUNICATION_FAILURE, "communication-failure"} - , - {RELIABILITY_TRIPPED, "tripped"} - , - {0, NULL} -}; + {RELIABILITY_NO_FAULT_DETECTED, "no-fault-detected"}, + {RELIABILITY_NO_SENSOR, "no-sensor"}, + {RELIABILITY_OVER_RANGE, "over-range"}, + {RELIABILITY_UNDER_RANGE, "under-range"}, + {RELIABILITY_OPEN_LOOP, "open-loop"}, + {RELIABILITY_SHORTED_LOOP, "shorted-loop"}, + {RELIABILITY_NO_OUTPUT, "no-output"}, + {RELIABILITY_UNRELIABLE_OTHER, "unreliable-other"}, + {RELIABILITY_PROCESS_ERROR, "process-error"}, + {RELIABILITY_MULTI_STATE_FAULT, "mult-state-fault"}, + {RELIABILITY_CONFIGURATION_ERROR, "configuration-error"}, + {RELIABILITY_MEMBER_FAULT, "member-fault"}, + {RELIABILITY_COMMUNICATION_FAILURE, "communication-failure"}, + {RELIABILITY_TRIPPED, "tripped"}, + {0, NULL}}; -const char *bactext_reliability_name( - unsigned index) +const char *bactext_reliability_name(unsigned index) { return indtext_by_index_default(bacnet_reliability_names, index, - ASHRAE_Reserved_String); + ASHRAE_Reserved_String); } INDTEXT_DATA bacnet_device_status_names[] = { - {STATUS_OPERATIONAL, "operational"} - , - {STATUS_OPERATIONAL_READ_ONLY, "operational-read-only"} - , - {STATUS_DOWNLOAD_REQUIRED, "download-required"} - , - {STATUS_DOWNLOAD_IN_PROGRESS, "download-in-progress"} - , - {STATUS_NON_OPERATIONAL, "non-operational"} - , - {STATUS_BACKUP_IN_PROGRESS, "backup-in-progress"} - , - {0, NULL} -}; + {STATUS_OPERATIONAL, "operational"}, + {STATUS_OPERATIONAL_READ_ONLY, "operational-read-only"}, + {STATUS_DOWNLOAD_REQUIRED, "download-required"}, + {STATUS_DOWNLOAD_IN_PROGRESS, "download-in-progress"}, + {STATUS_NON_OPERATIONAL, "non-operational"}, + {STATUS_BACKUP_IN_PROGRESS, "backup-in-progress"}, + {0, NULL}}; -const char *bactext_device_status_name( - unsigned index) +const char *bactext_device_status_name(unsigned index) { return indtext_by_index_default(bacnet_device_status_names, index, - ASHRAE_Reserved_String); + ASHRAE_Reserved_String); } INDTEXT_DATA bacnet_segmentation_names[] = { - {SEGMENTATION_BOTH, "segmented-both"} - , - {SEGMENTATION_TRANSMIT, "segmented-transmit"} - , - {SEGMENTATION_RECEIVE, "segmented-receive"} - , - {SEGMENTATION_NONE, "no-segmentation"} - , - {0, NULL} -}; + {SEGMENTATION_BOTH, "segmented-both"}, + {SEGMENTATION_TRANSMIT, "segmented-transmit"}, + {SEGMENTATION_RECEIVE, "segmented-receive"}, + {SEGMENTATION_NONE, "no-segmentation"}, + {0, NULL}}; -const char *bactext_segmentation_name( - unsigned index) +const char *bactext_segmentation_name(unsigned index) { return indtext_by_index_default(bacnet_segmentation_names, index, - ASHRAE_Reserved_String); + ASHRAE_Reserved_String); } -bool bactext_segmentation_index( - const char *search_name, - unsigned *found_index) +bool bactext_segmentation_index(const char *search_name, unsigned *found_index) { return indtext_by_istring(bacnet_segmentation_names, search_name, - found_index); + found_index); } INDTEXT_DATA bacnet_node_type_names[] = { - {BACNET_NODE_UNKNOWN, "unknown"} - , - {BACNET_NODE_SYSTEM, "system"} - , - {BACNET_NODE_NETWORK, "network"} - , - {BACNET_NODE_DEVICE, "device"} - , - {BACNET_NODE_ORGANIZATIONAL, "organizational"} - , - {BACNET_NODE_AREA, "area"} - , - {BACNET_NODE_EQUIPMENT, "equipment"} - , - {BACNET_NODE_POINT, "point"} - , - {BACNET_NODE_COLLECTION, "collection"} - , - {BACNET_NODE_PROPERTY, "property"} - , - {BACNET_NODE_FUNCTIONAL, "functional"} - , - {BACNET_NODE_OTHER, "other"} - , - {0, NULL} -}; + {BACNET_NODE_UNKNOWN, "unknown"}, + {BACNET_NODE_SYSTEM, "system"}, + {BACNET_NODE_NETWORK, "network"}, + {BACNET_NODE_DEVICE, "device"}, + {BACNET_NODE_ORGANIZATIONAL, "organizational"}, + {BACNET_NODE_AREA, "area"}, + {BACNET_NODE_EQUIPMENT, "equipment"}, + {BACNET_NODE_POINT, "point"}, + {BACNET_NODE_COLLECTION, "collection"}, + {BACNET_NODE_PROPERTY, "property"}, + {BACNET_NODE_FUNCTIONAL, "functional"}, + {BACNET_NODE_OTHER, "other"}, + {0, NULL}}; -const char *bactext_node_type_name( - unsigned index) +const char *bactext_node_type_name(unsigned index) { return indtext_by_index_default(bacnet_node_type_names, index, - ASHRAE_Reserved_String); + ASHRAE_Reserved_String); } INDTEXT_DATA network_layer_msg_names[] = { - {NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK, "Who-Is-Router-To-Network"} - , - {NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK, "I-Am-Router-To-Network"} - , + {NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK, "Who-Is-Router-To-Network"}, + {NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK, "I-Am-Router-To-Network"}, {NETWORK_MESSAGE_I_COULD_BE_ROUTER_TO_NETWORK, - "I-Could-Be-Router-To-Network"} - , - {NETWORK_MESSAGE_REJECT_MESSAGE_TO_NETWORK, "Reject-Message-to-Network"} - , - {NETWORK_MESSAGE_ROUTER_BUSY_TO_NETWORK, "Router-Busy-To-Network"} - , - {NETWORK_MESSAGE_ROUTER_AVAILABLE_TO_NETWORK, "Router-Available-To-Network"} - , - {NETWORK_MESSAGE_INIT_RT_TABLE, "Initialize-Routing-Table"} - , - {NETWORK_MESSAGE_INIT_RT_TABLE_ACK, "Initialize-Routing-Table-Ack"} - , - {NETWORK_MESSAGE_ESTABLISH_CONNECTION_TO_NETWORK, "Est-Conn-Ntwk"} - , /* Terse since unused */ - {NETWORK_MESSAGE_DISCONNECT_CONNECTION_TO_NETWORK, "Dsc-Conn-Ntwk"} - , - {0, NULL} -}; + "I-Could-Be-Router-To-Network"}, + {NETWORK_MESSAGE_REJECT_MESSAGE_TO_NETWORK, "Reject-Message-to-Network"}, + {NETWORK_MESSAGE_ROUTER_BUSY_TO_NETWORK, "Router-Busy-To-Network"}, + {NETWORK_MESSAGE_ROUTER_AVAILABLE_TO_NETWORK, + "Router-Available-To-Network"}, + {NETWORK_MESSAGE_INIT_RT_TABLE, "Initialize-Routing-Table"}, + {NETWORK_MESSAGE_INIT_RT_TABLE_ACK, "Initialize-Routing-Table-Ack"}, + {NETWORK_MESSAGE_ESTABLISH_CONNECTION_TO_NETWORK, + "Est-Conn-Ntwk"}, /* Terse since unused */ + {NETWORK_MESSAGE_DISCONNECT_CONNECTION_TO_NETWORK, "Dsc-Conn-Ntwk"}, + {0, NULL}}; -const char *bactext_network_layer_msg_name( - unsigned index) +const char *bactext_network_layer_msg_name(unsigned index) { if (index <= 0x7F) return indtext_by_index_default(network_layer_msg_names, index, - ASHRAE_Reserved_String); + ASHRAE_Reserved_String); else if (index < NETWORK_MESSAGE_INVALID) return Vendor_Proprietary_String; else @@ -2408,143 +1431,90 @@ const char *bactext_network_layer_msg_name( } INDTEXT_DATA life_safety_state_names[] = { - {LIFE_SAFETY_STATE_QUIET, "quiet"} - , - {LIFE_SAFETY_STATE_PRE_ALARM, "pre-alarm"} - , - {LIFE_SAFETY_STATE_ALARM, "alarm"} - , - {LIFE_SAFETY_STATE_FAULT, "fault"} - , - {LIFE_SAFETY_STATE_FAULT_PRE_ALARM, "fault-pre-alarm"} - , - {LIFE_SAFETY_STATE_FAULT_ALARM, "fault-alarm"} - , - {LIFE_SAFETY_STATE_NOT_READY, "not-ready"} - , - {LIFE_SAFETY_STATE_ACTIVE, "active"} - , - {LIFE_SAFETY_STATE_TAMPER, "tamper"} - , - {LIFE_SAFETY_STATE_TEST_ALARM, "test-alarm"} - , - {LIFE_SAFETY_STATE_TEST_ACTIVE, "test-active"} - , - {LIFE_SAFETY_STATE_TEST_FAULT, "test-fault"} - , - {LIFE_SAFETY_STATE_TEST_FAULT_ALARM, "fault-alarm"} - , - {LIFE_SAFETY_STATE_HOLDUP, "holdupt"} - , - {LIFE_SAFETY_STATE_DURESS, "duress"} - , - {LIFE_SAFETY_STATE_TAMPER_ALARM, "tamper-alarm"} - , - {LIFE_SAFETY_STATE_ABNORMAL, "abnormal"} - , - {LIFE_SAFETY_STATE_EMERGENCY_POWER, "emergency-power"} - , - {LIFE_SAFETY_STATE_DELAYED, "delayed"} - , - {LIFE_SAFETY_STATE_BLOCKED, "blocked"} - , - {LIFE_SAFETY_STATE_LOCAL_ALARM, "local-alarm"} - , - {LIFE_SAFETY_STATE_GENERAL_ALARM, "general-alarm"} - , - {LIFE_SAFETY_STATE_SUPERVISORY, "supervisory"} - , - {LIFE_SAFETY_STATE_TEST_SUPERVISORY, "test-supervisory"} - , - {0, NULL} -}; + {LIFE_SAFETY_STATE_QUIET, "quiet"}, + {LIFE_SAFETY_STATE_PRE_ALARM, "pre-alarm"}, + {LIFE_SAFETY_STATE_ALARM, "alarm"}, + {LIFE_SAFETY_STATE_FAULT, "fault"}, + {LIFE_SAFETY_STATE_FAULT_PRE_ALARM, "fault-pre-alarm"}, + {LIFE_SAFETY_STATE_FAULT_ALARM, "fault-alarm"}, + {LIFE_SAFETY_STATE_NOT_READY, "not-ready"}, + {LIFE_SAFETY_STATE_ACTIVE, "active"}, + {LIFE_SAFETY_STATE_TAMPER, "tamper"}, + {LIFE_SAFETY_STATE_TEST_ALARM, "test-alarm"}, + {LIFE_SAFETY_STATE_TEST_ACTIVE, "test-active"}, + {LIFE_SAFETY_STATE_TEST_FAULT, "test-fault"}, + {LIFE_SAFETY_STATE_TEST_FAULT_ALARM, "fault-alarm"}, + {LIFE_SAFETY_STATE_HOLDUP, "holdupt"}, + {LIFE_SAFETY_STATE_DURESS, "duress"}, + {LIFE_SAFETY_STATE_TAMPER_ALARM, "tamper-alarm"}, + {LIFE_SAFETY_STATE_ABNORMAL, "abnormal"}, + {LIFE_SAFETY_STATE_EMERGENCY_POWER, "emergency-power"}, + {LIFE_SAFETY_STATE_DELAYED, "delayed"}, + {LIFE_SAFETY_STATE_BLOCKED, "blocked"}, + {LIFE_SAFETY_STATE_LOCAL_ALARM, "local-alarm"}, + {LIFE_SAFETY_STATE_GENERAL_ALARM, "general-alarm"}, + {LIFE_SAFETY_STATE_SUPERVISORY, "supervisory"}, + {LIFE_SAFETY_STATE_TEST_SUPERVISORY, "test-supervisory"}, + {0, NULL}}; -const char *bactext_life_safety_state_name( - unsigned index) +const char *bactext_life_safety_state_name(unsigned index) { - if (index < MAX_LIFE_SAFETY_STATE) + if (index < MAX_LIFE_SAFETY_STATE) return indtext_by_index_default(life_safety_state_names, index, - ASHRAE_Reserved_String); + ASHRAE_Reserved_String); else return "Invalid Safety State Message"; } -INDTEXT_DATA lighting_in_progress[] = { - {BACNET_LIGHTING_IDLE, "idle" } - , - { BACNET_LIGHTING_FADE_ACTIVE, "fade" } - , - { BACNET_LIGHTING_RAMP_ACTIVE, "ramp" } - , - { BACNET_LIGHTING_NOT_CONTROLLED, "not" } - , - {BACNET_LIGHTING_OTHER, "other"} - , - { 0, NULL } -}; +INDTEXT_DATA lighting_in_progress[] = {{BACNET_LIGHTING_IDLE, "idle"}, + {BACNET_LIGHTING_FADE_ACTIVE, "fade"}, + {BACNET_LIGHTING_RAMP_ACTIVE, "ramp"}, + {BACNET_LIGHTING_NOT_CONTROLLED, "not"}, + {BACNET_LIGHTING_OTHER, "other"}, + {0, NULL}}; -const char *bactext_lighting_in_progress( - unsigned index) +const char *bactext_lighting_in_progress(unsigned index) { - if (index < MAX_BACNET_LIGHTING_IN_PROGRESS) - return indtext_by_index_default(lighting_in_progress, index, - ASHRAE_Reserved_String); - else - return "Invalid Lighting In Progress Message"; + if (index < MAX_BACNET_LIGHTING_IN_PROGRESS) + return indtext_by_index_default(lighting_in_progress, index, + ASHRAE_Reserved_String); + else + return "Invalid Lighting In Progress Message"; } -INDTEXT_DATA lighting_transition[] = { - { BACNET_LIGHTING_TRANSITION_IDLE, "idle" } - , - { BACNET_LIGHTING_TRANSITION_FADE, "fade" } - , - { BACNET_LIGHTING_TRANSITION_RAMP, "ramp" } - , - { 0, NULL } -}; +INDTEXT_DATA lighting_transition[] = {{BACNET_LIGHTING_TRANSITION_IDLE, "idle"}, + {BACNET_LIGHTING_TRANSITION_FADE, "fade"}, + {BACNET_LIGHTING_TRANSITION_RAMP, "ramp"}, + {0, NULL}}; -const char *bactext_lighting_transition( - unsigned index) +const char *bactext_lighting_transition(unsigned index) { - if (index < MAX_BACNET_LIGHTING_TRANSITION) - return indtext_by_index_default(lighting_transition, index, - ASHRAE_Reserved_String); - else - return "Invalid Lighting Transition Message"; + if (index < MAX_BACNET_LIGHTING_TRANSITION) + return indtext_by_index_default(lighting_transition, index, + ASHRAE_Reserved_String); + else + return "Invalid Lighting Transition Message"; } INDTEXT_DATA bacnet_lighting_operation_names[] = { - {BACNET_LIGHTS_NONE, "none"} - , - {BACNET_LIGHTS_FADE_TO, "fade-to"} - , - {BACNET_LIGHTS_RAMP_TO, "ramp-to"} - , - {BACNET_LIGHTS_STEP_UP, "step-up"} - , - {BACNET_LIGHTS_STEP_DOWN, "step-down"} - , - {BACNET_LIGHTS_STEP_ON, "step-on"} - , - {BACNET_LIGHTS_STEP_OFF, "step-off"} - , - {BACNET_LIGHTS_WARN, "warn"} - , - {BACNET_LIGHTS_WARN_OFF, "warn-off"} - , - {BACNET_LIGHTS_WARN_RELINQUISH, "warn-relinquish"} - , - {BACNET_LIGHTS_STOP, "stop"} - , - {0, NULL} -}; + {BACNET_LIGHTS_NONE, "none"}, + {BACNET_LIGHTS_FADE_TO, "fade-to"}, + {BACNET_LIGHTS_RAMP_TO, "ramp-to"}, + {BACNET_LIGHTS_STEP_UP, "step-up"}, + {BACNET_LIGHTS_STEP_DOWN, "step-down"}, + {BACNET_LIGHTS_STEP_ON, "step-on"}, + {BACNET_LIGHTS_STEP_OFF, "step-off"}, + {BACNET_LIGHTS_WARN, "warn"}, + {BACNET_LIGHTS_WARN_OFF, "warn-off"}, + {BACNET_LIGHTS_WARN_RELINQUISH, "warn-relinquish"}, + {BACNET_LIGHTS_STOP, "stop"}, + {0, NULL}}; -const char *bactext_lighting_operation_name( - unsigned index) +const char *bactext_lighting_operation_name(unsigned index) { if (index < BACNET_LIGHTS_PROPRIETARY_FIRST) return indtext_by_index_default(network_layer_msg_names, index, - ASHRAE_Reserved_String); + ASHRAE_Reserved_String); else if (index <= BACNET_LIGHTS_PROPRIETARY_LAST) return Vendor_Proprietary_String; else @@ -2552,18 +1522,13 @@ const char *bactext_lighting_operation_name( } INDTEXT_DATA bacnet_device_communications_names[] = { - {COMMUNICATION_ENABLE, "enabled"} - , - {COMMUNICATION_DISABLE, "disabled"} - , - {COMMUNICATION_DISABLE_INITIATION, "initiation disabled"} - , - {0, NULL} -}; + {COMMUNICATION_ENABLE, "enabled"}, + {COMMUNICATION_DISABLE, "disabled"}, + {COMMUNICATION_DISABLE_INITIATION, "initiation disabled"}, + {0, NULL}}; -const char *bactext_device_communications_name( - unsigned index) +const char *bactext_device_communications_name(unsigned index) { return indtext_by_index_default(bacnet_device_communications_names, index, - ASHRAE_Reserved_String); + ASHRAE_Reserved_String); } diff --git a/src/bactimevalue.c b/src/bactimevalue.c index 9071a039..e3a9d28b 100644 --- a/src/bactimevalue.c +++ b/src/bactimevalue.c @@ -37,8 +37,7 @@ #include "bacdcode.h" #include "bactimevalue.h" -int bacapp_encode_time_value(uint8_t * apdu, - BACNET_TIME_VALUE * value) +int bacapp_encode_time_value(uint8_t* apdu, BACNET_TIME_VALUE* value) { int len; int apdu_len = 0; @@ -52,9 +51,8 @@ int bacapp_encode_time_value(uint8_t * apdu, return apdu_len; } -int bacapp_encode_context_time_value(uint8_t * apdu, - uint8_t tag_number, - BACNET_TIME_VALUE * value) +int bacapp_encode_context_time_value(uint8_t* apdu, uint8_t tag_number, + BACNET_TIME_VALUE* value) { int len; int apdu_len = 0; @@ -71,8 +69,7 @@ int bacapp_encode_context_time_value(uint8_t * apdu, return apdu_len; } -int bacapp_decode_time_value(uint8_t * apdu, - BACNET_TIME_VALUE * value) +int bacapp_decode_time_value(uint8_t* apdu, BACNET_TIME_VALUE* value) { int len; int apdu_len = 0; @@ -90,9 +87,8 @@ int bacapp_decode_time_value(uint8_t * apdu, return apdu_len; } -int bacapp_decode_context_time_value(uint8_t * apdu, - uint8_t tag_number, - BACNET_TIME_VALUE * value) +int bacapp_decode_context_time_value(uint8_t* apdu, uint8_t tag_number, + BACNET_TIME_VALUE* value) { int len = 0; int section_length; diff --git a/src/bigend.c b/src/bigend.c index a411d0bb..2ccf6d07 100644 --- a/src/bigend.c +++ b/src/bigend.c @@ -35,8 +35,7 @@ /* function to return true on Big-Endian architectures */ /* (based on Harbison & Steele) */ -int big_endian( - void) +int big_endian(void) { union { long l; diff --git a/src/bip.c b/src/bip.c index 493a23df..f7aa8b6b 100644 --- a/src/bip.c +++ b/src/bip.c @@ -32,22 +32,22 @@ ------------------------------------------- ####COPYRIGHTEND####*/ -#include /* for standard integer types uint8_t etc. */ -#include /* for the standard bool type. */ +#include /* for standard integer types uint8_t etc. */ +#include /* for the standard bool type. */ #include "bacdcode.h" #include "bacint.h" #include "bip.h" #include "bvlc.h" -#include "net.h" /* custom per port */ +#include "net.h" /* custom per port */ #if PRINT_ENABLED -#include /* for standard i/o, like printing */ +#include /* for standard i/o, like printing */ #endif /** @file bip.c Configuration and Operations for BACnet/IP */ static int BIP_Socket = -1; /* port to use - stored in network byte order */ -static uint16_t BIP_Port = 0; /* this will force initialization in demos */ +static uint16_t BIP_Port = 0; /* this will force initialization in demos */ /* IP Address - stored in network byte order */ static struct in_addr BIP_Address; /* Broadcast Address - stored in network byte order */ @@ -57,8 +57,7 @@ static struct in_addr BIP_Broadcast_Address; * * @param sock_fd [in] Handle for the BACnet/IP socket. */ -void bip_set_socket( - int sock_fd) +void bip_set_socket(int sock_fd) { BIP_Socket = sock_fd; } @@ -67,63 +66,53 @@ void bip_set_socket( * * @return The handle to the BACnet/IP socket. */ -int bip_socket( - void) +int bip_socket(void) { return BIP_Socket; } -bool bip_valid( - void) +bool bip_valid(void) { return (BIP_Socket != -1); } -void bip_set_addr( - uint32_t net_address) -{ /* in network byte order */ +void bip_set_addr(uint32_t net_address) +{ /* in network byte order */ BIP_Address.s_addr = net_address; } /* returns network byte order */ -uint32_t bip_get_addr( - void) +uint32_t bip_get_addr(void) { return BIP_Address.s_addr; } -void bip_set_broadcast_addr( - uint32_t net_address) -{ /* in network byte order */ +void bip_set_broadcast_addr(uint32_t net_address) +{ /* in network byte order */ BIP_Broadcast_Address.s_addr = net_address; } /* returns network byte order */ -uint32_t bip_get_broadcast_addr( - void) +uint32_t bip_get_broadcast_addr(void) { return BIP_Broadcast_Address.s_addr; } - -void bip_set_port( - uint16_t port) -{ /* in network byte order */ +void bip_set_port(uint16_t port) +{ /* in network byte order */ BIP_Port = port; } /* returns network byte order */ -uint16_t bip_get_port( - void) +uint16_t bip_get_port(void) { return BIP_Port; } static int bip_decode_bip_address( - BACNET_ADDRESS * bac_addr, - struct in_addr *address, /* in network format */ - uint16_t * port) -{ /* in network format */ + BACNET_ADDRESS *bac_addr, struct in_addr *address, /* in network format */ + uint16_t *port) +{ /* in network format */ int len = 0; if (bac_addr) { @@ -144,21 +133,20 @@ static int bip_decode_bip_address( * @param pdu_len [in] Number of bytes in the pdu buffer. * @return Number of bytes sent on success, negative number on failure. */ -int bip_send_pdu( - BACNET_ADDRESS * dest, /* destination address */ - BACNET_NPDU_DATA * npdu_data, /* network information */ - uint8_t * pdu, /* any data to be sent - may be null */ - unsigned pdu_len) -{ /* number of bytes of data */ +int bip_send_pdu(BACNET_ADDRESS *dest, /* destination address */ + BACNET_NPDU_DATA *npdu_data, /* network information */ + uint8_t *pdu, /* any data to be sent - may be null */ + unsigned pdu_len) +{ /* number of bytes of data */ struct sockaddr_in bip_dest; - uint8_t mtu[MAX_MPDU] = { 0 }; + uint8_t mtu[MAX_MPDU] = {0}; int mtu_len = 0; int bytes_sent = 0; /* addr and port in host format */ struct in_addr address; uint16_t port = 0; - (void) npdu_data; + (void)npdu_data; /* assumes that the driver has already been initialized */ if (BIP_Socket < 0) { return BIP_Socket; @@ -191,16 +179,14 @@ int bip_send_pdu( bip_dest.sin_port = port; memset(&(bip_dest.sin_zero), '\0', 8); mtu_len = 2; - mtu_len += - encode_unsigned16(&mtu[mtu_len], - (uint16_t) (pdu_len + 4 /*inclusive */ )); + mtu_len += encode_unsigned16(&mtu[mtu_len], + (uint16_t)(pdu_len + 4 /*inclusive */)); memcpy(&mtu[mtu_len], pdu, pdu_len); mtu_len += pdu_len; /* Send the packet */ - bytes_sent = - sendto(BIP_Socket, (char *) mtu, mtu_len, 0, - (struct sockaddr *) &bip_dest, sizeof(struct sockaddr)); + bytes_sent = sendto(BIP_Socket, (char *)mtu, mtu_len, 0, + (struct sockaddr *)&bip_dest, sizeof(struct sockaddr)); return bytes_sent; } @@ -211,23 +197,24 @@ int bip_send_pdu( * * @param src [out] Source of the packet - who should receive any response. * @param pdu [out] A buffer to hold the PDU portion of the received packet, - * after the BVLC portion has been stripped off. + * after the BVLC portion has been stripped + * off. * @param max_pdu [in] Size of the pdu[] buffer. * @param timeout [in] The number of milliseconds to wait for a packet. * @return The number of octets (remaining) in the PDU, or zero on failure. */ uint16_t bip_receive( - BACNET_ADDRESS * src, /* source address */ - uint8_t * pdu, /* PDU data */ - uint16_t max_pdu, /* amount of space available in the PDU */ + BACNET_ADDRESS *src, /* source address */ + uint8_t *pdu, /* PDU data */ + uint16_t max_pdu, /* amount of space available in the PDU */ unsigned timeout) { int received_bytes = 0; - uint16_t pdu_len = 0; /* return value */ + uint16_t pdu_len = 0; /* return value */ fd_set read_fds; int max = 0; struct timeval select_timeout; - struct sockaddr_in sin = { 0 }; + struct sockaddr_in sin = {0}; socklen_t sin_len = sizeof(sin); uint16_t i = 0; int function = 0; @@ -252,9 +239,8 @@ uint16_t bip_receive( max = BIP_Socket; /* see if there is a packet for us */ if (select(max + 1, &read_fds, NULL, NULL, &select_timeout) > 0) - received_bytes = - recvfrom(BIP_Socket, (char *) &pdu[0], max_pdu, 0, - (struct sockaddr *) &sin, &sin_len); + received_bytes = recvfrom(BIP_Socket, (char *)&pdu[0], max_pdu, 0, + (struct sockaddr *)&sin, &sin_len); else return 0; @@ -279,7 +265,7 @@ uint16_t bip_receive( return 0; } - function = bvlc_get_function_code(); /* aka, pdu[1] */ + function = bvlc_get_function_code(); /* aka, pdu[1] */ if ((function == BVLC_ORIGINAL_UNICAST_NPDU) || (function == BVLC_ORIGINAL_BROADCAST_NPDU)) { /* ignore messages from me */ @@ -297,7 +283,7 @@ uint16_t bip_receive( /* FIXME: check destination address */ /* see if it is broadcast or for us */ /* decode the length of the PDU - length is inclusive of BVLC */ - (void) decode_unsigned16(&pdu[2], &pdu_len); + (void)decode_unsigned16(&pdu[2], &pdu_len); /* subtract off the BVLC header */ pdu_len -= 4; if (pdu_len < max_pdu) { @@ -339,7 +325,7 @@ uint16_t bip_receive( /* FIXME: check destination address */ /* see if it is broadcast or for us */ /* decode the length of the PDU - length is inclusive of BVLC */ - (void) decode_unsigned16(&pdu[2], &pdu_len); + (void)decode_unsigned16(&pdu[2], &pdu_len); /* subtract off the BVLC header */ pdu_len -= 10; if (pdu_len < max_pdu) { @@ -358,8 +344,7 @@ uint16_t bip_receive( return pdu_len; } -void bip_get_my_address( - BACNET_ADDRESS * my_address) +void bip_get_my_address(BACNET_ADDRESS *my_address) { int i = 0; @@ -367,8 +352,8 @@ void bip_get_my_address( my_address->mac_len = 6; memcpy(&my_address->mac[0], &BIP_Address.s_addr, 4); memcpy(&my_address->mac[4], &BIP_Port, 2); - my_address->net = 0; /* local only, no routing */ - my_address->len = 0; /* no SLEN */ + my_address->net = 0; /* local only, no routing */ + my_address->len = 0; /* no SLEN */ for (i = 0; i < MAX_MAC_LEN; i++) { /* no SADR */ my_address->adr[i] = 0; @@ -378,17 +363,16 @@ void bip_get_my_address( return; } -void bip_get_broadcast_address( - BACNET_ADDRESS * dest) -{ /* destination address */ - int i = 0; /* counter */ +void bip_get_broadcast_address(BACNET_ADDRESS *dest) +{ /* destination address */ + int i = 0; /* counter */ if (dest) { dest->mac_len = 6; memcpy(&dest->mac[0], &BIP_Broadcast_Address.s_addr, 4); memcpy(&dest->mac[4], &BIP_Port, 2); dest->net = BACNET_BROADCAST_NETWORK; - dest->len = 0; /* no SLEN */ + dest->len = 0; /* no SLEN */ for (i = 0; i < MAX_MAC_LEN; i++) { /* no SADR */ dest->adr[i] = 0; diff --git a/src/bvlc.c b/src/bvlc.c index eca727cf..454973b2 100644 --- a/src/bvlc.c +++ b/src/bvlc.c @@ -32,8 +32,8 @@ ------------------------------------------- ####COPYRIGHTEND####*/ -#include /* for standard integer types uint8_t etc. */ -#include /* for the standard bool type. */ +#include /* for standard integer types uint8_t etc. */ +#include /* for the standard bool type. */ #include #include "bacenum.h" #include "bacdcode.h" @@ -64,7 +64,7 @@ static bool BVLC_NAT_Handling = false; BACNET_BVLC_RESULT BVLC_Result_Code = BVLC_RESULT_SUCCESSFUL_COMPLETION; /** The current BVLC Function Code being handled. */ -BACNET_BVLC_FUNCTION BVLC_Function_Code = BVLC_RESULT; /* A safe default */ +BACNET_BVLC_FUNCTION BVLC_Function_Code = BVLC_RESULT; /* A safe default */ /* Define BBMD_ENABLED to get the functions that a * BBMD needs to handle its services. @@ -73,7 +73,6 @@ BACNET_BVLC_FUNCTION BVLC_Function_Code = BVLC_RESULT; /* A safe default */ */ #if defined(BBMD_ENABLED) && BBMD_ENABLED - #ifndef MAX_BBMD_ENTRIES #define MAX_BBMD_ENTRIES 128 #endif @@ -97,7 +96,7 @@ typedef struct { /* seconds for valid entry lifetime */ uint16_t time_to_live; /* our counter */ - time_t seconds_remaining; /* includes 30 second grace period */ + time_t seconds_remaining; /* includes 30 second grace period */ } FD_TABLE_ENTRY; #ifndef MAX_FD_ENTRIES @@ -105,13 +104,12 @@ typedef struct { #endif static FD_TABLE_ENTRY FD_Table[MAX_FD_ENTRIES]; - /* Define BBMD_BACKUP_FILE if the contents of the BDT - * (broadcast distribution table) are to be stored in + * (broadcast distribution table) are to be stored in * a backup file, so the contents are not lost across * power failures, shutdowns, etc... * (this is required behaviour as defined in BACnet standard). - * + * * BBMD_BACKUP_FILE should be set to the file name * in which to store the BDT. */ @@ -121,63 +119,63 @@ static FD_TABLE_ENTRY FD_Table[MAX_FD_ENTRIES]; #define tostr(a) str(a) #define str(a) #a -void bvlc_bdt_backup_local( - void) +void bvlc_bdt_backup_local(void) { static FILE *bdt_file_ptr = NULL; - + /* only try opening the file if not already opened previously */ if (!bdt_file_ptr) - bdt_file_ptr = fopen(tostr(BBMD_BACKUP_FILE),"wb"); - + bdt_file_ptr = fopen(tostr(BBMD_BACKUP_FILE), "wb"); + /* if error opening file for writing -> silently abort */ if (!bdt_file_ptr) return; - + fseek(bdt_file_ptr, 0, SEEK_SET); - fwrite(BBMD_Table, sizeof(BBMD_TABLE_ENTRY), MAX_BBMD_ENTRIES, bdt_file_ptr); + fwrite(BBMD_Table, sizeof(BBMD_TABLE_ENTRY), MAX_BBMD_ENTRIES, + bdt_file_ptr); fflush(bdt_file_ptr); } -void bvlc_bdt_restore_local( - void) +void bvlc_bdt_restore_local(void) { static FILE *bdt_file_ptr = NULL; - + /* only try opening the file if not already opened previously */ if (!bdt_file_ptr) - bdt_file_ptr = fopen(tostr(BBMD_BACKUP_FILE),"rb"); - + bdt_file_ptr = fopen(tostr(BBMD_BACKUP_FILE), "rb"); + /* if error opening file for reading -> silently abort */ if (!bdt_file_ptr) return; - + fseek(bdt_file_ptr, 0, SEEK_SET); { BBMD_TABLE_ENTRY BBMD_Table_tmp[MAX_BBMD_ENTRIES]; size_t entries = 0; - - entries = fread(BBMD_Table_tmp, sizeof(BBMD_TABLE_ENTRY), MAX_BBMD_ENTRIES, bdt_file_ptr); + + entries = fread(BBMD_Table_tmp, sizeof(BBMD_TABLE_ENTRY), + MAX_BBMD_ENTRIES, bdt_file_ptr); if (entries == MAX_BBMD_ENTRIES) /* success reading the BDT table. */ - memcpy(BBMD_Table, BBMD_Table_tmp, sizeof(BBMD_TABLE_ENTRY) * MAX_BBMD_ENTRIES); + memcpy(BBMD_Table, BBMD_Table_tmp, + sizeof(BBMD_TABLE_ENTRY) * MAX_BBMD_ENTRIES); } } #else -void bvlc_bdt_backup_local (void) {} -void bvlc_bdt_restore_local(void) {} +void bvlc_bdt_backup_local(void) +{ +} +void bvlc_bdt_restore_local(void) +{ +} #endif - - - - /** A timer function that is called about once a second. * * @param seconds - number of elapsed seconds since the last call */ -void bvlc_maintenance_timer( - time_t seconds) +void bvlc_maintenance_timer(time_t seconds) { unsigned i = 0; @@ -206,14 +204,13 @@ void bvlc_maintenance_timer( * * @return number of bytes decoded */ -static void bvlc_internet_to_bacnet_address( - BACNET_ADDRESS * src, - struct sockaddr_in *sin) +static void bvlc_internet_to_bacnet_address(BACNET_ADDRESS *src, + struct sockaddr_in *sin) { if (src && sin) { memcpy(&src->mac[0], &sin->sin_addr.s_addr, 4); memcpy(&src->mac[4], &sin->sin_port, 2); - src->mac_len = (uint8_t) 6; + src->mac_len = (uint8_t)6; src->net = 0; src->len = 0; } @@ -236,10 +233,8 @@ static void bvlc_internet_to_bacnet_address( * * @return number of bytes encoded */ -static int bvlc_encode_bip_address( - uint8_t * pdu, - struct in_addr *address, - uint16_t port) +static int bvlc_encode_bip_address(uint8_t *pdu, struct in_addr *address, + uint16_t port) { int len = 0; @@ -260,10 +255,8 @@ static int bvlc_encode_bip_address( * * @return number of bytes decoded */ -static int bvlc_decode_bip_address( - uint8_t * pdu, - struct in_addr *address, - uint16_t * port) +static int bvlc_decode_bip_address(uint8_t *pdu, struct in_addr *address, + uint16_t *port) { int len = 0; @@ -285,11 +278,8 @@ static int bvlc_decode_bip_address( * * @return number of bytes encoded */ -static int bvlc_encode_address_entry( - uint8_t * pdu, - struct in_addr *address, - uint16_t port, - struct in_addr *mask) +static int bvlc_encode_address_entry(uint8_t *pdu, struct in_addr *address, + uint16_t port, struct in_addr *mask) { int len = 0; @@ -303,7 +293,6 @@ static int bvlc_encode_address_entry( } #endif - /** Encode the BVLC Result message * * @param pdu - buffer to store the encoding @@ -311,9 +300,7 @@ static int bvlc_encode_address_entry( * * @return number of bytes encoded */ -static int bvlc_encode_bvlc_result( - uint8_t * pdu, - BACNET_BVLC_RESULT result_code) +static int bvlc_encode_bvlc_result(uint8_t *pdu, BACNET_BVLC_RESULT result_code) { if (pdu) { pdu[0] = BVLL_TYPE_BACNET_IP; @@ -322,7 +309,7 @@ static int bvlc_encode_bvlc_result( of the entire BVLL message, including the two octets of the length field itself, most significant octet first. */ encode_unsigned16(&pdu[2], 6); - encode_unsigned16(&pdu[4], (uint16_t) result_code); + encode_unsigned16(&pdu[4], (uint16_t)result_code); } return 6; @@ -336,9 +323,7 @@ static int bvlc_encode_bvlc_result( * * @return number of bytes encoded */ -int bvlc_encode_write_bdt_init( - uint8_t * pdu, - unsigned entries) +int bvlc_encode_write_bdt_init(uint8_t *pdu, unsigned entries) { int len = 0; uint16_t BVLC_length = 0; @@ -349,7 +334,7 @@ int bvlc_encode_write_bdt_init( /* The 2-octet BVLC Length field is the length, in octets, of the entire BVLL message, including the two octets of the length field itself, most significant octet first. */ - BVLC_length = 4 + (uint16_t) (entries * 10); + BVLC_length = 4 + (uint16_t)(entries * 10); encode_unsigned16(&pdu[2], BVLC_length); len = 4; } @@ -364,8 +349,7 @@ int bvlc_encode_write_bdt_init( * * @return number of bytes encoded */ -int bvlc_encode_read_bdt( - uint8_t * pdu) +int bvlc_encode_read_bdt(uint8_t *pdu) { int len = 0; @@ -391,14 +375,12 @@ int bvlc_encode_read_bdt( * @return Upon successful completion, returns the number of bytes sent. * Otherwise, -1 shall be returned and errno set to indicate the error. */ -int bvlc_bbmd_read_bdt( - uint32_t bbmd_address, - uint16_t bbmd_port) +int bvlc_bbmd_read_bdt(uint32_t bbmd_address, uint16_t bbmd_port) { - uint8_t mtu[MAX_MPDU] = { 0 }; + uint8_t mtu[MAX_MPDU] = {0}; uint16_t mtu_len = 0; int rv = 0; - struct sockaddr_in bbmd = { 0 }; + struct sockaddr_in bbmd = {0}; mtu_len = bvlc_encode_read_bdt(mtu); if (mtu_len > 0) { @@ -418,9 +400,7 @@ int bvlc_bbmd_read_bdt( * * @return number of bytes encoded */ -static int bvlc_encode_read_bdt_ack_init( - uint8_t * pdu, - unsigned entries) +static int bvlc_encode_read_bdt_ack_init(uint8_t *pdu, unsigned entries) { int len = 0; uint16_t BVLC_length = 0; @@ -431,7 +411,7 @@ static int bvlc_encode_read_bdt_ack_init( /* The 2-octet BVLC Length field is the length, in octets, of the entire BVLL message, including the two octets of the length field itself, most significant octet first. */ - BVLC_length = 4 + (uint16_t) (entries * 10); + BVLC_length = 4 + (uint16_t)(entries * 10); encode_unsigned16(&pdu[2], BVLC_length); len = 4; } @@ -446,11 +426,9 @@ static int bvlc_encode_read_bdt_ack_init( * * @return number of bytes encoded */ -static int bvlc_encode_read_bdt_ack( - uint8_t * pdu, - uint16_t max_pdu) +static int bvlc_encode_read_bdt_ack(uint8_t *pdu, uint16_t max_pdu) { - int pdu_len = 0; /* return value */ + int pdu_len = 0; /* return value */ int len = 0; unsigned count = 0; unsigned i; @@ -469,10 +447,9 @@ static int bvlc_encode_read_bdt_ack( pdu_len = 0; break; } - len = - bvlc_encode_address_entry(&pdu[pdu_len], - &BBMD_Table[i].dest_address, BBMD_Table[i].dest_port, - &BBMD_Table[i].broadcast_mask); + len = bvlc_encode_address_entry( + &pdu[pdu_len], &BBMD_Table[i].dest_address, + BBMD_Table[i].dest_port, &BBMD_Table[i].broadcast_mask); pdu_len += len; } } @@ -490,12 +467,9 @@ static int bvlc_encode_read_bdt_ack( * * @return number of bytes encoded */ -static int bvlc_encode_forwarded_npdu( - uint8_t * pdu, - uint16_t max_pdu, - struct sockaddr_in *sin, - uint8_t * npdu, - unsigned npdu_length) +static int bvlc_encode_forwarded_npdu(uint8_t *pdu, uint16_t max_pdu, + struct sockaddr_in *sin, uint8_t *npdu, + unsigned npdu_length) { int len = 0; @@ -508,12 +482,11 @@ static int bvlc_encode_forwarded_npdu( /* The 2-octet BVLC Length field is the length, in octets, of the entire BVLL message, including the two octets of the length field itself, most significant octet first. */ - encode_unsigned16(&pdu[2], (uint16_t) (4 + 6 + npdu_length)); + encode_unsigned16(&pdu[2], (uint16_t)(4 + 6 + npdu_length)); len = 4; /* 6-octet address encoding */ - len += - bvlc_encode_bip_address(&pdu[len], &sin->sin_addr, - sin->sin_port); + len += bvlc_encode_bip_address(&pdu[len], &sin->sin_addr, + sin->sin_port); for (i = 0; i < npdu_length; i++) { pdu[len] = npdu[i]; len++; @@ -532,8 +505,7 @@ static int bvlc_encode_forwarded_npdu( * * @return number of bytes encoded */ -int bvlc_encode_read_fdt( - uint8_t * pdu) +int bvlc_encode_read_fdt(uint8_t *pdu) { int len = 0; @@ -551,7 +523,6 @@ int bvlc_encode_read_fdt( } #endif - #if defined(BBMD_ENABLED) && BBMD_ENABLED /** Encode the initial part of a Read Foreign Device Table Ack * @@ -560,9 +531,7 @@ int bvlc_encode_read_fdt( * * @return number of bytes encoded */ -static int bvlc_encode_read_fdt_ack_init( - uint8_t * pdu, - unsigned entries) +static int bvlc_encode_read_fdt_ack_init(uint8_t *pdu, unsigned entries) { int len = 0; uint16_t BVLC_length = 0; @@ -573,7 +542,7 @@ static int bvlc_encode_read_fdt_ack_init( /* The 2-octet BVLC Length field is the length, in octets, of the entire BVLL message, including the two octets of the length field itself, most significant octet first. */ - BVLC_length = 4 + (uint16_t) (entries * 10); + BVLC_length = 4 + (uint16_t)(entries * 10); encode_unsigned16(&pdu[2], BVLC_length); len = 4; } @@ -588,11 +557,9 @@ static int bvlc_encode_read_fdt_ack_init( * * @return number of bytes encoded */ -static int bvlc_encode_read_fdt_ack( - uint8_t * pdu, - uint16_t max_pdu) +static int bvlc_encode_read_fdt_ack(uint8_t *pdu, uint16_t max_pdu) { - int pdu_len = 0; /* return value */ + int pdu_len = 0; /* return value */ int len = 0; unsigned count = 0; unsigned i; @@ -612,13 +579,13 @@ static int bvlc_encode_read_fdt_ack( pdu_len = 0; break; } - len = - bvlc_encode_bip_address(&pdu[pdu_len], - &FD_Table[i].dest_address, FD_Table[i].dest_port); + len = bvlc_encode_bip_address(&pdu[pdu_len], + &FD_Table[i].dest_address, + FD_Table[i].dest_port); pdu_len += len; len = encode_unsigned16(&pdu[pdu_len], FD_Table[i].time_to_live); pdu_len += len; - seconds_remaining = (uint16_t) FD_Table[i].seconds_remaining; + seconds_remaining = (uint16_t)FD_Table[i].seconds_remaining; len = encode_unsigned16(&pdu[pdu_len], seconds_remaining); pdu_len += len; } @@ -628,7 +595,6 @@ static int bvlc_encode_read_fdt_ack( } #endif - #if defined(BBMD_CLIENT_ENABLED) && BBMD_CLIENT_ENABLED /** Encode an Foreign Device Table entry * @@ -638,10 +604,7 @@ static int bvlc_encode_read_fdt_ack( * * @return number of bytes encoded */ -int bvlc_encode_delete_fdt_entry( - uint8_t * pdu, - uint32_t address, - uint16_t port) +int bvlc_encode_delete_fdt_entry(uint8_t *pdu, uint32_t address, uint16_t port) { int len = 0; @@ -671,13 +634,11 @@ int bvlc_encode_delete_fdt_entry( * * @return number of bytes encoded */ -int bvlc_encode_original_unicast_npdu( - uint8_t * pdu, - uint8_t * npdu, - unsigned npdu_length) +int bvlc_encode_original_unicast_npdu(uint8_t *pdu, uint8_t *npdu, + unsigned npdu_length) { - int len = 0; /* return value */ - unsigned i = 0; /* loop counter */ + int len = 0; /* return value */ + unsigned i = 0; /* loop counter */ uint16_t BVLC_length = 0; if (pdu) { @@ -686,7 +647,7 @@ int bvlc_encode_original_unicast_npdu( /* The 2-octet BVLC Length field is the length, in octets, of the entire BVLL message, including the two octets of the length field itself, most significant octet first. */ - BVLC_length = 4 + (uint16_t) npdu_length; + BVLC_length = 4 + (uint16_t)npdu_length; len = encode_unsigned16(&pdu[2], BVLC_length) + 2; for (i = 0; i < npdu_length; i++) { pdu[len] = npdu[i]; @@ -707,13 +668,11 @@ int bvlc_encode_original_unicast_npdu( * * @return number of bytes encoded */ -int bvlc_encode_original_broadcast_npdu( - uint8_t * pdu, - uint8_t * npdu, - unsigned npdu_length) +int bvlc_encode_original_broadcast_npdu(uint8_t *pdu, uint8_t *npdu, + unsigned npdu_length) { - int len = 0; /* return value */ - unsigned i = 0; /* loop counter */ + int len = 0; /* return value */ + unsigned i = 0; /* loop counter */ uint16_t BVLC_length = 0; if (pdu) { @@ -722,7 +681,7 @@ int bvlc_encode_original_broadcast_npdu( /* The 2-octet BVLC Length field is the length, in octets, of the entire BVLL message, including the two octets of the length field itself, most significant octet first. */ - BVLC_length = 4 + (uint16_t) npdu_length; + BVLC_length = 4 + (uint16_t)npdu_length; len = encode_unsigned16(&pdu[2], BVLC_length) + 2; for (i = 0; i < npdu_length; i++) { pdu[len] = npdu[i]; @@ -734,7 +693,6 @@ int bvlc_encode_original_broadcast_npdu( } #endif - #if defined(BBMD_ENABLED) && BBMD_ENABLED /** Create a Broadcast Distribution Table from message * @@ -743,9 +701,7 @@ int bvlc_encode_original_broadcast_npdu( * * @return true if all the entries fit in the table */ -static bool bvlc_create_bdt( - uint8_t * npdu, - uint16_t npdu_length) +static bool bvlc_create_bdt(uint8_t *npdu, uint16_t npdu_length) { bool status = false; unsigned i = 0; @@ -786,9 +742,8 @@ static bool bvlc_create_bdt( * * @return true if the Foreign Device was added */ -static bool bvlc_register_foreign_device( - struct sockaddr_in *sin, - uint16_t time_to_live) +static bool bvlc_register_foreign_device(struct sockaddr_in *sin, + uint16_t time_to_live) { unsigned i = 0; bool status = false; @@ -823,7 +778,6 @@ static bool bvlc_register_foreign_device( } } - return status; } @@ -833,12 +787,10 @@ static bool bvlc_register_foreign_device( * * @return true if the Foreign Device was found and removed. */ -static bool bvlc_delete_foreign_device( - uint8_t * pdu, - uint16_t pdu_len) +static bool bvlc_delete_foreign_device(uint8_t *pdu, uint16_t pdu_len) { - struct sockaddr_in sin = { 0 }; /* the ip address */ - bool status = false; /* return value */ + struct sockaddr_in sin = {0}; /* the ip address */ + bool status = false; /* return value */ unsigned i = 0; if (pdu_len < 6) { @@ -872,12 +824,9 @@ static bool bvlc_delete_foreign_device( * @return Upon successful completion, returns the number of bytes sent. * Otherwise, -1 shall be returned and errno set to indicate the error. */ -int bvlc_send_mpdu( - struct sockaddr_in *dest, - uint8_t * mtu, - uint16_t mtu_len) +int bvlc_send_mpdu(struct sockaddr_in *dest, uint8_t *mtu, uint16_t mtu_len) { - struct sockaddr_in bvlc_dest = { 0 }; + struct sockaddr_in bvlc_dest = {0}; /* assumes that the driver has already been initialized */ if (bip_socket() < 0) { @@ -889,8 +838,8 @@ int bvlc_send_mpdu( bvlc_dest.sin_port = dest->sin_port; memset(&(bvlc_dest.sin_zero), '\0', 8); /* Send the packet */ - return sendto(bip_socket(), (char *) mtu, mtu_len, 0, - (struct sockaddr *) &bvlc_dest, sizeof(struct sockaddr)); + return sendto(bip_socket(), (char *)mtu, mtu_len, 0, + (struct sockaddr *)&bvlc_dest, sizeof(struct sockaddr)); } #if defined(BBMD_ENABLED) && BBMD_ENABLED @@ -902,16 +851,13 @@ int bvlc_send_mpdu( * @param npdu_length - length of the NPDU * @param original - was the message an original (not forwarded) */ -static void bvlc_bdt_forward_npdu( - struct sockaddr_in *sin, - uint8_t * npdu, - uint16_t npdu_length, - bool original) +static void bvlc_bdt_forward_npdu(struct sockaddr_in *sin, uint8_t *npdu, + uint16_t npdu_length, bool original) { - uint8_t mtu[MAX_MPDU] = { 0 }; + uint8_t mtu[MAX_MPDU] = {0}; uint16_t mtu_len = 0; - unsigned i = 0; /* loop counter */ - struct sockaddr_in bip_dest = { 0 }; + unsigned i = 0; /* loop counter */ + struct sockaddr_in bip_dest = {0}; /* If we are forwarding an original broadcast message and the NAT * handling is enabled, change the source address to NAT routers @@ -921,15 +867,14 @@ static void bvlc_bdt_forward_npdu( * If we are forwarding a message from peer BBMD or foreign device * or the NAT handling is disabled, leave the source address as is. */ - if(BVLC_NAT_Handling && original) { + if (BVLC_NAT_Handling && original) { struct sockaddr_in nat_addr = *sin; nat_addr.sin_addr = BVLC_Global_Address; - mtu_len = (uint16_t) bvlc_encode_forwarded_npdu(&mtu[0], - (uint16_t)sizeof(mtu), &nat_addr, npdu, npdu_length); - } - else { - mtu_len = (uint16_t) bvlc_encode_forwarded_npdu(&mtu[0], - (uint16_t)sizeof(mtu), sin, npdu, npdu_length); + mtu_len = (uint16_t)bvlc_encode_forwarded_npdu( + &mtu[0], (uint16_t)sizeof(mtu), &nat_addr, npdu, npdu_length); + } else { + mtu_len = (uint16_t)bvlc_encode_forwarded_npdu( + &mtu[0], (uint16_t)sizeof(mtu), sin, npdu, npdu_length); } /* loop through the BDT and send one to each entry, except us */ for (i = 0; i < MAX_BBMD_ENTRIES; i++) { @@ -938,13 +883,12 @@ static void bvlc_bdt_forward_npdu( sent is formed by inverting the broadcast distribution mask in the BDT entry and logically ORing it with the BBMD address of the same entry. */ - bip_dest.sin_addr.s_addr = - ((~BBMD_Table[i].broadcast_mask. - s_addr) | BBMD_Table[i].dest_address.s_addr); + bip_dest.sin_addr.s_addr = ((~BBMD_Table[i].broadcast_mask.s_addr) | + BBMD_Table[i].dest_address.s_addr); bip_dest.sin_port = BBMD_Table[i].dest_port; /* don't send to my broadcast address and same port */ - if ((bip_dest.sin_addr.s_addr == bip_get_broadcast_addr()) - && (bip_dest.sin_port == bip_get_port())) { + if ((bip_dest.sin_addr.s_addr == bip_get_broadcast_addr()) && + (bip_dest.sin_port == bip_get_port())) { continue; } /* don't send to my ip address and same port */ @@ -963,7 +907,8 @@ static void bvlc_bdt_forward_npdu( } bvlc_send_mpdu(&bip_dest, mtu, mtu_len); debug_printf("BVLC: BDT Sent Forwarded-NPDU to %s:%04X\n", - inet_ntoa(bip_dest.sin_addr), ntohs(bip_dest.sin_port)); + inet_ntoa(bip_dest.sin_addr), + ntohs(bip_dest.sin_port)); } } @@ -978,18 +923,15 @@ static void bvlc_bdt_forward_npdu( * @param max_npdu - amount of space available in the NPDU * @param npdu_length - reported length of the NPDU */ -static void bvlc_forward_npdu( - struct sockaddr_in *sin, - uint8_t * npdu, - uint16_t npdu_length) +static void bvlc_forward_npdu(struct sockaddr_in *sin, uint8_t *npdu, + uint16_t npdu_length) { - uint8_t mtu[MAX_MPDU] = { 0 }; + uint8_t mtu[MAX_MPDU] = {0}; uint16_t mtu_len = 0; - struct sockaddr_in bip_dest = { 0 }; + struct sockaddr_in bip_dest = {0}; - mtu_len = - (uint16_t) bvlc_encode_forwarded_npdu(&mtu[0], - (uint16_t)sizeof(mtu), sin, npdu, npdu_length); + mtu_len = (uint16_t)bvlc_encode_forwarded_npdu( + &mtu[0], (uint16_t)sizeof(mtu), sin, npdu, npdu_length); bip_dest.sin_addr.s_addr = bip_get_broadcast_addr(); bip_dest.sin_port = bip_get_port(); bvlc_send_mpdu(&bip_dest, mtu, mtu_len); @@ -1004,16 +946,13 @@ static void bvlc_forward_npdu( * @param npdu_length - reported length of the NPDU * @param original - was the message an original (not forwarded) */ -static void bvlc_fdt_forward_npdu( - struct sockaddr_in *sin, - uint8_t * npdu, - uint16_t npdu_length, - bool original) +static void bvlc_fdt_forward_npdu(struct sockaddr_in *sin, uint8_t *npdu, + uint16_t npdu_length, bool original) { - uint8_t mtu[MAX_MPDU] = { 0 }; + uint8_t mtu[MAX_MPDU] = {0}; uint16_t mtu_len = 0; - unsigned i = 0; /* loop counter */ - struct sockaddr_in bip_dest = { 0 }; + unsigned i = 0; /* loop counter */ + struct sockaddr_in bip_dest = {0}; /* If we are forwarding an original broadcast message and the NAT * handling is enabled, change the source address to NAT routers @@ -1023,14 +962,14 @@ static void bvlc_fdt_forward_npdu( * If we are forwarding a message from peer BBMD or foreign device * or the NAT handling is disabled, leave the source address as is. */ - if(BVLC_NAT_Handling && original) { + if (BVLC_NAT_Handling && original) { struct sockaddr_in nat_addr = *sin; nat_addr.sin_addr = BVLC_Global_Address; - mtu_len = (uint16_t)bvlc_encode_forwarded_npdu(&mtu[0], - (uint16_t)sizeof(mtu), &nat_addr, npdu, npdu_length); + mtu_len = (uint16_t)bvlc_encode_forwarded_npdu( + &mtu[0], (uint16_t)sizeof(mtu), &nat_addr, npdu, npdu_length); } else { - mtu_len = (uint16_t)bvlc_encode_forwarded_npdu(&mtu[0], - (uint16_t)sizeof(mtu), sin, npdu, npdu_length); + mtu_len = (uint16_t)bvlc_encode_forwarded_npdu( + &mtu[0], (uint16_t)sizeof(mtu), sin, npdu, npdu_length); } /* loop through the FDT and send one to each entry */ @@ -1059,7 +998,8 @@ static void bvlc_fdt_forward_npdu( } bvlc_send_mpdu(&bip_dest, mtu, mtu_len); debug_printf("BVLC: FDT Sent Forwarded-NPDU to %s:%04X\n", - inet_ntoa(bip_dest.sin_addr), ntohs(bip_dest.sin_port)); + inet_ntoa(bip_dest.sin_addr), + ntohs(bip_dest.sin_port)); } } @@ -1067,7 +1007,6 @@ static void bvlc_fdt_forward_npdu( } #endif - /** Sends a BVLC Result * * @param dest - destination address @@ -1076,13 +1015,13 @@ static void bvlc_fdt_forward_npdu( * @return number of bytes encoded to send */ static int bvlc_send_result( - struct sockaddr_in *dest, /* the destination address */ + struct sockaddr_in *dest, /* the destination address */ BACNET_BVLC_RESULT result_code) { - uint8_t mtu[MAX_MPDU] = { 0 }; + uint8_t mtu[MAX_MPDU] = {0}; uint16_t mtu_len = 0; - mtu_len = (uint16_t) bvlc_encode_bvlc_result(&mtu[0], result_code); + mtu_len = (uint16_t)bvlc_encode_bvlc_result(&mtu[0], result_code); if (mtu_len) { bvlc_send_mpdu(dest, mtu, mtu_len); } @@ -1097,13 +1036,12 @@ static int bvlc_send_result( * * @return number of bytes encoded to send */ -static int bvlc_send_bdt( - struct sockaddr_in *dest) +static int bvlc_send_bdt(struct sockaddr_in *dest) { - uint8_t mtu[MAX_MPDU] = { 0 }; + uint8_t mtu[MAX_MPDU] = {0}; uint16_t mtu_len = 0; - mtu_len = (uint16_t) bvlc_encode_read_bdt_ack(&mtu[0], sizeof(mtu)); + mtu_len = (uint16_t)bvlc_encode_read_bdt_ack(&mtu[0], sizeof(mtu)); if (mtu_len) { bvlc_send_mpdu(dest, &mtu[0], mtu_len); } @@ -1117,13 +1055,12 @@ static int bvlc_send_bdt( * * @return number of bytes encoded to send */ -static int bvlc_send_fdt( - struct sockaddr_in *dest) +static int bvlc_send_fdt(struct sockaddr_in *dest) { - uint8_t mtu[MAX_MPDU] = { 0 }; + uint8_t mtu[MAX_MPDU] = {0}; uint16_t mtu_len = 0; - mtu_len = (uint16_t) bvlc_encode_read_fdt_ack(&mtu[0], sizeof(mtu)); + mtu_len = (uint16_t)bvlc_encode_read_fdt_ack(&mtu[0], sizeof(mtu)); if (mtu_len) { bvlc_send_mpdu(dest, &mtu[0], mtu_len); } @@ -1137,15 +1074,13 @@ static int bvlc_send_fdt( * * @return True if BDT member is found and has a unicast mask */ -static bool bvlc_bdt_member_mask_is_unicast( - struct sockaddr_in *sin) +static bool bvlc_bdt_member_mask_is_unicast(struct sockaddr_in *sin) { bool unicast = false; - unsigned i = 0; /* loop counter */ + unsigned i = 0; /* loop counter */ for (i = 0; i < MAX_BBMD_ENTRIES; i++) { if (BBMD_Table[i].valid) { - /* Skip ourself*/ if ((BBMD_Table[i].dest_address.s_addr == bip_get_addr()) && (BBMD_Table[i].dest_port == bip_get_port())) { @@ -1176,19 +1111,16 @@ static bool bvlc_bdt_member_mask_is_unicast( * * @return Number of bytes received, or 0 if none or timeout. */ -uint16_t bvlc_receive( - BACNET_ADDRESS * src, - uint8_t * npdu, - uint16_t max_npdu, - unsigned timeout) +uint16_t bvlc_receive(BACNET_ADDRESS *src, uint8_t *npdu, uint16_t max_npdu, + unsigned timeout) { - uint16_t npdu_len = 0; /* return value */ + uint16_t npdu_len = 0; /* return value */ fd_set read_fds; int max = 0; struct timeval select_timeout; - struct sockaddr_in sin = { 0 }; - struct sockaddr_in original_sin = { 0 }; - struct sockaddr_in dest = { 0 }; + struct sockaddr_in sin = {0}; + struct sockaddr_in original_sin = {0}; + struct sockaddr_in dest = {0}; socklen_t sin_len = sizeof(sin); int received_bytes = 0; uint16_t result_code = 0; @@ -1217,9 +1149,8 @@ uint16_t bvlc_receive( max = bip_socket(); /* see if there is a packet for us */ if (select(max + 1, &read_fds, NULL, NULL, &select_timeout) > 0) { - received_bytes = - recvfrom(bip_socket(), (char *) &npdu[0], max_npdu, 0, - (struct sockaddr *) &sin, &sin_len); + received_bytes = recvfrom(bip_socket(), (char *)&npdu[0], max_npdu, 0, + (struct sockaddr *)&sin, &sin_len); } else { return 0; } @@ -1237,8 +1168,8 @@ uint16_t bvlc_receive( } BVLC_Function_Code = npdu[1]; /* decode the length of the PDU - length is inclusive of BVLC */ - (void) decode_unsigned16(&npdu[2], &npdu_len); - if ((npdu_len < 4) || (npdu_len > (max_npdu-4))) { + (void)decode_unsigned16(&npdu[2], &npdu_len); + if ((npdu_len < 4) || (npdu_len > (max_npdu - 4))) { return 0; } /* subtract off the BVLC header */ @@ -1253,8 +1184,8 @@ uint16_t bvlc_receive( foreign device shall re-register with the BBMD by sending a BVLL Register-Foreign-Device message */ /* Clients can now get this result */ - (void) decode_unsigned16(&npdu[4], &result_code); - BVLC_Result_Code = (BACNET_BVLC_RESULT) result_code; + (void)decode_unsigned16(&npdu[4], &result_code); + BVLC_Result_Code = (BACNET_BVLC_RESULT)result_code; debug_printf("BVLC: Result Code=%d\n", BVLC_Result_Code); /* not an NPDU */ npdu_len = 0; @@ -1273,8 +1204,8 @@ uint16_t bvlc_receive( if (status) { bvlc_send_result(&sin, BVLC_RESULT_SUCCESSFUL_COMPLETION); } else { - bvlc_send_result(&sin, - BVLC_RESULT_WRITE_BROADCAST_DISTRIBUTION_TABLE_NAK); + bvlc_send_result( + &sin, BVLC_RESULT_WRITE_BROADCAST_DISTRIBUTION_TABLE_NAK); } /* not an NPDU */ npdu_len = 0; @@ -1289,8 +1220,8 @@ uint16_t bvlc_receive( originating device with a result code of X'0020' indicating that the read attempt has failed. */ if (bvlc_send_bdt(&sin) <= 0) { - bvlc_send_result(&sin, - BVLC_RESULT_READ_BROADCAST_DISTRIBUTION_TABLE_NAK); + bvlc_send_result( + &sin, BVLC_RESULT_READ_BROADCAST_DISTRIBUTION_TABLE_NAK); } /* not an NPDU */ npdu_len = 0; @@ -1306,43 +1237,47 @@ uint16_t bvlc_receive( process it according to whether it was received from a peer BBMD as the result of a directed broadcast or a unicast transmission. A BBMD may ascertain the method by which Forwarded- - NPDU messages will arrive by inspecting the broadcast distribution - mask field in its own BDT entry since all BDTs are required - to be identical. If the message arrived via directed broadcast, - it was also received by the other devices on the BBMD's subnet. In - this case the BBMD merely retransmits the message directly to each - foreign device currently in the BBMD's FDT. If the - message arrived via a unicast transmission it has not yet been - received by the other devices on the BBMD's subnet. In this case, - the message is sent to the devices on the BBMD's subnet using the - B/IP broadcast address as well as to each foreign device - currently in the BBMD's FDT. A BBMD on a subnet with no other - BACnet devices may omit the broadcast using the B/IP - broadcast address. The method by which a BBMD determines whether - or not other BACnet devices are present is a local matter. */ + NPDU messages will arrive by inspecting the broadcast + distribution mask field in its own BDT entry since all BDTs are + required to be identical. If the message arrived via directed + broadcast, it was also received by the other devices on the + BBMD's subnet. In this case the BBMD merely retransmits the + message directly to each foreign device currently in the BBMD's + FDT. If the message arrived via a unicast transmission it has not + yet been received by the other devices on the BBMD's subnet. In + this case, the message is sent to the devices on the BBMD's + subnet using the B/IP broadcast address as well as to each + foreign device currently in the BBMD's FDT. A BBMD on a subnet + with no other BACnet devices may omit the broadcast using the + B/IP broadcast address. The method by which a BBMD determines + whether or not other BACnet devices are present is a local + matter. */ if (npdu_len < 6) { return 0; } /* decode the 4 byte original address and 2 byte port */ bvlc_decode_bip_address(&npdu[4], &original_sin.sin_addr, - &original_sin.sin_port); + &original_sin.sin_port); debug_printf("BVLC: Received Forwarded-NPDU from %s:%04X.\n", - inet_ntoa(original_sin.sin_addr), ntohs(original_sin.sin_port)); + inet_ntoa(original_sin.sin_addr), + ntohs(original_sin.sin_port)); npdu_len -= 6; /* Broadcast locally if received via unicast from a BDT member */ if (bvlc_bdt_member_mask_is_unicast(&sin)) { dest.sin_addr.s_addr = bip_get_broadcast_addr(); dest.sin_port = bip_get_port(); - debug_printf("BVLC: Received unicast from BDT member, re-broadcasting locally to %s:%04X.\n", - inet_ntoa(dest.sin_addr), ntohs(dest.sin_port)); - bvlc_send_mpdu(&dest, &npdu[0], npdu_len+4+6); + debug_printf( + "BVLC: Received unicast from BDT member, re-broadcasting " + "locally to %s:%04X.\n", + inet_ntoa(dest.sin_addr), ntohs(dest.sin_port)); + bvlc_send_mpdu(&dest, &npdu[0], npdu_len + 4 + 6); } /* use the original addr from the BVLC for src */ dest.sin_addr.s_addr = original_sin.sin_addr.s_addr; dest.sin_port = original_sin.sin_port; bvlc_fdt_forward_npdu(&dest, &npdu[4 + 6], npdu_len, false); debug_printf("BVLC: Received Forwarded-NPDU from %s:%04X.\n", - inet_ntoa(dest.sin_addr), ntohs(dest.sin_port)); + inet_ntoa(dest.sin_addr), ntohs(dest.sin_port)); bvlc_internet_to_bacnet_address(src, &dest); if (npdu_len < max_npdu) { /* shift the buffer to return a valid NPDU */ @@ -1368,13 +1303,12 @@ uint16_t bvlc_receive( if (npdu_len < 2) { return 0; } - (void) decode_unsigned16(&npdu[4], &time_to_live); + (void)decode_unsigned16(&npdu[4], &time_to_live); if (bvlc_register_foreign_device(&sin, time_to_live)) { bvlc_send_result(&sin, BVLC_RESULT_SUCCESSFUL_COMPLETION); debug_printf("BVLC: Registered a Foreign Device.\n"); } else { - bvlc_send_result(&sin, - BVLC_RESULT_REGISTER_FOREIGN_DEVICE_NAK); + bvlc_send_result(&sin, BVLC_RESULT_REGISTER_FOREIGN_DEVICE_NAK); debug_printf("BVLC: Failed to Register a Foreign Device.\n"); } /* not an NPDU */ @@ -1387,11 +1321,11 @@ uint16_t bvlc_receive( Foreign-Device-Table-Ack message and send it to the originating device. If the BBMD is unable to perform the read of its FDT, it shall return a BVLC-Result message to the originating device - with a result code of X'0040' indicating that the read attempt has - failed. */ + with a result code of X'0040' indicating that the read attempt + has failed. */ if (bvlc_send_fdt(&sin) <= 0) { bvlc_send_result(&sin, - BVLC_RESULT_READ_FOREIGN_DEVICE_TABLE_NAK); + BVLC_RESULT_READ_FOREIGN_DEVICE_TABLE_NAK); } /* not an NPDU */ npdu_len = 0; @@ -1405,25 +1339,26 @@ uint16_t bvlc_receive( case BVLC_DELETE_FOREIGN_DEVICE_TABLE_ENTRY: debug_printf("BVLC: Received Delete-FDT-Entry.\n"); /* Upon receipt of a BVLL Delete-Foreign-Device-Table-Entry - message, a BBMD shall search its foreign device table for an entry - corresponding to the B/IP address supplied in the message. If an - entry is found, it shall be deleted and the BBMD shall return a - BVLC-Result message to the originating device with a result code - of X'0000'. Otherwise, the BBMD shall return a BVLCResult - message to the originating device with a result code of X'0050' - indicating that the deletion attempt has failed. */ + message, a BBMD shall search its foreign device table for an + entry corresponding to the B/IP address supplied in the message. + If an entry is found, it shall be deleted and the BBMD shall + return a BVLC-Result message to the originating device with a + result code of X'0000'. Otherwise, the BBMD shall return a + BVLCResult message to the originating device with a result code + of X'0050' indicating that the deletion attempt has failed. */ if (bvlc_delete_foreign_device(&npdu[4], npdu_len)) { bvlc_send_result(&sin, BVLC_RESULT_SUCCESSFUL_COMPLETION); } else { - bvlc_send_result(&sin, - BVLC_RESULT_DELETE_FOREIGN_DEVICE_TABLE_ENTRY_NAK); + bvlc_send_result( + &sin, BVLC_RESULT_DELETE_FOREIGN_DEVICE_TABLE_ENTRY_NAK); } /* not an NPDU */ npdu_len = 0; break; case BVLC_DISTRIBUTE_BROADCAST_TO_NETWORK: - debug_printf - ("BVLC: Received Distribute-Broadcast-to-Network from %s:%04X.\n", + debug_printf( + "BVLC: Received Distribute-Broadcast-to-Network from " + "%s:%04X.\n", inet_ntoa(sin.sin_addr), ntohs(sin.sin_port)); /* Upon receipt of a BVLL Distribute-Broadcast-To-Network message from a foreign device, the receiving BBMD shall transmit a @@ -1450,10 +1385,10 @@ uint16_t bvlc_receive( /* ignore messages from me */ npdu_len = 0; } else if (BVLC_NAT_Handling && - (sin.sin_addr.s_addr == BVLC_Global_Address.s_addr) && - (sin.sin_port == bip_get_port())) { - /* If the BBMD is behind a NAT router, the router forwards packets from - global IP and BACnet port to us. */ + (sin.sin_addr.s_addr == BVLC_Global_Address.s_addr) && + (sin.sin_port == bip_get_port())) { + /* If the BBMD is behind a NAT router, the router forwards + packets from global IP and BACnet port to us. */ npdu_len = 0; } else { bvlc_internet_to_bacnet_address(src, &sin); @@ -1514,14 +1449,11 @@ uint16_t bvlc_receive( * * @return returns number of bytes sent on success, negative number on failure */ -int bvlc_send_pdu( - BACNET_ADDRESS * dest, - BACNET_NPDU_DATA * npdu_data, - uint8_t * pdu, - unsigned pdu_len) +int bvlc_send_pdu(BACNET_ADDRESS *dest, BACNET_NPDU_DATA *npdu_data, + uint8_t *pdu, unsigned pdu_len) { - struct sockaddr_in bvlc_dest = { 0 }; - uint8_t mtu[MAX_MPDU] = { 0 }; + struct sockaddr_in bvlc_dest = {0}; + uint8_t mtu[MAX_MPDU] = {0}; uint16_t mtu_len = 0; /* addr and port in network format */ struct in_addr address; @@ -1529,7 +1461,7 @@ int bvlc_send_pdu( uint16_t BVLC_length = 0; /* bip datalink doesn't need to know the npdu data */ - (void) npdu_data; + (void)npdu_data; mtu[0] = BVLL_TYPE_BACNET_IP; /* handle various broadcasts: */ /* mac_len = 0 is a broadcast address */ @@ -1569,16 +1501,15 @@ int bvlc_send_pdu( } bvlc_dest.sin_addr.s_addr = address.s_addr; bvlc_dest.sin_port = port; - BVLC_length = (uint16_t) pdu_len + 4 /*inclusive */ ; + BVLC_length = (uint16_t)pdu_len + 4 /*inclusive */; mtu_len = 2; - mtu_len += (uint16_t) encode_unsigned16(&mtu[mtu_len], BVLC_length); + mtu_len += (uint16_t)encode_unsigned16(&mtu[mtu_len], BVLC_length); memcpy(&mtu[mtu_len], pdu, pdu_len); - mtu_len += (uint16_t) pdu_len; + mtu_len += (uint16_t)pdu_len; return bvlc_send_mpdu(&bvlc_dest, mtu, mtu_len); } #endif - /*********************************************** * Functions to register us as a foreign device. ********************************************* */ @@ -1591,9 +1522,8 @@ int bvlc_send_pdu( * @return Number of bytes encoded) on success, * or 0 if no encoding occurred. */ -static int bvlc_encode_register_foreign_device( - uint8_t * pdu, - uint16_t time_to_live_seconds) +static int bvlc_encode_register_foreign_device(uint8_t *pdu, + uint16_t time_to_live_seconds) { int len = 0; @@ -1620,12 +1550,10 @@ static int bvlc_encode_register_foreign_device( * 0 if no registration request is sent, or * -1 if registration fails. */ -int bvlc_register_with_bbmd( - uint32_t bbmd_address, - uint16_t bbmd_port, - uint16_t time_to_live_seconds) +int bvlc_register_with_bbmd(uint32_t bbmd_address, uint16_t bbmd_port, + uint16_t time_to_live_seconds) { - uint8_t mtu[MAX_MPDU] = { 0 }; + uint8_t mtu[MAX_MPDU] = {0}; uint16_t mtu_len = 0; int retval = 0; @@ -1637,14 +1565,12 @@ int bvlc_register_with_bbmd( we need to register our address with the remote BBMD using Write Broadcast Distribution Table, or register with the BBMD as a Foreign Device */ - mtu_len = - (uint16_t) bvlc_encode_register_foreign_device(&mtu[0], - time_to_live_seconds); + mtu_len = (uint16_t)bvlc_encode_register_foreign_device( + &mtu[0], time_to_live_seconds); retval = bvlc_send_mpdu(&Remote_BBMD, &mtu[0], mtu_len); return retval; } - /** Note any BVLC_RESULT code, or NAK the BVLL message in the unsupported cases. * Use this handler when you are not a BBMD. * Sets the BVLC_Function_Code in case it is needed later. @@ -1655,20 +1581,18 @@ int bvlc_register_with_bbmd( * @return Non-zero BVLC_RESULT_ code if we sent a response (NAK) to this * BVLC message. If zero, may need further processing. */ -int bvlc_for_non_bbmd( - struct sockaddr_in *sout, - uint8_t * npdu, - uint16_t received_bytes) +int bvlc_for_non_bbmd(struct sockaddr_in *sout, uint8_t *npdu, + uint16_t received_bytes) { - uint16_t result_code = 0; /* aka, BVLC_RESULT_SUCCESSFUL_COMPLETION */ + uint16_t result_code = 0; /* aka, BVLC_RESULT_SUCCESSFUL_COMPLETION */ - BVLC_Function_Code = npdu[1]; /* The BVLC function */ + BVLC_Function_Code = npdu[1]; /* The BVLC function */ switch (BVLC_Function_Code) { case BVLC_RESULT: if (received_bytes >= 6) { /* This is the result of our foreign device registration */ - (void) decode_unsigned16(&npdu[4], &result_code); - BVLC_Result_Code = (BACNET_BVLC_RESULT) result_code; + (void)decode_unsigned16(&npdu[4], &result_code); + BVLC_Result_Code = (BACNET_BVLC_RESULT)result_code; debug_printf("BVLC: Result Code=%d\n", BVLC_Result_Code); /* But don't send any response */ result_code = 0; @@ -1716,8 +1640,7 @@ int bvlc_for_non_bbmd( * BVLC_RESULT_REGISTER_FOREIGN_DEVICE_NAK if registration failed, * or one of the other codes (if we are a BBMD). */ -BACNET_BVLC_RESULT bvlc_get_last_result( - void) +BACNET_BVLC_RESULT bvlc_get_last_result(void) { return BVLC_Result_Code; } @@ -1729,8 +1652,7 @@ BACNET_BVLC_RESULT bvlc_get_last_result( * * @return A BVLC_ code, such as BVLC_ORIGINAL_UNICAST_NPDU. */ -BACNET_BVLC_FUNCTION bvlc_get_function_code( - void) +BACNET_BVLC_FUNCTION bvlc_get_function_code(void) { return BVLC_Function_Code; } @@ -1745,12 +1667,11 @@ BACNET_BVLC_FUNCTION bvlc_get_function_code( * * @return Number of valid entries in the table or -1 on error. */ -int bvlc_get_bdt_local( - const BBMD_TABLE_ENTRY** table) +int bvlc_get_bdt_local(const BBMD_TABLE_ENTRY **table) { int count = 0; - if(table == NULL) + if (table == NULL) return -1; *table = BBMD_Table; @@ -1766,8 +1687,7 @@ int bvlc_get_bdt_local( /** Invalidate all entries in the broadcast distribution table (BDT). */ -void bvlc_clear_bdt_local( - void) +void bvlc_clear_bdt_local(void) { int i = 0; for (i = 0; i < MAX_BBMD_ENTRIES; ++i) { @@ -1784,13 +1704,12 @@ void bvlc_clear_bdt_local( * * @return True if the new entry was added successfully. */ -bool bvlc_add_bdt_entry_local( - BBMD_TABLE_ENTRY* entry) +bool bvlc_add_bdt_entry_local(BBMD_TABLE_ENTRY *entry) { bool found = false; int i = 0; - if(entry == NULL) + if (entry == NULL) return false; /* Find first empty slot */ @@ -1801,14 +1720,15 @@ bool bvlc_add_bdt_entry_local( } /* Make sure that we are not adding a duplicate */ - if(BBMD_Table[i].dest_address.s_addr == entry->dest_address.s_addr && - BBMD_Table[i].broadcast_mask.s_addr == entry->broadcast_mask.s_addr && - BBMD_Table[i].dest_port == entry->dest_port) { + if (BBMD_Table[i].dest_address.s_addr == entry->dest_address.s_addr && + BBMD_Table[i].broadcast_mask.s_addr == + entry->broadcast_mask.s_addr && + BBMD_Table[i].dest_port == entry->dest_port) { return false; } } - if(!found) + if (!found) return false; /* Copy new entry to the empty slot */ @@ -1825,7 +1745,7 @@ bool bvlc_add_bdt_entry_local( /** Enable NAT handling and set the global IP address * @param [in] - Global IP address visible to peer BBMDs and foreign devices */ -void bvlc_set_global_address_for_nat(const struct in_addr* addr) +void bvlc_set_global_address_for_nat(const struct in_addr *addr) { BVLC_Global_Address = *addr; BVLC_NAT_Handling = true; @@ -1841,7 +1761,6 @@ void bvlc_disable_nat(void) debug_printf("BVLC: NAT Address disabled.\n"); } - #ifdef TEST #include #include @@ -1850,9 +1769,9 @@ void bvlc_disable_nat(void) /* copy the source internet address to the BACnet address */ /* FIXME: IPv6? */ static void bvlc_bacnet_to_internet_address( - struct sockaddr_in *sin, /* source address in network order */ - BACNET_ADDRESS * src) -{ /* returns the BACnet source address */ + struct sockaddr_in *sin, /* source address in network order */ + BACNET_ADDRESS *src) +{ /* returns the BACnet source address */ if (src && sin) { if (src->mac_len == 6) { @@ -1864,10 +1783,9 @@ static void bvlc_bacnet_to_internet_address( return; } -void testBIPAddress( - Test * pTest) +void testBIPAddress(Test *pTest) { - uint8_t apdu[50] = { 0 }; + uint8_t apdu[50] = {0}; uint32_t value = 0, test_value = 0; int len = 0, test_len = 0; struct in_addr address; @@ -1882,13 +1800,12 @@ void testBIPAddress( ct_test(pTest, port == test_port); } -void testInternetAddress( - Test * pTest) +void testInternetAddress(Test *pTest) { BACNET_ADDRESS src; BACNET_ADDRESS test_src; - struct sockaddr_in sin = { 0 }; - struct sockaddr_in test_sin = { 0 }; + struct sockaddr_in sin = {0}; + struct sockaddr_in test_sin = {0}; sin.sin_port = htons(0xBAC0); sin.sin_addr.s_addr = inet_addr("192.168.0.1"); @@ -1899,8 +1816,7 @@ void testInternetAddress( } #ifdef TEST_BVLC -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -1914,7 +1830,7 @@ int main( /* configure output */ ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/src/bvlc6.c b/src/bvlc6.c index f77692a6..14ce9a93 100644 --- a/src/bvlc6.c +++ b/src/bvlc6.c @@ -32,8 +32,8 @@ ------------------------------------------- ####COPYRIGHTEND####*/ -#include /* for standard integer types uint8_t etc. */ -#include /* for the standard bool type. */ +#include /* for standard integer types uint8_t etc. */ +#include /* for the standard bool type. */ #include #include "bacenum.h" #include "bacdcode.h" @@ -53,11 +53,8 @@ * * @return number of bytes encoded */ -int bvlc6_encode_header( - uint8_t * pdu, - uint16_t pdu_size, - uint8_t message_type, - uint16_t length) +int bvlc6_encode_header(uint8_t *pdu, uint16_t pdu_size, uint8_t message_type, + uint16_t length) { int bytes_encoded = 0; @@ -83,11 +80,8 @@ int bvlc6_encode_header( * * @return number of bytes decoded */ -int bvlc6_decode_header( - uint8_t * pdu, - uint16_t pdu_len, - uint8_t * message_type, - uint16_t * length) +int bvlc6_decode_header(uint8_t *pdu, uint16_t pdu_len, uint8_t *message_type, + uint16_t *length) { int bytes_consumed = 0; @@ -106,7 +100,6 @@ int bvlc6_decode_header( return bytes_consumed; } - /** Encode the BVLC Result message * * This message provides a mechanism to acknowledge the result @@ -127,21 +120,18 @@ int bvlc6_decode_header( * X'0030' Address-Resolution NAK * X'0060' Virtual-Address-Resolution NAK * X'0090' Register-Foreign-Device NAK - * X'00A0' Delete-Foreign-Device-Table-Entry NAK - * X'00C0' Distribute-Broadcast-To-Network NAK + * X'00A0' Delete-Foreign-Device-Table-Entry + * NAK X'00C0' Distribute-Broadcast-To-Network NAK */ -int bvlc6_encode_result( - uint8_t * pdu, - uint16_t pdu_size, - uint32_t vmac, - uint16_t result_code) +int bvlc6_encode_result(uint8_t *pdu, uint16_t pdu_size, uint32_t vmac, + uint16_t result_code) { int bytes_encoded = 0; const uint16_t length = 9; if (pdu && (pdu_size >= 9) && (vmac <= 0xFFFFFF)) { - bytes_encoded = bvlc6_encode_header(pdu, pdu_size, - BVLC6_RESULT, length); + bytes_encoded = + bvlc6_encode_header(pdu, pdu_size, BVLC6_RESULT, length); if (bytes_encoded == 4) { encode_unsigned24(&pdu[4], vmac); encode_unsigned16(&pdu[7], result_code); @@ -161,11 +151,8 @@ int bvlc6_encode_result( * * @return number of bytes decoded */ -int bvlc6_decode_result( - uint8_t * pdu, - uint16_t pdu_len, - uint32_t * vmac, - uint16_t * result_code) +int bvlc6_decode_result(uint8_t *pdu, uint16_t pdu_len, uint32_t *vmac, + uint16_t *result_code) { int bytes_consumed = 0; @@ -203,32 +190,25 @@ int bvlc6_decode_result( * Destination-Virtual-Address: 3-octets * BACnet NPDU: Variable length */ -int bvlc6_encode_original_unicast( - uint8_t * pdu, - uint16_t pdu_size, - uint32_t vmac_src, - uint32_t vmac_dst, - uint8_t * npdu, - uint16_t npdu_len) +int bvlc6_encode_original_unicast(uint8_t *pdu, uint16_t pdu_size, + uint32_t vmac_src, uint32_t vmac_dst, + uint8_t *npdu, uint16_t npdu_len) { int bytes_encoded = 0; uint16_t length = 10; uint16_t i = 0; - length += npdu_len; - if (pdu && - (pdu_size >= length) && - (vmac_src <= 0xFFFFFF) && + if (pdu && (pdu_size >= length) && (vmac_src <= 0xFFFFFF) && (vmac_dst <= 0xFFFFFF)) { - bytes_encoded = bvlc6_encode_header(pdu, pdu_size, - BVLC6_ORIGINAL_UNICAST_NPDU, length); + bytes_encoded = bvlc6_encode_header( + pdu, pdu_size, BVLC6_ORIGINAL_UNICAST_NPDU, length); if (bytes_encoded == 4) { encode_unsigned24(&pdu[4], vmac_src); encode_unsigned24(&pdu[7], vmac_dst); if (npdu && length) { for (i = 0; i < npdu_len; i++) { - pdu[10+i] = npdu[i]; + pdu[10 + i] = npdu[i]; } } bytes_encoded = (int)length; @@ -250,14 +230,10 @@ int bvlc6_encode_original_unicast( * * @return number of bytes decoded */ -int bvlc6_decode_original_unicast( - uint8_t * pdu, - uint16_t pdu_len, - uint32_t * vmac_src, - uint32_t * vmac_dst, - uint8_t * npdu, - uint16_t npdu_size, - uint16_t * npdu_len) +int bvlc6_decode_original_unicast(uint8_t *pdu, uint16_t pdu_len, + uint32_t *vmac_src, uint32_t *vmac_dst, + uint8_t *npdu, uint16_t npdu_size, + uint16_t *npdu_len) { int bytes_consumed = 0; uint16_t length = 0; @@ -273,7 +249,7 @@ int bvlc6_decode_original_unicast( length = pdu_len - 6; if (npdu && length && (length <= npdu_size)) { for (i = 0; i < length; i++) { - npdu[i] = pdu[6+i]; + npdu[i] = pdu[6 + i]; } } if (npdu_len) { @@ -304,28 +280,23 @@ int bvlc6_decode_original_unicast( * Source-Virtual-Address: 3-octets * BACnet NPDU: Variable length */ -int bvlc6_encode_original_broadcast( - uint8_t * pdu, - uint16_t pdu_size, - uint32_t vmac, - uint8_t * npdu, - uint16_t npdu_len) +int bvlc6_encode_original_broadcast(uint8_t *pdu, uint16_t pdu_size, + uint32_t vmac, uint8_t *npdu, + uint16_t npdu_len) { int bytes_encoded = 0; uint16_t length = 7; uint16_t i = 0; length += npdu_len; - if (pdu && - (pdu_size >= length) && - (vmac <= 0xFFFFFF)) { - bytes_encoded = bvlc6_encode_header(pdu, pdu_size, - BVLC6_ORIGINAL_BROADCAST_NPDU, length); + if (pdu && (pdu_size >= length) && (vmac <= 0xFFFFFF)) { + bytes_encoded = bvlc6_encode_header( + pdu, pdu_size, BVLC6_ORIGINAL_BROADCAST_NPDU, length); if (bytes_encoded == 4) { encode_unsigned24(&pdu[4], vmac); if (npdu && length) { for (i = 0; i < npdu_len; i++) { - pdu[7+i] = npdu[i]; + pdu[7 + i] = npdu[i]; } } bytes_encoded = (int)length; @@ -346,13 +317,9 @@ int bvlc6_encode_original_broadcast( * * @return number of bytes decoded */ -int bvlc6_decode_original_broadcast( - uint8_t * pdu, - uint16_t pdu_len, - uint32_t * vmac, - uint8_t * npdu, - uint16_t npdu_size, - uint16_t * npdu_len) +int bvlc6_decode_original_broadcast(uint8_t *pdu, uint16_t pdu_len, + uint32_t *vmac, uint8_t *npdu, + uint16_t npdu_size, uint16_t *npdu_len) { int bytes_consumed = 0; uint16_t length = 0; @@ -365,7 +332,7 @@ int bvlc6_decode_original_broadcast( length = pdu_len - 3; if (npdu && length && (length <= npdu_size)) { for (i = 0; i < length; i++) { - npdu[i] = pdu[3+i]; + npdu[i] = pdu[3 + i]; } } if (npdu_len) { @@ -396,21 +363,16 @@ int bvlc6_decode_original_broadcast( * Source-Virtual-Address: 3-octets * Target-Virtual-Address: 3-octets */ -int bvlc6_encode_address_resolution( - uint8_t * pdu, - uint16_t pdu_size, - uint32_t vmac_src, - uint32_t vmac_target) +int bvlc6_encode_address_resolution(uint8_t *pdu, uint16_t pdu_size, + uint32_t vmac_src, uint32_t vmac_target) { int bytes_encoded = 0; uint16_t length = 10; - - if (pdu && (pdu_size >= length) && - (vmac_src <= 0xFFFFFF) && + if (pdu && (pdu_size >= length) && (vmac_src <= 0xFFFFFF) && (vmac_target <= 0xFFFFFF)) { bytes_encoded = bvlc6_encode_header(pdu, pdu_size, - BVLC6_ADDRESS_RESOLUTION, length); + BVLC6_ADDRESS_RESOLUTION, length); if (bytes_encoded == 4) { encode_unsigned24(&pdu[4], vmac_src); encode_unsigned24(&pdu[7], vmac_target); @@ -430,11 +392,8 @@ int bvlc6_encode_address_resolution( * * @return number of bytes decoded */ -int bvlc6_decode_address_resolution( - uint8_t * pdu, - uint16_t pdu_len, - uint32_t * vmac_src, - uint32_t * vmac_target) +int bvlc6_decode_address_resolution(uint8_t *pdu, uint16_t pdu_len, + uint32_t *vmac_src, uint32_t *vmac_target) { int bytes_consumed = 0; @@ -464,10 +423,8 @@ int bvlc6_decode_address_resolution( * * @return number of bytes encoded */ -int bvlc6_encode_address( - uint8_t * pdu, - uint16_t pdu_size, - BACNET_IP6_ADDRESS * bip6_address) +int bvlc6_encode_address(uint8_t *pdu, uint16_t pdu_size, + BACNET_IP6_ADDRESS *bip6_address) { int bytes_encoded = 0; uint16_t length = BIP6_ADDRESS_MAX; @@ -492,10 +449,8 @@ int bvlc6_encode_address( * * @return number of bytes decoded */ -int bvlc6_decode_address( - uint8_t * pdu, - uint16_t pdu_len, - BACNET_IP6_ADDRESS * bip6_address) +int bvlc6_decode_address(uint8_t *pdu, uint16_t pdu_len, + BACNET_IP6_ADDRESS *bip6_address) { int bytes_consumed = 0; uint16_t length = BIP6_ADDRESS_MAX; @@ -524,9 +479,7 @@ int bvlc6_decode_address( * * @return true if the address was copied */ -bool bvlc6_address_copy( - BACNET_IP6_ADDRESS * dst, - BACNET_IP6_ADDRESS * src) +bool bvlc6_address_copy(BACNET_IP6_ADDRESS *dst, BACNET_IP6_ADDRESS *src) { bool status = false; unsigned int i = 0; @@ -554,9 +507,7 @@ bool bvlc6_address_copy( * * @return true if the addresses are different */ -bool bvlc6_address_different( - BACNET_IP6_ADDRESS * dst, - BACNET_IP6_ADDRESS * src) +bool bvlc6_address_different(BACNET_IP6_ADDRESS *dst, BACNET_IP6_ADDRESS *src) { bool status = false; unsigned int i = 0; @@ -594,16 +545,9 @@ bool bvlc6_address_different( * * @return true if the address is set */ -bool bvlc6_address_set( - BACNET_IP6_ADDRESS * addr, - uint16_t addr0, - uint16_t addr1, - uint16_t addr2, - uint16_t addr3, - uint16_t addr4, - uint16_t addr5, - uint16_t addr6, - uint16_t addr7) +bool bvlc6_address_set(BACNET_IP6_ADDRESS *addr, uint16_t addr0, uint16_t addr1, + uint16_t addr2, uint16_t addr3, uint16_t addr4, + uint16_t addr5, uint16_t addr6, uint16_t addr7) { bool status = false; @@ -641,16 +585,10 @@ bool bvlc6_address_set( * * @return true if the address is set */ -bool bvlc6_address_get( - BACNET_IP6_ADDRESS * addr, - uint16_t *addr0, - uint16_t *addr1, - uint16_t *addr2, - uint16_t *addr3, - uint16_t *addr4, - uint16_t *addr5, - uint16_t *addr6, - uint16_t *addr7) +bool bvlc6_address_get(BACNET_IP6_ADDRESS *addr, uint16_t *addr0, + uint16_t *addr1, uint16_t *addr2, uint16_t *addr3, + uint16_t *addr4, uint16_t *addr5, uint16_t *addr6, + uint16_t *addr7) { bool status = false; @@ -692,9 +630,7 @@ bool bvlc6_address_get( * * @return true if the address is set */ -bool bvlc6_vmac_address_set( - BACNET_ADDRESS * addr, - uint32_t device_id) +bool bvlc6_vmac_address_set(BACNET_ADDRESS *addr, uint32_t device_id) { bool status = false; @@ -716,9 +652,7 @@ bool bvlc6_vmac_address_set( * * @return true if the address is set */ -bool bvlc6_vmac_address_get( - BACNET_ADDRESS * addr, - uint32_t *device_id) +bool bvlc6_vmac_address_get(BACNET_ADDRESS *addr, uint32_t *device_id) { bool status = false; @@ -753,30 +687,26 @@ bool bvlc6_vmac_address_get( * Target-Virtual-Address: 3-octets * Original-Source-B/IPv6-Address 18-octets */ -int bvlc6_encode_forwarded_address_resolution( - uint8_t * pdu, - uint16_t pdu_size, - uint32_t vmac_src, - uint32_t vmac_target, - BACNET_IP6_ADDRESS * bip6_address) +int bvlc6_encode_forwarded_address_resolution(uint8_t *pdu, uint16_t pdu_size, + uint32_t vmac_src, + uint32_t vmac_target, + BACNET_IP6_ADDRESS *bip6_address) { int bytes_encoded = 0; uint16_t length = 0x001C; uint16_t offset = 0; - if (pdu && (pdu_size >= length) && - (vmac_src <= 0xFFFFFF) && - (vmac_target <= 0xFFFFFF) && - bip6_address) { - bytes_encoded = bvlc6_encode_header(pdu, pdu_size, - BVLC6_FORWARDED_ADDRESS_RESOLUTION, length); + if (pdu && (pdu_size >= length) && (vmac_src <= 0xFFFFFF) && + (vmac_target <= 0xFFFFFF) && bip6_address) { + bytes_encoded = bvlc6_encode_header( + pdu, pdu_size, BVLC6_FORWARDED_ADDRESS_RESOLUTION, length); if (bytes_encoded == 4) { offset = 4; encode_unsigned24(&pdu[offset], vmac_src); offset += 3; encode_unsigned24(&pdu[offset], vmac_target); offset += 3; - bvlc6_encode_address(&pdu[offset], pdu_size-offset, bip6_address); + bvlc6_encode_address(&pdu[offset], pdu_size - offset, bip6_address); bytes_encoded = (int)length; } } @@ -794,12 +724,10 @@ int bvlc6_encode_forwarded_address_resolution( * * @return number of bytes decoded */ -int bvlc6_decode_forwarded_address_resolution( - uint8_t * pdu, - uint16_t pdu_len, - uint32_t * vmac_src, - uint32_t * vmac_target, - BACNET_IP6_ADDRESS * bip6_address) +int bvlc6_decode_forwarded_address_resolution(uint8_t *pdu, uint16_t pdu_len, + uint32_t *vmac_src, + uint32_t *vmac_target, + BACNET_IP6_ADDRESS *bip6_address) { int bytes_consumed = 0; const uint16_t length = 3 + 3 + BIP6_ADDRESS_MAX; @@ -815,7 +743,7 @@ int bvlc6_decode_forwarded_address_resolution( } offset += 3; if (bip6_address) { - bvlc6_decode_address(&pdu[offset], pdu_len-offset, bip6_address); + bvlc6_decode_address(&pdu[offset], pdu_len - offset, bip6_address); } bytes_consumed = (int)length; } @@ -832,22 +760,18 @@ int bvlc6_decode_forwarded_address_resolution( * * @return number of bytes encoded */ -static int bvlc6_encode_address_ack( - uint8_t message_type, - uint8_t * pdu, - uint16_t pdu_size, - uint32_t vmac_src, - uint32_t vmac_dst) +static int bvlc6_encode_address_ack(uint8_t message_type, uint8_t *pdu, + uint16_t pdu_size, uint32_t vmac_src, + uint32_t vmac_dst) { int bytes_encoded = 0; const uint16_t length = 10; uint16_t offset = 0; - if (pdu && (pdu_size >= length) && - (vmac_src <= 0xFFFFFF) && + if (pdu && (pdu_size >= length) && (vmac_src <= 0xFFFFFF) && (vmac_dst <= 0xFFFFFF)) { - bytes_encoded = bvlc6_encode_header(pdu, pdu_size, - message_type, length); + bytes_encoded = + bvlc6_encode_header(pdu, pdu_size, message_type, length); if (bytes_encoded == 4) { offset = 4; encode_unsigned24(&pdu[offset], vmac_src); @@ -878,15 +802,11 @@ static int bvlc6_encode_address_ack( * Source-Virtual-Address: 3-octets * Destination-Virtual-Address: 3-octets */ -int bvlc6_encode_address_resolution_ack( - uint8_t * pdu, - uint16_t pdu_size, - uint32_t vmac_src, - uint32_t vmac_dst) +int bvlc6_encode_address_resolution_ack(uint8_t *pdu, uint16_t pdu_size, + uint32_t vmac_src, uint32_t vmac_dst) { - return bvlc6_encode_address_ack( - BVLC6_ADDRESS_RESOLUTION_ACK, - pdu, pdu_size,vmac_src, vmac_dst); + return bvlc6_encode_address_ack(BVLC6_ADDRESS_RESOLUTION_ACK, pdu, pdu_size, + vmac_src, vmac_dst); } /** Decode the BVLC Address-Resolution-Ack message @@ -898,11 +818,8 @@ int bvlc6_encode_address_resolution_ack( * * @return number of bytes decoded */ -int bvlc6_decode_address_resolution_ack( - uint8_t * pdu, - uint16_t pdu_len, - uint32_t * vmac_src, - uint32_t * vmac_dst) +int bvlc6_decode_address_resolution_ack(uint8_t *pdu, uint16_t pdu_len, + uint32_t *vmac_src, uint32_t *vmac_dst) { int bytes_consumed = 0; const uint16_t length = 6; @@ -938,18 +855,15 @@ int bvlc6_decode_address_resolution_ack( * BVLC Length: 2-octets X'0007' Length of the BVLL message * Source-Virtual-Address: 3-octets */ -int bvlc6_encode_virtual_address_resolution( - uint8_t * pdu, - uint16_t pdu_size, - uint32_t vmac_src) +int bvlc6_encode_virtual_address_resolution(uint8_t *pdu, uint16_t pdu_size, + uint32_t vmac_src) { int bytes_encoded = 0; const uint16_t length = 7; - if (pdu && (pdu_size >= length) && - (vmac_src <= 0xFFFFFF)) { - bytes_encoded = bvlc6_encode_header(pdu, pdu_size, - BVLC6_VIRTUAL_ADDRESS_RESOLUTION, length); + if (pdu && (pdu_size >= length) && (vmac_src <= 0xFFFFFF)) { + bytes_encoded = bvlc6_encode_header( + pdu, pdu_size, BVLC6_VIRTUAL_ADDRESS_RESOLUTION, length); if (bytes_encoded == 4) { encode_unsigned24(&pdu[4], vmac_src); bytes_encoded = (int)length; @@ -967,10 +881,8 @@ int bvlc6_encode_virtual_address_resolution( * * @return number of bytes decoded */ -int bvlc6_decode_virtual_address_resolution( - uint8_t * pdu, - uint16_t pdu_len, - uint32_t * vmac_src) +int bvlc6_decode_virtual_address_resolution(uint8_t *pdu, uint16_t pdu_len, + uint32_t *vmac_src) { int bytes_consumed = 0; @@ -1001,15 +913,12 @@ int bvlc6_decode_virtual_address_resolution( * Source-Virtual-Address: 3-octets * Destination-Virtual-Address: 3-octets */ -int bvlc6_encode_virtual_address_resolution_ack( - uint8_t * pdu, - uint16_t pdu_size, - uint32_t vmac_src, - uint32_t vmac_dst) +int bvlc6_encode_virtual_address_resolution_ack(uint8_t *pdu, uint16_t pdu_size, + uint32_t vmac_src, + uint32_t vmac_dst) { - return bvlc6_encode_address_ack( - BVLC6_VIRTUAL_ADDRESS_RESOLUTION_ACK, - pdu, pdu_size,vmac_src, vmac_dst); + return bvlc6_encode_address_ack(BVLC6_VIRTUAL_ADDRESS_RESOLUTION_ACK, pdu, + pdu_size, vmac_src, vmac_dst); } /** Decode the BVLC Virtual-Address-Resolution-Ack message @@ -1021,14 +930,12 @@ int bvlc6_encode_virtual_address_resolution_ack( * * @return number of bytes decoded */ -int bvlc6_decode_virtual_address_resolution_ack( - uint8_t * pdu, - uint16_t pdu_len, - uint32_t * vmac_src, - uint32_t * vmac_dst) +int bvlc6_decode_virtual_address_resolution_ack(uint8_t *pdu, uint16_t pdu_len, + uint32_t *vmac_src, + uint32_t *vmac_dst) { - return bvlc6_decode_address_resolution_ack(pdu, pdu_len, - vmac_src, vmac_dst); + return bvlc6_decode_address_resolution_ack(pdu, pdu_len, vmac_src, + vmac_dst); } /** Encode the BVLC Forwarded-NPDU message @@ -1054,35 +961,29 @@ int bvlc6_decode_virtual_address_resolution_ack( * Original-Source-B-IPv6-Address: 18-octets * BACnet NPDU from Originating Device: N-octets (N=L-25) */ -int bvlc6_encode_forwarded_npdu( - uint8_t * pdu, - uint16_t pdu_size, - uint32_t vmac_src, - BACNET_IP6_ADDRESS * bip6_address, - uint8_t * npdu, - uint16_t npdu_len) +int bvlc6_encode_forwarded_npdu(uint8_t *pdu, uint16_t pdu_size, + uint32_t vmac_src, + BACNET_IP6_ADDRESS *bip6_address, uint8_t *npdu, + uint16_t npdu_len) { int bytes_encoded = 0; - uint16_t length = 1+1+2+3+BIP6_ADDRESS_MAX; + uint16_t length = 1 + 1 + 2 + 3 + BIP6_ADDRESS_MAX; uint16_t i = 0; uint16_t offset = 0; length += npdu_len; - if (pdu && - (pdu_size >= length) && - (vmac_src <= 0xFFFFFF)) { - bytes_encoded = bvlc6_encode_header(pdu, pdu_size, - BVLC6_FORWARDED_NPDU, length); + if (pdu && (pdu_size >= length) && (vmac_src <= 0xFFFFFF)) { + bytes_encoded = + bvlc6_encode_header(pdu, pdu_size, BVLC6_FORWARDED_NPDU, length); if (bytes_encoded == 4) { offset = 4; encode_unsigned24(&pdu[offset], vmac_src); offset += 3; - bvlc6_encode_address(&pdu[offset], pdu_size-offset, - bip6_address); + bvlc6_encode_address(&pdu[offset], pdu_size - offset, bip6_address); offset += BIP6_ADDRESS_MAX; if (npdu && length) { for (i = 0; i < npdu_len; i++) { - pdu[offset+i] = npdu[i]; + pdu[offset + i] = npdu[i]; } } bytes_encoded = (int)length; @@ -1104,19 +1005,15 @@ int bvlc6_encode_forwarded_npdu( * * @return number of bytes decoded */ -int bvlc6_decode_forwarded_npdu( - uint8_t * pdu, - uint16_t pdu_len, - uint32_t * vmac_src, - BACNET_IP6_ADDRESS * bip6_address, - uint8_t * npdu, - uint16_t npdu_size, - uint16_t * npdu_len) +int bvlc6_decode_forwarded_npdu(uint8_t *pdu, uint16_t pdu_len, + uint32_t *vmac_src, + BACNET_IP6_ADDRESS *bip6_address, uint8_t *npdu, + uint16_t npdu_size, uint16_t *npdu_len) { int bytes_consumed = 0; uint16_t length = 0; uint16_t i = 0; - const uint16_t address_len = 3+BIP6_ADDRESS_MAX; + const uint16_t address_len = 3 + BIP6_ADDRESS_MAX; uint16_t offset = 0; if (pdu && (pdu_len >= address_len)) { @@ -1125,14 +1022,13 @@ int bvlc6_decode_forwarded_npdu( } offset += 3; if (bip6_address) { - bvlc6_decode_address(&pdu[offset], pdu_len-offset, - bip6_address); + bvlc6_decode_address(&pdu[offset], pdu_len - offset, bip6_address); } offset += BIP6_ADDRESS_MAX; length = pdu_len - offset; if (npdu && length && (length <= npdu_size)) { for (i = 0; i < length; i++) { - npdu[i] = pdu[offset+i]; + npdu[i] = pdu[offset + i]; } } if (npdu_len) { @@ -1163,20 +1059,17 @@ int bvlc6_decode_forwarded_npdu( * Source-Virtual-Address: 3-octets * Time-to-Live: 2-octets T Time-to-Live T, in seconds */ -int bvlc6_encode_register_foreign_device( - uint8_t * pdu, - uint16_t pdu_size, - uint32_t vmac_src, - uint16_t ttl_seconds) +int bvlc6_encode_register_foreign_device(uint8_t *pdu, uint16_t pdu_size, + uint32_t vmac_src, + uint16_t ttl_seconds) { int bytes_encoded = 0; const uint16_t length = 9; uint16_t offset = 0; - if (pdu && (pdu_size >= length) && - (vmac_src <= 0xFFFFFF)) { - bytes_encoded = bvlc6_encode_header(pdu, pdu_size, - BVLC6_REGISTER_FOREIGN_DEVICE, length); + if (pdu && (pdu_size >= length) && (vmac_src <= 0xFFFFFF)) { + bytes_encoded = bvlc6_encode_header( + pdu, pdu_size, BVLC6_REGISTER_FOREIGN_DEVICE, length); if (bytes_encoded == 4) { offset = 4; encode_unsigned24(&pdu[offset], vmac_src); @@ -1198,11 +1091,9 @@ int bvlc6_encode_register_foreign_device( * * @return number of bytes decoded */ -int bvlc6_decode_register_foreign_device( - uint8_t * pdu, - uint16_t pdu_len, - uint32_t * vmac_src, - uint16_t * ttl_seconds) +int bvlc6_decode_register_foreign_device(uint8_t *pdu, uint16_t pdu_len, + uint32_t *vmac_src, + uint16_t *ttl_seconds) { int bytes_consumed = 0; const uint16_t length = 5; @@ -1242,32 +1133,28 @@ int bvlc6_decode_register_foreign_device( * FDT Entry: 18-octets */ int bvlc6_encode_delete_foreign_device( - uint8_t * pdu, - uint16_t pdu_size, - uint32_t vmac_src, - BACNET_IP6_FOREIGN_DEVICE_TABLE_ENTRY * fdt_entry) + uint8_t *pdu, uint16_t pdu_size, uint32_t vmac_src, + BACNET_IP6_FOREIGN_DEVICE_TABLE_ENTRY *fdt_entry) { int bytes_encoded = 0; const uint16_t length = 0x0019; uint16_t offset = 0; - if (pdu && (pdu_size >= length) && - (vmac_src <= 0xFFFFFF)) { - bytes_encoded = bvlc6_encode_header(pdu, pdu_size, - BVLC6_DELETE_FOREIGN_DEVICE, length); + if (pdu && (pdu_size >= length) && (vmac_src <= 0xFFFFFF)) { + bytes_encoded = bvlc6_encode_header( + pdu, pdu_size, BVLC6_DELETE_FOREIGN_DEVICE, length); if (bytes_encoded == 4) { offset = 4; encode_unsigned24(&pdu[offset], vmac_src); offset += 3; if (fdt_entry) { - bvlc6_encode_address(&pdu[offset], pdu_size-offset, - &fdt_entry->bip6_address); + bvlc6_encode_address(&pdu[offset], pdu_size - offset, + &fdt_entry->bip6_address); offset += BIP6_ADDRESS_MAX; - encode_unsigned16(&pdu[offset], - fdt_entry->ttl_seconds); + encode_unsigned16(&pdu[offset], fdt_entry->ttl_seconds); offset += 2; encode_unsigned16(&pdu[offset], - fdt_entry->ttl_seconds_remaining); + fdt_entry->ttl_seconds_remaining); bytes_encoded = (int)length; } } @@ -1286,14 +1173,12 @@ int bvlc6_encode_delete_foreign_device( * @return number of bytes decoded */ int bvlc6_decode_delete_foreign_device( - uint8_t * pdu, - uint16_t pdu_len, - uint32_t * vmac_src, - BACNET_IP6_FOREIGN_DEVICE_TABLE_ENTRY * fdt_entry) + uint8_t *pdu, uint16_t pdu_len, uint32_t *vmac_src, + BACNET_IP6_FOREIGN_DEVICE_TABLE_ENTRY *fdt_entry) { int bytes_consumed = 0; - const uint16_t length = BIP6_ADDRESS_MAX+3+2+2-4; + const uint16_t length = BIP6_ADDRESS_MAX + 3 + 2 + 2 - 4; uint16_t offset = 0; if (pdu && (pdu_len >= length)) { @@ -1303,14 +1188,12 @@ int bvlc6_decode_delete_foreign_device( } offset += 3; if (fdt_entry) { - bvlc6_decode_address(&pdu[offset], pdu_len-offset, - &fdt_entry->bip6_address); + bvlc6_decode_address(&pdu[offset], pdu_len - offset, + &fdt_entry->bip6_address); offset += BIP6_ADDRESS_MAX; - decode_unsigned16(&pdu[offset], - &fdt_entry->ttl_seconds); + decode_unsigned16(&pdu[offset], &fdt_entry->ttl_seconds); offset += 2; - decode_unsigned16(&pdu[offset], - &fdt_entry->ttl_seconds_remaining); + decode_unsigned16(&pdu[offset], &fdt_entry->ttl_seconds_remaining); bytes_consumed = (int)length; } bytes_consumed = (int)length; @@ -1336,25 +1219,21 @@ int bvlc6_decode_delete_foreign_device( * BVLC Length: 2-octets L Length of the BVLL message * Security Wrapper: Variable length */ -int bvlc6_encode_secure_bvll( - uint8_t * pdu, - uint16_t pdu_size, - uint8_t * sbuf, - uint16_t sbuf_len) +int bvlc6_encode_secure_bvll(uint8_t *pdu, uint16_t pdu_size, uint8_t *sbuf, + uint16_t sbuf_len) { int bytes_encoded = 0; uint16_t length = 4; uint16_t i = 0; length += sbuf_len; - if (pdu && - (pdu_size >= length)) { - bytes_encoded = bvlc6_encode_header(pdu, pdu_size, - BVLC6_SECURE_BVLL, length); + if (pdu && (pdu_size >= length)) { + bytes_encoded = + bvlc6_encode_header(pdu, pdu_size, BVLC6_SECURE_BVLL, length); if (bytes_encoded == 4) { if (sbuf && sbuf_len) { for (i = 0; i < sbuf_len; i++) { - pdu[4+i] = sbuf[i]; + pdu[4 + i] = sbuf[i]; } } bytes_encoded = (int)length; @@ -1374,12 +1253,8 @@ int bvlc6_encode_secure_bvll( * * @return number of bytes decoded */ -int bvlc6_decode_secure_bvll( - uint8_t * pdu, - uint16_t pdu_len, - uint8_t * sbuf, - uint16_t sbuf_size, - uint16_t * sbuf_len) +int bvlc6_decode_secure_bvll(uint8_t *pdu, uint16_t pdu_len, uint8_t *sbuf, + uint16_t sbuf_size, uint16_t *sbuf_len) { int bytes_consumed = 0; uint16_t i = 0; @@ -1421,29 +1296,24 @@ int bvlc6_decode_secure_bvll( * Original-Source-Virtual-Address: 3-octets * BACnet NPDU from Originating Device: Variable length */ -int bvlc6_encode_distribute_broadcast_to_network( - uint8_t * pdu, - uint16_t pdu_size, - uint32_t vmac, - uint8_t * npdu, - uint16_t npdu_len) +int bvlc6_encode_distribute_broadcast_to_network(uint8_t *pdu, + uint16_t pdu_size, + uint32_t vmac, uint8_t *npdu, + uint16_t npdu_len) { int bytes_encoded = 0; uint16_t length = 7; uint16_t i = 0; - length += npdu_len; - if (pdu && - (pdu_size >= length) && - (vmac <= 0xFFFFFF)) { - bytes_encoded = bvlc6_encode_header(pdu, pdu_size, - BVLC6_DISTRIBUTE_BROADCAST_TO_NETWORK, length); + if (pdu && (pdu_size >= length) && (vmac <= 0xFFFFFF)) { + bytes_encoded = bvlc6_encode_header( + pdu, pdu_size, BVLC6_DISTRIBUTE_BROADCAST_TO_NETWORK, length); if (bytes_encoded == 4) { encode_unsigned24(&pdu[4], vmac); if (npdu && length) { for (i = 0; i < npdu_len; i++) { - pdu[7+i] = npdu[i]; + pdu[7 + i] = npdu[i]; } } bytes_encoded = (int)length; @@ -1464,13 +1334,10 @@ int bvlc6_encode_distribute_broadcast_to_network( * * @return number of bytes decoded */ -int bvlc6_decode_distribute_broadcast_to_network( - uint8_t * pdu, - uint16_t pdu_len, - uint32_t * vmac, - uint8_t * npdu, - uint16_t npdu_size, - uint16_t * npdu_len) +int bvlc6_decode_distribute_broadcast_to_network(uint8_t *pdu, uint16_t pdu_len, + uint32_t *vmac, uint8_t *npdu, + uint16_t npdu_size, + uint16_t *npdu_len) { int bytes_consumed = 0; uint16_t length = 0; @@ -1483,7 +1350,7 @@ int bvlc6_decode_distribute_broadcast_to_network( length = pdu_len - 3; if (npdu && length && (length <= npdu_size)) { for (i = 0; i < length; i++) { - npdu[i] = pdu[3+i]; + npdu[i] = pdu[3 + i]; } } if (npdu_len) { @@ -1500,38 +1367,31 @@ int bvlc6_decode_distribute_broadcast_to_network( #include #include "ctest.h" -static void test_BVLC6_Address( - Test * pTest, - BACNET_IP6_ADDRESS * bip6_address_1, - BACNET_IP6_ADDRESS * bip6_address_2) +static void test_BVLC6_Address(Test *pTest, BACNET_IP6_ADDRESS *bip6_address_1, + BACNET_IP6_ADDRESS *bip6_address_2) { unsigned i = 0; if (bip6_address_1 && bip6_address_2) { ct_test(pTest, bip6_address_1->port == bip6_address_2->port); for (i = 0; i < IP6_ADDRESS_MAX; i++) { - ct_test(pTest, bip6_address_1->address[i] == - bip6_address_2->address[i]); + ct_test(pTest, + bip6_address_1->address[i] == bip6_address_2->address[i]); } } return; } -static int test_BVLC6_Header( - Test * pTest, - uint8_t * pdu, - uint16_t pdu_len, - uint8_t * message_type, - uint16_t * length) +static int test_BVLC6_Header(Test *pTest, uint8_t *pdu, uint16_t pdu_len, + uint8_t *message_type, uint16_t *length) { int bytes_consumed = 0; int len = 0; if (pdu && message_type && length) { - len = bvlc6_decode_header(pdu, pdu_len, message_type, - length); + len = bvlc6_decode_header(pdu, pdu_len, message_type, length); ct_test(pTest, len == 4); bytes_consumed = len; } @@ -1539,12 +1399,10 @@ static int test_BVLC6_Header( return bytes_consumed; } -static void test_BVLC6_Result_Code( - Test * pTest, - uint32_t vmac, - uint16_t result_code) +static void test_BVLC6_Result_Code(Test *pTest, uint32_t vmac, + uint16_t result_code) { - uint8_t pdu[50] = { 0 }; + uint8_t pdu[50] = {0}; uint32_t test_vmac = 0; uint16_t test_result_code = 0; uint8_t message_type = 0; @@ -1553,22 +1411,20 @@ static void test_BVLC6_Result_Code( len = bvlc6_encode_result(pdu, sizeof(pdu), vmac, result_code); ct_test(pTest, len == 9); - test_len = test_BVLC6_Header(pTest, - pdu, len, &message_type, &length); + test_len = test_BVLC6_Header(pTest, pdu, len, &message_type, &length); ct_test(pTest, test_len == 4); ct_test(pTest, message_type == BVLC6_RESULT); ct_test(pTest, length == 9); - test_len += bvlc6_decode_result(&pdu[4], length-4, - &test_vmac, &test_result_code); + test_len += + bvlc6_decode_result(&pdu[4], length - 4, &test_vmac, &test_result_code); ct_test(pTest, len == test_len); ct_test(pTest, vmac == test_vmac); ct_test(pTest, result_code == test_result_code); - len = bvlc6_encode_result(pdu, sizeof(pdu), 0xffffff+1, result_code); + len = bvlc6_encode_result(pdu, sizeof(pdu), 0xffffff + 1, result_code); ct_test(pTest, len == 0); } -static void test_BVLC6_Result( - Test * pTest) +static void test_BVLC6_Result(Test *pTest) { uint32_t vmac = 0; uint16_t result_code[6] = { @@ -1577,8 +1433,7 @@ static void test_BVLC6_Result( BVLC6_RESULT_VIRTUAL_ADDRESS_RESOLUTION_NAK, BVLC6_RESULT_REGISTER_FOREIGN_DEVICE_NAK, BVLC6_RESULT_DELETE_FOREIGN_DEVICE_NAK, - BVLC6_RESULT_DISTRIBUTE_BROADCAST_TO_NETWORK_NAK - }; + BVLC6_RESULT_DISTRIBUTE_BROADCAST_TO_NETWORK_NAK}; unsigned int i = 0; vmac = 4194303; @@ -1587,15 +1442,13 @@ static void test_BVLC6_Result( } } -static void test_BVLC6_Original_Unicast_NPDU_Message( - Test * pTest, - uint8_t * npdu, - uint16_t npdu_len, - uint32_t vmac_src, - uint32_t vmac_dst) +static void test_BVLC6_Original_Unicast_NPDU_Message(Test *pTest, uint8_t *npdu, + uint16_t npdu_len, + uint32_t vmac_src, + uint32_t vmac_dst) { - uint8_t test_npdu[50] = { 0 }; - uint8_t pdu[60] = { 0 }; + uint8_t test_npdu[50] = {0}; + uint8_t pdu[60] = {0}; uint32_t test_vmac_src = 0; uint32_t test_vmac_dst = 0; uint16_t test_npdu_len = 0; @@ -1604,19 +1457,17 @@ static void test_BVLC6_Original_Unicast_NPDU_Message( int len = 0, msg_len = 0, test_len = 0; uint16_t i = 0; - len = bvlc6_encode_original_unicast(pdu, sizeof(pdu), - vmac_src, vmac_dst, - npdu, npdu_len); + len = bvlc6_encode_original_unicast(pdu, sizeof(pdu), vmac_src, vmac_dst, + npdu, npdu_len); msg_len = 10 + npdu_len; ct_test(pTest, len == msg_len); - test_len = test_BVLC6_Header(pTest, - pdu, len, &message_type, &length); + test_len = test_BVLC6_Header(pTest, pdu, len, &message_type, &length); ct_test(pTest, test_len == 4); ct_test(pTest, message_type == BVLC6_ORIGINAL_UNICAST_NPDU); ct_test(pTest, length == msg_len); - test_len += bvlc6_decode_original_unicast(&pdu[4], length-4, - &test_vmac_src, &test_vmac_dst, - test_npdu, sizeof(test_npdu), &test_npdu_len); + test_len += bvlc6_decode_original_unicast( + &pdu[4], length - 4, &test_vmac_src, &test_vmac_dst, test_npdu, + sizeof(test_npdu), &test_npdu_len); ct_test(pTest, len == test_len); ct_test(pTest, msg_len == test_len); ct_test(pTest, vmac_src == test_vmac_src); @@ -1627,17 +1478,16 @@ static void test_BVLC6_Original_Unicast_NPDU_Message( } } -static void test_BVLC6_Original_Unicast_NPDU( - Test * pTest) +static void test_BVLC6_Original_Unicast_NPDU(Test *pTest) { - uint8_t npdu[50] = { 0 }; + uint8_t npdu[50] = {0}; uint32_t vmac_src = 0; uint32_t vmac_dst = 0; uint16_t npdu_len = 0; uint16_t i = 0; - test_BVLC6_Original_Unicast_NPDU_Message(pTest, - npdu, npdu_len, vmac_src, vmac_dst); + test_BVLC6_Original_Unicast_NPDU_Message(pTest, npdu, npdu_len, vmac_src, + vmac_dst); /* now with some NPDU data */ for (i = 0; i < sizeof(npdu); i++) { npdu[i] = i; @@ -1645,18 +1495,17 @@ static void test_BVLC6_Original_Unicast_NPDU( npdu_len = sizeof(npdu); vmac_src = 4194303; vmac_dst = 4194302; - test_BVLC6_Original_Unicast_NPDU_Message(pTest, - npdu, npdu_len, vmac_src, vmac_dst); + test_BVLC6_Original_Unicast_NPDU_Message(pTest, npdu, npdu_len, vmac_src, + vmac_dst); } -static void test_BVLC6_Original_Broadcast_NPDU_Message( - Test * pTest, - uint8_t * npdu, - uint16_t npdu_len, - uint32_t vmac) +static void test_BVLC6_Original_Broadcast_NPDU_Message(Test *pTest, + uint8_t *npdu, + uint16_t npdu_len, + uint32_t vmac) { - uint8_t test_npdu[50] = { 0 }; - uint8_t pdu[60] = { 0 }; + uint8_t test_npdu[50] = {0}; + uint8_t pdu[60] = {0}; uint32_t test_vmac = 0; uint16_t test_npdu_len = 0; uint8_t message_type = 0; @@ -1664,17 +1513,17 @@ static void test_BVLC6_Original_Broadcast_NPDU_Message( int len = 0, msg_len = 0, test_len = 0; uint16_t i = 0; - len = bvlc6_encode_original_broadcast(pdu, sizeof(pdu), - vmac, npdu, npdu_len); + len = + bvlc6_encode_original_broadcast(pdu, sizeof(pdu), vmac, npdu, npdu_len); msg_len = 7 + npdu_len; ct_test(pTest, len == msg_len); - test_len = test_BVLC6_Header(pTest, - pdu, len, &message_type, &length); + test_len = test_BVLC6_Header(pTest, pdu, len, &message_type, &length); ct_test(pTest, test_len == 4); ct_test(pTest, message_type == BVLC6_ORIGINAL_BROADCAST_NPDU); ct_test(pTest, length == msg_len); - test_len += bvlc6_decode_original_broadcast(&pdu[4], length-4, - &test_vmac, test_npdu, sizeof(test_npdu), &test_npdu_len); + test_len += bvlc6_decode_original_broadcast(&pdu[4], length - 4, &test_vmac, + test_npdu, sizeof(test_npdu), + &test_npdu_len); ct_test(pTest, len == test_len); ct_test(pTest, msg_len == test_len); ct_test(pTest, vmac == test_vmac); @@ -1684,32 +1533,28 @@ static void test_BVLC6_Original_Broadcast_NPDU_Message( } } -static void test_BVLC6_Original_Broadcast_NPDU( - Test * pTest) +static void test_BVLC6_Original_Broadcast_NPDU(Test *pTest) { - uint8_t npdu[50] = { 0 }; + uint8_t npdu[50] = {0}; uint32_t vmac = 0; uint16_t npdu_len = 0; uint16_t i = 0; - test_BVLC6_Original_Broadcast_NPDU_Message(pTest, - npdu, npdu_len, vmac); + test_BVLC6_Original_Broadcast_NPDU_Message(pTest, npdu, npdu_len, vmac); /* now with some NPDU data */ for (i = 0; i < sizeof(npdu); i++) { npdu[i] = i; } npdu_len = sizeof(npdu); vmac = 4194303; - test_BVLC6_Original_Broadcast_NPDU_Message(pTest, - npdu, npdu_len, vmac); + test_BVLC6_Original_Broadcast_NPDU_Message(pTest, npdu, npdu_len, vmac); } -static void test_BVLC6_Address_Resolution_Message( - Test * pTest, - uint32_t vmac_src, - uint32_t vmac_target) +static void test_BVLC6_Address_Resolution_Message(Test *pTest, + uint32_t vmac_src, + uint32_t vmac_target) { - uint8_t pdu[60] = { 0 }; + uint8_t pdu[60] = {0}; uint32_t test_vmac_src = 0; uint32_t test_vmac_target = 0; uint8_t message_type = 0; @@ -1717,44 +1562,38 @@ static void test_BVLC6_Address_Resolution_Message( int len = 0, test_len = 0; const int msg_len = 10; - len = bvlc6_encode_address_resolution(pdu, sizeof(pdu), - vmac_src, vmac_target); + len = bvlc6_encode_address_resolution(pdu, sizeof(pdu), vmac_src, + vmac_target); ct_test(pTest, len == msg_len); - test_len = test_BVLC6_Header(pTest, - pdu, len, &message_type, &length); + test_len = test_BVLC6_Header(pTest, pdu, len, &message_type, &length); ct_test(pTest, test_len == 4); ct_test(pTest, message_type == BVLC6_ADDRESS_RESOLUTION); ct_test(pTest, length == msg_len); - test_len += bvlc6_decode_address_resolution(&pdu[4], length-4, - &test_vmac_src, &test_vmac_target); + test_len += bvlc6_decode_address_resolution( + &pdu[4], length - 4, &test_vmac_src, &test_vmac_target); ct_test(pTest, len == test_len); ct_test(pTest, msg_len == test_len); ct_test(pTest, vmac_src == test_vmac_src); ct_test(pTest, vmac_target == test_vmac_target); } -static void test_BVLC6_Address_Resolution( - Test * pTest) +static void test_BVLC6_Address_Resolution(Test *pTest) { uint32_t vmac_src = 0; uint32_t vmac_target = 0; - test_BVLC6_Address_Resolution_Message(pTest, - vmac_src, vmac_target); + test_BVLC6_Address_Resolution_Message(pTest, vmac_src, vmac_target); vmac_src = 4194303; vmac_target = 4194302; - test_BVLC6_Address_Resolution_Message(pTest, - vmac_src, vmac_target); + test_BVLC6_Address_Resolution_Message(pTest, vmac_src, vmac_target); } static void test_BVLC6_Forwarded_Address_Resolution_Message( - Test * pTest, - uint32_t vmac_src, - uint32_t vmac_dst, - BACNET_IP6_ADDRESS * bip6_address) + Test *pTest, uint32_t vmac_src, uint32_t vmac_dst, + BACNET_IP6_ADDRESS *bip6_address) { BACNET_IP6_ADDRESS test_bip6_address = {{0}}; - uint8_t pdu[60] = { 0 }; + uint8_t pdu[60] = {0}; uint32_t test_vmac_src = 0; uint32_t test_vmac_dst = 0; uint8_t message_type = 0; @@ -1762,19 +1601,15 @@ static void test_BVLC6_Forwarded_Address_Resolution_Message( int len = 0, test_len = 0; const int msg_len = 4 + 3 + 3 + BIP6_ADDRESS_MAX; - len = bvlc6_encode_forwarded_address_resolution( - pdu, sizeof(pdu), - vmac_src, vmac_dst, - bip6_address); + len = bvlc6_encode_forwarded_address_resolution(pdu, sizeof(pdu), vmac_src, + vmac_dst, bip6_address); ct_test(pTest, len == msg_len); - test_len = test_BVLC6_Header(pTest, - pdu, len, &message_type, &length); + test_len = test_BVLC6_Header(pTest, pdu, len, &message_type, &length); ct_test(pTest, test_len == 4); ct_test(pTest, message_type == BVLC6_FORWARDED_ADDRESS_RESOLUTION); ct_test(pTest, length == msg_len); test_len += bvlc6_decode_forwarded_address_resolution( - &pdu[4], length-4, - &test_vmac_src, &test_vmac_dst, + &pdu[4], length - 4, &test_vmac_src, &test_vmac_dst, &test_bip6_address); ct_test(pTest, len == test_len); ct_test(pTest, msg_len == test_len); @@ -1783,16 +1618,15 @@ static void test_BVLC6_Forwarded_Address_Resolution_Message( test_BVLC6_Address(pTest, bip6_address, &test_bip6_address); } -static void test_BVLC6_Forwarded_Address_Resolution( - Test * pTest) +static void test_BVLC6_Forwarded_Address_Resolution(Test *pTest) { BACNET_IP6_ADDRESS bip6_address = {{0}}; uint32_t vmac_src = 0; uint32_t vmac_target = 0; uint16_t i = 0; - test_BVLC6_Forwarded_Address_Resolution_Message(pTest, - vmac_src, vmac_target, &bip6_address); + test_BVLC6_Forwarded_Address_Resolution_Message(pTest, vmac_src, + vmac_target, &bip6_address); /* now with some address data */ for (i = 0; i < sizeof(bip6_address.address); i++) { bip6_address.address[i] = i; @@ -1800,16 +1634,15 @@ static void test_BVLC6_Forwarded_Address_Resolution( bip6_address.port = 47808; vmac_src = 4194303; vmac_target = 4194302; - test_BVLC6_Forwarded_Address_Resolution_Message(pTest, - vmac_src, vmac_target, &bip6_address); + test_BVLC6_Forwarded_Address_Resolution_Message(pTest, vmac_src, + vmac_target, &bip6_address); } -static void test_BVLC6_Address_Resolution_Ack_Message( - Test * pTest, - uint32_t vmac_src, - uint32_t vmac_dst) +static void test_BVLC6_Address_Resolution_Ack_Message(Test *pTest, + uint32_t vmac_src, + uint32_t vmac_dst) { - uint8_t pdu[60] = { 0 }; + uint8_t pdu[60] = {0}; uint32_t test_vmac_src = 0; uint32_t test_vmac_dst = 0; uint8_t message_type = 0; @@ -1817,80 +1650,69 @@ static void test_BVLC6_Address_Resolution_Ack_Message( int len = 0, test_len = 0; const int msg_len = 10; - len = bvlc6_encode_address_resolution_ack(pdu, sizeof(pdu), - vmac_src, vmac_dst); + len = bvlc6_encode_address_resolution_ack(pdu, sizeof(pdu), vmac_src, + vmac_dst); ct_test(pTest, len == msg_len); - test_len = test_BVLC6_Header(pTest, - pdu, len, &message_type, &length); + test_len = test_BVLC6_Header(pTest, pdu, len, &message_type, &length); ct_test(pTest, test_len == 4); ct_test(pTest, message_type == BVLC6_ADDRESS_RESOLUTION_ACK); ct_test(pTest, length == msg_len); - test_len += bvlc6_decode_address_resolution_ack(&pdu[4], length-4, - &test_vmac_src, &test_vmac_dst); + test_len += bvlc6_decode_address_resolution_ack( + &pdu[4], length - 4, &test_vmac_src, &test_vmac_dst); ct_test(pTest, len == test_len); ct_test(pTest, msg_len == test_len); ct_test(pTest, vmac_src == test_vmac_src); ct_test(pTest, vmac_dst == test_vmac_dst); } -static void test_BVLC6_Address_Resolution_Ack( - Test * pTest) +static void test_BVLC6_Address_Resolution_Ack(Test *pTest) { uint32_t vmac_src = 0; uint32_t vmac_dst = 0; - test_BVLC6_Address_Resolution_Ack_Message(pTest, - vmac_src, vmac_dst); + test_BVLC6_Address_Resolution_Ack_Message(pTest, vmac_src, vmac_dst); vmac_src = 4194303; vmac_dst = 4194302; - test_BVLC6_Address_Resolution_Ack_Message(pTest, - vmac_src, vmac_dst); + test_BVLC6_Address_Resolution_Ack_Message(pTest, vmac_src, vmac_dst); } -static void test_BVLC6_Virtual_Address_Resolution_Message( - Test * pTest, - uint32_t vmac_src) +static void test_BVLC6_Virtual_Address_Resolution_Message(Test *pTest, + uint32_t vmac_src) { - uint8_t pdu[60] = { 0 }; + uint8_t pdu[60] = {0}; uint32_t test_vmac_src = 0; uint8_t message_type = 0; uint16_t length = 0; int len = 0, test_len = 0; const int msg_len = 7; - len = bvlc6_encode_virtual_address_resolution(pdu, sizeof(pdu), - vmac_src); + len = bvlc6_encode_virtual_address_resolution(pdu, sizeof(pdu), vmac_src); ct_test(pTest, len == msg_len); - test_len = test_BVLC6_Header(pTest, - pdu, len, &message_type, &length); + test_len = test_BVLC6_Header(pTest, pdu, len, &message_type, &length); ct_test(pTest, test_len == 4); ct_test(pTest, message_type == BVLC6_VIRTUAL_ADDRESS_RESOLUTION); ct_test(pTest, length == msg_len); - test_len += bvlc6_decode_virtual_address_resolution(&pdu[4], length-4, - &test_vmac_src); + test_len += bvlc6_decode_virtual_address_resolution(&pdu[4], length - 4, + &test_vmac_src); ct_test(pTest, len == test_len); ct_test(pTest, msg_len == test_len); ct_test(pTest, vmac_src == test_vmac_src); } -static void test_BVLC6_Virtual_Address_Resolution( - Test * pTest) +static void test_BVLC6_Virtual_Address_Resolution(Test *pTest) { uint32_t vmac_src = 0; - test_BVLC6_Virtual_Address_Resolution_Message(pTest, - vmac_src); + test_BVLC6_Virtual_Address_Resolution_Message(pTest, vmac_src); vmac_src = 0x1234; - test_BVLC6_Virtual_Address_Resolution_Message(pTest, - vmac_src); + test_BVLC6_Virtual_Address_Resolution_Message(pTest, vmac_src); } -static void test_BVLC6_Virtual_Address_Resolution_Ack_Message( - Test * pTest, - uint32_t vmac_src, - uint32_t vmac_dst) +static void test_BVLC6_Virtual_Address_Resolution_Ack_Message(Test *pTest, + uint32_t vmac_src, + uint32_t vmac_dst) { - uint8_t pdu[60] = { 0 }; + uint8_t pdu[60] = {0}; uint32_t test_vmac_src = 0; uint32_t test_vmac_dst = 0; uint8_t message_type = 0; @@ -1899,44 +1721,40 @@ static void test_BVLC6_Virtual_Address_Resolution_Ack_Message( const int msg_len = 10; len = bvlc6_encode_virtual_address_resolution_ack(pdu, sizeof(pdu), - vmac_src, vmac_dst); + vmac_src, vmac_dst); ct_test(pTest, len == msg_len); - test_len = test_BVLC6_Header(pTest, - pdu, len, &message_type, &length); + test_len = test_BVLC6_Header(pTest, pdu, len, &message_type, &length); ct_test(pTest, test_len == 4); ct_test(pTest, message_type == BVLC6_VIRTUAL_ADDRESS_RESOLUTION_ACK); ct_test(pTest, length == msg_len); - test_len += bvlc6_decode_virtual_address_resolution_ack(&pdu[4], length-4, - &test_vmac_src, &test_vmac_dst); + test_len += bvlc6_decode_virtual_address_resolution_ack( + &pdu[4], length - 4, &test_vmac_src, &test_vmac_dst); ct_test(pTest, len == test_len); ct_test(pTest, msg_len == test_len); ct_test(pTest, vmac_src == test_vmac_src); ct_test(pTest, vmac_dst == test_vmac_dst); } -static void test_BVLC6_Virtual_Address_Resolution_Ack( - Test * pTest) +static void test_BVLC6_Virtual_Address_Resolution_Ack(Test *pTest) { uint32_t vmac_src = 0; uint32_t vmac_dst = 0; - test_BVLC6_Virtual_Address_Resolution_Ack_Message(pTest, - vmac_src, vmac_dst); + test_BVLC6_Virtual_Address_Resolution_Ack_Message(pTest, vmac_src, + vmac_dst); vmac_src = 4194303; vmac_dst = 4194302; - test_BVLC6_Virtual_Address_Resolution_Ack_Message(pTest, - vmac_src, vmac_dst); + test_BVLC6_Virtual_Address_Resolution_Ack_Message(pTest, vmac_src, + vmac_dst); } -static void test_BVLC6_Forwarded_NPDU_Message( - Test * pTest, - uint8_t * npdu, - uint16_t npdu_len, - uint32_t vmac_src, - BACNET_IP6_ADDRESS * bip6_address) +static void test_BVLC6_Forwarded_NPDU_Message(Test *pTest, uint8_t *npdu, + uint16_t npdu_len, + uint32_t vmac_src, + BACNET_IP6_ADDRESS *bip6_address) { - uint8_t test_npdu[50] = { 0 }; - uint8_t pdu[75] = { 0 }; + uint8_t test_npdu[50] = {0}; + uint8_t pdu[75] = {0}; uint32_t test_vmac_src = 0; BACNET_IP6_ADDRESS test_bip6_address = {{0}}; uint16_t test_npdu_len = 0; @@ -1945,19 +1763,17 @@ static void test_BVLC6_Forwarded_NPDU_Message( int len = 0, msg_len = 0, test_len = 0; uint16_t i = 0; - len = bvlc6_encode_forwarded_npdu(pdu, sizeof(pdu), - vmac_src, bip6_address, - npdu, npdu_len); - msg_len = 1+1+2+3+BIP6_ADDRESS_MAX+npdu_len; + len = bvlc6_encode_forwarded_npdu(pdu, sizeof(pdu), vmac_src, bip6_address, + npdu, npdu_len); + msg_len = 1 + 1 + 2 + 3 + BIP6_ADDRESS_MAX + npdu_len; ct_test(pTest, len == msg_len); - test_len = test_BVLC6_Header(pTest, - pdu, len, &message_type, &length); + test_len = test_BVLC6_Header(pTest, pdu, len, &message_type, &length); ct_test(pTest, test_len == 4); ct_test(pTest, message_type == BVLC6_FORWARDED_NPDU); ct_test(pTest, length == msg_len); - test_len += bvlc6_decode_forwarded_npdu(&pdu[4], length-4, - &test_vmac_src, &test_bip6_address, - test_npdu, sizeof(test_npdu), &test_npdu_len); + test_len += bvlc6_decode_forwarded_npdu(&pdu[4], length - 4, &test_vmac_src, + &test_bip6_address, test_npdu, + sizeof(test_npdu), &test_npdu_len); ct_test(pTest, len == test_len); ct_test(pTest, msg_len == test_len); ct_test(pTest, vmac_src == test_vmac_src); @@ -1968,17 +1784,16 @@ static void test_BVLC6_Forwarded_NPDU_Message( } } -static void test_BVLC6_Forwarded_NPDU( - Test * pTest) +static void test_BVLC6_Forwarded_NPDU(Test *pTest) { - uint8_t npdu[50] = { 0 }; + uint8_t npdu[50] = {0}; uint32_t vmac_src = 0; BACNET_IP6_ADDRESS bip6_address = {{0}}; uint16_t npdu_len = 0; uint16_t i = 0; - test_BVLC6_Forwarded_NPDU_Message(pTest, - npdu, npdu_len, vmac_src, &bip6_address); + test_BVLC6_Forwarded_NPDU_Message(pTest, npdu, npdu_len, vmac_src, + &bip6_address); for (i = 0; i < sizeof(bip6_address.address); i++) { bip6_address.address[i] = i; } @@ -1989,16 +1804,15 @@ static void test_BVLC6_Forwarded_NPDU( } npdu_len = sizeof(npdu); vmac_src = 4194303; - test_BVLC6_Forwarded_NPDU_Message(pTest, - npdu, npdu_len, vmac_src, &bip6_address); + test_BVLC6_Forwarded_NPDU_Message(pTest, npdu, npdu_len, vmac_src, + &bip6_address); } -static void test_BVLC6_Register_Foreign_Device_Message( - Test * pTest, - uint32_t vmac_src, - uint16_t ttl_seconds) +static void test_BVLC6_Register_Foreign_Device_Message(Test *pTest, + uint32_t vmac_src, + uint16_t ttl_seconds) { - uint8_t pdu[60] = { 0 }; + uint8_t pdu[60] = {0}; uint32_t test_vmac_src = 0; uint16_t test_ttl_seconds = 0; uint8_t message_type = 0; @@ -2006,42 +1820,37 @@ static void test_BVLC6_Register_Foreign_Device_Message( int len = 0, test_len = 0; const int msg_len = 9; - len = bvlc6_encode_register_foreign_device(pdu, sizeof(pdu), - vmac_src, ttl_seconds); + len = bvlc6_encode_register_foreign_device(pdu, sizeof(pdu), vmac_src, + ttl_seconds); ct_test(pTest, len == msg_len); - test_len = test_BVLC6_Header(pTest, - pdu, len, &message_type, &length); + test_len = test_BVLC6_Header(pTest, pdu, len, &message_type, &length); ct_test(pTest, test_len == 4); ct_test(pTest, message_type == BVLC6_REGISTER_FOREIGN_DEVICE); ct_test(pTest, length == msg_len); - test_len += bvlc6_decode_register_foreign_device(&pdu[4], length-4, - &test_vmac_src, &test_ttl_seconds); + test_len += bvlc6_decode_register_foreign_device( + &pdu[4], length - 4, &test_vmac_src, &test_ttl_seconds); ct_test(pTest, len == test_len); ct_test(pTest, msg_len == test_len); ct_test(pTest, vmac_src == test_vmac_src); ct_test(pTest, ttl_seconds == test_ttl_seconds); } -static void test_BVLC6_Register_Foreign_Device( - Test * pTest) +static void test_BVLC6_Register_Foreign_Device(Test *pTest) { uint32_t vmac_src = 0; uint16_t ttl_seconds = 0; - test_BVLC6_Register_Foreign_Device_Message(pTest, - vmac_src, ttl_seconds); + test_BVLC6_Register_Foreign_Device_Message(pTest, vmac_src, ttl_seconds); vmac_src = 4194303; ttl_seconds = 600; - test_BVLC6_Register_Foreign_Device_Message(pTest, - vmac_src, ttl_seconds); + test_BVLC6_Register_Foreign_Device_Message(pTest, vmac_src, ttl_seconds); } static void test_BVLC6_Delete_Foreign_Device_Message( - Test * pTest, - uint32_t vmac_src, + Test *pTest, uint32_t vmac_src, BACNET_IP6_FOREIGN_DEVICE_TABLE_ENTRY *fdt_entry) { - uint8_t pdu[64] = { 0 }; + uint8_t pdu[64] = {0}; uint32_t test_vmac_src = 0; BACNET_IP6_FOREIGN_DEVICE_TABLE_ENTRY test_fdt_entry = {0}; uint8_t message_type = 0; @@ -2049,36 +1858,33 @@ static void test_BVLC6_Delete_Foreign_Device_Message( int len = 0, test_len = 0; const int msg_len = 0x0019; - len = bvlc6_encode_delete_foreign_device(pdu, sizeof(pdu), - vmac_src, fdt_entry); + len = bvlc6_encode_delete_foreign_device(pdu, sizeof(pdu), vmac_src, + fdt_entry); ct_test(pTest, len == msg_len); - test_len = test_BVLC6_Header(pTest, - pdu, len, &message_type, &length); + test_len = test_BVLC6_Header(pTest, pdu, len, &message_type, &length); ct_test(pTest, test_len == 4); ct_test(pTest, message_type == BVLC6_DELETE_FOREIGN_DEVICE); ct_test(pTest, length == msg_len); - test_len += bvlc6_decode_delete_foreign_device(&pdu[4], length-4, - &test_vmac_src, &test_fdt_entry); + test_len += bvlc6_decode_delete_foreign_device( + &pdu[4], length - 4, &test_vmac_src, &test_fdt_entry); ct_test(pTest, len == test_len); ct_test(pTest, msg_len == test_len); ct_test(pTest, vmac_src == test_vmac_src); test_BVLC6_Address(pTest, &fdt_entry->bip6_address, - &test_fdt_entry.bip6_address); + &test_fdt_entry.bip6_address); ct_test(pTest, fdt_entry->ttl_seconds == test_fdt_entry.ttl_seconds); ct_test(pTest, fdt_entry->ttl_seconds_remaining == - test_fdt_entry.ttl_seconds_remaining); + test_fdt_entry.ttl_seconds_remaining); } -static void test_BVLC6_Delete_Foreign_Device( - Test * pTest) +static void test_BVLC6_Delete_Foreign_Device(Test *pTest) { uint32_t vmac_src = 0; BACNET_IP6_FOREIGN_DEVICE_TABLE_ENTRY fdt_entry = {0}; unsigned int i = 0; /* test with zeros */ - test_BVLC6_Delete_Foreign_Device_Message(pTest, - vmac_src, &fdt_entry); + test_BVLC6_Delete_Foreign_Device_Message(pTest, vmac_src, &fdt_entry); /* test with valid values */ vmac_src = 4194303; for (i = 0; i < sizeof(fdt_entry.bip6_address.address); i++) { @@ -2088,34 +1894,29 @@ static void test_BVLC6_Delete_Foreign_Device( fdt_entry.ttl_seconds = 600; fdt_entry.ttl_seconds_remaining = 42; fdt_entry.next = NULL; - test_BVLC6_Delete_Foreign_Device_Message(pTest, - vmac_src, &fdt_entry); + test_BVLC6_Delete_Foreign_Device_Message(pTest, vmac_src, &fdt_entry); } -static void test_BVLC6_Secure_BVLL_Message( - Test * pTest, - uint8_t * sbuf, - uint16_t sbuf_len) +static void test_BVLC6_Secure_BVLL_Message(Test *pTest, uint8_t *sbuf, + uint16_t sbuf_len) { - uint8_t test_sbuf[50] = { 0 }; - uint8_t pdu[60] = { 0 }; + uint8_t test_sbuf[50] = {0}; + uint8_t pdu[60] = {0}; uint16_t test_sbuf_len = 0; uint8_t message_type = 0; uint16_t length = 0; int len = 0, msg_len = 0, test_len = 0; uint16_t i = 0; - len = bvlc6_encode_secure_bvll(pdu, sizeof(pdu), - sbuf, sbuf_len); - msg_len = 1+1+2+sbuf_len; + len = bvlc6_encode_secure_bvll(pdu, sizeof(pdu), sbuf, sbuf_len); + msg_len = 1 + 1 + 2 + sbuf_len; ct_test(pTest, len == msg_len); - test_len = test_BVLC6_Header(pTest, - pdu, len, &message_type, &length); + test_len = test_BVLC6_Header(pTest, pdu, len, &message_type, &length); ct_test(pTest, test_len == 4); ct_test(pTest, message_type == BVLC6_SECURE_BVLL); ct_test(pTest, length == msg_len); - test_len += bvlc6_decode_secure_bvll(&pdu[4], length-4, - test_sbuf, sizeof(test_sbuf), &test_sbuf_len); + test_len += bvlc6_decode_secure_bvll(&pdu[4], length - 4, test_sbuf, + sizeof(test_sbuf), &test_sbuf_len); ct_test(pTest, len == test_len); ct_test(pTest, msg_len == test_len); ct_test(pTest, sbuf_len == test_sbuf_len); @@ -2124,32 +1925,26 @@ static void test_BVLC6_Secure_BVLL_Message( } } -static void test_BVLC6_Secure_BVLL( - Test * pTest) +static void test_BVLC6_Secure_BVLL(Test *pTest) { - uint8_t sbuf[50] = { 0 }; + uint8_t sbuf[50] = {0}; uint16_t sbuf_len = 0; uint16_t i = 0; - test_BVLC6_Secure_BVLL_Message(pTest, - sbuf, sbuf_len); + test_BVLC6_Secure_BVLL_Message(pTest, sbuf, sbuf_len); /* now with some NPDU data */ for (i = 0; i < sizeof(sbuf); i++) { sbuf[i] = i; } sbuf_len = sizeof(sbuf); - test_BVLC6_Secure_BVLL_Message(pTest, - sbuf, sbuf_len); + test_BVLC6_Secure_BVLL_Message(pTest, sbuf, sbuf_len); } static void test_BVLC6_Distribute_Broadcast_To_Network_Message( - Test * pTest, - uint8_t * npdu, - uint16_t npdu_len, - uint32_t vmac) + Test *pTest, uint8_t *npdu, uint16_t npdu_len, uint32_t vmac) { - uint8_t test_npdu[50] = { 0 }; - uint8_t pdu[60] = { 0 }; + uint8_t test_npdu[50] = {0}; + uint8_t pdu[60] = {0}; uint32_t test_vmac = 0; uint16_t test_npdu_len = 0; uint8_t message_type = 0; @@ -2157,18 +1952,17 @@ static void test_BVLC6_Distribute_Broadcast_To_Network_Message( int len = 0, msg_len = 0, test_len = 0; uint16_t i = 0; - len = bvlc6_encode_distribute_broadcast_to_network(pdu, sizeof(pdu), - vmac, npdu, npdu_len); + len = bvlc6_encode_distribute_broadcast_to_network(pdu, sizeof(pdu), vmac, + npdu, npdu_len); msg_len = 7 + npdu_len; ct_test(pTest, len == msg_len); - test_len = test_BVLC6_Header(pTest, - pdu, len, &message_type, &length); + test_len = test_BVLC6_Header(pTest, pdu, len, &message_type, &length); ct_test(pTest, test_len == 4); ct_test(pTest, message_type == BVLC6_DISTRIBUTE_BROADCAST_TO_NETWORK); ct_test(pTest, length == msg_len); test_len += bvlc6_decode_distribute_broadcast_to_network( - &pdu[4], length-4, - &test_vmac, test_npdu, sizeof(test_npdu), &test_npdu_len); + &pdu[4], length - 4, &test_vmac, test_npdu, sizeof(test_npdu), + &test_npdu_len); ct_test(pTest, len == test_len); ct_test(pTest, msg_len == test_len); ct_test(pTest, vmac == test_vmac); @@ -2178,28 +1972,26 @@ static void test_BVLC6_Distribute_Broadcast_To_Network_Message( } } -static void test_BVLC6_Distribute_Broadcast_To_Network( - Test * pTest) +static void test_BVLC6_Distribute_Broadcast_To_Network(Test *pTest) { - uint8_t npdu[50] = { 0 }; + uint8_t npdu[50] = {0}; uint32_t vmac = 0; uint16_t npdu_len = 0; uint16_t i = 0; - test_BVLC6_Distribute_Broadcast_To_Network_Message(pTest, - npdu, npdu_len, vmac); + test_BVLC6_Distribute_Broadcast_To_Network_Message(pTest, npdu, npdu_len, + vmac); /* now with some NPDU data */ for (i = 0; i < sizeof(npdu); i++) { npdu[i] = i; } npdu_len = sizeof(npdu); vmac = 4194303; - test_BVLC6_Distribute_Broadcast_To_Network_Message(pTest, - npdu, npdu_len, vmac); + test_BVLC6_Distribute_Broadcast_To_Network_Message(pTest, npdu, npdu_len, + vmac); } -static void test_BVLC6_Address_Copy( - Test * pTest) +static void test_BVLC6_Address_Copy(Test *pTest) { unsigned int i = 0; BACNET_IP6_ADDRESS src = {{0}}; @@ -2234,8 +2026,7 @@ static void test_BVLC6_Address_Copy( } } -static void test_BVLC6_Address_Get_Set( - Test * pTest) +static void test_BVLC6_Address_Get_Set(Test *pTest) { uint16_t i = 0; BACNET_IP6_ADDRESS src = {{0}}; @@ -2244,19 +2035,17 @@ static void test_BVLC6_Address_Get_Set( bool status = false; for (i = 0; i < 16; i++) { - status = bvlc6_address_set(&src, - group, 0, 0, 0, 0, 0, 0, 0); + status = bvlc6_address_set(&src, group, 0, 0, 0, 0, 0, 0, 0); ct_test(pTest, status); - status = bvlc6_address_get(&src, - &test_group, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + status = bvlc6_address_get(&src, &test_group, NULL, NULL, NULL, NULL, + NULL, NULL, NULL); ct_test(pTest, status); ct_test(pTest, group == test_group); - group = group<<1; + group = group << 1; } } -static void test_BVLC6_VMAC_Address_Get_Set( - Test * pTest) +static void test_BVLC6_VMAC_Address_Get_Set(Test *pTest) { uint16_t i = 0; BACNET_ADDRESS addr; @@ -2273,12 +2062,11 @@ static void test_BVLC6_VMAC_Address_Get_Set( status = bvlc6_vmac_address_get(&addr, &test_device_id); ct_test(pTest, status); ct_test(pTest, device_id == test_device_id); - device_id = device_id<<1; + device_id = device_id << 1; } } -void test_BVLC6( - Test * pTest) +void test_BVLC6(Test *pTest) { bool rc; @@ -2318,8 +2106,7 @@ void test_BVLC6( } #ifdef TEST_BVLC6 -int main( - void) +int main(void) { Test *pTest; @@ -2328,7 +2115,7 @@ int main( /* configure output */ ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/src/cov.c b/src/cov.c index bbbb2934..0c349c5b 100644 --- a/src/cov.c +++ b/src/cov.c @@ -48,31 +48,26 @@ COV Subscribe Property COV Notification Unconfirmed COV Notification */ -static int notify_encode_apdu( - uint8_t * apdu, - unsigned max_apdu_len, - BACNET_COV_DATA * data) +static int notify_encode_apdu(uint8_t *apdu, unsigned max_apdu_len, + BACNET_COV_DATA *data) { - int len = 0; /* length of each encoding */ - int apdu_len = 0; /* total length of the apdu, return value */ - BACNET_PROPERTY_VALUE *value = NULL; /* value in list */ - BACNET_APPLICATION_DATA_VALUE *app_data = NULL; + int len = 0; /* length of each encoding */ + int apdu_len = 0; /* total length of the apdu, return value */ + BACNET_PROPERTY_VALUE *value = NULL; /* value in list */ + BACNET_APPLICATION_DATA_VALUE *app_data = NULL; if (apdu) { /* tag 0 - subscriberProcessIdentifier */ - len = - encode_context_unsigned(&apdu[apdu_len], 0, - data->subscriberProcessIdentifier); + len = encode_context_unsigned(&apdu[apdu_len], 0, + data->subscriberProcessIdentifier); apdu_len += len; /* tag 1 - initiatingDeviceIdentifier */ - len = - encode_context_object_id(&apdu[apdu_len], 1, OBJECT_DEVICE, - data->initiatingDeviceIdentifier); + len = encode_context_object_id(&apdu[apdu_len], 1, OBJECT_DEVICE, + data->initiatingDeviceIdentifier); apdu_len += len; /* tag 2 - monitoredObjectIdentifier */ - len = - encode_context_object_id(&apdu[apdu_len], 2, - (int) data->monitoredObjectIdentifier.type, + len = encode_context_object_id( + &apdu[apdu_len], 2, (int)data->monitoredObjectIdentifier.type, data->monitoredObjectIdentifier.instance); apdu_len += len; /* tag 3 - timeRemaining */ @@ -88,15 +83,13 @@ static int notify_encode_apdu( value = data->listOfValues; while (value != NULL) { /* tag 0 - propertyIdentifier */ - len = - encode_context_enumerated(&apdu[apdu_len], 0, - value->propertyIdentifier); + len = encode_context_enumerated(&apdu[apdu_len], 0, + value->propertyIdentifier); apdu_len += len; /* tag 1 - propertyArrayIndex OPTIONAL */ if (value->propertyArrayIndex != BACNET_ARRAY_ALL) { - len = - encode_context_unsigned(&apdu[apdu_len], 1, - value->propertyArrayIndex); + len = encode_context_unsigned(&apdu[apdu_len], 1, + value->propertyArrayIndex); apdu_len += len; } /* tag 2 - value */ @@ -104,21 +97,18 @@ static int notify_encode_apdu( len = encode_opening_tag(&apdu[apdu_len], 2); apdu_len += len; app_data = &value->value; - while (app_data != NULL) - { - len = - bacapp_encode_application_data(&apdu[apdu_len], app_data); + while (app_data != NULL) { + len = bacapp_encode_application_data(&apdu[apdu_len], app_data); apdu_len += len; - app_data = app_data->next; + app_data = app_data->next; } len = encode_closing_tag(&apdu[apdu_len], 2); apdu_len += len; /* tag 3 - priority OPTIONAL */ if (value->priority != BACNET_NO_PRIORITY) { - len = - encode_context_unsigned(&apdu[apdu_len], 3, - value->priority); + len = encode_context_unsigned(&apdu[apdu_len], 3, + value->priority); apdu_len += len; } /* is there another one to encode? */ @@ -132,14 +122,11 @@ static int notify_encode_apdu( return apdu_len; } -int ccov_notify_encode_apdu( - uint8_t * apdu, - unsigned max_apdu_len, - uint8_t invoke_id, - BACNET_COV_DATA * data) +int ccov_notify_encode_apdu(uint8_t *apdu, unsigned max_apdu_len, + uint8_t invoke_id, BACNET_COV_DATA *data) { - int len = 0; /* length of each encoding */ - int apdu_len = BACNET_STATUS_ERROR; /* return value */ + int len = 0; /* length of each encoding */ + int apdu_len = BACNET_STATUS_ERROR; /* return value */ if (apdu && data && memcopylen(0, max_apdu_len, 4)) { apdu[0] = PDU_TYPE_CONFIRMED_SERVICE_REQUEST; @@ -147,39 +134,37 @@ int ccov_notify_encode_apdu( apdu[2] = invoke_id; apdu[3] = SERVICE_CONFIRMED_COV_NOTIFICATION; apdu_len = 4; - len = notify_encode_apdu(&apdu[apdu_len], - max_apdu_len-apdu_len, data); + len = + notify_encode_apdu(&apdu[apdu_len], max_apdu_len - apdu_len, data); if (len < 0) { /* return the error */ apdu_len = len; } else { - apdu_len += len; - } + apdu_len += len; + } } return apdu_len; } -int ucov_notify_encode_apdu( - uint8_t * apdu, - unsigned max_apdu_len, - BACNET_COV_DATA * data) +int ucov_notify_encode_apdu(uint8_t *apdu, unsigned max_apdu_len, + BACNET_COV_DATA *data) { - int len = 0; /* length of each encoding */ - int apdu_len = BACNET_STATUS_ERROR; /* return value */ + int len = 0; /* length of each encoding */ + int apdu_len = BACNET_STATUS_ERROR; /* return value */ if (apdu && data && memcopylen(0, max_apdu_len, 2)) { apdu[0] = PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST; apdu[1] = SERVICE_UNCONFIRMED_COV_NOTIFICATION; /* service choice */ apdu_len = 2; - len = notify_encode_apdu(&apdu[apdu_len], - max_apdu_len-apdu_len, data); + len = + notify_encode_apdu(&apdu[apdu_len], max_apdu_len - apdu_len, data); if (len < 0) { /* return the error */ apdu_len = len; } else { - apdu_len += len; - } + apdu_len += len; + } } return apdu_len; @@ -187,27 +172,24 @@ int ucov_notify_encode_apdu( /* decode the service request only */ /* COV and Unconfirmed COV are the same */ -int cov_notify_decode_service_request( - uint8_t * apdu, - unsigned apdu_len, - BACNET_COV_DATA * data) +int cov_notify_decode_service_request(uint8_t *apdu, unsigned apdu_len, + BACNET_COV_DATA *data) { - int len = 0; /* return value */ + int len = 0; /* return value */ int app_len = 0; uint8_t tag_number = 0; uint32_t len_value = 0; - uint32_t decoded_value = 0; /* for decoding */ - uint16_t decoded_type = 0; /* for decoding */ - uint32_t property = 0; /* for decoding */ - BACNET_PROPERTY_VALUE *value = NULL; /* value in list */ - BACNET_APPLICATION_DATA_VALUE *app_data = NULL; + uint32_t decoded_value = 0; /* for decoding */ + uint16_t decoded_type = 0; /* for decoding */ + uint32_t property = 0; /* for decoding */ + BACNET_PROPERTY_VALUE *value = NULL; /* value in list */ + BACNET_APPLICATION_DATA_VALUE *app_data = NULL; if (apdu_len && data) { /* tag 0 - subscriberProcessIdentifier */ if (decode_is_context_tag(&apdu[len], 0)) { - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value); len += decode_unsigned(&apdu[len], len_value, &decoded_value); data->subscriberProcessIdentifier = decoded_value; } else { @@ -215,12 +197,10 @@ int cov_notify_decode_service_request( } /* tag 1 - initiatingDeviceIdentifier */ if (decode_is_context_tag(&apdu[len], 1)) { - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value); - len += - decode_object_id(&apdu[len], &decoded_type, - &data->initiatingDeviceIdentifier); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value); + len += decode_object_id(&apdu[len], &decoded_type, + &data->initiatingDeviceIdentifier); if (decoded_type != OBJECT_DEVICE) { return BACNET_STATUS_ERROR; } @@ -229,21 +209,18 @@ int cov_notify_decode_service_request( } /* tag 2 - monitoredObjectIdentifier */ if (decode_is_context_tag(&apdu[len], 2)) { - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value); - len += - decode_object_id(&apdu[len], &decoded_type, - &data->monitoredObjectIdentifier.instance); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value); + len += decode_object_id(&apdu[len], &decoded_type, + &data->monitoredObjectIdentifier.instance); data->monitoredObjectIdentifier.type = decoded_type; } else { return BACNET_STATUS_ERROR; } /* tag 3 - timeRemaining */ if (decode_is_context_tag(&apdu[len], 3)) { - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value); len += decode_unsigned(&apdu[len], len_value, &decoded_value); data->timeRemaining = decoded_value; } else { @@ -264,19 +241,17 @@ int cov_notify_decode_service_request( while (value != NULL) { /* tag 0 - propertyIdentifier */ if (decode_is_context_tag(&apdu[len], 0)) { - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value); len += decode_enumerated(&apdu[len], len_value, &property); - value->propertyIdentifier = (BACNET_PROPERTY_ID) property; + value->propertyIdentifier = (BACNET_PROPERTY_ID)property; } else { return BACNET_STATUS_ERROR; } /* tag 1 - propertyArrayIndex OPTIONAL */ if (decode_is_context_tag(&apdu[len], 1)) { - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value); len += decode_unsigned(&apdu[len], len_value, &decoded_value); value->propertyArrayIndex = decoded_value; } else { @@ -289,18 +264,16 @@ int cov_notify_decode_service_request( /* a tag number of 2 is not extended so only one octet */ len++; app_data = &value->value; - while (!decode_is_closing_tag_number(&apdu[len], 2)) - { + while (!decode_is_closing_tag_number(&apdu[len], 2)) { if (app_data == NULL) { /* out of room to store more values */ return BACNET_STATUS_ERROR; } - app_len = - bacapp_decode_application_data(&apdu[len], apdu_len - len, app_data); - if (app_len < 0) - { - return BACNET_STATUS_ERROR; - } + app_len = bacapp_decode_application_data( + &apdu[len], apdu_len - len, app_data); + if (app_len < 0) { + return BACNET_STATUS_ERROR; + } len += app_len; app_data = app_data->next; @@ -309,11 +282,10 @@ int cov_notify_decode_service_request( len++; /* tag 3 - priority OPTIONAL */ if (decode_is_context_tag(&apdu[len], 3)) { - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value); len += decode_unsigned(&apdu[len], len_value, &decoded_value); - value->priority = (uint8_t) decoded_value; + value->priority = (uint8_t)decoded_value; } else { value->priority = BACNET_NO_PRIORITY; } @@ -356,14 +328,12 @@ SubscribeCOV-Request ::= SEQUENCE { } */ -int cov_subscribe_encode_apdu( - uint8_t * apdu, - unsigned max_apdu_len, - uint8_t invoke_id, - BACNET_SUBSCRIBE_COV_DATA * data) +int cov_subscribe_encode_apdu(uint8_t *apdu, unsigned max_apdu_len, + uint8_t invoke_id, + BACNET_SUBSCRIBE_COV_DATA *data) { - int len = 0; /* length of each encoding */ - int apdu_len = 0; /* total length of the apdu, return value */ + int len = 0; /* length of each encoding */ + int apdu_len = 0; /* total length of the apdu, return value */ if (apdu && data) { apdu[0] = PDU_TYPE_CONFIRMED_SERVICE_REQUEST; @@ -372,14 +342,12 @@ int cov_subscribe_encode_apdu( apdu[3] = SERVICE_CONFIRMED_SUBSCRIBE_COV; apdu_len = 4; /* tag 0 - subscriberProcessIdentifier */ - len = - encode_context_unsigned(&apdu[apdu_len], 0, - data->subscriberProcessIdentifier); + len = encode_context_unsigned(&apdu[apdu_len], 0, + data->subscriberProcessIdentifier); apdu_len += len; /* tag 1 - monitoredObjectIdentifier */ - len = - encode_context_object_id(&apdu[apdu_len], 1, - (int) data->monitoredObjectIdentifier.type, + len = encode_context_object_id( + &apdu[apdu_len], 1, (int)data->monitoredObjectIdentifier.type, data->monitoredObjectIdentifier.instance); apdu_len += len; /* @@ -389,9 +357,8 @@ int cov_subscribe_encode_apdu( */ if (!data->cancellationRequest) { /* tag 2 - issueConfirmedNotifications */ - len = - encode_context_boolean(&apdu[apdu_len], 2, - data->issueConfirmedNotifications); + len = encode_context_boolean(&apdu[apdu_len], 2, + data->issueConfirmedNotifications); apdu_len += len; /* tag 3 - lifetime */ len = encode_context_unsigned(&apdu[apdu_len], 3, data->lifetime); @@ -403,12 +370,10 @@ int cov_subscribe_encode_apdu( } /* decode the service request only */ -int cov_subscribe_decode_service_request( - uint8_t * apdu, - unsigned apdu_len, - BACNET_SUBSCRIBE_COV_DATA * data) +int cov_subscribe_decode_service_request(uint8_t *apdu, unsigned apdu_len, + BACNET_SUBSCRIBE_COV_DATA *data) { - int len = 0; /* return value */ + int len = 0; /* return value */ uint8_t tag_number = 0; uint32_t len_value = 0; uint32_t decoded_value = 0; /* for decoding */ @@ -417,9 +382,8 @@ int cov_subscribe_decode_service_request( if (apdu_len && data) { /* tag 0 - subscriberProcessIdentifier */ if (decode_is_context_tag(&apdu[len], 0)) { - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value); len += decode_unsigned(&apdu[len], len_value, &decoded_value); data->subscriberProcessIdentifier = decoded_value; } else { @@ -428,25 +392,22 @@ int cov_subscribe_decode_service_request( } /* tag 1 - monitoredObjectIdentifier */ if (decode_is_context_tag(&apdu[len], 1)) { - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value); - len += - decode_object_id(&apdu[len], &decoded_type, - &data->monitoredObjectIdentifier.instance); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value); + len += decode_object_id(&apdu[len], &decoded_type, + &data->monitoredObjectIdentifier.instance); data->monitoredObjectIdentifier.type = decoded_type; } else { data->error_code = ERROR_CODE_REJECT_INVALID_TAG; return BACNET_STATUS_REJECT; } /* optional parameters - if missing, means cancellation */ - if ((unsigned) len < apdu_len) { + if ((unsigned)len < apdu_len) { /* tag 2 - issueConfirmedNotifications - optional */ if (decode_is_context_tag(&apdu[len], 2)) { data->cancellationRequest = false; - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value); data->issueConfirmedNotifications = decode_context_boolean(&apdu[len]); len += len_value; @@ -455,9 +416,8 @@ int cov_subscribe_decode_service_request( } /* tag 3 - lifetime - optional */ if (decode_is_context_tag(&apdu[len], 3)) { - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value); len += decode_unsigned(&apdu[len], len_value, &decoded_value); data->lifetime = decoded_value; } else { @@ -471,7 +431,6 @@ int cov_subscribe_decode_service_request( return len; } - /* SubscribeCOVProperty-Request ::= SEQUENCE { subscriberProcessIdentifier [0] Unsigned32, @@ -491,14 +450,12 @@ BACnetPropertyReference ::= SEQUENCE { */ -int cov_subscribe_property_encode_apdu( - uint8_t * apdu, - unsigned max_apdu_len, - uint8_t invoke_id, - BACNET_SUBSCRIBE_COV_DATA * data) +int cov_subscribe_property_encode_apdu(uint8_t *apdu, unsigned max_apdu_len, + uint8_t invoke_id, + BACNET_SUBSCRIBE_COV_DATA *data) { - int len = 0; /* length of each encoding */ - int apdu_len = 0; /* total length of the apdu, return value */ + int len = 0; /* length of each encoding */ + int apdu_len = 0; /* total length of the apdu, return value */ if (apdu && data) { apdu[0] = PDU_TYPE_CONFIRMED_SERVICE_REQUEST; @@ -507,21 +464,18 @@ int cov_subscribe_property_encode_apdu( apdu[3] = SERVICE_CONFIRMED_SUBSCRIBE_COV_PROPERTY; apdu_len = 4; /* tag 0 - subscriberProcessIdentifier */ - len = - encode_context_unsigned(&apdu[apdu_len], 0, - data->subscriberProcessIdentifier); + len = encode_context_unsigned(&apdu[apdu_len], 0, + data->subscriberProcessIdentifier); apdu_len += len; /* tag 1 - monitoredObjectIdentifier */ - len = - encode_context_object_id(&apdu[apdu_len], 1, - (int) data->monitoredObjectIdentifier.type, + len = encode_context_object_id( + &apdu[apdu_len], 1, (int)data->monitoredObjectIdentifier.type, data->monitoredObjectIdentifier.instance); apdu_len += len; if (!data->cancellationRequest) { /* tag 2 - issueConfirmedNotifications */ - len = - encode_context_boolean(&apdu[apdu_len], 2, - data->issueConfirmedNotifications); + len = encode_context_boolean(&apdu[apdu_len], 2, + data->issueConfirmedNotifications); apdu_len += len; /* tag 3 - lifetime */ len = encode_context_unsigned(&apdu[apdu_len], 3, data->lifetime); @@ -530,16 +484,13 @@ int cov_subscribe_property_encode_apdu( /* tag 4 - monitoredPropertyIdentifier */ len = encode_opening_tag(&apdu[apdu_len], 4); apdu_len += len; - len = - encode_context_enumerated(&apdu[apdu_len], 0, - data->monitoredProperty.propertyIdentifier); + len = encode_context_enumerated( + &apdu[apdu_len], 0, data->monitoredProperty.propertyIdentifier); apdu_len += len; if (data->monitoredProperty.propertyArrayIndex != BACNET_ARRAY_ALL) { - len = - encode_context_unsigned(&apdu[apdu_len], 1, - data->monitoredProperty.propertyArrayIndex); + len = encode_context_unsigned( + &apdu[apdu_len], 1, data->monitoredProperty.propertyArrayIndex); apdu_len += len; - } len = encode_closing_tag(&apdu[apdu_len], 4); apdu_len += len; @@ -556,11 +507,9 @@ int cov_subscribe_property_encode_apdu( /* decode the service request only */ int cov_subscribe_property_decode_service_request( - uint8_t * apdu, - unsigned apdu_len, - BACNET_SUBSCRIBE_COV_DATA * data) + uint8_t *apdu, unsigned apdu_len, BACNET_SUBSCRIBE_COV_DATA *data) { - int len = 0; /* return value */ + int len = 0; /* return value */ uint8_t tag_number = 0; uint32_t len_value = 0; uint32_t decoded_value = 0; /* for decoding */ @@ -570,9 +519,8 @@ int cov_subscribe_property_decode_service_request( if (apdu_len && data) { /* tag 0 - subscriberProcessIdentifier */ if (decode_is_context_tag(&apdu[len], 0)) { - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value); len += decode_unsigned(&apdu[len], len_value, &decoded_value); data->subscriberProcessIdentifier = decoded_value; } else { @@ -581,12 +529,10 @@ int cov_subscribe_property_decode_service_request( } /* tag 1 - monitoredObjectIdentifier */ if (decode_is_context_tag(&apdu[len], 1)) { - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value); - len += - decode_object_id(&apdu[len], &decoded_type, - &data->monitoredObjectIdentifier.instance); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value); + len += decode_object_id(&apdu[len], &decoded_type, + &data->monitoredObjectIdentifier.instance); data->monitoredObjectIdentifier.type = decoded_type; } else { data->error_code = ERROR_CODE_REJECT_INVALID_TAG; @@ -595,9 +541,8 @@ int cov_subscribe_property_decode_service_request( /* tag 2 - issueConfirmedNotifications - optional */ if (decode_is_context_tag(&apdu[len], 2)) { data->cancellationRequest = false; - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value); data->issueConfirmedNotifications = decode_context_boolean(&apdu[len]); len++; @@ -606,9 +551,8 @@ int cov_subscribe_property_decode_service_request( } /* tag 3 - lifetime - optional */ if (decode_is_context_tag(&apdu[len], 3)) { - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value); len += decode_unsigned(&apdu[len], len_value, &decoded_value); data->lifetime = decoded_value; } else { @@ -623,21 +567,19 @@ int cov_subscribe_property_decode_service_request( len++; /* the propertyIdentifier is tag 0 */ if (decode_is_context_tag(&apdu[len], 0)) { - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value); len += decode_enumerated(&apdu[len], len_value, &property); data->monitoredProperty.propertyIdentifier = - (BACNET_PROPERTY_ID) property; + (BACNET_PROPERTY_ID)property; } else { data->error_code = ERROR_CODE_REJECT_INVALID_TAG; return BACNET_STATUS_REJECT; } /* the optional array index is tag 1 */ if (decode_is_context_tag(&apdu[len], 1)) { - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value); len += decode_unsigned(&apdu[len], len_value, &decoded_value); data->monitoredProperty.propertyArrayIndex = decoded_value; } else { @@ -653,9 +595,8 @@ int cov_subscribe_property_decode_service_request( /* tag 5 - covIncrement - optional */ if (decode_is_context_tag(&apdu[len], 5)) { data->covIncrementPresent = true; - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value); len += decode_real(&apdu[len], &data->covIncrement); } else { data->covIncrementPresent = false; @@ -675,10 +616,8 @@ int cov_subscribe_property_decode_service_request( * a buffer or array. * @param count - number of BACNET_PROPERTY_VALUE elements */ -void cov_data_value_list_link( - BACNET_COV_DATA *data, - BACNET_PROPERTY_VALUE *value_list, - size_t count) +void cov_data_value_list_link(BACNET_COV_DATA *data, + BACNET_PROPERTY_VALUE *value_list, size_t count) { BACNET_PROPERTY_VALUE *current_value_list = NULL; @@ -703,11 +642,8 @@ void cov_data_value_list_link( #include "ctest.h" #include "bacapp.h" -int ccov_notify_decode_apdu( - uint8_t * apdu, - unsigned apdu_len, - uint8_t * invoke_id, - BACNET_COV_DATA * data) +int ccov_notify_decode_apdu(uint8_t *apdu, unsigned apdu_len, + uint8_t *invoke_id, BACNET_COV_DATA *data) { int len = 0; unsigned offset = 0; @@ -719,25 +655,22 @@ int ccov_notify_decode_apdu( if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST) return -2; /* apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU); */ - *invoke_id = apdu[2]; /* invoke id - filled in by net layer */ + *invoke_id = apdu[2]; /* invoke id - filled in by net layer */ if (apdu[3] != SERVICE_CONFIRMED_COV_NOTIFICATION) return -3; offset = 4; /* optional limits - must be used as a pair */ if (apdu_len > offset) { - len = - cov_notify_decode_service_request(&apdu[offset], apdu_len - offset, - data); + len = cov_notify_decode_service_request(&apdu[offset], + apdu_len - offset, data); } return len; } -int ucov_notify_decode_apdu( - uint8_t * apdu, - unsigned apdu_len, - BACNET_COV_DATA * data) +int ucov_notify_decode_apdu(uint8_t *apdu, unsigned apdu_len, + BACNET_COV_DATA *data) { int len = 0; unsigned offset = 0; @@ -752,19 +685,16 @@ int ucov_notify_decode_apdu( /* optional limits - must be used as a pair */ offset = 2; if (apdu_len > offset) { - len = - cov_notify_decode_service_request(&apdu[offset], apdu_len - offset, - data); + len = cov_notify_decode_service_request(&apdu[offset], + apdu_len - offset, data); } return len; } -int cov_subscribe_decode_apdu( - uint8_t * apdu, - unsigned apdu_len, - uint8_t * invoke_id, - BACNET_SUBSCRIBE_COV_DATA * data) +int cov_subscribe_decode_apdu(uint8_t *apdu, unsigned apdu_len, + uint8_t *invoke_id, + BACNET_SUBSCRIBE_COV_DATA *data) { int len = 0; unsigned offset = 0; @@ -775,26 +705,23 @@ int cov_subscribe_decode_apdu( if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST) return -2; /* apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU); */ - *invoke_id = apdu[2]; /* invoke id - filled in by net layer */ + *invoke_id = apdu[2]; /* invoke id - filled in by net layer */ if (apdu[3] != SERVICE_CONFIRMED_SUBSCRIBE_COV) return -3; offset = 4; /* optional limits - must be used as a pair */ if (apdu_len > offset) { - len = - cov_subscribe_decode_service_request(&apdu[offset], - apdu_len - offset, data); + len = cov_subscribe_decode_service_request(&apdu[offset], + apdu_len - offset, data); } return len; } -int cov_subscribe_property_decode_apdu( - uint8_t * apdu, - unsigned apdu_len, - uint8_t * invoke_id, - BACNET_SUBSCRIBE_COV_DATA * data) +int cov_subscribe_property_decode_apdu(uint8_t *apdu, unsigned apdu_len, + uint8_t *invoke_id, + BACNET_SUBSCRIBE_COV_DATA *data) { int len = 0; unsigned offset = 0; @@ -805,42 +732,35 @@ int cov_subscribe_property_decode_apdu( if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST) return -2; /* apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU); */ - *invoke_id = apdu[2]; /* invoke id - filled in by net layer */ + *invoke_id = apdu[2]; /* invoke id - filled in by net layer */ if (apdu[3] != SERVICE_CONFIRMED_SUBSCRIBE_COV_PROPERTY) return -3; offset = 4; /* optional limits - must be used as a pair */ if (apdu_len > offset) { - len = - cov_subscribe_property_decode_service_request(&apdu[offset], - apdu_len - offset, data); + len = cov_subscribe_property_decode_service_request( + &apdu[offset], apdu_len - offset, data); } return len; } /* dummy function stubs */ -void testCOVNotifyData( - Test * pTest, - BACNET_COV_DATA * data, - BACNET_COV_DATA * test_data) +void testCOVNotifyData(Test *pTest, BACNET_COV_DATA *data, + BACNET_COV_DATA *test_data) { BACNET_PROPERTY_VALUE *value = NULL; BACNET_PROPERTY_VALUE *test_value = NULL; - ct_test(pTest, - test_data->subscriberProcessIdentifier == - data->subscriberProcessIdentifier); - ct_test(pTest, - test_data->initiatingDeviceIdentifier == - data->initiatingDeviceIdentifier); - ct_test(pTest, - test_data->monitoredObjectIdentifier.type == - data->monitoredObjectIdentifier.type); - ct_test(pTest, - test_data->monitoredObjectIdentifier.instance == - data->monitoredObjectIdentifier.instance); + ct_test(pTest, test_data->subscriberProcessIdentifier == + data->subscriberProcessIdentifier); + ct_test(pTest, test_data->initiatingDeviceIdentifier == + data->initiatingDeviceIdentifier); + ct_test(pTest, test_data->monitoredObjectIdentifier.type == + data->monitoredObjectIdentifier.type); + ct_test(pTest, test_data->monitoredObjectIdentifier.instance == + data->monitoredObjectIdentifier.instance); ct_test(pTest, test_data->timeRemaining == data->timeRemaining); /* test the listOfValues in some clever manner */ value = data->listOfValues; @@ -848,25 +768,22 @@ void testCOVNotifyData( while (value) { ct_test(pTest, test_value); if (test_value) { + ct_test(pTest, test_value->propertyIdentifier == + value->propertyIdentifier); + ct_test(pTest, test_value->propertyArrayIndex == + value->propertyArrayIndex); + ct_test(pTest, test_value->priority == value->priority); ct_test(pTest, - test_value->propertyIdentifier == value->propertyIdentifier); - ct_test(pTest, - test_value->propertyArrayIndex == value->propertyArrayIndex); - ct_test(pTest, - test_value->priority == value->priority); - ct_test(pTest, - bacapp_same_value(&test_value->value, &value->value)); + bacapp_same_value(&test_value->value, &value->value)); test_value = test_value->next; } value = value->next; } } -void testUCOVNotifyData( - Test * pTest, - BACNET_COV_DATA * data) +void testUCOVNotifyData(Test *pTest, BACNET_COV_DATA *data) { - uint8_t apdu[480] = { 0 }; + uint8_t apdu[480] = {0}; int len = 0; int apdu_len = 0; BACNET_COV_DATA test_data; @@ -882,12 +799,9 @@ void testUCOVNotifyData( testCOVNotifyData(pTest, data, &test_data); } -void testCCOVNotifyData( - Test * pTest, - uint8_t invoke_id, - BACNET_COV_DATA * data) +void testCCOVNotifyData(Test *pTest, uint8_t invoke_id, BACNET_COV_DATA *data) { - uint8_t apdu[480] = { 0 }; + uint8_t apdu[480] = {0}; int len = 0; int apdu_len = 0; BACNET_COV_DATA test_data; @@ -899,16 +813,14 @@ void testCCOVNotifyData( apdu_len = len; cov_data_value_list_link(&test_data, &value_list[0], 2); - len = - ccov_notify_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, - &test_data); + len = ccov_notify_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, + &test_data); ct_test(pTest, len > 0); ct_test(pTest, test_invoke_id == invoke_id); testCOVNotifyData(pTest, data, &test_data); } -void testCOVNotify( - Test * pTest) +void testCOVNotify(Test *pTest) { uint8_t invoke_id = 12; BACNET_COV_DATA data; @@ -925,71 +837,57 @@ void testCOVNotify( value_list[0].propertyIdentifier = PROP_PRESENT_VALUE; value_list[0].propertyArrayIndex = BACNET_ARRAY_ALL; bacapp_parse_application_data(BACNET_APPLICATION_TAG_REAL, "21.0", - &value_list[0].value); + &value_list[0].value); value_list[0].priority = 0; /* second value */ value_list[1].propertyIdentifier = PROP_STATUS_FLAGS; value_list[1].propertyArrayIndex = BACNET_ARRAY_ALL; bacapp_parse_application_data(BACNET_APPLICATION_TAG_BIT_STRING, "0000", - &value_list[1].value); + &value_list[1].value); value_list[1].priority = 0; testUCOVNotifyData(pTest, &data); testCCOVNotifyData(pTest, invoke_id, &data); } -void testCOVSubscribeData( - Test * pTest, - BACNET_SUBSCRIBE_COV_DATA * data, - BACNET_SUBSCRIBE_COV_DATA * test_data) +void testCOVSubscribeData(Test *pTest, BACNET_SUBSCRIBE_COV_DATA *data, + BACNET_SUBSCRIBE_COV_DATA *test_data) { - ct_test(pTest, - test_data->subscriberProcessIdentifier == - data->subscriberProcessIdentifier); - ct_test(pTest, - test_data->monitoredObjectIdentifier.type == - data->monitoredObjectIdentifier.type); - ct_test(pTest, - test_data->monitoredObjectIdentifier.instance == - data->monitoredObjectIdentifier.instance); - ct_test(pTest, - test_data->cancellationRequest == data->cancellationRequest); + ct_test(pTest, test_data->subscriberProcessIdentifier == + data->subscriberProcessIdentifier); + ct_test(pTest, test_data->monitoredObjectIdentifier.type == + data->monitoredObjectIdentifier.type); + ct_test(pTest, test_data->monitoredObjectIdentifier.instance == + data->monitoredObjectIdentifier.instance); + ct_test(pTest, test_data->cancellationRequest == data->cancellationRequest); if (test_data->cancellationRequest != data->cancellationRequest) { printf("cancellation request failed!\n"); } if (!test_data->cancellationRequest) { - ct_test(pTest, - test_data->issueConfirmedNotifications == - data->issueConfirmedNotifications); + ct_test(pTest, test_data->issueConfirmedNotifications == + data->issueConfirmedNotifications); ct_test(pTest, test_data->lifetime == data->lifetime); } } -void testCOVSubscribePropertyData( - Test * pTest, - BACNET_SUBSCRIBE_COV_DATA * data, - BACNET_SUBSCRIBE_COV_DATA * test_data) +void testCOVSubscribePropertyData(Test *pTest, BACNET_SUBSCRIBE_COV_DATA *data, + BACNET_SUBSCRIBE_COV_DATA *test_data) { testCOVSubscribeData(pTest, data, test_data); - ct_test(pTest, - test_data->monitoredProperty.propertyIdentifier == - data->monitoredProperty.propertyIdentifier); - ct_test(pTest, - test_data->monitoredProperty.propertyArrayIndex == - data->monitoredProperty.propertyArrayIndex); - ct_test(pTest, - test_data->covIncrementPresent == data->covIncrementPresent); + ct_test(pTest, test_data->monitoredProperty.propertyIdentifier == + data->monitoredProperty.propertyIdentifier); + ct_test(pTest, test_data->monitoredProperty.propertyArrayIndex == + data->monitoredProperty.propertyArrayIndex); + ct_test(pTest, test_data->covIncrementPresent == data->covIncrementPresent); if (test_data->covIncrementPresent) { ct_test(pTest, test_data->covIncrement == data->covIncrement); } } -void testCOVSubscribeEncoding( - Test * pTest, - uint8_t invoke_id, - BACNET_SUBSCRIBE_COV_DATA * data) +void testCOVSubscribeEncoding(Test *pTest, uint8_t invoke_id, + BACNET_SUBSCRIBE_COV_DATA *data) { - uint8_t apdu[480] = { 0 }; + uint8_t apdu[480] = {0}; int len = 0; int apdu_len = 0; BACNET_SUBSCRIBE_COV_DATA test_data; @@ -999,40 +897,35 @@ void testCOVSubscribeEncoding( ct_test(pTest, len != 0); apdu_len = len; - len = - cov_subscribe_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, - &test_data); + len = cov_subscribe_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, + &test_data); ct_test(pTest, len > 0); ct_test(pTest, test_invoke_id == invoke_id); testCOVSubscribeData(pTest, data, &test_data); } -void testCOVSubscribePropertyEncoding( - Test * pTest, - uint8_t invoke_id, - BACNET_SUBSCRIBE_COV_DATA * data) +void testCOVSubscribePropertyEncoding(Test *pTest, uint8_t invoke_id, + BACNET_SUBSCRIBE_COV_DATA *data) { - uint8_t apdu[480] = { 0 }; + uint8_t apdu[480] = {0}; int len = 0; int apdu_len = 0; BACNET_SUBSCRIBE_COV_DATA test_data; uint8_t test_invoke_id = 0; len = cov_subscribe_property_encode_apdu(&apdu[0], sizeof(apdu), invoke_id, - data); + data); ct_test(pTest, len != 0); apdu_len = len; - len = - cov_subscribe_property_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, - &test_data); + len = cov_subscribe_property_decode_apdu(&apdu[0], apdu_len, + &test_invoke_id, &test_data); ct_test(pTest, len > 0); ct_test(pTest, test_invoke_id == invoke_id); testCOVSubscribePropertyData(pTest, data, &test_data); } -void testCOVSubscribe( - Test * pTest) +void testCOVSubscribe(Test *pTest) { uint8_t invoke_id = 12; BACNET_SUBSCRIBE_COV_DATA data; @@ -1049,8 +942,7 @@ void testCOVSubscribe( testCOVSubscribeEncoding(pTest, invoke_id, &data); } -void testCOVSubscribeProperty( - Test * pTest) +void testCOVSubscribeProperty(Test *pTest) { uint8_t invoke_id = 12; BACNET_SUBSCRIBE_COV_DATA data; @@ -1077,9 +969,7 @@ void testCOVSubscribeProperty( } #ifdef TEST_COV -int main( - int argc, - char *argv[]) +int main(int argc, char *argv[]) { Test *pTest; bool rc; @@ -1095,7 +985,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/src/crc.c b/src/crc.c index 04af0c22..1ed2ad59 100644 --- a/src/crc.c +++ b/src/crc.c @@ -42,89 +42,69 @@ #if defined(CRC_USE_TABLE) /* note: table is created using unit test below */ static const uint8_t HeaderCRC[256] = { - 0x00, 0xfe, 0xff, 0x01, 0xfd, 0x03, 0x02, 0xfc, - 0xf9, 0x07, 0x06, 0xf8, 0x04, 0xfa, 0xfb, 0x05, - 0xf1, 0x0f, 0x0e, 0xf0, 0x0c, 0xf2, 0xf3, 0x0d, - 0x08, 0xf6, 0xf7, 0x09, 0xf5, 0x0b, 0x0a, 0xf4, - 0xe1, 0x1f, 0x1e, 0xe0, 0x1c, 0xe2, 0xe3, 0x1d, - 0x18, 0xe6, 0xe7, 0x19, 0xe5, 0x1b, 0x1a, 0xe4, - 0x10, 0xee, 0xef, 0x11, 0xed, 0x13, 0x12, 0xec, - 0xe9, 0x17, 0x16, 0xe8, 0x14, 0xea, 0xeb, 0x15, - 0xc1, 0x3f, 0x3e, 0xc0, 0x3c, 0xc2, 0xc3, 0x3d, - 0x38, 0xc6, 0xc7, 0x39, 0xc5, 0x3b, 0x3a, 0xc4, - 0x30, 0xce, 0xcf, 0x31, 0xcd, 0x33, 0x32, 0xcc, - 0xc9, 0x37, 0x36, 0xc8, 0x34, 0xca, 0xcb, 0x35, - 0x20, 0xde, 0xdf, 0x21, 0xdd, 0x23, 0x22, 0xdc, - 0xd9, 0x27, 0x26, 0xd8, 0x24, 0xda, 0xdb, 0x25, - 0xd1, 0x2f, 0x2e, 0xd0, 0x2c, 0xd2, 0xd3, 0x2d, - 0x28, 0xd6, 0xd7, 0x29, 0xd5, 0x2b, 0x2a, 0xd4, - 0x81, 0x7f, 0x7e, 0x80, 0x7c, 0x82, 0x83, 0x7d, - 0x78, 0x86, 0x87, 0x79, 0x85, 0x7b, 0x7a, 0x84, - 0x70, 0x8e, 0x8f, 0x71, 0x8d, 0x73, 0x72, 0x8c, - 0x89, 0x77, 0x76, 0x88, 0x74, 0x8a, 0x8b, 0x75, - 0x60, 0x9e, 0x9f, 0x61, 0x9d, 0x63, 0x62, 0x9c, - 0x99, 0x67, 0x66, 0x98, 0x64, 0x9a, 0x9b, 0x65, - 0x91, 0x6f, 0x6e, 0x90, 0x6c, 0x92, 0x93, 0x6d, - 0x68, 0x96, 0x97, 0x69, 0x95, 0x6b, 0x6a, 0x94, - 0x40, 0xbe, 0xbf, 0x41, 0xbd, 0x43, 0x42, 0xbc, - 0xb9, 0x47, 0x46, 0xb8, 0x44, 0xba, 0xbb, 0x45, - 0xb1, 0x4f, 0x4e, 0xb0, 0x4c, 0xb2, 0xb3, 0x4d, - 0x48, 0xb6, 0xb7, 0x49, 0xb5, 0x4b, 0x4a, 0xb4, - 0xa1, 0x5f, 0x5e, 0xa0, 0x5c, 0xa2, 0xa3, 0x5d, - 0x58, 0xa6, 0xa7, 0x59, 0xa5, 0x5b, 0x5a, 0xa4, - 0x50, 0xae, 0xaf, 0x51, 0xad, 0x53, 0x52, 0xac, - 0xa9, 0x57, 0x56, 0xa8, 0x54, 0xaa, 0xab, 0x55 -}; + 0x00, 0xfe, 0xff, 0x01, 0xfd, 0x03, 0x02, 0xfc, 0xf9, 0x07, 0x06, 0xf8, + 0x04, 0xfa, 0xfb, 0x05, 0xf1, 0x0f, 0x0e, 0xf0, 0x0c, 0xf2, 0xf3, 0x0d, + 0x08, 0xf6, 0xf7, 0x09, 0xf5, 0x0b, 0x0a, 0xf4, 0xe1, 0x1f, 0x1e, 0xe0, + 0x1c, 0xe2, 0xe3, 0x1d, 0x18, 0xe6, 0xe7, 0x19, 0xe5, 0x1b, 0x1a, 0xe4, + 0x10, 0xee, 0xef, 0x11, 0xed, 0x13, 0x12, 0xec, 0xe9, 0x17, 0x16, 0xe8, + 0x14, 0xea, 0xeb, 0x15, 0xc1, 0x3f, 0x3e, 0xc0, 0x3c, 0xc2, 0xc3, 0x3d, + 0x38, 0xc6, 0xc7, 0x39, 0xc5, 0x3b, 0x3a, 0xc4, 0x30, 0xce, 0xcf, 0x31, + 0xcd, 0x33, 0x32, 0xcc, 0xc9, 0x37, 0x36, 0xc8, 0x34, 0xca, 0xcb, 0x35, + 0x20, 0xde, 0xdf, 0x21, 0xdd, 0x23, 0x22, 0xdc, 0xd9, 0x27, 0x26, 0xd8, + 0x24, 0xda, 0xdb, 0x25, 0xd1, 0x2f, 0x2e, 0xd0, 0x2c, 0xd2, 0xd3, 0x2d, + 0x28, 0xd6, 0xd7, 0x29, 0xd5, 0x2b, 0x2a, 0xd4, 0x81, 0x7f, 0x7e, 0x80, + 0x7c, 0x82, 0x83, 0x7d, 0x78, 0x86, 0x87, 0x79, 0x85, 0x7b, 0x7a, 0x84, + 0x70, 0x8e, 0x8f, 0x71, 0x8d, 0x73, 0x72, 0x8c, 0x89, 0x77, 0x76, 0x88, + 0x74, 0x8a, 0x8b, 0x75, 0x60, 0x9e, 0x9f, 0x61, 0x9d, 0x63, 0x62, 0x9c, + 0x99, 0x67, 0x66, 0x98, 0x64, 0x9a, 0x9b, 0x65, 0x91, 0x6f, 0x6e, 0x90, + 0x6c, 0x92, 0x93, 0x6d, 0x68, 0x96, 0x97, 0x69, 0x95, 0x6b, 0x6a, 0x94, + 0x40, 0xbe, 0xbf, 0x41, 0xbd, 0x43, 0x42, 0xbc, 0xb9, 0x47, 0x46, 0xb8, + 0x44, 0xba, 0xbb, 0x45, 0xb1, 0x4f, 0x4e, 0xb0, 0x4c, 0xb2, 0xb3, 0x4d, + 0x48, 0xb6, 0xb7, 0x49, 0xb5, 0x4b, 0x4a, 0xb4, 0xa1, 0x5f, 0x5e, 0xa0, + 0x5c, 0xa2, 0xa3, 0x5d, 0x58, 0xa6, 0xa7, 0x59, 0xa5, 0x5b, 0x5a, 0xa4, + 0x50, 0xae, 0xaf, 0x51, 0xad, 0x53, 0x52, 0xac, 0xa9, 0x57, 0x56, 0xa8, + 0x54, 0xaa, 0xab, 0x55}; -uint8_t CRC_Calc_Header( - uint8_t dataValue, - uint8_t crcValue) +uint8_t CRC_Calc_Header(uint8_t dataValue, uint8_t crcValue) { return HeaderCRC[crcValue ^ dataValue]; } /* note: table is created using unit test below */ static const uint16_t DataCRC[256] = { - 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf, - 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7, - 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e, - 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876, - 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd, - 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5, - 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c, - 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974, - 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb, - 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3, - 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a, - 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72, - 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9, - 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1, - 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738, - 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70, - 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7, - 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff, - 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036, - 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e, - 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5, - 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd, - 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134, - 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c, - 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3, - 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb, - 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232, - 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a, - 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1, - 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9, - 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330, - 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78 -}; + 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf, 0x8c48, + 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7, 0x1081, 0x0108, + 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e, 0x9cc9, 0x8d40, 0xbfdb, + 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876, 0x2102, 0x308b, 0x0210, 0x1399, + 0x6726, 0x76af, 0x4434, 0x55bd, 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, + 0xfae7, 0xc87c, 0xd9f5, 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, + 0x54b5, 0x453c, 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, + 0xc974, 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb, + 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3, 0x5285, + 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a, 0xdecd, 0xcf44, + 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72, 0x6306, 0x728f, 0x4014, + 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9, 0xef4e, 0xfec7, 0xcc5c, 0xddd5, + 0xa96a, 0xb8e3, 0x8a78, 0x9bf1, 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, + 0x242a, 0x16b1, 0x0738, 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, + 0x9af9, 0x8b70, 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, + 0xf0b7, 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff, + 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036, 0x18c1, + 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e, 0xa50a, 0xb483, + 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5, 0x2942, 0x38cb, 0x0a50, + 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd, 0xb58b, 0xa402, 0x9699, 0x8710, + 0xf3af, 0xe226, 0xd0bd, 0xc134, 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, + 0x6e6e, 0x5cf5, 0x4d7c, 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, + 0xa33a, 0xb2b3, 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, + 0x3efb, 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232, + 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a, 0xe70e, + 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1, 0x6b46, 0x7acf, + 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9, 0xf78f, 0xe606, 0xd49d, + 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330, 0x7bc7, 0x6a4e, 0x58d5, 0x495c, + 0x3de3, 0x2c6a, 0x1ef1, 0x0f78}; -uint16_t CRC_Calc_Data( - uint8_t dataValue, - uint16_t crcValue) +uint16_t CRC_Calc_Data(uint8_t dataValue, uint16_t crcValue) { return ((crcValue >> 8) ^ DataCRC[(crcValue & 0x00FF) ^ dataValue]); - } #else /* Accumulate "dataValue" into the CRC in crcValue. */ @@ -132,18 +112,15 @@ uint16_t CRC_Calc_Data( /* */ /* The ^ operator means exclusive OR. */ /* Note: This function is copied directly from the BACnet standard. */ -uint8_t CRC_Calc_Header( - uint8_t dataValue, - uint8_t crcValue) +uint8_t CRC_Calc_Header(uint8_t dataValue, uint8_t crcValue) { uint16_t crc; crc = crcValue ^ dataValue; /* XOR C7..C0 with D7..D0 */ /* Exclusive OR the terms in the table (top down) */ - crc = crc ^ (crc << 1) ^ (crc << 2) ^ (crc << 3) - ^ (crc << 4) ^ (crc << 5) ^ (crc << 6) - ^ (crc << 7); + crc = crc ^ (crc << 1) ^ (crc << 2) ^ (crc << 3) ^ (crc << 4) ^ (crc << 5) ^ + (crc << 6) ^ (crc << 7); /* Combine bits shifted out left hand end */ return (crc & 0xfe) ^ ((crc >> 8) & 1); @@ -154,18 +131,15 @@ uint8_t CRC_Calc_Header( /* */ /* The ^ operator means exclusive OR. */ /* Note: This function is copied directly from the BACnet standard. */ -uint16_t CRC_Calc_Data( - uint8_t dataValue, - uint16_t crcValue) +uint16_t CRC_Calc_Data(uint8_t dataValue, uint16_t crcValue) { uint16_t crcLow; - crcLow = (crcValue & 0xff) ^ dataValue; /* XOR C7..C0 with D7..D0 */ + crcLow = (crcValue & 0xff) ^ dataValue; /* XOR C7..C0 with D7..D0 */ /* Exclusive OR the terms in the table (top down) */ - return (crcValue >> 8) ^ (crcLow << 8) ^ (crcLow << 3) - ^ (crcLow << 12) ^ (crcLow >> 4) - ^ (crcLow & 0x0f) ^ ((crcLow & 0x0f) << 7); + return (crcValue >> 8) ^ (crcLow << 8) ^ (crcLow << 3) ^ (crcLow << 12) ^ + (crcLow >> 4) ^ (crcLow & 0x0f) ^ ((crcLow & 0x0f) << 7); } #endif @@ -176,8 +150,7 @@ uint16_t CRC_Calc_Data( #include "bytes.h" /* test from Annex G 1.0 of BACnet Standard */ -void testCRC8( - Test * pTest) +void testCRC8(Test *pTest) { uint8_t crc = 0xff; /* accumulates the crc value */ uint8_t frame_crc; /* appended to the end of the frame */ @@ -202,8 +175,7 @@ void testCRC8( } /* test from Annex G 2.0 of BACnet Standard */ -void testCRC16( - Test * pTest) +void testCRC16(Test *pTest) { uint16_t crc = 0xffff; uint16_t data_crc; @@ -224,13 +196,12 @@ void testCRC16( ct_test(pTest, crc == 0xF0B8); } -void testCRC8CreateTable( - Test * pTest) +void testCRC8CreateTable(Test *pTest) { uint8_t crc = 0xff; /* accumulates the crc value */ int i; - (void) pTest; + (void)pTest; printf("static const uint8_t HeaderCRC[256] =\n"); printf("{\n"); printf(" "); @@ -247,13 +218,12 @@ void testCRC8CreateTable( printf("};\n"); } -void testCRC16CreateTable( - Test * pTest) +void testCRC16CreateTable(Test *pTest) { uint16_t crc; int i; - (void) pTest; + (void)pTest; printf("static const uint16_t DataCRC[256] =\n"); printf("{\n"); printf(" "); @@ -273,8 +243,7 @@ void testCRC16CreateTable( #endif #ifdef TEST_CRC -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -293,7 +262,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); diff --git a/src/credential_authentication_factor.c b/src/credential_authentication_factor.c index 127b8154..0a9b3e7b 100644 --- a/src/credential_authentication_factor.c +++ b/src/credential_authentication_factor.c @@ -1,35 +1,33 @@ /************************************************************************** -* -* Copyright (C) 2015 Nikola Jelic -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2015 Nikola Jelic + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include "credential_authentication_factor.h" #include "bacdcode.h" - int bacapp_encode_credential_authentication_factor( - uint8_t * apdu, - BACNET_CREDENTIAL_AUTHENTICATION_FACTOR * caf) + uint8_t* apdu, BACNET_CREDENTIAL_AUTHENTICATION_FACTOR* caf) { int len; int apdu_len = 0; @@ -40,9 +38,8 @@ int bacapp_encode_credential_authentication_factor( else apdu_len += len; - len = - bacapp_encode_context_authentication_factor(&apdu[apdu_len], 1, - &caf->authentication_factor); + len = bacapp_encode_context_authentication_factor( + &apdu[apdu_len], 1, &caf->authentication_factor); if (len < 0) return -1; else @@ -52,9 +49,7 @@ int bacapp_encode_credential_authentication_factor( } int bacapp_encode_context_credential_authentication_factor( - uint8_t * apdu, - uint8_t tag, - BACNET_CREDENTIAL_AUTHENTICATION_FACTOR * caf) + uint8_t* apdu, uint8_t tag, BACNET_CREDENTIAL_AUTHENTICATION_FACTOR* caf) { int len; int apdu_len = 0; @@ -69,12 +64,10 @@ int bacapp_encode_context_credential_authentication_factor( apdu_len += len; return apdu_len; - } int bacapp_decode_credential_authentication_factor( - uint8_t * apdu, - BACNET_CREDENTIAL_AUTHENTICATION_FACTOR * caf) + uint8_t* apdu, BACNET_CREDENTIAL_AUTHENTICATION_FACTOR* caf) { int len; int apdu_len = 0; @@ -89,9 +82,8 @@ int bacapp_decode_credential_authentication_factor( return -1; if (decode_is_context_tag(&apdu[apdu_len], 1)) { - len = - bacapp_decode_context_authentication_factor(&apdu[apdu_len], 1, - &caf->authentication_factor); + len = bacapp_decode_context_authentication_factor( + &apdu[apdu_len], 1, &caf->authentication_factor); if (len < 0) return -1; else @@ -103,9 +95,7 @@ int bacapp_decode_credential_authentication_factor( } int bacapp_decode_context_credential_authentication_factor( - uint8_t * apdu, - uint8_t tag, - BACNET_CREDENTIAL_AUTHENTICATION_FACTOR * caf) + uint8_t* apdu, uint8_t tag, BACNET_CREDENTIAL_AUTHENTICATION_FACTOR* caf) { int len = 0; int section_length; diff --git a/src/datalink.c b/src/datalink.c index 459034ea..72697b76 100644 --- a/src/datalink.c +++ b/src/datalink.c @@ -44,17 +44,19 @@ #include /* Function pointers - point to your datalink */ -/** Function template to Initialize the DataLink services at the given interface. +/** Function template to Initialize the DataLink services at the given + interface. * @ingroup DLTemplates * * @note For Linux, ifname is eth0, ath0, arc0, ttyS0, and others. - For Windows, ifname is the COM port or dotted ip address of the interface. + For Windows, ifname is the COM port or dotted ip address of the + interface. * @param ifname [in] The named interface to use for the network layer. * @return True if the interface is successfully initialized, * else False if the initialization fails. */ -bool(*datalink_init) (char *ifname); +bool (*datalink_init)(char *ifname); /** Function template to send a packet via the DataLink. * @ingroup DLTemplates @@ -65,33 +67,22 @@ bool(*datalink_init) (char *ifname); * @param pdu_len [in] Number of bytes in the pdu buffer. * @return Number of bytes sent on success, negative number on failure. */ -int ( - *datalink_send_pdu) ( - BACNET_ADDRESS * dest, - BACNET_NPDU_DATA * npdu_data, - uint8_t * pdu, - unsigned pdu_len); +int (*datalink_send_pdu)(BACNET_ADDRESS *dest, BACNET_NPDU_DATA *npdu_data, + uint8_t *pdu, unsigned pdu_len); -uint16_t(*datalink_receive) (BACNET_ADDRESS * src, uint8_t * pdu, - uint16_t max_pdu, unsigned timeout); +uint16_t (*datalink_receive)(BACNET_ADDRESS *src, uint8_t *pdu, + uint16_t max_pdu, unsigned timeout); /** Function template to close the DataLink services and perform any cleanup. * @ingroup DLTemplates */ -void ( - *datalink_cleanup) ( - void); +void (*datalink_cleanup)(void); -void ( - *datalink_get_broadcast_address) ( - BACNET_ADDRESS * dest); +void (*datalink_get_broadcast_address)(BACNET_ADDRESS *dest); -void ( - *datalink_get_my_address) ( - BACNET_ADDRESS * my_address); +void (*datalink_get_my_address)(BACNET_ADDRESS *my_address); -void datalink_set( - char *datalink_string) +void datalink_set(char *datalink_string) { if (strcasecmp("bip", datalink_string) == 0) { datalink_init = bip_init; @@ -147,46 +138,35 @@ void datalink_set( #endif #if defined(BACDL_NONE) -int datalink_send_pdu( - BACNET_ADDRESS * dest, - BACNET_NPDU_DATA * npdu_data, - uint8_t * pdu, - unsigned pdu_len) +int datalink_send_pdu(BACNET_ADDRESS *dest, BACNET_NPDU_DATA *npdu_data, + uint8_t *pdu, unsigned pdu_len) { return 0; } -uint16_t datalink_receive( - BACNET_ADDRESS * src, - uint8_t * pdu, - uint16_t max_pdu, - unsigned timeout) +uint16_t datalink_receive(BACNET_ADDRESS *src, uint8_t *pdu, uint16_t max_pdu, + unsigned timeout) { return 0; } -void datalink_cleanup( - void) +void datalink_cleanup(void) { } -void datalink_get_broadcast_address( - BACNET_ADDRESS * dest) +void datalink_get_broadcast_address(BACNET_ADDRESS *dest) { } -void datalink_get_my_address( - BACNET_ADDRESS * my_address) +void datalink_get_my_address(BACNET_ADDRESS *my_address) { } -void datalink_set_interface( - char *ifname) +void datalink_set_interface(char *ifname) { } -void datalink_set( - char *datalink_string) +void datalink_set(char *datalink_string) { } #endif diff --git a/src/datetime.c b/src/datetime.c index 41adee13..0f26327b 100644 --- a/src/datetime.c +++ b/src/datetime.c @@ -60,8 +60,7 @@ time or date may be interpreted as "any" or "don't care" */ -bool datetime_is_leap_year( - uint16_t year) +bool datetime_is_leap_year(uint16_t year) { if ((year % 4) == 0 && ((year % 100) != 0 || (year % 400) == 0)) return (true); @@ -69,13 +68,11 @@ bool datetime_is_leap_year( return (false); } -uint8_t datetime_month_days( - uint16_t year, - uint8_t month) +uint8_t datetime_month_days(uint16_t year, uint8_t month) { /* note: start with a zero in the first element to save us from a month - 1 calculation in the lookup */ - int month_days[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; + int month_days[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; /* return value */ uint8_t days = 0; @@ -83,34 +80,29 @@ uint8_t datetime_month_days( if ((month == 2) && datetime_is_leap_year(year)) { days = 29; } else if (month >= 1 && month <= 12) { - days = (uint8_t) month_days[month]; + days = (uint8_t)month_days[month]; } return days; } -bool datetime_ymd_is_valid( - uint16_t year, - uint8_t month, - uint8_t day) +bool datetime_ymd_is_valid(uint16_t year, uint8_t month, uint8_t day) { - bool status = false; /* true if value date */ - uint8_t monthdays = 0; /* days in a month */ + bool status = false; /* true if value date */ + uint8_t monthdays = 0; /* days in a month */ monthdays = datetime_month_days(year, month); - if ((year >= BACNET_EPOCH_YEAR) && (monthdays > 0) && - (day >= 1) && (day <= monthdays)) { + if ((year >= BACNET_EPOCH_YEAR) && (monthdays > 0) && (day >= 1) && + (day <= monthdays)) { status = true; } return status; } -bool datetime_date_is_valid( - BACNET_DATE * bdate) +bool datetime_date_is_valid(BACNET_DATE *bdate) { - - bool status = false; /* true if value date */ + bool status = false; /* true if value date */ if (bdate) { status = datetime_ymd_is_valid(bdate->year, bdate->month, bdate->day); @@ -119,10 +111,7 @@ bool datetime_date_is_valid( return status; } -static uint32_t day_of_year( - uint16_t year, - uint8_t month, - uint8_t day) +static uint32_t day_of_year(uint16_t year, uint8_t month, uint8_t day) { uint32_t days = 0; /* return value */ uint8_t months = 0; /* loop counter for months */ @@ -137,21 +126,18 @@ static uint32_t day_of_year( return (days); } -static void day_of_year_into_md( - uint32_t days, - uint16_t year, - uint8_t * pMonth, - uint8_t * pDay) +static void day_of_year_into_md(uint32_t days, uint16_t year, uint8_t *pMonth, + uint8_t *pDay) { uint8_t month = 1; uint8_t day = 0; - while (days > (uint32_t) datetime_month_days(year, month)) { + while (days > (uint32_t)datetime_month_days(year, month)) { days -= datetime_month_days(year, month); month++; } - day = (uint8_t) (day + days); + day = (uint8_t)(day + days); if (pMonth) { *pMonth = month; @@ -163,10 +149,8 @@ static void day_of_year_into_md( return; } -void datetime_day_of_year_into_date( - uint32_t days, - uint16_t year, - BACNET_DATE *bdate) +void datetime_day_of_year_into_date(uint32_t days, uint16_t year, + BACNET_DATE *bdate) { uint8_t month = 0; uint8_t day = 0; @@ -175,8 +159,7 @@ void datetime_day_of_year_into_date( datetime_set_date(bdate, year, month, day); } -uint32_t datetime_day_of_year( - BACNET_DATE *bdate) +uint32_t datetime_day_of_year(BACNET_DATE *bdate) { uint32_t days = 0; @@ -187,10 +170,7 @@ uint32_t datetime_day_of_year( return days; } -static uint32_t days_since_epoch( - uint16_t year, - uint8_t month, - uint8_t day) +static uint32_t days_since_epoch(uint16_t year, uint8_t month, uint8_t day) { uint32_t days = 0; /* return value */ uint16_t years = 0; /* loop counter for years */ @@ -209,8 +189,7 @@ static uint32_t days_since_epoch( return (days); } -uint32_t datetime_days_since_epoch( - BACNET_DATE * bdate) +uint32_t datetime_days_since_epoch(BACNET_DATE *bdate) { uint32_t days = 0; @@ -221,11 +200,8 @@ uint32_t datetime_days_since_epoch( return days; } -static void days_since_epoch_into_ymd( - uint32_t days, - uint16_t * pYear, - uint8_t * pMonth, - uint8_t * pDay) +static void days_since_epoch_into_ymd(uint32_t days, uint16_t *pYear, + uint8_t *pMonth, uint8_t *pDay) { uint16_t year = BACNET_EPOCH_YEAR; uint8_t month = 1; @@ -240,12 +216,12 @@ static void days_since_epoch_into_ymd( year++; } - while (days >= (uint32_t) datetime_month_days(year, month)) { + while (days >= (uint32_t)datetime_month_days(year, month)) { days -= datetime_month_days(year, month); month++; } - day = (uint8_t) (day + days); + day = (uint8_t)(day + days); if (pYear) *pYear = year; @@ -257,9 +233,7 @@ static void days_since_epoch_into_ymd( return; } -void datetime_days_since_epoch_into_date( - uint32_t days, - BACNET_DATE * bdate) +void datetime_days_since_epoch_into_date(uint32_t days, BACNET_DATE *bdate) { uint16_t year = 0; uint8_t month = 0; @@ -271,10 +245,7 @@ void datetime_days_since_epoch_into_date( /* Jan 1, 1900 is a Monday */ /* wday 1=Monday...7=Sunday */ -uint8_t datetime_day_of_week( - uint16_t year, - uint8_t month, - uint8_t day) +uint8_t datetime_day_of_week(uint16_t year, uint8_t month, uint8_t day) { uint8_t dow = (uint8_t)BACNET_EPOCH_DOW; @@ -283,8 +254,7 @@ uint8_t datetime_day_of_week( return dow; } -bool datetime_time_is_valid( - BACNET_TIME * btime) +bool datetime_time_is_valid(BACNET_TIME *btime) { bool status = false; @@ -306,29 +276,24 @@ bool datetime_time_is_valid( * * @return true if the date and time are valid */ -bool datetime_is_valid( - BACNET_DATE * bdate, - BACNET_TIME * btime) +bool datetime_is_valid(BACNET_DATE *bdate, BACNET_TIME *btime) { return datetime_date_is_valid(bdate) && datetime_time_is_valid(btime); } - /* if the date1 is the same as date2, return is 0 if date1 is after date2, returns positive if date1 is before date2, returns negative */ -int datetime_compare_date( - BACNET_DATE * date1, - BACNET_DATE * date2) +int datetime_compare_date(BACNET_DATE *date1, BACNET_DATE *date2) { int diff = 0; if (date1 && date2) { - diff = (int) date1->year - (int) date2->year; + diff = (int)date1->year - (int)date2->year; if (diff == 0) { - diff = (int) date1->month - (int) date2->month; + diff = (int)date1->month - (int)date2->month; if (diff == 0) { - diff = (int) date1->day - (int) date2->day; + diff = (int)date1->day - (int)date2->day; } } } @@ -339,20 +304,18 @@ int datetime_compare_date( /* if the time1 is the same as time2, return is 0 if time1 is after time2, returns positive if time1 is before time2, returns negative */ -int datetime_compare_time( - BACNET_TIME * time1, - BACNET_TIME * time2) +int datetime_compare_time(BACNET_TIME *time1, BACNET_TIME *time2) { int diff = 0; if (time1 && time2) { - diff = (int) time1->hour - (int) time2->hour; + diff = (int)time1->hour - (int)time2->hour; if (diff == 0) { - diff = (int) time1->min - (int) time2->min; + diff = (int)time1->min - (int)time2->min; if (diff == 0) { - diff = (int) time1->sec - (int) time2->sec; + diff = (int)time1->sec - (int)time2->sec; if (diff == 0) { - diff = (int) time1->hundredths - (int) time2->hundredths; + diff = (int)time1->hundredths - (int)time2->hundredths; } } } @@ -364,9 +327,7 @@ int datetime_compare_time( /* if the datetime1 is the same as datetime2, return is 0 if datetime1 is before datetime2, returns negative if datetime1 is after datetime2, returns positive */ -int datetime_compare( - BACNET_DATE_TIME * datetime1, - BACNET_DATE_TIME * datetime2) +int datetime_compare(BACNET_DATE_TIME *datetime1, BACNET_DATE_TIME *datetime2) { int diff = 0; @@ -378,9 +339,7 @@ int datetime_compare( return diff; } -int datetime_wildcard_compare_date( - BACNET_DATE * date1, - BACNET_DATE * date2) +int datetime_wildcard_compare_date(BACNET_DATE *date1, BACNET_DATE *date2) { int diff = 0; @@ -404,9 +363,7 @@ int datetime_wildcard_compare_date( return diff; } -int datetime_wildcard_compare_time( - BACNET_TIME * time1, - BACNET_TIME * time2) +int datetime_wildcard_compare_time(BACNET_TIME *time1, BACNET_TIME *time2) { int diff = 0; @@ -435,27 +392,21 @@ int datetime_wildcard_compare_time( return diff; } -int datetime_wildcard_compare( - BACNET_DATE_TIME * datetime1, - BACNET_DATE_TIME * datetime2) +int datetime_wildcard_compare(BACNET_DATE_TIME *datetime1, + BACNET_DATE_TIME *datetime2) { int diff = 0; - diff = datetime_wildcard_compare_date( - &datetime1->date, - &datetime2->date); + diff = datetime_wildcard_compare_date(&datetime1->date, &datetime2->date); if (diff == 0) { - diff = datetime_wildcard_compare_time( - &datetime1->time, - &datetime2->time); + diff = + datetime_wildcard_compare_time(&datetime1->time, &datetime2->time); } return diff; } -void datetime_copy_date( - BACNET_DATE * dest_date, - BACNET_DATE * src_date) +void datetime_copy_date(BACNET_DATE *dest_date, BACNET_DATE *src_date) { if (dest_date && src_date) { dest_date->year = src_date->year; @@ -465,9 +416,7 @@ void datetime_copy_date( } } -void datetime_copy_time( - BACNET_TIME * dest_time, - BACNET_TIME * src_time) +void datetime_copy_time(BACNET_TIME *dest_time, BACNET_TIME *src_time) { if (dest_time && src_time) { dest_time->hour = src_time->hour; @@ -477,19 +426,15 @@ void datetime_copy_time( } } -void datetime_copy( - BACNET_DATE_TIME * dest_datetime, - BACNET_DATE_TIME * src_datetime) +void datetime_copy(BACNET_DATE_TIME *dest_datetime, + BACNET_DATE_TIME *src_datetime) { datetime_copy_time(&dest_datetime->time, &src_datetime->time); datetime_copy_date(&dest_datetime->date, &src_datetime->date); } -void datetime_set_date( - BACNET_DATE * bdate, - uint16_t year, - uint8_t month, - uint8_t day) +void datetime_set_date(BACNET_DATE *bdate, uint16_t year, uint8_t month, + uint8_t day) { if (bdate) { bdate->year = year; @@ -499,12 +444,8 @@ void datetime_set_date( } } -void datetime_set_time( - BACNET_TIME * btime, - uint8_t hour, - uint8_t minute, - uint8_t seconds, - uint8_t hundredths) +void datetime_set_time(BACNET_TIME *btime, uint8_t hour, uint8_t minute, + uint8_t seconds, uint8_t hundredths) { if (btime) { btime->hour = hour; @@ -514,10 +455,8 @@ void datetime_set_time( } } -void datetime_set( - BACNET_DATE_TIME * bdatetime, - BACNET_DATE * bdate, - BACNET_TIME * btime) +void datetime_set(BACNET_DATE_TIME *bdatetime, BACNET_DATE *bdate, + BACNET_TIME *btime) { if (bdate && btime && bdatetime) { bdatetime->time.hour = btime->hour; @@ -531,15 +470,9 @@ void datetime_set( } } -void datetime_set_values( - BACNET_DATE_TIME * bdatetime, - uint16_t year, - uint8_t month, - uint8_t day, - uint8_t hour, - uint8_t minute, - uint8_t seconds, - uint8_t hundredths) +void datetime_set_values(BACNET_DATE_TIME *bdatetime, uint16_t year, + uint8_t month, uint8_t day, uint8_t hour, + uint8_t minute, uint8_t seconds, uint8_t hundredths) { if (bdatetime) { bdatetime->date.year = year; @@ -553,33 +486,27 @@ void datetime_set_values( } } -static uint32_t seconds_since_midnight( - uint8_t hours, - uint8_t minutes, - uint8_t seconds) +static uint32_t seconds_since_midnight(uint8_t hours, uint8_t minutes, + uint8_t seconds) { return ((hours * 60 * 60) + (minutes * 60) + seconds); } -static uint16_t minutes_since_midnight( - uint8_t hours, - uint8_t minutes) +static uint16_t minutes_since_midnight(uint8_t hours, uint8_t minutes) { return ((hours * 60) + minutes); } -static void seconds_since_midnight_into_hms( - uint32_t seconds, - uint8_t * pHours, - uint8_t * pMinutes, - uint8_t * pSeconds) +static void seconds_since_midnight_into_hms(uint32_t seconds, uint8_t *pHours, + uint8_t *pMinutes, + uint8_t *pSeconds) { uint8_t hour = 0; uint8_t minute = 0; - hour = (uint8_t) (seconds / (60 * 60)); + hour = (uint8_t)(seconds / (60 * 60)); seconds -= (hour * 60 * 60); - minute = (uint8_t) (seconds / 60); + minute = (uint8_t)(seconds / 60); seconds -= (minute * 60); if (pHours) @@ -587,7 +514,7 @@ static void seconds_since_midnight_into_hms( if (pMinutes) *pMinutes = minute; if (pSeconds) - *pSeconds = (uint8_t) seconds; + *pSeconds = (uint8_t)seconds; } /** Calculates the number of seconds since midnight @@ -596,16 +523,12 @@ static void seconds_since_midnight_into_hms( * * @return seconds since midnight */ -uint32_t datetime_seconds_since_midnight( - BACNET_TIME * btime) +uint32_t datetime_seconds_since_midnight(BACNET_TIME *btime) { uint32_t seconds = 0; if (btime) { - seconds = seconds_since_midnight( - btime->hour, - btime->min, - btime->sec); + seconds = seconds_since_midnight(btime->hour, btime->min, btime->sec); } return seconds; @@ -617,15 +540,12 @@ uint32_t datetime_seconds_since_midnight( * * @return minutes since midnight */ -uint16_t datetime_minutes_since_midnight( - BACNET_TIME * btime) +uint16_t datetime_minutes_since_midnight(BACNET_TIME *btime) { uint32_t minutes = 0; if (btime) { - minutes = minutes_since_midnight( - btime->hour, - btime->min); + minutes = minutes_since_midnight(btime->hour, btime->min); } return minutes; @@ -636,9 +556,7 @@ uint16_t datetime_minutes_since_midnight( * @param bdatetime [in] the starting date and time * @param minutes [in] number of minutes to add or subtract from the time */ -void datetime_add_minutes( - BACNET_DATE_TIME * bdatetime, - int32_t minutes) +void datetime_add_minutes(BACNET_DATE_TIME *bdatetime, int32_t minutes) { uint32_t bdatetime_minutes = 0; uint32_t bdatetime_days = 0; @@ -647,7 +565,8 @@ void datetime_add_minutes( /* convert bdatetime to seconds and days */ bdatetime_minutes = seconds_since_midnight(bdatetime->time.hour, bdatetime->time.min, - bdatetime->time.sec) / 60; + bdatetime->time.sec) / + 60; bdatetime_days = datetime_days_since_epoch(&bdatetime->date); /* more minutes than in a day? */ @@ -678,13 +597,13 @@ void datetime_add_minutes( /* convert bdatetime from seconds and days */ seconds_since_midnight_into_hms(bdatetime_minutes * 60, - &bdatetime->time.hour, &bdatetime->time.min, NULL); + &bdatetime->time.hour, &bdatetime->time.min, + NULL); datetime_days_since_epoch_into_date(bdatetime_days, &bdatetime->date); } /* Returns true if year is a wildcard */ -bool datetime_wildcard_year( - BACNET_DATE *bdate) +bool datetime_wildcard_year(BACNET_DATE *bdate) { bool wildcard_present = false; @@ -698,8 +617,7 @@ bool datetime_wildcard_year( } /* Sets the year as a wildcard */ -void datetime_wildcard_year_set( - BACNET_DATE *bdate) +void datetime_wildcard_year_set(BACNET_DATE *bdate) { if (bdate) { bdate->year = BACNET_EPOCH_YEAR + 0xFF; @@ -707,8 +625,7 @@ void datetime_wildcard_year_set( } /* Returns true if month is a wildcard */ -bool datetime_wildcard_month( - BACNET_DATE *bdate) +bool datetime_wildcard_month(BACNET_DATE *bdate) { bool wildcard_present = false; @@ -722,8 +639,7 @@ bool datetime_wildcard_month( } /* Sets the month as a wildcard */ -void datetime_wildcard_month_set( - BACNET_DATE *bdate) +void datetime_wildcard_month_set(BACNET_DATE *bdate) { if (bdate) { bdate->month = 0xFF; @@ -731,8 +647,7 @@ void datetime_wildcard_month_set( } /* Returns true if day is a wildcard */ -bool datetime_wildcard_day( - BACNET_DATE *bdate) +bool datetime_wildcard_day(BACNET_DATE *bdate) { bool wildcard_present = false; @@ -746,8 +661,7 @@ bool datetime_wildcard_day( } /* Sets the day as a wildcard */ -void datetime_wildcard_day_set( - BACNET_DATE *bdate) +void datetime_wildcard_day_set(BACNET_DATE *bdate) { if (bdate) { bdate->day = 0xFF; @@ -755,8 +669,7 @@ void datetime_wildcard_day_set( } /* Returns true if weekday is a wildcard */ -bool datetime_wildcard_weekday( - BACNET_DATE *bdate) +bool datetime_wildcard_weekday(BACNET_DATE *bdate) { bool wildcard_present = false; @@ -770,8 +683,7 @@ bool datetime_wildcard_weekday( } /* Sets the weekday as a wildcard */ -void datetime_wildcard_weekday_set( - BACNET_DATE *bdate) +void datetime_wildcard_weekday_set(BACNET_DATE *bdate) { if (bdate) { bdate->wday = 0xFF; @@ -779,8 +691,7 @@ void datetime_wildcard_weekday_set( } /* Returns true if hour is a wildcard */ -bool datetime_wildcard_hour( - BACNET_TIME *btime) +bool datetime_wildcard_hour(BACNET_TIME *btime) { bool wildcard_present = false; @@ -794,8 +705,7 @@ bool datetime_wildcard_hour( } /* Sets the hour as a wildcard */ -void datetime_wildcard_hour_set( - BACNET_TIME *btime) +void datetime_wildcard_hour_set(BACNET_TIME *btime) { if (btime) { btime->hour = 0xFF; @@ -803,8 +713,7 @@ void datetime_wildcard_hour_set( } /* Returns true if minute is a wildcard */ -bool datetime_wildcard_minute( - BACNET_TIME *btime) +bool datetime_wildcard_minute(BACNET_TIME *btime) { bool wildcard_present = false; @@ -818,8 +727,7 @@ bool datetime_wildcard_minute( } /* Sets the minute as a wildcard */ -void datetime_wildcard_minute_set( - BACNET_TIME *btime) +void datetime_wildcard_minute_set(BACNET_TIME *btime) { if (btime) { btime->min = 0xFF; @@ -827,8 +735,7 @@ void datetime_wildcard_minute_set( } /* Returns true if seconds is wildcard */ -bool datetime_wildcard_second( - BACNET_TIME *btime) +bool datetime_wildcard_second(BACNET_TIME *btime) { bool wildcard_present = false; @@ -842,8 +749,7 @@ bool datetime_wildcard_second( } /* Sets the seconds as a wildcard */ -void datetime_wildcard_second_set( - BACNET_TIME *btime) +void datetime_wildcard_second_set(BACNET_TIME *btime) { if (btime) { btime->sec = 0xFF; @@ -851,8 +757,7 @@ void datetime_wildcard_second_set( } /* Returns true if hundredths is a wildcard */ -bool datetime_wildcard_hundredths( - BACNET_TIME *btime) +bool datetime_wildcard_hundredths(BACNET_TIME *btime) { bool wildcard_present = false; @@ -866,16 +771,14 @@ bool datetime_wildcard_hundredths( } /* Sets the hundredths as a wildcard */ -void datetime_wildcard_hundredths_set( - BACNET_TIME *btime) +void datetime_wildcard_hundredths_set(BACNET_TIME *btime) { if (btime) { btime->hundredths = 0xFF; } } -bool datetime_wildcard( - BACNET_DATE_TIME * bdatetime) +bool datetime_wildcard(BACNET_DATE_TIME *bdatetime) { bool wildcard_present = false; @@ -899,8 +802,7 @@ bool datetime_wildcard( * on it's own. Also checks for special day and month values. Used in * trendlog object. */ -bool datetime_wildcard_present( - BACNET_DATE_TIME * bdatetime) +bool datetime_wildcard_present(BACNET_DATE_TIME *bdatetime) { bool wildcard_present = false; @@ -918,8 +820,7 @@ bool datetime_wildcard_present( return wildcard_present; } -void datetime_date_wildcard_set( - BACNET_DATE * bdate) +void datetime_date_wildcard_set(BACNET_DATE *bdate) { if (bdate) { bdate->year = BACNET_EPOCH_YEAR + 0xFF; @@ -929,8 +830,7 @@ void datetime_date_wildcard_set( } } -void datetime_time_wildcard_set( - BACNET_TIME * btime) +void datetime_time_wildcard_set(BACNET_TIME *btime) { if (btime) { btime->hour = 0xFF; @@ -940,8 +840,7 @@ void datetime_time_wildcard_set( } } -void datetime_wildcard_set( - BACNET_DATE_TIME * bdatetime) +void datetime_wildcard_set(BACNET_DATE_TIME *bdatetime) { if (bdatetime) { datetime_date_wildcard_set(&bdatetime->date); @@ -949,14 +848,11 @@ void datetime_wildcard_set( } } -int bacapp_encode_datetime( - uint8_t * apdu, - BACNET_DATE_TIME * value) +int bacapp_encode_datetime(uint8_t *apdu, BACNET_DATE_TIME *value) { int len = 0; int apdu_len = 0; - if (apdu && value) { len = encode_application_date(&apdu[0], &value->date); apdu_len += len; @@ -967,16 +863,12 @@ int bacapp_encode_datetime( return apdu_len; } - -int bacapp_encode_context_datetime( - uint8_t * apdu, - uint8_t tag_number, - BACNET_DATE_TIME * value) +int bacapp_encode_context_datetime(uint8_t *apdu, uint8_t tag_number, + BACNET_DATE_TIME *value) { int len = 0; int apdu_len = 0; - if (apdu && value) { len = encode_opening_tag(&apdu[apdu_len], tag_number); apdu_len += len; @@ -990,21 +882,19 @@ int bacapp_encode_context_datetime( return apdu_len; } -int bacapp_decode_datetime( - uint8_t * apdu, - BACNET_DATE_TIME * value) +int bacapp_decode_datetime(uint8_t *apdu, BACNET_DATE_TIME *value) { int len = 0; int section_len; - if (-1 == (section_len = - decode_application_date(&apdu[len], &value->date))) { + if (-1 == + (section_len = decode_application_date(&apdu[len], &value->date))) { return -1; } len += section_len; - if (-1 == (section_len = - decode_application_time(&apdu[len], &value->time))) { + if (-1 == + (section_len = decode_application_time(&apdu[len], &value->time))) { return -1; } @@ -1013,10 +903,8 @@ int bacapp_decode_datetime( return len; } -int bacapp_decode_context_datetime( - uint8_t * apdu, - uint8_t tag_number, - BACNET_DATE_TIME * value) +int bacapp_decode_context_datetime(uint8_t *apdu, uint8_t tag_number, + BACNET_DATE_TIME *value) { int apdu_len = 0; int len; @@ -1046,8 +934,7 @@ int bacapp_decode_context_datetime( #include #include "ctest.h" -static void testBACnetDateTimeWildcard( - Test * pTest) +static void testBACnetDateTimeWildcard(Test *pTest) { BACNET_DATE_TIME bdatetime; bool status = false; @@ -1061,8 +948,7 @@ static void testBACnetDateTimeWildcard( ct_test(pTest, status == true); } -static void testBACnetDateTimeAdd( - Test * pTest) +static void testBACnetDateTimeAdd(Test *pTest) { BACNET_DATE_TIME bdatetime, test_bdatetime; uint32_t minutes = 0; @@ -1105,8 +991,7 @@ static void testBACnetDateTimeAdd( ct_test(pTest, diff == 0); } -static void testBACnetDateTimeSeconds( - Test * pTest) +static void testBACnetDateTimeSeconds(Test *pTest) { uint8_t hour = 0, minute = 0, second = 0; uint8_t test_hour = 0, test_minute = 0, test_second = 0; @@ -1117,18 +1002,16 @@ static void testBACnetDateTimeSeconds( for (second = 0; second < 60; second += 17) { seconds = seconds_since_midnight(hour, minute, second); seconds_since_midnight_into_hms(seconds, &test_hour, - &test_minute, &test_second); + &test_minute, &test_second); test_seconds = - seconds_since_midnight(test_hour, test_minute, - test_second); + seconds_since_midnight(test_hour, test_minute, test_second); ct_test(pTest, seconds == test_seconds); } } } } -static void testBACnetDate( - Test * pTest) +static void testBACnetDate(Test *pTest) { BACNET_DATE bdate1, bdate2; int diff = 0; @@ -1189,8 +1072,7 @@ static void testBACnetDate( return; } -static void testBACnetTime( - Test * pTest) +static void testBACnetTime(Test *pTest) { BACNET_TIME btime1, btime2; int diff = 0; @@ -1239,8 +1121,7 @@ static void testBACnetTime( return; } -static void testBACnetDateTime( - Test * pTest) +static void testBACnetDateTime(Test *pTest) { BACNET_DATE_TIME bdatetime1, bdatetime2; BACNET_DATE bdate; @@ -1303,12 +1184,10 @@ static void testBACnetDateTime( diff = datetime_compare(&bdatetime1, &bdatetime2); ct_test(pTest, diff > 0); - return; } -static void testWildcardDateTime( - Test * pTest) +static void testWildcardDateTime(Test *pTest) { BACNET_DATE_TIME bdatetime1, bdatetime2; BACNET_DATE bdate; @@ -1330,8 +1209,7 @@ static void testWildcardDateTime( return; } -static void testDayOfYear( - Test * pTest) +static void testDayOfYear(Test *pTest) { uint32_t days = 0; uint8_t month = 0, test_month = 0; @@ -1368,8 +1246,7 @@ static void testDayOfYear( } } -static void testDateEpoch( - Test * pTest) +static void testDateEpoch(Test *pTest) { uint32_t days = 0; uint16_t year = 0, test_year = 0; @@ -1383,13 +1260,12 @@ static void testDateEpoch( ct_test(pTest, month == 1); ct_test(pTest, day == 1); - - for (year = BACNET_EPOCH_YEAR; year < (BACNET_EPOCH_YEAR+0xFF); year++) { + for (year = BACNET_EPOCH_YEAR; year < (BACNET_EPOCH_YEAR + 0xFF); year++) { for (month = 1; month <= 12; month++) { for (day = 1; day <= datetime_month_days(year, month); day++) { days = days_since_epoch(year, month, day); - days_since_epoch_into_ymd(days, - &test_year, &test_month, &test_day); + days_since_epoch_into_ymd(days, &test_year, &test_month, + &test_day); ct_test(pTest, year == test_year); ct_test(pTest, month == test_month); ct_test(pTest, day == test_day); @@ -1398,8 +1274,7 @@ static void testDateEpoch( } } -static void testBACnetDayOfWeek( - Test * pTest) +static void testBACnetDayOfWeek(Test *pTest) { uint8_t dow = 0; @@ -1427,8 +1302,7 @@ static void testBACnetDayOfWeek( ct_test(pTest, dow == 3); } -static void testDatetimeCodec( - Test * pTest) +static void testDatetimeCodec(Test *pTest) { uint8_t apdu[MAX_APDU]; BACNET_DATE_TIME datetimeIn; @@ -1460,11 +1334,9 @@ static void testDatetimeCodec( ct_test(pTest, datetimeIn.time.min == datetimeOut.time.min); ct_test(pTest, datetimeIn.time.sec == datetimeOut.time.sec); ct_test(pTest, datetimeIn.time.hundredths == datetimeOut.time.hundredths); - } -void testDateTime( - Test * pTest) +void testDateTime(Test *pTest) { bool rc; @@ -1494,8 +1366,7 @@ void testDateTime( } #ifdef TEST_DATE_TIME -int main( - void) +int main(void) { Test *pTest; @@ -1503,12 +1374,11 @@ int main( testDateTime(pTest); ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; } - #endif /* TEST_DATE_TIME */ #endif /* TEST */ diff --git a/src/dcc.c b/src/dcc.c index 481d03de..ab017796 100644 --- a/src/dcc.c +++ b/src/dcc.c @@ -49,14 +49,12 @@ static BACNET_COMMUNICATION_ENABLE_DISABLE DCC_Enable_Disable = COMMUNICATION_ENABLE; /* password is optionally supported */ -BACNET_COMMUNICATION_ENABLE_DISABLE dcc_enable_status( - void) +BACNET_COMMUNICATION_ENABLE_DISABLE dcc_enable_status(void) { return DCC_Enable_Disable; } -bool dcc_communication_enabled( - void) +bool dcc_communication_enabled(void) { return (DCC_Enable_Disable == COMMUNICATION_ENABLE); } @@ -64,8 +62,7 @@ bool dcc_communication_enabled( /* When network communications are completely disabled, only DeviceCommunicationControl and ReinitializeDevice APDUs shall be processed and no messages shall be initiated.*/ -bool dcc_communication_disabled( - void) +bool dcc_communication_disabled(void) { return (DCC_Enable_Disable == COMMUNICATION_DISABLE); } @@ -79,23 +76,20 @@ bool dcc_communication_disabled( for any Who-Is request that is received if and only if the Who-Is request does not contain an address range or the device is included in the address range. */ -bool dcc_communication_initiation_disabled( - void) +bool dcc_communication_initiation_disabled(void) { return (DCC_Enable_Disable == COMMUNICATION_DISABLE_INITIATION); } /* note: 0 indicates either expired, or infinite duration */ -uint32_t dcc_duration_seconds( - void) +uint32_t dcc_duration_seconds(void) { return DCC_Time_Duration_Seconds; } /* called every second or so. If more than one second, then seconds should be the number of seconds to tick away */ -void dcc_timer_seconds( - uint32_t seconds) +void dcc_timer_seconds(uint32_t seconds) { if (DCC_Time_Duration_Seconds) { if (DCC_Time_Duration_Seconds > seconds) @@ -108,9 +102,8 @@ void dcc_timer_seconds( } } -bool dcc_set_status_duration( - BACNET_COMMUNICATION_ENABLE_DISABLE status, - uint16_t minutes) +bool dcc_set_status_duration(BACNET_COMMUNICATION_ENABLE_DISABLE status, + uint16_t minutes) { bool valid = false; @@ -130,15 +123,13 @@ bool dcc_set_status_duration( #if BACNET_SVC_DCC_A /* encode service */ -int dcc_encode_apdu( - uint8_t * apdu, - uint8_t invoke_id, - uint16_t timeDuration, /* 0=optional */ - BACNET_COMMUNICATION_ENABLE_DISABLE enable_disable, - BACNET_CHARACTER_STRING * password) -{ /* NULL=optional */ - int len = 0; /* length of each encoding */ - int apdu_len = 0; /* total length of the apdu, return value */ +int dcc_encode_apdu(uint8_t *apdu, uint8_t invoke_id, + uint16_t timeDuration, /* 0=optional */ + BACNET_COMMUNICATION_ENABLE_DISABLE enable_disable, + BACNET_CHARACTER_STRING *password) +{ /* NULL=optional */ + int len = 0; /* length of each encoding */ + int apdu_len = 0; /* total length of the apdu, return value */ if (apdu) { apdu[0] = PDU_TYPE_CONFIRMED_SERVICE_REQUEST; @@ -157,8 +148,7 @@ int dcc_encode_apdu( /* optional password */ if (password) { /* FIXME: must be at least 1 character, limited to 20 characters */ - len = - encode_context_character_string(&apdu[apdu_len], 2, password); + len = encode_context_character_string(&apdu[apdu_len], 2, password); apdu_len += len; } } @@ -169,11 +159,9 @@ int dcc_encode_apdu( /* decode the service request only */ int dcc_decode_service_request( - uint8_t * apdu, - unsigned apdu_len, - uint16_t * timeDuration, - BACNET_COMMUNICATION_ENABLE_DISABLE * enable_disable, - BACNET_CHARACTER_STRING * password) + uint8_t *apdu, unsigned apdu_len, uint16_t *timeDuration, + BACNET_COMMUNICATION_ENABLE_DISABLE *enable_disable, + BACNET_CHARACTER_STRING *password) { unsigned len = 0; uint8_t tag_number = 0; @@ -186,12 +174,11 @@ int dcc_decode_service_request( * But if not included, take it as indefinite, * which we return as "very large" */ if (decode_is_context_tag(&apdu[len], 0)) { - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value_type); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value_type); len += decode_unsigned(&apdu[len], len_value_type, &value32); if (timeDuration) { - *timeDuration = (uint16_t) value32; + *timeDuration = (uint16_t)value32; } } else if (timeDuration) { /* zero indicates infinite duration and @@ -202,21 +189,19 @@ int dcc_decode_service_request( if (!decode_is_context_tag(&apdu[len], 1)) { return -1; } - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value_type); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value_type); len += decode_enumerated(&apdu[len], len_value_type, &value32); if (enable_disable) { - *enable_disable = (BACNET_COMMUNICATION_ENABLE_DISABLE) value32; + *enable_disable = (BACNET_COMMUNICATION_ENABLE_DISABLE)value32; } /* Tag 2: password --optional-- */ if (len < apdu_len) { if (!decode_is_context_tag(&apdu[len], 2)) { return -1; } - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value_type); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value_type); len += decode_character_string(&apdu[len], len_value_type, password); } else if (password) { @@ -224,7 +209,7 @@ int dcc_decode_service_request( } } - return (int) len; + return (int)len; } #ifdef TEST @@ -232,13 +217,10 @@ int dcc_decode_service_request( #include #include "ctest.h" -int dcc_decode_apdu( - uint8_t * apdu, - unsigned apdu_len, - uint8_t * invoke_id, - uint16_t * timeDuration, - BACNET_COMMUNICATION_ENABLE_DISABLE * enable_disable, - BACNET_CHARACTER_STRING * password) +int dcc_decode_apdu(uint8_t *apdu, unsigned apdu_len, uint8_t *invoke_id, + uint16_t *timeDuration, + BACNET_COMMUNICATION_ENABLE_DISABLE *enable_disable, + BACNET_CHARACTER_STRING *password) { int len = 0; unsigned offset = 0; @@ -249,7 +231,7 @@ int dcc_decode_apdu( if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST) return -1; /* apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU); */ - *invoke_id = apdu[2]; /* invoke id - filled in by net layer */ + *invoke_id = apdu[2]; /* invoke id - filled in by net layer */ if (apdu[3] != SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL) return -1; offset = 4; @@ -257,20 +239,18 @@ int dcc_decode_apdu( if (apdu_len > offset) { len = dcc_decode_service_request(&apdu[offset], apdu_len - offset, - timeDuration, enable_disable, password); + timeDuration, enable_disable, password); } return len; } void test_DeviceCommunicationControlData( - Test * pTest, - uint8_t invoke_id, - uint16_t timeDuration, + Test *pTest, uint8_t invoke_id, uint16_t timeDuration, BACNET_COMMUNICATION_ENABLE_DISABLE enable_disable, - BACNET_CHARACTER_STRING * password) + BACNET_CHARACTER_STRING *password) { - uint8_t apdu[480] = { 0 }; + uint8_t apdu[480] = {0}; int len = 0; int apdu_len = 0; uint8_t test_invoke_id = 0; @@ -278,15 +258,14 @@ void test_DeviceCommunicationControlData( BACNET_COMMUNICATION_ENABLE_DISABLE test_enable_disable; BACNET_CHARACTER_STRING test_password; - len = - dcc_encode_apdu(&apdu[0], invoke_id, timeDuration, enable_disable, - password); + len = dcc_encode_apdu(&apdu[0], invoke_id, timeDuration, enable_disable, + password); ct_test(pTest, len != 0); apdu_len = len; len = - dcc_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, - &test_timeDuration, &test_enable_disable, &test_password); + dcc_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, &test_timeDuration, + &test_enable_disable, &test_password); ct_test(pTest, len != -1); ct_test(pTest, test_invoke_id == invoke_id); ct_test(pTest, test_timeDuration == timeDuration); @@ -294,8 +273,7 @@ void test_DeviceCommunicationControlData( ct_test(pTest, characterstring_same(&test_password, password)); } -void test_DeviceCommunicationControl( - Test * pTest) +void test_DeviceCommunicationControl(Test *pTest) { uint8_t invoke_id = 128; uint16_t timeDuration = 0; @@ -306,19 +284,18 @@ void test_DeviceCommunicationControl( enable_disable = COMMUNICATION_DISABLE_INITIATION; characterstring_init_ansi(&password, "John 3:16"); test_DeviceCommunicationControlData(pTest, invoke_id, timeDuration, - enable_disable, &password); + enable_disable, &password); timeDuration = 12345; enable_disable = COMMUNICATION_DISABLE; test_DeviceCommunicationControlData(pTest, invoke_id, timeDuration, - enable_disable, NULL); + enable_disable, NULL); return; } #ifdef TEST_DEVICE_COMMUNICATION_CONTROL -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -330,7 +307,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/src/debug.c b/src/debug.c index 430d7904..992a80e2 100644 --- a/src/debug.c +++ b/src/debug.c @@ -32,19 +32,17 @@ ------------------------------------------- ####COPYRIGHTEND####*/ -#include /* for standard integer types uint8_t etc. */ -#include /* for the standard bool type. */ -#include /* Standard I/O */ -#include /* Standard Library */ +#include /* for standard integer types uint8_t etc. */ +#include /* for the standard bool type. */ +#include /* Standard I/O */ +#include /* Standard Library */ #include #include "debug.h" /** @file debug.c Debug print function */ #if DEBUG_ENABLED -void debug_printf( - const char *format, - ...) +void debug_printf(const char *format, ...) { va_list ap; @@ -56,9 +54,7 @@ void debug_printf( return; } #else -void debug_printf( - const char *format, - ...) +void debug_printf(const char *format, ...) { format = format; } diff --git a/src/event.c b/src/event.c index f0d47b40..bc6258a4 100644 --- a/src/event.c +++ b/src/event.c @@ -39,17 +39,15 @@ /** @file event.c Encode/Decode Event Notifications */ -int uevent_notify_encode_apdu( - uint8_t * apdu, - BACNET_EVENT_NOTIFICATION_DATA * data) +int uevent_notify_encode_apdu(uint8_t *apdu, + BACNET_EVENT_NOTIFICATION_DATA *data) { - int len = 0; /* length of each encoding */ - int apdu_len = 0; /* total length of the apdu, return value */ - + int len = 0; /* length of each encoding */ + int apdu_len = 0; /* total length of the apdu, return value */ if (apdu) { apdu[0] = PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST; - apdu[1] = SERVICE_UNCONFIRMED_EVENT_NOTIFICATION; /* service choice */ + apdu[1] = SERVICE_UNCONFIRMED_EVENT_NOTIFICATION; /* service choice */ apdu_len = 2; len += event_notify_encode_service_request(&apdu[apdu_len], data); @@ -64,13 +62,11 @@ int uevent_notify_encode_apdu( return apdu_len; } -int cevent_notify_encode_apdu( - uint8_t * apdu, - uint8_t invoke_id, - BACNET_EVENT_NOTIFICATION_DATA * data) +int cevent_notify_encode_apdu(uint8_t *apdu, uint8_t invoke_id, + BACNET_EVENT_NOTIFICATION_DATA *data) { - int len = 0; /* length of each encoding */ - int apdu_len = 0; /* total length of the apdu, return value */ + int len = 0; /* length of each encoding */ + int apdu_len = 0; /* total length of the apdu, return value */ if (apdu) { apdu[0] = PDU_TYPE_CONFIRMED_SERVICE_REQUEST; @@ -91,45 +87,39 @@ int cevent_notify_encode_apdu( return apdu_len; } -int event_notify_encode_service_request( - uint8_t * apdu, - BACNET_EVENT_NOTIFICATION_DATA * data) +int event_notify_encode_service_request(uint8_t *apdu, + BACNET_EVENT_NOTIFICATION_DATA *data) { - int len = 0; /* length of each encoding */ - int apdu_len = 0; /* total length of the apdu, return value */ + int len = 0; /* length of each encoding */ + int apdu_len = 0; /* total length of the apdu, return value */ if (apdu) { /* tag 0 - processIdentifier */ - len = - encode_context_unsigned(&apdu[apdu_len], 0, - data->processIdentifier); + len = encode_context_unsigned(&apdu[apdu_len], 0, + data->processIdentifier); apdu_len += len; /* tag 1 - initiatingObjectIdentifier */ - len = - encode_context_object_id(&apdu[apdu_len], 1, - (int) data->initiatingObjectIdentifier.type, + len = encode_context_object_id( + &apdu[apdu_len], 1, (int)data->initiatingObjectIdentifier.type, data->initiatingObjectIdentifier.instance); apdu_len += len; /* tag 2 - eventObjectIdentifier */ - len = - encode_context_object_id(&apdu[apdu_len], 2, - (int) data->eventObjectIdentifier.type, - data->eventObjectIdentifier.instance); + len = encode_context_object_id(&apdu[apdu_len], 2, + (int)data->eventObjectIdentifier.type, + data->eventObjectIdentifier.instance); apdu_len += len; /* tag 3 - timeStamp */ - len = - bacapp_encode_context_timestamp(&apdu[apdu_len], 3, - &data->timeStamp); + len = bacapp_encode_context_timestamp(&apdu[apdu_len], 3, + &data->timeStamp); apdu_len += len; /* tag 4 - noticicationClass */ - len = - encode_context_unsigned(&apdu[apdu_len], 4, - data->notificationClass); + len = encode_context_unsigned(&apdu[apdu_len], 4, + data->notificationClass); apdu_len += len; /* tag 5 - priority */ @@ -143,9 +133,8 @@ int event_notify_encode_service_request( /* tag 7 - messageText */ if (data->messageText) { - len = - encode_context_character_string(&apdu[apdu_len], 7, - data->messageText); + len = encode_context_character_string(&apdu[apdu_len], 7, + data->messageText); apdu_len += len; } /* tag 8 - notifyType */ @@ -157,15 +146,13 @@ int event_notify_encode_service_request( case NOTIFY_EVENT: /* tag 9 - ackRequired */ - len = - encode_context_boolean(&apdu[apdu_len], 9, - data->ackRequired); + len = encode_context_boolean(&apdu[apdu_len], 9, + data->ackRequired); apdu_len += len; /* tag 10 - fromState */ - len = - encode_context_enumerated(&apdu[apdu_len], 10, - data->fromState); + len = encode_context_enumerated(&apdu[apdu_len], 10, + data->fromState); apdu_len += len; break; @@ -189,16 +176,16 @@ int event_notify_encode_service_request( len = encode_opening_tag(&apdu[apdu_len], 0); apdu_len += len; - len = - encode_context_bitstring(&apdu[apdu_len], 0, - &data->notificationParams. - changeOfBitstring.referencedBitString); + len = encode_context_bitstring( + &apdu[apdu_len], 0, + &data->notificationParams.changeOfBitstring + .referencedBitString); apdu_len += len; - len = - encode_context_bitstring(&apdu[apdu_len], 1, - &data->notificationParams. - changeOfBitstring.statusFlags); + len = encode_context_bitstring( + &apdu[apdu_len], 1, + &data->notificationParams.changeOfBitstring + .statusFlags); apdu_len += len; len = encode_closing_tag(&apdu[apdu_len], 0); @@ -212,18 +199,18 @@ int event_notify_encode_service_request( len = encode_opening_tag(&apdu[apdu_len], 0); apdu_len += len; - len = - bacapp_encode_property_state(&apdu[apdu_len], + len = bacapp_encode_property_state( + &apdu[apdu_len], &data->notificationParams.changeOfState.newState); apdu_len += len; len = encode_closing_tag(&apdu[apdu_len], 0); apdu_len += len; - len = - encode_context_bitstring(&apdu[apdu_len], 1, - &data->notificationParams. - changeOfState.statusFlags); + len = encode_context_bitstring( + &apdu[apdu_len], 1, + &data->notificationParams.changeOfState + .statusFlags); apdu_len += len; len = encode_closing_tag(&apdu[apdu_len], 1); @@ -239,19 +226,18 @@ int event_notify_encode_service_request( switch (data->notificationParams.changeOfValue.tag) { case CHANGE_OF_VALUE_REAL: - len = - encode_context_real(&apdu[apdu_len], 1, - data->notificationParams. - changeOfValue.newValue.changeValue); + len = encode_context_real( + &apdu[apdu_len], 1, + data->notificationParams.changeOfValue + .newValue.changeValue); apdu_len += len; break; case CHANGE_OF_VALUE_BITS: - len = - encode_context_bitstring(&apdu[apdu_len], - 0, - &data->notificationParams. - changeOfValue.newValue.changedBits); + len = encode_context_bitstring( + &apdu[apdu_len], 0, + &data->notificationParams.changeOfValue + .newValue.changedBits); apdu_len += len; break; @@ -262,41 +248,40 @@ int event_notify_encode_service_request( len = encode_closing_tag(&apdu[apdu_len], 0); apdu_len += len; - len = - encode_context_bitstring(&apdu[apdu_len], 1, - &data->notificationParams. - changeOfValue.statusFlags); + len = encode_context_bitstring( + &apdu[apdu_len], 1, + &data->notificationParams.changeOfValue + .statusFlags); apdu_len += len; len = encode_closing_tag(&apdu[apdu_len], 2); apdu_len += len; break; - case EVENT_FLOATING_LIMIT: len = encode_opening_tag(&apdu[apdu_len], 4); apdu_len += len; - len = - encode_context_real(&apdu[apdu_len], 0, - data->notificationParams. - floatingLimit.referenceValue); + len = encode_context_real( + &apdu[apdu_len], 0, + data->notificationParams.floatingLimit + .referenceValue); apdu_len += len; - len = - encode_context_bitstring(&apdu[apdu_len], 1, - &data->notificationParams. - floatingLimit.statusFlags); + len = encode_context_bitstring( + &apdu[apdu_len], 1, + &data->notificationParams.floatingLimit + .statusFlags); apdu_len += len; - len = - encode_context_real(&apdu[apdu_len], 2, - data->notificationParams. - floatingLimit.setPointValue); + len = encode_context_real( + &apdu[apdu_len], 2, + data->notificationParams.floatingLimit + .setPointValue); apdu_len += len; - len = - encode_context_real(&apdu[apdu_len], 3, + len = encode_context_real( + &apdu[apdu_len], 3, data->notificationParams.floatingLimit.errorLimit); apdu_len += len; @@ -304,29 +289,27 @@ int event_notify_encode_service_request( apdu_len += len; break; - case EVENT_OUT_OF_RANGE: len = encode_opening_tag(&apdu[apdu_len], 5); apdu_len += len; - len = - encode_context_real(&apdu[apdu_len], 0, - data->notificationParams. - outOfRange.exceedingValue); + len = encode_context_real( + &apdu[apdu_len], 0, + data->notificationParams.outOfRange.exceedingValue); apdu_len += len; - len = - encode_context_bitstring(&apdu[apdu_len], 1, + len = encode_context_bitstring( + &apdu[apdu_len], 1, &data->notificationParams.outOfRange.statusFlags); apdu_len += len; - len = - encode_context_real(&apdu[apdu_len], 2, + len = encode_context_real( + &apdu[apdu_len], 2, data->notificationParams.outOfRange.deadband); apdu_len += len; - len = - encode_context_real(&apdu[apdu_len], 3, + len = encode_context_real( + &apdu[apdu_len], 3, data->notificationParams.outOfRange.exceededLimit); apdu_len += len; @@ -338,28 +321,28 @@ int event_notify_encode_service_request( len = encode_opening_tag(&apdu[apdu_len], 8); apdu_len += len; - len = - encode_context_enumerated(&apdu[apdu_len], 0, - data->notificationParams. - changeOfLifeSafety.newState); + len = encode_context_enumerated( + &apdu[apdu_len], 0, + data->notificationParams.changeOfLifeSafety + .newState); apdu_len += len; - len = - encode_context_enumerated(&apdu[apdu_len], 1, - data->notificationParams. - changeOfLifeSafety.newMode); + len = encode_context_enumerated( + &apdu[apdu_len], 1, + data->notificationParams.changeOfLifeSafety + .newMode); apdu_len += len; - len = - encode_context_bitstring(&apdu[apdu_len], 2, - &data->notificationParams. - changeOfLifeSafety.statusFlags); + len = encode_context_bitstring( + &apdu[apdu_len], 2, + &data->notificationParams.changeOfLifeSafety + .statusFlags); apdu_len += len; - len = - encode_context_enumerated(&apdu[apdu_len], 3, - data->notificationParams. - changeOfLifeSafety.operationExpected); + len = encode_context_enumerated( + &apdu[apdu_len], 3, + data->notificationParams.changeOfLifeSafety + .operationExpected); apdu_len += len; len = encode_closing_tag(&apdu[apdu_len], 8); @@ -370,23 +353,22 @@ int event_notify_encode_service_request( len = encode_opening_tag(&apdu[apdu_len], 10); apdu_len += len; - len = - bacapp_encode_context_device_obj_property_ref(&apdu - [apdu_len], 0, - &data->notificationParams. - bufferReady.bufferProperty); + len = bacapp_encode_context_device_obj_property_ref( + &apdu[apdu_len], 0, + &data->notificationParams.bufferReady + .bufferProperty); apdu_len += len; - len = - encode_context_unsigned(&apdu[apdu_len], 1, - data->notificationParams. - bufferReady.previousNotification); + len = encode_context_unsigned( + &apdu[apdu_len], 1, + data->notificationParams.bufferReady + .previousNotification); apdu_len += len; - len = - encode_context_unsigned(&apdu[apdu_len], 2, - data->notificationParams. - bufferReady.currentNotification); + len = encode_context_unsigned( + &apdu[apdu_len], 2, + data->notificationParams.bufferReady + .currentNotification); apdu_len += len; len = encode_closing_tag(&apdu[apdu_len], 10); @@ -396,22 +378,22 @@ int event_notify_encode_service_request( len = encode_opening_tag(&apdu[apdu_len], 11); apdu_len += len; - len = - encode_context_unsigned(&apdu[apdu_len], 0, - data->notificationParams. - unsignedRange.exceedingValue); + len = encode_context_unsigned( + &apdu[apdu_len], 0, + data->notificationParams.unsignedRange + .exceedingValue); apdu_len += len; - len = - encode_context_bitstring(&apdu[apdu_len], 1, - &data->notificationParams. - unsignedRange.statusFlags); + len = encode_context_bitstring( + &apdu[apdu_len], 1, + &data->notificationParams.unsignedRange + .statusFlags); apdu_len += len; - len = - encode_context_unsigned(&apdu[apdu_len], 2, - data->notificationParams. - unsignedRange.exceededLimit); + len = encode_context_unsigned( + &apdu[apdu_len], 2, + data->notificationParams.unsignedRange + .exceededLimit); apdu_len += len; len = encode_closing_tag(&apdu[apdu_len], 11); @@ -435,86 +417,78 @@ int event_notify_encode_service_request( return apdu_len; } -int event_notify_decode_service_request( - uint8_t * apdu, - unsigned apdu_len, - BACNET_EVENT_NOTIFICATION_DATA * data) +int event_notify_decode_service_request(uint8_t *apdu, unsigned apdu_len, + BACNET_EVENT_NOTIFICATION_DATA *data) { - int len = 0; /* return value */ + int len = 0; /* return value */ int section_length = 0; uint32_t value = 0; if (apdu_len && data) { /* tag 0 - processIdentifier */ - if ((section_length = - decode_context_unsigned(&apdu[len], 0, - &data->processIdentifier)) == -1) { + if ((section_length = decode_context_unsigned( + &apdu[len], 0, &data->processIdentifier)) == -1) { return -1; } else { len += section_length; } /* tag 1 - initiatingObjectIdentifier */ - if ((section_length = - decode_context_object_id(&apdu[len], 1, - &data->initiatingObjectIdentifier.type, - &data->initiatingObjectIdentifier.instance)) == -1) { + if ((section_length = decode_context_object_id( + &apdu[len], 1, &data->initiatingObjectIdentifier.type, + &data->initiatingObjectIdentifier.instance)) == -1) { return -1; } else { len += section_length; } /* tag 2 - eventObjectIdentifier */ - if ((section_length = - decode_context_object_id(&apdu[len], 2, - &data->eventObjectIdentifier.type, - &data->eventObjectIdentifier.instance)) == -1) { + if ((section_length = decode_context_object_id( + &apdu[len], 2, &data->eventObjectIdentifier.type, + &data->eventObjectIdentifier.instance)) == -1) { return -1; } else { len += section_length; } /* tag 3 - timeStamp */ - if ((section_length = - bacapp_decode_context_timestamp(&apdu[len], 3, - &data->timeStamp)) == -1) { + if ((section_length = bacapp_decode_context_timestamp( + &apdu[len], 3, &data->timeStamp)) == -1) { return -1; } else { len += section_length; } /* tag 4 - noticicationClass */ - if ((section_length = - decode_context_unsigned(&apdu[len], 4, - &data->notificationClass)) == -1) { + if ((section_length = decode_context_unsigned( + &apdu[len], 4, &data->notificationClass)) == -1) { return -1; } else { len += section_length; } /* tag 5 - priority */ - if ((section_length = - decode_context_unsigned(&apdu[len], 5, &value)) == -1) { + if ((section_length = decode_context_unsigned(&apdu[len], 5, &value)) == + -1) { return -1; } else { if (value > 0xff) { return -1; } else { - data->priority = (uint8_t) value; + data->priority = (uint8_t)value; len += section_length; } } /* tag 6 - eventType */ if ((section_length = - decode_context_enumerated(&apdu[len], 6, &value)) == -1) { + decode_context_enumerated(&apdu[len], 6, &value)) == -1) { return -1; } else { - data->eventType = (BACNET_EVENT_TYPE) value; + data->eventType = (BACNET_EVENT_TYPE)value; len += section_length; } /* tag 7 - messageText */ if (decode_is_context_tag(&apdu[len], 7)) { if (data->messageText != NULL) { - if ((section_length = - decode_context_character_string(&apdu[len], 7, - data->messageText)) == -1) { + if ((section_length = decode_context_character_string( + &apdu[len], 7, data->messageText)) == -1) { /*FIXME This is an optional parameter */ return -1; } else { @@ -531,10 +505,10 @@ int event_notify_decode_service_request( /* tag 8 - notifyType */ if ((section_length = - decode_context_enumerated(&apdu[len], 8, &value)) == -1) { + decode_context_enumerated(&apdu[len], 8, &value)) == -1) { return -1; } else { - data->notifyType = (BACNET_NOTIFY_TYPE) value; + data->notifyType = (BACNET_NOTIFY_TYPE)value; len += section_length; } switch (data->notifyType) { @@ -549,12 +523,11 @@ int event_notify_decode_service_request( len += section_length; /* tag 10 - fromState */ - if ((section_length = - decode_context_enumerated(&apdu[len], 10, - &value)) == -1) { + if ((section_length = decode_context_enumerated( + &apdu[len], 10, &value)) == -1) { return -1; } else { - data->fromState = (BACNET_EVENT_STATE) value; + data->fromState = (BACNET_EVENT_STATE)value; len += section_length; } break; @@ -564,14 +537,13 @@ int event_notify_decode_service_request( case NOTIFY_ACK_NOTIFICATION: default: break; - } /* tag 11 - toState */ if ((section_length = - decode_context_enumerated(&apdu[len], 11, &value)) == -1) { + decode_context_enumerated(&apdu[len], 11, &value)) == -1) { return -1; } else { - data->toState = (BACNET_EVENT_STATE) value; + data->toState = (BACNET_EVENT_STATE)value; len += section_length; } /* tag 12 - eventValues */ @@ -584,7 +556,7 @@ int event_notify_decode_service_request( return -1; } if (decode_is_opening_tag_number(&apdu[len], - (uint8_t) data->eventType)) { + (uint8_t)data->eventType)) { len++; } else { return -1; @@ -592,20 +564,19 @@ int event_notify_decode_service_request( switch (data->eventType) { case EVENT_CHANGE_OF_BITSTRING: - if (-1 == (section_length = - decode_context_bitstring(&apdu[len], 0, - &data-> - notificationParams.changeOfBitstring. - referencedBitString))) { + if (-1 == + (section_length = decode_context_bitstring( + &apdu[len], 0, + &data->notificationParams.changeOfBitstring + .referencedBitString))) { return -1; } len += section_length; - if (-1 == (section_length = - decode_context_bitstring(&apdu[len], 1, - &data-> - notificationParams.changeOfBitstring. - statusFlags))) { + if (-1 == (section_length = decode_context_bitstring( + &apdu[len], 1, + &data->notificationParams + .changeOfBitstring.statusFlags))) { return -1; } len += section_length; @@ -614,18 +585,18 @@ int event_notify_decode_service_request( case EVENT_CHANGE_OF_STATE: if (-1 == (section_length = - bacapp_decode_context_property_state(&apdu - [len], 0, - &data->notificationParams. - changeOfState.newState))) { + bacapp_decode_context_property_state( + &apdu[len], 0, + &data->notificationParams + .changeOfState.newState))) { return -1; } len += section_length; - if (-1 == (section_length = - decode_context_bitstring(&apdu[len], 1, - &data->notificationParams. - changeOfState.statusFlags))) { + if (-1 == (section_length = decode_context_bitstring( + &apdu[len], 1, + &data->notificationParams.changeOfState + .statusFlags))) { return -1; } len += section_length; @@ -639,26 +610,25 @@ int event_notify_decode_service_request( len++; if (decode_is_context_tag(&apdu[len], - CHANGE_OF_VALUE_BITS)) { - - if (-1 == (section_length = - decode_context_bitstring(&apdu[len], 0, - &data-> - notificationParams.changeOfValue. - newValue.changedBits))) { + CHANGE_OF_VALUE_BITS)) { + if (-1 == + (section_length = decode_context_bitstring( + &apdu[len], 0, + &data->notificationParams.changeOfValue + .newValue.changedBits))) { return -1; } len += section_length; data->notificationParams.changeOfValue.tag = CHANGE_OF_VALUE_BITS; - } else if (decode_is_context_tag(&apdu[len], - CHANGE_OF_VALUE_REAL)) { - if (-1 == (section_length = - decode_context_real(&apdu[len], 1, - &data-> - notificationParams.changeOfValue. - newValue.changeValue))) { + } else if (decode_is_context_tag( + &apdu[len], CHANGE_OF_VALUE_REAL)) { + if (-1 == + (section_length = decode_context_real( + &apdu[len], 1, + &data->notificationParams.changeOfValue + .newValue.changeValue))) { return -1; } @@ -673,170 +643,165 @@ int event_notify_decode_service_request( } len++; - - if (-1 == (section_length = - decode_context_bitstring(&apdu[len], 1, - &data->notificationParams. - changeOfValue.statusFlags))) { + if (-1 == (section_length = decode_context_bitstring( + &apdu[len], 1, + &data->notificationParams.changeOfValue + .statusFlags))) { return -1; } len += section_length; break; case EVENT_FLOATING_LIMIT: - if (-1 == (section_length = - decode_context_real(&apdu[len], 0, - &data->notificationParams. - floatingLimit.referenceValue))) { + if (-1 == (section_length = decode_context_real( + &apdu[len], 0, + &data->notificationParams.floatingLimit + .referenceValue))) { return -1; } len += section_length; - if (-1 == (section_length = - decode_context_bitstring(&apdu[len], 1, - &data->notificationParams. - floatingLimit.statusFlags))) { + if (-1 == (section_length = decode_context_bitstring( + &apdu[len], 1, + &data->notificationParams.floatingLimit + .statusFlags))) { return -1; } len += section_length; - if (-1 == (section_length = - decode_context_real(&apdu[len], 2, - &data->notificationParams. - floatingLimit.setPointValue))) { + if (-1 == (section_length = decode_context_real( + &apdu[len], 2, + &data->notificationParams.floatingLimit + .setPointValue))) { return -1; } len += section_length; - if (-1 == (section_length = - decode_context_real(&apdu[len], 3, - &data->notificationParams. - floatingLimit.errorLimit))) { + if (-1 == (section_length = decode_context_real( + &apdu[len], 3, + &data->notificationParams.floatingLimit + .errorLimit))) { return -1; } len += section_length; break; case EVENT_OUT_OF_RANGE: - if (-1 == (section_length = - decode_context_real(&apdu[len], 0, - &data->notificationParams. - outOfRange.exceedingValue))) { + if (-1 == (section_length = decode_context_real( + &apdu[len], 0, + &data->notificationParams.outOfRange + .exceedingValue))) { return -1; } len += section_length; - if (-1 == (section_length = - decode_context_bitstring(&apdu[len], 1, - &data->notificationParams. - outOfRange.statusFlags))) { + if (-1 == (section_length = decode_context_bitstring( + &apdu[len], 1, + &data->notificationParams.outOfRange + .statusFlags))) { return -1; } len += section_length; - if (-1 == (section_length = - decode_context_real(&apdu[len], 2, - &data->notificationParams. - outOfRange.deadband))) { + if (-1 == (section_length = decode_context_real( + &apdu[len], 2, + &data->notificationParams.outOfRange + .deadband))) { return -1; } len += section_length; - if (-1 == (section_length = - decode_context_real(&apdu[len], 3, - &data->notificationParams. - outOfRange.exceededLimit))) { + if (-1 == (section_length = decode_context_real( + &apdu[len], 3, + &data->notificationParams.outOfRange + .exceededLimit))) { return -1; } len += section_length; break; - case EVENT_CHANGE_OF_LIFE_SAFETY: - if (-1 == (section_length = - decode_context_enumerated(&apdu[len], 0, - &value))) { + if (-1 == (section_length = decode_context_enumerated( + &apdu[len], 0, &value))) { return -1; } data->notificationParams.changeOfLifeSafety.newState = - (BACNET_LIFE_SAFETY_STATE) value; + (BACNET_LIFE_SAFETY_STATE)value; len += section_length; - if (-1 == (section_length = - decode_context_enumerated(&apdu[len], 1, - &value))) { + if (-1 == (section_length = decode_context_enumerated( + &apdu[len], 1, &value))) { return -1; } data->notificationParams.changeOfLifeSafety.newMode = - (BACNET_LIFE_SAFETY_MODE) value; + (BACNET_LIFE_SAFETY_MODE)value; len += section_length; - if (-1 == (section_length = - decode_context_bitstring(&apdu[len], 2, - &data-> - notificationParams.changeOfLifeSafety. - statusFlags))) { + if (-1 == (section_length = decode_context_bitstring( + &apdu[len], 2, + &data->notificationParams + .changeOfLifeSafety.statusFlags))) { return -1; } len += section_length; - if (-1 == (section_length = - decode_context_enumerated(&apdu[len], 3, - &value))) { + if (-1 == (section_length = decode_context_enumerated( + &apdu[len], 3, &value))) { return -1; } - data->notificationParams. - changeOfLifeSafety.operationExpected = - (BACNET_LIFE_SAFETY_OPERATION) value; + data->notificationParams.changeOfLifeSafety + .operationExpected = + (BACNET_LIFE_SAFETY_OPERATION)value; len += section_length; break; case EVENT_BUFFER_READY: - if (-1 == (section_length = - bacapp_decode_context_device_obj_property_ref - (&apdu[len], 0, - &data->notificationParams. - bufferReady.bufferProperty))) { + if (-1 == + (section_length = + bacapp_decode_context_device_obj_property_ref( + &apdu[len], 0, + &data->notificationParams.bufferReady + .bufferProperty))) { return -1; } len += section_length; - if (-1 == (section_length = - decode_context_unsigned(&apdu[len], 1, - &data->notificationParams. - bufferReady.previousNotification))) { + if (-1 == (section_length = decode_context_unsigned( + &apdu[len], 1, + &data->notificationParams.bufferReady + .previousNotification))) { return -1; } len += section_length; - if (-1 == (section_length = - decode_context_unsigned(&apdu[len], 2, - &data->notificationParams. - bufferReady.currentNotification))) { + if (-1 == (section_length = decode_context_unsigned( + &apdu[len], 2, + &data->notificationParams.bufferReady + .currentNotification))) { return -1; } len += section_length; break; case EVENT_UNSIGNED_RANGE: - if (-1 == (section_length = - decode_context_unsigned(&apdu[len], 0, - &data->notificationParams. - unsignedRange.exceedingValue))) { + if (-1 == (section_length = decode_context_unsigned( + &apdu[len], 0, + &data->notificationParams.unsignedRange + .exceedingValue))) { return -1; } len += section_length; - if (-1 == (section_length = - decode_context_bitstring(&apdu[len], 1, - &data->notificationParams. - unsignedRange.statusFlags))) { + if (-1 == (section_length = decode_context_bitstring( + &apdu[len], 1, + &data->notificationParams.unsignedRange + .statusFlags))) { return -1; } len += section_length; - if (-1 == (section_length = - decode_context_unsigned(&apdu[len], 2, - &data->notificationParams. - unsignedRange.exceededLimit))) { + if (-1 == (section_length = decode_context_unsigned( + &apdu[len], 2, + &data->notificationParams.unsignedRange + .exceededLimit))) { return -1; } len += section_length; @@ -846,7 +811,7 @@ int event_notify_decode_service_request( return -1; } if (decode_is_closing_tag_number(&apdu[len], - (uint8_t) data->eventType)) { + (uint8_t)data->eventType)) { len++; } else { return -1; @@ -869,31 +834,26 @@ int event_notify_decode_service_request( return len; } -#ifdef TEST +#ifdef TEST #include #include #include "ctest.h" - BACNET_EVENT_NOTIFICATION_DATA data; BACNET_EVENT_NOTIFICATION_DATA data2; -void testBaseEventState( - Test * pTest) +void testBaseEventState(Test *pTest) { ct_test(pTest, data.processIdentifier == data2.processIdentifier); - ct_test(pTest, - data.initiatingObjectIdentifier.instance == - data2.initiatingObjectIdentifier.instance); - ct_test(pTest, - data.initiatingObjectIdentifier.type == - data2.initiatingObjectIdentifier.type); - ct_test(pTest, - data.eventObjectIdentifier.instance == - data2.eventObjectIdentifier.instance); - ct_test(pTest, - data.eventObjectIdentifier.type == data2.eventObjectIdentifier.type); + ct_test(pTest, data.initiatingObjectIdentifier.instance == + data2.initiatingObjectIdentifier.instance); + ct_test(pTest, data.initiatingObjectIdentifier.type == + data2.initiatingObjectIdentifier.type); + ct_test(pTest, data.eventObjectIdentifier.instance == + data2.eventObjectIdentifier.instance); + ct_test(pTest, data.eventObjectIdentifier.type == + data2.eventObjectIdentifier.type); ct_test(pTest, data.notificationClass == data2.notificationClass); ct_test(pTest, data.priority == data2.priority); ct_test(pTest, data.notifyType == data2.notifyType); @@ -903,62 +863,49 @@ void testBaseEventState( if (data.messageText != NULL && data2.messageText != NULL) { ct_test(pTest, - data.messageText->encoding == data2.messageText->encoding); + data.messageText->encoding == data2.messageText->encoding); ct_test(pTest, data.messageText->length == data2.messageText->length); - ct_test(pTest, strcmp(data.messageText->value, - data2.messageText->value) == 0); + ct_test(pTest, + strcmp(data.messageText->value, data2.messageText->value) == 0); } ct_test(pTest, data.timeStamp.tag == data2.timeStamp.tag); switch (data.timeStamp.tag) { case TIME_STAMP_SEQUENCE: - ct_test(pTest, - data.timeStamp.value.sequenceNum == - data2.timeStamp.value.sequenceNum); + ct_test(pTest, data.timeStamp.value.sequenceNum == + data2.timeStamp.value.sequenceNum); break; case TIME_STAMP_DATETIME: - ct_test(pTest, - data.timeStamp.value.dateTime.time.hour == - data2.timeStamp.value.dateTime.time.hour); - ct_test(pTest, - data.timeStamp.value.dateTime.time.min == - data2.timeStamp.value.dateTime.time.min); - ct_test(pTest, - data.timeStamp.value.dateTime.time.sec == - data2.timeStamp.value.dateTime.time.sec); - ct_test(pTest, - data.timeStamp.value.dateTime.time.hundredths == - data2.timeStamp.value.dateTime.time.hundredths); + ct_test(pTest, data.timeStamp.value.dateTime.time.hour == + data2.timeStamp.value.dateTime.time.hour); + ct_test(pTest, data.timeStamp.value.dateTime.time.min == + data2.timeStamp.value.dateTime.time.min); + ct_test(pTest, data.timeStamp.value.dateTime.time.sec == + data2.timeStamp.value.dateTime.time.sec); + ct_test(pTest, data.timeStamp.value.dateTime.time.hundredths == + data2.timeStamp.value.dateTime.time.hundredths); - ct_test(pTest, - data.timeStamp.value.dateTime.date.day == - data2.timeStamp.value.dateTime.date.day); - ct_test(pTest, - data.timeStamp.value.dateTime.date.month == - data2.timeStamp.value.dateTime.date.month); - ct_test(pTest, - data.timeStamp.value.dateTime.date.wday == - data2.timeStamp.value.dateTime.date.wday); - ct_test(pTest, - data.timeStamp.value.dateTime.date.year == - data2.timeStamp.value.dateTime.date.year); + ct_test(pTest, data.timeStamp.value.dateTime.date.day == + data2.timeStamp.value.dateTime.date.day); + ct_test(pTest, data.timeStamp.value.dateTime.date.month == + data2.timeStamp.value.dateTime.date.month); + ct_test(pTest, data.timeStamp.value.dateTime.date.wday == + data2.timeStamp.value.dateTime.date.wday); + ct_test(pTest, data.timeStamp.value.dateTime.date.year == + data2.timeStamp.value.dateTime.date.year); break; case TIME_STAMP_TIME: - ct_test(pTest, - data.timeStamp.value.time.hour == - data2.timeStamp.value.time.hour); - ct_test(pTest, - data.timeStamp.value.time.min == - data2.timeStamp.value.time.min); - ct_test(pTest, - data.timeStamp.value.time.sec == - data2.timeStamp.value.time.sec); - ct_test(pTest, - data.timeStamp.value.time.hundredths == - data2.timeStamp.value.time.hundredths); + ct_test(pTest, data.timeStamp.value.time.hour == + data2.timeStamp.value.time.hour); + ct_test(pTest, data.timeStamp.value.time.min == + data2.timeStamp.value.time.min); + ct_test(pTest, data.timeStamp.value.time.sec == + data2.timeStamp.value.time.sec); + ct_test(pTest, data.timeStamp.value.time.hundredths == + data2.timeStamp.value.time.hundredths); break; default: @@ -967,8 +914,7 @@ void testBaseEventState( } } -void testEventEventState( - Test * pTest) +void testEventEventState(Test *pTest) { uint8_t buffer[MAX_APDU]; int inLen; @@ -976,7 +922,7 @@ void testEventEventState( BACNET_CHARACTER_STRING messageText; BACNET_CHARACTER_STRING messageText2; characterstring_init_ansi(&messageText, - "This is a test of the message text\n"); + "This is a test of the message text\n"); data.messageText = &messageText; data2.messageText = &messageText2; @@ -1001,14 +947,13 @@ void testEventEventState( bitstring_init(&data.notificationParams.changeOfState.statusFlags); bitstring_set_bit(&data.notificationParams.changeOfState.statusFlags, - STATUS_FLAG_IN_ALARM, true); + STATUS_FLAG_IN_ALARM, true); bitstring_set_bit(&data.notificationParams.changeOfState.statusFlags, - STATUS_FLAG_FAULT, false); + STATUS_FLAG_FAULT, false); bitstring_set_bit(&data.notificationParams.changeOfState.statusFlags, - STATUS_FLAG_OVERRIDDEN, false); + STATUS_FLAG_OVERRIDDEN, false); bitstring_set_bit(&data.notificationParams.changeOfState.statusFlags, - STATUS_FLAG_OUT_OF_SERVICE, false); - + STATUS_FLAG_OUT_OF_SERVICE, false); inLen = event_notify_encode_service_request(&buffer[0], &data); @@ -1017,24 +962,23 @@ void testEventEventState( ct_test(pTest, inLen == outLen); testBaseEventState(pTest); + ct_test(pTest, data.notificationParams.changeOfState.newState.tag == + data2.notificationParams.changeOfState.newState.tag); ct_test(pTest, - data.notificationParams.changeOfState.newState.tag == - data2.notificationParams.changeOfState.newState.tag); - ct_test(pTest, - data.notificationParams.changeOfState.newState.state.units == - data2.notificationParams.changeOfState.newState.state.units); + data.notificationParams.changeOfState.newState.state.units == + data2.notificationParams.changeOfState.newState.state.units); - ct_test(pTest, - bitstring_same(&data.notificationParams.changeOfState.statusFlags, - &data2.notificationParams.changeOfState.statusFlags)); + ct_test(pTest, bitstring_same( + &data.notificationParams.changeOfState.statusFlags, + &data2.notificationParams.changeOfState.statusFlags)); - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ /* ** Same, but timestamp of @@ -1059,20 +1003,19 @@ void testEventEventState( ct_test(pTest, inLen == outLen); testBaseEventState(pTest); + ct_test(pTest, data.notificationParams.changeOfState.newState.tag == + data2.notificationParams.changeOfState.newState.tag); ct_test(pTest, - data.notificationParams.changeOfState.newState.tag == - data2.notificationParams.changeOfState.newState.tag); - ct_test(pTest, - data.notificationParams.changeOfState.newState.state.units == - data2.notificationParams.changeOfState.newState.state.units); + data.notificationParams.changeOfState.newState.state.units == + data2.notificationParams.changeOfState.newState.state.units); - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ /* ** Event Type = EVENT_CHANGE_OF_BITSTRING @@ -1082,27 +1025,31 @@ 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); bitstring_set_bit(&data.notificationParams.changeOfBitstring.statusFlags, - STATUS_FLAG_IN_ALARM, true); + STATUS_FLAG_IN_ALARM, true); bitstring_set_bit(&data.notificationParams.changeOfBitstring.statusFlags, - STATUS_FLAG_FAULT, false); + STATUS_FLAG_FAULT, false); bitstring_set_bit(&data.notificationParams.changeOfBitstring.statusFlags, - STATUS_FLAG_OVERRIDDEN, false); + STATUS_FLAG_OVERRIDDEN, false); bitstring_set_bit(&data.notificationParams.changeOfBitstring.statusFlags, - STATUS_FLAG_OUT_OF_SERVICE, false); + STATUS_FLAG_OUT_OF_SERVICE, false); memset(buffer, 0, MAX_APDU); inLen = event_notify_encode_service_request(&buffer[0], &data); @@ -1114,22 +1061,24 @@ void testEventEventState( ct_test(pTest, inLen == outLen); testBaseEventState(pTest); - ct_test(pTest, - bitstring_same(&data.notificationParams.changeOfBitstring. - referencedBitString, + ct_test( + pTest, + bitstring_same( + &data.notificationParams.changeOfBitstring.referencedBitString, &data2.notificationParams.changeOfBitstring.referencedBitString)); ct_test(pTest, - bitstring_same(&data.notificationParams.changeOfBitstring.statusFlags, - &data2.notificationParams.changeOfBitstring.statusFlags)); + bitstring_same( + &data.notificationParams.changeOfBitstring.statusFlags, + &data2.notificationParams.changeOfBitstring.statusFlags)); - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ /* ** Event Type = EVENT_CHANGE_OF_VALUE - float value */ @@ -1141,13 +1090,13 @@ void testEventEventState( bitstring_init(&data.notificationParams.changeOfValue.statusFlags); bitstring_set_bit(&data.notificationParams.changeOfValue.statusFlags, - STATUS_FLAG_IN_ALARM, true); + STATUS_FLAG_IN_ALARM, true); bitstring_set_bit(&data.notificationParams.changeOfValue.statusFlags, - STATUS_FLAG_FAULT, false); + STATUS_FLAG_FAULT, false); bitstring_set_bit(&data.notificationParams.changeOfValue.statusFlags, - STATUS_FLAG_OVERRIDDEN, false); + STATUS_FLAG_OVERRIDDEN, false); bitstring_set_bit(&data.notificationParams.changeOfValue.statusFlags, - STATUS_FLAG_OUT_OF_SERVICE, false); + STATUS_FLAG_OUT_OF_SERVICE, false); memset(buffer, 0, MAX_APDU); inLen = event_notify_encode_service_request(&buffer[0], &data); @@ -1159,19 +1108,16 @@ void testEventEventState( ct_test(pTest, inLen == outLen); testBaseEventState(pTest); - ct_test(pTest, - bitstring_same(&data.notificationParams.changeOfValue.statusFlags, - &data2.notificationParams.changeOfValue.statusFlags)); + ct_test(pTest, bitstring_same( + &data.notificationParams.changeOfValue.statusFlags, + &data2.notificationParams.changeOfValue.statusFlags)); + + ct_test(pTest, data.notificationParams.changeOfValue.tag == + data2.notificationParams.changeOfValue.tag); ct_test(pTest, - data.notificationParams.changeOfValue.tag == - data2.notificationParams.changeOfValue.tag); - - ct_test(pTest, - data.notificationParams.changeOfValue.newValue.changeValue == - data2.notificationParams.changeOfValue.newValue.changeValue); - - + data.notificationParams.changeOfValue.newValue.changeValue == + data2.notificationParams.changeOfValue.newValue.changeValue); /* ** Event Type = EVENT_CHANGE_OF_VALUE - bitstring value @@ -1179,16 +1125,15 @@ 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); @@ -1200,26 +1145,25 @@ void testEventEventState( ct_test(pTest, inLen == outLen); testBaseEventState(pTest); - ct_test(pTest, - bitstring_same(&data.notificationParams.changeOfValue.statusFlags, - &data2.notificationParams.changeOfValue.statusFlags)); + ct_test(pTest, bitstring_same( + &data.notificationParams.changeOfValue.statusFlags, + &data2.notificationParams.changeOfValue.statusFlags)); + + ct_test(pTest, data.notificationParams.changeOfValue.tag == + data2.notificationParams.changeOfValue.tag); ct_test(pTest, - data.notificationParams.changeOfValue.tag == - data2.notificationParams.changeOfValue.tag); + bitstring_same( + &data.notificationParams.changeOfValue.newValue.changedBits, + &data2.notificationParams.changeOfValue.newValue.changedBits)); - ct_test(pTest, - bitstring_same(&data.notificationParams.changeOfValue.newValue. - changedBits, - &data2.notificationParams.changeOfValue.newValue.changedBits)); - - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ /* ** Event Type = EVENT_FLOATING_LIMIT */ @@ -1231,13 +1175,13 @@ void testEventEventState( bitstring_init(&data.notificationParams.floatingLimit.statusFlags); bitstring_set_bit(&data.notificationParams.floatingLimit.statusFlags, - STATUS_FLAG_IN_ALARM, true); + STATUS_FLAG_IN_ALARM, true); bitstring_set_bit(&data.notificationParams.floatingLimit.statusFlags, - STATUS_FLAG_FAULT, false); + STATUS_FLAG_FAULT, false); bitstring_set_bit(&data.notificationParams.floatingLimit.statusFlags, - STATUS_FLAG_OVERRIDDEN, false); + STATUS_FLAG_OVERRIDDEN, false); bitstring_set_bit(&data.notificationParams.floatingLimit.statusFlags, - STATUS_FLAG_OUT_OF_SERVICE, false); + STATUS_FLAG_OUT_OF_SERVICE, false); memset(buffer, 0, MAX_APDU); inLen = event_notify_encode_service_request(&buffer[0], &data); @@ -1249,29 +1193,25 @@ void testEventEventState( ct_test(pTest, inLen == outLen); testBaseEventState(pTest); - ct_test(pTest, - data.notificationParams.floatingLimit.referenceValue == - data2.notificationParams.floatingLimit.referenceValue); + ct_test(pTest, data.notificationParams.floatingLimit.referenceValue == + data2.notificationParams.floatingLimit.referenceValue); - ct_test(pTest, - data.notificationParams.floatingLimit.setPointValue == - data2.notificationParams.floatingLimit.setPointValue); + ct_test(pTest, data.notificationParams.floatingLimit.setPointValue == + data2.notificationParams.floatingLimit.setPointValue); - ct_test(pTest, - data.notificationParams.floatingLimit.errorLimit == - data2.notificationParams.floatingLimit.errorLimit); - ct_test(pTest, - bitstring_same(&data.notificationParams.floatingLimit.statusFlags, - &data2.notificationParams.floatingLimit.statusFlags)); + ct_test(pTest, data.notificationParams.floatingLimit.errorLimit == + data2.notificationParams.floatingLimit.errorLimit); + ct_test(pTest, bitstring_same( + &data.notificationParams.floatingLimit.statusFlags, + &data2.notificationParams.floatingLimit.statusFlags)); - - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ /* ** Event Type = EVENT_OUT_OF_RANGE */ @@ -1283,13 +1223,13 @@ void testEventEventState( bitstring_init(&data.notificationParams.outOfRange.statusFlags); bitstring_set_bit(&data.notificationParams.outOfRange.statusFlags, - STATUS_FLAG_IN_ALARM, true); + STATUS_FLAG_IN_ALARM, true); bitstring_set_bit(&data.notificationParams.outOfRange.statusFlags, - STATUS_FLAG_FAULT, false); + STATUS_FLAG_FAULT, false); bitstring_set_bit(&data.notificationParams.outOfRange.statusFlags, - STATUS_FLAG_OVERRIDDEN, false); + STATUS_FLAG_OVERRIDDEN, false); bitstring_set_bit(&data.notificationParams.outOfRange.statusFlags, - STATUS_FLAG_OUT_OF_SERVICE, false); + STATUS_FLAG_OUT_OF_SERVICE, false); memset(buffer, 0, MAX_APDU); inLen = event_notify_encode_service_request(&buffer[0], &data); @@ -1301,49 +1241,45 @@ void testEventEventState( ct_test(pTest, inLen == outLen); testBaseEventState(pTest); - ct_test(pTest, - data.notificationParams.outOfRange.deadband == - data2.notificationParams.outOfRange.deadband); + ct_test(pTest, data.notificationParams.outOfRange.deadband == + data2.notificationParams.outOfRange.deadband); - ct_test(pTest, - data.notificationParams.outOfRange.exceededLimit == - data2.notificationParams.outOfRange.exceededLimit); + ct_test(pTest, data.notificationParams.outOfRange.exceededLimit == + data2.notificationParams.outOfRange.exceededLimit); + ct_test(pTest, data.notificationParams.outOfRange.exceedingValue == + data2.notificationParams.outOfRange.exceedingValue); ct_test(pTest, - data.notificationParams.outOfRange.exceedingValue == - data2.notificationParams.outOfRange.exceedingValue); - ct_test(pTest, - bitstring_same(&data.notificationParams.outOfRange.statusFlags, - &data2.notificationParams.outOfRange.statusFlags)); + bitstring_same(&data.notificationParams.outOfRange.statusFlags, + &data2.notificationParams.outOfRange.statusFlags)); - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ /* ** Event Type = EVENT_CHANGE_OF_LIFE_SAFETY */ data.eventType = EVENT_CHANGE_OF_LIFE_SAFETY; data.notificationParams.changeOfLifeSafety.newState = LIFE_SAFETY_STATE_ALARM; - data.notificationParams.changeOfLifeSafety.newMode = - LIFE_SAFETY_MODE_ARMED; + data.notificationParams.changeOfLifeSafety.newMode = LIFE_SAFETY_MODE_ARMED; data.notificationParams.changeOfLifeSafety.operationExpected = LIFE_SAFETY_OP_RESET; bitstring_init(&data.notificationParams.changeOfLifeSafety.statusFlags); bitstring_set_bit(&data.notificationParams.changeOfLifeSafety.statusFlags, - STATUS_FLAG_IN_ALARM, true); + STATUS_FLAG_IN_ALARM, true); bitstring_set_bit(&data.notificationParams.changeOfLifeSafety.statusFlags, - STATUS_FLAG_FAULT, false); + STATUS_FLAG_FAULT, false); bitstring_set_bit(&data.notificationParams.changeOfLifeSafety.statusFlags, - STATUS_FLAG_OVERRIDDEN, false); + STATUS_FLAG_OVERRIDDEN, false); bitstring_set_bit(&data.notificationParams.changeOfLifeSafety.statusFlags, - STATUS_FLAG_OUT_OF_SERVICE, false); + STATUS_FLAG_OUT_OF_SERVICE, false); memset(buffer, 0, MAX_APDU); inLen = event_notify_encode_service_request(&buffer[0], &data); @@ -1355,29 +1291,28 @@ void testEventEventState( ct_test(pTest, inLen == outLen); testBaseEventState(pTest); - ct_test(pTest, - data.notificationParams.changeOfLifeSafety.newMode == - data2.notificationParams.changeOfLifeSafety.newMode); + ct_test(pTest, data.notificationParams.changeOfLifeSafety.newMode == + data2.notificationParams.changeOfLifeSafety.newMode); + + ct_test(pTest, data.notificationParams.changeOfLifeSafety.newState == + data2.notificationParams.changeOfLifeSafety.newState); ct_test(pTest, - data.notificationParams.changeOfLifeSafety.newState == - data2.notificationParams.changeOfLifeSafety.newState); + data.notificationParams.changeOfLifeSafety.operationExpected == + data2.notificationParams.changeOfLifeSafety.operationExpected); ct_test(pTest, - data.notificationParams.changeOfLifeSafety.operationExpected == - data2.notificationParams.changeOfLifeSafety.operationExpected); + bitstring_same( + &data.notificationParams.changeOfLifeSafety.statusFlags, + &data2.notificationParams.changeOfLifeSafety.statusFlags)); - ct_test(pTest, - bitstring_same(&data.notificationParams.changeOfLifeSafety.statusFlags, - &data2.notificationParams.changeOfLifeSafety.statusFlags)); - - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ /* ** Event Type = EVENT_UNSIGNED_RANGE */ @@ -1388,13 +1323,13 @@ void testEventEventState( bitstring_init(&data.notificationParams.unsignedRange.statusFlags); bitstring_set_bit(&data.notificationParams.unsignedRange.statusFlags, - STATUS_FLAG_IN_ALARM, true); + STATUS_FLAG_IN_ALARM, true); bitstring_set_bit(&data.notificationParams.unsignedRange.statusFlags, - STATUS_FLAG_FAULT, false); + STATUS_FLAG_FAULT, false); bitstring_set_bit(&data.notificationParams.unsignedRange.statusFlags, - STATUS_FLAG_OVERRIDDEN, false); + STATUS_FLAG_OVERRIDDEN, false); bitstring_set_bit(&data.notificationParams.unsignedRange.statusFlags, - STATUS_FLAG_OUT_OF_SERVICE, false); + STATUS_FLAG_OUT_OF_SERVICE, false); memset(buffer, 0, MAX_APDU); inLen = event_notify_encode_service_request(&buffer[0], &data); @@ -1406,25 +1341,23 @@ void testEventEventState( ct_test(pTest, inLen == outLen); testBaseEventState(pTest); - ct_test(pTest, - data.notificationParams.unsignedRange.exceedingValue == - data2.notificationParams.unsignedRange.exceedingValue); + ct_test(pTest, data.notificationParams.unsignedRange.exceedingValue == + data2.notificationParams.unsignedRange.exceedingValue); - ct_test(pTest, - data.notificationParams.unsignedRange.exceededLimit == - data2.notificationParams.unsignedRange.exceededLimit); + ct_test(pTest, data.notificationParams.unsignedRange.exceededLimit == + data2.notificationParams.unsignedRange.exceededLimit); - ct_test(pTest, - bitstring_same(&data.notificationParams.unsignedRange.statusFlags, - &data2.notificationParams.unsignedRange.statusFlags)); + ct_test(pTest, bitstring_same( + &data.notificationParams.unsignedRange.statusFlags, + &data2.notificationParams.unsignedRange.statusFlags)); - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ - /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ + /**********************************************************************************/ /* ** Event Type = EVENT_BUFFER_READY */ @@ -1433,12 +1366,12 @@ void testEventEventState( data.notificationParams.bufferReady.currentNotification = 2345; data.notificationParams.bufferReady.bufferProperty.deviceIdentifier.type = OBJECT_DEVICE; - data.notificationParams.bufferReady.bufferProperty. - deviceIdentifier.instance = 500; + data.notificationParams.bufferReady.bufferProperty.deviceIdentifier + .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; @@ -1454,53 +1387,47 @@ void testEventEventState( testBaseEventState(pTest); ct_test(pTest, - data.notificationParams.bufferReady.previousNotification == - data2.notificationParams.bufferReady.previousNotification); + data.notificationParams.bufferReady.previousNotification == + data2.notificationParams.bufferReady.previousNotification); ct_test(pTest, - data.notificationParams.bufferReady.currentNotification == - data2.notificationParams.bufferReady.currentNotification); - + data.notificationParams.bufferReady.currentNotification == + data2.notificationParams.bufferReady.currentNotification); ct_test(pTest, - data.notificationParams.bufferReady.bufferProperty. - deviceIdentifier.type == - data2.notificationParams.bufferReady.bufferProperty. - deviceIdentifier.type); + data.notificationParams.bufferReady.bufferProperty.deviceIdentifier + .type == data2.notificationParams.bufferReady.bufferProperty + .deviceIdentifier.type); ct_test(pTest, - data.notificationParams.bufferReady.bufferProperty. - deviceIdentifier.instance == - data2.notificationParams.bufferReady.bufferProperty. - deviceIdentifier.instance); + data.notificationParams.bufferReady.bufferProperty.deviceIdentifier + .instance == data2.notificationParams.bufferReady + .bufferProperty.deviceIdentifier.instance); ct_test(pTest, - data.notificationParams.bufferReady.bufferProperty. - objectIdentifier.instance == - data2.notificationParams.bufferReady.bufferProperty. - objectIdentifier.instance); + data.notificationParams.bufferReady.bufferProperty.objectIdentifier + .instance == data2.notificationParams.bufferReady + .bufferProperty.objectIdentifier.instance); ct_test(pTest, - data.notificationParams.bufferReady.bufferProperty. - objectIdentifier.type == - data2.notificationParams.bufferReady.bufferProperty. - objectIdentifier.type); + data.notificationParams.bufferReady.bufferProperty.objectIdentifier + .type == data2.notificationParams.bufferReady.bufferProperty + .objectIdentifier.type); + + ct_test( + pTest, + data.notificationParams.bufferReady.bufferProperty.propertyIdentifier == + data2.notificationParams.bufferReady.bufferProperty + .propertyIdentifier); ct_test(pTest, - data.notificationParams.bufferReady. - bufferProperty.propertyIdentifier == - data2.notificationParams.bufferReady. - bufferProperty.propertyIdentifier); - - ct_test(pTest, - data.notificationParams.bufferReady.bufferProperty.arrayIndex == - data2.notificationParams.bufferReady.bufferProperty.arrayIndex); + data.notificationParams.bufferReady.bufferProperty.arrayIndex == + data2.notificationParams.bufferReady.bufferProperty.arrayIndex); } #ifdef TEST_EVENT -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -1512,7 +1439,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/src/fifo.c b/src/fifo.c index 2ac10eff..f6085024 100755 --- a/src/fifo.c +++ b/src/fifo.c @@ -1,110 +1,109 @@ /** -* @file -* @author Steve Karg -* @date 2004 -* @brief Generic interrupt safe FIFO library for deeply embedded system. -* -* @section LICENSE -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to: -* The Free Software Foundation, Inc. -* 59 Temple Place - Suite 330 -* Boston, MA 02111-1307 -* USA. -* -* As a special exception, if other files instantiate templates or -* use macros or inline functions from this file, or you compile -* this file and link it with other works to produce a work based -* on this file, this file does not by itself cause the resulting -* work to be covered by the GNU General Public License. However -* the source code for this file must still be made available in -* accordance with section (3) of the GNU General Public License. -* -* This exception does not invalidate any other reasons why a work -* based on this file might be covered by the GNU General Public -* License. -* -* @section DESCRIPTION -* -* Generic interrupt safe FIFO library for deeply embedded system -* This library only uses a byte sized chunk for a data element. -* It uses a data store whose size is a power of 2 (8, 16, 32, 64, ...) -* and doesn't waste any data bytes. It has very low overhead, and -* utilizes modulo for indexing the data in the data store. -* -* To use this library, first declare a data store, sized for a power of 2: -* {@code -* static volatile uint8_t data_store[64]; -* } -* -* Then declare the FIFO tracking structure: -* {@code -* static FIFO_BUFFER queue; -* } -* -* Initialize the queue with the data store: -* {@code -* FIFO_Init(&queue, data_store, sizeof(data_store)); -* } -* -* Then begin to use the FIFO queue by giving it data, retreiving data, -* and checking the FIFO queue to see if it is empty or full: -* {@code -* uint8_t in_data = 0; -* uint8_t out_data = 0; -* uint8_t add_data[5] = {0}; -* uint8_t pull_data[5] = {0}; -* unsigned count = 0; -* bool status = false; -* -* status = FIFO_Put(&queue, in_data); -* if (!FIFO_Empty(&queue)) { -* out_data = FIFO_Get(&queue); -* } -* if (FIFO_Available(&queue, sizeof(add_data))) { -* status = FIFO_Add(&queue, add_data, sizeof(add_data)); -* } -* count = FIFO_Count(&queue); -* if (count == sizeof(add_data)) { -* count = FIFO_Pull(&queue, &pull_data[0], sizeof(pull_data)); -* } -* -* } -* -* Normally the FIFO is used by a producer, such as in interrupt service -* routine, which places data into the queue using FIFO_Put(), and a consumer, -* such as a main loop handler, which pulls data from the queue by first -* checking the queue for data using FIFO_Empty(), and then pulling data from -* the queue using FIFO_Get(). -* -*/ + * @file + * @author Steve Karg + * @date 2004 + * @brief Generic interrupt safe FIFO library for deeply embedded system. + * + * @section LICENSE + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to: + * The Free Software Foundation, Inc. + * 59 Temple Place - Suite 330 + * Boston, MA 02111-1307 + * USA. + * + * As a special exception, if other files instantiate templates or + * use macros or inline functions from this file, or you compile + * this file and link it with other works to produce a work based + * on this file, this file does not by itself cause the resulting + * work to be covered by the GNU General Public License. However + * the source code for this file must still be made available in + * accordance with section (3) of the GNU General Public License. + * + * This exception does not invalidate any other reasons why a work + * based on this file might be covered by the GNU General Public + * License. + * + * @section DESCRIPTION + * + * Generic interrupt safe FIFO library for deeply embedded system + * This library only uses a byte sized chunk for a data element. + * It uses a data store whose size is a power of 2 (8, 16, 32, 64, ...) + * and doesn't waste any data bytes. It has very low overhead, and + * utilizes modulo for indexing the data in the data store. + * + * To use this library, first declare a data store, sized for a power of 2: + * {@code + * static volatile uint8_t data_store[64]; + * } + * + * Then declare the FIFO tracking structure: + * {@code + * static FIFO_BUFFER queue; + * } + * + * Initialize the queue with the data store: + * {@code + * FIFO_Init(&queue, data_store, sizeof(data_store)); + * } + * + * Then begin to use the FIFO queue by giving it data, retreiving data, + * and checking the FIFO queue to see if it is empty or full: + * {@code + * uint8_t in_data = 0; + * uint8_t out_data = 0; + * uint8_t add_data[5] = {0}; + * uint8_t pull_data[5] = {0}; + * unsigned count = 0; + * bool status = false; + * + * status = FIFO_Put(&queue, in_data); + * if (!FIFO_Empty(&queue)) { + * out_data = FIFO_Get(&queue); + * } + * if (FIFO_Available(&queue, sizeof(add_data))) { + * status = FIFO_Add(&queue, add_data, sizeof(add_data)); + * } + * count = FIFO_Count(&queue); + * if (count == sizeof(add_data)) { + * count = FIFO_Pull(&queue, &pull_data[0], sizeof(pull_data)); + * } + * + * } + * + * Normally the FIFO is used by a producer, such as in interrupt service + * routine, which places data into the queue using FIFO_Put(), and a consumer, + * such as a main loop handler, which pulls data from the queue by first + * checking the queue for data using FIFO_Empty(), and then pulling data from + * the queue using FIFO_Get(). + * + */ #include #include #include #include "fifo.h" /** -* Returns the number of bytes in the FIFO -* -* @param b - pointer to FIFO_BUFFER structure -* -* @return Number of bytes in the FIFO -*/ -unsigned FIFO_Count( - FIFO_BUFFER const *b) + * Returns the number of bytes in the FIFO + * + * @param b - pointer to FIFO_BUFFER structure + * + * @return Number of bytes in the FIFO + */ +unsigned FIFO_Count(FIFO_BUFFER const *b) { - unsigned head, tail; /* used to avoid volatile decision */ + unsigned head, tail; /* used to avoid volatile decision */ if (b) { head = b->head; @@ -116,57 +115,52 @@ unsigned FIFO_Count( } /** -* Returns the full status of the FIFO -* -* @param b - pointer to FIFO_BUFFER structure -* -* @return true if the FIFO is full, false if it is not. -*/ -bool FIFO_Full( - FIFO_BUFFER const *b) + * Returns the full status of the FIFO + * + * @param b - pointer to FIFO_BUFFER structure + * + * @return true if the FIFO is full, false if it is not. + */ +bool FIFO_Full(FIFO_BUFFER const *b) { return (b ? (FIFO_Count(b) == b->buffer_len) : true); } /** -* Tests to see if space is available in the FIFO -* -* @param b - pointer to FIFO_BUFFER structure -* @param count [in] - number of bytes tested for availability -* -* @return true if the number of bytes sought is available -*/ -bool FIFO_Available( - FIFO_BUFFER const *b, - unsigned count) + * Tests to see if space is available in the FIFO + * + * @param b - pointer to FIFO_BUFFER structure + * @param count [in] - number of bytes tested for availability + * + * @return true if the number of bytes sought is available + */ +bool FIFO_Available(FIFO_BUFFER const *b, unsigned count) { return (b ? (count <= (b->buffer_len - FIFO_Count(b))) : false); } /** -* Returns the empty status of the FIFO -* -* @param b - pointer to FIFO_BUFFER structure -* @return true if the FIFO is empty, false if it is not. -*/ -bool FIFO_Empty( - FIFO_BUFFER const *b) + * Returns the empty status of the FIFO + * + * @param b - pointer to FIFO_BUFFER structure + * @return true if the FIFO is empty, false if it is not. + */ +bool FIFO_Empty(FIFO_BUFFER const *b) { return (b ? (FIFO_Count(b) == 0) : true); } /** -* Peeks at the data from the front of the FIFO without removing it. -* Use FIFO_Empty() or FIFO_Available() function to see if there is -* data to retrieve since this function doesn't return a flag indicating -* success or failure. -* -* @param b - pointer to FIFO_BUFFER structure -* -* @return byte of data, or zero if nothing in the list -*/ -uint8_t FIFO_Peek( - FIFO_BUFFER const *b) + * Peeks at the data from the front of the FIFO without removing it. + * Use FIFO_Empty() or FIFO_Available() function to see if there is + * data to retrieve since this function doesn't return a flag indicating + * success or failure. + * + * @param b - pointer to FIFO_BUFFER structure + * + * @return byte of data, or zero if nothing in the list + */ +uint8_t FIFO_Peek(FIFO_BUFFER const *b) { unsigned index; @@ -179,17 +173,16 @@ uint8_t FIFO_Peek( } /** -* Gets a byte from the front of the FIFO, and removes it. -* Use FIFO_Empty() or FIFO_Available() function to see if there is -* data to retrieve since this function doesn't return a flag indicating -* success or failure. -* -* @param b - pointer to FIFO_BUFFER structure -* -* @return the data -*/ -uint8_t FIFO_Get( - FIFO_BUFFER * b) + * Gets a byte from the front of the FIFO, and removes it. + * Use FIFO_Empty() or FIFO_Available() function to see if there is + * data to retrieve since this function doesn't return a flag indicating + * success or failure. + * + * @param b - pointer to FIFO_BUFFER structure + * + * @return the data + */ +uint8_t FIFO_Get(FIFO_BUFFER *b) { uint8_t data_byte = 0; unsigned index; @@ -203,20 +196,17 @@ uint8_t FIFO_Get( } /** -* Pulls one or more bytes from the front of the FIFO, and removes them -* from the FIFO. If less bytes are available, only the available bytes -* are retrieved. -* -* @param b - pointer to FIFO_BUFFER structure -* @param buffer [out] - buffer to hold the pulled bytes -* @param length [in] - number of bytes to pull from the FIFO -* -* @return the number of bytes actually pulled from the FIFO -*/ -unsigned FIFO_Pull( - FIFO_BUFFER * b, - uint8_t * buffer, - unsigned length) + * Pulls one or more bytes from the front of the FIFO, and removes them + * from the FIFO. If less bytes are available, only the available bytes + * are retrieved. + * + * @param b - pointer to FIFO_BUFFER structure + * @param buffer [out] - buffer to hold the pulled bytes + * @param length [in] - number of bytes to pull from the FIFO + * + * @return the number of bytes actually pulled from the FIFO + */ +unsigned FIFO_Pull(FIFO_BUFFER *b, uint8_t *buffer, unsigned length) { unsigned count; uint8_t data_byte; @@ -246,18 +236,16 @@ unsigned FIFO_Pull( } /** -* Adds a byte of data to the FIFO -* -* @param b - pointer to FIFO_BUFFER structure -* @param data_byte [in] - data to put into the FIFO -* -* @return true on successful add, false if not added -*/ -bool FIFO_Put( - FIFO_BUFFER * b, - uint8_t data_byte) + * Adds a byte of data to the FIFO + * + * @param b - pointer to FIFO_BUFFER structure + * @param data_byte [in] - data to put into the FIFO + * + * @return true on successful add, false if not added + */ +bool FIFO_Put(FIFO_BUFFER *b, uint8_t data_byte) { - bool status = false; /* return value */ + bool status = false; /* return value */ unsigned index; if (b) { @@ -274,20 +262,17 @@ bool FIFO_Put( } /** -* Adds one or more bytes of data to the FIFO -* -* @param b - pointer to FIFO_BUFFER structure -* @param buffer [out] - data bytes to add to the FIFO -* @param count [in] - number of bytes to add to the FIFO -* -* @return true if space available and added, false if not added -*/ -bool FIFO_Add( - FIFO_BUFFER * b, - uint8_t * buffer, - unsigned count) + * Adds one or more bytes of data to the FIFO + * + * @param b - pointer to FIFO_BUFFER structure + * @param buffer [out] - data bytes to add to the FIFO + * @param count [in] - number of bytes to add to the FIFO + * + * @return true if space available and added, false if not added + */ +bool FIFO_Add(FIFO_BUFFER *b, uint8_t *buffer, unsigned count) { - bool status = false; /* return value */ + bool status = false; /* return value */ unsigned index; /* limit the buffer to prevent overwriting */ @@ -306,16 +291,15 @@ bool FIFO_Add( } /** -* Flushes any data in the FIFO buffer -* -* @param b - pointer to FIFO_BUFFER structure -* -* @return none -*/ -void FIFO_Flush( - FIFO_BUFFER * b) + * Flushes any data in the FIFO buffer + * + * @param b - pointer to FIFO_BUFFER structure + * + * @return none + */ +void FIFO_Flush(FIFO_BUFFER *b) { - unsigned head; /* used to avoid volatile decision */ + unsigned head; /* used to avoid volatile decision */ if (b) { head = b->head; @@ -324,18 +308,15 @@ void FIFO_Flush( } /** -* Initializes the FIFO buffer with a data store -* -* @param b - pointer to FIFO_BUFFER structure -* @param buffer [in] - data bytes used to store bytes used by the FIFO -* @param buffer_len [in] - size of the buffer in bytes - must be power of 2. -* -* @return none -*/ -void FIFO_Init( - FIFO_BUFFER * b, - volatile uint8_t * buffer, - unsigned buffer_len) + * Initializes the FIFO buffer with a data store + * + * @param b - pointer to FIFO_BUFFER structure + * @param buffer [in] - data bytes used to store bytes used by the FIFO + * @param buffer_len [in] - size of the buffer in bytes - must be power of 2. + * + * @return none + */ +void FIFO_Init(FIFO_BUFFER *b, volatile uint8_t *buffer, unsigned buffer_len) { if (b && buffer && buffer_len) { b->head = 0; @@ -354,19 +335,18 @@ void FIFO_Init( #include "ctest.h" /** -* Unit Test for the FIFO buffer -* -* @param pTest - test tracking pointer -*/ -void testFIFOBuffer( - Test * pTest) + * Unit Test for the FIFO buffer + * + * @param pTest - test tracking pointer + */ +void testFIFOBuffer(Test *pTest) { /* FIFO data structure */ - FIFO_BUFFER test_buffer = { 0 }; + FIFO_BUFFER test_buffer = {0}; /* FIFO data store. Note: size must be a power of two! */ - volatile uint8_t data_store[64] = { 0 }; - uint8_t add_data[40] = { "RoseSteveLouPatRachelJessicaDaniAmyHerb" }; - uint8_t test_add_data[40] = { 0 }; + volatile uint8_t data_store[64] = {0}; + uint8_t add_data[40] = {"RoseSteveLouPatRachelJessicaDaniAmyHerb"}; + uint8_t test_add_data[40] = {0}; uint8_t test_data = 0; unsigned index = 0; unsigned count = 0; @@ -474,12 +454,11 @@ void testFIFOBuffer( #ifdef TEST_FIFO_BUFFER /** -* Main program entry for Unit Test -* -* @return returns 0 on success, and non-zero on fail. -*/ -int main( - void) + * Main program entry for Unit Test + * + * @return returns 0 on success, and non-zero on fail. + */ +int main(void) { Test *pTest; bool rc; @@ -492,7 +471,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); diff --git a/src/filename.c b/src/filename.c index 4eeebf6f..34dd9975 100644 --- a/src/filename.c +++ b/src/filename.c @@ -37,10 +37,9 @@ /** @file filename.c Function for filename manipulation */ -char *filename_remove_path( - const char *filename_in) +char *filename_remove_path(const char *filename_in) { - char *filename_out = (char *) filename_in; + char *filename_out = (char *)filename_in; /* allow the device ID to be set */ if (filename_in) { @@ -53,7 +52,7 @@ char *filename_remove_path( filename_out++; } else { /* no slash in filename */ - filename_out = (char *) filename_in; + filename_out = (char *)filename_in; } } @@ -66,8 +65,7 @@ char *filename_remove_path( #include "ctest.h" -void testFilename( - Test * pTest) +void testFilename(Test *pTest) { char *data1 = "c:\\Joshua\\run"; char *data2 = "/home/Anna/run"; @@ -91,8 +89,7 @@ void testFilename( } #ifdef TEST_FILENAME -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -105,7 +102,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); diff --git a/src/get_alarm_sum.c b/src/get_alarm_sum.c index e6c1b563..7277cad3 100644 --- a/src/get_alarm_sum.c +++ b/src/get_alarm_sum.c @@ -1,41 +1,41 @@ /** -* @file -* @author Krzysztof Malorny -* @date 2011 -* @brief GetAlarmSummary service encoding and decoding -* -* @section LICENSE -* -* Copyright (C) 2011 Krzysztof Malorny -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -* @section DESCRIPTION -* -* The GetAlarmSummary service is used by a client BACnet-user -* to obtain a summary of "active alarms." The term "active alarm" refers -* to BACnet standard objects that have an Event_State property whose value -* is not equal to NORMAL and a Notify_Type property whose value is ALARM. -* The GetEnrollmentSummary service provides a more sophisticated approach -* with various kinds of filters -*/ + * @file + * @author Krzysztof Malorny + * @date 2011 + * @brief GetAlarmSummary service encoding and decoding + * + * @section LICENSE + * + * Copyright (C) 2011 Krzysztof Malorny + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * @section DESCRIPTION + * + * The GetAlarmSummary service is used by a client BACnet-user + * to obtain a summary of "active alarms." The term "active alarm" refers + * to BACnet standard objects that have an Event_State property whose value + * is not equal to NORMAL and a Notify_Type property whose value is ALARM. + * The GetEnrollmentSummary service provides a more sophisticated approach + * with various kinds of filters + */ #include #include "bacdcode.h" @@ -43,10 +43,8 @@ #include "npdu.h" /* encode service */ -int get_alarm_summary_encode_apdu( - uint8_t * apdu, - uint8_t invoke_id - ) { +int get_alarm_summary_encode_apdu(uint8_t* apdu, uint8_t invoke_id) +{ int apdu_len = 0; /* total length of the apdu, return value */ if (apdu) { @@ -67,15 +65,13 @@ int get_alarm_summary_encode_apdu( * * @return number of bytes encoded */ -int get_alarm_summary_ack_encode_apdu_init( - uint8_t * apdu, - uint8_t invoke_id) +int get_alarm_summary_ack_encode_apdu_init(uint8_t* apdu, uint8_t invoke_id) { - 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 */ - apdu[1] = invoke_id; /* original invoke id from request */ + apdu[1] = invoke_id; /* original invoke id from request */ apdu[2] = SERVICE_CONFIRMED_GET_ALARM_SUMMARY; apdu_len = 3; } @@ -92,28 +88,24 @@ int get_alarm_summary_ack_encode_apdu_init( * @return number of bytes encoded, or BACNET_STATUS_ERROR if an error. */ int get_alarm_summary_ack_encode_apdu_data( - uint8_t * apdu, - size_t max_apdu, - BACNET_GET_ALARM_SUMMARY_DATA * get_alarm_data) + uint8_t* apdu, size_t max_apdu, + BACNET_GET_ALARM_SUMMARY_DATA* get_alarm_data) { - 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_len = BACNET_STATUS_ERROR; } else if (max_apdu >= 10) { /* tag 0 - Object Identifier */ - apdu_len += - encode_application_object_id(&apdu[apdu_len], - (int) get_alarm_data->objectIdentifier.type, + apdu_len += encode_application_object_id( + &apdu[apdu_len], (int)get_alarm_data->objectIdentifier.type, get_alarm_data->objectIdentifier.instance); /* tag 1 - Alarm State */ - apdu_len += - encode_application_enumerated(&apdu[apdu_len], - get_alarm_data->alarmState); + apdu_len += encode_application_enumerated(&apdu[apdu_len], + get_alarm_data->alarmState); /* tag 2 - Acknowledged Transitions */ - apdu_len += - encode_application_bitstring(&apdu[apdu_len], - &get_alarm_data->acknowledgedTransitions); + apdu_len += encode_application_bitstring( + &apdu[apdu_len], &get_alarm_data->acknowledgedTransitions); } else { apdu_len = BACNET_STATUS_ABORT; } @@ -130,39 +122,35 @@ int get_alarm_summary_ack_encode_apdu_data( * @return number of bytes decoded, or BACNET_STATUS_ERROR if an error. */ int get_alarm_summary_ack_decode_apdu_data( - uint8_t * apdu, - size_t max_apdu, - BACNET_GET_ALARM_SUMMARY_DATA * get_alarm_data) + uint8_t* apdu, size_t max_apdu, + BACNET_GET_ALARM_SUMMARY_DATA* get_alarm_data) { - int apdu_len = 0; /* total length of the apdu, return value */ + int apdu_len = 0; /* total length of the apdu, return value */ BACNET_APPLICATION_DATA_VALUE value; if (!apdu) { apdu_len = BACNET_STATUS_ERROR; } else if (max_apdu >= 10) { /* tag 0 - Object Identifier */ - apdu_len += - bacapp_decode_application_data(&apdu[apdu_len], - (unsigned int)(max_apdu - apdu_len), &value); + apdu_len += bacapp_decode_application_data( + &apdu[apdu_len], (unsigned int)(max_apdu - apdu_len), &value); if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) { get_alarm_data->objectIdentifier = value.type.Object_Id; } else { return BACNET_STATUS_ERROR; } /* tag 1 - Alarm State */ - apdu_len += - bacapp_decode_application_data(&apdu[apdu_len], - (unsigned int)(max_apdu - apdu_len), &value); + apdu_len += bacapp_decode_application_data( + &apdu[apdu_len], (unsigned int)(max_apdu - apdu_len), &value); if (value.tag == BACNET_APPLICATION_TAG_ENUMERATED) { get_alarm_data->alarmState = - (BACNET_EVENT_STATE) value.type.Enumerated; + (BACNET_EVENT_STATE)value.type.Enumerated; } else { return BACNET_STATUS_ERROR; } /* tag 2 - Acknowledged Transitions */ - apdu_len += - bacapp_decode_application_data(&apdu[apdu_len], - (unsigned int)(max_apdu - apdu_len), &value); + apdu_len += bacapp_decode_application_data( + &apdu[apdu_len], (unsigned int)(max_apdu - apdu_len), &value); if (value.tag == BACNET_APPLICATION_TAG_BIT_STRING) { get_alarm_data->acknowledgedTransitions = value.type.Bit_String; } else { diff --git a/src/getevent.c b/src/getevent.c index 2d0e5aa0..2b00bc14 100644 --- a/src/getevent.c +++ b/src/getevent.c @@ -40,13 +40,11 @@ /** @file getevent.c Encode/Decode GetEvent services */ /* encode service */ -int getevent_encode_apdu( - uint8_t * apdu, - uint8_t invoke_id, - BACNET_OBJECT_ID * lastReceivedObjectIdentifier) +int getevent_encode_apdu(uint8_t *apdu, uint8_t invoke_id, + BACNET_OBJECT_ID *lastReceivedObjectIdentifier) { - int len = 0; /* length of each encoding */ - int apdu_len = 0; /* total length of the apdu, return value */ + int len = 0; /* length of each encoding */ + int apdu_len = 0; /* total length of the apdu, return value */ if (apdu) { apdu[0] = PDU_TYPE_CONFIRMED_SERVICE_REQUEST; @@ -56,9 +54,8 @@ int getevent_encode_apdu( apdu_len = 4; /* encode optional parameter */ if (lastReceivedObjectIdentifier) { - len = - encode_context_object_id(&apdu[apdu_len], 0, - (int) lastReceivedObjectIdentifier->type, + len = encode_context_object_id( + &apdu[apdu_len], 0, (int)lastReceivedObjectIdentifier->type, lastReceivedObjectIdentifier->instance); apdu_len += len; } @@ -69,9 +66,8 @@ int getevent_encode_apdu( /* decode the service request only */ int getevent_decode_service_request( - uint8_t * apdu, - unsigned apdu_len, - BACNET_OBJECT_ID * lastReceivedObjectIdentifier) + uint8_t *apdu, unsigned apdu_len, + BACNET_OBJECT_ID *lastReceivedObjectIdentifier) { unsigned len = 0; @@ -80,24 +76,21 @@ int getevent_decode_service_request( /* Tag 0: Object ID - optional */ if (!decode_is_context_tag(&apdu[len++], 0)) return -1; - len += - decode_object_id(&apdu[len], &lastReceivedObjectIdentifier->type, - &lastReceivedObjectIdentifier->instance); + len += decode_object_id(&apdu[len], &lastReceivedObjectIdentifier->type, + &lastReceivedObjectIdentifier->instance); } - return (int) len; + return (int)len; } -int getevent_ack_encode_apdu_init( - uint8_t * apdu, - size_t max_apdu, - uint8_t invoke_id) +int getevent_ack_encode_apdu_init(uint8_t *apdu, size_t max_apdu, + uint8_t invoke_id) { - int apdu_len = 0; /* total length of the apdu, return value */ + int apdu_len = 0; /* total length of the apdu, return value */ if (apdu && (max_apdu >= 4)) { apdu[0] = PDU_TYPE_COMPLEX_ACK; /* complex ACK service */ - apdu[1] = invoke_id; /* original invoke id from request */ + apdu[1] = invoke_id; /* original invoke id from request */ apdu[2] = SERVICE_CONFIRMED_GET_EVENT_INFORMATION; apdu_len = 3; /* service ack follows */ @@ -109,13 +102,12 @@ int getevent_ack_encode_apdu_init( } int getevent_ack_encode_apdu_data( - uint8_t * apdu, - size_t max_apdu, - BACNET_GET_EVENT_INFORMATION_DATA * get_event_data) + uint8_t *apdu, size_t max_apdu, + BACNET_GET_EVENT_INFORMATION_DATA *get_event_data) { - int apdu_len = 0; /* total length of the apdu, return value */ + int apdu_len = 0; /* total length of the apdu, return value */ BACNET_GET_EVENT_INFORMATION_DATA *event_data; - unsigned i = 0; /* counter */ + unsigned i = 0; /* counter */ /* unused parameter */ max_apdu = max_apdu; @@ -123,40 +115,33 @@ int getevent_ack_encode_apdu_data( event_data = get_event_data; while (event_data) { /* Tag 0: objectIdentifier */ - apdu_len += - encode_context_object_id(&apdu[apdu_len], 0, - (int) event_data->objectIdentifier.type, + apdu_len += encode_context_object_id( + &apdu[apdu_len], 0, (int)event_data->objectIdentifier.type, event_data->objectIdentifier.instance); /* Tag 1: eventState */ - apdu_len += - encode_context_enumerated(&apdu[apdu_len], 1, - event_data->eventState); + apdu_len += encode_context_enumerated(&apdu[apdu_len], 1, + event_data->eventState); /* Tag 2: acknowledgedTransitions */ - apdu_len += - encode_context_bitstring(&apdu[apdu_len], 2, - &event_data->acknowledgedTransitions); + apdu_len += encode_context_bitstring( + &apdu[apdu_len], 2, &event_data->acknowledgedTransitions); /* Tag 3: eventTimeStamps */ apdu_len += encode_opening_tag(&apdu[apdu_len], 3); for (i = 0; i < 3; i++) { - apdu_len += - bacapp_encode_timestamp(&apdu[apdu_len], - &event_data->eventTimeStamps[i]); + apdu_len += bacapp_encode_timestamp( + &apdu[apdu_len], &event_data->eventTimeStamps[i]); } apdu_len += encode_closing_tag(&apdu[apdu_len], 3); /* Tag 4: notifyType */ - apdu_len += - encode_context_enumerated(&apdu[apdu_len], 4, - event_data->notifyType); + apdu_len += encode_context_enumerated(&apdu[apdu_len], 4, + event_data->notifyType); /* Tag 5: eventEnable */ - apdu_len += - encode_context_bitstring(&apdu[apdu_len], 5, - &event_data->eventEnable); + apdu_len += encode_context_bitstring(&apdu[apdu_len], 5, + &event_data->eventEnable); /* Tag 6: eventPriorities */ apdu_len += encode_opening_tag(&apdu[apdu_len], 6); for (i = 0; i < 3; i++) { - apdu_len += - encode_application_unsigned(&apdu[apdu_len], - event_data->eventPriorities[i]); + apdu_len += encode_application_unsigned( + &apdu[apdu_len], event_data->eventPriorities[i]); } apdu_len += encode_closing_tag(&apdu[apdu_len], 6); event_data = event_data->next; @@ -166,12 +151,10 @@ int getevent_ack_encode_apdu_data( return apdu_len; } -int getevent_ack_encode_apdu_end( - uint8_t * apdu, - size_t max_apdu, - bool moreEvents) +int getevent_ack_encode_apdu_end(uint8_t *apdu, size_t max_apdu, + bool moreEvents) { - int apdu_len = 0; /* total length of the apdu, return value */ + int apdu_len = 0; /* total length of the apdu, return value */ /* unused parameter */ max_apdu = max_apdu; @@ -184,17 +167,15 @@ int getevent_ack_encode_apdu_end( } int getevent_ack_decode_service_request( - uint8_t * apdu, - int apdu_len, /* total length of the apdu */ - BACNET_GET_EVENT_INFORMATION_DATA * get_event_data, - bool * moreEvents) + uint8_t *apdu, int apdu_len, /* total length of the apdu */ + BACNET_GET_EVENT_INFORMATION_DATA *get_event_data, bool *moreEvents) { uint8_t tag_number = 0; uint32_t len_value = 0; - int len = 0; /* total length of decodes */ - uint32_t enum_value = 0; /* for decoding */ + int len = 0; /* total length of decodes */ + uint32_t enum_value = 0; /* for decoding */ BACNET_GET_EVENT_INFORMATION_DATA *event_data; - unsigned i = 0; /* counter */ + unsigned i = 0; /* counter */ /* FIXME: check apdu_len against the len during decode */ event_data = get_event_data; @@ -206,21 +187,18 @@ int getevent_ack_decode_service_request( while (event_data) { /* Tag 0: objectIdentifier */ if (decode_is_context_tag(&apdu[len], 0)) { - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value); - len += - decode_object_id(&apdu[len], - &event_data->objectIdentifier.type, - &event_data->objectIdentifier.instance); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value); + len += decode_object_id(&apdu[len], + &event_data->objectIdentifier.type, + &event_data->objectIdentifier.instance); } else { return -1; } /* Tag 1: eventState */ if (decode_is_context_tag(&apdu[len], 1)) { - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value); len += decode_enumerated(&apdu[len], len_value, &enum_value); event_data->eventState = enum_value; } else { @@ -228,40 +206,34 @@ int getevent_ack_decode_service_request( } /* Tag 2: acknowledgedTransitions */ if (decode_is_context_tag(&apdu[len], 2)) { - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value); - len += - decode_bitstring(&apdu[len], len_value, - &event_data->acknowledgedTransitions); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value); + len += decode_bitstring(&apdu[len], len_value, + &event_data->acknowledgedTransitions); } else { return -1; } /* Tag 3: eventTimeStamps */ if (decode_is_opening_tag_number(&apdu[len], 3)) { - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value); for (i = 0; i < 3; i++) { - len += - bacapp_decode_timestamp(&apdu[len], - &event_data->eventTimeStamps[i]); + len += bacapp_decode_timestamp( + &apdu[len], &event_data->eventTimeStamps[i]); } } else { return -1; } if (decode_is_closing_tag_number(&apdu[len], 3)) { - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value); } else { return -1; } /* Tag 4: notifyType */ if (decode_is_context_tag(&apdu[len], 4)) { - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value); len += decode_enumerated(&apdu[len], len_value, &enum_value); event_data->notifyType = enum_value; } else { @@ -269,50 +241,42 @@ int getevent_ack_decode_service_request( } /* Tag 5: eventEnable */ if (decode_is_context_tag(&apdu[len], 5)) { - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value); - len += - decode_bitstring(&apdu[len], len_value, - &event_data->eventEnable); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value); + len += decode_bitstring(&apdu[len], len_value, + &event_data->eventEnable); } else { return -1; } /* Tag 6: eventPriorities */ if (decode_is_opening_tag_number(&apdu[len], 6)) { - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value); for (i = 0; i < 3; i++) { - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value); - len += - decode_unsigned(&apdu[len], len_value, - &event_data->eventPriorities[i]); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value); + len += decode_unsigned(&apdu[len], len_value, + &event_data->eventPriorities[i]); } } else { return -1; } if (decode_is_closing_tag_number(&apdu[len], 6)) { - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value); } else { return -1; } if (decode_is_closing_tag_number(&apdu[len], 0)) { - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value); event_data->next = NULL; } event_data = event_data->next; } if (decode_is_context_tag(&apdu[len], 1)) { - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value); if (len_value == 1) *moreEvents = decode_context_boolean(&apdu[len++]); else @@ -330,11 +294,8 @@ int getevent_ack_decode_service_request( #include #include "ctest.h" -int getevent_decode_apdu( - uint8_t * apdu, - unsigned apdu_len, - uint8_t * invoke_id, - BACNET_OBJECT_ID * lastReceivedObjectIdentifier) +int getevent_decode_apdu(uint8_t *apdu, unsigned apdu_len, uint8_t *invoke_id, + BACNET_OBJECT_ID *lastReceivedObjectIdentifier) { int len = 0; unsigned offset = 0; @@ -345,26 +306,24 @@ int getevent_decode_apdu( if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST) return -1; /* apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU); */ - *invoke_id = apdu[2]; /* invoke id - filled in by net layer */ + *invoke_id = apdu[2]; /* invoke id - filled in by net layer */ if (apdu[3] != SERVICE_CONFIRMED_GET_EVENT_INFORMATION) return -1; offset = 4; if (apdu_len > offset) { - len = - getevent_decode_service_request(&apdu[offset], apdu_len - offset, - lastReceivedObjectIdentifier); + len = getevent_decode_service_request(&apdu[offset], apdu_len - offset, + lastReceivedObjectIdentifier); } return len; } -int getevent_ack_decode_apdu( - uint8_t * apdu, - int apdu_len, /* total length of the apdu */ - uint8_t * invoke_id, - BACNET_GET_EVENT_INFORMATION_DATA * get_event_data, - bool * moreEvents) +int getevent_ack_decode_apdu(uint8_t *apdu, + int apdu_len, /* total length of the apdu */ + uint8_t *invoke_id, + BACNET_GET_EVENT_INFORMATION_DATA *get_event_data, + bool *moreEvents) { int len = 0; int offset = 0; @@ -379,18 +338,16 @@ int getevent_ack_decode_apdu( return -1; offset = 3; if (apdu_len > offset) { - len = - getevent_ack_decode_service_request(&apdu[offset], - apdu_len - offset, get_event_data, moreEvents); + len = getevent_ack_decode_service_request( + &apdu[offset], apdu_len - offset, get_event_data, moreEvents); } return len; } -void testGetEventInformationAck( - Test * pTest) +void testGetEventInformationAck(Test *pTest) { - uint8_t apdu[480] = { 0 }; + uint8_t apdu[480] = {0}; int len = 0; int apdu_len = 0; uint8_t invoke_id = 1; @@ -406,11 +363,11 @@ void testGetEventInformationAck( event_data.eventState = EVENT_STATE_NORMAL; bitstring_init(&event_data.acknowledgedTransitions); bitstring_set_bit(&event_data.acknowledgedTransitions, - TRANSITION_TO_OFFNORMAL, false); + TRANSITION_TO_OFFNORMAL, false); bitstring_set_bit(&event_data.acknowledgedTransitions, TRANSITION_TO_FAULT, - false); - bitstring_set_bit(&event_data.acknowledgedTransitions, - TRANSITION_TO_NORMAL, false); + false); + bitstring_set_bit(&event_data.acknowledgedTransitions, TRANSITION_TO_NORMAL, + false); for (i = 0; i < 3; i++) { event_data.eventTimeStamps[i].tag = TIME_STAMP_SEQUENCE; event_data.eventTimeStamps[i].value.sequenceNum = 0; @@ -429,37 +386,33 @@ 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; - len = getevent_ack_decode_apdu(&apdu[0], apdu_len, /* total length of the apdu */ + len = getevent_ack_decode_apdu( + &apdu[0], apdu_len, /* total length of the apdu */ &test_invoke_id, &test_event_data, &test_moreEvents); ct_test(pTest, len != -1); ct_test(pTest, test_invoke_id == invoke_id); - ct_test(pTest, - event_data.objectIdentifier.type == - test_event_data.objectIdentifier.type); - ct_test(pTest, - event_data.objectIdentifier.instance == - test_event_data.objectIdentifier.instance); + ct_test(pTest, event_data.objectIdentifier.type == + test_event_data.objectIdentifier.type); + ct_test(pTest, event_data.objectIdentifier.instance == + test_event_data.objectIdentifier.instance); ct_test(pTest, event_data.eventState == test_event_data.eventState); } -void testGetEventInformation( - Test * pTest) +void testGetEventInformation(Test *pTest) { - uint8_t apdu[480] = { 0 }; + uint8_t apdu[480] = {0}; int len = 0; int apdu_len = 0; uint8_t invoke_id = 128; @@ -469,30 +422,25 @@ void testGetEventInformation( lastReceivedObjectIdentifier.type = OBJECT_BINARY_INPUT; lastReceivedObjectIdentifier.instance = 12345; - len = - getevent_encode_apdu(&apdu[0], invoke_id, - &lastReceivedObjectIdentifier); + len = getevent_encode_apdu(&apdu[0], invoke_id, + &lastReceivedObjectIdentifier); ct_test(pTest, len != 0); apdu_len = len; - len = - getevent_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, - &test_lastReceivedObjectIdentifier); + len = getevent_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, + &test_lastReceivedObjectIdentifier); ct_test(pTest, len != -1); ct_test(pTest, test_invoke_id == invoke_id); - ct_test(pTest, - test_lastReceivedObjectIdentifier.type == - lastReceivedObjectIdentifier.type); - ct_test(pTest, - test_lastReceivedObjectIdentifier.instance == - lastReceivedObjectIdentifier.instance); + ct_test(pTest, test_lastReceivedObjectIdentifier.type == + lastReceivedObjectIdentifier.type); + ct_test(pTest, test_lastReceivedObjectIdentifier.instance == + lastReceivedObjectIdentifier.instance); return; } #ifdef TEST_GET_EVENT_INFORMATION -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -506,7 +454,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/src/iam.c b/src/iam.c index ed9dfb43..789de093 100755 --- a/src/iam.c +++ b/src/iam.c @@ -43,29 +43,23 @@ /** @file iam.c Encode/Decode I-Am service */ /* encode I-Am service */ -int iam_encode_apdu( - uint8_t * apdu, - uint32_t device_id, - unsigned max_apdu, - int segmentation, - uint16_t vendor_id) +int iam_encode_apdu(uint8_t *apdu, uint32_t device_id, unsigned max_apdu, + int segmentation, uint16_t vendor_id) { - int len = 0; /* length of each encoding */ - int apdu_len = 0; /* total length of the apdu, return value */ + int len = 0; /* length of each encoding */ + int apdu_len = 0; /* total length of the apdu, return value */ if (apdu) { apdu[0] = PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST; - apdu[1] = SERVICE_UNCONFIRMED_I_AM; /* service choice */ + apdu[1] = SERVICE_UNCONFIRMED_I_AM; /* service choice */ apdu_len = 2; - len = - encode_application_object_id(&apdu[apdu_len], OBJECT_DEVICE, - device_id); + len = encode_application_object_id(&apdu[apdu_len], OBJECT_DEVICE, + device_id); apdu_len += len; len = encode_application_unsigned(&apdu[apdu_len], max_apdu); apdu_len += len; - len = - encode_application_enumerated(&apdu[apdu_len], - (uint32_t) segmentation); + len = encode_application_enumerated(&apdu[apdu_len], + (uint32_t)segmentation); apdu_len += len; len = encode_application_unsigned(&apdu[apdu_len], vendor_id); apdu_len += len; @@ -74,24 +68,20 @@ int iam_encode_apdu( return apdu_len; } -int iam_decode_service_request( - uint8_t * apdu, - uint32_t * pDevice_id, - unsigned *pMax_apdu, - int *pSegmentation, - uint16_t * pVendor_id) +int iam_decode_service_request(uint8_t *apdu, uint32_t *pDevice_id, + unsigned *pMax_apdu, int *pSegmentation, + uint16_t *pVendor_id) { int len = 0; - int apdu_len = 0; /* total length of the apdu, return value */ - uint16_t object_type = 0; /* should be a Device Object */ + int apdu_len = 0; /* total length of the apdu, return value */ + uint16_t object_type = 0; /* should be a Device Object */ uint32_t object_instance = 0; uint8_t tag_number = 0; uint32_t len_value = 0; uint32_t decoded_value = 0; /* OBJECT ID - object id */ - len = - decode_tag_number_and_value(&apdu[apdu_len], &tag_number, &len_value); + len = decode_tag_number_and_value(&apdu[apdu_len], &tag_number, &len_value); apdu_len += len; if (tag_number != BACNET_APPLICATION_TAG_OBJECT_ID) return -1; @@ -102,18 +92,16 @@ int iam_decode_service_request( if (pDevice_id) *pDevice_id = object_instance; /* MAX APDU - unsigned */ - len = - decode_tag_number_and_value(&apdu[apdu_len], &tag_number, &len_value); + len = decode_tag_number_and_value(&apdu[apdu_len], &tag_number, &len_value); apdu_len += len; if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT) return -1; len = decode_unsigned(&apdu[apdu_len], len_value, &decoded_value); apdu_len += len; if (pMax_apdu) - *pMax_apdu = (unsigned) decoded_value; + *pMax_apdu = (unsigned)decoded_value; /* Segmentation - enumerated */ - len = - decode_tag_number_and_value(&apdu[apdu_len], &tag_number, &len_value); + len = decode_tag_number_and_value(&apdu[apdu_len], &tag_number, &len_value); apdu_len += len; if (tag_number != BACNET_APPLICATION_TAG_ENUMERATED) return -1; @@ -122,10 +110,9 @@ int iam_decode_service_request( if (decoded_value >= MAX_BACNET_SEGMENTATION) return -1; if (pSegmentation) - *pSegmentation = (int) decoded_value; + *pSegmentation = (int)decoded_value; /* Vendor ID - unsigned16 */ - len = - decode_tag_number_and_value(&apdu[apdu_len], &tag_number, &len_value); + len = decode_tag_number_and_value(&apdu[apdu_len], &tag_number, &len_value); apdu_len += len; if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT) return -1; @@ -134,7 +121,7 @@ int iam_decode_service_request( if (decoded_value > 0xFFFF) return -1; if (pVendor_id) - *pVendor_id = (uint16_t) decoded_value; + *pVendor_id = (uint16_t)decoded_value; return apdu_len; } @@ -144,14 +131,10 @@ int iam_decode_service_request( #include #include "ctest.h" -int iam_decode_apdu( - uint8_t * apdu, - uint32_t * pDevice_id, - unsigned *pMax_apdu, - int *pSegmentation, - uint16_t * pVendor_id) +int iam_decode_apdu(uint8_t *apdu, uint32_t *pDevice_id, unsigned *pMax_apdu, + int *pSegmentation, uint16_t *pVendor_id) { - int apdu_len = 0; /* total length of the apdu, return value */ + int apdu_len = 0; /* total length of the apdu, return value */ /* valid data? */ if (!apdu) @@ -161,17 +144,15 @@ int iam_decode_apdu( return -1; if (apdu[1] != SERVICE_UNCONFIRMED_I_AM) return -1; - apdu_len = - iam_decode_service_request(&apdu[2], pDevice_id, pMax_apdu, - pSegmentation, pVendor_id); + apdu_len = iam_decode_service_request(&apdu[2], pDevice_id, pMax_apdu, + pSegmentation, pVendor_id); return apdu_len; } -void testIAm( - Test * pTest) +void testIAm(Test *pTest) { - uint8_t apdu[480] = { 0 }; + uint8_t apdu[480] = {0}; int len = 0; uint32_t device_id = 42; unsigned max_apdu = 480; @@ -183,13 +164,11 @@ void testIAm( uint16_t test_vendor_id = 0; len = - iam_encode_apdu(&apdu[0], device_id, max_apdu, segmentation, - vendor_id); + iam_encode_apdu(&apdu[0], device_id, max_apdu, segmentation, vendor_id); ct_test(pTest, len != 0); - len = - iam_decode_apdu(&apdu[0], &test_device_id, &test_max_apdu, - &test_segmentation, &test_vendor_id); + len = iam_decode_apdu(&apdu[0], &test_device_id, &test_max_apdu, + &test_segmentation, &test_vendor_id); ct_test(pTest, len != -1); ct_test(pTest, test_device_id == device_id); @@ -199,8 +178,7 @@ void testIAm( } #ifdef TEST_IAM -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -212,7 +190,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/src/ihave.c b/src/ihave.c index 724e7532..30339bee 100644 --- a/src/ihave.c +++ b/src/ihave.c @@ -39,31 +39,28 @@ /** @file ihave.c Encode/Decode I-Have service */ -int ihave_encode_apdu( - uint8_t * apdu, - BACNET_I_HAVE_DATA * data) +int ihave_encode_apdu(uint8_t *apdu, BACNET_I_HAVE_DATA *data) { - int len = 0; /* length of each encoding */ - int apdu_len = 0; /* total length of the apdu, return value */ + int len = 0; /* length of each encoding */ + int apdu_len = 0; /* total length of the apdu, return value */ if (apdu && data) { apdu[0] = PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST; apdu[1] = SERVICE_UNCONFIRMED_I_HAVE; apdu_len = 2; /* deviceIdentifier */ - len = - encode_application_object_id(&apdu[apdu_len], - (int) data->device_id.type, data->device_id.instance); + len = encode_application_object_id(&apdu[apdu_len], + (int)data->device_id.type, + data->device_id.instance); apdu_len += len; /* objectIdentifier */ - len = - encode_application_object_id(&apdu[apdu_len], - (int) data->object_id.type, data->object_id.instance); + len = encode_application_object_id(&apdu[apdu_len], + (int)data->object_id.type, + data->object_id.instance); apdu_len += len; /* objectName */ - len = - encode_application_character_string(&apdu[apdu_len], - &data->object_name); + len = encode_application_character_string(&apdu[apdu_len], + &data->object_name); apdu_len += len; } @@ -73,44 +70,36 @@ int ihave_encode_apdu( #if BACNET_SVC_I_HAVE_A /* decode the service request only */ -int ihave_decode_service_request( - uint8_t * apdu, - unsigned apdu_len, - BACNET_I_HAVE_DATA * data) +int ihave_decode_service_request(uint8_t *apdu, unsigned apdu_len, + BACNET_I_HAVE_DATA *data) { int len = 0; uint8_t tag_number = 0; uint32_t len_value = 0; - uint16_t decoded_type = 0; /* for decoding */ + uint16_t decoded_type = 0; /* for decoding */ if (apdu_len && data) { /* deviceIdentifier */ - len += - decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); if (tag_number == BACNET_APPLICATION_TAG_OBJECT_ID) { - len += - decode_object_id(&apdu[len], &decoded_type, - &data->device_id.instance); + len += decode_object_id(&apdu[len], &decoded_type, + &data->device_id.instance); data->device_id.type = decoded_type; } else return -1; /* objectIdentifier */ - len += - decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); if (tag_number == BACNET_APPLICATION_TAG_OBJECT_ID) { - len += - decode_object_id(&apdu[len], &decoded_type, - &data->object_id.instance); + len += decode_object_id(&apdu[len], &decoded_type, + &data->object_id.instance); data->object_id.type = decoded_type; } else return -1; /* objectName */ - len += - decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); if (tag_number == BACNET_APPLICATION_TAG_CHARACTER_STRING) { - len += - decode_character_string(&apdu[len], len_value, - &data->object_name); + len += decode_character_string(&apdu[len], len_value, + &data->object_name); } else return -1; } else @@ -119,10 +108,8 @@ int ihave_decode_service_request( return len; } -int ihave_decode_apdu( - uint8_t * apdu, - unsigned apdu_len, - BACNET_I_HAVE_DATA * data) +int ihave_decode_apdu(uint8_t *apdu, unsigned apdu_len, + BACNET_I_HAVE_DATA *data) { int len = 0; @@ -144,11 +131,9 @@ int ihave_decode_apdu( #include #include "ctest.h" -void testIHaveData( - Test * pTest, - BACNET_I_HAVE_DATA * data) +void testIHaveData(Test *pTest, BACNET_I_HAVE_DATA *data) { - uint8_t apdu[480] = { 0 }; + uint8_t apdu[480] = {0}; int len = 0; int apdu_len = 0; BACNET_I_HAVE_DATA test_data; @@ -163,26 +148,25 @@ void testIHaveData( ct_test(pTest, test_data.device_id.instance == data->device_id.instance); ct_test(pTest, test_data.object_id.type == data->object_id.type); ct_test(pTest, test_data.object_id.instance == data->object_id.instance); - ct_test(pTest, characterstring_same(&test_data.object_name, - &data->object_name)); + ct_test(pTest, + characterstring_same(&test_data.object_name, &data->object_name)); } -void testIHave( - Test * pTest) +void testIHave(Test *pTest) { BACNET_I_HAVE_DATA data; characterstring_init_ansi(&data.object_name, "Patricia - my love!"); data.device_id.type = OBJECT_DEVICE; for (data.device_id.instance = 1; - data.device_id.instance <= BACNET_MAX_INSTANCE; - data.device_id.instance <<= 1) { + data.device_id.instance <= BACNET_MAX_INSTANCE; + data.device_id.instance <<= 1) { for (data.object_id.type = OBJECT_ANALOG_INPUT; - data.object_id.type < MAX_BACNET_OBJECT_TYPE; - data.object_id.type++) { + data.object_id.type < MAX_BACNET_OBJECT_TYPE; + data.object_id.type++) { for (data.object_id.instance = 1; - data.object_id.instance <= BACNET_MAX_INSTANCE; - data.object_id.instance <<= 1) { + data.object_id.instance <= BACNET_MAX_INSTANCE; + data.object_id.instance <<= 1) { testIHaveData(pTest, &data); } } @@ -190,8 +174,7 @@ void testIHave( } #ifdef TEST_I_HAVE -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -203,7 +186,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/src/indtext.c b/src/indtext.c index 2faee0b2..88516487 100644 --- a/src/indtext.c +++ b/src/indtext.c @@ -13,9 +13,9 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to + along with this program; if not, write to The Free Software Foundation, Inc. - 59 Temple Place - Suite 330 + 59 Temple Place - Suite 330 Boston, MA 02111-1307, USA. As a special exception, if other files instantiate templates or @@ -39,32 +39,28 @@ #if !defined(__BORLANDC__) && !defined(_MSC_VER) #include -int stricmp( - const char *s1, - const char *s2) +int stricmp(const char *s1, const char *s2) { unsigned char c1, c2; do { - c1 = (unsigned char) *s1; - c2 = (unsigned char) *s2; - c1 = (unsigned char) tolower(c1); - c2 = (unsigned char) tolower(c2); + c1 = (unsigned char)*s1; + c2 = (unsigned char)*s2; + c1 = (unsigned char)tolower(c1); + c2 = (unsigned char)tolower(c2); s1++; s2++; } while ((c1 == c2) && (c1 != '\0')); - return (int) c1 - c2; + return (int)c1 - c2; } #endif #if defined(_MSC_VER) #define stricmp _stricmp #endif -bool indtext_by_string( - INDTEXT_DATA * data_list, - const char *search_name, - unsigned *found_index) +bool indtext_by_string(INDTEXT_DATA *data_list, const char *search_name, + unsigned *found_index) { bool found = false; unsigned index = 0; @@ -87,10 +83,8 @@ bool indtext_by_string( } /* case insensitive version */ -bool indtext_by_istring( - INDTEXT_DATA * data_list, - const char *search_name, - unsigned *found_index) +bool indtext_by_istring(INDTEXT_DATA *data_list, const char *search_name, + unsigned *found_index) { bool found = false; unsigned index = 0; @@ -112,10 +106,9 @@ bool indtext_by_istring( return found; } -unsigned indtext_by_string_default( - INDTEXT_DATA * data_list, - const char *search_name, - unsigned default_index) +unsigned indtext_by_string_default(INDTEXT_DATA *data_list, + const char *search_name, + unsigned default_index) { unsigned index = 0; @@ -125,10 +118,9 @@ unsigned indtext_by_string_default( return index; } -unsigned indtext_by_istring_default( - INDTEXT_DATA * data_list, - const char *search_name, - unsigned default_index) +unsigned indtext_by_istring_default(INDTEXT_DATA *data_list, + const char *search_name, + unsigned default_index) { unsigned index = 0; @@ -138,10 +130,8 @@ unsigned indtext_by_istring_default( return index; } -const char *indtext_by_index_default( - INDTEXT_DATA * data_list, - unsigned index, - const char *default_string) +const char *indtext_by_index_default(INDTEXT_DATA *data_list, unsigned index, + const char *default_string) { const char *pString = NULL; @@ -159,29 +149,22 @@ const char *indtext_by_index_default( } const char *indtext_by_index_split_default( - INDTEXT_DATA * data_list, - unsigned index, - unsigned split_index, - const char *before_split_default_name, - const char *default_name) + INDTEXT_DATA *data_list, unsigned index, unsigned split_index, + const char *before_split_default_name, const char *default_name) { if (index < split_index) return indtext_by_index_default(data_list, index, - before_split_default_name); + before_split_default_name); else return indtext_by_index_default(data_list, index, default_name); } - -const char *indtext_by_index( - INDTEXT_DATA * data_list, - unsigned index) +const char *indtext_by_index(INDTEXT_DATA *data_list, unsigned index) { return indtext_by_index_default(data_list, index, NULL); } -unsigned indtext_count( - INDTEXT_DATA * data_list) +unsigned indtext_count(INDTEXT_DATA *data_list) { unsigned count = 0; /* return value */ @@ -198,17 +181,11 @@ unsigned indtext_count( #include #include "ctest.h" -static INDTEXT_DATA data_list[] = { - {1, "Joshua"}, - {2, "Mary"}, - {3, "Anna"}, - {4, "Christopher"}, - {5, "Patricia"}, - {0, NULL} -}; +static INDTEXT_DATA data_list[] = {{1, "Joshua"}, {2, "Mary"}, + {3, "Anna"}, {4, "Christopher"}, + {5, "Patricia"}, {0, NULL}}; -void testIndexText( - Test * pTest) +void testIndexText(Test *pTest) { unsigned i; /*counter */ const char *pString; @@ -224,7 +201,7 @@ void testIndexText( ct_test(pTest, valid == true); ct_test(pTest, index == i); ct_test(pTest, index == indtext_by_string_default(data_list, - pString, index)); + pString, index)); } } ct_test(pTest, indtext_count(data_list) == count); @@ -238,14 +215,13 @@ void testIndexText( ct_test(pTest, indtext_by_istring(data_list, "JOSHUA", NULL) == true); ct_test(pTest, indtext_by_istring(data_list, "joshua", NULL) == true); valid = indtext_by_istring(data_list, "ANNA", &index); - ct_test(pTest, index == indtext_by_istring_default(data_list, "ANNA", - index)); + ct_test(pTest, + index == indtext_by_istring_default(data_list, "ANNA", index)); } #endif #ifdef TEST_INDEX_TEXT -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -258,7 +234,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); diff --git a/src/key.c b/src/key.c index b0569f37..6cec9c13 100644 --- a/src/key.c +++ b/src/key.c @@ -13,9 +13,9 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to + along with this program; if not, write to The Free Software Foundation, Inc. - 59 Temple Place - Suite 330 + 59 Temple Place - Suite 330 Boston, MA 02111-1307, USA. As a special exception, if other files instantiate templates or @@ -44,8 +44,7 @@ #include "ctest.h" /* test the encode and decode macros */ -void testKeys( - Test * pTest) +void testKeys(Test *pTest) { int type, id; int decoded_type, decoded_id; @@ -65,12 +64,11 @@ void testKeys( } /* test the encode and decode macros */ -void testKeySample( - Test * pTest) +void testKeySample(Test *pTest) { int type, id; - int type_list[] = { 0, 1, KEY_TYPE_MAX / 2, KEY_TYPE_MAX - 1, -1 }; - int id_list[] = { 0, 1, KEY_ID_MAX / 2, KEY_ID_MAX - 1, -1 }; + int type_list[] = {0, 1, KEY_TYPE_MAX / 2, KEY_TYPE_MAX - 1, -1}; + int id_list[] = {0, 1, KEY_ID_MAX / 2, KEY_ID_MAX - 1, -1}; int type_index = 0; int id_index = 0; int decoded_type, decoded_id; @@ -96,22 +94,21 @@ void testKeySample( } #ifdef TEST_KEY -int main( - void) +int main(void) { Test *pTest; bool rc; pTest = ct_create("key", NULL); /* add the individual tests */ -/* rc = ct_addTestFunction(pTest, testKeys); */ -/* assert(rc); */ + /* rc = ct_addTestFunction(pTest, testKeys); */ + /* assert(rc); */ rc = ct_addTestFunction(pTest, testKeySample); assert(rc); /* run all the tests */ ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); /* completed testing - cleanup */ ct_destroy(pTest); diff --git a/src/keylist.c b/src/keylist.c index 38ec66c6..bb9896be 100644 --- a/src/keylist.c +++ b/src/keylist.c @@ -42,7 +42,7 @@ #include -#include "keylist.h" /* check for valid prototypes */ +#include "keylist.h" /* check for valid prototypes */ #ifndef FALSE #define FALSE 0 @@ -57,15 +57,13 @@ /******************************************************************** */ /* grab memory for a node */ -static struct Keylist_Node *NodeCreate( - void) +static struct Keylist_Node *NodeCreate(void) { return calloc(1, sizeof(struct Keylist_Node)); } /* grab memory for a list */ -static struct Keylist *KeylistCreate( - void) +static struct Keylist *KeylistCreate(void) { return calloc(1, sizeof(struct Keylist)); } @@ -73,13 +71,12 @@ static struct Keylist *KeylistCreate( /* check to see if the array is big enough for an addition */ /* or is too big when we are deleting and we can shrink */ /* returns TRUE if success, FALSE if failed */ -static int CheckArraySize( - OS_Keylist list) +static int CheckArraySize(OS_Keylist list) { - int new_size = 0; /* set it up so that no size change is the default */ - const int chunk = 8; /* minimum number of nodes to allocate memory for */ - struct Keylist_Node **new_array; /* new array of nodes, if needed */ - int i; /* counter */ + int new_size = 0; /* set it up so that no size change is the default */ + const int chunk = 8; /* minimum number of nodes to allocate memory for */ + struct Keylist_Node **new_array; /* new array of nodes, if needed */ + int i; /* counter */ if (!list) return FALSE; @@ -91,9 +88,8 @@ static int CheckArraySize( else if ((list->size > chunk) && (list->count < (list->size - chunk))) new_size = list->size - chunk; if (new_size) { - /* Allocate more room for node pointer array */ - new_array = calloc((size_t) new_size, sizeof(new_array)); + new_array = calloc((size_t)new_size, sizeof(new_array)); /* See if we got the memory we wanted */ if (!new_array) @@ -112,24 +108,21 @@ static int CheckArraySize( return TRUE; } - /* find the index of the key that we are looking for */ /* since it is sorted, we can optimize the search */ /* returns TRUE if found, and FALSE not found */ /* returns the found key and the index where it was found in parameters */ -/* If the key is not found, the nearest index from the bottom will be returned, */ +/* If the key is not found, the nearest index from the bottom will be returned, + */ /* allowing the ability to find where an key should go into the list. */ -static int FindIndex( - OS_Keylist list, - KEY key, - int *pIndex) +static int FindIndex(OS_Keylist list, KEY key, int *pIndex) { - struct Keylist_Node *node; /* holds the new node */ - int left = 0; /* the left branch of tree, beginning of list */ - int right = 0; /* the right branch on the tree, end of list */ - int index = 0; /* our current search place in the array */ - KEY current_key = 0; /* place holder for current node key */ - int status = FALSE; /* return value */ + struct Keylist_Node *node; /* holds the new node */ + int left = 0; /* the left branch of tree, beginning of list */ + int right = 0; /* the right branch on the tree, end of list */ + int index = 0; /* our current search place in the array */ + KEY current_key = 0; /* place holder for current node key */ + int status = FALSE; /* return value */ if (!list || !list->array || !list->count) { *pIndex = 0; return (FALSE); @@ -137,7 +130,6 @@ static int FindIndex( right = list->count - 1; /* assume that the list is sorted */ do { - /* A binary search */ index = (left + right) / 2; node = list->array[index]; @@ -149,15 +141,13 @@ static int FindIndex( else left = index + 1; - } - while ((key != current_key) && (left <= right)); + } while ((key != current_key) && (left <= right)); if (key == current_key) { status = TRUE; *pIndex = index; } else { - /* where the index should be */ if (key > current_key) *pIndex = index + 1; @@ -168,24 +158,20 @@ static int FindIndex( return (status); } - /******************************************************************** */ /* list data functions */ /******************************************************************** */ /* inserts a node into its sorted position */ -int Keylist_Data_Add( - OS_Keylist list, - KEY key, - void *data) +int Keylist_Data_Add(OS_Keylist list, KEY key, void *data) { - struct Keylist_Node *node; /* holds the new node */ - int index = -1; /* return value */ - int i; /* counts through the array */ + struct Keylist_Node *node; /* holds the new node */ + int index = -1; /* return value */ + int i; /* counts through the array */ if (list && CheckArraySize(list)) { /* figure out where to put the new node */ if (list->count) { - (void) FindIndex(list, key, &index); + (void)FindIndex(list, key, &index); /* Add to the beginning of the list */ if (index < 0) index = 0; @@ -218,9 +204,7 @@ int Keylist_Data_Add( /* deletes a node specified by its index */ /* returns the data from the node */ -void *Keylist_Data_Delete_By_Index( - OS_Keylist list, - int index) +void *Keylist_Data_Delete_By_Index(OS_Keylist list, int index) { struct Keylist_Node *node; void *data = NULL; @@ -233,17 +217,15 @@ void *Keylist_Data_Delete_By_Index( /* move the nodes to account for the deleted one */ if (list->count == 1) { - /* There is no node shifting to do */ } /* We are the last one */ else if (index == (list->count - 1)) { - /* There is no node shifting to do */ } /* Move all the nodes down one */ else { - int i; /* counter */ + int i; /* counter */ int count = list->count - 1; for (i = index; i < count; i++) { list->array[i] = list->array[i + 1]; @@ -254,20 +236,17 @@ void *Keylist_Data_Delete_By_Index( free(node); /* potentially reduce the size of the array */ - (void) CheckArraySize(list); + (void)CheckArraySize(list); } return (data); } - /* deletes a node specified by its key */ /* returns the data from the node */ -void *Keylist_Data_Delete( - OS_Keylist list, - KEY key) +void *Keylist_Data_Delete(OS_Keylist list, KEY key) { - void *data = NULL; /* return value */ - int index; /* where the node is in the array */ + void *data = NULL; /* return value */ + int index; /* where the node is in the array */ if (list) { if (FindIndex(list, key, &index)) @@ -278,11 +257,10 @@ void *Keylist_Data_Delete( } /* returns the data from last node, and removes it from the list */ -void *Keylist_Data_Pop( - OS_Keylist list) +void *Keylist_Data_Pop(OS_Keylist list) { - void *data = NULL; /* return value */ - int index; /* position in the array */ + void *data = NULL; /* return value */ + int index; /* position in the array */ if (list && list->count) { index = list->count - 1; @@ -293,12 +271,10 @@ void *Keylist_Data_Pop( } /* returns the data from the node specified by key */ -void *Keylist_Data( - OS_Keylist list, - KEY key) +void *Keylist_Data(OS_Keylist list, KEY key) { struct Keylist_Node *node = NULL; - int index = 0; /* used to look up the index of node */ + int index = 0; /* used to look up the index of node */ if (list && list->array && list->count) { if (FindIndex(list, key, &index)) @@ -309,11 +285,9 @@ void *Keylist_Data( } /* returns the index from the node specified by key */ -int Keylist_Index( - OS_Keylist list, - KEY key) +int Keylist_Index(OS_Keylist list, KEY key) { - int index = -1; /* used to look up the index of node */ + int index = -1; /* used to look up the index of node */ if (list && list->array && list->count) { if (!FindIndex(list, key, &index)) { @@ -324,11 +298,8 @@ int Keylist_Index( return index; } - /* returns the data specified by index */ -void *Keylist_Data_Index( - OS_Keylist list, - int index) +void *Keylist_Data_Index(OS_Keylist list, int index) { struct Keylist_Node *node = NULL; @@ -340,11 +311,9 @@ void *Keylist_Data_Index( } /* return the key at the given index */ -KEY Keylist_Key( - OS_Keylist list, - int index) +KEY Keylist_Key(OS_Keylist list, int index) { - KEY key = 0; /* return value */ + KEY key = 0; /* return value */ struct Keylist_Node *node; if (list && list->array && list->count && (index >= 0) && @@ -358,9 +327,7 @@ KEY Keylist_Key( } /* returns the next empty key from the list */ -KEY Keylist_Next_Empty_Key( - OS_Keylist list, - KEY key) +KEY Keylist_Next_Empty_Key(OS_Keylist list, KEY key) { int index; @@ -376,8 +343,7 @@ KEY Keylist_Next_Empty_Key( } /* return the number of nodes in this list */ -int Keylist_Count( - OS_Keylist list) +int Keylist_Count(OS_Keylist list) { return list->count; } @@ -387,8 +353,7 @@ int Keylist_Count( /******************************************************************** */ /* returns head of the list or NULL on failure. */ -OS_Keylist Keylist_Create( - void) +OS_Keylist Keylist_Create(void) { struct Keylist *list; @@ -400,13 +365,12 @@ OS_Keylist Keylist_Create( } /* delete specified list */ -void Keylist_Delete( - OS_Keylist list) -{ /* list number to be deleted */ +void Keylist_Delete(OS_Keylist list) +{ /* list number to be deleted */ if (list) { /* clean out the list */ while (list->count) { - (void) Keylist_Data_Delete_By_Index(list, 0); + (void)Keylist_Data_Delete_By_Index(list, 0); } if (list->array) free(list->array); @@ -423,8 +387,7 @@ void Keylist_Delete( #include "ctest.h" /* test the FIFO */ -static void testKeyListFIFO( - Test * pTest) +static void testKeyListFIFO(Test *pTest) { OS_Keylist list; KEY key; @@ -467,8 +430,7 @@ static void testKeyListFIFO( } /* test the FILO */ -static void testKeyListFILO( - Test * pTest) +static void testKeyListFILO(Test *pTest) { OS_Keylist list; KEY key; @@ -514,8 +476,7 @@ static void testKeyListFILO( return; } -static void testKeyListDataKey( - Test * pTest) +static void testKeyListDataKey(Test *pTest) { OS_Keylist list; KEY key; @@ -587,16 +548,14 @@ static void testKeyListDataKey( /* cleanup */ do { data = Keylist_Data_Pop(list); - } - while (data); + } while (data); Keylist_Delete(list); return; } -static void testKeyListDataIndex( - Test * pTest) +static void testKeyListDataIndex(Test *pTest) { OS_Keylist list; KEY key; @@ -617,7 +576,6 @@ static void testKeyListDataIndex( index = Keylist_Data_Add(list, key, data3); ct_test(pTest, index == 0); - ct_test(pTest, Keylist_Count(list) == 3); /* look at the data */ @@ -658,8 +616,7 @@ static void testKeyListDataIndex( /* cleanup */ do { data = Keylist_Data_Pop(list); - } - while (data); + } while (data); Keylist_Delete(list); @@ -667,8 +624,7 @@ static void testKeyListDataIndex( } /* test access of a lot of entries */ -static void testKeyListLarge( - Test * pTest) +static void testKeyListLarge(Test *pTest) { int data1 = 42; int *data; @@ -683,7 +639,6 @@ static void testKeyListLarge( for (key = 0; key < num_keys; key++) { index = Keylist_Data_Add(list, key, &data1); - } for (key = 0; key < num_keys; key++) { data = Keylist_Data(list, key); @@ -699,8 +654,7 @@ static void testKeyListLarge( } /* test access of a lot of entries */ -void testKeyList( - Test * pTest) +void testKeyList(Test *pTest) { bool rc; @@ -718,8 +672,7 @@ void testKeyList( } #ifdef TEST_KEYLIST -int main( - void) +int main(void) { Test *pTest; @@ -727,7 +680,7 @@ int main( testKeyList(pTest); ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); diff --git a/src/lighting.c b/src/lighting.c index 66918ae4..0fceb026 100644 --- a/src/lighting.c +++ b/src/lighting.c @@ -42,7 +42,6 @@ /** @file lighting.c Manipulate BACnet lighting command values */ - /** * Encodes into bytes from the lighting-command structure * @@ -51,45 +50,37 @@ * * @return number of bytes encoded, or 0 if unable to encode. */ -int lighting_command_encode( - uint8_t * apdu, - BACNET_LIGHTING_COMMAND * data) +int lighting_command_encode(uint8_t *apdu, BACNET_LIGHTING_COMMAND *data) { - int apdu_len = 0; /* total length of the apdu, return value */ - int len = 0; /* total length of the apdu, return value */ + int apdu_len = 0; /* total length of the apdu, return value */ + int len = 0; /* total length of the apdu, return value */ if (apdu) { - len = encode_context_enumerated(&apdu[apdu_len], 0, - data->operation); + len = encode_context_enumerated(&apdu[apdu_len], 0, data->operation); apdu_len += len; /* optional target-level */ if (data->use_target_level) { - len = encode_context_real(&apdu[apdu_len], 1, - data->target_level); + len = encode_context_real(&apdu[apdu_len], 1, data->target_level); apdu_len += len; } /* optional ramp-rate */ if (data->use_ramp_rate) { - len = encode_context_real(&apdu[apdu_len], 2, - data->ramp_rate); + len = encode_context_real(&apdu[apdu_len], 2, data->ramp_rate); apdu_len += len; } /* optional step increment */ if (data->use_step_increment) { - len = encode_context_real(&apdu[apdu_len], 3, - data->step_increment); + len = encode_context_real(&apdu[apdu_len], 3, data->step_increment); apdu_len += len; } /* optional fade time */ if (data->use_fade_time) { - len = encode_context_unsigned(&apdu[apdu_len], 4, - data->fade_time); + len = encode_context_unsigned(&apdu[apdu_len], 4, data->fade_time); apdu_len += len; } /* optional priority */ if (data->use_priority) { - len = encode_context_unsigned(&apdu[apdu_len], 5, - data->priority); + len = encode_context_unsigned(&apdu[apdu_len], 5, data->priority); apdu_len += len; } } @@ -107,10 +98,8 @@ int lighting_command_encode( * * @return number of bytes encoded, or 0 if unable to encode. */ -int lighting_command_encode_context( - uint8_t * apdu, - uint8_t tag_number, - BACNET_LIGHTING_COMMAND * value) +int lighting_command_encode_context(uint8_t *apdu, uint8_t tag_number, + BACNET_LIGHTING_COMMAND *value) { int apdu_len = 0; @@ -130,10 +119,8 @@ int lighting_command_encode_context( * * @return number of bytes encoded */ -int lighting_command_decode( - uint8_t * apdu, - unsigned apdu_max_len, - BACNET_LIGHTING_COMMAND * data) +int lighting_command_decode(uint8_t *apdu, unsigned apdu_max_len, + BACNET_LIGHTING_COMMAND *data) { int len = 0; int apdu_len = 0; @@ -148,9 +135,8 @@ int lighting_command_decode( /* Tag 0: operation */ if (!decode_is_context_tag(&apdu[apdu_len], 0)) return BACNET_STATUS_ERROR; - len = - decode_tag_number_and_value(&apdu[apdu_len], &tag_number, - &len_value_type); + len = decode_tag_number_and_value(&apdu[apdu_len], &tag_number, + &len_value_type); apdu_len += len; len = decode_enumerated(&apdu[apdu_len], len_value_type, &unsigned_value); @@ -160,9 +146,8 @@ int lighting_command_decode( apdu_len += len; /* Tag 1: target-level - OPTIONAL */ if (decode_is_context_tag(&apdu[apdu_len], 1)) { - len = - decode_tag_number_and_value(&apdu[apdu_len], &tag_number, - &len_value_type); + len = decode_tag_number_and_value(&apdu[apdu_len], &tag_number, + &len_value_type); apdu_len += len; len = decode_real(&apdu[apdu_len], &real_value); data->target_level = real_value; @@ -173,9 +158,8 @@ int lighting_command_decode( } /* Tag 2: ramp-rate - OPTIONAL */ if (decode_is_context_tag(&apdu[apdu_len], 2)) { - len = - decode_tag_number_and_value(&apdu[apdu_len], &tag_number, - &len_value_type); + len = decode_tag_number_and_value(&apdu[apdu_len], &tag_number, + &len_value_type); apdu_len += len; len = decode_real(&apdu[apdu_len], &real_value); data->ramp_rate = real_value; @@ -185,9 +169,8 @@ int lighting_command_decode( } /* Tag 3: step-increment - OPTIONAL */ if (decode_is_context_tag(&apdu[apdu_len], 3)) { - len = - decode_tag_number_and_value(&apdu[apdu_len], &tag_number, - &len_value_type); + len = decode_tag_number_and_value(&apdu[apdu_len], &tag_number, + &len_value_type); apdu_len += len; len = decode_real(&apdu[apdu_len], &real_value); data->step_increment = real_value; @@ -197,12 +180,11 @@ int lighting_command_decode( } /* Tag 4: fade-time - OPTIONAL */ if (decode_is_context_tag(&apdu[apdu_len], 4)) { - len = - decode_tag_number_and_value(&apdu[apdu_len], &tag_number, - &len_value_type); + len = decode_tag_number_and_value(&apdu[apdu_len], &tag_number, + &len_value_type); apdu_len += len; len = decode_unsigned(&apdu[apdu_len], len_value_type, - &unsigned_value); + &unsigned_value); data->fade_time = unsigned_value; data->use_fade_time = true; } else { @@ -210,12 +192,11 @@ int lighting_command_decode( } /* Tag 5: priority - OPTIONAL */ if (decode_is_context_tag(&apdu[apdu_len], 4)) { - len = - decode_tag_number_and_value(&apdu[apdu_len], &tag_number, - &len_value_type); + len = decode_tag_number_and_value(&apdu[apdu_len], &tag_number, + &len_value_type); apdu_len += len; len = decode_unsigned(&apdu[apdu_len], len_value_type, - &unsigned_value); + &unsigned_value); data->priority = unsigned_value; data->use_priority = true; } else { @@ -234,9 +215,8 @@ int lighting_command_decode( * * @return true if copy succeeded */ -bool lighting_command_copy( - BACNET_LIGHTING_COMMAND * dst, - BACNET_LIGHTING_COMMAND * src) +bool lighting_command_copy(BACNET_LIGHTING_COMMAND *dst, + BACNET_LIGHTING_COMMAND *src) { bool status = false; @@ -266,9 +246,8 @@ bool lighting_command_copy( * * @return true if lighting-commands are the same for values in-use */ -bool lighting_command_same( - BACNET_LIGHTING_COMMAND * dst, - BACNET_LIGHTING_COMMAND * src) +bool lighting_command_same(BACNET_LIGHTING_COMMAND *dst, + BACNET_LIGHTING_COMMAND *src) { bool status = false; @@ -284,20 +263,17 @@ bool lighting_command_same( (dst->target_level != src->target_level)) { status = false; } - if ((dst->use_ramp_rate) && - (dst->ramp_rate != src->ramp_rate)) { + if ((dst->use_ramp_rate) && (dst->ramp_rate != src->ramp_rate)) { status = false; } if ((dst->use_step_increment) && (dst->step_increment != src->step_increment)) { status = false; } - if ((dst->use_fade_time) && - (dst->fade_time != src->fade_time)) { + if ((dst->use_fade_time) && (dst->fade_time != src->fade_time)) { status = false; } - if ((dst->use_priority) && - (dst->priority != src->priority)) { + if ((dst->use_priority) && (dst->priority != src->priority)) { status = false; } } @@ -311,9 +287,7 @@ bool lighting_command_same( #include #include "ctest.h" -void testBACnetLightingCommand( - Test * pTest, - BACNET_LIGHTING_COMMAND *data) +void testBACnetLightingCommand(Test *pTest, BACNET_LIGHTING_COMMAND *data) { bool status = false; BACNET_LIGHTING_COMMAND test_data; @@ -335,8 +309,7 @@ void testBACnetLightingCommand( status = lighting_command_same(&test_data, data); } -void testBACnetLightingCommandAll( - Test * pTest) +void testBACnetLightingCommandAll(Test *pTest) { BACNET_LIGHTING_COMMAND data; @@ -362,8 +335,7 @@ void testBACnetLightingCommandAll( } #ifdef TEST_LIGHTING_COMMAND -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -375,7 +347,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/src/lso.c b/src/lso.c index 6ad4d27f..8a77a317 100644 --- a/src/lso.c +++ b/src/lso.c @@ -37,13 +37,10 @@ /** @file lso.c BACnet Life Safety Operation encode/decode */ -int lso_encode_apdu( - uint8_t * apdu, - uint8_t invoke_id, - BACNET_LSO_DATA * data) +int lso_encode_apdu(uint8_t *apdu, uint8_t invoke_id, BACNET_LSO_DATA *data) { - int len = 0; /* length of each encoding */ - int apdu_len = 0; /* total length of the apdu, return value */ + int len = 0; /* length of each encoding */ + int apdu_len = 0; /* total length of the apdu, return value */ if (apdu && data) { apdu[0] = PDU_TYPE_CONFIRMED_SERVICE_REQUEST; @@ -55,9 +52,8 @@ int lso_encode_apdu( len = encode_context_unsigned(&apdu[apdu_len], 0, data->processId); apdu_len += len; /* tag 1 - requestingSource */ - len = - encode_context_character_string(&apdu[apdu_len], 1, - &data->requestingSrc); + len = encode_context_character_string(&apdu[apdu_len], 1, + &data->requestingSrc); apdu_len += len; /* Operation @@ -68,9 +64,9 @@ int lso_encode_apdu( Object ID */ - len = - encode_context_object_id(&apdu[apdu_len], 3, - (int) data->targetObject.type, data->targetObject.instance); + len = encode_context_object_id(&apdu[apdu_len], 3, + (int)data->targetObject.type, + data->targetObject.instance); apdu_len += len; } @@ -78,48 +74,43 @@ int lso_encode_apdu( return apdu_len; } -int lso_decode_service_request( - uint8_t * apdu, - unsigned apdu_len, - BACNET_LSO_DATA * data) +int lso_decode_service_request(uint8_t *apdu, unsigned apdu_len, + BACNET_LSO_DATA *data) { - int len = 0; /* return value */ - int section_length = 0; /* length returned from decoding */ - uint32_t operation = 0; /* handles decoded value */ + int len = 0; /* return value */ + int section_length = 0; /* length returned from decoding */ + uint32_t operation = 0; /* handles decoded value */ /* check for value pointers */ if (apdu_len && data) { /* Tag 0: Object ID */ - if ((section_length = - decode_context_unsigned(&apdu[len], 0, - &data->processId)) == -1) { + if ((section_length = decode_context_unsigned( + &apdu[len], 0, &data->processId)) == -1) { + return -1; + } + len += section_length; + + if ((section_length = decode_context_character_string( + &apdu[len], 1, &data->requestingSrc)) == -1) { return -1; } len += section_length; if ((section_length = - decode_context_character_string(&apdu[len], 1, - &data->requestingSrc)) == -1) { + decode_context_enumerated(&apdu[len], 2, &operation)) == -1) { return -1; } - len += section_length; - - if ((section_length = - decode_context_enumerated(&apdu[len], 2, &operation)) == -1) { - return -1; - } - data->operation = (BACNET_LIFE_SAFETY_OPERATION) operation; + data->operation = (BACNET_LIFE_SAFETY_OPERATION)operation; len += section_length; /* ** This is an optional parameter, so dont fail if it doesnt exist */ if (decode_is_context_tag(&apdu[len], 3)) { - if ((section_length = - decode_context_object_id(&apdu[len], 3, - &data->targetObject.type, - &data->targetObject.instance)) == -1) { + if ((section_length = decode_context_object_id( + &apdu[len], 3, &data->targetObject.type, + &data->targetObject.instance)) == -1) { return -1; } len += section_length; @@ -128,7 +119,6 @@ int lso_decode_service_request( data->targetObject.instance = 0; } return len; - } return 0; @@ -140,8 +130,7 @@ int lso_decode_service_request( #include "ctest.h" #include "bacapp.h" -void testLSO( - Test * pTest) +void testLSO(Test *pTest) { uint8_t apdu[1000]; int len; @@ -151,7 +140,6 @@ void testLSO( memset(&rxdata, 0, sizeof(rxdata)); - characterstring_init_ansi(&data.requestingSrc, "foobar"); data.operation = LIFE_SAFETY_OP_RESET; data.processId = 0x1234; @@ -167,13 +155,11 @@ void testLSO( ct_test(pTest, data.targetObject.instance == rxdata.targetObject.instance); ct_test(pTest, data.targetObject.type == rxdata.targetObject.type); ct_test(pTest, memcmp(data.requestingSrc.value, rxdata.requestingSrc.value, - rxdata.requestingSrc.length) == 0); + rxdata.requestingSrc.length) == 0); } #ifdef TEST_LSO -int main( - int argc, - char *argv[]) +int main(int argc, char *argv[]) { Test *pTest; bool rc; @@ -185,7 +171,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/src/memcopy.c b/src/memcopy.c index bb7d93d6..420d8207 100644 --- a/src/memcopy.c +++ b/src/memcopy.c @@ -1,87 +1,79 @@ /** -* @file -* @author Steve Karg -* @date 2008 -* @section LICENSE -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to: -* The Free Software Foundation, Inc. -* 59 Temple Place - Suite 330 -* Boston, MA 02111-1307 -* USA. -* -* As a special exception, if other files instantiate templates or -* use macros or inline functions from this file, or you compile -* this file and link it with other works to produce a work based -* on this file, this file does not by itself cause the resulting -* work to be covered by the GNU General Public License. However -* the source code for this file must still be made available in -* accordance with section (3) of the GNU General Public License. -* -* This exception does not invalidate any other reasons why a work -* based on this file might be covered by the GNU General Public -* License. -* -* @section DESCRIPTION -* -* Memory copy functions for deeply embedded system. The functions -* are used with a buffer, the buffer offset, the sizeof the buffer, -* and the number of bytes to copy to the buffer. -*/ + * @file + * @author Steve Karg + * @date 2008 + * @section LICENSE + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to: + * The Free Software Foundation, Inc. + * 59 Temple Place - Suite 330 + * Boston, MA 02111-1307 + * USA. + * + * As a special exception, if other files instantiate templates or + * use macros or inline functions from this file, or you compile + * this file and link it with other works to produce a work based + * on this file, this file does not by itself cause the resulting + * work to be covered by the GNU General Public License. However + * the source code for this file must still be made available in + * accordance with section (3) of the GNU General Public License. + * + * This exception does not invalidate any other reasons why a work + * based on this file might be covered by the GNU General Public + * License. + * + * @section DESCRIPTION + * + * Memory copy functions for deeply embedded system. The functions + * are used with a buffer, the buffer offset, the sizeof the buffer, + * and the number of bytes to copy to the buffer. + */ #include #include "memcopy.h" #include /** -* Tests to see if the number of bytes is available from an offset -* given the maximum sizeof a buffer. -* -* @param offset - offset into a buffer -* @param max - maximum sizeof a buffer -* @param len - number of bytes to add to the buffer starting at offset. -* -* @return True if there is enough space to copy len bytes. -*/ -bool memcopylen( - size_t offset, - size_t max, - size_t len) + * Tests to see if the number of bytes is available from an offset + * given the maximum sizeof a buffer. + * + * @param offset - offset into a buffer + * @param max - maximum sizeof a buffer + * @param len - number of bytes to add to the buffer starting at offset. + * + * @return True if there is enough space to copy len bytes. + */ +bool memcopylen(size_t offset, size_t max, size_t len) { return ((offset + len) <= max); } -#if defined (MEMCOPY_SIMPLE) +#if defined(MEMCOPY_SIMPLE) /** -* Copy len bytes from src to offset of dest if there is enough space -* in a buffer of max bytes. -* -* @param dest - pointer to the destination buffer -* @param src - pointer to the source buffer -* @param offset - offset into the destination buffer -* @param max - maximum sizeof the destination buffer -* @param len - number of bytes to add to the destination buffer -* starting at offset. -* -* @return returns zero if there is not enough space, or returns -* the number of bytes copied. -*/ -size_t memcopy( - void *dest, - void *src, - size_t offset, - size_t len, - size_t max) + * Copy len bytes from src to offset of dest if there is enough space + * in a buffer of max bytes. + * + * @param dest - pointer to the destination buffer + * @param src - pointer to the source buffer + * @param offset - offset into the destination buffer + * @param max - maximum sizeof the destination buffer + * @param len - number of bytes to add to the destination buffer + * starting at offset. + * + * @return returns zero if there is not enough space, or returns + * the number of bytes copied. + */ +size_t memcopy(void *dest, void *src, size_t offset, size_t len, size_t max) { size_t i; size_t copy_len = 0; @@ -100,28 +92,26 @@ size_t memcopy( } #else /** -* Copy len bytes from src to offset of dest if there is enough space -* in a buffer of max bytes. -* -* @param dest - pointer to the destination buffer -* @param src - pointer to the source buffer -* @param offset - offset into the destination buffer -* @param max - maximum sizeof the destination buffer -* @param len - number of bytes to add to the destination buffer -* starting at offset. -* -* @return returns zero if there is not enough space, or returns -* the number of bytes copied. -*/ -size_t memcopy( - void *dest, - void *src, - size_t offset, /* where in dest to put the data */ - size_t len, /* amount of data to copy */ - size_t max) -{ /* total size of destination */ + * Copy len bytes from src to offset of dest if there is enough space + * in a buffer of max bytes. + * + * @param dest - pointer to the destination buffer + * @param src - pointer to the source buffer + * @param offset - offset into the destination buffer + * @param max - maximum sizeof the destination buffer + * @param len - number of bytes to add to the destination buffer + * starting at offset. + * + * @return returns zero if there is not enough space, or returns + * the number of bytes copied. + */ +size_t memcopy(void *dest, void *src, + size_t offset, /* where in dest to put the data */ + size_t len, /* amount of data to copy */ + size_t max) +{ /* total size of destination */ if (memcopylen(offset, max, len)) { - memcpy(&((char *) dest)[offset], src, len); + memcpy(&((char *)dest)[offset], src, len); return (len); } @@ -135,8 +125,7 @@ size_t memcopy( #include "ctest.h" -void test_memcopy( - Test * pTest) +void test_memcopy(Test *pTest) { char *data1 = "Joshua"; char *data2 = "Anna"; @@ -149,15 +138,13 @@ void test_memcopy( ct_test(pTest, memcmp(&buffer[0], &data1[0], len) == 0); len = memcopy(&buffer[0], &data2[0], len, sizeof(data2), sizeof(buffer)); ct_test(pTest, len == sizeof(data2)); - len = - memcopy(&buffer[0], &big_buffer[0], 1, sizeof(big_buffer), - sizeof(buffer)); + len = memcopy(&buffer[0], &big_buffer[0], 1, sizeof(big_buffer), + sizeof(buffer)); ct_test(pTest, len == 0); } #ifdef TEST_MEM_COPY -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -170,7 +157,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); diff --git a/src/mstp.c b/src/mstp.c index 7fb0d426..b60508f1 100644 --- a/src/mstp.c +++ b/src/mstp.c @@ -70,9 +70,7 @@ #if defined(PRINT_ENABLED_RECEIVE) #define printf_receive debug_printf #else -static inline void printf_receive( - const char *format, - ...) +static inline void printf_receive(const char *format, ...) { format = format; } @@ -81,9 +79,7 @@ static inline void printf_receive( #if defined(PRINT_ENABLED_RECEIVE_DATA) #define printf_receive_data debug_printf #else -static inline void printf_receive_data( - const char *format, - ...) +static inline void printf_receive_data(const char *format, ...) { format = format; } @@ -92,9 +88,7 @@ static inline void printf_receive_data( #if defined(PRINT_ENABLED_RECEIVE_ERRORS) #define printf_receive_error debug_printf #else -static inline void printf_receive_error( - const char *format, - ...) +static inline void printf_receive_error(const char *format, ...) { format = format; } @@ -103,9 +97,7 @@ static inline void printf_receive_error( #if defined(PRINT_ENABLED_MASTER) #define printf_master debug_printf #else -static inline void printf_master( - const char *format, - ...) +static inline void printf_master(const char *format, ...) { format = format; } @@ -166,17 +158,18 @@ static inline void printf_master( #endif /* we need to be able to increment without rolling over */ -#define INCREMENT_AND_LIMIT_UINT8(x) {if (x < 0xFF) x++;} +#define INCREMENT_AND_LIMIT_UINT8(x) \ + { \ + if (x < 0xFF) \ + x++; \ + } -bool MSTP_Line_Active( - volatile struct mstp_port_struct_t *mstp_port) +bool MSTP_Line_Active(volatile struct mstp_port_struct_t *mstp_port) { return (mstp_port->EventCount > Nmin_octets); } -void MSTP_Fill_BACnet_Address( - BACNET_ADDRESS * src, - uint8_t mstp_address) +void MSTP_Fill_BACnet_Address(BACNET_ADDRESS *src, uint8_t mstp_address) { int i = 0; @@ -200,17 +193,17 @@ void MSTP_Fill_BACnet_Address( } uint16_t MSTP_Create_Frame( - uint8_t * buffer, /* where frame is loaded */ - uint16_t buffer_len, /* amount of space available */ - uint8_t frame_type, /* type of frame to send - see defines */ - uint8_t destination, /* destination address */ - uint8_t source, /* source address */ - uint8_t * data, /* any data to be sent - may be null */ + uint8_t *buffer, /* where frame is loaded */ + uint16_t buffer_len, /* amount of space available */ + uint8_t frame_type, /* type of frame to send - see defines */ + uint8_t destination, /* destination address */ + uint8_t source, /* source address */ + uint8_t *data, /* any data to be sent - may be null */ uint16_t data_len) -{ /* number of bytes of data (up to 501) */ - uint8_t crc8 = 0xFF; /* used to calculate the crc value */ - uint16_t crc16 = 0xFFFF; /* used to calculate the crc value */ - uint16_t index = 0; /* used to load the data portion of the frame */ +{ /* number of bytes of data (up to 501) */ + uint8_t crc8 = 0xFF; /* used to calculate the crc value */ + uint16_t crc16 = 0xFFFF; /* used to calculate the crc value */ + uint16_t index = 0; /* used to load the data portion of the frame */ /* not enough to do a header */ if (buffer_len < 8) @@ -224,7 +217,7 @@ uint16_t MSTP_Create_Frame( crc8 = CRC_Calc_Header(buffer[3], crc8); buffer[4] = source; crc8 = CRC_Calc_Header(buffer[4], crc8); - buffer[5] = data_len >> 8; /* MSB first */ + buffer[5] = data_len >> 8; /* MSB first */ crc8 = CRC_Calc_Header(buffer[5], crc8); buffer[6] = data_len & 0xFF; crc8 = CRC_Calc_Header(buffer[6], crc8); @@ -242,7 +235,7 @@ uint16_t MSTP_Create_Frame( if (index > 8) { if ((index + 2) <= buffer_len) { crc16 = ~crc16; - buffer[index] = crc16 & 0xFF; /* LSB first */ + buffer[index] = crc16 & 0xFF; /* LSB first */ index++; buffer[index] = crc16 >> 8; index++; @@ -250,45 +243,45 @@ uint16_t MSTP_Create_Frame( return 0; } - return index; /* returns the frame length */ + return index; /* returns the frame length */ } void MSTP_Create_And_Send_Frame( - volatile struct mstp_port_struct_t *mstp_port, /* port to send from */ - uint8_t frame_type, /* type of frame to send - see defines */ - uint8_t destination, /* destination address */ - uint8_t source, /* source address */ - uint8_t * data, /* any data to be sent - may be null */ + volatile struct mstp_port_struct_t *mstp_port, /* port to send from */ + uint8_t frame_type, /* type of frame to send - see defines */ + uint8_t destination, /* destination address */ + uint8_t source, /* source address */ + uint8_t *data, /* any data to be sent - may be null */ uint16_t data_len) -{ /* number of bytes of data (up to 501) */ - uint16_t len = 0; /* number of bytes to send */ +{ /* number of bytes of data (up to 501) */ + uint16_t len = 0; /* number of bytes to send */ - len = - MSTP_Create_Frame((uint8_t *) & mstp_port->OutputBuffer[0], - mstp_port->OutputBufferSize, frame_type, destination, source, data, - data_len); + len = MSTP_Create_Frame((uint8_t *)&mstp_port->OutputBuffer[0], + mstp_port->OutputBufferSize, frame_type, + destination, source, data, data_len); - RS485_Send_Frame(mstp_port, (uint8_t *) & mstp_port->OutputBuffer[0], len); + RS485_Send_Frame(mstp_port, (uint8_t *)&mstp_port->OutputBuffer[0], len); /* FIXME: be sure to reset SilenceTimer() after each octet is sent! */ } -void MSTP_Receive_Frame_FSM( - volatile struct mstp_port_struct_t *mstp_port) +void MSTP_Receive_Frame_FSM(volatile struct mstp_port_struct_t *mstp_port) { MSTP_RECEIVE_STATE receive_state = mstp_port->receive_state; - printf_receive - ("MSTP Rx: State=%s Data=%02X hCRC=%02X Index=%u EC=%u DateLen=%u Silence=%u\n", + printf_receive( + "MSTP Rx: State=%s Data=%02X hCRC=%02X Index=%u EC=%u DateLen=%u " + "Silence=%u\n", mstptext_receive_state(mstp_port->receive_state), mstp_port->DataRegister, mstp_port->HeaderCRC, mstp_port->Index, mstp_port->EventCount, mstp_port->DataLength, - mstp_port->SilenceTimer((void *) mstp_port)); + mstp_port->SilenceTimer((void *)mstp_port)); switch (mstp_port->receive_state) { - /* In the IDLE state, the node waits for the beginning of a frame. */ + /* In the IDLE state, the node waits for the beginning of a frame. + */ case MSTP_RECEIVE_STATE_IDLE: /* EatAnError */ if (mstp_port->ReceiveError == true) { mstp_port->ReceiveError = false; - mstp_port->SilenceTimerReset((void *) mstp_port); + mstp_port->SilenceTimerReset((void *)mstp_port); INCREMENT_AND_LIMIT_UINT8(mstp_port->EventCount); /* wait for the start of a frame. */ } else if (mstp_port->DataAvailable == true) { @@ -304,14 +297,15 @@ void MSTP_Receive_Frame_FSM( /* wait for the start of a frame. */ } mstp_port->DataAvailable = false; - mstp_port->SilenceTimerReset((void *) mstp_port); + mstp_port->SilenceTimerReset((void *)mstp_port); INCREMENT_AND_LIMIT_UINT8(mstp_port->EventCount); } break; - /* In the PREAMBLE state, the node waits for the second octet of the preamble. */ + /* In the PREAMBLE state, the node waits for the second octet of the + * preamble. */ case MSTP_RECEIVE_STATE_PREAMBLE: /* Timeout */ - if (mstp_port->SilenceTimer((void *) mstp_port) > Tframe_abort) { + if (mstp_port->SilenceTimer((void *)mstp_port) > Tframe_abort) { /* a correct preamble has not been received */ /* wait for the start of a frame. */ mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE; @@ -319,7 +313,7 @@ void MSTP_Receive_Frame_FSM( /* Error */ else if (mstp_port->ReceiveError == true) { mstp_port->ReceiveError = false; - mstp_port->SilenceTimerReset((void *) mstp_port); + mstp_port->SilenceTimerReset((void *)mstp_port); INCREMENT_AND_LIMIT_UINT8(mstp_port->EventCount); /* wait for the start of a frame. */ mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE; @@ -342,28 +336,32 @@ void MSTP_Receive_Frame_FSM( mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE; } mstp_port->DataAvailable = false; - mstp_port->SilenceTimerReset((void *) mstp_port); + mstp_port->SilenceTimerReset((void *)mstp_port); INCREMENT_AND_LIMIT_UINT8(mstp_port->EventCount); } break; - /* In the HEADER state, the node waits for the fixed message header. */ + /* In the HEADER state, the node waits for the fixed message header. + */ case MSTP_RECEIVE_STATE_HEADER: /* Timeout */ - if (mstp_port->SilenceTimer((void *) mstp_port) > Tframe_abort) { - /* indicate that an error has occurred during the reception of a frame */ + if (mstp_port->SilenceTimer((void *)mstp_port) > Tframe_abort) { + /* indicate that an error has occurred during the reception of a + * frame */ mstp_port->ReceivedInvalidFrame = true; /* wait for the start of a frame. */ mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE; - printf_receive_error("MSTP: Rx Header: SilenceTimer %u > %d\n", - (unsigned) mstp_port->SilenceTimer((void *) mstp_port), + printf_receive_error( + "MSTP: Rx Header: SilenceTimer %u > %d\n", + (unsigned)mstp_port->SilenceTimer((void *)mstp_port), Tframe_abort); } /* Error */ else if (mstp_port->ReceiveError == true) { mstp_port->ReceiveError = false; - mstp_port->SilenceTimerReset((void *) mstp_port); + mstp_port->SilenceTimerReset((void *)mstp_port); INCREMENT_AND_LIMIT_UINT8(mstp_port->EventCount); - /* indicate that an error has occurred during the reception of a frame */ + /* indicate that an error has occurred during the reception of a + * frame */ mstp_port->ReceivedInvalidFrame = true; printf_receive_error("MSTP: Rx Header: ReceiveError\n"); /* wait for the start of a frame. */ @@ -372,49 +370,43 @@ void MSTP_Receive_Frame_FSM( printf_receive_data("%02X ", mstp_port->DataRegister); /* FrameType */ if (mstp_port->Index == 0) { - mstp_port->HeaderCRC = - CRC_Calc_Header(mstp_port->DataRegister, - mstp_port->HeaderCRC); + mstp_port->HeaderCRC = CRC_Calc_Header( + mstp_port->DataRegister, mstp_port->HeaderCRC); mstp_port->FrameType = mstp_port->DataRegister; mstp_port->Index = 1; } /* Destination */ else if (mstp_port->Index == 1) { - mstp_port->HeaderCRC = - CRC_Calc_Header(mstp_port->DataRegister, - mstp_port->HeaderCRC); + mstp_port->HeaderCRC = CRC_Calc_Header( + mstp_port->DataRegister, mstp_port->HeaderCRC); mstp_port->DestinationAddress = mstp_port->DataRegister; mstp_port->Index = 2; } /* Source */ else if (mstp_port->Index == 2) { - mstp_port->HeaderCRC = - CRC_Calc_Header(mstp_port->DataRegister, - mstp_port->HeaderCRC); + mstp_port->HeaderCRC = CRC_Calc_Header( + mstp_port->DataRegister, mstp_port->HeaderCRC); mstp_port->SourceAddress = mstp_port->DataRegister; mstp_port->Index = 3; } /* Length1 */ else if (mstp_port->Index == 3) { - mstp_port->HeaderCRC = - CRC_Calc_Header(mstp_port->DataRegister, - mstp_port->HeaderCRC); + mstp_port->HeaderCRC = CRC_Calc_Header( + mstp_port->DataRegister, mstp_port->HeaderCRC); mstp_port->DataLength = mstp_port->DataRegister * 256; mstp_port->Index = 4; } /* Length2 */ else if (mstp_port->Index == 4) { - mstp_port->HeaderCRC = - CRC_Calc_Header(mstp_port->DataRegister, - mstp_port->HeaderCRC); + mstp_port->HeaderCRC = CRC_Calc_Header( + mstp_port->DataRegister, mstp_port->HeaderCRC); mstp_port->DataLength += mstp_port->DataRegister; mstp_port->Index = 5; } /* HeaderCRC */ else if (mstp_port->Index == 5) { - mstp_port->HeaderCRC = - CRC_Calc_Header(mstp_port->DataRegister, - mstp_port->HeaderCRC); + mstp_port->HeaderCRC = CRC_Calc_Header( + mstp_port->DataRegister, mstp_port->HeaderCRC); mstp_port->HeaderCRCActual = mstp_port->DataRegister; /* don't wait for next state - do it here */ if (mstp_port->HeaderCRC != 0x55) { @@ -422,23 +414,23 @@ void MSTP_Receive_Frame_FSM( /* indicate that an error has occurred during the reception of a frame */ mstp_port->ReceivedInvalidFrame = true; - printf_receive_error - ("MSTP: Rx Header: BadCRC [%02X]\n", - mstp_port->DataRegister); + printf_receive_error("MSTP: Rx Header: BadCRC [%02X]\n", + mstp_port->DataRegister); /* wait for the start of the next frame. */ mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE; } else { if (mstp_port->DataLength == 0) { /* NoData */ - printf_receive_data("%s", - mstptext_frame_type((unsigned) - mstp_port->FrameType)); + printf_receive_data( + "%s", mstptext_frame_type( + (unsigned)mstp_port->FrameType)); if ((mstp_port->DestinationAddress == - mstp_port->This_Station) - || (mstp_port->DestinationAddress == - MSTP_BROADCAST_ADDRESS)) { + mstp_port->This_Station) || + (mstp_port->DestinationAddress == + MSTP_BROADCAST_ADDRESS)) { /* ForUs */ - /* indicate that a frame with no data has been received */ + /* indicate that a frame with no data has been + * received */ mstp_port->ReceivedValidFrame = true; } else { /* NotForUs */ @@ -449,9 +441,9 @@ void MSTP_Receive_Frame_FSM( } else { /* receive the data portion of the frame. */ if ((mstp_port->DestinationAddress == - mstp_port->This_Station) - || (mstp_port->DestinationAddress == - MSTP_BROADCAST_ADDRESS)) { + mstp_port->This_Station) || + (mstp_port->DestinationAddress == + MSTP_BROADCAST_ADDRESS)) { if (mstp_port->DataLength <= mstp_port->InputBufferSize) { /* Data */ @@ -459,9 +451,9 @@ void MSTP_Receive_Frame_FSM( MSTP_RECEIVE_STATE_DATA; } else { /* FrameTooLong */ - printf_receive_error - ("MSTP: Rx Header: FrameTooLong %u\n", - (unsigned) mstp_port->DataLength); + printf_receive_error( + "MSTP: Rx Header: FrameTooLong %u\n", + (unsigned)mstp_port->DataLength); mstp_port->receive_state = MSTP_RECEIVE_STATE_SKIP_DATA; } @@ -482,25 +474,27 @@ 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; } - mstp_port->SilenceTimerReset((void *) mstp_port); + mstp_port->SilenceTimerReset((void *)mstp_port); INCREMENT_AND_LIMIT_UINT8(mstp_port->EventCount); mstp_port->DataAvailable = false; } break; - /* In the DATA state, the node waits for the data portion of a frame. */ + /* In the DATA state, the node waits for the data portion of a + * frame. */ case MSTP_RECEIVE_STATE_DATA: case MSTP_RECEIVE_STATE_SKIP_DATA: /* Timeout */ - if (mstp_port->SilenceTimer((void *) mstp_port) > Tframe_abort) { - /* indicate that an error has occurred during the reception of a frame */ + if (mstp_port->SilenceTimer((void *)mstp_port) > Tframe_abort) { + /* indicate that an error has occurred during the reception of a + * frame */ mstp_port->ReceivedInvalidFrame = true; - printf_receive_error - ("MSTP: Rx Data: SilenceTimer %ums > %dms\n", - (unsigned) mstp_port->SilenceTimer((void *) mstp_port), + printf_receive_error( + "MSTP: Rx Data: SilenceTimer %ums > %dms\n", + (unsigned)mstp_port->SilenceTimer((void *)mstp_port), Tframe_abort); /* wait for the start of the next frame. */ mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE; @@ -508,8 +502,9 @@ void MSTP_Receive_Frame_FSM( /* Error */ else if (mstp_port->ReceiveError == true) { mstp_port->ReceiveError = false; - mstp_port->SilenceTimerReset((void *) mstp_port); - /* indicate that an error has occurred during the reception of a frame */ + mstp_port->SilenceTimerReset((void *)mstp_port); + /* indicate that an error has occurred during the reception of a + * frame */ mstp_port->ReceivedInvalidFrame = true; printf_receive_error("MSTP: Rx Data: ReceiveError\n"); /* wait for the start of the next frame. */ @@ -518,9 +513,8 @@ void MSTP_Receive_Frame_FSM( printf_receive_data("%02X ", mstp_port->DataRegister); if (mstp_port->Index < mstp_port->DataLength) { /* DataOctet */ - mstp_port->DataCRC = - CRC_Calc_Data(mstp_port->DataRegister, - mstp_port->DataCRC); + mstp_port->DataCRC = CRC_Calc_Data(mstp_port->DataRegister, + mstp_port->DataCRC); if (mstp_port->Index < mstp_port->InputBufferSize) { mstp_port->InputBuffer[mstp_port->Index] = mstp_port->DataRegister; @@ -529,20 +523,19 @@ void MSTP_Receive_Frame_FSM( mstp_port->receive_state = MSTP_RECEIVE_STATE_DATA; } else if (mstp_port->Index == mstp_port->DataLength) { /* CRC1 */ - mstp_port->DataCRC = - CRC_Calc_Data(mstp_port->DataRegister, - mstp_port->DataCRC); + mstp_port->DataCRC = CRC_Calc_Data(mstp_port->DataRegister, + mstp_port->DataCRC); mstp_port->DataCRCActualMSB = mstp_port->DataRegister; mstp_port->Index++; mstp_port->receive_state = MSTP_RECEIVE_STATE_DATA; } else if (mstp_port->Index == (mstp_port->DataLength + 1)) { /* CRC2 */ - mstp_port->DataCRC = - CRC_Calc_Data(mstp_port->DataRegister, - mstp_port->DataCRC); + mstp_port->DataCRC = CRC_Calc_Data(mstp_port->DataRegister, + mstp_port->DataCRC); mstp_port->DataCRCActualLSB = mstp_port->DataRegister; - printf_receive_data("%s", - mstptext_frame_type((unsigned) mstp_port->FrameType)); + printf_receive_data( + "%s", + 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) { @@ -557,7 +550,7 @@ void MSTP_Receive_Frame_FSM( } else { mstp_port->ReceivedInvalidFrame = true; printf_receive_error("MSTP: Rx Data: BadCRC [%02X]\n", - mstp_port->DataRegister); + mstp_port->DataRegister); } mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE; } else { @@ -565,7 +558,7 @@ void MSTP_Receive_Frame_FSM( mstp_port->receive_state = MSTP_RECEIVE_STATE_IDLE; } mstp_port->DataAvailable = false; - mstp_port->SilenceTimerReset((void *) mstp_port); + mstp_port->SilenceTimerReset((void *)mstp_port); } break; default: @@ -582,8 +575,7 @@ void MSTP_Receive_Frame_FSM( } /* returns true if we need to transition immediately */ -bool MSTP_Master_Node_FSM( - volatile struct mstp_port_struct_t * mstp_port) +bool MSTP_Master_Node_FSM(volatile struct mstp_port_struct_t *mstp_port) { unsigned length = 0; uint8_t next_poll_station = 0; @@ -622,15 +614,17 @@ bool MSTP_Master_Node_FSM( /* wait for the next frame - remain in IDLE */ mstp_port->ReceivedInvalidFrame = false; } else if (mstp_port->ReceivedValidFrame == true) { - printf_master("MSTP: ReceivedValidFrame " - "Src=%02X Dest=%02X DataLen=%u " "FC=%u ST=%u Type=%s\n", + printf_master( + "MSTP: ReceivedValidFrame " + "Src=%02X Dest=%02X DataLen=%u " + "FC=%u ST=%u Type=%s\n", mstp_port->SourceAddress, mstp_port->DestinationAddress, mstp_port->DataLength, mstp_port->FrameCount, - mstp_port->SilenceTimer((void *) mstp_port), - mstptext_frame_type((unsigned) mstp_port->FrameType)); - if ((mstp_port->DestinationAddress == mstp_port->This_Station) - || (mstp_port->DestinationAddress == - MSTP_BROADCAST_ADDRESS)) { + mstp_port->SilenceTimer((void *)mstp_port), + mstptext_frame_type((unsigned)mstp_port->FrameType)); + if ((mstp_port->DestinationAddress == + mstp_port->This_Station) || + (mstp_port->DestinationAddress == MSTP_BROADCAST_ADDRESS)) { /* destined for me! */ switch (mstp_port->FrameType) { case FRAME_TYPE_TOKEN: @@ -652,20 +646,23 @@ bool MSTP_Master_Node_FSM( /* DestinationAddress is equal to TS */ if (mstp_port->DestinationAddress == mstp_port->This_Station) { - MSTP_Create_And_Send_Frame(mstp_port, + MSTP_Create_And_Send_Frame( + mstp_port, FRAME_TYPE_REPLY_TO_POLL_FOR_MASTER, mstp_port->SourceAddress, mstp_port->This_Station, NULL, 0); } break; case FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY: - /* indicate successful reception to the higher layers */ - (void) MSTP_Put_Receive(mstp_port); + /* indicate successful reception to the higher + * layers */ + (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); + /* indicate successful reception to the higher + * layers */ + (void)MSTP_Put_Receive(mstp_port); /* broadcast DER just remains IDLE */ if (mstp_port->DestinationAddress != MSTP_BROADCAST_ADDRESS) { @@ -674,11 +671,11 @@ bool MSTP_Master_Node_FSM( } break; case FRAME_TYPE_TEST_REQUEST: - MSTP_Create_And_Send_Frame(mstp_port, - FRAME_TYPE_TEST_RESPONSE, + MSTP_Create_And_Send_Frame( + mstp_port, FRAME_TYPE_TEST_RESPONSE, mstp_port->SourceAddress, - mstp_port->This_Station, - mstp_port->InputBuffer, mstp_port->DataLength); + mstp_port->This_Station, mstp_port->InputBuffer, + mstp_port->DataLength); break; case FRAME_TYPE_TEST_RESPONSE: default: @@ -691,10 +688,11 @@ bool MSTP_Master_Node_FSM( MSTP_MASTER_STATE_ANSWER_DATA_REQUEST) { mstp_port->ReceivedValidFrame = false; } - } else if (mstp_port->SilenceTimer((void *) mstp_port) >= Tno_token) { + } else if (mstp_port->SilenceTimer((void *)mstp_port) >= + Tno_token) { /* LostToken */ /* assume that the token has been lost */ - mstp_port->EventCount = 0; /* Addendum 135-2004d-8 */ + mstp_port->EventCount = 0; /* Addendum 135-2004d-8 */ mstp_port->master_state = MSTP_MASTER_STATE_NO_TOKEN; /* set the receive frame flags to false in case we received some bytes and had a timeout for some reason */ @@ -708,7 +706,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; @@ -718,8 +716,8 @@ bool MSTP_Master_Node_FSM( uint8_t frame_type = mstp_port->OutputBuffer[2]; uint8_t destination = mstp_port->OutputBuffer[3]; RS485_Send_Frame(mstp_port, - (uint8_t *) & mstp_port->OutputBuffer[0], - (uint16_t) length); + (uint8_t *)&mstp_port->OutputBuffer[0], + (uint16_t)length); mstp_port->FrameCount++; switch (frame_type) { case FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY: @@ -751,14 +749,16 @@ bool MSTP_Master_Node_FSM( case MSTP_MASTER_STATE_WAIT_FOR_REPLY: /* In the WAIT_FOR_REPLY state, the node waits for */ /* a reply from another node. */ - if (mstp_port->SilenceTimer((void *) mstp_port) >= Treply_timeout) { + if (mstp_port->SilenceTimer((void *)mstp_port) >= Treply_timeout) { /* ReplyTimeout */ /* assume that the request has failed */ mstp_port->FrameCount = mstp_port->Nmax_info_frames; mstp_port->master_state = MSTP_MASTER_STATE_DONE_WITH_TOKEN; /* Any retry of the data frame shall await the next entry */ - /* to the USE_TOKEN state. (Because of the length of the timeout, */ - /* this transition will cause the token to be passed regardless */ + /* to the USE_TOKEN state. (Because of the length of the + * timeout, */ + /* this transition will cause the token to be passed regardless + */ /* of the initial value of FrameCount.) */ transition_now = true; } else { @@ -766,8 +766,7 @@ bool MSTP_Master_Node_FSM( /* InvalidFrame */ /* error in frame reception */ mstp_port->ReceivedInvalidFrame = false; - mstp_port->master_state = - MSTP_MASTER_STATE_DONE_WITH_TOKEN; + mstp_port->master_state = MSTP_MASTER_STATE_DONE_WITH_TOKEN; transition_now = true; } else if (mstp_port->ReceivedValidFrame == true) { if (mstp_port->DestinationAddress == @@ -784,9 +783,11 @@ bool MSTP_Master_Node_FSM( break; case FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY: /* ReceivedReply */ - /* or a proprietary type that indicates a reply */ - /* indicate successful reception to the higher layers */ - (void) MSTP_Put_Receive(mstp_port); + /* or a proprietary type that indicates a reply + */ + /* indicate successful reception to the higher + * layers */ + (void)MSTP_Put_Receive(mstp_port); mstp_port->master_state = MSTP_MASTER_STATE_DONE_WITH_TOKEN; break; @@ -800,7 +801,7 @@ bool MSTP_Master_Node_FSM( } else { /* ReceivedUnexpectedFrame */ /* an unexpected frame was received */ - /* This may indicate the presence of multiple tokens. */ + /* This may indicate the presence of multiple tokens. */ /* Synchronize with the network. */ /* This action drops the token. */ mstp_port->master_state = MSTP_MASTER_STATE_IDLE; @@ -820,14 +821,14 @@ bool MSTP_Master_Node_FSM( mstp_port->master_state = MSTP_MASTER_STATE_USE_TOKEN; transition_now = true; } else if ((mstp_port->SoleMaster == false) && - (mstp_port->Next_Station == mstp_port->This_Station)) { + (mstp_port->Next_Station == mstp_port->This_Station)) { /* NextStationUnknown - added in Addendum 135-2008v-1 */ /* then the next station to which the token should be sent is unknown - so PollForMaster */ mstp_port->Poll_Station = next_this_station; - MSTP_Create_And_Send_Frame(mstp_port, - FRAME_TYPE_POLL_FOR_MASTER, mstp_port->Poll_Station, - mstp_port->This_Station, NULL, 0); + MSTP_Create_And_Send_Frame( + mstp_port, FRAME_TYPE_POLL_FOR_MASTER, + mstp_port->Poll_Station, mstp_port->This_Station, NULL, 0); mstp_port->RetryCount = 0; mstp_port->master_state = MSTP_MASTER_STATE_POLL_FOR_MASTER; } else if (mstp_port->TokenCount < (Npoll - 1)) { @@ -836,7 +837,8 @@ bool MSTP_Master_Node_FSM( (mstp_port->Next_Station != next_this_station)) { /* SoleMaster */ /* there are no other known master nodes to */ - /* which the token may be sent (true master-slave operation). */ + /* which the token may be sent (true master-slave + * operation). */ mstp_port->FrameCount = 0; mstp_port->TokenCount++; mstp_port->master_state = MSTP_MASTER_STATE_USE_TOKEN; @@ -844,14 +846,17 @@ bool MSTP_Master_Node_FSM( } else { /* SendToken */ /* Npoll changed in Errata SSPC-135-2004 */ - /* The comparison of NS and TS+1 eliminates the Poll For Master */ - /* if there are no addresses between TS and NS, since there is no */ - /* address at which a new master node may be found in that case. */ + /* The comparison of NS and TS+1 eliminates the Poll For + * Master */ + /* if there are no addresses between TS and NS, since there + * is no */ + /* address at which a new master node may be found in that + * case. */ mstp_port->TokenCount++; /* transmit a Token frame to NS */ - MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TOKEN, - mstp_port->Next_Station, mstp_port->This_Station, NULL, - 0); + MSTP_Create_And_Send_Frame( + mstp_port, FRAME_TYPE_TOKEN, mstp_port->Next_Station, + mstp_port->This_Station, NULL, 0); mstp_port->RetryCount = 0; mstp_port->EventCount = 0; mstp_port->master_state = MSTP_MASTER_STATE_PASS_TOKEN; @@ -860,25 +865,26 @@ bool MSTP_Master_Node_FSM( if (mstp_port->SoleMaster == true) { /* SoleMasterRestartMaintenancePFM */ mstp_port->Poll_Station = next_next_station; - MSTP_Create_And_Send_Frame(mstp_port, - FRAME_TYPE_POLL_FOR_MASTER, mstp_port->Poll_Station, - mstp_port->This_Station, NULL, 0); + MSTP_Create_And_Send_Frame( + mstp_port, FRAME_TYPE_POLL_FOR_MASTER, + mstp_port->Poll_Station, mstp_port->This_Station, NULL, + 0); /* no known successor node */ mstp_port->Next_Station = mstp_port->This_Station; mstp_port->RetryCount = 0; /* changed in Errata SSPC-135-2004 */ mstp_port->TokenCount = 1; - /* mstp_port->EventCount = 0; removed in Addendum 135-2004d-8 */ + /* mstp_port->EventCount = 0; removed in Addendum + * 135-2004d-8 */ /* find a new successor to TS */ - mstp_port->master_state = - MSTP_MASTER_STATE_POLL_FOR_MASTER; + mstp_port->master_state = MSTP_MASTER_STATE_POLL_FOR_MASTER; } else { /* ResetMaintenancePFM */ mstp_port->Poll_Station = mstp_port->This_Station; /* transmit a Token frame to NS */ - MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TOKEN, - mstp_port->Next_Station, mstp_port->This_Station, NULL, - 0); + MSTP_Create_And_Send_Frame( + mstp_port, FRAME_TYPE_TOKEN, mstp_port->Next_Station, + mstp_port->This_Station, NULL, 0); mstp_port->RetryCount = 0; /* changed in Errata SSPC-135-2004 */ mstp_port->TokenCount = 1; @@ -888,9 +894,9 @@ bool MSTP_Master_Node_FSM( } else { /* SendMaintenancePFM */ mstp_port->Poll_Station = next_poll_station; - MSTP_Create_And_Send_Frame(mstp_port, - FRAME_TYPE_POLL_FOR_MASTER, mstp_port->Poll_Station, - mstp_port->This_Station, NULL, 0); + MSTP_Create_And_Send_Frame( + mstp_port, FRAME_TYPE_POLL_FOR_MASTER, + mstp_port->Poll_Station, mstp_port->This_Station, NULL, 0); mstp_port->RetryCount = 0; mstp_port->master_state = MSTP_MASTER_STATE_POLL_FOR_MASTER; } @@ -898,10 +904,11 @@ bool MSTP_Master_Node_FSM( case MSTP_MASTER_STATE_PASS_TOKEN: /* The PASS_TOKEN state listens for a successor to begin using */ /* the token that this node has just attempted to pass. */ - if (mstp_port->SilenceTimer((void *) mstp_port) <= Tusage_timeout) { + if (mstp_port->SilenceTimer((void *)mstp_port) <= Tusage_timeout) { if (mstp_port->EventCount > Nmin_octets) { /* SawTokenUser */ - /* Assume that a frame has been sent by the new token user. */ + /* Assume that a frame has been sent by the new token user. + */ /* Enter the IDLE state to process the frame. */ mstp_port->master_state = MSTP_MASTER_STATE_IDLE; transition_now = true; @@ -911,9 +918,9 @@ bool MSTP_Master_Node_FSM( /* RetrySendToken */ mstp_port->RetryCount++; /* Transmit a Token frame to NS */ - MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TOKEN, - mstp_port->Next_Station, mstp_port->This_Station, NULL, - 0); + MSTP_Create_And_Send_Frame( + mstp_port, FRAME_TYPE_TOKEN, mstp_port->Next_Station, + mstp_port->This_Station, NULL, 0); mstp_port->EventCount = 0; /* re-enter the current state to listen for NS */ /* to begin using the token. */ @@ -923,50 +930,53 @@ bool MSTP_Master_Node_FSM( /* note: if NS=TS-1, this node could send PFM to self! */ mstp_port->Poll_Station = next_next_station; /* Transmit a Poll For Master frame to PS. */ - MSTP_Create_And_Send_Frame(mstp_port, - FRAME_TYPE_POLL_FOR_MASTER, mstp_port->Poll_Station, - mstp_port->This_Station, NULL, 0); + MSTP_Create_And_Send_Frame( + mstp_port, FRAME_TYPE_POLL_FOR_MASTER, + mstp_port->Poll_Station, mstp_port->This_Station, NULL, + 0); /* no known successor node */ mstp_port->Next_Station = mstp_port->This_Station; mstp_port->RetryCount = 0; mstp_port->TokenCount = 0; - /* mstp_port->EventCount = 0; removed in Addendum 135-2004d-8 */ + /* mstp_port->EventCount = 0; removed in Addendum + * 135-2004d-8 */ /* find a new successor to TS */ - mstp_port->master_state = - MSTP_MASTER_STATE_POLL_FOR_MASTER; + mstp_port->master_state = MSTP_MASTER_STATE_POLL_FOR_MASTER; } } break; case MSTP_MASTER_STATE_NO_TOKEN: - /* The NO_TOKEN state is entered if mstp_port->SilenceTimer() becomes greater */ - /* than Tno_token, indicating that there has been no network activity */ - /* for that period of time. The timeout is continued to determine */ + /* The NO_TOKEN state is entered if mstp_port->SilenceTimer() + * becomes greater */ + /* than Tno_token, indicating that there has been no network + * activity */ + /* for that period of time. The timeout is continued to determine */ /* whether or not this node may create a token. */ my_timeout = Tno_token + (Tslot * mstp_port->This_Station); - if (mstp_port->SilenceTimer((void *) mstp_port) < my_timeout) { + if (mstp_port->SilenceTimer((void *)mstp_port) < my_timeout) { if (mstp_port->EventCount > Nmin_octets) { /* SawFrame */ /* Some other node exists at a lower address. */ - /* Enter the IDLE state to receive and process the incoming frame. */ + /* Enter the IDLE state to receive and process the incoming + * frame. */ mstp_port->master_state = MSTP_MASTER_STATE_IDLE; transition_now = true; } } else { ns_timeout = Tno_token + (Tslot * (mstp_port->This_Station + 1)); - mm_timeout = - Tno_token + (Tslot * (mstp_port->Nmax_master + 1)); - if ((mstp_port->SilenceTimer((void *) mstp_port) < ns_timeout) - || (mstp_port->SilenceTimer((void *) mstp_port) > - mm_timeout)) { + mm_timeout = Tno_token + (Tslot * (mstp_port->Nmax_master + 1)); + if ((mstp_port->SilenceTimer((void *)mstp_port) < ns_timeout) || + (mstp_port->SilenceTimer((void *)mstp_port) > mm_timeout)) { /* GenerateToken */ /* Assume that this node is the lowest numerical address */ /* on the network and is empowered to create a token. */ mstp_port->Poll_Station = next_this_station; /* Transmit a Poll For Master frame to PS. */ - MSTP_Create_And_Send_Frame(mstp_port, - FRAME_TYPE_POLL_FOR_MASTER, mstp_port->Poll_Station, - mstp_port->This_Station, NULL, 0); + MSTP_Create_And_Send_Frame( + mstp_port, FRAME_TYPE_POLL_FOR_MASTER, + mstp_port->Poll_Station, mstp_port->This_Station, NULL, + 0); /* indicate that the next station is unknown */ mstp_port->Next_Station = mstp_port->This_Station; mstp_port->RetryCount = 0; @@ -975,8 +985,7 @@ bool MSTP_Master_Node_FSM( removed Addendum 135-2004d-8 */ /* enter the POLL_FOR_MASTER state to find a new successor to TS. */ - mstp_port->master_state = - MSTP_MASTER_STATE_POLL_FOR_MASTER; + mstp_port->master_state = MSTP_MASTER_STATE_POLL_FOR_MASTER; } else { /* We missed our time slot! We should never get here unless @@ -997,17 +1006,18 @@ bool MSTP_Master_Node_FSM( /* a previously sent Poll For Master frame in order to find */ /* a successor node. */ if (mstp_port->ReceivedValidFrame == true) { - if ((mstp_port->DestinationAddress == mstp_port->This_Station) - && (mstp_port->FrameType == - FRAME_TYPE_REPLY_TO_POLL_FOR_MASTER)) { + if ((mstp_port->DestinationAddress == + mstp_port->This_Station) && + (mstp_port->FrameType == + FRAME_TYPE_REPLY_TO_POLL_FOR_MASTER)) { /* ReceivedReplyToPFM */ mstp_port->SoleMaster = false; mstp_port->Next_Station = mstp_port->SourceAddress; mstp_port->EventCount = 0; /* Transmit a Token frame to NS */ - MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TOKEN, - mstp_port->Next_Station, mstp_port->This_Station, NULL, - 0); + MSTP_Create_And_Send_Frame( + mstp_port, FRAME_TYPE_TOKEN, mstp_port->Next_Station, + mstp_port->This_Station, NULL, 0); mstp_port->Poll_Station = mstp_port->This_Station; mstp_port->TokenCount = 0; mstp_port->RetryCount = 0; @@ -1022,9 +1032,9 @@ bool MSTP_Master_Node_FSM( transition_now = true; } mstp_port->ReceivedValidFrame = false; - } else if ((mstp_port->SilenceTimer((void *) mstp_port) > - Tusage_timeout) || - (mstp_port->ReceivedInvalidFrame == true)) { + } else if ((mstp_port->SilenceTimer((void *)mstp_port) > + Tusage_timeout) || + (mstp_port->ReceivedInvalidFrame == true)) { if (mstp_port->SoleMaster == true) { /* SoleMaster */ /* There was no valid reply to the periodic poll */ @@ -1041,8 +1051,9 @@ bool MSTP_Master_Node_FSM( mstp_port->EventCount = 0; /* transmit a Token frame to NS */ MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TOKEN, - mstp_port->Next_Station, mstp_port->This_Station, - NULL, 0); + mstp_port->Next_Station, + mstp_port->This_Station, + NULL, 0); mstp_port->RetryCount = 0; mstp_port->master_state = MSTP_MASTER_STATE_PASS_TOKEN; } else { @@ -1050,15 +1061,16 @@ bool MSTP_Master_Node_FSM( /* SendNextPFM */ mstp_port->Poll_Station = next_poll_station; /* Transmit a Poll For Master frame to PS. */ - MSTP_Create_And_Send_Frame(mstp_port, - FRAME_TYPE_POLL_FOR_MASTER, + MSTP_Create_And_Send_Frame( + mstp_port, FRAME_TYPE_POLL_FOR_MASTER, mstp_port->Poll_Station, mstp_port->This_Station, NULL, 0); mstp_port->RetryCount = 0; /* Re-enter the current state. */ } else { /* DeclareSoleMaster */ - /* to indicate that this station is the only master */ + /* to indicate that this station is the only master + */ mstp_port->SoleMaster = true; mstp_port->FrameCount = 0; mstp_port->master_state = @@ -1077,23 +1089,24 @@ bool MSTP_Master_Node_FSM( /* FIXME: MSTP_Get_Reply waits for a matching reply, but if the next queued message doesn't match, then we sit here for Treply_delay doing nothing */ - 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 */ /* within Treply_delay after the reception of the */ /* final octet of the requesting frame */ /* (the mechanism used to determine this is a local matter), */ - /* then call MSTP_Create_And_Send_Frame to transmit the reply frame */ + /* then call MSTP_Create_And_Send_Frame to transmit the reply + * frame */ /* and enter the IDLE state to wait for the next frame. */ RS485_Send_Frame(mstp_port, - (uint8_t *) & mstp_port->OutputBuffer[0], - (uint16_t) length); + (uint8_t *)&mstp_port->OutputBuffer[0], + (uint16_t)length); mstp_port->master_state = MSTP_MASTER_STATE_IDLE; /* clear our flag we were holding for comparison */ mstp_port->ReceivedValidFrame = false; - } else if (mstp_port->SilenceTimer((void *) mstp_port) > - Treply_delay) { + } else if (mstp_port->SilenceTimer((void *)mstp_port) > + Treply_delay) { /* DeferredReply */ /* If no reply will be available from the higher layers */ /* within Treply_delay after the reception of the */ @@ -1101,11 +1114,12 @@ bool MSTP_Master_Node_FSM( /* used to determine this is a local matter), */ /* then an immediate reply is not possible. */ /* Any reply shall wait until this node receives the token. */ - /* Call MSTP_Create_And_Send_Frame to transmit a Reply Postponed frame, */ + /* Call MSTP_Create_And_Send_Frame to transmit a Reply Postponed + * frame, */ /* and enter the IDLE state. */ - MSTP_Create_And_Send_Frame(mstp_port, - FRAME_TYPE_REPLY_POSTPONED, mstp_port->SourceAddress, - mstp_port->This_Station, NULL, 0); + MSTP_Create_And_Send_Frame( + mstp_port, FRAME_TYPE_REPLY_POSTPONED, + mstp_port->SourceAddress, mstp_port->This_Station, NULL, 0); mstp_port->master_state = MSTP_MASTER_STATE_IDLE; /* clear our flag we were holding for comparison */ mstp_port->ReceivedValidFrame = false; @@ -1117,20 +1131,20 @@ bool MSTP_Master_Node_FSM( } if (mstp_port->master_state != master_state) { /* change of state detected - so print the details for debugging */ - printf_master - ("MSTP: TS=%02X[%02X] NS=%02X[%02X] PS=%02X[%02X] EC=%u TC=%u ST=%u %s\n", - mstp_port->This_Station, next_this_station, - mstp_port->Next_Station, next_next_station, - mstp_port->Poll_Station, next_poll_station, mstp_port->EventCount, - mstp_port->TokenCount, mstp_port->SilenceTimer((void *) mstp_port), + printf_master( + "MSTP: TS=%02X[%02X] NS=%02X[%02X] PS=%02X[%02X] EC=%u TC=%u ST=%u " + "%s\n", + mstp_port->This_Station, next_this_station, mstp_port->Next_Station, + next_next_station, mstp_port->Poll_Station, next_poll_station, + mstp_port->EventCount, mstp_port->TokenCount, + mstp_port->SilenceTimer((void *)mstp_port), mstptext_master_state(mstp_port->master_state)); } return transition_now; } -void MSTP_Slave_Node_FSM( - volatile struct mstp_port_struct_t *mstp_port) +void MSTP_Slave_Node_FSM(volatile struct mstp_port_struct_t *mstp_port) { unsigned length = 0; @@ -1146,26 +1160,30 @@ void MSTP_Slave_Node_FSM( /* The ANSWER_DATA_REQUEST state is entered when a */ /* BACnet Data Expecting Reply, a Test_Request, or */ /* a proprietary frame that expects a reply is received. */ - 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 */ /* within Treply_delay after the reception of the */ /* final octet of the requesting frame */ - /* (the mechanism used to determine this is a local matter), */ - /* then call MSTP_Create_And_Send_Frame to transmit the reply frame */ - /* and enter the IDLE state to wait for the next frame. */ + /* (the mechanism used to determine this is a local + * matter), */ + /* then call MSTP_Create_And_Send_Frame to transmit the + * reply frame */ + /* and enter the IDLE state to wait for the next frame. + */ RS485_Send_Frame(mstp_port, - (uint8_t *) & mstp_port->OutputBuffer[0], - (uint16_t) length); + (uint8_t *)&mstp_port->OutputBuffer[0], + (uint16_t)length); /* clear our flag we were holding for comparison */ mstp_port->ReceivedValidFrame = false; - } else if (mstp_port->SilenceTimer((void *) mstp_port) > - Treply_delay) { + } else if (mstp_port->SilenceTimer((void *)mstp_port) > + Treply_delay) { /* If no reply will be available from the higher layers - within Treply_delay after the reception of the final octet - of the requesting frame (the mechanism used to determine - this is a local matter), then no reply is possible. */ + within Treply_delay after the reception of the final + octet of the requesting frame (the mechanism used to + determine this is a local matter), then no reply is + possible. */ /* clear our flag we were holding for comparison */ mstp_port->ReceivedValidFrame = false; } @@ -1175,7 +1193,8 @@ void MSTP_Slave_Node_FSM( break; case FRAME_TYPE_TEST_REQUEST: mstp_port->ReceivedValidFrame = false; - MSTP_Create_And_Send_Frame(mstp_port, FRAME_TYPE_TEST_RESPONSE, + MSTP_Create_And_Send_Frame( + mstp_port, FRAME_TYPE_TEST_RESPONSE, mstp_port->SourceAddress, mstp_port->This_Station, &mstp_port->InputBuffer[0], mstp_port->DataLength); break; @@ -1196,8 +1215,7 @@ void MSTP_Slave_Node_FSM( /* note: InputBuffer and InputBufferSize assumed to be set */ /* note: OutputBuffer and OutputBufferSize assumed to be set */ /* note: SilenceTimer and SilenceTimerReset assumed to be set */ -void MSTP_Init( - volatile struct mstp_port_struct_t *mstp_port) +void MSTP_Init(volatile struct mstp_port_struct_t *mstp_port) { if (mstp_port) { #if 0 @@ -1233,7 +1251,7 @@ void MSTP_Init( mstp_port->ReceivedValidFrame = false; mstp_port->ReceivedValidFrameNotForUs = false; mstp_port->RetryCount = 0; - mstp_port->SilenceTimerReset((void *) mstp_port); + mstp_port->SilenceTimerReset((void *)mstp_port); mstp_port->SoleMaster = false; mstp_port->SourceAddress = 0; mstp_port->TokenCount = 0; @@ -1250,46 +1268,43 @@ static uint8_t RxBuffer[MAX_MPDU]; static uint8_t TxBuffer[MAX_MPDU]; /* test stub functions */ void RS485_Send_Frame( - volatile struct mstp_port_struct_t *mstp_port, /* port specific data */ - uint8_t * buffer, /* frame to send (up to 501 bytes of data) */ + volatile struct mstp_port_struct_t *mstp_port, /* port specific data */ + uint8_t *buffer, /* frame to send (up to 501 bytes of data) */ uint16_t nbytes) -{ /* number of bytes of data (up to 501) */ - (void) mstp_port; - (void) buffer; - (void) nbytes; +{ /* number of bytes of data (up to 501) */ + (void)mstp_port; + (void)buffer; + (void)nbytes; } #define RING_BUFFER_DATA_SIZE 1 #define RING_BUFFER_SIZE MAX_MPDU static RING_BUFFER Test_Buffer; static uint8_t Test_Buffer_Data[RING_BUFFER_DATA_SIZE * RING_BUFFER_SIZE]; -static void Load_Input_Buffer( - uint8_t * buffer, - size_t len) +static void Load_Input_Buffer(uint8_t *buffer, size_t len) { - static bool initialized = false; /* tracks our init */ + static bool initialized = false; /* tracks our init */ if (!initialized) { initialized = true; - Ringbuf_Init(&Test_Buffer, (char *) Test_Buffer_Data, - RING_BUFFER_DATA_SIZE, RING_BUFFER_SIZE); + Ringbuf_Init(&Test_Buffer, (char *)Test_Buffer_Data, + RING_BUFFER_DATA_SIZE, RING_BUFFER_SIZE); } /* empty any the existing data */ while (!Ringbuf_Empty(&Test_Buffer)) { - (void) Ringbuf_Pop(&Test_Buffer, NULL); + (void)Ringbuf_Pop(&Test_Buffer, NULL); } if (buffer) { while (len) { - (void) Ringbuf_Put(&Test_Buffer, (char *) buffer); + (void)Ringbuf_Put(&Test_Buffer, (char *)buffer); len--; buffer++; } } } -void RS485_Check_UART_Data( - volatile struct mstp_port_struct_t *mstp_port) -{ /* port specific data */ +void RS485_Check_UART_Data(volatile struct mstp_port_struct_t *mstp_port) +{ /* port specific data */ char *data; if (!Ringbuf_Empty(&Test_Buffer) && mstp_port && (mstp_port->DataAvailable == false)) { @@ -1298,61 +1313,51 @@ void RS485_Check_UART_Data( mstp_port->DataRegister = *data; mstp_port->DataAvailable = true; } - (void) Ringbuf_Pop(&Test_Buffer, NULL); + (void)Ringbuf_Pop(&Test_Buffer, NULL); } } -uint16_t MSTP_Put_Receive( - volatile struct mstp_port_struct_t *mstp_port) +uint16_t MSTP_Put_Receive(volatile struct mstp_port_struct_t *mstp_port) { return mstp_port->DataLength; } /* for the MS/TP state machine to use for getting data to send */ /* Return: amount of PDU data */ -uint16_t MSTP_Get_Send( - volatile struct mstp_port_struct_t * mstp_port, - unsigned timeout) -{ /* milliseconds to wait for a packet */ +uint16_t MSTP_Get_Send(volatile struct mstp_port_struct_t *mstp_port, + unsigned timeout) +{ /* milliseconds to wait for a packet */ return 0; } -uint16_t MSTP_Get_Reply( - volatile struct mstp_port_struct_t * mstp_port, - unsigned timeout) -{ /* milliseconds to wait for a packet */ +uint16_t MSTP_Get_Reply(volatile struct mstp_port_struct_t *mstp_port, + unsigned timeout) +{ /* milliseconds to wait for a packet */ return 0; } uint16_t SilenceTime = 0; -static uint16_t Timer_Silence( - void) +static uint16_t Timer_Silence(void) { return SilenceTime; } -static void Timer_Silence_Reset( - void) +static void Timer_Silence_Reset(void) { SilenceTime = 0; } -void testReceiveNodeFSM( - Test * pTest) +void testReceiveNodeFSM(Test *pTest) { - volatile struct mstp_port_struct_t mstp_port; /* port data */ - unsigned EventCount = 0; /* local counter */ - uint8_t my_mac = 0x05; /* local MAC address */ - uint8_t HeaderCRC = 0; /* for local CRC calculation */ - uint8_t FrameType = 0; /* type of packet that was sent */ - unsigned len; /* used for the size of the message packet */ - size_t i; /* used to loop through the message bytes */ - uint8_t buffer[MAX_MPDU] = { - 0 - }; - uint8_t data[MAX_PDU] = { - 0 - }; + volatile struct mstp_port_struct_t mstp_port; /* port data */ + unsigned EventCount = 0; /* local counter */ + uint8_t my_mac = 0x05; /* local MAC address */ + uint8_t HeaderCRC = 0; /* for local CRC calculation */ + uint8_t FrameType = 0; /* type of packet that was sent */ + unsigned len; /* used for the size of the message packet */ + size_t i; /* used to loop through the message bytes */ + uint8_t buffer[MAX_MPDU] = {0}; + uint8_t data[MAX_PDU] = {0}; mstp_port.InputBuffer = &RxBuffer[0]; mstp_port.InputBufferSize = sizeof(RxBuffer); mstp_port.OutputBuffer = &TxBuffer[0]; @@ -1600,8 +1605,8 @@ void testReceiveNodeFSM( ct_test(pTest, mstp_port.DataLength == 0); /* HeaderCRC */ mstp_port.DataAvailable = true; - ct_test(pTest, HeaderCRC == 0x73); /* per Annex G example */ - mstp_port.DataRegister = ~HeaderCRC; /* one's compliment of CRC is sent */ + ct_test(pTest, HeaderCRC == 0x73); /* per Annex G example */ + mstp_port.DataRegister = ~HeaderCRC; /* one's compliment of CRC is sent */ INCREMENT_AND_LIMIT_UINT8(EventCount); MSTP_Receive_Frame_FSM(&mstp_port); ct_test(pTest, mstp_port.DataAvailable == false); @@ -1613,10 +1618,11 @@ void testReceiveNodeFSM( /* BadCRC in header check */ mstp_port.ReceivedInvalidFrame = false; mstp_port.ReceivedValidFrame = false; - len = MSTP_Create_Frame(buffer, sizeof(buffer), FRAME_TYPE_TOKEN, 0x10, /* destination */ - my_mac, /* source */ - NULL, /* data */ - 0); /* data size */ + len = MSTP_Create_Frame(buffer, sizeof(buffer), FRAME_TYPE_TOKEN, + 0x10, /* destination */ + my_mac, /* source */ + NULL, /* data */ + 0); /* data size */ ct_test(pTest, len > 0); /* make the header CRC bad */ buffer[7] = 0x00; @@ -1635,10 +1641,11 @@ void testReceiveNodeFSM( /* NoData for us */ mstp_port.ReceivedInvalidFrame = false; mstp_port.ReceivedValidFrame = false; - len = MSTP_Create_Frame(buffer, sizeof(buffer), FRAME_TYPE_TOKEN, my_mac, /* destination */ - my_mac, /* source */ - NULL, /* data */ - 0); /* data size */ + len = MSTP_Create_Frame(buffer, sizeof(buffer), FRAME_TYPE_TOKEN, + my_mac, /* destination */ + my_mac, /* source */ + NULL, /* data */ + 0); /* data size */ ct_test(pTest, len > 0); Load_Input_Buffer(buffer, len); for (i = 0; i < len; i++) { @@ -1655,10 +1662,11 @@ void testReceiveNodeFSM( /* FrameTooLong */ mstp_port.ReceivedInvalidFrame = false; mstp_port.ReceivedValidFrame = false; - len = MSTP_Create_Frame(buffer, sizeof(buffer), FRAME_TYPE_TOKEN, my_mac, /* destination */ - my_mac, /* source */ - NULL, /* data */ - 0); /* data size */ + len = MSTP_Create_Frame(buffer, sizeof(buffer), FRAME_TYPE_TOKEN, + my_mac, /* destination */ + my_mac, /* source */ + NULL, /* data */ + 0); /* data size */ ct_test(pTest, len > 0); /* make the header data length bad */ buffer[5] = 0x02; @@ -1678,9 +1686,8 @@ void testReceiveNodeFSM( mstp_port.ReceivedInvalidFrame = false; mstp_port.ReceivedValidFrame = false; memset(data, 0, sizeof(data)); - len = - MSTP_Create_Frame(buffer, sizeof(buffer), FRAME_TYPE_PROPRIETARY_MIN, - my_mac, my_mac, data, sizeof(data)); + len = MSTP_Create_Frame(buffer, sizeof(buffer), FRAME_TYPE_PROPRIETARY_MIN, + my_mac, my_mac, data, sizeof(data)); ct_test(pTest, len > 0); Load_Input_Buffer(buffer, len); RS485_Check_UART_Data(&mstp_port); @@ -1696,11 +1703,10 @@ void testReceiveNodeFSM( return; } -void testMasterNodeFSM( - Test * pTest) +void testMasterNodeFSM(Test *pTest) { - volatile struct mstp_port_struct_t MSTP_Port; /* port data */ - uint8_t my_mac = 0x05; /* local MAC address */ + volatile struct mstp_port_struct_t MSTP_Port; /* port data */ + uint8_t my_mac = 0x05; /* local MAC address */ MSTP_Port.InputBuffer = &RxBuffer[0]; MSTP_Port.InputBufferSize = sizeof(RxBuffer); MSTP_Port.OutputBuffer = &TxBuffer[0]; @@ -1718,8 +1724,7 @@ void testMasterNodeFSM( #endif #ifdef TEST_MSTP -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -1731,7 +1736,7 @@ int main( assert(rc); ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; } diff --git a/src/mstptext.c b/src/mstptext.c index 5ffec65e..4fec6a2e 100644 --- a/src/mstptext.c +++ b/src/mstptext.c @@ -44,11 +44,9 @@ static INDTEXT_DATA mstp_receive_state_text[] = { {MSTP_RECEIVE_STATE_PREAMBLE, "PREAMBLE"}, {MSTP_RECEIVE_STATE_HEADER, "HEADER"}, {MSTP_RECEIVE_STATE_DATA, "DATA"}, - {0, NULL} -}; + {0, NULL}}; -const char *mstptext_receive_state( - unsigned index) +const char *mstptext_receive_state(unsigned index) { return indtext_by_index_default(mstp_receive_state_text, index, "unknown"); } @@ -63,11 +61,9 @@ static INDTEXT_DATA mstp_master_state_text[] = { {MSTP_MASTER_STATE_NO_TOKEN, "NO_TOKEN"}, {MSTP_MASTER_STATE_POLL_FOR_MASTER, "POLL_FOR_MASTER"}, {MSTP_MASTER_STATE_ANSWER_DATA_REQUEST, "ANSWER_DATA_REQUEST"}, - {0, NULL} -}; + {0, NULL}}; -const char *mstptext_master_state( - unsigned index) +const char *mstptext_master_state(unsigned index) { return indtext_by_index_default(mstp_master_state_text, index, "unknown"); } @@ -80,14 +76,13 @@ static INDTEXT_DATA mstp_frame_type_text[] = { {FRAME_TYPE_TEST_RESPONSE, "TEST_RESPONSE"}, {FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY, "BACNET_DATA_EXPECTING_REPLY"}, {FRAME_TYPE_BACNET_DATA_NOT_EXPECTING_REPLY, - "BACNET_DATA_NOT_EXPECTING_REPLY"}, + "BACNET_DATA_NOT_EXPECTING_REPLY"}, {FRAME_TYPE_REPLY_POSTPONED, "REPLY_POSTPONED"}, - {0, NULL} -}; + {0, NULL}}; -const char *mstptext_frame_type( - unsigned index) +const char *mstptext_frame_type(unsigned index) { return indtext_by_index_split_default(mstp_frame_type_text, index, - FRAME_TYPE_PROPRIETARY_MIN, "UNKNOWN", "PROPRIETARY"); + FRAME_TYPE_PROPRIETARY_MIN, "UNKNOWN", + "PROPRIETARY"); } diff --git a/src/npdu.c b/src/npdu.c index 42eeee92..b31f85fb 100644 --- a/src/npdu.c +++ b/src/npdu.c @@ -47,9 +47,7 @@ * @param dest [out] The 'to' structure * @param src [in] The 'from' structure */ -void npdu_copy_data( - BACNET_NPDU_DATA * dest, - BACNET_NPDU_DATA * src) +void npdu_copy_data(BACNET_NPDU_DATA *dest, BACNET_NPDU_DATA *src) { if (dest && src) { dest->protocol_version = src->protocol_version; @@ -102,7 +100,6 @@ ABORT.request Yes No Yes No ABORT.indication Yes Yes Yes No */ - /** Encode the NPDU portion of a message to be sent, based on the npdu_data * and associated data. * If this is to be a Network Layer Control Message, there are probably @@ -110,9 +107,9 @@ ABORT.indication Yes Yes Yes No * The Network Layer Protocol Control Information byte is described * in section 6.2.2 of the BACnet standard. * @param npdu [out] Buffer which will hold the encoded NPDU header bytes. - * The size isn't given, but it must be at least 2 bytes - * for the simplest case, and should always be at least 24 - * bytes to accommodate the maximal case (all fields loaded). + * The size isn't given, but it must be at + * least 2 bytes for the simplest case, and should always be at least 24 bytes + * to accommodate the maximal case (all fields loaded). * @param dest [in] The routing destination information if the message must * be routed to reach its destination. * If dest->net and dest->len are 0, there is no @@ -129,15 +126,11 @@ ABORT.indication Yes Yes Yes No * NPDU section. * If 0 or negative, there were problems with the data or encoding. */ -int npdu_encode_pdu( - uint8_t * npdu, - BACNET_ADDRESS * dest, - BACNET_ADDRESS * src, - BACNET_NPDU_DATA * npdu_data) +int npdu_encode_pdu(uint8_t *npdu, BACNET_ADDRESS *dest, BACNET_ADDRESS *src, + BACNET_NPDU_DATA *npdu_data) { - int len = 0; /* return value - number of octets loaded in this function */ - uint8_t i = 0; /* counter */ - + int len = 0; /* return value - number of octets loaded in this function */ + uint8_t i = 0; /* counter */ if (npdu && npdu_data) { /* protocol version */ @@ -194,7 +187,7 @@ int npdu_encode_pdu( } } } - if (src && src->net && src->len) { /* Only insert if valid */ + if (src && src->net && src->len) { /* Only insert if valid */ len += encode_unsigned16(&npdu[len], src->net); npdu[len++] = src->len; /* SLEN = 0 denotes broadcast MAC SADR and SADR field is absent */ @@ -264,22 +257,23 @@ is expected for the service being issued. * @see npdu_encode_npdu_network if you need to set a network layer msg. * * @param npdu_data [out] Returns a filled-out structure with information - * provided by the other arguments and good defaults. + * provided by the other arguments and + * good defaults. * @param data_expecting_reply [in] True if message should have a reply. * @param priority [in] One of the 4 priorities defined in section 6.2.2, * like B'11' = Life Safety message */ -void npdu_encode_npdu_data( - BACNET_NPDU_DATA * npdu_data, - bool data_expecting_reply, - BACNET_MESSAGE_PRIORITY priority) +void npdu_encode_npdu_data(BACNET_NPDU_DATA *npdu_data, + bool data_expecting_reply, + BACNET_MESSAGE_PRIORITY priority) { if (npdu_data) { npdu_data->data_expecting_reply = data_expecting_reply; npdu_data->protocol_version = BACNET_PROTOCOL_VERSION; - npdu_data->network_layer_message = false; /* false if APDU */ - npdu_data->network_message_type = NETWORK_MESSAGE_INVALID; /* optional */ - npdu_data->vendor_id = 0; /* optional, if net message type is > 0x80 */ + npdu_data->network_layer_message = false; /* false if APDU */ + npdu_data->network_message_type = + NETWORK_MESSAGE_INVALID; /* optional */ + npdu_data->vendor_id = 0; /* optional, if net message type is > 0x80 */ npdu_data->priority = priority; npdu_data->hop_count = HOP_COUNT_DEFAULT; } @@ -288,7 +282,8 @@ void npdu_encode_npdu_data( /** Decode the NPDU portion of a received message, particularly the NCPI byte. * The Network Layer Protocol Control Information byte is described * in section 6.2.2 of the BACnet standard. - * @param npdu [in] Buffer holding the received NPDU header bytes (must be at least 2) + * @param npdu [in] Buffer holding the received NPDU header bytes (must be at + * least 2) * @param dest [out] Returned with routing destination information if the NPDU * has any and if this points to non-null storage for it. * If dest->net and dest->len are 0 on return, there is no @@ -300,20 +295,18 @@ void npdu_encode_npdu_data( * This src describes the original source of the message when * it had to be routed to reach this BACnet Device. * @param npdu_data [out] Returns a filled-out structure with information - * decoded from the NCPI and other NPDU bytes. + * decoded from the NCPI and other NPDU + * bytes. * @return On success, returns the number of bytes which were decoded from the - * NPDU section; if this is a network layer message, there may be more - * bytes left in the NPDU; if not a network msg, the APDU follows. - * If 0 or negative, there were problems with the data or arguments. + * NPDU section; if this is a network layer message, there may + * be more bytes left in the NPDU; if not a network msg, the APDU follows. If 0 + * or negative, there were problems with the data or arguments. */ -int npdu_decode( - uint8_t * npdu, - BACNET_ADDRESS * dest, - BACNET_ADDRESS * src, - BACNET_NPDU_DATA * npdu_data) +int npdu_decode(uint8_t *npdu, BACNET_ADDRESS *dest, BACNET_ADDRESS *src, + BACNET_NPDU_DATA *npdu_data) { - int len = 0; /* return value - number of octets loaded in this function */ - uint8_t i = 0; /* counter */ + int len = 0; /* return value - number of octets loaded in this function */ + uint8_t i = 0; /* counter */ uint16_t src_net = 0; uint16_t dest_net = 0; uint8_t slen = 0; @@ -345,7 +338,7 @@ int npdu_decode( /* B'10' = Critical Equipment message */ /* B'01' = Urgent message */ /* B'00' = Normal message */ - npdu_data->priority = (BACNET_MESSAGE_PRIORITY) (npdu[1] & 0x03); + npdu_data->priority = (BACNET_MESSAGE_PRIORITY)(npdu[1] & 0x03); /* set the offset to where the optional stuff starts */ len = 2; /*Bit 5: Destination specifier where: */ @@ -431,7 +424,7 @@ int npdu_decode( /* Message Type field is present. */ if (npdu_data->network_layer_message) { npdu_data->network_message_type = - (BACNET_NETWORK_MESSAGE_TYPE) npdu[len++]; + (BACNET_NETWORK_MESSAGE_TYPE)npdu[len++]; /* Message Type field contains a value in the range 0x80 - 0xFF, */ /* then a Vendor ID field shall be present */ if (npdu_data->network_message_type >= 0x80) @@ -451,23 +444,22 @@ int npdu_decode( #include #include "ctest.h" -void testNPDU2( - Test * pTest) +void testNPDU2(Test *pTest) { - uint8_t pdu[480] = { 0 }; - BACNET_ADDRESS dest = { 0 }; - BACNET_ADDRESS src = { 0 }; - BACNET_ADDRESS npdu_dest = { 0 }; - BACNET_ADDRESS npdu_src = { 0 }; + uint8_t pdu[480] = {0}; + BACNET_ADDRESS dest = {0}; + BACNET_ADDRESS src = {0}; + BACNET_ADDRESS npdu_dest = {0}; + BACNET_ADDRESS npdu_src = {0}; int len = 0; bool data_expecting_reply = true; BACNET_MESSAGE_PRIORITY priority = MESSAGE_PRIORITY_NORMAL; - BACNET_NPDU_DATA npdu_data = { 0 }; - int i = 0; /* counter */ + BACNET_NPDU_DATA npdu_data = {0}; + int i = 0; /* counter */ int npdu_len = 0; - bool network_layer_message = false; /* false if APDU */ - BACNET_NETWORK_MESSAGE_TYPE network_message_type = 0; /* optional */ - uint16_t vendor_id = 0; /* optional, if net message type is > 0x80 */ + bool network_layer_message = false; /* false if APDU */ + BACNET_NETWORK_MESSAGE_TYPE network_message_type = 0; /* optional */ + uint16_t vendor_id = 0; /* optional, if net message type is > 0x80 */ dest.mac_len = 6; for (i = 0; i < dest.mac_len; i++) { @@ -516,23 +508,22 @@ void testNPDU2( } } -void testNPDU1( - Test * pTest) +void testNPDU1(Test *pTest) { - uint8_t pdu[480] = { 0 }; - BACNET_ADDRESS dest = { 0 }; - BACNET_ADDRESS src = { 0 }; - BACNET_ADDRESS npdu_dest = { 0 }; - BACNET_ADDRESS npdu_src = { 0 }; + uint8_t pdu[480] = {0}; + BACNET_ADDRESS dest = {0}; + BACNET_ADDRESS src = {0}; + BACNET_ADDRESS npdu_dest = {0}; + BACNET_ADDRESS npdu_src = {0}; int len = 0; bool data_expecting_reply = false; BACNET_MESSAGE_PRIORITY priority = MESSAGE_PRIORITY_NORMAL; - BACNET_NPDU_DATA npdu_data = { 0 }; - int i = 0; /* counter */ + BACNET_NPDU_DATA npdu_data = {0}; + int i = 0; /* counter */ int npdu_len = 0; - bool network_layer_message = false; /* false if APDU */ - BACNET_NETWORK_MESSAGE_TYPE network_message_type = 0; /* optional */ - uint16_t vendor_id = 0; /* optional, if net message type is > 0x80 */ + bool network_layer_message = false; /* false if APDU */ + BACNET_NETWORK_MESSAGE_TYPE network_message_type = 0; /* optional */ + uint16_t vendor_id = 0; /* optional, if net message type is > 0x80 */ /* mac_len = 0 if global address */ dest.mac_len = 0; @@ -574,24 +565,20 @@ void testNPDU1( #ifdef TEST_NPDU /* dummy stub for testing */ -void tsm_free_invoke_id( - uint8_t invokeID) +void tsm_free_invoke_id(uint8_t invokeID) { - (void) invokeID; + (void)invokeID; } -void iam_handler( - uint8_t * service_request, - uint16_t service_len, - BACNET_ADDRESS * src) +void iam_handler(uint8_t *service_request, uint16_t service_len, + BACNET_ADDRESS *src) { - (void) service_request; - (void) service_len; - (void) src; + (void)service_request; + (void)service_len; + (void)src; } -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -605,7 +592,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/src/proplist.c b/src/proplist.c index 69d6798c..31b2f242 100644 --- a/src/proplist.c +++ b/src/proplist.c @@ -49,11 +49,7 @@ /* note: the PROP_PROPERTY_LIST is NOT included in these lists, on purpose */ static const int Default_Properties_Required[] = { - PROP_OBJECT_IDENTIFIER, - PROP_OBJECT_NAME, - PROP_OBJECT_TYPE, - -1 -}; + PROP_OBJECT_IDENTIFIER, PROP_OBJECT_NAME, PROP_OBJECT_TYPE, -1}; static const int Device_Properties_Required[] = { PROP_OBJECT_IDENTIFIER, @@ -76,8 +72,7 @@ static const int Device_Properties_Required[] = { PROP_NUMBER_OF_APDU_RETRIES, PROP_DEVICE_ADDRESS_BINDING, PROP_DATABASE_REVISION, - -1 -}; + -1}; static const int Device_Properties_Optional[] = { PROP_LOCATION, @@ -114,22 +109,19 @@ static const int Device_Properties_Optional[] = { PROP_ALIGN_INTERVALS, PROP_INTERVAL_OFFSET, PROP_PROFILE_NAME, - -1 -}; + -1}; -static const int Accumulator_Properties_Required[] = { - PROP_OBJECT_IDENTIFIER, - PROP_OBJECT_NAME, - PROP_OBJECT_TYPE, - PROP_PRESENT_VALUE, - PROP_STATUS_FLAGS, - PROP_EVENT_STATE, - PROP_OUT_OF_SERVICE, - PROP_SCALE, - PROP_UNITS, - PROP_MAX_PRES_VALUE, - -1 -}; +static const int Accumulator_Properties_Required[] = {PROP_OBJECT_IDENTIFIER, + PROP_OBJECT_NAME, + PROP_OBJECT_TYPE, + PROP_PRESENT_VALUE, + PROP_STATUS_FLAGS, + PROP_EVENT_STATE, + PROP_OUT_OF_SERVICE, + PROP_SCALE, + PROP_UNITS, + PROP_MAX_PRES_VALUE, + -1}; static const int Accumulator_Properties_Optional[] = { PROP_DESCRIPTION, @@ -155,20 +147,12 @@ static const int Accumulator_Properties_Optional[] = { PROP_EVENT_MESSAGE_TEXTS, PROP_RELIABILITY_EVALUATION_INHIBIT, PROP_PROFILE_NAME, - -1 -}; + -1}; static const int Analog_Input_Properties_Required[] = { - PROP_OBJECT_IDENTIFIER, - PROP_OBJECT_NAME, - PROP_OBJECT_TYPE, - PROP_PRESENT_VALUE, - PROP_STATUS_FLAGS, - PROP_EVENT_STATE, - PROP_OUT_OF_SERVICE, - PROP_UNITS, - -1 -}; + PROP_OBJECT_IDENTIFIER, PROP_OBJECT_NAME, PROP_OBJECT_TYPE, + PROP_PRESENT_VALUE, PROP_STATUS_FLAGS, PROP_EVENT_STATE, + PROP_OUT_OF_SERVICE, PROP_UNITS, -1}; static const int Analog_Input_Properties_Optional[] = { PROP_DESCRIPTION, @@ -192,22 +176,19 @@ static const int Analog_Input_Properties_Optional[] = { PROP_EVENT_MESSAGE_TEXTS, PROP_RELIABILITY_EVALUATION_INHIBIT, PROP_PROFILE_NAME, - -1 -}; + -1}; -static const int Analog_Output_Properties_Required[] = { - PROP_OBJECT_IDENTIFIER, - PROP_OBJECT_NAME, - PROP_OBJECT_TYPE, - PROP_PRESENT_VALUE, - PROP_STATUS_FLAGS, - PROP_EVENT_STATE, - PROP_OUT_OF_SERVICE, - PROP_UNITS, - PROP_PRIORITY_ARRAY, - PROP_RELINQUISH_DEFAULT, - -1 -}; +static const int Analog_Output_Properties_Required[] = {PROP_OBJECT_IDENTIFIER, + PROP_OBJECT_NAME, + PROP_OBJECT_TYPE, + PROP_PRESENT_VALUE, + PROP_STATUS_FLAGS, + PROP_EVENT_STATE, + PROP_OUT_OF_SERVICE, + PROP_UNITS, + PROP_PRIORITY_ARRAY, + PROP_RELINQUISH_DEFAULT, + -1}; static const int Analog_Output_Properties_Optional[] = { PROP_DESCRIPTION, @@ -230,20 +211,12 @@ static const int Analog_Output_Properties_Optional[] = { PROP_EVENT_MESSAGE_TEXTS, PROP_RELIABILITY_EVALUATION_INHIBIT, PROP_PROFILE_NAME, - -1 -}; + -1}; static const int Analog_Value_Properties_Required[] = { - PROP_OBJECT_IDENTIFIER, - PROP_OBJECT_NAME, - PROP_OBJECT_TYPE, - PROP_PRESENT_VALUE, - PROP_STATUS_FLAGS, - PROP_EVENT_STATE, - PROP_OUT_OF_SERVICE, - PROP_UNITS, - -1 -}; + PROP_OBJECT_IDENTIFIER, PROP_OBJECT_NAME, PROP_OBJECT_TYPE, + PROP_PRESENT_VALUE, PROP_STATUS_FLAGS, PROP_EVENT_STATE, + PROP_OUT_OF_SERVICE, PROP_UNITS, -1}; static const int Analog_Value_Properties_Optional[] = { PROP_DESCRIPTION, @@ -264,22 +237,19 @@ static const int Analog_Value_Properties_Optional[] = { PROP_EVENT_MESSAGE_TEXTS, PROP_RELIABILITY_EVALUATION_INHIBIT, PROP_PROFILE_NAME, - -1 -}; + -1}; -static const int Averaging_Properties_Required[] = { - PROP_OBJECT_IDENTIFIER, - PROP_OBJECT_NAME, - PROP_OBJECT_TYPE, - PROP_MINIMUM_VALUE, - PROP_AVERAGE_VALUE, - PROP_MAXIMUM_VALUE, - PROP_STATUS_FLAGS, - PROP_EVENT_STATE, - PROP_OUT_OF_SERVICE, - PROP_UNITS, - -1 -}; +static const int Averaging_Properties_Required[] = {PROP_OBJECT_IDENTIFIER, + PROP_OBJECT_NAME, + PROP_OBJECT_TYPE, + PROP_MINIMUM_VALUE, + PROP_AVERAGE_VALUE, + PROP_MAXIMUM_VALUE, + PROP_STATUS_FLAGS, + PROP_EVENT_STATE, + PROP_OUT_OF_SERVICE, + PROP_UNITS, + -1}; static const int Averaging_Properties_Optional[] = { PROP_PROFILE_NAME, @@ -292,20 +262,12 @@ static const int Averaging_Properties_Optional[] = { PROP_OBJECT_PROPERTY_REFERENCE, PROP_WINDOW_INTERVAL, PROP_WINDOW_SAMPLES, - -1 -}; + -1}; static const int Binary_Input_Properties_Required[] = { - PROP_OBJECT_IDENTIFIER, - PROP_OBJECT_NAME, - PROP_OBJECT_TYPE, - PROP_PRESENT_VALUE, - PROP_STATUS_FLAGS, - PROP_EVENT_STATE, - PROP_OUT_OF_SERVICE, - PROP_POLARITY, - -1 -}; + PROP_OBJECT_IDENTIFIER, PROP_OBJECT_NAME, PROP_OBJECT_TYPE, + PROP_PRESENT_VALUE, PROP_STATUS_FLAGS, PROP_EVENT_STATE, + PROP_OUT_OF_SERVICE, PROP_POLARITY, -1}; static const int Binary_Input_Properties_Optional[] = { PROP_DESCRIPTION, @@ -328,22 +290,19 @@ static const int Binary_Input_Properties_Optional[] = { PROP_EVENT_MESSAGE_TEXTS, PROP_RELIABILITY_EVALUATION_INHIBIT, PROP_PROFILE_NAME, - -1 -}; + -1}; -static const int Binary_Output_Properties_Required[] = { - PROP_OBJECT_IDENTIFIER, - PROP_OBJECT_NAME, - PROP_OBJECT_TYPE, - PROP_PRESENT_VALUE, - PROP_STATUS_FLAGS, - PROP_EVENT_STATE, - PROP_OUT_OF_SERVICE, - PROP_POLARITY, - PROP_PRIORITY_ARRAY, - PROP_RELINQUISH_DEFAULT, - -1 -}; +static const int Binary_Output_Properties_Required[] = {PROP_OBJECT_IDENTIFIER, + PROP_OBJECT_NAME, + PROP_OBJECT_TYPE, + PROP_PRESENT_VALUE, + PROP_STATUS_FLAGS, + PROP_EVENT_STATE, + PROP_OUT_OF_SERVICE, + PROP_POLARITY, + PROP_PRIORITY_ARRAY, + PROP_RELINQUISH_DEFAULT, + -1}; static const int Binary_Output_Properties_Optional[] = { PROP_DESCRIPTION, @@ -368,19 +327,13 @@ static const int Binary_Output_Properties_Optional[] = { PROP_EVENT_MESSAGE_TEXTS, PROP_RELIABILITY_EVALUATION_INHIBIT, PROP_PROFILE_NAME, - -1 -}; + -1}; static const int Binary_Value_Properties_Required[] = { - PROP_OBJECT_IDENTIFIER, - PROP_OBJECT_NAME, - PROP_OBJECT_TYPE, - PROP_PRESENT_VALUE, - PROP_STATUS_FLAGS, - PROP_EVENT_STATE, - PROP_OUT_OF_SERVICE, - -1 -}; + PROP_OBJECT_IDENTIFIER, PROP_OBJECT_NAME, + PROP_OBJECT_TYPE, PROP_PRESENT_VALUE, + PROP_STATUS_FLAGS, PROP_EVENT_STATE, + PROP_OUT_OF_SERVICE, -1}; static const int Binary_Value_Properties_Optional[] = { PROP_DESCRIPTION, @@ -406,23 +359,14 @@ static const int Binary_Value_Properties_Optional[] = { PROP_EVENT_MESSAGE_TEXTS, PROP_RELIABILITY_EVALUATION_INHIBIT, PROP_PROFILE_NAME, - -1 -}; + -1}; static const int Calendar_Properties_Required[] = { - PROP_OBJECT_IDENTIFIER, - PROP_OBJECT_NAME, - PROP_OBJECT_TYPE, - PROP_PRESENT_VALUE, - PROP_DATE_LIST, - -1 -}; + PROP_OBJECT_IDENTIFIER, PROP_OBJECT_NAME, PROP_OBJECT_TYPE, + PROP_PRESENT_VALUE, PROP_DATE_LIST, -1}; -static const int Calendar_Properties_Optional[] = { - PROP_DESCRIPTION, - PROP_PROFILE_NAME, - -1 -}; +static const int Calendar_Properties_Optional[] = {PROP_DESCRIPTION, + PROP_PROFILE_NAME, -1}; static const int Channel_Properties_Required[] = { PROP_OBJECT_IDENTIFIER, @@ -436,8 +380,7 @@ static const int Channel_Properties_Required[] = { PROP_LIST_OF_OBJECT_PROPERTY_REFERENCES, PROP_CHANNEL_NUMBER, PROP_CONTROL_GROUPS, - -1 -}; + -1}; static const int Channel_Properties_Optional[] = { PROP_DESCRIPTION, @@ -455,56 +398,34 @@ static const int Channel_Properties_Optional[] = { PROP_EVENT_MESSAGE_TEXTS_CONFIG, PROP_RELIABILITY_EVALUATION_INHIBIT, PROP_PROFILE_NAME, - -1 -}; + -1}; -static const int Command_Properties_Required[] = { - PROP_OBJECT_IDENTIFIER, - PROP_OBJECT_NAME, - PROP_OBJECT_TYPE, - PROP_PRESENT_VALUE, - PROP_IN_PROCESS, - PROP_ALL_WRITES_SUCCESSFUL, - PROP_ACTION, - -1 -}; +static const int Command_Properties_Required[] = {PROP_OBJECT_IDENTIFIER, + PROP_OBJECT_NAME, + PROP_OBJECT_TYPE, + PROP_PRESENT_VALUE, + PROP_IN_PROCESS, + PROP_ALL_WRITES_SUCCESSFUL, + PROP_ACTION, + -1}; static const int Command_Properties_Optional[] = { - PROP_DESCRIPTION, - PROP_ACTION_TEXT, - PROP_PROFILE_NAME, - -1 -}; + PROP_DESCRIPTION, PROP_ACTION_TEXT, PROP_PROFILE_NAME, -1}; static const int CharacterString_Value_Properties_Required[] = { - PROP_OBJECT_IDENTIFIER, - PROP_OBJECT_NAME, - PROP_OBJECT_TYPE, - PROP_PRESENT_VALUE, - PROP_STATUS_FLAGS, - -1 -}; + PROP_OBJECT_IDENTIFIER, PROP_OBJECT_NAME, PROP_OBJECT_TYPE, + PROP_PRESENT_VALUE, PROP_STATUS_FLAGS, -1}; static const int CharacterString_Value_Properties_Optional[] = { - PROP_DESCRIPTION, - PROP_EVENT_STATE, - PROP_RELIABILITY, - PROP_OUT_OF_SERVICE, - PROP_PRIORITY_ARRAY, - PROP_RELINQUISH_DEFAULT, - PROP_TIME_DELAY, - PROP_NOTIFICATION_CLASS, - PROP_ALARM_VALUES, - PROP_FAULT_VALUES, - PROP_EVENT_ENABLE, - PROP_ACKED_TRANSITIONS, - PROP_NOTIFY_TYPE, - PROP_EVENT_TIME_STAMPS, - PROP_EVENT_MESSAGE_TEXTS, - PROP_RELIABILITY_EVALUATION_INHIBIT, - PROP_PROFILE_NAME, - -1 -}; + PROP_DESCRIPTION, PROP_EVENT_STATE, + PROP_RELIABILITY, PROP_OUT_OF_SERVICE, + PROP_PRIORITY_ARRAY, PROP_RELINQUISH_DEFAULT, + PROP_TIME_DELAY, PROP_NOTIFICATION_CLASS, + PROP_ALARM_VALUES, PROP_FAULT_VALUES, + PROP_EVENT_ENABLE, PROP_ACKED_TRANSITIONS, + PROP_NOTIFY_TYPE, PROP_EVENT_TIME_STAMPS, + PROP_EVENT_MESSAGE_TEXTS, PROP_RELIABILITY_EVALUATION_INHIBIT, + PROP_PROFILE_NAME, -1}; static const int Lighting_Output_Properties_Required[] = { PROP_OBJECT_IDENTIFIER, @@ -525,8 +446,7 @@ static const int Lighting_Output_Properties_Required[] = { PROP_PRIORITY_ARRAY, PROP_RELINQUISH_DEFAULT, PROP_LIGHTING_COMMAND_DEFAULT_PRIORITY, - -1 -}; + -1}; static const int Lighting_Output_Properties_Optional[] = { PROP_DESCRIPTION, @@ -540,8 +460,7 @@ static const int Lighting_Output_Properties_Optional[] = { PROP_COV_INCREMENT, PROP_RELIABILITY_EVALUATION_INHIBIT, PROP_PROFILE_NAME, - -1 -}; + -1}; static const int Load_Control_Properties_Required[] = { PROP_OBJECT_IDENTIFIER, @@ -559,42 +478,25 @@ static const int Load_Control_Properties_Required[] = { PROP_ACTUAL_SHED_LEVEL, PROP_SHED_LEVELS, PROP_SHED_LEVEL_DESCRIPTIONS, - -1 -}; + -1}; static const int Load_Control_Properties_Optional[] = { - PROP_DESCRIPTION, - PROP_STATE_DESCRIPTION, - PROP_RELIABILITY, - PROP_FULL_DUTY_BASELINE, - PROP_NOTIFICATION_CLASS, - PROP_TIME_DELAY, - PROP_EVENT_ENABLE, - PROP_ACKED_TRANSITIONS, - PROP_NOTIFY_TYPE, - PROP_EVENT_TIME_STAMPS, - PROP_EVENT_MESSAGE_TEXTS, - PROP_RELIABILITY_EVALUATION_INHIBIT, - PROP_PROFILE_NAME, - -1 -}; + PROP_DESCRIPTION, PROP_STATE_DESCRIPTION, + PROP_RELIABILITY, PROP_FULL_DUTY_BASELINE, + PROP_NOTIFICATION_CLASS, PROP_TIME_DELAY, + PROP_EVENT_ENABLE, PROP_ACKED_TRANSITIONS, + PROP_NOTIFY_TYPE, PROP_EVENT_TIME_STAMPS, + PROP_EVENT_MESSAGE_TEXTS, PROP_RELIABILITY_EVALUATION_INHIBIT, + PROP_PROFILE_NAME, -1}; static const int Life_Safety_Point_Properties_Required[] = { - PROP_OBJECT_IDENTIFIER, - PROP_OBJECT_NAME, - PROP_OBJECT_TYPE, - PROP_PRESENT_VALUE, - PROP_TRACKING_VALUE, - PROP_STATUS_FLAGS, - PROP_EVENT_STATE, - PROP_OUT_OF_SERVICE, - PROP_RELIABILITY, - PROP_MODE, - PROP_ACCEPTED_MODES, - PROP_SILENCED, - PROP_OPERATION_EXPECTED, - -1 -}; + PROP_OBJECT_IDENTIFIER, PROP_OBJECT_NAME, + PROP_OBJECT_TYPE, PROP_PRESENT_VALUE, + PROP_TRACKING_VALUE, PROP_STATUS_FLAGS, + PROP_EVENT_STATE, PROP_OUT_OF_SERVICE, + PROP_RELIABILITY, PROP_MODE, + PROP_ACCEPTED_MODES, PROP_SILENCED, + PROP_OPERATION_EXPECTED, -1}; static const int Life_Safety_Point_Properties_Optional[] = { PROP_DESCRIPTION, @@ -615,39 +517,22 @@ static const int Life_Safety_Point_Properties_Optional[] = { PROP_MEMBER_OF, PROP_RELIABILITY_EVALUATION_INHIBIT, PROP_PROFILE_NAME, - -1 -}; + -1}; static const int Multistate_Input_Properties_Required[] = { - PROP_OBJECT_IDENTIFIER, - PROP_OBJECT_NAME, - PROP_OBJECT_TYPE, - PROP_PRESENT_VALUE, - PROP_STATUS_FLAGS, - PROP_EVENT_STATE, - PROP_OUT_OF_SERVICE, - PROP_NUMBER_OF_STATES, - -1 -}; + PROP_OBJECT_IDENTIFIER, PROP_OBJECT_NAME, PROP_OBJECT_TYPE, + PROP_PRESENT_VALUE, PROP_STATUS_FLAGS, PROP_EVENT_STATE, + PROP_OUT_OF_SERVICE, PROP_NUMBER_OF_STATES, -1}; static const int Multistate_Input_Properties_Optional[] = { - PROP_DESCRIPTION, - PROP_DEVICE_TYPE, - PROP_RELIABILITY, - PROP_STATE_TEXT, - PROP_TIME_DELAY, - PROP_NOTIFICATION_CLASS, - PROP_ALARM_VALUES, - PROP_FAULT_VALUES, - PROP_EVENT_ENABLE, - PROP_ACKED_TRANSITIONS, - PROP_NOTIFY_TYPE, - PROP_EVENT_TIME_STAMPS, - PROP_EVENT_MESSAGE_TEXTS, - PROP_RELIABILITY_EVALUATION_INHIBIT, - PROP_PROFILE_NAME, - -1 -}; + PROP_DESCRIPTION, PROP_DEVICE_TYPE, + PROP_RELIABILITY, PROP_STATE_TEXT, + PROP_TIME_DELAY, PROP_NOTIFICATION_CLASS, + PROP_ALARM_VALUES, PROP_FAULT_VALUES, + PROP_EVENT_ENABLE, PROP_ACKED_TRANSITIONS, + PROP_NOTIFY_TYPE, PROP_EVENT_TIME_STAMPS, + PROP_EVENT_MESSAGE_TEXTS, PROP_RELIABILITY_EVALUATION_INHIBIT, + PROP_PROFILE_NAME, -1}; static const int Multistate_Output_Properties_Required[] = { PROP_OBJECT_IDENTIFIER, @@ -660,8 +545,7 @@ static const int Multistate_Output_Properties_Required[] = { PROP_NUMBER_OF_STATES, PROP_PRIORITY_ARRAY, PROP_RELINQUISH_DEFAULT, - -1 -}; + -1}; static const int Multistate_Output_Properties_Optional[] = { PROP_DESCRIPTION, @@ -678,20 +562,12 @@ static const int Multistate_Output_Properties_Optional[] = { PROP_EVENT_MESSAGE_TEXTS, PROP_RELIABILITY_EVALUATION_INHIBIT, PROP_PROFILE_NAME, - -1 -}; + -1}; static const int Multistate_Value_Properties_Required[] = { - PROP_OBJECT_IDENTIFIER, - PROP_OBJECT_NAME, - PROP_OBJECT_TYPE, - PROP_PRESENT_VALUE, - PROP_STATUS_FLAGS, - PROP_EVENT_STATE, - PROP_OUT_OF_SERVICE, - PROP_NUMBER_OF_STATES, - -1 -}; + PROP_OBJECT_IDENTIFIER, PROP_OBJECT_NAME, PROP_OBJECT_TYPE, + PROP_PRESENT_VALUE, PROP_STATUS_FLAGS, PROP_EVENT_STATE, + PROP_OUT_OF_SERVICE, PROP_NUMBER_OF_STATES, -1}; static const int Multistate_Value_Properties_Optional[] = { PROP_DESCRIPTION, @@ -710,41 +586,30 @@ static const int Multistate_Value_Properties_Optional[] = { PROP_EVENT_MESSAGE_TEXTS, PROP_RELIABILITY_EVALUATION_INHIBIT, PROP_PROFILE_NAME, - -1 -}; + -1}; static const int Notification_Class_Properties_Required[] = { - PROP_OBJECT_IDENTIFIER, - PROP_OBJECT_NAME, - PROP_OBJECT_TYPE, - PROP_NOTIFICATION_CLASS, - PROP_PRIORITY, - PROP_ACK_REQUIRED, - PROP_RECIPIENT_LIST, - -1 -}; + PROP_OBJECT_IDENTIFIER, PROP_OBJECT_NAME, + PROP_OBJECT_TYPE, PROP_NOTIFICATION_CLASS, + PROP_PRIORITY, PROP_ACK_REQUIRED, + PROP_RECIPIENT_LIST, -1}; static const int Notification_Class_Properties_Optional[] = { - PROP_DESCRIPTION, - PROP_PROFILE_NAME, - -1 -}; + PROP_DESCRIPTION, PROP_PROFILE_NAME, -1}; -static const int Trend_Log_Properties_Required[] = { - PROP_OBJECT_IDENTIFIER, - PROP_OBJECT_NAME, - PROP_OBJECT_TYPE, - PROP_ENABLE, - PROP_STOP_WHEN_FULL, - PROP_BUFFER_SIZE, - PROP_LOG_BUFFER, - PROP_RECORD_COUNT, - PROP_TOTAL_RECORD_COUNT, - PROP_EVENT_STATE, - PROP_LOGGING_TYPE, - PROP_STATUS_FLAGS, - -1 -}; +static const int Trend_Log_Properties_Required[] = {PROP_OBJECT_IDENTIFIER, + PROP_OBJECT_NAME, + PROP_OBJECT_TYPE, + PROP_ENABLE, + PROP_STOP_WHEN_FULL, + PROP_BUFFER_SIZE, + PROP_LOG_BUFFER, + PROP_RECORD_COUNT, + PROP_TOTAL_RECORD_COUNT, + PROP_EVENT_STATE, + PROP_LOGGING_TYPE, + PROP_STATUS_FLAGS, + -1}; static const int Trend_Log_Properties_Optional[] = { PROP_DESCRIPTION, @@ -769,39 +634,30 @@ static const int Trend_Log_Properties_Optional[] = { PROP_RELIABILITY, PROP_RELIABILITY_EVALUATION_INHIBIT, PROP_PROFILE_NAME, - -1 -}; + -1}; -static const int File_Properties_Required[] = { - PROP_OBJECT_IDENTIFIER, - PROP_OBJECT_NAME, - PROP_OBJECT_TYPE, - PROP_FILE_TYPE, - PROP_FILE_SIZE, - PROP_MODIFICATION_DATE, - PROP_ARCHIVE, - PROP_READ_ONLY, - PROP_FILE_ACCESS_METHOD, - -1 -}; +static const int File_Properties_Required[] = {PROP_OBJECT_IDENTIFIER, + PROP_OBJECT_NAME, + PROP_OBJECT_TYPE, + PROP_FILE_TYPE, + PROP_FILE_SIZE, + PROP_MODIFICATION_DATE, + PROP_ARCHIVE, + PROP_READ_ONLY, + PROP_FILE_ACCESS_METHOD, + -1}; static const int File_Properties_Optional[] = { - PROP_DESCRIPTION, - PROP_RECORD_COUNT, - PROP_PROFILE_NAME, - -1 -}; + PROP_DESCRIPTION, PROP_RECORD_COUNT, PROP_PROFILE_NAME, -1}; /* These three arrays are used by the ReadPropertyMultiple handler */ -static const int Integer_Value_Properties_Required[] = { - PROP_OBJECT_IDENTIFIER, - PROP_OBJECT_NAME, - PROP_OBJECT_TYPE, - PROP_PRESENT_VALUE, - PROP_STATUS_FLAGS, - PROP_UNITS, - -1 -}; +static const int Integer_Value_Properties_Required[] = {PROP_OBJECT_IDENTIFIER, + PROP_OBJECT_NAME, + PROP_OBJECT_TYPE, + PROP_PRESENT_VALUE, + PROP_STATUS_FLAGS, + PROP_UNITS, + -1}; static const int Integer_Value_Properties_Optional[] = { PROP_DESCRIPTION, @@ -832,8 +688,7 @@ static const int Integer_Value_Properties_Optional[] = { PROP_MAX_PRES_VALUE, PROP_RESOLUTION, PROP_PROFILE_NAME, - -1 -}; + -1}; /** * Function that returns the list of all Optional properties @@ -844,10 +699,9 @@ static const int Integer_Value_Properties_Optional[] = { * type 'int' that contain BACnet object properties for the given object * type. */ -const int * property_list_optional( - BACNET_OBJECT_TYPE object_type) +const int *property_list_optional(BACNET_OBJECT_TYPE object_type) { - const int * pList = NULL; + const int *pList = NULL; switch (object_type) { case OBJECT_DEVICE: @@ -887,8 +741,7 @@ const int * property_list_optional( pList = Command_Properties_Optional; break; case OBJECT_CHARACTERSTRING_VALUE: - pList = - CharacterString_Value_Properties_Optional; + pList = CharacterString_Value_Properties_Optional; break; case OBJECT_LIGHTING_OUTPUT: pList = Lighting_Output_Properties_Optional; @@ -897,24 +750,19 @@ const int * property_list_optional( pList = Load_Control_Properties_Optional; break; case OBJECT_LIFE_SAFETY_POINT: - pList = - Life_Safety_Point_Properties_Optional; + pList = Life_Safety_Point_Properties_Optional; break; case OBJECT_MULTI_STATE_INPUT: - pList = - Multistate_Input_Properties_Optional; + pList = Multistate_Input_Properties_Optional; break; case OBJECT_MULTI_STATE_OUTPUT: - pList = - Multistate_Output_Properties_Optional; + pList = Multistate_Output_Properties_Optional; break; case OBJECT_MULTI_STATE_VALUE: - pList = - Multistate_Value_Properties_Optional; + pList = Multistate_Value_Properties_Optional; break; case OBJECT_NOTIFICATION_CLASS: - pList = - Notification_Class_Properties_Optional; + pList = Notification_Class_Properties_Optional; break; case OBJECT_TRENDLOG: pList = Trend_Log_Properties_Optional; @@ -941,10 +789,9 @@ const int * property_list_optional( * type 'int' that contain BACnet object properties for the given object * type. */ -const int * property_list_required( - BACNET_OBJECT_TYPE object_type) +const int *property_list_required(BACNET_OBJECT_TYPE object_type) { - const int * pList = NULL; + const int *pList = NULL; switch (object_type) { case OBJECT_DEVICE: @@ -984,8 +831,7 @@ const int * property_list_required( pList = Command_Properties_Required; break; case OBJECT_CHARACTERSTRING_VALUE: - pList = - CharacterString_Value_Properties_Required; + pList = CharacterString_Value_Properties_Required; break; case OBJECT_LOAD_CONTROL: pList = Load_Control_Properties_Required; @@ -994,24 +840,19 @@ const int * property_list_required( pList = Lighting_Output_Properties_Required; break; case OBJECT_LIFE_SAFETY_POINT: - pList = - Life_Safety_Point_Properties_Required; + pList = Life_Safety_Point_Properties_Required; break; case OBJECT_MULTI_STATE_INPUT: - pList = - Multistate_Input_Properties_Required; + pList = Multistate_Input_Properties_Required; break; case OBJECT_MULTI_STATE_OUTPUT: - pList = - Multistate_Output_Properties_Required; + pList = Multistate_Output_Properties_Required; break; case OBJECT_MULTI_STATE_VALUE: - pList = - Multistate_Value_Properties_Required; + pList = Multistate_Value_Properties_Required; break; case OBJECT_NOTIFICATION_CLASS: - pList = - Notification_Class_Properties_Required; + pList = Notification_Class_Properties_Required; break; case OBJECT_TRENDLOG: pList = Trend_Log_Properties_Required; @@ -1039,9 +880,8 @@ const int * property_list_required( * type 'int' that contain BACnet object properties for the given object * type. */ -void property_list_special( - BACNET_OBJECT_TYPE object_type, - struct special_property_list_t *pPropertyList) +void property_list_special(BACNET_OBJECT_TYPE object_type, + struct special_property_list_t *pPropertyList) { if (pPropertyList == NULL) { return; @@ -1060,13 +900,12 @@ void property_list_special( } BACNET_PROPERTY_ID property_list_special_property( - BACNET_OBJECT_TYPE object_type, - BACNET_PROPERTY_ID special_property, + BACNET_OBJECT_TYPE object_type, BACNET_PROPERTY_ID special_property, unsigned index) { - int property = -1; /* return value */ + int property = -1; /* return value */ unsigned required, optional, proprietary; - struct special_property_list_t PropertyList = { {0} }; + struct special_property_list_t PropertyList = {{0}}; property_list_special(object_type, &PropertyList); required = PropertyList.Required.count; @@ -1102,21 +941,19 @@ BACNET_PROPERTY_ID property_list_special_property( } } - return (BACNET_PROPERTY_ID) property; + return (BACNET_PROPERTY_ID)property; } -unsigned property_list_special_count( - BACNET_OBJECT_TYPE object_type, - BACNET_PROPERTY_ID special_property) +unsigned property_list_special_count(BACNET_OBJECT_TYPE object_type, + BACNET_PROPERTY_ID special_property) { unsigned count = 0; /* return value */ - struct special_property_list_t PropertyList = { {0} }; + struct special_property_list_t PropertyList = {{0}}; property_list_special(object_type, &PropertyList); if (special_property == PROP_ALL) { - count = - PropertyList.Required.count + PropertyList.Optional.count + - PropertyList.Proprietary.count; + count = PropertyList.Required.count + PropertyList.Optional.count + + PropertyList.Proprietary.count; } else if (special_property == PROP_REQUIRED) { count = PropertyList.Required.count; } else if (special_property == PROP_OPTIONAL) { @@ -1133,8 +970,7 @@ unsigned property_list_special_count( * @param pList - array of type 'int' that is a list of BACnet object * properties, terminated by a '-1' value. */ -unsigned property_list_count( - const int *pList) +unsigned property_list_count(const int *pList) { unsigned property_count = 0; @@ -1156,9 +992,7 @@ unsigned property_list_count( * * @return true if object_property is a member of the property list */ -bool property_list_member( - const int *pList, - int object_property) +bool property_list_member(const int *pList, int object_property) { bool status = false; @@ -1185,13 +1019,11 @@ bool property_list_member( * @return number of APDU bytes in the response, or * BACNET_STATUS_ERROR on error. */ -int property_list_encode( - BACNET_READ_PROPERTY_DATA * rpdata, - const int *pListRequired, - const int *pListOptional, - const int *pListProprietary) +int property_list_encode(BACNET_READ_PROPERTY_DATA *rpdata, + const int *pListRequired, const int *pListOptional, + const int *pListProprietary) { - int apdu_len = 0; /* return value */ + int apdu_len = 0; /* return value */ uint8_t *apdu = NULL; int max_apdu_len = 0; uint32_t count = 0; @@ -1220,10 +1052,10 @@ int property_list_encode( case PROP_PROPERTY_LIST: if (rpdata->array_index == 0) { /* Array element zero is the number of elements in the array */ - apdu_len = - encode_application_unsigned(&apdu[0], count); + apdu_len = encode_application_unsigned(&apdu[0], count); } else if (rpdata->array_index == BACNET_ARRAY_ALL) { - /* if no index was specified, then try to encode the entire list */ + /* if no index was specified, then try to encode the entire list + */ /* into one packet. */ if (required_count > 3) { for (i = 0; i < required_count; i++) { @@ -1232,9 +1064,8 @@ int property_list_encode( (pListRequired[i] == PROP_OBJECT_NAME)) { continue; } else { - len = - encode_application_enumerated(&apdu[apdu_len], - (uint32_t)pListRequired[i]); + len = encode_application_enumerated( + &apdu[apdu_len], (uint32_t)pListRequired[i]); } /* add it if we have room */ if ((apdu_len + len) < max_apdu_len) { @@ -1249,9 +1080,8 @@ int property_list_encode( } if (optional_count) { for (i = 0; i < optional_count; i++) { - len = - encode_application_enumerated(&apdu[apdu_len], - (uint32_t)pListOptional[i]); + len = encode_application_enumerated( + &apdu[apdu_len], (uint32_t)pListOptional[i]); /* add it if we have room */ if ((apdu_len + len) < max_apdu_len) { apdu_len += len; @@ -1265,9 +1095,8 @@ int property_list_encode( } if (proprietary_count) { for (i = 0; i < proprietary_count; i++) { - len = - encode_application_enumerated(&apdu[apdu_len], - (uint32_t)pListProprietary[i]); + len = encode_application_enumerated( + &apdu[apdu_len], (uint32_t)pListProprietary[i]); /* add it if we have room */ if ((apdu_len + len) < max_apdu_len) { apdu_len += len; @@ -1343,8 +1172,7 @@ int property_list_encode( #include #include "ctest.h" -void testPropList( - Test * pTest) +void testPropList(Test *pTest) { unsigned i = 0, j = 0; unsigned count = 0; @@ -1352,17 +1180,15 @@ void testPropList( unsigned object_id = 0, object_name = 0, object_type = 0; struct special_property_list_t property_list = {0}; - for (i = 0; i < OBJECT_PROPRIETARY_MIN; i++) { - count = property_list_special_count((BACNET_OBJECT_TYPE) i, PROP_ALL); + count = property_list_special_count((BACNET_OBJECT_TYPE)i, PROP_ALL); ct_test(pTest, count >= 3); object_id = 0; object_name = 0; object_type = 0; for (j = 0; j < count; j++) { - property = - property_list_special_property((BACNET_OBJECT_TYPE) i, - PROP_ALL, j); + property = property_list_special_property((BACNET_OBJECT_TYPE)i, + PROP_ALL, j); if (property == PROP_OBJECT_TYPE) { object_type++; } @@ -1377,25 +1203,18 @@ void testPropList( ct_test(pTest, object_id == 1); ct_test(pTest, object_name == 1); /* test member function */ - property_list_special((BACNET_OBJECT_TYPE) i, &property_list); - ct_test(pTest, - property_list_member( - property_list.Required.pList, - PROP_OBJECT_TYPE)); - ct_test(pTest, - property_list_member( - property_list.Required.pList, - PROP_OBJECT_IDENTIFIER)); - ct_test(pTest, - property_list_member( - property_list.Required.pList, - PROP_OBJECT_NAME)); + property_list_special((BACNET_OBJECT_TYPE)i, &property_list); + ct_test(pTest, property_list_member(property_list.Required.pList, + PROP_OBJECT_TYPE)); + ct_test(pTest, property_list_member(property_list.Required.pList, + PROP_OBJECT_IDENTIFIER)); + ct_test(pTest, property_list_member(property_list.Required.pList, + PROP_OBJECT_NAME)); } } #ifdef TEST_PROPLIST -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -1407,7 +1226,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/src/ptransfer.c b/src/ptransfer.c index 2807817b..67cdb854 100644 --- a/src/ptransfer.c +++ b/src/ptransfer.c @@ -40,30 +40,26 @@ /** @file ptransfer.c Encode/Decode Private Transfer data */ /* encode service */ -static int pt_encode_apdu( - uint8_t * apdu, - uint16_t max_apdu, - BACNET_PRIVATE_TRANSFER_DATA * private_data) +static int pt_encode_apdu(uint8_t *apdu, uint16_t max_apdu, + BACNET_PRIVATE_TRANSFER_DATA *private_data) { - int len = 0; /* length of each encoding */ - int apdu_len = 0; /* total length of the apdu, return value */ -/* - Unconfirmed/ConfirmedPrivateTransfer-Request ::= SEQUENCE { - vendorID [0] Unsigned, - serviceNumber [1] Unsigned, - serviceParameters [2] ABSTRACT-SYNTAX.&Type OPTIONAL - } -*/ + int len = 0; /* length of each encoding */ + int apdu_len = 0; /* total length of the apdu, return value */ + /* + Unconfirmed/ConfirmedPrivateTransfer-Request ::= SEQUENCE { + vendorID [0] Unsigned, + serviceNumber [1] Unsigned, + serviceParameters [2] ABSTRACT-SYNTAX.&Type OPTIONAL + } + */ /* unused parameter */ max_apdu = max_apdu; if (apdu) { len = - encode_context_unsigned(&apdu[apdu_len], 0, - private_data->vendorID); + encode_context_unsigned(&apdu[apdu_len], 0, private_data->vendorID); apdu_len += len; - len = - encode_context_unsigned(&apdu[apdu_len], 1, - private_data->serviceNumber); + len = encode_context_unsigned(&apdu[apdu_len], 1, + private_data->serviceNumber); apdu_len += len; len = encode_opening_tag(&apdu[apdu_len], 2); apdu_len += len; @@ -78,12 +74,10 @@ static int pt_encode_apdu( return apdu_len; } -int ptransfer_encode_apdu( - uint8_t * apdu, - uint8_t invoke_id, - BACNET_PRIVATE_TRANSFER_DATA * private_data) +int ptransfer_encode_apdu(uint8_t *apdu, uint8_t invoke_id, + BACNET_PRIVATE_TRANSFER_DATA *private_data) { - int apdu_len = 0; /* total length of the apdu, return value */ + int apdu_len = 0; /* total length of the apdu, return value */ int len = 0; if (apdu) { @@ -92,29 +86,26 @@ int ptransfer_encode_apdu( apdu[2] = invoke_id; apdu[3] = SERVICE_CONFIRMED_PRIVATE_TRANSFER; apdu_len = 4; - len = - pt_encode_apdu(&apdu[apdu_len], (uint16_t) (MAX_APDU - apdu_len), - private_data); + len = pt_encode_apdu(&apdu[apdu_len], (uint16_t)(MAX_APDU - apdu_len), + private_data); apdu_len += len; } return apdu_len; } -int uptransfer_encode_apdu( - uint8_t * apdu, - BACNET_PRIVATE_TRANSFER_DATA * private_data) +int uptransfer_encode_apdu(uint8_t *apdu, + BACNET_PRIVATE_TRANSFER_DATA *private_data) { - int apdu_len = 0; /* total length of the apdu, return value */ + int apdu_len = 0; /* total length of the apdu, return value */ int len = 0; if (apdu) { apdu[0] = PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST; apdu[1] = SERVICE_UNCONFIRMED_PRIVATE_TRANSFER; apdu_len = 2; - len = - pt_encode_apdu(&apdu[apdu_len], (uint16_t) (MAX_APDU - apdu_len), - private_data); + len = pt_encode_apdu(&apdu[apdu_len], (uint16_t)(MAX_APDU - apdu_len), + private_data); apdu_len += len; } @@ -122,10 +113,8 @@ int uptransfer_encode_apdu( } /* decode the service request only */ -int ptransfer_decode_service_request( - uint8_t * apdu, - unsigned apdu_len, - BACNET_PRIVATE_TRANSFER_DATA * private_data) +int ptransfer_decode_service_request(uint8_t *apdu, unsigned apdu_len, + BACNET_PRIVATE_TRANSFER_DATA *private_data) { int len = 0; /* return value */ int decode_len = 0; /* return value */ @@ -139,7 +128,7 @@ int ptransfer_decode_service_request( return -1; } len = decode_len; - private_data->vendorID = (uint16_t) unsigned_value; + private_data->vendorID = (uint16_t)unsigned_value; /* Tag 1: serviceNumber */ decode_len = decode_context_unsigned(&apdu[len], 1, &unsigned_value); if (decode_len < 0) { @@ -154,9 +143,9 @@ int ptransfer_decode_service_request( /* don't decode the serviceParameters here */ private_data->serviceParameters = &apdu[len]; private_data->serviceParametersLen = - (int) apdu_len - len - 1 /*closing tag */ ; + (int)apdu_len - len - 1 /*closing tag */; /* len includes the data and the closing tag */ - len = (int) apdu_len; + len = (int)apdu_len; } else { return -1; } @@ -165,15 +154,13 @@ int ptransfer_decode_service_request( return len; } -int ptransfer_error_encode_apdu( - uint8_t * apdu, - uint8_t invoke_id, - BACNET_ERROR_CLASS error_class, - BACNET_ERROR_CODE error_code, - BACNET_PRIVATE_TRANSFER_DATA * private_data) +int ptransfer_error_encode_apdu(uint8_t *apdu, uint8_t invoke_id, + BACNET_ERROR_CLASS error_class, + BACNET_ERROR_CODE error_code, + BACNET_PRIVATE_TRANSFER_DATA *private_data) { - int apdu_len = 0; /* total length of the apdu, return value */ - int len = 0; /* length of the part of the encoding */ + int apdu_len = 0; /* total length of the apdu, return value */ + int len = 0; /* length of the part of the encoding */ if (apdu) { apdu[0] = PDU_TYPE_ERROR; @@ -181,14 +168,14 @@ int ptransfer_error_encode_apdu( apdu[2] = SERVICE_CONFIRMED_PRIVATE_TRANSFER; apdu_len = 3; /* service parameters */ -/* - ConfirmedPrivateTransfer-Error ::= SEQUENCE { - errorType [0] Error, - vendorID [1] Unsigned, - serviceNumber [2] Unsigned, - errorParameters [3] ABSTRACT-SYNTAX.&Type OPTIONAL - } -*/ + /* + ConfirmedPrivateTransfer-Error ::= SEQUENCE { + errorType [0] Error, + vendorID [1] Unsigned, + serviceNumber [2] Unsigned, + errorParameters [3] ABSTRACT-SYNTAX.&Type OPTIONAL + } + */ len = encode_opening_tag(&apdu[apdu_len], 0); apdu_len += len; len = encode_application_enumerated(&apdu[apdu_len], error_class); @@ -198,12 +185,10 @@ int ptransfer_error_encode_apdu( len = encode_closing_tag(&apdu[apdu_len], 0); apdu_len += len; len = - encode_context_unsigned(&apdu[apdu_len], 1, - private_data->vendorID); + encode_context_unsigned(&apdu[apdu_len], 1, private_data->vendorID); apdu_len += len; - len = - encode_context_unsigned(&apdu[apdu_len], 2, - private_data->serviceNumber); + len = encode_context_unsigned(&apdu[apdu_len], 2, + private_data->serviceNumber); apdu_len += len; len = encode_opening_tag(&apdu[apdu_len], 3); apdu_len += len; @@ -220,11 +205,8 @@ int ptransfer_error_encode_apdu( /* decode the service request only */ int ptransfer_error_decode_service_request( - uint8_t * apdu, - unsigned apdu_len, - BACNET_ERROR_CLASS * error_class, - BACNET_ERROR_CODE * error_code, - BACNET_PRIVATE_TRANSFER_DATA * private_data) + uint8_t *apdu, unsigned apdu_len, BACNET_ERROR_CLASS *error_class, + BACNET_ERROR_CODE *error_code, BACNET_PRIVATE_TRANSFER_DATA *private_data) { int len = 0; /* return value */ int decode_len = 0; /* return value */ @@ -239,9 +221,8 @@ int ptransfer_error_decode_service_request( /* a tag number of 0 is not extended so only one octet */ len++; /* error class */ - decode_len = - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value_type); + decode_len = decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value_type); len += decode_len; if (tag_number != BACNET_APPLICATION_TAG_ENUMERATED) { return 0; @@ -250,12 +231,11 @@ int ptransfer_error_decode_service_request( decode_enumerated(&apdu[len], len_value_type, &unsigned_value); len += decode_len; if (error_class) { - *error_class = (BACNET_ERROR_CLASS) unsigned_value; + *error_class = (BACNET_ERROR_CLASS)unsigned_value; } /* error code */ - decode_len = - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value_type); + decode_len = decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value_type); len += decode_len; if (tag_number != BACNET_APPLICATION_TAG_ENUMERATED) { return 0; @@ -264,7 +244,7 @@ int ptransfer_error_decode_service_request( decode_enumerated(&apdu[len], len_value_type, &unsigned_value); len += decode_len; if (error_code) { - *error_code = (BACNET_ERROR_CODE) unsigned_value; + *error_code = (BACNET_ERROR_CODE)unsigned_value; } if (decode_is_closing_tag_number(&apdu[len], 0)) { /* a tag number of 0 is not extended so only one octet */ @@ -279,7 +259,7 @@ int ptransfer_error_decode_service_request( return -1; } len += decode_len; - private_data->vendorID = (uint16_t) unsigned_value; + private_data->vendorID = (uint16_t)unsigned_value; /* Tag 2: serviceNumber */ decode_len = decode_context_unsigned(&apdu[len], 2, &unsigned_value); if (decode_len < 0) { @@ -294,7 +274,7 @@ int ptransfer_error_decode_service_request( /* don't decode the serviceParameters here */ private_data->serviceParameters = &apdu[len]; private_data->serviceParametersLen = - (int) apdu_len - len - 1 /*closing tag */ ; + (int)apdu_len - len - 1 /*closing tag */; } else { return -1; } @@ -304,34 +284,30 @@ int ptransfer_error_decode_service_request( return len; } -int ptransfer_ack_encode_apdu( - uint8_t * apdu, - uint8_t invoke_id, - BACNET_PRIVATE_TRANSFER_DATA * private_data) +int ptransfer_ack_encode_apdu(uint8_t *apdu, uint8_t invoke_id, + BACNET_PRIVATE_TRANSFER_DATA *private_data) { - int len = 0; /* length of each encoding */ - int apdu_len = 0; /* total length of the apdu, return value */ + int len = 0; /* length of each encoding */ + int apdu_len = 0; /* total length of the apdu, return value */ if (apdu) { apdu[0] = PDU_TYPE_COMPLEX_ACK; /* complex ACK service */ - apdu[1] = invoke_id; /* original invoke id from request */ - apdu[2] = SERVICE_CONFIRMED_PRIVATE_TRANSFER; /* service choice */ + apdu[1] = invoke_id; /* original invoke id from request */ + apdu[2] = SERVICE_CONFIRMED_PRIVATE_TRANSFER; /* service choice */ apdu_len = 3; /* service ack follows */ -/* - ConfirmedPrivateTransfer-ACK ::= SEQUENCE { - vendorID [0] Unsigned, - serviceNumber [1] Unsigned, - resultBlock [2] ABSTRACT-SYNTAX.&Type OPTIONAL - } -*/ + /* + ConfirmedPrivateTransfer-ACK ::= SEQUENCE { + vendorID [0] Unsigned, + serviceNumber [1] Unsigned, + resultBlock [2] ABSTRACT-SYNTAX.&Type OPTIONAL + } + */ len = - encode_context_unsigned(&apdu[apdu_len], 0, - private_data->vendorID); + encode_context_unsigned(&apdu[apdu_len], 0, private_data->vendorID); apdu_len += len; - len = - encode_context_unsigned(&apdu[apdu_len], 1, - private_data->serviceNumber); + len = encode_context_unsigned(&apdu[apdu_len], 1, + private_data->serviceNumber); apdu_len += len; len = encode_opening_tag(&apdu[apdu_len], 2); apdu_len += len; @@ -349,18 +325,14 @@ int ptransfer_ack_encode_apdu( /* ptransfer_ack_decode_service_request() is the same as ptransfer_decode_service_request */ - #ifdef TEST #include #include #include "ctest.h" #include "bacapp.h" -int ptransfer_decode_apdu( - uint8_t * apdu, - unsigned apdu_len, - uint8_t * invoke_id, - BACNET_PRIVATE_TRANSFER_DATA * private_data) +int ptransfer_decode_apdu(uint8_t *apdu, unsigned apdu_len, uint8_t *invoke_id, + BACNET_PRIVATE_TRANSFER_DATA *private_data) { int len = 0; unsigned offset = 0; @@ -378,18 +350,15 @@ int ptransfer_decode_apdu( offset = 4; if (apdu_len > offset) { - len = - ptransfer_decode_service_request(&apdu[offset], apdu_len - offset, - private_data); + len = ptransfer_decode_service_request(&apdu[offset], apdu_len - offset, + private_data); } return len; } -int uptransfer_decode_apdu( - uint8_t * apdu, - unsigned apdu_len, - BACNET_PRIVATE_TRANSFER_DATA * private_data) +int uptransfer_decode_apdu(uint8_t *apdu, unsigned apdu_len, + BACNET_PRIVATE_TRANSFER_DATA *private_data) { int len = 0; unsigned offset = 0; @@ -406,19 +375,17 @@ int uptransfer_decode_apdu( } offset = 2; if (apdu_len > offset) { - len = - ptransfer_decode_service_request(&apdu[offset], apdu_len - offset, - private_data); + len = ptransfer_decode_service_request(&apdu[offset], apdu_len - offset, + private_data); } return len; } -int ptransfer_ack_decode_apdu( - uint8_t * apdu, - int apdu_len, /* total length of the apdu */ - uint8_t * invoke_id, - BACNET_PRIVATE_TRANSFER_DATA * private_data) +int ptransfer_ack_decode_apdu(uint8_t *apdu, + int apdu_len, /* total length of the apdu */ + uint8_t *invoke_id, + BACNET_PRIVATE_TRANSFER_DATA *private_data) { int len = 0; int offset = 0; @@ -433,21 +400,19 @@ int ptransfer_ack_decode_apdu( return -1; offset = 3; if (apdu_len > offset) { - len = - ptransfer_decode_service_request(&apdu[offset], apdu_len - offset, - private_data); + len = ptransfer_decode_service_request(&apdu[offset], apdu_len - offset, + private_data); } return len; } -int ptransfer_error_decode_apdu( - uint8_t * apdu, - int apdu_len, /* total length of the apdu */ - uint8_t * invoke_id, - BACNET_ERROR_CLASS * error_class, - BACNET_ERROR_CODE * error_code, - BACNET_PRIVATE_TRANSFER_DATA * private_data) +int ptransfer_error_decode_apdu(uint8_t *apdu, + int apdu_len, /* total length of the apdu */ + uint8_t *invoke_id, + BACNET_ERROR_CLASS *error_class, + BACNET_ERROR_CODE *error_code, + BACNET_PRIVATE_TRANSFER_DATA *private_data) { int len = 0; int offset = 0; @@ -462,27 +427,26 @@ int ptransfer_error_decode_apdu( return -1; offset = 3; if (apdu_len > offset) { - len = - ptransfer_error_decode_service_request(&apdu[offset], - apdu_len - offset, error_class, error_code, private_data); + len = ptransfer_error_decode_service_request( + &apdu[offset], apdu_len - offset, error_class, error_code, + private_data); } return len; } -void test_Private_Transfer_Ack( - Test * pTest) +void test_Private_Transfer_Ack(Test *pTest) { - uint8_t apdu[480] = { 0 }; + uint8_t apdu[480] = {0}; int len = 0; int apdu_len = 0; uint8_t invoke_id = 128; uint8_t test_invoke_id = 0; BACNET_PRIVATE_TRANSFER_DATA private_data; BACNET_PRIVATE_TRANSFER_DATA test_data; - uint8_t test_value[480] = { 0 }; + uint8_t test_value[480] = {0}; int private_data_len = 0; - char private_data_chunk[33] = { "00112233445566778899AABBCCDDEEFF" }; + char private_data_chunk[33] = {"00112233445566778899AABBCCDDEEFF"}; BACNET_APPLICATION_DATA_VALUE data_value; BACNET_APPLICATION_DATA_VALUE test_data_value; bool status = false; @@ -490,9 +454,8 @@ void test_Private_Transfer_Ack( private_data.vendorID = BACNET_VENDOR_ID; private_data.serviceNumber = 1; - status = - bacapp_parse_application_data(BACNET_APPLICATION_TAG_OCTET_STRING, - &private_data_chunk[0], &data_value); + status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_OCTET_STRING, + &private_data_chunk[0], &data_value); ct_test(pTest, status == true); private_data_len = bacapp_encode_application_data(&test_value[0], &data_value); @@ -500,30 +463,27 @@ void test_Private_Transfer_Ack( private_data.serviceParameters = &test_value[0]; private_data.serviceParametersLen = private_data_len; - len = ptransfer_ack_encode_apdu(&apdu[0], invoke_id, &private_data); ct_test(pTest, len != 0); ct_test(pTest, len != -1); apdu_len = len; - len = - ptransfer_ack_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, - &test_data); + len = ptransfer_ack_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, + &test_data); ct_test(pTest, len != -1); ct_test(pTest, test_invoke_id == invoke_id); ct_test(pTest, test_data.vendorID == private_data.vendorID); ct_test(pTest, test_data.serviceNumber == private_data.serviceNumber); - ct_test(pTest, - test_data.serviceParametersLen == private_data.serviceParametersLen); - len = - bacapp_decode_application_data(test_data.serviceParameters, - test_data.serviceParametersLen, &test_data_value); + ct_test(pTest, test_data.serviceParametersLen == + private_data.serviceParametersLen); + len = bacapp_decode_application_data(test_data.serviceParameters, + test_data.serviceParametersLen, + &test_data_value); ct_test(pTest, bacapp_same_value(&data_value, &test_data_value) == true); } -void test_Private_Transfer_Error( - Test * pTest) +void test_Private_Transfer_Error(Test *pTest) { - uint8_t apdu[480] = { 0 }; + uint8_t apdu[480] = {0}; int len = 0; int apdu_len = 0; uint8_t invoke_id = 128; @@ -534,9 +494,9 @@ void test_Private_Transfer_Error( BACNET_ERROR_CODE test_error_code = 0; BACNET_PRIVATE_TRANSFER_DATA private_data; BACNET_PRIVATE_TRANSFER_DATA test_data; - uint8_t test_value[480] = { 0 }; + uint8_t test_value[480] = {0}; int private_data_len = 0; - char private_data_chunk[33] = { "00112233445566778899AABBCCDDEEFF" }; + char private_data_chunk[33] = {"00112233445566778899AABBCCDDEEFF"}; BACNET_APPLICATION_DATA_VALUE data_value; BACNET_APPLICATION_DATA_VALUE test_data_value; bool status = false; @@ -544,61 +504,57 @@ void test_Private_Transfer_Error( private_data.vendorID = BACNET_VENDOR_ID; private_data.serviceNumber = 1; - status = - bacapp_parse_application_data(BACNET_APPLICATION_TAG_OCTET_STRING, - &private_data_chunk[0], &data_value); + status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_OCTET_STRING, + &private_data_chunk[0], &data_value); ct_test(pTest, status == true); private_data_len = bacapp_encode_application_data(&test_value[0], &data_value); private_data.serviceParameters = &test_value[0]; private_data.serviceParametersLen = private_data_len; - len = - ptransfer_error_encode_apdu(&apdu[0], invoke_id, error_class, - error_code, &private_data); + len = ptransfer_error_encode_apdu(&apdu[0], invoke_id, error_class, + error_code, &private_data); ct_test(pTest, len != 0); ct_test(pTest, len != -1); apdu_len = len; - len = - ptransfer_error_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, - &test_error_class, &test_error_code, &test_data); + len = ptransfer_error_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, + &test_error_class, &test_error_code, + &test_data); ct_test(pTest, len != -1); ct_test(pTest, test_invoke_id == invoke_id); ct_test(pTest, test_data.vendorID == private_data.vendorID); ct_test(pTest, test_data.serviceNumber == private_data.serviceNumber); ct_test(pTest, test_error_class == error_class); ct_test(pTest, test_error_code == error_code); - ct_test(pTest, - test_data.serviceParametersLen == private_data.serviceParametersLen); - len = - bacapp_decode_application_data(test_data.serviceParameters, - test_data.serviceParametersLen, &test_data_value); + ct_test(pTest, test_data.serviceParametersLen == + private_data.serviceParametersLen); + len = bacapp_decode_application_data(test_data.serviceParameters, + test_data.serviceParametersLen, + &test_data_value); ct_test(pTest, bacapp_same_value(&data_value, &test_data_value) == true); } -void test_Private_Transfer_Request( - Test * pTest) +void test_Private_Transfer_Request(Test *pTest) { - uint8_t apdu[480] = { 0 }; - uint8_t test_value[480] = { 0 }; + uint8_t apdu[480] = {0}; + uint8_t test_value[480] = {0}; int len = 0; int apdu_len = 0; uint8_t invoke_id = 128; uint8_t test_invoke_id = 0; int private_data_len = 0; - char private_data_chunk[33] = { "00112233445566778899AABBCCDDEEFF" }; - BACNET_APPLICATION_DATA_VALUE data_value = { 0 }; - BACNET_APPLICATION_DATA_VALUE test_data_value = { 0 }; - BACNET_PRIVATE_TRANSFER_DATA private_data = { 0 }; - BACNET_PRIVATE_TRANSFER_DATA test_data = { 0 }; + char private_data_chunk[33] = {"00112233445566778899AABBCCDDEEFF"}; + BACNET_APPLICATION_DATA_VALUE data_value = {0}; + BACNET_APPLICATION_DATA_VALUE test_data_value = {0}; + BACNET_PRIVATE_TRANSFER_DATA private_data = {0}; + BACNET_PRIVATE_TRANSFER_DATA test_data = {0}; bool status = false; private_data.vendorID = BACNET_VENDOR_ID; private_data.serviceNumber = 1; - status = - bacapp_parse_application_data(BACNET_APPLICATION_TAG_OCTET_STRING, - &private_data_chunk[0], &data_value); + status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_OCTET_STRING, + &private_data_chunk[0], &data_value); ct_test(pTest, status == true); private_data_len = bacapp_encode_application_data(&test_value[0], &data_value); @@ -613,25 +569,24 @@ void test_Private_Transfer_Request( ct_test(pTest, len != -1); ct_test(pTest, test_data.vendorID == private_data.vendorID); ct_test(pTest, test_data.serviceNumber == private_data.serviceNumber); - ct_test(pTest, - test_data.serviceParametersLen == private_data.serviceParametersLen); - len = - bacapp_decode_application_data(test_data.serviceParameters, - test_data.serviceParametersLen, &test_data_value); + ct_test(pTest, test_data.serviceParametersLen == + private_data.serviceParametersLen); + len = bacapp_decode_application_data(test_data.serviceParameters, + test_data.serviceParametersLen, + &test_data_value); ct_test(pTest, bacapp_same_value(&data_value, &test_data_value) == true); return; } -void test_Unconfirmed_Private_Transfer_Request( - Test * pTest) +void test_Unconfirmed_Private_Transfer_Request(Test *pTest) { - uint8_t apdu[480] = { 0 }; - uint8_t test_value[480] = { 0 }; + uint8_t apdu[480] = {0}; + uint8_t test_value[480] = {0}; int len = 0; int apdu_len = 0; int private_data_len = 0; - char private_data_chunk[32] = { "I Love You, Patricia!" }; + char private_data_chunk[32] = {"I Love You, Patricia!"}; BACNET_APPLICATION_DATA_VALUE data_value; BACNET_APPLICATION_DATA_VALUE test_data_value; BACNET_PRIVATE_TRANSFER_DATA private_data; @@ -643,7 +598,7 @@ void test_Unconfirmed_Private_Transfer_Request( status = bacapp_parse_application_data(BACNET_APPLICATION_TAG_CHARACTER_STRING, - &private_data_chunk[0], &data_value); + &private_data_chunk[0], &data_value); ct_test(pTest, status == true); private_data_len = bacapp_encode_application_data(&test_value[0], &data_value); @@ -657,19 +612,18 @@ void test_Unconfirmed_Private_Transfer_Request( ct_test(pTest, len != -1); ct_test(pTest, test_data.vendorID == private_data.vendorID); ct_test(pTest, test_data.serviceNumber == private_data.serviceNumber); - ct_test(pTest, - test_data.serviceParametersLen == private_data.serviceParametersLen); - len = - bacapp_decode_application_data(test_data.serviceParameters, - test_data.serviceParametersLen, &test_data_value); + ct_test(pTest, test_data.serviceParametersLen == + private_data.serviceParametersLen); + len = bacapp_decode_application_data(test_data.serviceParameters, + test_data.serviceParametersLen, + &test_data_value); ct_test(pTest, bacapp_same_value(&data_value, &test_data_value) == true); return; } #ifdef TEST_PRIVATE_TRANSFER -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -687,7 +641,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/src/rd.c b/src/rd.c index 19b36cb1..b622242f 100644 --- a/src/rd.c +++ b/src/rd.c @@ -40,14 +40,12 @@ /** @file rd.c Encode/Decode Reinitialize Device APDUs */ #if BACNET_SVC_RD_A /* encode service */ -int rd_encode_apdu( - uint8_t * apdu, - uint8_t invoke_id, - BACNET_REINITIALIZED_STATE state, - BACNET_CHARACTER_STRING * password) +int rd_encode_apdu(uint8_t *apdu, uint8_t invoke_id, + BACNET_REINITIALIZED_STATE state, + BACNET_CHARACTER_STRING *password) { - int len = 0; /* length of each encoding */ - int apdu_len = 0; /* total length of the apdu, return value */ + int len = 0; /* length of each encoding */ + int apdu_len = 0; /* total length of the apdu, return value */ if (apdu) { apdu[0] = PDU_TYPE_CONFIRMED_SERVICE_REQUEST; @@ -60,8 +58,7 @@ int rd_encode_apdu( /* optional password */ if (password) { /* FIXME: must be at least 1 character, limited to 20 characters */ - len = - encode_context_character_string(&apdu[apdu_len], 1, password); + len = encode_context_character_string(&apdu[apdu_len], 1, password); apdu_len += len; } } @@ -71,11 +68,9 @@ int rd_encode_apdu( #endif /* decode the service request only */ -int rd_decode_service_request( - uint8_t * apdu, - unsigned apdu_len, - BACNET_REINITIALIZED_STATE * state, - BACNET_CHARACTER_STRING * password) +int rd_decode_service_request(uint8_t *apdu, unsigned apdu_len, + BACNET_REINITIALIZED_STATE *state, + BACNET_CHARACTER_STRING *password) { unsigned len = 0; uint8_t tag_number = 0; @@ -87,25 +82,23 @@ int rd_decode_service_request( /* Tag 0: reinitializedStateOfDevice */ if (!decode_is_context_tag(&apdu[len], 0)) return -1; - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value_type); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value_type); len += decode_enumerated(&apdu[len], len_value_type, &value); if (state) - *state = (BACNET_REINITIALIZED_STATE) value; + *state = (BACNET_REINITIALIZED_STATE)value; /* Tag 1: password - optional */ if (len < apdu_len) { if (!decode_is_context_tag(&apdu[len], 1)) return -1; - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value_type); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value_type); len += decode_character_string(&apdu[len], len_value_type, password); } } - return (int) len; + return (int)len; } #ifdef TEST @@ -113,12 +106,9 @@ int rd_decode_service_request( #include #include "ctest.h" -int rd_decode_apdu( - uint8_t * apdu, - unsigned apdu_len, - uint8_t * invoke_id, - BACNET_REINITIALIZED_STATE * state, - BACNET_CHARACTER_STRING * password) +int rd_decode_apdu(uint8_t *apdu, unsigned apdu_len, uint8_t *invoke_id, + BACNET_REINITIALIZED_STATE *state, + BACNET_CHARACTER_STRING *password) { int len = 0; unsigned offset = 0; @@ -129,24 +119,22 @@ int rd_decode_apdu( if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST) return -1; /* apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU); */ - *invoke_id = apdu[2]; /* invoke id - filled in by net layer */ + *invoke_id = apdu[2]; /* invoke id - filled in by net layer */ if (apdu[3] != SERVICE_CONFIRMED_REINITIALIZE_DEVICE) return -1; offset = 4; if (apdu_len > offset) { - len = - rd_decode_service_request(&apdu[offset], apdu_len - offset, state, - password); + len = rd_decode_service_request(&apdu[offset], apdu_len - offset, state, + password); } return len; } -void test_ReinitializeDevice( - Test * pTest) +void test_ReinitializeDevice(Test *pTest) { - uint8_t apdu[480] = { 0 }; + uint8_t apdu[480] = {0}; int len = 0; int apdu_len = 0; uint8_t invoke_id = 128; @@ -162,9 +150,8 @@ void test_ReinitializeDevice( ct_test(pTest, len != 0); apdu_len = len; - len = - rd_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, &test_state, - &test_password); + len = rd_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, &test_state, + &test_password); ct_test(pTest, len != -1); ct_test(pTest, test_invoke_id == invoke_id); ct_test(pTest, test_state == state); @@ -174,8 +161,7 @@ void test_ReinitializeDevice( } #ifdef TEST_REINITIALIZE_DEVICE -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -187,7 +173,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/src/readrange.c b/src/readrange.c index 1b2300fc..47da94ed 100644 --- a/src/readrange.c +++ b/src/readrange.c @@ -43,10 +43,8 @@ * ReadRange-Request ::= SEQUENCE { * objectIdentifier [0] BACnetObjectIdentifier, * propertyIdentifier [1] BACnetPropertyIdentifier, - * propertyArrayIndex [2] Unsigned OPTIONAL, -- used only with array datatype - * range CHOICE { - * byPosition [3] SEQUENCE { - * referenceIndex Unsigned, + * propertyArrayIndex [2] Unsigned OPTIONAL, -- used only with array + * datatype range CHOICE { byPosition [3] SEQUENCE { referenceIndex Unsigned, * count INTEGER * }, * -- context tag 4 is deprecated @@ -67,12 +65,10 @@ * Build a ReadRange request packet. * *****************************************************************************/ -int rr_encode_apdu( - uint8_t * apdu, - uint8_t invoke_id, - BACNET_READ_RANGE_DATA * rrdata) +int rr_encode_apdu(uint8_t* 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; @@ -81,29 +77,26 @@ int rr_encode_apdu( apdu[3] = SERVICE_CONFIRMED_READ_RANGE; /* service choice */ apdu_len = 4; - apdu_len += - encode_context_object_id(&apdu[apdu_len], 0, rrdata->object_type, - rrdata->object_instance); - apdu_len += - encode_context_enumerated(&apdu[apdu_len], 1, - rrdata->object_property); + apdu_len += encode_context_object_id( + &apdu[apdu_len], 0, rrdata->object_type, rrdata->object_instance); + apdu_len += encode_context_enumerated(&apdu[apdu_len], 1, + rrdata->object_property); /* optional array index */ if (rrdata->array_index != BACNET_ARRAY_ALL) { - apdu_len += - encode_context_unsigned(&apdu[apdu_len], 2, - rrdata->array_index); + apdu_len += encode_context_unsigned(&apdu[apdu_len], 2, + rrdata->array_index); } - /* Build the appropriate (optional) range parameter based on the request type */ + /* Build the appropriate (optional) range parameter based on the request + * type */ switch (rrdata->RequestType) { case RR_BY_POSITION: apdu_len += encode_opening_tag(&apdu[apdu_len], 3); - apdu_len += - encode_application_unsigned(&apdu[apdu_len], - rrdata->Range.RefIndex); + apdu_len += encode_application_unsigned(&apdu[apdu_len], + rrdata->Range.RefIndex); apdu_len += encode_application_signed(&apdu[apdu_len], rrdata->Count); apdu_len += encode_closing_tag(&apdu[apdu_len], 3); @@ -111,9 +104,8 @@ int rr_encode_apdu( case RR_BY_SEQUENCE: apdu_len += encode_opening_tag(&apdu[apdu_len], 6); - apdu_len += - encode_application_unsigned(&apdu[apdu_len], - rrdata->Range.RefSeqNum); + apdu_len += encode_application_unsigned( + &apdu[apdu_len], rrdata->Range.RefSeqNum); apdu_len += encode_application_signed(&apdu[apdu_len], rrdata->Count); apdu_len += encode_closing_tag(&apdu[apdu_len], 6); @@ -121,18 +113,17 @@ int rr_encode_apdu( case RR_BY_TIME: apdu_len += encode_opening_tag(&apdu[apdu_len], 7); - apdu_len += - encode_application_date(&apdu[apdu_len], - &rrdata->Range.RefTime.date); - apdu_len += - encode_application_time(&apdu[apdu_len], - &rrdata->Range.RefTime.time); + apdu_len += encode_application_date( + &apdu[apdu_len], &rrdata->Range.RefTime.date); + apdu_len += encode_application_time( + &apdu[apdu_len], &rrdata->Range.RefTime.time); apdu_len += encode_application_signed(&apdu[apdu_len], rrdata->Count); apdu_len += encode_closing_tag(&apdu[apdu_len], 7); break; - case RR_READ_ALL: /* to attempt a read of the whole array or list, omit the range parameter */ + case RR_READ_ALL: /* to attempt a read of the whole array or list, + omit the range parameter */ break; default: @@ -147,16 +138,14 @@ int rr_encode_apdu( * Decode the received ReadRange request * *****************************************************************************/ -int rr_decode_service_request( - uint8_t * apdu, - unsigned apdu_len, - BACNET_READ_RANGE_DATA * rrdata) +int rr_decode_service_request(uint8_t* apdu, unsigned apdu_len, + BACNET_READ_RANGE_DATA* rrdata) { unsigned len = 0; unsigned TagLen = 0; uint8_t tag_number = 0; uint32_t len_value_type = 0; - uint16_t type = 0; /* for decoding */ + uint16_t type = 0; /* for decoding */ uint32_t UnsignedTemp; /* check for value pointers */ @@ -165,129 +154,118 @@ int rr_decode_service_request( if (!decode_is_context_tag(&apdu[len++], 0)) return -1; len += decode_object_id(&apdu[len], &type, &rrdata->object_instance); - rrdata->object_type = (BACNET_OBJECT_TYPE) type; + rrdata->object_type = (BACNET_OBJECT_TYPE)type; /* Tag 1: Property ID */ - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value_type); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value_type); if (tag_number != 1) return -1; len += decode_enumerated(&apdu[len], len_value_type, &UnsignedTemp); - rrdata->object_property = (BACNET_PROPERTY_ID) UnsignedTemp; + rrdata->object_property = (BACNET_PROPERTY_ID)UnsignedTemp; rrdata->Overhead = RR_OVERHEAD; /* Start with the fixed overhead */ /* Tag 2: Optional Array Index - set to ALL if not present */ - rrdata->array_index = BACNET_ARRAY_ALL; /* Assuming this is the most common outcome... */ + 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, - &len_value_type); + TagLen = (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 */ - rrdata->RequestType = RR_READ_ALL; /* Assume the worst to cut out explicit checking later */ + rrdata->RequestType = RR_READ_ALL; /* Assume the worst to cut out + explicit checking later */ if (len < apdu_len) { /* - * Note: We pick up the opening tag and then decode the parameter types we recognise. - * We deal with the count and the closing tag in each case statement even though it - * might appear that we could do them after the switch statement as common elements. - * This is so that if we receive a tag we don't recognise, we don't try to decode it - * blindly and make a mess of it. + * Note: We pick up the opening tag and then decode the parameter + * types we recognise. We deal with the count and the closing tag in + * each case statement even though it might appear that we could do + * them after the switch statement as common elements. This is so + * that if we receive a tag we don't recognise, we don't try to + * decode it blindly and make a mess of it. */ - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value_type); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value_type); switch (tag_number) { - case 3: /* ReadRange by position */ + case 3: /* ReadRange by position */ rrdata->RequestType = RR_BY_POSITION; - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value_type); - len += - decode_unsigned(&apdu[len], len_value_type, - &rrdata->Range.RefIndex); - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value_type); - len += - decode_signed(&apdu[len], len_value_type, - &rrdata->Count); - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value_type); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value_type); + len += decode_unsigned(&apdu[len], len_value_type, + &rrdata->Range.RefIndex); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value_type); + len += decode_signed(&apdu[len], len_value_type, + &rrdata->Count); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value_type); break; - case 6: /* ReadRange by sequence number */ + case 6: /* ReadRange by sequence number */ rrdata->RequestType = RR_BY_SEQUENCE; - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value_type); - len += - decode_unsigned(&apdu[len], len_value_type, - &rrdata->Range.RefSeqNum); - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value_type); - len += - decode_signed(&apdu[len], len_value_type, - &rrdata->Count); - 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 */ + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value_type); + len += decode_unsigned(&apdu[len], len_value_type, + &rrdata->Range.RefSeqNum); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value_type); + len += decode_signed(&apdu[len], len_value_type, + &rrdata->Count); + 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 + */ break; - case 7: /* ReadRange by time stamp */ + case 7: /* ReadRange by time stamp */ rrdata->RequestType = RR_BY_TIME; - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value_type); - len += - decode_date(&apdu[len], &rrdata->Range.RefTime.date); - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value_type); - len += - decode_bacnet_time(&apdu[len], - &rrdata->Range.RefTime.time); - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value_type); - len += - decode_signed(&apdu[len], len_value_type, - &rrdata->Count); - 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 */ + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value_type); + len += decode_date(&apdu[len], &rrdata->Range.RefTime.date); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value_type); + len += decode_bacnet_time(&apdu[len], + &rrdata->Range.RefTime.time); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value_type); + len += decode_signed(&apdu[len], len_value_type, + &rrdata->Count); + 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 + */ break; - default: /* If we don't recognise the tag then we do nothing here and try to return - * all elements of the array */ + default: /* If we don't recognise the tag then we do nothing + * here and try to return all elements of the array */ break; } } } - return (int) len; + return (int)len; } /* * ReadRange-ACK ::= SEQUENCE { * objectIdentifier [0] BACnetObjectIdentifier, * propertyIdentifier [1] BACnetPropertyIdentifier, - * propertyArrayIndex [2] Unsigned OPTIONAL , -- used only with array datatype - * resultFlags [3] BACnetResultFlags, - * itemCount [4] Unsigned, - * itemData [5] SEQUENCE OF ABSTRACT-SYNTAX.&TYPE, - * firstSequenceNumber [6] Unsigned32 OPTIONAL -- used only if 'Item Count' > 0 and the request was either of - * -- type 'By Sequence Number' or 'By Time' + * propertyArrayIndex [2] Unsigned OPTIONAL , -- used only with + * array datatype resultFlags [3] BACnetResultFlags, itemCount [4] + * Unsigned, itemData [5] SEQUENCE OF ABSTRACT-SYNTAX.&TYPE, + * firstSequenceNumber [6] Unsigned32 OPTIONAL -- used only if 'Item Count' + * > 0 and the request was either of + * -- type 'By Sequence Number' + * or 'By Time' * } */ @@ -295,31 +273,26 @@ int rr_decode_service_request( * Build a ReadRange response packet * *****************************************************************************/ -int rr_ack_encode_apdu( - uint8_t * apdu, - uint8_t invoke_id, - BACNET_READ_RANGE_DATA * rrdata) +int rr_ack_encode_apdu(uint8_t* apdu, uint8_t invoke_id, + BACNET_READ_RANGE_DATA* rrdata) { - int len = 0; /* length of each encoding */ - int apdu_len = 0; /* total length of the apdu, return value */ + int len = 0; /* length of each encoding */ + int apdu_len = 0; /* total length of the apdu, return value */ if (apdu) { apdu[0] = PDU_TYPE_COMPLEX_ACK; /* complex ACK service */ - apdu[1] = invoke_id; /* original invoke id from request */ + apdu[1] = invoke_id; /* original invoke id from request */ apdu[2] = SERVICE_CONFIRMED_READ_RANGE; /* service choice */ apdu_len = 3; /* service ack follows */ - apdu_len += - encode_context_object_id(&apdu[apdu_len], 0, rrdata->object_type, - rrdata->object_instance); - apdu_len += - encode_context_enumerated(&apdu[apdu_len], 1, - rrdata->object_property); + apdu_len += encode_context_object_id( + &apdu[apdu_len], 0, rrdata->object_type, rrdata->object_instance); + apdu_len += encode_context_enumerated(&apdu[apdu_len], 1, + rrdata->object_property); /* context 2 array index is optional */ if (rrdata->array_index != BACNET_ARRAY_ALL) { - apdu_len += - encode_context_unsigned(&apdu[apdu_len], 2, - rrdata->array_index); + apdu_len += encode_context_unsigned(&apdu[apdu_len], 2, + rrdata->array_index); } /* Context 3 BACnet Result Flags */ apdu_len += @@ -327,8 +300,9 @@ int rr_ack_encode_apdu( /* Context 4 Item Count */ apdu_len += encode_context_unsigned(&apdu[apdu_len], 4, rrdata->ItemCount); - /* Context 5 Property list - reading the standard it looks like an empty list still - * requires an opening and closing tag as the tagged parameter is not optional + /* Context 5 Property list - reading the standard it looks like an empty + * list still requires an opening and closing tag as the tagged + * parameter is not optional */ apdu_len += encode_opening_tag(&apdu[apdu_len], 5); if (rrdata->ItemCount != 0) { @@ -338,12 +312,12 @@ int rr_ack_encode_apdu( } apdu_len += encode_closing_tag(&apdu[apdu_len], 5); - if ((rrdata->ItemCount != 0) && (rrdata->RequestType != RR_BY_POSITION) - && (rrdata->RequestType != RR_READ_ALL)) { + if ((rrdata->ItemCount != 0) && + (rrdata->RequestType != RR_BY_POSITION) && + (rrdata->RequestType != RR_READ_ALL)) { /* Context 6 Sequence number of first item */ - apdu_len += - encode_context_unsigned(&apdu[apdu_len], 6, - rrdata->FirstSequence); + apdu_len += encode_context_unsigned(&apdu[apdu_len], 6, + rrdata->FirstSequence); } } @@ -354,19 +328,18 @@ int rr_ack_encode_apdu( * Decode the received ReadRange response * *****************************************************************************/ -int rr_ack_decode_service_request( - uint8_t * apdu, - int apdu_len, /* total length of the apdu */ - BACNET_READ_RANGE_DATA * rrdata) +int rr_ack_decode_service_request(uint8_t* apdu, + int apdu_len, /* total length of the apdu */ + BACNET_READ_RANGE_DATA* rrdata) { uint8_t tag_number = 0; uint32_t len_value_type = 0; - int tag_len = 0; /* length of tag decode */ - int len = 0; /* total length of decodes */ + int tag_len = 0; /* length of tag decode */ + int len = 0; /* total length of decodes */ int start_len; - uint16_t object = 0; /* object type */ - uint32_t property = 0; /* for decoding */ - uint32_t array_value = 0; /* for decoding */ + uint16_t object = 0; /* object type */ + uint32_t property = 0; /* for decoding */ + uint32_t array_value = 0; /* for decoding */ /* FIXME: check apdu_len against the len during decode */ /* Tag 0: Object ID */ @@ -374,7 +347,7 @@ int rr_ack_decode_service_request( return -1; len = 1; len += decode_object_id(&apdu[len], &object, &rrdata->object_instance); - rrdata->object_type = (BACNET_OBJECT_TYPE) object; + rrdata->object_type = (BACNET_OBJECT_TYPE)object; /* Tag 1: Property ID */ len += @@ -382,7 +355,7 @@ int rr_ack_decode_service_request( if (tag_number != 1) return -1; len += decode_enumerated(&apdu[len], len_value_type, &property); - rrdata->object_property = (BACNET_PROPERTY_ID) property; + rrdata->object_property = (BACNET_PROPERTY_ID)property; /* Tag 2: Optional Array Index */ tag_len = @@ -411,44 +384,42 @@ int rr_ack_decode_service_request( len += decode_unsigned(&apdu[len], len_value_type, &rrdata->ItemCount); if (decode_is_opening_tag_number(&apdu[len], 5)) { - len++; /* a tag number of 5 is not extended so only one octet */ - /* Setup the start position and length of the data returned from the request - * don't decode the application tag number or its data here */ + len++; /* a tag number of 5 is not extended so only one octet */ + /* Setup the start position and length of the data returned from the + * request don't decode the application tag number or its data here */ rrdata->application_data = &apdu[len]; start_len = len; while (len < apdu_len) { if (IS_CONTEXT_SPECIFIC(apdu[len]) && (decode_is_closing_tag_number(&apdu[len], 5))) { rrdata->application_data_len = len - start_len; - len++; /* Step over single byte closing tag */ + len++; /* Step over single byte closing tag */ break; } else { /* Don't care about tag number, just skipping over anyway */ - len += - decode_tag_number_and_value(&apdu[len], NULL, - &len_value_type); - len += len_value_type; /* Skip over data value as well */ - if (len >= apdu_len) /* APDU is exhausted so we have failed to find closing tag */ + len += decode_tag_number_and_value(&apdu[len], NULL, + &len_value_type); + len += len_value_type; /* Skip over data value as well */ + if (len >= apdu_len) /* APDU is exhausted so we have failed to + find closing tag */ return (-1); } } } else { return -1; } - if (len < apdu_len) { /* Still something left to look at? */ + if (len < apdu_len) { /* Still something left to look at? */ /* Tag 6: Item count */ - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value_type); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value_type); if (tag_number != 6) return -1; len += - decode_unsigned(&apdu[len], len_value_type, - &rrdata->FirstSequence); + decode_unsigned(&apdu[len], len_value_type, &rrdata->FirstSequence); } - len = apdu_len; /* There should be nothing left to see here */ + len = apdu_len; /* There should be nothing left to see here */ return len; } diff --git a/src/reject.c b/src/reject.c index a2a55239..4e7d8e5d 100644 --- a/src/reject.c +++ b/src/reject.c @@ -39,15 +39,13 @@ /** @file reject.c Encode/Decode Reject APDUs */ -/* Helper function to avoid needing additional entries in service data structures - * when passing back reject status. - * Convert from error code to reject code. - * Anything not defined gets converted to REJECT_REASON_OTHER. - * Will need reworking if it is required to return proprietary reject codes. +/* Helper function to avoid needing additional entries in service data + * structures when passing back reject status. Convert from error code to reject + * code. Anything not defined gets converted to REJECT_REASON_OTHER. Will need + * reworking if it is required to return proprietary reject codes. */ -BACNET_REJECT_REASON reject_convert_error_code( - BACNET_ERROR_CODE error_code) +BACNET_REJECT_REASON reject_convert_error_code(BACNET_ERROR_CODE error_code) { BACNET_REJECT_REASON reject_code = REJECT_REASON_OTHER; @@ -92,12 +90,9 @@ BACNET_REJECT_REASON reject_convert_error_code( } /* encode service */ -int reject_encode_apdu( - uint8_t * apdu, - uint8_t invoke_id, - uint8_t reject_reason) +int reject_encode_apdu(uint8_t *apdu, uint8_t invoke_id, uint8_t reject_reason) { - 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_REJECT; @@ -111,11 +106,8 @@ int reject_encode_apdu( #if !BACNET_SVC_SERVER /* decode the service request only */ -int reject_decode_service_request( - uint8_t * apdu, - unsigned apdu_len, - uint8_t * invoke_id, - uint8_t * reject_reason) +int reject_decode_service_request(uint8_t *apdu, unsigned apdu_len, + uint8_t *invoke_id, uint8_t *reject_reason) { int len = 0; @@ -136,11 +128,8 @@ int reject_decode_service_request( #include "ctest.h" /* decode the whole APDU - mainly used for unit testing */ -int reject_decode_apdu( - uint8_t * apdu, - unsigned apdu_len, - uint8_t * invoke_id, - uint8_t * reject_reason) +int reject_decode_apdu(uint8_t *apdu, unsigned apdu_len, uint8_t *invoke_id, + uint8_t *reject_reason) { int len = 0; @@ -151,19 +140,17 @@ int reject_decode_apdu( if (apdu[0] != PDU_TYPE_REJECT) return -1; if (apdu_len > 1) { - len = - reject_decode_service_request(&apdu[1], apdu_len - 1, - invoke_id, reject_reason); + len = reject_decode_service_request(&apdu[1], apdu_len - 1, + invoke_id, reject_reason); } } return len; } -void testReject( - Test * pTest) +void testReject(Test *pTest) { - uint8_t apdu[480] = { 0 }; + uint8_t apdu[480] = {0}; int len = 0; int apdu_len = 0; uint8_t invoke_id = 0; @@ -175,41 +162,35 @@ void testReject( ct_test(pTest, len != 0); apdu_len = len; - len = - reject_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, - &test_reject_reason); + len = reject_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, + &test_reject_reason); ct_test(pTest, len != -1); ct_test(pTest, test_invoke_id == invoke_id); ct_test(pTest, test_reject_reason == reject_reason); /* change type to get negative response */ apdu[0] = PDU_TYPE_ABORT; - len = - reject_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, - &test_reject_reason); + len = reject_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, + &test_reject_reason); ct_test(pTest, len == -1); /* test NULL APDU */ - len = - reject_decode_apdu(NULL, apdu_len, &test_invoke_id, - &test_reject_reason); + len = reject_decode_apdu(NULL, apdu_len, &test_invoke_id, + &test_reject_reason); ct_test(pTest, len == -1); /* force a zero length */ - len = - reject_decode_apdu(&apdu[0], 0, &test_invoke_id, &test_reject_reason); + len = reject_decode_apdu(&apdu[0], 0, &test_invoke_id, &test_reject_reason); ct_test(pTest, len == 0); - /* check them all... */ for (invoke_id = 0; invoke_id < 255; invoke_id++) { for (reject_reason = 0; reject_reason < 255; reject_reason++) { len = reject_encode_apdu(&apdu[0], invoke_id, reject_reason); apdu_len = len; ct_test(pTest, len != 0); - len = - reject_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, - &test_reject_reason); + len = reject_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, + &test_reject_reason); ct_test(pTest, len != -1); ct_test(pTest, test_invoke_id == invoke_id); ct_test(pTest, test_reject_reason == reject_reason); @@ -218,8 +199,7 @@ void testReject( } #ifdef TEST_REJECT -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -231,7 +211,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/src/ringbuf.c b/src/ringbuf.c index b032d6d5..b24a467a 100644 --- a/src/ringbuf.c +++ b/src/ringbuf.c @@ -1,66 +1,66 @@ /** -* @file -* @author Steve Karg -* @date 2004 -* @brief Generic ring buffer library for deeply embedded system. -* -* @section LICENSE -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to: -* The Free Software Foundation, Inc. -* 59 Temple Place - Suite 330 -* Boston, MA 02111-1307 -* USA. -* -* As a special exception, if other files instantiate templates or -* use macros or inline functions from this file, or you compile -* this file and link it with other works to produce a work based -* on this file, this file does not by itself cause the resulting -* work to be covered by the GNU General Public License. However -* the source code for this file must still be made available in -* accordance with section (3) of the GNU General Public License. -* -* This exception does not invalidate any other reasons why a work -* based on this file might be covered by the GNU General Public -* License. -* -* @section DESCRIPTION -* -* Generic ring buffer library for deeply embedded system. -* It uses a data store whose size is a power of 2 (8, 16, 32, 64, ...) -* and doesn't waste any data bytes. It has very low overhead, and -* utilizes modulo for indexing the data in the data store. -* It uses separate variables for consumer and producer so it can -* be used in multithreaded environment. -* -* See the unit tests for usage examples. -* -*/ + * @file + * @author Steve Karg + * @date 2004 + * @brief Generic ring buffer library for deeply embedded system. + * + * @section LICENSE + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to: + * The Free Software Foundation, Inc. + * 59 Temple Place - Suite 330 + * Boston, MA 02111-1307 + * USA. + * + * As a special exception, if other files instantiate templates or + * use macros or inline functions from this file, or you compile + * this file and link it with other works to produce a work based + * on this file, this file does not by itself cause the resulting + * work to be covered by the GNU General Public License. However + * the source code for this file must still be made available in + * accordance with section (3) of the GNU General Public License. + * + * This exception does not invalidate any other reasons why a work + * based on this file might be covered by the GNU General Public + * License. + * + * @section DESCRIPTION + * + * Generic ring buffer library for deeply embedded system. + * It uses a data store whose size is a power of 2 (8, 16, 32, 64, ...) + * and doesn't waste any data bytes. It has very low overhead, and + * utilizes modulo for indexing the data in the data store. + * It uses separate variables for consumer and producer so it can + * be used in multithreaded environment. + * + * See the unit tests for usage examples. + * + */ #include #include #include #include "ringbuf.h" /** -* Returns the number of elements in the ring buffer -* -* @param b - pointer to RING_BUFFER structure -* @return Number of elements in the ring buffer -*/ + * Returns the number of elements in the ring buffer + * + * @param b - pointer to RING_BUFFER structure + * @return Number of elements in the ring buffer + */ unsigned Ringbuf_Count(RING_BUFFER const *b) { - unsigned head, tail; /* used to avoid volatile decision */ + unsigned head, tail; /* used to avoid volatile decision */ if (b) { head = b->head; @@ -72,32 +72,32 @@ unsigned Ringbuf_Count(RING_BUFFER const *b) } /** -* Returns the empty/full status of the ring buffer -* -* @param b - pointer to RING_BUFFER structure -* @return true if the ring buffer is full, false if it is not. -*/ + * Returns the empty/full status of the ring buffer + * + * @param b - pointer to RING_BUFFER structure + * @return true if the ring buffer is full, false if it is not. + */ bool Ringbuf_Full(RING_BUFFER const *b) { return (b ? (Ringbuf_Count(b) == b->element_count) : true); } /** -* Returns the empty/full status of the ring buffer -* -* @param b - pointer to RING_BUFFER structure -* @return true if the ring buffer is empty, false if it is not. -*/ + * Returns the empty/full status of the ring buffer + * + * @param b - pointer to RING_BUFFER structure + * @return true if the ring buffer is empty, false if it is not. + */ bool Ringbuf_Empty(RING_BUFFER const *b) { return (b ? (Ringbuf_Count(b) == 0) : true); } /** -* Updates the depth tracking in the ring buffer -* -* @param b - pointer to RING_BUFFER structure -*/ + * Updates the depth tracking in the ring buffer + * + * @param b - pointer to RING_BUFFER structure + */ static void Ringbuf_Depth_Update(RING_BUFFER *b) { unsigned count; @@ -111,11 +111,11 @@ static void Ringbuf_Depth_Update(RING_BUFFER *b) } /** -* Updates the depth tracking in the ring buffer -* -* @param b - pointer to RING_BUFFER structure -* @return largest number of items that have been in the ring buffer -*/ + * Updates the depth tracking in the ring buffer + * + * @param b - pointer to RING_BUFFER structure + * @return largest number of items that have been in the ring buffer + */ unsigned Ringbuf_Depth(RING_BUFFER const *b) { unsigned depth = 0; @@ -128,11 +128,11 @@ unsigned Ringbuf_Depth(RING_BUFFER const *b) } /** -* Resets the depth tracking in the ring buffer -* -* @param b - pointer to RING_BUFFER structure -* @return largest number of items that have been in the ring buffer -*/ + * Resets the depth tracking in the ring buffer + * + * @param b - pointer to RING_BUFFER structure + * @return largest number of items that have been in the ring buffer + */ unsigned Ringbuf_Depth_Reset(RING_BUFFER *b) { unsigned depth = 0; @@ -146,11 +146,11 @@ unsigned Ringbuf_Depth_Reset(RING_BUFFER *b) } /** -* Gets the capacity of the ring buffer (number of possible elements) -* -* @param b - pointer to RING_BUFFER structure -* @return largest number of items that have been in the ring buffer -*/ + * Gets the capacity of the ring buffer (number of possible elements) + * + * @param b - pointer to RING_BUFFER structure + * @return largest number of items that have been in the ring buffer + */ unsigned Ringbuf_Size(RING_BUFFER const *b) { unsigned count = 0; @@ -163,14 +163,14 @@ unsigned Ringbuf_Size(RING_BUFFER const *b) } /** -* Looks at the data from the head of the list without removing it -* -* @param b - pointer to RING_BUFFER structure -* @return pointer to the data, or NULL if nothing in the list -*/ + * Looks at the data from the head of the list without removing it + * + * @param b - pointer to RING_BUFFER structure + * @return pointer to the data, or NULL if nothing in the list + */ volatile uint8_t *Ringbuf_Peek(RING_BUFFER const *b) { - volatile uint8_t *data_element = NULL; /* return value */ + volatile uint8_t *data_element = NULL; /* return value */ if (!Ringbuf_Empty(b)) { data_element = b->buffer; @@ -181,28 +181,27 @@ volatile uint8_t *Ringbuf_Peek(RING_BUFFER const *b) } /** -* Looks at the data from the next element of the list without removing it -* -* @param b - pointer to RING_BUFFER structure -* @param data_element - find the next element from this one -* @return pointer to the data, or NULL if nothing in the list -*/ -volatile uint8_t *Ringbuf_Peek_Next(RING_BUFFER const *b, - uint8_t * data_element) + * Looks at the data from the next element of the list without removing it + * + * @param b - pointer to RING_BUFFER structure + * @param data_element - find the next element from this one + * @return pointer to the data, or NULL if nothing in the list + */ +volatile uint8_t *Ringbuf_Peek_Next(RING_BUFFER const *b, uint8_t *data_element) { - unsigned index; /* list index */ + unsigned index; /* list index */ volatile uint8_t *this_element; - volatile uint8_t *next_element = NULL; /* return value */ + volatile uint8_t *next_element = NULL; /* return value */ if (!Ringbuf_Empty(b) && data_element != NULL) { /* Use (b->head-1) here to avoid walking off end of ring */ - for (index = b->tail; index < b->head-1; index++) { + for (index = b->tail; index < b->head - 1; index++) { /* Find the specified data_element */ - this_element = b->buffer + - ((index % b->element_count) * b->element_size); + this_element = + b->buffer + ((index % b->element_count) * b->element_size); if (data_element == this_element) { /* Found the current element, get the next one on the list */ - next_element = b->buffer + - (((index+1) % b->element_count) * b->element_size); + next_element = b->buffer + (((index + 1) % b->element_count) * + b->element_size); break; } } @@ -212,18 +211,17 @@ volatile uint8_t *Ringbuf_Peek_Next(RING_BUFFER const *b, } /** -* Copy the data from the front of the list, and removes it -* -* @param b - pointer to RING_BUFFER structure -* @param data_element - element of data that is loaded with data from ring -* @return true if data was copied, false if list is empty -*/ -bool Ringbuf_Pop(RING_BUFFER * b, - uint8_t * data_element) + * Copy the data from the front of the list, and removes it + * + * @param b - pointer to RING_BUFFER structure + * @param data_element - element of data that is loaded with data from ring + * @return true if data was copied, false if list is empty + */ +bool Ringbuf_Pop(RING_BUFFER *b, uint8_t *data_element) { - bool status = false; /* return value */ + bool status = false; /* return value */ volatile uint8_t *ring_data = NULL; /* used to help point ring data */ - unsigned i; /* loop counter */ + unsigned i; /* loop counter */ if (!Ringbuf_Empty(b)) { ring_data = b->buffer; @@ -241,29 +239,28 @@ bool Ringbuf_Pop(RING_BUFFER * b, } /** -* Copy the data from the specified element, and removes it and moves other -* elements up the list -* -* @param b - pointer to RING_BUFFER structure -* @param this_element - element to find -* @param data_element - element of data that is loaded with data from ring -* @return true if data was copied, false if list is empty -*/ -bool Ringbuf_Pop_Element(RING_BUFFER * b, - uint8_t * this_element, - uint8_t * data_element) + * Copy the data from the specified element, and removes it and moves other + * elements up the list + * + * @param b - pointer to RING_BUFFER structure + * @param this_element - element to find + * @param data_element - element of data that is loaded with data from ring + * @return true if data was copied, false if list is empty + */ +bool Ringbuf_Pop_Element(RING_BUFFER *b, uint8_t *this_element, + uint8_t *data_element) { - bool status = false; /* return value */ + bool status = false; /* return value */ volatile uint8_t *ring_data = NULL; /* used to help point ring data */ volatile uint8_t *prev_data; - unsigned index; /* list index */ - unsigned this_index = b->head; /* index of element to remove */ - unsigned i; /* loop counter */ + unsigned index; /* list index */ + unsigned this_index = b->head; /* index of element to remove */ + unsigned i; /* loop counter */ if (!Ringbuf_Empty(b) && this_element != NULL) { for (index = b->tail; index < b->head; index++) { /* Find the specified data_element */ - ring_data = b->buffer + - ((index % b->element_count) * b->element_size); + ring_data = + b->buffer + ((index % b->element_count) * b->element_size); if (this_element == ring_data) { /* Found the specified element, copy the data if required */ this_index = index; @@ -277,12 +274,12 @@ bool Ringbuf_Pop_Element(RING_BUFFER * b, } if (this_index < b->head) { /* Found a match, move elements up the list to fill the gap */ - for ( index = this_index; index > b->tail; index--) { + for (index = this_index; index > b->tail; index--) { /* Get pointers to current and previous data_elements */ - ring_data = b->buffer + - ((index % b->element_count) * b->element_size); - prev_data = b->buffer + - (((index-1) % b->element_count) * b->element_size); + ring_data = + b->buffer + ((index % b->element_count) * b->element_size); + prev_data = b->buffer + (((index - 1) % b->element_count) * + b->element_size); for (i = 0; i < b->element_size; i++) { ring_data[i] = prev_data[i]; } @@ -296,18 +293,17 @@ bool Ringbuf_Pop_Element(RING_BUFFER * b, } /** -* Adds an element of data to the ring buffer -* -* @param b - pointer to RING_BUFFER structure -* @param data_element - one element that is copied to the ring buffer -* @return true on succesful add, false if not added -*/ -bool Ringbuf_Put(RING_BUFFER * b, - uint8_t * data_element) + * Adds an element of data to the ring buffer + * + * @param b - pointer to RING_BUFFER structure + * @param data_element - one element that is copied to the ring buffer + * @return true on succesful add, false if not added + */ +bool Ringbuf_Put(RING_BUFFER *b, uint8_t *data_element) { - bool status = false; /* return value */ + bool status = false; /* return value */ volatile uint8_t *ring_data = NULL; /* used to help point ring data */ - unsigned i; /* loop counter */ + unsigned i; /* loop counter */ if (b && data_element) { /* limit the amount of elements that we accept */ @@ -327,22 +323,21 @@ bool Ringbuf_Put(RING_BUFFER * b, } /** -* Adds an element of data to the front of the ring buffer -* -* Note that this function moves the tail on add instead of head, -* so this function cannot be used if you are keeping producer and -* consumer as separate processes (i.e. interrupt handlers) -* -* @param b - pointer to RING_BUFFER structure -* @param data_element - one element to copy to the front of the ring -* @return true on succesful add, false if not added -*/ -bool Ringbuf_Put_Front(RING_BUFFER * b, - uint8_t * data_element) + * Adds an element of data to the front of the ring buffer + * + * Note that this function moves the tail on add instead of head, + * so this function cannot be used if you are keeping producer and + * consumer as separate processes (i.e. interrupt handlers) + * + * @param b - pointer to RING_BUFFER structure + * @param data_element - one element to copy to the front of the ring + * @return true on succesful add, false if not added + */ +bool Ringbuf_Put_Front(RING_BUFFER *b, uint8_t *data_element) { - bool status = false; /* return value */ + bool status = false; /* return value */ volatile uint8_t *ring_data = NULL; /* used to help point ring data */ - unsigned i = 0; /* loop counter */ + unsigned i = 0; /* loop counter */ if (b && data_element) { /* limit the amount of elements that we accept */ @@ -363,13 +358,13 @@ bool Ringbuf_Put_Front(RING_BUFFER * b, } /** -* Gets a pointer to the next free data element of the buffer -* without adding it to the ring. -* -* @param b - pointer to RING_BUFFER structure -* @return pointer to the next data element, or NULL if the list is full -*/ -volatile uint8_t *Ringbuf_Data_Peek(RING_BUFFER * b) + * Gets a pointer to the next free data element of the buffer + * without adding it to the ring. + * + * @param b - pointer to RING_BUFFER structure + * @return pointer to the next data element, or NULL if the list is full + */ +volatile uint8_t *Ringbuf_Data_Peek(RING_BUFFER *b) { volatile uint8_t *ring_data = NULL; /* used to help point ring data */ @@ -385,15 +380,15 @@ volatile uint8_t *Ringbuf_Data_Peek(RING_BUFFER * b) } /** -* Adds the previously peeked element of data to the end of the -* ring buffer. -* -* @param b - pointer to RING_BUFFER structure -* @param data_element - pointer to the peeked data element -* @return true if the buffer has space and the data element points to the -* same memory previously peeked. -*/ -bool Ringbuf_Data_Put(RING_BUFFER * b, volatile uint8_t *data_element) + * Adds the previously peeked element of data to the end of the + * ring buffer. + * + * @param b - pointer to RING_BUFFER structure + * @param data_element - pointer to the peeked data element + * @return true if the buffer has space and the data element points to the + * same memory previously peeked. + */ +bool Ringbuf_Data_Put(RING_BUFFER *b, volatile uint8_t *data_element) { bool status = false; volatile uint8_t *ring_data = NULL; /* used to help point ring data */ @@ -416,33 +411,31 @@ bool Ringbuf_Data_Put(RING_BUFFER * b, volatile uint8_t *data_element) } /** -* Test that the parameter is a power of two. -* -* @param x unsigned integer value to be tested -* -* @return true if the parameter is a power of 2 -*/ -static bool isPowerOfTwo (unsigned int x) + * Test that the parameter is a power of two. + * + * @param x unsigned integer value to be tested + * + * @return true if the parameter is a power of 2 + */ +static bool isPowerOfTwo(unsigned int x) { /* First x in the below expression is for the case when x is 0 */ - return x && (!(x&(x-1))); + return x && (!(x & (x - 1))); } /** -* Configures the ring buffer data buffer. Note that the element_count -* parameter must be a power of two. -* -* @param b - pointer to RING_BUFFER structure -* @param buffer - pointer to a data buffer that is used to store the ring data -* @param element_size - size of one element in the data block -* @param element_count - number elements in the data block -* -* @return true if ring buffer was initialized -*/ -bool Ringbuf_Init(RING_BUFFER * b, - volatile uint8_t * buffer, - unsigned element_size, - unsigned element_count) + * Configures the ring buffer data buffer. Note that the element_count + * parameter must be a power of two. + * + * @param b - pointer to RING_BUFFER structure + * @param buffer - pointer to a data buffer that is used to store the ring data + * @param element_size - size of one element in the data block + * @param element_count - number elements in the data block + * + * @return true if ring buffer was initialized + */ +bool Ringbuf_Init(RING_BUFFER *b, volatile uint8_t *buffer, + unsigned element_size, unsigned element_count) { bool status = false; @@ -467,19 +460,17 @@ bool Ringbuf_Init(RING_BUFFER * b, #include "ctest.h" /** -* Unit Test for the ring buffer -* -* @param pTest - test tracking pointer -* @param test_buffer - pointer to RING_BUFFER structure -* @param data_element - one data element -* @param element_size - size of one data element -* @param element_count - number of data elements in the store -*/ -static void testRingAroundBuffer(Test * pTest, - RING_BUFFER * test_buffer, - uint8_t * data_element, - unsigned element_size, - unsigned element_count) + * Unit Test for the ring buffer + * + * @param pTest - test tracking pointer + * @param test_buffer - pointer to RING_BUFFER structure + * @param data_element - one data element + * @param element_size - size of one data element + * @param element_count - number of data elements in the store + */ +static void testRingAroundBuffer(Test *pTest, RING_BUFFER *test_buffer, + uint8_t *data_element, unsigned element_size, + unsigned element_count) { volatile uint8_t *test_data; unsigned index; @@ -492,7 +483,7 @@ static void testRingAroundBuffer(Test * pTest, /* test the ring around the buffer */ for (index = 0; index < element_count; index++) { for (count = 1; count < 4; count++) { - value = (index * count)%255; + value = (index * count) % 255; for (data_index = 0; data_index < element_size; data_index++) { data_element[data_index] = value; } @@ -501,7 +492,7 @@ static void testRingAroundBuffer(Test * pTest, ct_test(pTest, Ringbuf_Count(test_buffer) == count); } for (count = 1; count < 4; count++) { - value = (index * count)%255; + value = (index * count) % 255; test_data = Ringbuf_Peek(test_buffer); ct_test(pTest, test_data); if (test_data) { @@ -517,19 +508,16 @@ static void testRingAroundBuffer(Test * pTest, } /** -* Unit Test for the ring buffer -* -* @param pTest - test tracking pointer -* @param data_store - buffer to store elements -* @param data_element - one data element -* @param element_size - size of one data element -* @param element_count - number of data elements in the store -*/ -static bool testRingBuf(Test * pTest, - uint8_t * data_store, - uint8_t * data_element, - unsigned element_size, - unsigned element_count) + * Unit Test for the ring buffer + * + * @param pTest - test tracking pointer + * @param data_store - buffer to store elements + * @param data_element - one data element + * @param element_size - size of one data element + * @param element_count - number of data elements in the store + */ +static bool testRingBuf(Test *pTest, uint8_t *data_store, uint8_t *data_element, + unsigned element_size, unsigned element_count) { RING_BUFFER test_buffer; volatile uint8_t *test_data; @@ -537,8 +525,8 @@ static bool testRingBuf(Test * pTest, unsigned data_index; bool status; - status = Ringbuf_Init(&test_buffer, data_store, - element_size, element_count); + status = + Ringbuf_Init(&test_buffer, data_store, element_size, element_count); if (!status) { return false; } @@ -558,7 +546,7 @@ static bool testRingBuf(Test * pTest, ct_test(pTest, test_data[data_index] == data_element[data_index]); } ct_test(pTest, !Ringbuf_Empty(&test_buffer)); - (void) Ringbuf_Pop(&test_buffer, NULL); + (void)Ringbuf_Pop(&test_buffer, NULL); ct_test(pTest, Ringbuf_Empty(&test_buffer)); ct_test(pTest, Ringbuf_Depth(&test_buffer) == 1); @@ -570,7 +558,7 @@ static bool testRingBuf(Test * pTest, status = Ringbuf_Put(&test_buffer, data_element); ct_test(pTest, status == true); ct_test(pTest, !Ringbuf_Empty(&test_buffer)); - ct_test(pTest, Ringbuf_Depth(&test_buffer) == (index+1)); + ct_test(pTest, Ringbuf_Depth(&test_buffer) == (index + 1)); } ct_test(pTest, Ringbuf_Depth(&test_buffer) == element_count); /* verify actions on full buffer */ @@ -593,7 +581,7 @@ static bool testRingBuf(Test * pTest, ct_test(pTest, test_data[data_index] == index); } } - (void) Ringbuf_Pop(&test_buffer, NULL); + (void)Ringbuf_Pop(&test_buffer, NULL); } ct_test(pTest, Ringbuf_Empty(&test_buffer)); ct_test(pTest, Ringbuf_Depth(&test_buffer) == element_count); @@ -601,102 +589,97 @@ static bool testRingBuf(Test * pTest, ct_test(pTest, Ringbuf_Depth(&test_buffer) == 0); testRingAroundBuffer(pTest, &test_buffer, data_element, element_size, - element_count); + element_count); /* adjust the internal index of Ringbuf to test unsigned wrapping */ test_buffer.head = UINT_MAX - 1; test_buffer.tail = UINT_MAX - 1; testRingAroundBuffer(pTest, &test_buffer, data_element, element_size, - element_count); + element_count); return true; } /** -* Unit Test for the ring buffer with 16 data elements -* -* @param pTest - test tracking pointer -*/ -void testRingBufSizeSmall(Test * pTest) + * Unit Test for the ring buffer with 16 data elements + * + * @param pTest - test tracking pointer + */ +void testRingBufSizeSmall(Test *pTest) { bool status; uint8_t data_element[5]; uint8_t data_store[sizeof(data_element) * NEXT_POWER_OF_2(16)]; - status = testRingBuf(pTest, data_store, data_element, - sizeof(data_element), - sizeof(data_store) / sizeof(data_element)); + status = testRingBuf(pTest, data_store, data_element, sizeof(data_element), + sizeof(data_store) / sizeof(data_element)); ct_test(pTest, status); } /** -* Unit Test for the ring buffer with 32 data elements -* -* @param pTest - test tracking pointer -*/ -void testRingBufSizeLarge(Test * pTest) + * Unit Test for the ring buffer with 32 data elements + * + * @param pTest - test tracking pointer + */ +void testRingBufSizeLarge(Test *pTest) { bool status; uint8_t data_element[16]; uint8_t data_store[sizeof(data_element) * NEXT_POWER_OF_2(99)]; - status = testRingBuf(pTest, data_store, data_element, - sizeof(data_element), - sizeof(data_store) / sizeof(data_element)); + status = testRingBuf(pTest, data_store, data_element, sizeof(data_element), + sizeof(data_store) / sizeof(data_element)); ct_test(pTest, status); } /** -* Unit Test for the ring buffer with 32 data elements -* -* @param pTest - test tracking pointer -*/ -void testRingBufSizeInvalid(Test * pTest) + * Unit Test for the ring buffer with 32 data elements + * + * @param pTest - test tracking pointer + */ +void testRingBufSizeInvalid(Test *pTest) { bool status; uint8_t data_element[16]; uint8_t data_store[sizeof(data_element) * 99]; - status = testRingBuf(pTest, data_store, data_element, - sizeof(data_element), - sizeof(data_store) / sizeof(data_element)); - ct_test(pTest, status==false); + status = testRingBuf(pTest, data_store, data_element, sizeof(data_element), + sizeof(data_store) / sizeof(data_element)); + ct_test(pTest, status == false); } -void testRingBufPowerOfTwo(Test * pTest) +void testRingBufPowerOfTwo(Test *pTest) { - ct_test(pTest, NEXT_POWER_OF_2(3)==4); - ct_test(pTest, NEXT_POWER_OF_2(100)==128); - ct_test(pTest, NEXT_POWER_OF_2(127)==128); - ct_test(pTest, NEXT_POWER_OF_2(128)==128); - ct_test(pTest, NEXT_POWER_OF_2(129)==256); - ct_test(pTest, NEXT_POWER_OF_2(300)==512); - ct_test(pTest, NEXT_POWER_OF_2(500)==512); + ct_test(pTest, NEXT_POWER_OF_2(3) == 4); + ct_test(pTest, NEXT_POWER_OF_2(100) == 128); + ct_test(pTest, NEXT_POWER_OF_2(127) == 128); + ct_test(pTest, NEXT_POWER_OF_2(128) == 128); + ct_test(pTest, NEXT_POWER_OF_2(129) == 256); + ct_test(pTest, NEXT_POWER_OF_2(300) == 512); + ct_test(pTest, NEXT_POWER_OF_2(500) == 512); } /** -* Unit Test for the ring buffer peek/pop next element -* -* @param pTest - test tracking pointer -* @param data_store - buffer to store elements -* @param data_element - one data element -* @param element_size - size of one data element -* @param element_count - number of data elements in the store -*/ -static bool testRingBufNextElement(Test * pTest, - uint8_t * data_store, - uint8_t * data_element, - unsigned element_size, - unsigned element_count) + * Unit Test for the ring buffer peek/pop next element + * + * @param pTest - test tracking pointer + * @param data_store - buffer to store elements + * @param data_element - one data element + * @param element_size - size of one data element + * @param element_count - number of data elements in the store + */ +static bool testRingBufNextElement(Test *pTest, uint8_t *data_store, + uint8_t *data_element, unsigned element_size, + unsigned element_count) { RING_BUFFER test_buffer; volatile uint8_t *test_data; unsigned index; unsigned data_index; bool status; - status = Ringbuf_Init(&test_buffer, data_store, - element_size, element_count); + status = + Ringbuf_Init(&test_buffer, data_store, element_size, element_count); if (!status) { return false; } @@ -716,7 +699,7 @@ static bool testRingBufNextElement(Test * pTest, ct_test(pTest, test_data[data_index] == data_element[data_index]); } ct_test(pTest, !Ringbuf_Empty(&test_buffer)); - (void) Ringbuf_Pop(&test_buffer, NULL); + (void)Ringbuf_Pop(&test_buffer, NULL); ct_test(pTest, Ringbuf_Empty(&test_buffer)); ct_test(pTest, Ringbuf_Depth(&test_buffer) == 1); @@ -728,7 +711,7 @@ static bool testRingBufNextElement(Test * pTest, status = Ringbuf_Put(&test_buffer, data_element); ct_test(pTest, status == true); ct_test(pTest, !Ringbuf_Empty(&test_buffer)); - ct_test(pTest, Ringbuf_Depth(&test_buffer) == (index+1)); + ct_test(pTest, Ringbuf_Depth(&test_buffer) == (index + 1)); } ct_test(pTest, Ringbuf_Depth(&test_buffer) == element_count); ct_test(pTest, Ringbuf_Count(&test_buffer) == element_count); @@ -753,54 +736,54 @@ static bool testRingBufNextElement(Test * pTest, /* Walk through ring buffer and pop alternate elements */ test_data = Ringbuf_Peek(&test_buffer); ct_test(pTest, test_data); - for (index = 1; index < element_count/2; index++) { + for (index = 1; index < element_count / 2; index++) { test_data = Ringbuf_Peek_Next(&test_buffer, (uint8_t *)test_data); ct_test(pTest, test_data); - (void) Ringbuf_Pop_Element(&test_buffer, (uint8_t *)test_data, NULL); + (void)Ringbuf_Pop_Element(&test_buffer, (uint8_t *)test_data, NULL); test_data = Ringbuf_Peek_Next(&test_buffer, (uint8_t *)test_data); } - ct_test(pTest, Ringbuf_Count(&test_buffer) == element_count/2+1); + ct_test(pTest, Ringbuf_Count(&test_buffer) == element_count / 2 + 1); /* Walk through ring buffer and check data */ test_data = Ringbuf_Peek(&test_buffer); ct_test(pTest, test_data); - for (index = 0; index < element_count/2; index++) { + for (index = 0; index < element_count / 2; index++) { if (test_data) { for (data_index = 0; data_index < element_size; data_index++) { - ct_test(pTest, test_data[data_index] == index*2); + ct_test(pTest, test_data[data_index] == index * 2); } } test_data = Ringbuf_Peek_Next(&test_buffer, (uint8_t *)test_data); ct_test(pTest, test_data); } - ct_test(pTest, Ringbuf_Count(&test_buffer) == element_count/2+1); + ct_test(pTest, Ringbuf_Count(&test_buffer) == element_count / 2 + 1); return true; } /** -* Unit Test for the ring buffer with 16 data elements -* -* @param pTest - test tracking pointer -*/ -void testRingBufNextElementSizeSmall(Test * pTest) + * Unit Test for the ring buffer with 16 data elements + * + * @param pTest - test tracking pointer + */ +void testRingBufNextElementSizeSmall(Test *pTest) { bool status; uint8_t data_element[5]; uint8_t data_store[sizeof(data_element) * NEXT_POWER_OF_2(16)]; status = testRingBufNextElement(pTest, data_store, data_element, - sizeof(data_element), - sizeof(data_store) / sizeof(data_element)); + sizeof(data_element), + sizeof(data_store) / sizeof(data_element)); ct_test(pTest, status); } #ifdef TEST_RING_BUFFER /** -* Main program entry for Unit Test -* -* @return returns 0 on success, and non-zero on fail. -*/ + * Main program entry for Unit Test + * + * @return returns 0 on success, and non-zero on fail. + */ int main(void) { Test *pTest; @@ -822,7 +805,7 @@ int main(void) ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); diff --git a/src/rp.c b/src/rp.c index c711cae2..fded70fb 100644 --- a/src/rp.c +++ b/src/rp.c @@ -41,41 +41,37 @@ #if BACNET_SVC_RP_A /* encode service */ -int rp_encode_apdu( - uint8_t * apdu, - uint8_t invoke_id, - BACNET_READ_PROPERTY_DATA * rpdata) +int rp_encode_apdu(uint8_t *apdu, uint8_t invoke_id, + BACNET_READ_PROPERTY_DATA *rpdata) { - int len = 0; /* length of each encoding */ - int apdu_len = 0; /* total length of the apdu, return value */ + int len = 0; /* length of each encoding */ + int apdu_len = 0; /* total length of the apdu, return value */ if (apdu) { apdu[0] = PDU_TYPE_CONFIRMED_SERVICE_REQUEST; apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU); apdu[2] = invoke_id; - apdu[3] = SERVICE_CONFIRMED_READ_PROPERTY; /* service choice */ + apdu[3] = SERVICE_CONFIRMED_READ_PROPERTY; /* service choice */ apdu_len = 4; if (rpdata->object_type <= BACNET_MAX_OBJECT) { /* check bounds so that we could create malformed messages for testing */ - len = - encode_context_object_id(&apdu[apdu_len], 0, - rpdata->object_type, rpdata->object_instance); + len = encode_context_object_id(&apdu[apdu_len], 0, + rpdata->object_type, + rpdata->object_instance); apdu_len += len; } if (rpdata->object_property <= MAX_BACNET_PROPERTY_ID) { /* check bounds so that we could create malformed messages for testing */ - len = - encode_context_enumerated(&apdu[apdu_len], 1, - rpdata->object_property); + len = encode_context_enumerated(&apdu[apdu_len], 1, + rpdata->object_property); apdu_len += len; } /* optional array index */ if (rpdata->array_index != BACNET_ARRAY_ALL) { - len = - encode_context_unsigned(&apdu[apdu_len], 2, - rpdata->array_index); + len = encode_context_unsigned(&apdu[apdu_len], 2, + rpdata->array_index); apdu_len += len; } } @@ -85,17 +81,15 @@ int rp_encode_apdu( #endif /* decode the service request only */ -int rp_decode_service_request( - uint8_t * apdu, - unsigned apdu_len, - BACNET_READ_PROPERTY_DATA * rpdata) +int rp_decode_service_request(uint8_t *apdu, unsigned apdu_len, + BACNET_READ_PROPERTY_DATA *rpdata) { unsigned len = 0; uint8_t tag_number = 0; uint32_t len_value_type = 0; - uint16_t type = 0; /* for decoding */ - uint32_t property = 0; /* for decoding */ - uint32_t array_value = 0; /* for decoding */ + uint16_t type = 0; /* for decoding */ + uint32_t property = 0; /* for decoding */ + uint32_t array_value = 0; /* for decoding */ /* check for value pointers */ if (rpdata) { @@ -112,22 +106,20 @@ int rp_decode_service_request( return BACNET_STATUS_REJECT; } len += decode_object_id(&apdu[len], &type, &rpdata->object_instance); - rpdata->object_type = (BACNET_OBJECT_TYPE) type; + rpdata->object_type = (BACNET_OBJECT_TYPE)type; /* Tag 1: Property ID */ - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value_type); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value_type); if (tag_number != 1) { rpdata->error_code = ERROR_CODE_REJECT_INVALID_TAG; return BACNET_STATUS_REJECT; } len += decode_enumerated(&apdu[len], len_value_type, &property); - rpdata->object_property = (BACNET_PROPERTY_ID) property; + rpdata->object_property = (BACNET_PROPERTY_ID)property; /* Tag 2: Optional Array Index */ if (len < apdu_len) { - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value_type); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value_type); if ((tag_number == 2) && (len < apdu_len)) { len += decode_unsigned(&apdu[len], len_value_type, &array_value); @@ -148,38 +140,33 @@ int rp_decode_service_request( return BACNET_STATUS_REJECT; } - return (int) len; + return (int)len; } /* alternate method to encode the ack without extra buffer */ -int rp_ack_encode_apdu_init( - uint8_t * apdu, - uint8_t invoke_id, - BACNET_READ_PROPERTY_DATA * rpdata) +int rp_ack_encode_apdu_init(uint8_t *apdu, uint8_t invoke_id, + BACNET_READ_PROPERTY_DATA *rpdata) { - int len = 0; /* length of each encoding */ - int apdu_len = 0; /* total length of the apdu, return value */ + int len = 0; /* length of each encoding */ + int apdu_len = 0; /* total length of the apdu, return value */ if (apdu) { apdu[0] = PDU_TYPE_COMPLEX_ACK; /* complex ACK service */ - apdu[1] = invoke_id; /* original invoke id from request */ - apdu[2] = SERVICE_CONFIRMED_READ_PROPERTY; /* service choice */ + apdu[1] = invoke_id; /* original invoke id from request */ + apdu[2] = SERVICE_CONFIRMED_READ_PROPERTY; /* service choice */ apdu_len = 3; /* service ack follows */ - len = - encode_context_object_id(&apdu[apdu_len], 0, rpdata->object_type, - rpdata->object_instance); + len = encode_context_object_id(&apdu[apdu_len], 0, rpdata->object_type, + rpdata->object_instance); apdu_len += len; - len = - encode_context_enumerated(&apdu[apdu_len], 1, - rpdata->object_property); + len = encode_context_enumerated(&apdu[apdu_len], 1, + rpdata->object_property); apdu_len += len; /* context 2 array index is optional */ if (rpdata->array_index != BACNET_ARRAY_ALL) { - len = - encode_context_unsigned(&apdu[apdu_len], 2, - rpdata->array_index); + len = encode_context_unsigned(&apdu[apdu_len], 2, + rpdata->array_index); apdu_len += len; } len = encode_opening_tag(&apdu[apdu_len], 3); @@ -190,10 +177,9 @@ int rp_ack_encode_apdu_init( } /* note: encode the application tagged data yourself */ -int rp_ack_encode_apdu_object_property_end( - uint8_t * apdu) +int rp_ack_encode_apdu_object_property_end(uint8_t *apdu) { - 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_len = encode_closing_tag(&apdu[0], 3); @@ -202,13 +188,11 @@ int rp_ack_encode_apdu_object_property_end( return apdu_len; } -int rp_ack_encode_apdu( - uint8_t * apdu, - uint8_t invoke_id, - BACNET_READ_PROPERTY_DATA * rpdata) +int rp_ack_encode_apdu(uint8_t *apdu, uint8_t invoke_id, + BACNET_READ_PROPERTY_DATA *rpdata) { - int len = 0; /* length of each encoding */ - int apdu_len = 0; /* total length of the apdu, return value */ + int len = 0; /* length of each encoding */ + int apdu_len = 0; /* total length of the apdu, return value */ if (apdu) { /* Do the initial encoding */ @@ -223,7 +207,6 @@ int rp_ack_encode_apdu( return apdu_len; } - #if BACNET_SVC_RP_A /** Decode the ReadProperty reply and store the result for one Property in a * BACNET_READ_PROPERTY_DATA structure. @@ -236,18 +219,17 @@ int rp_ack_encode_apdu( * @return Number of decoded bytes (could be less than apdu_len), * or -1 on decoding error. */ -int rp_ack_decode_service_request( - uint8_t * apdu, - int apdu_len, /* total length of the apdu */ - BACNET_READ_PROPERTY_DATA * rpdata) +int rp_ack_decode_service_request(uint8_t *apdu, + int apdu_len, /* total length of the apdu */ + BACNET_READ_PROPERTY_DATA *rpdata) { uint8_t tag_number = 0; uint32_t len_value_type = 0; - int tag_len = 0; /* length of tag decode */ - int len = 0; /* total length of decodes */ - uint16_t object = 0; /* object type */ - uint32_t property = 0; /* for decoding */ - uint32_t array_value = 0; /* for decoding */ + int tag_len = 0; /* length of tag decode */ + int len = 0; /* total length of decodes */ + uint16_t object = 0; /* object type */ + uint32_t property = 0; /* for decoding */ + uint32_t array_value = 0; /* for decoding */ /* FIXME: check apdu_len against the len during decode */ /* Tag 0: Object ID */ @@ -255,14 +237,14 @@ int rp_ack_decode_service_request( return -1; len = 1; len += decode_object_id(&apdu[len], &object, &rpdata->object_instance); - rpdata->object_type = (BACNET_OBJECT_TYPE) object; + rpdata->object_type = (BACNET_OBJECT_TYPE)object; /* Tag 1: Property ID */ len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type); if (tag_number != 1) return -1; len += decode_enumerated(&apdu[len], len_value_type, &property); - rpdata->object_property = (BACNET_PROPERTY_ID) property; + rpdata->object_property = (BACNET_PROPERTY_ID)property; /* Tag 2: Optional Array Index */ tag_len = decode_tag_number_and_value(&apdu[len], &tag_number, &len_value_type); @@ -278,7 +260,7 @@ int rp_ack_decode_service_request( len++; /* don't decode the application tag number or its data here */ rpdata->application_data = &apdu[len]; - rpdata->application_data_len = apdu_len - len - 1 /*closing tag */ ; + rpdata->application_data_len = apdu_len - len - 1 /*closing tag */; /* len includes the data and the closing tag */ len = apdu_len; } else { @@ -294,11 +276,8 @@ int rp_ack_decode_service_request( #include #include "ctest.h" -int rp_decode_apdu( - uint8_t * apdu, - unsigned apdu_len, - uint8_t * invoke_id, - BACNET_READ_PROPERTY_DATA * rpdata) +int rp_decode_apdu(uint8_t *apdu, unsigned apdu_len, uint8_t *invoke_id, + BACNET_READ_PROPERTY_DATA *rpdata) { int len = 0; unsigned offset = 0; @@ -309,25 +288,22 @@ int rp_decode_apdu( if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST) return -1; /* apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU); */ - *invoke_id = apdu[2]; /* invoke id - filled in by net layer */ + *invoke_id = apdu[2]; /* invoke id - filled in by net layer */ if (apdu[3] != SERVICE_CONFIRMED_READ_PROPERTY) return -1; offset = 4; if (apdu_len > offset) { len = - rp_decode_service_request(&apdu[offset], apdu_len - offset, - rpdata); + rp_decode_service_request(&apdu[offset], apdu_len - offset, rpdata); } return len; } -int rp_ack_decode_apdu( - uint8_t * apdu, - int apdu_len, /* total length of the apdu */ - uint8_t * invoke_id, - BACNET_READ_PROPERTY_DATA * rpdata) +int rp_ack_decode_apdu(uint8_t *apdu, + int apdu_len, /* total length of the apdu */ + uint8_t *invoke_id, BACNET_READ_PROPERTY_DATA *rpdata) { int len = 0; int offset = 0; @@ -342,19 +318,17 @@ int rp_ack_decode_apdu( return -1; offset = 3; if (apdu_len > offset) { - len = - rp_ack_decode_service_request(&apdu[offset], apdu_len - offset, - rpdata); + len = rp_ack_decode_service_request(&apdu[offset], apdu_len - offset, + rpdata); } return len; } -void testReadPropertyAck( - Test * pTest) +void testReadPropertyAck(Test *pTest) { - uint8_t apdu[480] = { 0 }; - uint8_t apdu2[480] = { 0 }; + uint8_t apdu[480] = {0}; + uint8_t apdu2[480] = {0}; int len = 0; int apdu_len = 0; uint8_t invoke_id = 1; @@ -370,17 +344,16 @@ void testReadPropertyAck( rpdata.object_property = PROP_OBJECT_IDENTIFIER; rpdata.array_index = BACNET_ARRAY_ALL; - rpdata.application_data_len = - encode_bacnet_object_id(&apdu2[0], rpdata.object_type, - rpdata.object_instance); + rpdata.application_data_len = encode_bacnet_object_id( + &apdu2[0], rpdata.object_type, rpdata.object_instance); rpdata.application_data = &apdu2[0]; len = rp_ack_encode_apdu(&apdu[0], invoke_id, &rpdata); ct_test(pTest, len != 0); ct_test(pTest, len != -1); apdu_len = len; - len = rp_ack_decode_apdu(&apdu[0], apdu_len, /* total length of the apdu */ - &test_invoke_id, &test_data); + len = rp_ack_decode_apdu(&apdu[0], apdu_len, /* total length of the apdu */ + &test_invoke_id, &test_data); ct_test(pTest, len != -1); ct_test(pTest, test_invoke_id == invoke_id); @@ -389,22 +362,20 @@ void testReadPropertyAck( ct_test(pTest, test_data.object_property == rpdata.object_property); ct_test(pTest, test_data.array_index == rpdata.array_index); ct_test(pTest, - test_data.application_data_len == rpdata.application_data_len); + test_data.application_data_len == rpdata.application_data_len); /* since object property == object_id, decode the application data using the appropriate decode function */ len = - decode_object_id(test_data.application_data, &object, - &object_instance); + decode_object_id(test_data.application_data, &object, &object_instance); object_type = object; ct_test(pTest, object_type == rpdata.object_type); ct_test(pTest, object_instance == rpdata.object_instance); } -void testReadProperty( - Test * pTest) +void testReadProperty(Test *pTest) { - uint8_t apdu[480] = { 0 }; + uint8_t apdu[480] = {0}; int len = 0; int apdu_len = 0; uint8_t invoke_id = 128; @@ -431,8 +402,7 @@ void testReadProperty( } #ifdef TEST_READ_PROPERTY -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -446,7 +416,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/src/rpm.c b/src/rpm.c index 95bc3f40..dd9e25ba 100644 --- a/src/rpm.c +++ b/src/rpm.c @@ -44,11 +44,9 @@ #if BACNET_SVC_RPM_A /* encode the initial portion of the service */ -int rpm_encode_apdu_init( - uint8_t * apdu, - uint8_t invoke_id) +int rpm_encode_apdu_init(uint8_t *apdu, uint8_t invoke_id) { - 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; @@ -61,17 +59,14 @@ int rpm_encode_apdu_init( return apdu_len; } -int rpm_encode_apdu_object_begin( - uint8_t * apdu, - BACNET_OBJECT_TYPE object_type, - uint32_t object_instance) +int rpm_encode_apdu_object_begin(uint8_t *apdu, BACNET_OBJECT_TYPE object_type, + uint32_t object_instance) { - 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_len = - encode_context_object_id(&apdu[0], 0, object_type, - object_instance); + encode_context_object_id(&apdu[0], 0, object_type, object_instance); /* Tag 1: sequence of ReadAccessSpecification */ apdu_len += encode_opening_tag(&apdu[apdu_len], 1); } @@ -79,12 +74,11 @@ int rpm_encode_apdu_object_begin( return apdu_len; } -int rpm_encode_apdu_object_property( - uint8_t * apdu, - BACNET_PROPERTY_ID object_property, - uint32_t array_index) +int rpm_encode_apdu_object_property(uint8_t *apdu, + BACNET_PROPERTY_ID object_property, + uint32_t array_index) { - 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_len = encode_context_enumerated(&apdu[0], 0, object_property); @@ -97,10 +91,9 @@ int rpm_encode_apdu_object_property( return apdu_len; } -int rpm_encode_apdu_object_end( - uint8_t * apdu) +int rpm_encode_apdu_object_end(uint8_t *apdu) { - 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_len = encode_closing_tag(&apdu[0], 1); @@ -117,22 +110,18 @@ int rpm_encode_apdu_object_end( * @param read_access_data [in] The RPM data to be requested. * @return Length of encoded bytes, or 0 on failure. */ -int rpm_encode_apdu( - uint8_t * apdu, - size_t max_apdu, - uint8_t invoke_id, - BACNET_READ_ACCESS_DATA * read_access_data) +int rpm_encode_apdu(uint8_t *apdu, size_t max_apdu, uint8_t invoke_id, + BACNET_READ_ACCESS_DATA *read_access_data) { - int apdu_len = 0; /* total length of the apdu, return value */ - int len = 0; /* length of the data */ - BACNET_READ_ACCESS_DATA *rpm_object; /* current object */ - uint8_t apdu_temp[16]; /* temp for data before copy */ - BACNET_PROPERTY_REFERENCE *rpm_property; /* current property */ + int apdu_len = 0; /* total length of the apdu, return value */ + int len = 0; /* length of the data */ + BACNET_READ_ACCESS_DATA *rpm_object; /* current object */ + uint8_t apdu_temp[16]; /* temp for data before copy */ + BACNET_PROPERTY_REFERENCE *rpm_property; /* current property */ len = rpm_encode_apdu_init(&apdu_temp[0], invoke_id); - len = - (int) memcopy(&apdu[0], &apdu_temp[0], (size_t) apdu_len, (size_t) len, - (size_t) max_apdu); + len = (int)memcopy(&apdu[0], &apdu_temp[0], (size_t)apdu_len, (size_t)len, + (size_t)max_apdu); if (len == 0) { return 0; } @@ -141,19 +130,17 @@ int rpm_encode_apdu( while (rpm_object) { len = encode_context_object_id(&apdu_temp[0], 0, rpm_object->object_type, - rpm_object->object_instance); - len = - (int) memcopy(&apdu[0], &apdu_temp[0], (size_t) apdu_len, - (size_t) len, (size_t) max_apdu); + rpm_object->object_instance); + len = (int)memcopy(&apdu[0], &apdu_temp[0], (size_t)apdu_len, + (size_t)len, (size_t)max_apdu); if (len == 0) { return 0; } apdu_len += len; /* Tag 1: sequence of ReadAccessSpecification */ len = encode_opening_tag(&apdu_temp[0], 1); - len = - (int) memcopy(&apdu[0], &apdu_temp[0], (size_t) apdu_len, - (size_t) len, (size_t) max_apdu); + len = (int)memcopy(&apdu[0], &apdu_temp[0], (size_t)apdu_len, + (size_t)len, (size_t)max_apdu); if (len == 0) { return 0; } @@ -161,24 +148,20 @@ int rpm_encode_apdu( rpm_property = rpm_object->listOfProperties; while (rpm_property) { /* stuff as many properties into it as APDU length will allow */ - len = - encode_context_enumerated(&apdu_temp[0], 0, - rpm_property->propertyIdentifier); - len = - (int) memcopy(&apdu[0], &apdu_temp[0], (size_t) apdu_len, - (size_t) len, (size_t) max_apdu); + len = encode_context_enumerated(&apdu_temp[0], 0, + rpm_property->propertyIdentifier); + len = (int)memcopy(&apdu[0], &apdu_temp[0], (size_t)apdu_len, + (size_t)len, (size_t)max_apdu); if (len == 0) { return 0; } apdu_len += len; /* optional array index */ if (rpm_property->propertyArrayIndex != BACNET_ARRAY_ALL) { - len = - encode_context_unsigned(&apdu_temp[0], 1, - rpm_property->propertyArrayIndex); - len = - (int) memcopy(&apdu[0], &apdu_temp[0], (size_t) apdu_len, - (size_t) len, (size_t) max_apdu); + len = encode_context_unsigned(&apdu_temp[0], 1, + rpm_property->propertyArrayIndex); + len = (int)memcopy(&apdu[0], &apdu_temp[0], (size_t)apdu_len, + (size_t)len, (size_t)max_apdu); if (len == 0) { return 0; } @@ -187,9 +170,8 @@ int rpm_encode_apdu( rpm_property = rpm_property->next; } len = encode_closing_tag(&apdu_temp[0], 1); - len = - (int) memcopy(&apdu[0], &apdu_temp[0], (size_t) apdu_len, - (size_t) len, (size_t) max_apdu); + len = (int)memcopy(&apdu[0], &apdu_temp[0], (size_t)apdu_len, + (size_t)len, (size_t)max_apdu); if (len == 0) { return 0; } @@ -205,17 +187,15 @@ int rpm_encode_apdu( /* decode the object portion of the service request only. Bails out if * tags are wrong or missing/incomplete */ -int rpm_decode_object_id( - uint8_t * apdu, - unsigned apdu_len, - BACNET_RPM_DATA * rpmdata) +int rpm_decode_object_id(uint8_t *apdu, unsigned apdu_len, + BACNET_RPM_DATA *rpmdata) { unsigned len = 0; - uint16_t type = 0; /* for decoding */ + uint16_t type = 0; /* for decoding */ /* check for value pointers */ if (apdu && apdu_len && rpmdata) { - if (apdu_len < 5) { /* Must be at least 2 tags and an object id */ + if (apdu_len < 5) { /* Must be at least 2 tags and an object id */ rpmdata->error_code = ERROR_CODE_REJECT_MISSING_REQUIRED_PARAMETER; return BACNET_STATUS_REJECT; } @@ -225,23 +205,21 @@ int rpm_decode_object_id( return BACNET_STATUS_REJECT; } len += decode_object_id(&apdu[len], &type, &rpmdata->object_instance); - rpmdata->object_type = (BACNET_OBJECT_TYPE) type; + rpmdata->object_type = (BACNET_OBJECT_TYPE)type; /* Tag 1: sequence of ReadAccessSpecification */ if (!decode_is_opening_tag_number(&apdu[len], 1)) { rpmdata->error_code = ERROR_CODE_REJECT_INVALID_TAG; return BACNET_STATUS_REJECT; } - len++; /* opening tag is only one octet */ + len++; /* opening tag is only one octet */ } - return (int) len; + return (int)len; } -int rpm_decode_object_end( - uint8_t * apdu, - unsigned apdu_len) +int rpm_decode_object_end(uint8_t *apdu, unsigned apdu_len) { - int len = 0; /* total length of the apdu, return value */ + int len = 0; /* total length of the apdu, return value */ if (apdu && apdu_len) { if (decode_is_closing_tag_number(apdu, 1) == true) @@ -259,17 +237,15 @@ int rpm_decode_object_end( -- if omitted with an array the entire array is referenced } */ -int rpm_decode_object_property( - uint8_t * apdu, - unsigned apdu_len, - BACNET_RPM_DATA * rpmdata) +int rpm_decode_object_property(uint8_t *apdu, unsigned apdu_len, + BACNET_RPM_DATA *rpmdata) { unsigned len = 0; unsigned option_len = 0; uint8_t tag_number = 0; uint32_t len_value_type = 0; - uint32_t property = 0; /* for decoding */ - uint32_t array_value = 0; /* for decoding */ + uint32_t property = 0; /* for decoding */ + uint32_t array_value = 0; /* for decoding */ /* check for valid pointers */ if (apdu && apdu_len && rpmdata) { @@ -279,9 +255,8 @@ int rpm_decode_object_property( return BACNET_STATUS_REJECT; } - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value_type); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value_type); if (tag_number != 0) { rpmdata->error_code = ERROR_CODE_REJECT_INVALID_TAG; return BACNET_STATUS_REJECT; @@ -292,14 +267,13 @@ int rpm_decode_object_property( return BACNET_STATUS_REJECT; } len += decode_enumerated(&apdu[len], len_value_type, &property); - rpmdata->object_property = (BACNET_PROPERTY_ID) property; + rpmdata->object_property = (BACNET_PROPERTY_ID)property; /* Assume most probable outcome */ rpmdata->array_index = BACNET_ARRAY_ALL; /* Tag 1: Optional propertyArrayIndex */ if (IS_CONTEXT_SPECIFIC(apdu[len]) && !IS_CLOSING_TAG(apdu[len])) { - option_len = - (unsigned) decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value_type); + option_len = (unsigned)decode_tag_number_and_value( + &apdu[len], &tag_number, &len_value_type); if (tag_number == 1) { len += option_len; /* Should be at least the unsigned array index + 1 tag left */ @@ -315,18 +289,16 @@ int rpm_decode_object_property( } } - return (int) len; + return (int)len; } -int rpm_ack_encode_apdu_init( - uint8_t * apdu, - uint8_t invoke_id) +int rpm_ack_encode_apdu_init(uint8_t *apdu, uint8_t invoke_id) { - 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 */ - apdu[1] = invoke_id; /* original invoke id from request */ + apdu[1] = invoke_id; /* original invoke id from request */ apdu[2] = SERVICE_CONFIRMED_READ_PROP_MULTIPLE; /* service choice */ apdu_len = 3; } @@ -334,17 +306,14 @@ int rpm_ack_encode_apdu_init( return apdu_len; } -int rpm_ack_encode_apdu_object_begin( - uint8_t * apdu, - BACNET_RPM_DATA * rpmdata) +int rpm_ack_encode_apdu_object_begin(uint8_t *apdu, BACNET_RPM_DATA *rpmdata) { - int apdu_len = 0; /* total length of the apdu, return value */ + int apdu_len = 0; /* total length of the apdu, return value */ if (apdu) { /* Tag 0: objectIdentifier */ - apdu_len = - encode_context_object_id(&apdu[0], 0, rpmdata->object_type, - rpmdata->object_instance); + apdu_len = encode_context_object_id(&apdu[0], 0, rpmdata->object_type, + rpmdata->object_instance); /* Tag 1: listOfResults */ apdu_len += encode_opening_tag(&apdu[apdu_len], 1); } @@ -352,12 +321,11 @@ int rpm_ack_encode_apdu_object_begin( return apdu_len; } -int rpm_ack_encode_apdu_object_property( - uint8_t * apdu, - BACNET_PROPERTY_ID object_property, - uint32_t array_index) +int rpm_ack_encode_apdu_object_property(uint8_t *apdu, + BACNET_PROPERTY_ID object_property, + uint32_t array_index) { - int apdu_len = 0; /* total length of the apdu, return value */ + int apdu_len = 0; /* total length of the apdu, return value */ if (apdu) { /* Tag 2: propertyIdentifier */ @@ -371,20 +339,20 @@ int rpm_ack_encode_apdu_object_property( return apdu_len; } -int rpm_ack_encode_apdu_object_property_value( - uint8_t * apdu, - uint8_t * application_data, - unsigned application_data_len) +int rpm_ack_encode_apdu_object_property_value(uint8_t *apdu, + uint8_t *application_data, + unsigned application_data_len) { - int apdu_len = 0; /* total length of the apdu, return value */ + int apdu_len = 0; /* total length of the apdu, return value */ unsigned len = 0; if (apdu) { /* Tag 4: propertyValue */ apdu_len += encode_opening_tag(&apdu[apdu_len], 4); - if (application_data == &apdu[apdu_len]) { /* Is Data already in place? */ - apdu_len += application_data_len; /* Yes, step over data */ - } else { /* No, copy data in */ + if (application_data == + &apdu[apdu_len]) { /* Is Data already in place? */ + apdu_len += application_data_len; /* Yes, step over data */ + } else { /* No, copy data in */ for (len = 0; len < application_data_len; len++) { apdu[apdu_len++] = application_data[len]; } @@ -395,18 +363,16 @@ int rpm_ack_encode_apdu_object_property_value( return apdu_len; } -int rpm_ack_encode_apdu_object_property_error( - uint8_t * apdu, - BACNET_ERROR_CLASS error_class, - BACNET_ERROR_CODE error_code) +int rpm_ack_encode_apdu_object_property_error(uint8_t *apdu, + BACNET_ERROR_CLASS error_class, + BACNET_ERROR_CODE error_code) { - int apdu_len = 0; /* total length of the apdu, return value */ + int apdu_len = 0; /* total length of the apdu, return value */ if (apdu) { /* Tag 5: propertyAccessError */ apdu_len += encode_opening_tag(&apdu[apdu_len], 5); - apdu_len += - encode_application_enumerated(&apdu[apdu_len], error_class); + apdu_len += encode_application_enumerated(&apdu[apdu_len], error_class); apdu_len += encode_application_enumerated(&apdu[apdu_len], error_code); apdu_len += encode_closing_tag(&apdu[apdu_len], 5); } @@ -414,10 +380,9 @@ int rpm_ack_encode_apdu_object_property_error( return apdu_len; } -int rpm_ack_encode_apdu_object_end( - uint8_t * apdu) +int rpm_ack_encode_apdu_object_end(uint8_t *apdu) { - 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_len = encode_closing_tag(&apdu[0], 1); @@ -429,14 +394,12 @@ int rpm_ack_encode_apdu_object_end( #if BACNET_SVC_RPM_A /* decode the object portion of the service request only */ -int rpm_ack_decode_object_id( - uint8_t * apdu, - unsigned apdu_len, - BACNET_OBJECT_TYPE * object_type, - uint32_t * object_instance) +int rpm_ack_decode_object_id(uint8_t *apdu, unsigned apdu_len, + BACNET_OBJECT_TYPE *object_type, + uint32_t *object_instance) { unsigned len = 0; - uint16_t type = 0; /* for decoding */ + uint16_t type = 0; /* for decoding */ /* check for value pointers */ if (apdu && apdu_len && object_type && object_instance) { @@ -445,22 +408,20 @@ int rpm_ack_decode_object_id( return -1; len += decode_object_id(&apdu[len], &type, object_instance); if (object_type) - *object_type = (BACNET_OBJECT_TYPE) type; + *object_type = (BACNET_OBJECT_TYPE)type; /* Tag 1: listOfResults */ if (!decode_is_opening_tag_number(&apdu[len], 1)) return -1; - len++; /* opening tag is only one octet */ + len++; /* opening tag is only one octet */ } - return (int) len; + return (int)len; } /* is this the end of the list of this objects properties values? */ -int rpm_ack_decode_object_end( - uint8_t * apdu, - unsigned apdu_len) +int rpm_ack_decode_object_end(uint8_t *apdu, unsigned apdu_len) { - int len = 0; /* total length of the apdu, return value */ + int len = 0; /* total length of the apdu, return value */ if (apdu && apdu_len) { if (decode_is_closing_tag_number(apdu, 1)) @@ -470,38 +431,34 @@ int rpm_ack_decode_object_end( return len; } -int rpm_ack_decode_object_property( - uint8_t * apdu, - unsigned apdu_len, - BACNET_PROPERTY_ID * object_property, - uint32_t * array_index) +int rpm_ack_decode_object_property(uint8_t *apdu, unsigned apdu_len, + BACNET_PROPERTY_ID *object_property, + uint32_t *array_index) { unsigned len = 0; unsigned tag_len = 0; uint8_t tag_number = 0; uint32_t len_value_type = 0; - uint32_t property = 0; /* for decoding */ - uint32_t array_value = 0; /* for decoding */ + uint32_t property = 0; /* for decoding */ + uint32_t array_value = 0; /* for decoding */ /* check for valid pointers */ if (apdu && apdu_len && object_property && array_index) { /* Tag 2: propertyIdentifier */ if (!IS_CONTEXT_SPECIFIC(apdu[len])) return -1; - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value_type); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value_type); if (tag_number != 2) return -1; len += decode_enumerated(&apdu[len], len_value_type, &property); if (object_property) - *object_property = (BACNET_PROPERTY_ID) property; + *object_property = (BACNET_PROPERTY_ID)property; /* Tag 3: Optional propertyArrayIndex */ if ((len < apdu_len) && IS_CONTEXT_SPECIFIC(apdu[len]) && (!IS_CLOSING_TAG(apdu[len]))) { - tag_len = - (unsigned) decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value_type); + tag_len = (unsigned)decode_tag_number_and_value( + &apdu[len], &tag_number, &len_value_type); if (tag_number == 3) { len += tag_len; len += @@ -515,7 +472,7 @@ int rpm_ack_decode_object_property( } } - return (int) len; + return (int)len; } #endif @@ -525,12 +482,10 @@ int rpm_ack_decode_object_property( #include #include "ctest.h" -int rpm_ack_decode_apdu( - uint8_t * apdu, - int apdu_len, /* total length of the apdu */ - uint8_t * invoke_id, - uint8_t ** service_request, - unsigned *service_request_len) +int rpm_ack_decode_apdu(uint8_t *apdu, + int apdu_len, /* total length of the apdu */ + uint8_t *invoke_id, uint8_t **service_request, + unsigned *service_request_len) { int offset = 0; @@ -553,12 +508,8 @@ int rpm_ack_decode_apdu( return offset; } -int rpm_decode_apdu( - uint8_t * apdu, - unsigned apdu_len, - uint8_t * invoke_id, - uint8_t ** service_request, - unsigned *service_request_len) +int rpm_decode_apdu(uint8_t *apdu, unsigned apdu_len, uint8_t *invoke_id, + uint8_t **service_request, unsigned *service_request_len) { unsigned offset = 0; @@ -568,7 +519,7 @@ int rpm_decode_apdu( if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST) return -1; /* apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU); */ - *invoke_id = apdu[2]; /* invoke id - filled in by net layer */ + *invoke_id = apdu[2]; /* invoke id - filled in by net layer */ if (apdu[3] != SERVICE_CONFIRMED_READ_PROP_MULTIPLE) return -1; offset = 4; @@ -583,10 +534,9 @@ int rpm_decode_apdu( return offset; } -void testReadPropertyMultiple( - Test * pTest) +void testReadPropertyMultiple(Test *pTest) { - uint8_t apdu[480] = { 0 }; + uint8_t apdu[480] = {0}; int len = 0; int test_len = 0; int apdu_len = 0; @@ -601,38 +551,37 @@ void testReadPropertyMultiple( rpmdata.object_property = PROP_OBJECT_IDENTIFIER; rpmdata.array_index = 0; - /* build the RPM - try to make it easy for the Application Layer development */ - /* IDEA: similar construction, but pass apdu, apdu_len pointer, size of apdu to - let the called function handle the out of space problem that these get into - by returning a boolean of success/failure. - It almost needs to use the keylist library or something similar. - Also check case of storing a backoff point (i.e. save enough room for object_end) */ + /* build the RPM - try to make it easy for the Application Layer development + */ + /* IDEA: similar construction, but pass apdu, apdu_len pointer, size of apdu + to let the called function handle the out of space problem that these get + into by returning a boolean of success/failure. It almost needs to use + the keylist library or something similar. Also check case of storing a + backoff point (i.e. save enough room for object_end) */ apdu_len = rpm_encode_apdu_init(&apdu[0], invoke_id); /* each object has a beginning and an end */ apdu_len += rpm_encode_apdu_object_begin(&apdu[apdu_len], OBJECT_DEVICE, 123); /* then stuff as many properties into it as APDU length will allow */ - apdu_len += - rpm_encode_apdu_object_property(&apdu[apdu_len], - PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL); - apdu_len += - rpm_encode_apdu_object_property(&apdu[apdu_len], PROP_OBJECT_NAME, - BACNET_ARRAY_ALL); + apdu_len += rpm_encode_apdu_object_property( + &apdu[apdu_len], PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL); + apdu_len += rpm_encode_apdu_object_property( + &apdu[apdu_len], PROP_OBJECT_NAME, BACNET_ARRAY_ALL); apdu_len += rpm_encode_apdu_object_end(&apdu[apdu_len]); /* each object has a beginning and an end */ apdu_len += rpm_encode_apdu_object_begin(&apdu[apdu_len], OBJECT_ANALOG_INPUT, 33); - apdu_len += - rpm_encode_apdu_object_property(&apdu[apdu_len], - PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL); - apdu_len += - rpm_encode_apdu_object_property(&apdu[apdu_len], PROP_ALL, - BACNET_ARRAY_ALL); + apdu_len += rpm_encode_apdu_object_property( + &apdu[apdu_len], PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL); + apdu_len += rpm_encode_apdu_object_property(&apdu[apdu_len], PROP_ALL, + BACNET_ARRAY_ALL); apdu_len += rpm_encode_apdu_object_end(&apdu[apdu_len]); ct_test(pTest, apdu_len != 0); - test_len = rpm_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, &service_request, /* will point to the service request in the apdu */ + test_len = rpm_decode_apdu( + &apdu[0], apdu_len, &test_invoke_id, + &service_request, /* will point to the service request in the apdu */ &service_request_len); ct_test(pTest, test_len != -1); ct_test(pTest, test_invoke_id == invoke_id); @@ -646,71 +595,61 @@ void testReadPropertyMultiple( ct_test(pTest, rpmdata.object_instance == 123); len = test_len; /* decode the object property portion of the service request */ - test_len = - rpm_decode_object_property(&service_request[len], - service_request_len - len, &rpmdata); + test_len = rpm_decode_object_property(&service_request[len], + service_request_len - len, &rpmdata); ct_test(pTest, test_len > 0); ct_test(pTest, rpmdata.object_property == PROP_OBJECT_IDENTIFIER); ct_test(pTest, rpmdata.array_index == BACNET_ARRAY_ALL); len += test_len; - test_len = - rpm_decode_object_property(&service_request[len], - service_request_len - len, &rpmdata); + test_len = rpm_decode_object_property(&service_request[len], + service_request_len - len, &rpmdata); ct_test(pTest, test_len > 0); ct_test(pTest, rpmdata.object_property == PROP_OBJECT_NAME); ct_test(pTest, rpmdata.array_index == BACNET_ARRAY_ALL); len += test_len; /* try again - we should fail */ - test_len = - rpm_decode_object_property(&service_request[len], - service_request_len - len, &rpmdata); + test_len = rpm_decode_object_property(&service_request[len], + service_request_len - len, &rpmdata); ct_test(pTest, test_len < 0); /* is it the end of this object? */ test_len = - rpm_decode_object_end(&service_request[len], - service_request_len - len); + rpm_decode_object_end(&service_request[len], service_request_len - len); ct_test(pTest, test_len == 1); len += test_len; /* try to decode an object id */ - test_len = - rpm_decode_object_id(&service_request[len], service_request_len - len, - &rpmdata); + test_len = rpm_decode_object_id(&service_request[len], + service_request_len - len, &rpmdata); ct_test(pTest, test_len > 0); ct_test(pTest, rpmdata.object_type == OBJECT_ANALOG_INPUT); ct_test(pTest, rpmdata.object_instance == 33); len += test_len; /* decode the object property portion of the service request only */ - test_len = - rpm_decode_object_property(&service_request[len], - service_request_len - len, &rpmdata); + test_len = rpm_decode_object_property(&service_request[len], + service_request_len - len, &rpmdata); ct_test(pTest, test_len > 0); ct_test(pTest, rpmdata.object_property == PROP_OBJECT_IDENTIFIER); ct_test(pTest, rpmdata.array_index == BACNET_ARRAY_ALL); len += test_len; - test_len = - rpm_decode_object_property(&service_request[len], - service_request_len - len, &rpmdata); + test_len = rpm_decode_object_property(&service_request[len], + service_request_len - len, &rpmdata); ct_test(pTest, test_len > 0); ct_test(pTest, rpmdata.object_property == PROP_ALL); ct_test(pTest, rpmdata.array_index == BACNET_ARRAY_ALL); len += test_len; - test_len = - rpm_decode_object_property(&service_request[len], - service_request_len - len, &rpmdata); + test_len = rpm_decode_object_property(&service_request[len], + service_request_len - len, &rpmdata); ct_test(pTest, test_len < 0); /* got an error -1, is it the end of this object? */ test_len = - rpm_decode_object_end(&service_request[len], - service_request_len - len); + rpm_decode_object_end(&service_request[len], service_request_len - len); ct_test(pTest, test_len == 1); len += test_len; ct_test(pTest, len == service_request_len); } -void testReadPropertyMultipleAck( - Test * pTest) +void testReadPropertyMultipleAck(Test *pTest) { - uint8_t apdu[480] = { 0 }; + uint8_t apdu[480] = {0}; int len = 0; int test_len = 0; int apdu_len = 0; @@ -722,9 +661,9 @@ void testReadPropertyMultipleAck( uint32_t object_instance = 0; BACNET_PROPERTY_ID object_property = PROP_OBJECT_IDENTIFIER; uint32_t array_index = 0; - BACNET_APPLICATION_DATA_VALUE application_data[4] = { {0} }; - BACNET_APPLICATION_DATA_VALUE test_application_data = { 0 }; - uint8_t application_data_buffer[MAX_APDU] = { 0 }; + BACNET_APPLICATION_DATA_VALUE application_data[4] = {{0}}; + BACNET_APPLICATION_DATA_VALUE test_application_data = {0}; + uint8_t application_data_buffer[MAX_APDU] = {0}; int application_data_buffer_len = 0; BACNET_ERROR_CLASS error_class; BACNET_ERROR_CODE error_code; @@ -745,32 +684,28 @@ void testReadPropertyMultipleAck( rpmdata.object_instance = 123; apdu_len += rpm_ack_encode_apdu_object_begin(&apdu[apdu_len], &rpmdata); /* reply property */ - apdu_len += - rpm_ack_encode_apdu_object_property(&apdu[apdu_len], - PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL); + apdu_len += rpm_ack_encode_apdu_object_property( + &apdu[apdu_len], PROP_OBJECT_IDENTIFIER, BACNET_ARRAY_ALL); /* reply value */ application_data[0].tag = BACNET_APPLICATION_TAG_OBJECT_ID; application_data[0].type.Object_Id.type = OBJECT_DEVICE; application_data[0].type.Object_Id.instance = 123; - application_data_buffer_len = - bacapp_encode_application_data(&application_data_buffer[0], - &application_data[0]); - apdu_len += - rpm_ack_encode_apdu_object_property_value(&apdu[apdu_len], - &application_data_buffer[0], application_data_buffer_len); + application_data_buffer_len = bacapp_encode_application_data( + &application_data_buffer[0], &application_data[0]); + apdu_len += rpm_ack_encode_apdu_object_property_value( + &apdu[apdu_len], &application_data_buffer[0], + application_data_buffer_len); /* reply property */ - apdu_len += - rpm_ack_encode_apdu_object_property(&apdu[apdu_len], PROP_OBJECT_TYPE, - BACNET_ARRAY_ALL); + apdu_len += rpm_ack_encode_apdu_object_property( + &apdu[apdu_len], PROP_OBJECT_TYPE, BACNET_ARRAY_ALL); /* reply value */ application_data[1].tag = BACNET_APPLICATION_TAG_ENUMERATED; application_data[1].type.Enumerated = OBJECT_DEVICE; - application_data_buffer_len = - bacapp_encode_application_data(&application_data_buffer[0], - &application_data[1]); - apdu_len += - rpm_ack_encode_apdu_object_property_value(&apdu[apdu_len], - &application_data_buffer[0], application_data_buffer_len); + application_data_buffer_len = bacapp_encode_application_data( + &application_data_buffer[0], &application_data[1]); + apdu_len += rpm_ack_encode_apdu_object_property_value( + &apdu[apdu_len], &application_data_buffer[0], + application_data_buffer_len); /* object end */ apdu_len += rpm_ack_encode_apdu_object_end(&apdu[apdu_len]); @@ -779,49 +714,46 @@ void testReadPropertyMultipleAck( rpmdata.object_instance = 33; apdu_len += rpm_ack_encode_apdu_object_begin(&apdu[apdu_len], &rpmdata); /* reply property */ - apdu_len += - rpm_ack_encode_apdu_object_property(&apdu[apdu_len], - PROP_PRESENT_VALUE, BACNET_ARRAY_ALL); + apdu_len += rpm_ack_encode_apdu_object_property( + &apdu[apdu_len], PROP_PRESENT_VALUE, BACNET_ARRAY_ALL); /* reply value */ application_data[2].tag = BACNET_APPLICATION_TAG_REAL; application_data[2].type.Real = 0.0; - application_data_buffer_len = - bacapp_encode_application_data(&application_data_buffer[0], - &application_data[2]); - apdu_len += - rpm_ack_encode_apdu_object_property_value(&apdu[apdu_len], - &application_data_buffer[0], application_data_buffer_len); + application_data_buffer_len = bacapp_encode_application_data( + &application_data_buffer[0], &application_data[2]); + apdu_len += rpm_ack_encode_apdu_object_property_value( + &apdu[apdu_len], &application_data_buffer[0], + application_data_buffer_len); /* reply property */ - apdu_len += - rpm_ack_encode_apdu_object_property(&apdu[apdu_len], PROP_DEADBAND, - BACNET_ARRAY_ALL); + apdu_len += rpm_ack_encode_apdu_object_property( + &apdu[apdu_len], PROP_DEADBAND, BACNET_ARRAY_ALL); /* reply error */ - apdu_len += - rpm_ack_encode_apdu_object_property_error(&apdu[apdu_len], - ERROR_CLASS_PROPERTY, ERROR_CODE_UNKNOWN_PROPERTY); + apdu_len += rpm_ack_encode_apdu_object_property_error( + &apdu[apdu_len], ERROR_CLASS_PROPERTY, ERROR_CODE_UNKNOWN_PROPERTY); /* object end */ apdu_len += rpm_ack_encode_apdu_object_end(&apdu[apdu_len]); ct_test(pTest, apdu_len != 0); - /****** decode the packet ******/ - test_len = rpm_ack_decode_apdu(&apdu[0], apdu_len, &test_invoke_id, &service_request, /* will point to the service request in the apdu */ + /****** decode the packet ******/ + test_len = rpm_ack_decode_apdu( + &apdu[0], apdu_len, &test_invoke_id, + &service_request, /* will point to the service request in the apdu */ &service_request_len); ct_test(pTest, test_len != -1); ct_test(pTest, test_invoke_id == invoke_id); ct_test(pTest, service_request != NULL); ct_test(pTest, service_request_len > 0); /* the first part should be the first object id */ - test_len = - rpm_ack_decode_object_id(service_request, service_request_len, - &object_type, &object_instance); + test_len = rpm_ack_decode_object_id(service_request, service_request_len, + &object_type, &object_instance); ct_test(pTest, test_len != -1); ct_test(pTest, object_type == OBJECT_DEVICE); ct_test(pTest, object_instance == 123); len = test_len; /* extract the property */ - test_len = - rpm_ack_decode_object_property(&service_request[len], - service_request_len - len, &object_property, &array_index); + test_len = rpm_ack_decode_object_property(&service_request[len], + service_request_len - len, + &object_property, &array_index); ct_test(pTest, object_property == PROP_OBJECT_IDENTIFIER); ct_test(pTest, array_index == BACNET_ARRAY_ALL); len += test_len; @@ -831,19 +763,19 @@ void testReadPropertyMultipleAck( /* decode the object property portion of the service request */ /* note: if this was an array, there could have been more than one element to decode */ - test_len = - bacapp_decode_application_data(&service_request[len], - service_request_len - len, &test_application_data); + test_len = bacapp_decode_application_data(&service_request[len], + service_request_len - len, + &test_application_data); ct_test(pTest, test_len > 0); - ct_test(pTest, bacapp_same_value(&application_data[0], - &test_application_data)); + ct_test(pTest, + bacapp_same_value(&application_data[0], &test_application_data)); len += test_len; ct_test(pTest, decode_is_closing_tag_number(&service_request[len], 4)); len++; /* see if there is another property */ - test_len = - rpm_ack_decode_object_property(&service_request[len], - service_request_len - len, &object_property, &array_index); + test_len = rpm_ack_decode_object_property(&service_request[len], + service_request_len - len, + &object_property, &array_index); ct_test(pTest, test_len != -1); ct_test(pTest, object_property == PROP_OBJECT_TYPE); ct_test(pTest, array_index == BACNET_ARRAY_ALL); @@ -852,39 +784,38 @@ void testReadPropertyMultipleAck( ct_test(pTest, decode_is_opening_tag_number(&service_request[len], 4)); len++; /* decode the object property portion of the service request */ - test_len = - bacapp_decode_application_data(&service_request[len], - service_request_len - len, &test_application_data); + test_len = bacapp_decode_application_data(&service_request[len], + service_request_len - len, + &test_application_data); ct_test(pTest, test_len > 0); - ct_test(pTest, bacapp_same_value(&application_data[1], - &test_application_data)); + ct_test(pTest, + bacapp_same_value(&application_data[1], &test_application_data)); len += test_len; ct_test(pTest, decode_is_closing_tag_number(&service_request[len], 4)); len++; /* see if there is another property */ /* this time we should fail */ - test_len = - rpm_ack_decode_object_property(&service_request[len], - service_request_len - len, &object_property, &array_index); + test_len = rpm_ack_decode_object_property(&service_request[len], + service_request_len - len, + &object_property, &array_index); ct_test(pTest, test_len == -1); /* see if it is the end of this object */ - test_len = - rpm_ack_decode_object_end(&service_request[len], - service_request_len - len); + test_len = rpm_ack_decode_object_end(&service_request[len], + service_request_len - len); ct_test(pTest, test_len == 1); len += test_len; /* try to decode another object id */ - test_len = - rpm_ack_decode_object_id(&service_request[len], - service_request_len - len, &object_type, &object_instance); + test_len = rpm_ack_decode_object_id(&service_request[len], + service_request_len - len, &object_type, + &object_instance); ct_test(pTest, test_len != -1); ct_test(pTest, object_type == OBJECT_ANALOG_INPUT); ct_test(pTest, object_instance == 33); len += test_len; /* decode the object property portion of the service request only */ - test_len = - rpm_ack_decode_object_property(&service_request[len], - service_request_len - len, &object_property, &array_index); + test_len = rpm_ack_decode_object_property(&service_request[len], + service_request_len - len, + &object_property, &array_index); ct_test(pTest, test_len != -1); ct_test(pTest, object_property == PROP_PRESENT_VALUE); ct_test(pTest, array_index == BACNET_ARRAY_ALL); @@ -893,19 +824,19 @@ void testReadPropertyMultipleAck( ct_test(pTest, decode_is_opening_tag_number(&service_request[len], 4)); len++; /* decode the object property portion of the service request */ - test_len = - bacapp_decode_application_data(&service_request[len], - service_request_len - len, &test_application_data); + test_len = bacapp_decode_application_data(&service_request[len], + service_request_len - len, + &test_application_data); ct_test(pTest, test_len > 0); - ct_test(pTest, bacapp_same_value(&application_data[2], - &test_application_data)); + ct_test(pTest, + bacapp_same_value(&application_data[2], &test_application_data)); len += test_len; ct_test(pTest, decode_is_closing_tag_number(&service_request[len], 4)); len++; /* see if there is another property */ - test_len = - rpm_ack_decode_object_property(&service_request[len], - service_request_len - len, &object_property, &array_index); + test_len = rpm_ack_decode_object_property(&service_request[len], + service_request_len - len, + &object_property, &array_index); ct_test(pTest, test_len != -1); ct_test(pTest, object_property == PROP_DEADBAND); ct_test(pTest, array_index == BACNET_ARRAY_ALL); @@ -914,9 +845,9 @@ void testReadPropertyMultipleAck( ct_test(pTest, decode_is_opening_tag_number(&service_request[len], 5)); len++; /* it was an error reply */ - test_len = - bacerror_decode_error_class_and_code(&service_request[len], - service_request_len - len, &error_class, &error_code); + test_len = bacerror_decode_error_class_and_code(&service_request[len], + service_request_len - len, + &error_class, &error_code); ct_test(pTest, test_len != 0); ct_test(pTest, error_class == ERROR_CLASS_PROPERTY); ct_test(pTest, error_code == ERROR_CODE_UNKNOWN_PROPERTY); @@ -924,27 +855,25 @@ void testReadPropertyMultipleAck( ct_test(pTest, decode_is_closing_tag_number(&service_request[len], 5)); len++; /* is there another property? */ - test_len = - rpm_ack_decode_object_property(&service_request[len], - service_request_len - len, &object_property, &array_index); + test_len = rpm_ack_decode_object_property(&service_request[len], + service_request_len - len, + &object_property, &array_index); ct_test(pTest, test_len == -1); /* got an error -1, is it the end of this object? */ - test_len = - rpm_ack_decode_object_end(&service_request[len], - service_request_len - len); + test_len = rpm_ack_decode_object_end(&service_request[len], + service_request_len - len); ct_test(pTest, test_len == 1); len += test_len; /* check for another object */ - test_len = - rpm_ack_decode_object_id(&service_request[len], - service_request_len - len, &object_type, &object_instance); + test_len = rpm_ack_decode_object_id(&service_request[len], + service_request_len - len, &object_type, + &object_instance); ct_test(pTest, test_len == 0); ct_test(pTest, len == service_request_len); } #ifdef TEST_READ_PROPERTY_MULTIPLE -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -958,7 +887,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/src/sbuf.c b/src/sbuf.c index efc7655e..075e64d2 100644 --- a/src/sbuf.c +++ b/src/sbuf.c @@ -42,11 +42,10 @@ #include #include "sbuf.h" -void sbuf_init( - STATIC_BUFFER * b, /* static buffer structure */ - char *data, /* data block */ - unsigned size) -{ /* actual size, in bytes, of the data block or array of data */ +void sbuf_init(STATIC_BUFFER *b, /* static buffer structure */ + char *data, /* data block */ + unsigned size) +{ /* actual size, in bytes, of the data block or array of data */ if (b) { b->data = data; b->size = size; @@ -57,38 +56,33 @@ void sbuf_init( } /* returns true if count==0, false if count > 0 */ -bool sbuf_empty( - STATIC_BUFFER const *b) +bool sbuf_empty(STATIC_BUFFER const *b) { return (b ? (b->count == 0) : false); } -char *sbuf_data( - STATIC_BUFFER const *b) +char *sbuf_data(STATIC_BUFFER const *b) { return (b ? b->data : NULL); } -unsigned sbuf_size( - STATIC_BUFFER * b) +unsigned sbuf_size(STATIC_BUFFER *b) { return (b ? b->size : 0); } -unsigned sbuf_count( - STATIC_BUFFER * b) +unsigned sbuf_count(STATIC_BUFFER *b) { return (b ? b->count : 0); } /* returns true if successful, false if not enough room to append data */ -bool sbuf_put( - STATIC_BUFFER * b, /* static buffer structure */ - unsigned offset, /* where to start */ - char *data, /* data to place in buffer */ - unsigned data_size) -{ /* how many bytes to add */ - bool status = false; /* return value */ +bool sbuf_put(STATIC_BUFFER *b, /* static buffer structure */ + unsigned offset, /* where to start */ + char *data, /* data to place in buffer */ + unsigned data_size) +{ /* how many bytes to add */ + bool status = false; /* return value */ if (b && b->data) { if (((offset + data_size) < b->size)) { @@ -107,11 +101,10 @@ bool sbuf_put( } /* returns true if successful, false if not enough room to append data */ -bool sbuf_append( - STATIC_BUFFER * b, /* static buffer structure */ - char *data, /* data to place in buffer */ - unsigned data_size) -{ /* how many bytes to add */ +bool sbuf_append(STATIC_BUFFER *b, /* static buffer structure */ + char *data, /* data to place in buffer */ + unsigned data_size) +{ /* how many bytes to add */ unsigned count = 0; if (b) { @@ -122,11 +115,10 @@ bool sbuf_append( } /* returns true if successful, false if not enough room to append data */ -bool sbuf_truncate( - STATIC_BUFFER * b, /* static buffer structure */ - unsigned count) -{ /* total number of bytes in to remove */ - bool status = false; /* return value */ +bool sbuf_truncate(STATIC_BUFFER *b, /* static buffer structure */ + unsigned count) +{ /* total number of bytes in to remove */ + bool status = false; /* return value */ if (b) { if (count < b->size) { @@ -144,8 +136,7 @@ bool sbuf_truncate( #include "ctest.h" -void testStaticBuffer( - Test * pTest) +void testStaticBuffer(Test *pTest) { STATIC_BUFFER sbuffer; char *data1 = "Joshua"; @@ -198,8 +189,7 @@ void testStaticBuffer( } #ifdef TEST_STATIC_BUFFER -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -212,7 +202,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); diff --git a/src/timestamp.c b/src/timestamp.c index 45949296..c601632b 100644 --- a/src/timestamp.c +++ b/src/timestamp.c @@ -37,9 +37,7 @@ /** @file timestamp.c Encode/Decode BACnet Timestamps */ -void bacapp_timestamp_sequence_set( - BACNET_TIMESTAMP * dest, - uint16_t sequenceNum) +void bacapp_timestamp_sequence_set(BACNET_TIMESTAMP *dest, uint16_t sequenceNum) { if (dest) { dest->tag = TIME_STAMP_SEQUENCE; @@ -47,9 +45,7 @@ void bacapp_timestamp_sequence_set( } } -void bacapp_timestamp_time_set( - BACNET_TIMESTAMP * dest, - BACNET_TIME *btime) +void bacapp_timestamp_time_set(BACNET_TIMESTAMP *dest, BACNET_TIME *btime) { if (dest && btime) { dest->tag = TIME_STAMP_TIME; @@ -57,9 +53,8 @@ void bacapp_timestamp_time_set( } } -void bacapp_timestamp_datetime_set( - BACNET_TIMESTAMP * dest, - BACNET_DATE_TIME * bdateTime) +void bacapp_timestamp_datetime_set(BACNET_TIMESTAMP *dest, + BACNET_DATE_TIME *bdateTime) { if (dest && bdateTime) { dest->tag = TIME_STAMP_DATETIME; @@ -67,9 +62,7 @@ void bacapp_timestamp_datetime_set( } } -void bacapp_timestamp_copy( - BACNET_TIMESTAMP * dest, - BACNET_TIMESTAMP * src) +void bacapp_timestamp_copy(BACNET_TIMESTAMP *dest, BACNET_TIMESTAMP *src) { if (dest && src) { dest->tag = src->tag; @@ -89,11 +82,9 @@ void bacapp_timestamp_copy( } } -int bacapp_encode_timestamp( - uint8_t * apdu, - BACNET_TIMESTAMP * value) +int bacapp_encode_timestamp(uint8_t *apdu, BACNET_TIMESTAMP *value) { - int len = 0; /* length of each encoding */ + int len = 0; /* length of each encoding */ if (value && apdu) { switch (value->tag) { @@ -102,15 +93,13 @@ int bacapp_encode_timestamp( break; case TIME_STAMP_SEQUENCE: - len = - encode_context_unsigned(&apdu[0], 1, - value->value.sequenceNum); + len = encode_context_unsigned(&apdu[0], 1, + value->value.sequenceNum); break; case TIME_STAMP_DATETIME: - len = - bacapp_encode_context_datetime(&apdu[0], 2, - &value->value.dateTime); + len = bacapp_encode_context_datetime(&apdu[0], 2, + &value->value.dateTime); break; default: @@ -123,12 +112,10 @@ int bacapp_encode_timestamp( return len; } -int bacapp_encode_context_timestamp( - uint8_t * apdu, - uint8_t tag_number, - BACNET_TIMESTAMP * value) +int bacapp_encode_context_timestamp(uint8_t *apdu, uint8_t tag_number, + BACNET_TIMESTAMP *value) { - int len = 0; /* length of each encoding */ + int len = 0; /* length of each encoding */ int apdu_len = 0; if (value && apdu) { @@ -142,9 +129,7 @@ int bacapp_encode_context_timestamp( return apdu_len; } -int bacapp_decode_timestamp( - uint8_t * apdu, - BACNET_TIMESTAMP * value) +int bacapp_decode_timestamp(uint8_t *apdu, BACNET_TIMESTAMP *value) { int len = 0; int section_len; @@ -152,18 +137,17 @@ int bacapp_decode_timestamp( uint32_t sequenceNum; if (apdu) { - section_len = - decode_tag_number_and_value(&apdu[len], &value->tag, - &len_value_type); + section_len = decode_tag_number_and_value(&apdu[len], &value->tag, + &len_value_type); if (-1 == section_len) { return -1; } switch (value->tag) { case TIME_STAMP_TIME: - if ((section_len = - decode_context_bacnet_time(&apdu[len], TIME_STAMP_TIME, - &value->value.time)) == -1) { + if ((section_len = decode_context_bacnet_time( + &apdu[len], TIME_STAMP_TIME, &value->value.time)) == + -1) { return -1; } else { len += section_len; @@ -171,14 +155,14 @@ int bacapp_decode_timestamp( break; case TIME_STAMP_SEQUENCE: - if ((section_len = - decode_context_unsigned(&apdu[len], - TIME_STAMP_SEQUENCE, &sequenceNum)) == -1) { + if ((section_len = decode_context_unsigned( + &apdu[len], TIME_STAMP_SEQUENCE, &sequenceNum)) == + -1) { return -1; } else { if (sequenceNum <= 0xffff) { len += section_len; - value->value.sequenceNum = (uint16_t) sequenceNum; + value->value.sequenceNum = (uint16_t)sequenceNum; } else { return -1; } @@ -186,10 +170,9 @@ int bacapp_decode_timestamp( break; case TIME_STAMP_DATETIME: - if ((section_len = - bacapp_decode_context_datetime(&apdu[len], - TIME_STAMP_DATETIME, - &value->value.dateTime)) == -1) { + if ((section_len = bacapp_decode_context_datetime( + &apdu[len], TIME_STAMP_DATETIME, + &value->value.dateTime)) == -1) { return -1; } else { len += section_len; @@ -204,15 +187,12 @@ int bacapp_decode_timestamp( return len; } -int bacapp_decode_context_timestamp( - uint8_t * apdu, - uint8_t tag_number, - BACNET_TIMESTAMP * value) +int bacapp_decode_context_timestamp(uint8_t *apdu, uint8_t tag_number, + BACNET_TIMESTAMP *value) { int len = 0; int section_len; - if (decode_is_opening_tag_number(&apdu[len], tag_number)) { len++; section_len = bacapp_decode_timestamp(&apdu[len], value); @@ -234,9 +214,7 @@ int bacapp_decode_context_timestamp( #include #include "ctest.h" - -void testTimestampSequence( - Test * pTest) +void testTimestampSequence(Test *pTest) { BACNET_TIMESTAMP testTimestampIn; BACNET_TIMESTAMP testTimestampOut; @@ -249,19 +227,16 @@ void testTimestampSequence( memset(&testTimestampOut, 0, sizeof(testTimestampOut)); - inLen = bacapp_encode_context_timestamp(buffer, 2, &testTimestampIn); outLen = bacapp_decode_context_timestamp(buffer, 2, &testTimestampOut); ct_test(pTest, inLen == outLen); ct_test(pTest, testTimestampIn.tag == testTimestampOut.tag); - ct_test(pTest, - testTimestampIn.value.sequenceNum == - testTimestampOut.value.sequenceNum); + ct_test(pTest, testTimestampIn.value.sequenceNum == + testTimestampOut.value.sequenceNum); } -void testTimestampTime( - Test * pTest) +void testTimestampTime(Test *pTest) { BACNET_TIMESTAMP testTimestampIn; BACNET_TIMESTAMP testTimestampOut; @@ -277,25 +252,22 @@ void testTimestampTime( memset(&testTimestampOut, 0, sizeof(testTimestampOut)); - inLen = bacapp_encode_context_timestamp(buffer, 2, &testTimestampIn); outLen = bacapp_decode_context_timestamp(buffer, 2, &testTimestampOut); ct_test(pTest, inLen == outLen); ct_test(pTest, testTimestampIn.tag == testTimestampOut.tag); + ct_test(pTest, testTimestampIn.value.time.hour == + testTimestampOut.value.time.hour); ct_test(pTest, - testTimestampIn.value.time.hour == testTimestampOut.value.time.hour); + testTimestampIn.value.time.min == testTimestampOut.value.time.min); ct_test(pTest, - testTimestampIn.value.time.min == testTimestampOut.value.time.min); - ct_test(pTest, - testTimestampIn.value.time.sec == testTimestampOut.value.time.sec); - ct_test(pTest, - testTimestampIn.value.time.hundredths == - testTimestampOut.value.time.hundredths); + testTimestampIn.value.time.sec == testTimestampOut.value.time.sec); + ct_test(pTest, testTimestampIn.value.time.hundredths == + testTimestampOut.value.time.hundredths); } -void testTimestampTimeDate( - Test * pTest) +void testTimestampTimeDate(Test *pTest) { BACNET_TIMESTAMP testTimestampIn; BACNET_TIMESTAMP testTimestampOut; @@ -321,38 +293,28 @@ void testTimestampTimeDate( ct_test(pTest, inLen == outLen); ct_test(pTest, testTimestampIn.tag == testTimestampOut.tag); - ct_test(pTest, - testTimestampIn.value.dateTime.time.hour == - testTimestampOut.value.dateTime.time.hour); - ct_test(pTest, - testTimestampIn.value.dateTime.time.min == - testTimestampOut.value.dateTime.time.min); - ct_test(pTest, - testTimestampIn.value.dateTime.time.sec == - testTimestampOut.value.dateTime.time.sec); - ct_test(pTest, - testTimestampIn.value.dateTime.time.hundredths == - testTimestampOut.value.dateTime.time.hundredths); - - ct_test(pTest, - testTimestampIn.value.dateTime.date.year == - testTimestampOut.value.dateTime.date.year); - ct_test(pTest, - testTimestampIn.value.dateTime.date.month == - testTimestampOut.value.dateTime.date.month); - ct_test(pTest, - testTimestampIn.value.dateTime.date.wday == - testTimestampOut.value.dateTime.date.wday); - ct_test(pTest, - testTimestampIn.value.dateTime.date.day == - testTimestampOut.value.dateTime.date.day); + ct_test(pTest, testTimestampIn.value.dateTime.time.hour == + testTimestampOut.value.dateTime.time.hour); + ct_test(pTest, testTimestampIn.value.dateTime.time.min == + testTimestampOut.value.dateTime.time.min); + ct_test(pTest, testTimestampIn.value.dateTime.time.sec == + testTimestampOut.value.dateTime.time.sec); + ct_test(pTest, testTimestampIn.value.dateTime.time.hundredths == + testTimestampOut.value.dateTime.time.hundredths); + ct_test(pTest, testTimestampIn.value.dateTime.date.year == + testTimestampOut.value.dateTime.date.year); + ct_test(pTest, testTimestampIn.value.dateTime.date.month == + testTimestampOut.value.dateTime.date.month); + ct_test(pTest, testTimestampIn.value.dateTime.date.wday == + testTimestampOut.value.dateTime.date.wday); + ct_test(pTest, testTimestampIn.value.dateTime.date.day == + testTimestampOut.value.dateTime.date.day); } #ifdef TEST_TIME_STAMP -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -370,7 +332,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/src/timesync.c b/src/timesync.c index 32b9e212..59a8f42e 100644 --- a/src/timesync.c +++ b/src/timesync.c @@ -41,14 +41,12 @@ /** @file timesync.c Encode/Decode TimeSync APDUs */ #if BACNET_SVC_TS_A /* encode service */ -int timesync_encode_apdu_service( - uint8_t * apdu, - BACNET_UNCONFIRMED_SERVICE service, - BACNET_DATE * my_date, - BACNET_TIME * my_time) +int timesync_encode_apdu_service(uint8_t *apdu, + BACNET_UNCONFIRMED_SERVICE service, + BACNET_DATE *my_date, BACNET_TIME *my_time) { - int len = 0; /* length of each encoding */ - int apdu_len = 0; /* total length of the apdu, return value */ + int len = 0; /* length of each encoding */ + int apdu_len = 0; /* total length of the apdu, return value */ if (apdu && my_date && my_time) { apdu[0] = PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST; @@ -63,31 +61,24 @@ int timesync_encode_apdu_service( return apdu_len; } -int timesync_utc_encode_apdu( - uint8_t * apdu, - BACNET_DATE * my_date, - BACNET_TIME * my_time) +int timesync_utc_encode_apdu(uint8_t *apdu, BACNET_DATE *my_date, + BACNET_TIME *my_time) { - return timesync_encode_apdu_service(apdu, - SERVICE_UNCONFIRMED_UTC_TIME_SYNCHRONIZATION, my_date, my_time); + return timesync_encode_apdu_service( + apdu, SERVICE_UNCONFIRMED_UTC_TIME_SYNCHRONIZATION, my_date, my_time); } -int timesync_encode_apdu( - uint8_t * apdu, - BACNET_DATE * my_date, - BACNET_TIME * my_time) +int timesync_encode_apdu(uint8_t *apdu, BACNET_DATE *my_date, + BACNET_TIME *my_time) { - return timesync_encode_apdu_service(apdu, - SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION, my_date, my_time); + return timesync_encode_apdu_service( + apdu, SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION, my_date, my_time); } #endif /* decode the service request only */ -int timesync_decode_service_request( - uint8_t * apdu, - unsigned apdu_len, - BACNET_DATE * my_date, - BACNET_TIME * my_time) +int timesync_decode_service_request(uint8_t *apdu, unsigned apdu_len, + BACNET_DATE *my_date, BACNET_TIME *my_time) { int len = 0; uint8_t tag_number = 0; @@ -95,15 +86,13 @@ int timesync_decode_service_request( if (apdu_len && my_date && my_time) { /* date */ - len += - decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); if (tag_number == BACNET_APPLICATION_TAG_DATE) { len += decode_date(&apdu[len], my_date); } else return -1; /* time */ - len += - decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); if (tag_number == BACNET_APPLICATION_TAG_TIME) { len += decode_bacnet_time(&apdu[len], my_time); } else @@ -137,10 +126,8 @@ int timesync_decode_service_request( * @return How many bytes were encoded in the buffer, or * BACNET_STATUS_ABORT if the response would not fit within the buffer. */ -int timesync_encode_timesync_recipients( - uint8_t * apdu, - unsigned max_apdu, - BACNET_RECIPIENT_LIST * recipient) +int timesync_encode_timesync_recipients(uint8_t *apdu, unsigned max_apdu, + BACNET_RECIPIENT_LIST *recipient) { int len = 0; int apdu_len = 0; @@ -152,9 +139,8 @@ int timesync_encode_timesync_recipients( if (pRecipient->tag == 0) { if (max_apdu >= (1 + 4)) { /* CHOICE - device [0] BACnetObjectIdentifier */ - len = - encode_context_object_id(&apdu[apdu_len], 0, - (int)pRecipient->type.device.type, + len = encode_context_object_id( + &apdu[apdu_len], 0, (int)pRecipient->type.device.type, pRecipient->type.device.instance); apdu_len += len; } else { @@ -164,8 +150,7 @@ int timesync_encode_timesync_recipients( if (pRecipient->type.address.net) { len = (int)(1 + 3 + 2 + pRecipient->type.address.len + 1); } else { - len = - (int)(1 + 3 + 2 + pRecipient->type.address.mac_len + 1); + len = (int)(1 + 3 + 2 + pRecipient->type.address.mac_len + 1); } if (max_apdu >= (unsigned)len) { /* CHOICE - address [1] BACnetAddress - opening */ @@ -173,9 +158,8 @@ int timesync_encode_timesync_recipients( apdu_len += len; /* network-number Unsigned16, */ /* -- A value of 0 indicates the local network */ - len = - encode_application_unsigned(&apdu[apdu_len], - pRecipient->type.address.net); + len = encode_application_unsigned(&apdu[apdu_len], + pRecipient->type.address.net); apdu_len += len; /* mac-address OCTET STRING */ /* -- A string of length 0 indicates a broadcast */ @@ -183,16 +167,15 @@ int timesync_encode_timesync_recipients( octetstring_init(&octet_string, NULL, 0); } else if (pRecipient->type.address.net) { octetstring_init(&octet_string, - &pRecipient->type.address.adr[0], - pRecipient->type.address.len); + &pRecipient->type.address.adr[0], + pRecipient->type.address.len); } else { octetstring_init(&octet_string, - &pRecipient->type.address.mac[0], - pRecipient->type.address.mac_len); + &pRecipient->type.address.mac[0], + pRecipient->type.address.mac_len); } - len = - encode_application_octet_string(&apdu[apdu_len], - &octet_string); + len = encode_application_octet_string(&apdu[apdu_len], + &octet_string); apdu_len += len; /* CHOICE - address [1] BACnetAddress - closing */ len = encode_closing_tag(&apdu[apdu_len], 1); @@ -231,10 +214,8 @@ int timesync_encode_timesync_recipients( * @return How many bytes were decoded from the buffer, or * BACNET_STATUS_ABORT if there was a problem decoding the buffer */ -int timesync_decode_timesync_recipients( - uint8_t * apdu, - unsigned max_apdu, - BACNET_RECIPIENT_LIST * recipient) +int timesync_decode_timesync_recipients(uint8_t *apdu, unsigned max_apdu, + BACNET_RECIPIENT_LIST *recipient) { int len = 0; int apdu_len = 0; @@ -250,10 +231,9 @@ int timesync_decode_timesync_recipients( /* device [0] BACnetObjectIdentifier */ if (decode_is_context_tag(&apdu[apdu_len], 0)) { pRecipient->tag = 0; - len = - decode_context_object_id(&apdu[apdu_len], 0, - &pRecipient->type.device.type, - &pRecipient->type.device.instance); + len = decode_context_object_id(&apdu[apdu_len], 0, + &pRecipient->type.device.type, + &pRecipient->type.device.instance); if (len < 0) { return BACNET_STATUS_ABORT; } @@ -262,22 +242,19 @@ int timesync_decode_timesync_recipients( apdu_len += 1; pRecipient->tag = 1; /* network-number Unsigned16 */ - tag_len = - decode_tag_number_and_value(&apdu[apdu_len], &tag_number, - &len_value_type); + tag_len = decode_tag_number_and_value(&apdu[apdu_len], &tag_number, + &len_value_type); apdu_len += tag_len; if (tag_number != BACNET_APPLICATION_TAG_UNSIGNED_INT) { return BACNET_STATUS_ABORT; } - len = - decode_unsigned(&apdu[apdu_len], len_value_type, - &unsigned_value); + len = decode_unsigned(&apdu[apdu_len], len_value_type, + &unsigned_value); pRecipient->type.address.net = unsigned_value; apdu_len += len; /* mac-address OCTET STRING */ - tag_len = - decode_tag_number_and_value(&apdu[apdu_len], &tag_number, - &len_value_type); + tag_len = decode_tag_number_and_value(&apdu[apdu_len], &tag_number, + &len_value_type); apdu_len += tag_len; if (tag_number != BACNET_APPLICATION_TAG_OCTET_STRING) { return BACNET_STATUS_ABORT; @@ -287,12 +264,12 @@ int timesync_decode_timesync_recipients( if (octetstring_length(&octet_string) == 0) { /* -- A string of length 0 indicates a broadcast */ } else if (pRecipient->type.address.net) { - pRecipient->type.address.len = - octetstring_copy_value(&pRecipient->type.address.adr[0], + pRecipient->type.address.len = octetstring_copy_value( + &pRecipient->type.address.adr[0], sizeof(pRecipient->type.address.adr), &octet_string); } else { - pRecipient->type.address.mac_len = - octetstring_copy_value(&pRecipient->type.address.mac[0], + pRecipient->type.address.mac_len = octetstring_copy_value( + &pRecipient->type.address.mac[0], sizeof(pRecipient->type.address.mac), &octet_string); } } else { @@ -304,51 +281,42 @@ int timesync_decode_timesync_recipients( return apdu_len; } - #ifdef TEST #include #include #include "ctest.h" -void testTimeSyncRecipientData( - Test * pTest, - BACNET_RECIPIENT_LIST * recipient1, - BACNET_RECIPIENT_LIST * recipient2) +void testTimeSyncRecipientData(Test *pTest, BACNET_RECIPIENT_LIST *recipient1, + BACNET_RECIPIENT_LIST *recipient2) { unsigned i = 0; if (recipient1 && recipient2) { ct_test(pTest, recipient1->tag == recipient2->tag); if (recipient1->tag == 0) { - ct_test(pTest, - recipient1->type.device.type == recipient2->type.device.type); - ct_test(pTest, - recipient1->type.device.instance == - recipient2->type.device.instance); + ct_test(pTest, recipient1->type.device.type == + recipient2->type.device.type); + ct_test(pTest, recipient1->type.device.instance == + recipient2->type.device.instance); } else if (recipient1->tag == 1) { - ct_test(pTest, - recipient1->type.address.net == recipient2->type.address.net); + ct_test(pTest, recipient1->type.address.net == + recipient2->type.address.net); if (recipient1->type.address.net == BACNET_BROADCAST_NETWORK) { - ct_test(pTest, - recipient1->type.address.mac_len == - recipient2->type.address.mac_len); + ct_test(pTest, recipient1->type.address.mac_len == + recipient2->type.address.mac_len); } else if (recipient1->type.address.net) { - ct_test(pTest, - recipient1->type.address.len == - recipient2->type.address.len); + ct_test(pTest, recipient1->type.address.len == + recipient2->type.address.len); for (i = 0; i < recipient1->type.address.len; i++) { - ct_test(pTest, - recipient1->type.address.adr[i] == - recipient2->type.address.adr[i]); + ct_test(pTest, recipient1->type.address.adr[i] == + recipient2->type.address.adr[i]); } } else { - ct_test(pTest, - recipient1->type.address.mac_len == - recipient2->type.address.mac_len); + ct_test(pTest, recipient1->type.address.mac_len == + recipient2->type.address.mac_len); for (i = 0; i < recipient1->type.address.mac_len; i++) { - ct_test(pTest, - recipient1->type.address.mac[i] == - recipient2->type.address.mac[i]); + ct_test(pTest, recipient1->type.address.mac[i] == + recipient2->type.address.mac[i]); } } } else { @@ -357,10 +325,9 @@ void testTimeSyncRecipientData( } } -void testTimeSyncRecipient( - Test * pTest) +void testTimeSyncRecipient(Test *pTest) { - uint8_t apdu[480] = { 0 }; + uint8_t apdu[480] = {0}; int len = 0; BACNET_RECIPIENT_LIST recipient[4]; BACNET_RECIPIENT_LIST test_recipient[4]; @@ -399,25 +366,21 @@ void testTimeSyncRecipient( recipient[2].type.address.mac[5] = 0xC1; recipient[2].type.address.mac_len = 6; /* perform positive test */ - len = - timesync_encode_timesync_recipients(&apdu[0], sizeof(apdu), - &recipient[0]); + len = timesync_encode_timesync_recipients(&apdu[0], sizeof(apdu), + &recipient[0]); ct_test(pTest, len != BACNET_STATUS_ABORT); ct_test(pTest, len > 0); - len = - timesync_decode_timesync_recipients(&apdu[0], sizeof(apdu), - &test_recipient[0]); + len = timesync_decode_timesync_recipients(&apdu[0], sizeof(apdu), + &test_recipient[0]); ct_test(pTest, len != BACNET_STATUS_ABORT); ct_test(pTest, len > 0); testTimeSyncRecipientData(pTest, &recipient[0], &test_recipient[0]); } -int timesync_decode_apdu_service( - uint8_t * apdu, - BACNET_UNCONFIRMED_SERVICE service, - unsigned apdu_len, - BACNET_DATE * my_date, - BACNET_TIME * my_time) +int timesync_decode_apdu_service(uint8_t *apdu, + BACNET_UNCONFIRMED_SERVICE service, + unsigned apdu_len, BACNET_DATE *my_date, + BACNET_TIME *my_time) { int len = 0; @@ -430,41 +393,32 @@ int timesync_decode_apdu_service( return -1; /* optional limits - must be used as a pair */ if (apdu_len > 2) { - len = - timesync_decode_service_request(&apdu[2], apdu_len - 2, my_date, - my_time); + len = timesync_decode_service_request(&apdu[2], apdu_len - 2, my_date, + my_time); } return len; } -int timesync_utc_decode_apdu( - uint8_t * apdu, - unsigned apdu_len, - BACNET_DATE * my_date, - BACNET_TIME * my_time) +int timesync_utc_decode_apdu(uint8_t *apdu, unsigned apdu_len, + BACNET_DATE *my_date, BACNET_TIME *my_time) { - return timesync_decode_apdu_service(apdu, - SERVICE_UNCONFIRMED_UTC_TIME_SYNCHRONIZATION, apdu_len, my_date, + return timesync_decode_apdu_service( + apdu, SERVICE_UNCONFIRMED_UTC_TIME_SYNCHRONIZATION, apdu_len, my_date, my_time); } -int timesync_decode_apdu( - uint8_t * apdu, - unsigned apdu_len, - BACNET_DATE * my_date, - BACNET_TIME * my_time) +int timesync_decode_apdu(uint8_t *apdu, unsigned apdu_len, BACNET_DATE *my_date, + BACNET_TIME *my_time) { - return timesync_decode_apdu_service(apdu, - SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION, apdu_len, my_date, my_time); + return timesync_decode_apdu_service( + apdu, SERVICE_UNCONFIRMED_TIME_SYNCHRONIZATION, apdu_len, my_date, + my_time); } -void testTimeSyncData( - Test * pTest, - BACNET_DATE * my_date, - BACNET_TIME * my_time) +void testTimeSyncData(Test *pTest, BACNET_DATE *my_date, BACNET_TIME *my_time) { - uint8_t apdu[480] = { 0 }; + uint8_t apdu[480] = {0}; int len = 0; int apdu_len = 0; BACNET_DATE test_date; @@ -487,16 +441,15 @@ void testTimeSyncData( ct_test(pTest, datetime_compare_date(my_date, &test_date) == 0); } -void testTimeSync( - Test * pTest) +void testTimeSync(Test *pTest) { BACNET_DATE bdate; BACNET_TIME btime; - bdate.year = 2006; /* AD */ - bdate.month = 4; /* 1=Jan */ - bdate.day = 11; /* 1..31 */ - bdate.wday = 1; /* 1=Monday */ + bdate.year = 2006; /* AD */ + bdate.month = 4; /* 1=Jan */ + bdate.day = 11; /* 1..31 */ + bdate.wday = 1; /* 1=Monday */ btime.hour = 7; btime.min = 0; @@ -507,8 +460,7 @@ void testTimeSync( } #ifdef TEST_TIMESYNC -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -520,7 +472,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/src/tsm.c b/src/tsm.c index 264257c8..cde2d66d 100644 --- a/src/tsm.c +++ b/src/tsm.c @@ -66,22 +66,20 @@ static uint8_t Current_Invoke_ID = 1; static tsm_timeout_function Timeout_Function; -void tsm_set_timeout_handler( - tsm_timeout_function pFunction) +void tsm_set_timeout_handler(tsm_timeout_function pFunction) { Timeout_Function = pFunction; } /* returns MAX_TSM_TRANSACTIONS if not found */ -static uint8_t tsm_find_invokeID_index( - uint8_t invokeID) +static uint8_t tsm_find_invokeID_index(uint8_t invokeID) { - unsigned i = 0; /* counter */ - uint8_t index = MAX_TSM_TRANSACTIONS; /* return value */ + unsigned i = 0; /* counter */ + uint8_t index = MAX_TSM_TRANSACTIONS; /* return value */ for (i = 0; i < MAX_TSM_TRANSACTIONS; i++) { if (TSM_List[i].InvokeID == invokeID) { - index = (uint8_t) i; + index = (uint8_t)i; break; } } @@ -89,15 +87,14 @@ static uint8_t tsm_find_invokeID_index( return index; } -static uint8_t tsm_find_first_free_index( - void) +static uint8_t tsm_find_first_free_index(void) { - unsigned i = 0; /* counter */ - uint8_t index = MAX_TSM_TRANSACTIONS; /* return value */ + unsigned i = 0; /* counter */ + uint8_t index = MAX_TSM_TRANSACTIONS; /* return value */ for (i = 0; i < MAX_TSM_TRANSACTIONS; i++) { if (TSM_List[i].InvokeID == 0) { - index = (uint8_t) i; + index = (uint8_t)i; break; } } @@ -105,11 +102,10 @@ static uint8_t tsm_find_first_free_index( return index; } -bool tsm_transaction_available( - void) +bool tsm_transaction_available(void) { - bool status = false; /* return value */ - unsigned i = 0; /* counter */ + bool status = false; /* return value */ + unsigned i = 0; /* counter */ for (i = 0; i < MAX_TSM_TRANSACTIONS; i++) { if (TSM_List[i].InvokeID == 0) { @@ -122,11 +118,10 @@ bool tsm_transaction_available( return status; } -uint8_t tsm_transaction_idle_count( - void) +uint8_t tsm_transaction_idle_count(void) { - uint8_t count = 0; /* return value */ - unsigned i = 0; /* counter */ + uint8_t count = 0; /* return value */ + unsigned i = 0; /* counter */ for (i = 0; i < MAX_TSM_TRANSACTIONS; i++) { if ((TSM_List[i].InvokeID == 0) && @@ -141,8 +136,7 @@ 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; @@ -153,8 +147,7 @@ void tsm_invokeID_set( /* gets the next free invokeID, and reserves a spot in the table returns 0 if none are available */ -uint8_t tsm_next_free_invokeID( - void) +uint8_t tsm_next_free_invokeID(void) { uint8_t index = 0; uint8_t invokeID = 0; @@ -175,7 +168,8 @@ uint8_t tsm_next_free_invokeID( TSM_List[index].RequestTimer = apdu_timeout(); /* update for the next call or check */ Current_Invoke_ID++; - /* skip zero - we treat that internally as invalid or no free */ + /* skip zero - we treat that internally as invalid or no + * free */ if (Current_Invoke_ID == 0) { Current_Invoke_ID = 1; } @@ -195,12 +189,10 @@ uint8_t tsm_next_free_invokeID( return invokeID; } -void tsm_set_confirmed_unsegmented_transaction( - uint8_t invokeID, - BACNET_ADDRESS * dest, - BACNET_NPDU_DATA * ndpu_data, - uint8_t * apdu, - uint16_t apdu_len) +void tsm_set_confirmed_unsegmented_transaction(uint8_t invokeID, + BACNET_ADDRESS *dest, + BACNET_NPDU_DATA *ndpu_data, + uint8_t *apdu, uint16_t apdu_len) { uint16_t j = 0; uint8_t index; @@ -228,12 +220,9 @@ void tsm_set_confirmed_unsegmented_transaction( /* used to retrieve the transaction payload */ /* if we wanted to find out what we sent (i.e. when we get an ack) */ -bool tsm_get_transaction_pdu( - uint8_t invokeID, - BACNET_ADDRESS * dest, - BACNET_NPDU_DATA * ndpu_data, - uint8_t * apdu, - uint16_t * apdu_len) +bool tsm_get_transaction_pdu(uint8_t invokeID, BACNET_ADDRESS *dest, + BACNET_NPDU_DATA *ndpu_data, uint8_t *apdu, + uint16_t *apdu_len) { uint16_t j = 0; uint8_t index; @@ -243,10 +232,11 @@ bool tsm_get_transaction_pdu( index = tsm_find_invokeID_index(invokeID); /* how much checking is needed? state? dest match? just invokeID? */ if (index < MAX_TSM_TRANSACTIONS) { - /* FIXME: we may want to free the transaction so it doesn't timeout */ + /* FIXME: we may want to free the transaction so it doesn't timeout + */ /* retrieve the transaction */ /* FIXME: bounds check the pdu_len? */ - *apdu_len = (uint16_t) TSM_List[index].apdu_len; + *apdu_len = (uint16_t)TSM_List[index].apdu_len; for (j = 0; j < *apdu_len; j++) { apdu[j] = TSM_List[index].apdu[j]; } @@ -260,10 +250,9 @@ bool tsm_get_transaction_pdu( } /* called once a millisecond or slower */ -void tsm_timer_milliseconds( - uint16_t milliseconds) +void tsm_timer_milliseconds(uint16_t milliseconds) { - unsigned i = 0; /* counter */ + unsigned i = 0; /* counter */ for (i = 0; i < MAX_TSM_TRANSACTIONS; i++) { if (TSM_List[i].state == TSM_STATE_AWAIT_CONFIRMATION) { @@ -276,9 +265,9 @@ void tsm_timer_milliseconds( if (TSM_List[i].RetryCount < apdu_retries()) { TSM_List[i].RequestTimer = apdu_timeout(); TSM_List[i].RetryCount++; - datalink_send_pdu(&TSM_List[i].dest, - &TSM_List[i].npdu_data, &TSM_List[i].apdu[0], - TSM_List[i].apdu_len); + datalink_send_pdu(&TSM_List[i].dest, &TSM_List[i].npdu_data, + &TSM_List[i].apdu[0], + TSM_List[i].apdu_len); } else { /* note: the invoke id has not been cleared yet and this indicates a failed message: @@ -296,8 +285,7 @@ void tsm_timer_milliseconds( } /* frees the invokeID and sets its state to IDLE */ -void tsm_free_invoke_id( - uint8_t invokeID) +void tsm_free_invoke_id(uint8_t invokeID) { uint8_t index; @@ -309,11 +297,11 @@ void tsm_free_invoke_id( } /** Check if the invoke ID has been made free by the Transaction State Machine. - * @param invokeID [in] The invokeID to be checked, normally of last message sent. + * @param invokeID [in] The invokeID to be checked, normally of last message + * sent. * @return True if it is free (done with), False if still pending in the TSM. */ -bool tsm_invoke_id_free( - uint8_t invokeID) +bool tsm_invoke_id_free(uint8_t invokeID) { bool status = true; uint8_t index; @@ -327,12 +315,12 @@ bool tsm_invoke_id_free( /** See if we failed get a confirmation for the message associated * with this invoke ID. - * @param invokeID [in] The invokeID to be checked, normally of last message sent. + * @param invokeID [in] The invokeID to be checked, normally of last message + * sent. * @return True if already failed, False if done or segmented or still waiting * for a confirmation. */ -bool tsm_invoke_id_failed( - uint8_t invokeID) +bool tsm_invoke_id_failed(uint8_t invokeID) { bool status = false; uint8_t index; @@ -348,7 +336,6 @@ bool tsm_invoke_id_failed( return status; } - #ifdef TEST #include #include @@ -358,37 +345,31 @@ bool tsm_invoke_id_failed( bool I_Am_Request = true; /* dummy function stubs */ -int datalink_send_pdu( - BACNET_ADDRESS * dest, - BACNET_NPDU_DATA * npdu_data, - uint8_t * pdu, - unsigned pdu_len) +int datalink_send_pdu(BACNET_ADDRESS *dest, BACNET_NPDU_DATA *npdu_data, + uint8_t *pdu, unsigned pdu_len) { - (void) dest; - (void) npdu_data; - (void) pdu; - (void) pdu_len; + (void)dest; + (void)npdu_data; + (void)pdu; + (void)pdu_len; return 0; } /* dummy function stubs */ -void datalink_get_broadcast_address( - BACNET_ADDRESS * dest) +void datalink_get_broadcast_address(BACNET_ADDRESS *dest) { - (void) dest; + (void)dest; } -void testTSM( - Test * pTest) +void testTSM(Test *pTest) { /* FIXME: add some unit testing... */ return; } #ifdef TEST_TSM -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -400,7 +381,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/src/ucix.c b/src/ucix.c index 26a9b2ec..21d37c53 100644 --- a/src/ucix.c +++ b/src/ucix.c @@ -13,7 +13,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. * - * Copyright (C) 2008 John Crispin + * Copyright (C) 2008 John Crispin */ #include @@ -27,12 +27,8 @@ static struct uci_ptr ptr; -static inline int ucix_get_ptr( - struct uci_context *ctx, - const char *p, - const char *s, - const char *o, - const char *t) +static inline int ucix_get_ptr(struct uci_context *ctx, const char *p, + const char *s, const char *o, const char *t) { memset(&ptr, 0, sizeof(ptr)); ptr.package = p; @@ -42,60 +38,51 @@ static inline int ucix_get_ptr( return uci_lookup_ptr(ctx, &ptr, NULL, true); } -struct uci_context *ucix_init( - const char *config_file) +struct uci_context *ucix_init(const char *config_file) { struct uci_context *ctx = uci_alloc_context(); -/* uci_add_history_path(ctx, "/var/state"); */ + /* uci_add_history_path(ctx, "/var/state"); */ uci_add_delta_path(ctx, "/var/state"); if (uci_load(ctx, config_file, NULL) != UCI_OK) { fprintf(stderr, "%s/%s is missing or corrupt\n", ctx->savedir, - config_file); + config_file); return NULL; } return ctx; } -struct uci_context *ucix_init_path( - const char *path, - const char *config_file) +struct uci_context *ucix_init_path(const char *path, const char *config_file) { struct uci_context *ctx = uci_alloc_context(); if (path) uci_set_confdir(ctx, path); if (uci_load(ctx, config_file, NULL) != UCI_OK) { fprintf(stderr, "%s/%s is missing or corrupt\n", ctx->savedir, - config_file); + config_file); return NULL; } return ctx; } -void ucix_cleanup( - struct uci_context *ctx) +void ucix_cleanup(struct uci_context *ctx) { uci_free_context(ctx); } -void ucix_save( - struct uci_context *ctx) +void ucix_save(struct uci_context *ctx) { uci_set_savedir(ctx, "/tmp/.uci/"); uci_save(ctx, NULL); } -void ucix_save_state( - struct uci_context *ctx) +void ucix_save_state(struct uci_context *ctx) { uci_set_savedir(ctx, "/var/state/"); uci_save(ctx, NULL); } -const char *ucix_get_option( - struct uci_context *ctx, - const char *p, - const char *s, - const char *o) +const char *ucix_get_option(struct uci_context *ctx, const char *p, + const char *s, const char *o) { struct uci_element *e = NULL; const char *value = NULL; @@ -125,12 +112,8 @@ const char *ucix_get_option( return value; } -int ucix_get_option_int( - struct uci_context *ctx, - const char *p, - const char *s, - const char *o, - int def) +int ucix_get_option_int(struct uci_context *ctx, const char *p, const char *s, + const char *o, int def) { const char *tmp = ucix_get_option(ctx, p, s, o); int ret = def; @@ -140,80 +123,57 @@ int ucix_get_option_int( return ret; } -void ucix_add_section( - struct uci_context *ctx, - const char *p, - const char *s, - const char *t) +void ucix_add_section(struct uci_context *ctx, const char *p, const char *s, + const char *t) { if (ucix_get_ptr(ctx, p, s, NULL, t)) return; uci_set(ctx, &ptr); } -void ucix_add_option( - struct uci_context *ctx, - const char *p, - const char *s, - const char *o, - const char *t) +void ucix_add_option(struct uci_context *ctx, const char *p, const char *s, + const char *o, const char *t) { if (ucix_get_ptr(ctx, p, s, o, (t) ? (t) : (""))) return; uci_set(ctx, &ptr); } -void ucix_add_option_int( - struct uci_context *ctx, - const char *p, - const char *s, - const char *o, - int t) +void ucix_add_option_int(struct uci_context *ctx, const char *p, const char *s, + const char *o, int t) { char tmp[64]; snprintf(tmp, 64, "%d", t); ucix_add_option(ctx, p, s, o, tmp); } -void ucix_del( - struct uci_context *ctx, - const char *p, - const char *s, - const char *o) +void ucix_del(struct uci_context *ctx, const char *p, const char *s, + const char *o) { if (!ucix_get_ptr(ctx, p, s, o, NULL)) uci_delete(ctx, &ptr); } -void ucix_revert( - struct uci_context *ctx, - const char *p, - const char *s, - const char *o) +void ucix_revert(struct uci_context *ctx, const char *p, const char *s, + const char *o) { if (!ucix_get_ptr(ctx, p, s, o, NULL)) uci_revert(ctx, &ptr); } -void ucix_for_each_section_type( - struct uci_context *ctx, - const char *p, - const char *t, - void (*cb) (const char *, - void *), - void *priv) +void ucix_for_each_section_type(struct uci_context *ctx, const char *p, + const char *t, void (*cb)(const char *, void *), + void *priv) { struct uci_element *e; if (ucix_get_ptr(ctx, p, NULL, NULL, NULL)) return; - uci_foreach_element(&ptr.p->sections, e) - if (!strcmp(t, uci_to_section(e)->type)) + uci_foreach_element(&ptr.p->sections, + e) if (!strcmp(t, uci_to_section(e)->type)) cb(e->name, priv); } -int ucix_commit( - struct uci_context *ctx, - const char *p) +int ucix_commit(struct uci_context *ctx, const char *p) { if (ucix_get_ptr(ctx, p, NULL, NULL, NULL)) return 1; diff --git a/src/vmac.c b/src/vmac.c index 13a3b0e2..f903473e 100644 --- a/src/vmac.c +++ b/src/vmac.c @@ -138,9 +138,7 @@ struct vmac_data *VMAC_Find_By_Key(uint32_t device_id) * * @return true if the addresses are different */ -bool VMAC_Different( - struct vmac_data *vmac1, - struct vmac_data *vmac2) +bool VMAC_Different(struct vmac_data *vmac1, struct vmac_data *vmac2) { bool status = false; unsigned int i = 0; @@ -171,9 +169,7 @@ bool VMAC_Different( * * @return true if the addresses are the same */ -bool VMAC_Match( - struct vmac_data *vmac1, - struct vmac_data *vmac2) +bool VMAC_Match(struct vmac_data *vmac1, struct vmac_data *vmac2) { bool status = false; unsigned int i = 0; @@ -268,8 +264,7 @@ void VMAC_Init(void) #include #include "ctest.h" -void testVMAC( - Test * pTest) +void testVMAC(Test *pTest) { uint32_t device_id = 123; uint32_t test_device_id = 0; @@ -304,8 +299,7 @@ void testVMAC( } #ifdef TEST_VMAC -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -317,7 +311,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/src/whohas.c b/src/whohas.c index 31487955..3190fc95 100644 --- a/src/whohas.c +++ b/src/whohas.c @@ -41,38 +41,33 @@ /* encode service - use -1 for limit for unlimited */ -int whohas_encode_apdu( - uint8_t * apdu, - BACNET_WHO_HAS_DATA * data) +int whohas_encode_apdu(uint8_t *apdu, BACNET_WHO_HAS_DATA *data) { - int len = 0; /* length of each encoding */ - int apdu_len = 0; /* total length of the apdu, return value */ + int len = 0; /* length of each encoding */ + int apdu_len = 0; /* total length of the apdu, return value */ if (apdu && data) { apdu[0] = PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST; - apdu[1] = SERVICE_UNCONFIRMED_WHO_HAS; /* service choice */ + apdu[1] = SERVICE_UNCONFIRMED_WHO_HAS; /* service choice */ apdu_len = 2; /* optional limits - must be used as a pair */ - if ((data->low_limit >= 0) - && (data->low_limit <= BACNET_MAX_INSTANCE) - && (data->high_limit >= 0) - && (data->high_limit <= BACNET_MAX_INSTANCE)) { + if ((data->low_limit >= 0) && + (data->low_limit <= BACNET_MAX_INSTANCE) && + (data->high_limit >= 0) && + (data->high_limit <= BACNET_MAX_INSTANCE)) { len = encode_context_unsigned(&apdu[apdu_len], 0, data->low_limit); apdu_len += len; - len = - encode_context_unsigned(&apdu[apdu_len], 1, data->high_limit); + len = encode_context_unsigned(&apdu[apdu_len], 1, data->high_limit); apdu_len += len; } if (data->is_object_name) { - len = - encode_context_character_string(&apdu[apdu_len], 3, - &data->object.name); + len = encode_context_character_string(&apdu[apdu_len], 3, + &data->object.name); apdu_len += len; } else { - len = - encode_context_object_id(&apdu[apdu_len], 2, - (int) data->object.identifier.type, - data->object.identifier.instance); + len = encode_context_object_id(&apdu[apdu_len], 2, + (int)data->object.identifier.type, + data->object.identifier.instance); apdu_len += len; } } @@ -81,10 +76,8 @@ int whohas_encode_apdu( } /* decode the service request only */ -int whohas_decode_service_request( - uint8_t * apdu, - unsigned apdu_len, - BACNET_WHO_HAS_DATA * data) +int whohas_decode_service_request(uint8_t *apdu, unsigned apdu_len, + BACNET_WHO_HAS_DATA *data) { int len = 0; uint8_t tag_number = 0; @@ -95,17 +88,15 @@ int whohas_decode_service_request( if (apdu_len && data) { /* optional limits - must be used as a pair */ if (decode_is_context_tag(&apdu[len], 0)) { - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value); len += decode_unsigned(&apdu[len], len_value, &decoded_value); if (decoded_value <= BACNET_MAX_INSTANCE) data->low_limit = decoded_value; if (!decode_is_context_tag(&apdu[len], 1)) return -1; - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value); len += decode_unsigned(&apdu[len], len_value, &decoded_value); if (decoded_value <= BACNET_MAX_INSTANCE) data->high_limit = decoded_value; @@ -116,23 +107,19 @@ int whohas_decode_service_request( /* object id */ if (decode_is_context_tag(&apdu[len], 2)) { data->is_object_name = false; - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value); - len += - decode_object_id(&apdu[len], &decoded_type, - &data->object.identifier.instance); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value); + len += decode_object_id(&apdu[len], &decoded_type, + &data->object.identifier.instance); data->object.identifier.type = decoded_type; } /* object name */ else if (decode_is_context_tag(&apdu[len], 3)) { data->is_object_name = true; - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value); - len += - decode_character_string(&apdu[len], len_value, - &data->object.name); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value); + len += decode_character_string(&apdu[len], len_value, + &data->object.name); } /* missing required parameters */ else @@ -147,10 +134,8 @@ int whohas_decode_service_request( #include #include "ctest.h" -int whohas_decode_apdu( - uint8_t * apdu, - unsigned apdu_len, - BACNET_WHO_HAS_DATA * data) +int whohas_decode_apdu(uint8_t *apdu, unsigned apdu_len, + BACNET_WHO_HAS_DATA *data) { int len = 0; @@ -169,11 +154,9 @@ int whohas_decode_apdu( return len; } -void testWhoHasData( - Test * pTest, - BACNET_WHO_HAS_DATA * data) +void testWhoHasData(Test *pTest, BACNET_WHO_HAS_DATA *data) { - uint8_t apdu[480] = { 0 }; + uint8_t apdu[480] = {0}; int len = 0; int apdu_len = 0; BACNET_WHO_HAS_DATA test_data; @@ -189,21 +172,19 @@ void testWhoHasData( ct_test(pTest, test_data.is_object_name == data->is_object_name); /* Object ID */ if (data->is_object_name == false) { - ct_test(pTest, - test_data.object.identifier.type == data->object.identifier.type); - ct_test(pTest, - test_data.object.identifier.instance == - data->object.identifier.instance); + ct_test(pTest, test_data.object.identifier.type == + data->object.identifier.type); + ct_test(pTest, test_data.object.identifier.instance == + data->object.identifier.instance); } /* Object Name */ else { ct_test(pTest, characterstring_same(&test_data.object.name, - &data->object.name)); + &data->object.name)); } } -void testWhoHas( - Test * pTest) +void testWhoHas(Test *pTest) { BACNET_WHO_HAS_DATA data; @@ -215,16 +196,16 @@ void testWhoHas( testWhoHasData(pTest, &data); for (data.low_limit = 0; data.low_limit <= BACNET_MAX_INSTANCE; - data.low_limit += (BACNET_MAX_INSTANCE / 4)) { + data.low_limit += (BACNET_MAX_INSTANCE / 4)) { for (data.high_limit = 0; data.high_limit <= BACNET_MAX_INSTANCE; - data.high_limit += (BACNET_MAX_INSTANCE / 4)) { + data.high_limit += (BACNET_MAX_INSTANCE / 4)) { data.is_object_name = false; for (data.object.identifier.type = OBJECT_ANALOG_INPUT; - data.object.identifier.type < MAX_BACNET_OBJECT_TYPE; - data.object.identifier.type++) { + data.object.identifier.type < MAX_BACNET_OBJECT_TYPE; + data.object.identifier.type++) { for (data.object.identifier.instance = 1; - data.object.identifier.instance <= BACNET_MAX_INSTANCE; - data.object.identifier.instance <<= 1) { + data.object.identifier.instance <= BACNET_MAX_INSTANCE; + data.object.identifier.instance <<= 1) { testWhoHasData(pTest, &data); } } @@ -236,8 +217,7 @@ void testWhoHas( } #ifdef TEST_WHOHAS -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -249,7 +229,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/src/whois.c b/src/whois.c index 6323e173..8246e913 100644 --- a/src/whois.c +++ b/src/whois.c @@ -40,17 +40,14 @@ /** @file whois.c Encode/Decode Who-Is requests */ /* encode I-Am service - use -1 for limit if you want unlimited */ -int whois_encode_apdu( - uint8_t * apdu, - int32_t low_limit, - int32_t high_limit) +int whois_encode_apdu(uint8_t *apdu, int32_t low_limit, int32_t high_limit) { - int len = 0; /* length of each encoding */ - int apdu_len = 0; /* total length of the apdu, return value */ + int len = 0; /* length of each encoding */ + int apdu_len = 0; /* total length of the apdu, return value */ if (apdu) { apdu[0] = PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST; - apdu[1] = SERVICE_UNCONFIRMED_WHO_IS; /* service choice */ + apdu[1] = SERVICE_UNCONFIRMED_WHO_IS; /* service choice */ apdu_len = 2; /* optional limits - must be used as a pair */ if ((low_limit >= 0) && (low_limit <= BACNET_MAX_INSTANCE) && @@ -66,11 +63,8 @@ int whois_encode_apdu( } /* decode the service request only */ -int whois_decode_service_request( - uint8_t * apdu, - unsigned apdu_len, - int32_t * pLow_limit, - int32_t * pHigh_limit) +int whois_decode_service_request(uint8_t *apdu, unsigned apdu_len, + int32_t *pLow_limit, int32_t *pHigh_limit) { unsigned int len = 0; uint8_t tag_number = 0; @@ -79,8 +73,7 @@ int whois_decode_service_request( /* optional limits - must be used as a pair */ if (apdu_len) { - len += - decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); if (tag_number != 0) { return BACNET_STATUS_ERROR; } @@ -92,13 +85,14 @@ int whois_decode_service_request( } } if (apdu_len > (unsigned)len) { - len += - decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value); if (tag_number != 1) { return BACNET_STATUS_ERROR; } if (apdu_len > (unsigned)len) { - len += decode_unsigned(&apdu[len], len_value, &decoded_value); + len += + decode_unsigned(&apdu[len], len_value, &decoded_value); if (decoded_value <= BACNET_MAX_INSTANCE) { if (pHigh_limit) { *pHigh_limit = decoded_value; @@ -131,11 +125,8 @@ int whois_decode_service_request( #include #include "ctest.h" -int whois_decode_apdu( - uint8_t * apdu, - unsigned apdu_len, - int32_t * pLow_limit, - int32_t * pHigh_limit) +int whois_decode_apdu(uint8_t *apdu, unsigned apdu_len, int32_t *pLow_limit, + int32_t *pHigh_limit) { int len = 0; @@ -144,25 +135,24 @@ int whois_decode_apdu( } /* optional limits - must be used as a pair */ if (apdu_len >= 2) { - /* optional checking - most likely was already done prior to this call */ + /* optional checking - most likely was already done prior to this call + */ if (apdu[0] != PDU_TYPE_UNCONFIRMED_SERVICE_REQUEST) { return BACNET_STATUS_ERROR; } if (apdu[1] != SERVICE_UNCONFIRMED_WHO_IS) { return BACNET_STATUS_ERROR; } - len = - whois_decode_service_request(&apdu[2], apdu_len - 2, pLow_limit, - pHigh_limit); + len = whois_decode_service_request(&apdu[2], apdu_len - 2, pLow_limit, + pHigh_limit); } return len; } -void testWhoIs( - Test * pTest) +void testWhoIs(Test *pTest) { - uint8_t apdu[480] = { 0 }; + uint8_t apdu[480] = {0}; int len = 0; int apdu_len = 0; int32_t low_limit = -1; @@ -175,24 +165,22 @@ void testWhoIs( ct_test(pTest, len > 0); apdu_len = len; - len = - whois_decode_apdu(&apdu[0], apdu_len, &test_low_limit, - &test_high_limit); + len = whois_decode_apdu(&apdu[0], apdu_len, &test_low_limit, + &test_high_limit); ct_test(pTest, len != BACNET_STATUS_ERROR); ct_test(pTest, test_low_limit == low_limit); ct_test(pTest, test_high_limit == high_limit); /* normal who-is with limits - complete range */ for (low_limit = 0; low_limit <= BACNET_MAX_INSTANCE; - low_limit += (BACNET_MAX_INSTANCE / 4)) { + low_limit += (BACNET_MAX_INSTANCE / 4)) { for (high_limit = 0; high_limit <= BACNET_MAX_INSTANCE; - high_limit += (BACNET_MAX_INSTANCE / 4)) { + high_limit += (BACNET_MAX_INSTANCE / 4)) { len = whois_encode_apdu(&apdu[0], low_limit, high_limit); apdu_len = len; ct_test(pTest, len > 0); - len = - whois_decode_apdu(&apdu[0], apdu_len, &test_low_limit, - &test_high_limit); + len = whois_decode_apdu(&apdu[0], apdu_len, &test_low_limit, + &test_high_limit); ct_test(pTest, len != BACNET_STATUS_ERROR); ct_test(pTest, test_low_limit == low_limit); ct_test(pTest, test_high_limit == high_limit); @@ -210,17 +198,15 @@ void testWhoIs( len = whois_encode_apdu(&apdu[0], low_limit, high_limit); ct_test(pTest, len > 0); apdu_len = len; - len = - whois_decode_apdu(&apdu[0], apdu_len, &test_low_limit, - &test_high_limit); + len = whois_decode_apdu(&apdu[0], apdu_len, &test_low_limit, + &test_high_limit); ct_test(pTest, len != BACNET_STATUS_ERROR); ct_test(pTest, test_low_limit == low_limit); ct_test(pTest, test_high_limit == high_limit); } #ifdef TEST_WHOIS -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -232,7 +218,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/src/wp.c b/src/wp.c index 1109ecfa..e253cffb 100644 --- a/src/wp.c +++ b/src/wp.c @@ -40,33 +40,28 @@ /** @file wp.c Encode/Decode BACnet Write Property APDUs */ #if BACNET_SVC_WP_A /* encode service */ -int wp_encode_apdu( - uint8_t * apdu, - uint8_t invoke_id, - BACNET_WRITE_PROPERTY_DATA * wpdata) +int wp_encode_apdu(uint8_t *apdu, uint8_t invoke_id, + BACNET_WRITE_PROPERTY_DATA *wpdata) { - int apdu_len = 0; /* total length of the apdu, return value */ - int len = 0; /* total length of the apdu, return value */ + int apdu_len = 0; /* total length of the apdu, return value */ + int len = 0; /* total length of the apdu, return value */ if (apdu) { apdu[0] = PDU_TYPE_CONFIRMED_SERVICE_REQUEST; apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU); apdu[2] = invoke_id; - apdu[3] = SERVICE_CONFIRMED_WRITE_PROPERTY; /* service choice */ + apdu[3] = SERVICE_CONFIRMED_WRITE_PROPERTY; /* service choice */ apdu_len = 4; - len = - encode_context_object_id(&apdu[apdu_len], 0, wpdata->object_type, - wpdata->object_instance); + len = encode_context_object_id(&apdu[apdu_len], 0, wpdata->object_type, + wpdata->object_instance); apdu_len += len; - len = - encode_context_enumerated(&apdu[apdu_len], 1, - wpdata->object_property); + len = encode_context_enumerated(&apdu[apdu_len], 1, + wpdata->object_property); apdu_len += len; /* optional array index; ALL is -1 which is assumed when missing */ if (wpdata->array_index != BACNET_ARRAY_ALL) { - len = - encode_context_unsigned(&apdu[apdu_len], 2, - wpdata->array_index); + len = encode_context_unsigned(&apdu[apdu_len], 2, + wpdata->array_index); apdu_len += len; } /* propertyValue */ @@ -80,8 +75,7 @@ int wp_encode_apdu( apdu_len += len; /* optional priority - 0 if not set, 1..16 if set */ if (wpdata->priority != BACNET_NO_PRIORITY) { - len = - encode_context_unsigned(&apdu[apdu_len], 4, wpdata->priority); + len = encode_context_unsigned(&apdu[apdu_len], 4, wpdata->priority); apdu_len += len; } } @@ -93,19 +87,17 @@ int wp_encode_apdu( /* decode the service request only */ /* FIXME: there could be various error messages returned using unique values less than zero */ -int wp_decode_service_request( - uint8_t * apdu, - unsigned apdu_len, - BACNET_WRITE_PROPERTY_DATA * wpdata) +int wp_decode_service_request(uint8_t *apdu, unsigned apdu_len, + BACNET_WRITE_PROPERTY_DATA *wpdata) { int len = 0; int tag_len = 0; uint8_t tag_number = 0; uint32_t len_value_type = 0; - uint16_t type = 0; /* for decoding */ - uint32_t property = 0; /* for decoding */ + uint16_t type = 0; /* for decoding */ + uint32_t property = 0; /* for decoding */ uint32_t unsigned_value = 0; - int i = 0; /* loop counter */ + int i = 0; /* loop counter */ /* check for value pointers */ if (apdu_len && wpdata) { @@ -113,24 +105,22 @@ int wp_decode_service_request( if (!decode_is_context_tag(&apdu[len++], 0)) return -1; len += decode_object_id(&apdu[len], &type, &wpdata->object_instance); - wpdata->object_type = (BACNET_OBJECT_TYPE) type; + wpdata->object_type = (BACNET_OBJECT_TYPE)type; /* Tag 1: Property ID */ - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value_type); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value_type); if (tag_number != 1) return -1; len += decode_enumerated(&apdu[len], len_value_type, &property); - wpdata->object_property = (BACNET_PROPERTY_ID) property; + wpdata->object_property = (BACNET_PROPERTY_ID)property; /* Tag 2: Optional Array Index */ - /* note: decode without incrementing len so we can check for opening tag */ - tag_len = - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value_type); + /* note: decode without incrementing len so we can check for opening tag + */ + tag_len = decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value_type); if (tag_number == 2) { len += tag_len; - len += - decode_unsigned(&apdu[len], len_value_type, &unsigned_value); + len += decode_unsigned(&apdu[len], len_value_type, &unsigned_value); wpdata->array_index = unsigned_value; } else wpdata->array_index = BACNET_ARRAY_ALL; @@ -138,9 +128,8 @@ int wp_decode_service_request( if (!decode_is_opening_tag_number(&apdu[len], 3)) return -1; /* determine the length of the data blob */ - wpdata->application_data_len = - bacapp_data_len(&apdu[len], apdu_len - len, - (BACNET_PROPERTY_ID) property); + wpdata->application_data_len = bacapp_data_len( + &apdu[len], apdu_len - len, (BACNET_PROPERTY_ID)property); /* a tag number of 3 is not extended so only one octet */ len++; /* copy the data from the APDU */ @@ -155,18 +144,16 @@ int wp_decode_service_request( len++; /* Tag 4: optional Priority - assumed MAX if not explicitly set */ wpdata->priority = BACNET_MAX_PRIORITY; - if ((unsigned) len < apdu_len) { - tag_len = - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value_type); + if ((unsigned)len < apdu_len) { + tag_len = decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value_type); if (tag_number == 4) { len += tag_len; - len = - decode_unsigned(&apdu[len], len_value_type, - &unsigned_value); - if ((unsigned_value >= BACNET_MIN_PRIORITY) - && (unsigned_value <= BACNET_MAX_PRIORITY)) { - wpdata->priority = (uint8_t) unsigned_value; + len = decode_unsigned(&apdu[len], len_value_type, + &unsigned_value); + if ((unsigned_value >= BACNET_MIN_PRIORITY) && + (unsigned_value <= BACNET_MAX_PRIORITY)) { + wpdata->priority = (uint8_t)unsigned_value; } else return -5; } @@ -181,11 +168,8 @@ int wp_decode_service_request( #include #include "ctest.h" -int wp_decode_apdu( - uint8_t * apdu, - unsigned apdu_len, - uint8_t * invoke_id, - BACNET_WRITE_PROPERTY_DATA * wpdata) +int wp_decode_apdu(uint8_t *apdu, unsigned apdu_len, uint8_t *invoke_id, + BACNET_WRITE_PROPERTY_DATA *wpdata) { int len = 0; unsigned offset = 0; @@ -196,28 +180,25 @@ int wp_decode_apdu( if (apdu[0] != PDU_TYPE_CONFIRMED_SERVICE_REQUEST) return -1; /* apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU); */ - *invoke_id = apdu[2]; /* invoke id - filled in by net layer */ + *invoke_id = apdu[2]; /* invoke id - filled in by net layer */ if (apdu[3] != SERVICE_CONFIRMED_WRITE_PROPERTY) return -1; offset = 4; if (apdu_len > offset) { len = - wp_decode_service_request(&apdu[offset], apdu_len - offset, - wpdata); + wp_decode_service_request(&apdu[offset], apdu_len - offset, wpdata); } return len; } -void testWritePropertyTag( - Test * pTest, - BACNET_APPLICATION_DATA_VALUE * value) +void testWritePropertyTag(Test *pTest, BACNET_APPLICATION_DATA_VALUE *value) { - BACNET_WRITE_PROPERTY_DATA wpdata = { 0 }; - BACNET_WRITE_PROPERTY_DATA test_data = { 0 }; + BACNET_WRITE_PROPERTY_DATA wpdata = {0}; + BACNET_WRITE_PROPERTY_DATA test_data = {0}; BACNET_APPLICATION_DATA_VALUE test_value; - uint8_t apdu[480] = { 0 }; + uint8_t apdu[480] = {0}; int len = 0; int apdu_len = 0; uint8_t invoke_id = 128; @@ -236,9 +217,9 @@ void testWritePropertyTag( ct_test(pTest, test_data.object_property == wpdata.object_property); ct_test(pTest, test_data.array_index == wpdata.array_index); /* decode the application value of the request */ - len = - bacapp_decode_application_data(test_data.application_data, - test_data.application_data_len, &test_value); + len = bacapp_decode_application_data(test_data.application_data, + test_data.application_data_len, + &test_value); ct_test(pTest, test_value.tag == value->tag); switch (test_value.tag) { case BACNET_APPLICATION_TAG_NULL: @@ -248,23 +229,23 @@ void testWritePropertyTag( break; case BACNET_APPLICATION_TAG_UNSIGNED_INT: ct_test(pTest, - test_value.type.Unsigned_Int == value->type.Unsigned_Int); + test_value.type.Unsigned_Int == value->type.Unsigned_Int); break; case BACNET_APPLICATION_TAG_SIGNED_INT: ct_test(pTest, - test_value.type.Signed_Int == value->type.Signed_Int); + test_value.type.Signed_Int == value->type.Signed_Int); break; case BACNET_APPLICATION_TAG_REAL: ct_test(pTest, test_value.type.Real == value->type.Real); break; case BACNET_APPLICATION_TAG_ENUMERATED: ct_test(pTest, - test_value.type.Enumerated == value->type.Enumerated); + test_value.type.Enumerated == value->type.Enumerated); break; case BACNET_APPLICATION_TAG_DATE: ct_test(pTest, test_value.type.Date.year == value->type.Date.year); ct_test(pTest, - test_value.type.Date.month == value->type.Date.month); + test_value.type.Date.month == value->type.Date.month); ct_test(pTest, test_value.type.Date.day == value->type.Date.day); ct_test(pTest, test_value.type.Date.wday == value->type.Date.wday); break; @@ -272,24 +253,21 @@ void testWritePropertyTag( ct_test(pTest, test_value.type.Time.hour == value->type.Time.hour); ct_test(pTest, test_value.type.Time.min == value->type.Time.min); ct_test(pTest, test_value.type.Time.sec == value->type.Time.sec); - ct_test(pTest, - test_value.type.Time.hundredths == - value->type.Time.hundredths); + ct_test(pTest, test_value.type.Time.hundredths == + value->type.Time.hundredths); break; case BACNET_APPLICATION_TAG_OBJECT_ID: - ct_test(pTest, - test_value.type.Object_Id.type == value->type.Object_Id.type); - ct_test(pTest, - test_value.type.Object_Id.instance == - value->type.Object_Id.instance); + ct_test(pTest, test_value.type.Object_Id.type == + value->type.Object_Id.type); + ct_test(pTest, test_value.type.Object_Id.instance == + value->type.Object_Id.instance); break; default: break; } } -void testWriteProperty( - Test * pTest) +void testWriteProperty(Test *pTest) { BACNET_APPLICATION_DATA_VALUE value; @@ -366,8 +344,7 @@ void testWriteProperty( } #ifdef TEST_WRITE_PROPERTY -int main( - void) +int main(void) { Test *pTest; bool rc; @@ -379,7 +356,7 @@ int main( ct_setStream(pTest, stdout); ct_run(pTest); - (void) ct_report(pTest); + (void)ct_report(pTest); ct_destroy(pTest); return 0; diff --git a/src/wpm.c b/src/wpm.c index 3919af08..1901daf0 100644 --- a/src/wpm.c +++ b/src/wpm.c @@ -1,28 +1,28 @@ /************************************************************************** -* -* Copyright (C) 2011 Krzysztof Malorny -* Contributions by Nikola Jelic 2011 -* -* Permission is hereby granted, free of charge, to any person obtaining -* a copy of this software and associated documentation files (the -* "Software"), to deal in the Software without restriction, including -* without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to -* permit persons to whom the Software is furnished to do so, subject to -* the following conditions: -* -* The above copyright notice and this permission notice shall be included -* in all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -* -*********************************************************************/ + * + * Copyright (C) 2011 Krzysztof Malorny + * Contributions by Nikola Jelic 2011 + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + *********************************************************************/ #include #include "bacapp.h" #include "bacenum.h" @@ -49,10 +49,8 @@ * @param data [out] The BACNET_WRITE_PROPERTY_DATA structure * which will contain the reponse values or error. */ -int wpm_decode_object_id( - uint8_t * apdu, - uint16_t apdu_len, - BACNET_WRITE_PROPERTY_DATA * wp_data) +int wpm_decode_object_id(uint8_t *apdu, uint16_t apdu_len, + BACNET_WRITE_PROPERTY_DATA *wp_data) { uint8_t tag_number = 0; uint32_t len_value = 0; @@ -62,14 +60,12 @@ int wpm_decode_object_id( if (apdu && (apdu_len > 5) && wp_data) { /* Context tag 0 - Object ID */ - len += - decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); if ((tag_number == 0) && (apdu_len > len)) { apdu_len -= len; if (apdu_len >= 4) { - len += - decode_object_id(&apdu[len], &object_type, - &object_instance); + len += decode_object_id(&apdu[len], &object_type, + &object_instance); wp_data->object_type = object_type; wp_data->object_instance = object_instance; apdu_len -= len; @@ -93,28 +89,23 @@ int wpm_decode_object_id( return BACNET_STATUS_REJECT; } - return (int) len; + return (int)len; } - -int wpm_decode_object_property( - uint8_t * apdu, - uint16_t apdu_len, - BACNET_WRITE_PROPERTY_DATA * wp_data) +int wpm_decode_object_property(uint8_t *apdu, uint16_t apdu_len, + BACNET_WRITE_PROPERTY_DATA *wp_data) { uint8_t tag_number = 0; uint32_t len_value = 0; uint32_t ulVal = 0; int len = 0, i = 0; - if ((apdu) && (apdu_len) && (wp_data)) { wp_data->array_index = BACNET_ARRAY_ALL; wp_data->priority = BACNET_MAX_PRIORITY; wp_data->application_data_len = 0; /* tag 0 - Property Identifier */ - len += - decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); if (tag_number == 0) { len += decode_enumerated(&apdu[len], len_value, &ulVal); wp_data->object_property = ulVal; @@ -124,22 +115,20 @@ int wpm_decode_object_property( } /* tag 1 - Property Array Index - optional */ - len += - decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); if (tag_number == 1) { len += decode_unsigned(&apdu[len], len_value, &ulVal); wp_data->array_index = ulVal; - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value); } /* tag 2 - Property Value */ if ((tag_number == 2) && (decode_is_opening_tag(&apdu[len - 1]))) { len--; wp_data->application_data_len = - bacapp_data_len(&apdu[len], (unsigned) (apdu_len - len), - wp_data->object_property); + bacapp_data_len(&apdu[len], (unsigned)(apdu_len - len), + wp_data->object_property); len++; /* copy application data */ @@ -147,9 +136,8 @@ int wpm_decode_object_property( wp_data->application_data[i] = apdu[len + i]; } len += wp_data->application_data_len; - len += - decode_tag_number_and_value(&apdu[len], &tag_number, - &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, + &len_value); /* closing tag 2 */ if ((tag_number != 2) && (decode_is_closing_tag(&apdu[len - 1]))) { wp_data->error_code = ERROR_CODE_REJECT_INVALID_TAG; @@ -161,8 +149,7 @@ int wpm_decode_object_property( } /* tag 3 - Priority - optional */ - len += - decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); + len += decode_tag_number_and_value(&apdu[len], &tag_number, &len_value); if (tag_number == 3) { len += decode_unsigned(&apdu[len], len_value, &ulVal); wp_data->priority = ulVal; @@ -177,35 +164,29 @@ int wpm_decode_object_property( } /* encode functions */ -int wpm_encode_apdu_init( - uint8_t * apdu, - uint8_t invoke_id) +int wpm_encode_apdu_init(uint8_t *apdu, uint8_t invoke_id) { - 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; apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU); apdu[2] = invoke_id; - apdu[3] = SERVICE_CONFIRMED_WRITE_PROP_MULTIPLE; /* service choice */ + apdu[3] = SERVICE_CONFIRMED_WRITE_PROP_MULTIPLE; /* service choice */ apdu_len = 4; } return apdu_len; - } -int wpm_encode_apdu_object_begin( - uint8_t * apdu, - BACNET_OBJECT_TYPE object_type, - uint32_t object_instance) +int wpm_encode_apdu_object_begin(uint8_t *apdu, BACNET_OBJECT_TYPE object_type, + uint32_t object_instance) { - 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_len = - encode_context_object_id(&apdu[0], 0, object_type, - object_instance); + encode_context_object_id(&apdu[0], 0, object_type, object_instance); /* Tag 1: sequence of WriteAccessSpecification */ apdu_len += encode_opening_tag(&apdu[apdu_len], 1); } @@ -213,10 +194,9 @@ int wpm_encode_apdu_object_begin( return apdu_len; } -int wpm_encode_apdu_object_end( - uint8_t * apdu) +int wpm_encode_apdu_object_end(uint8_t *apdu) { - 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_len = encode_closing_tag(&apdu[0], 1); @@ -225,11 +205,10 @@ int wpm_encode_apdu_object_end( return apdu_len; } -int wpm_encode_apdu_object_property( - uint8_t * apdu, - BACNET_WRITE_PROPERTY_DATA * wpdata) +int wpm_encode_apdu_object_property(uint8_t *apdu, + BACNET_WRITE_PROPERTY_DATA *wpdata) { - int apdu_len = 0; /* total length of the apdu, return value */ + int apdu_len = 0; /* total length of the apdu, return value */ int len = 0; if (apdu) { @@ -237,9 +216,8 @@ int wpm_encode_apdu_object_property( encode_context_enumerated(&apdu[0], 0, wpdata->object_property); /* optional array index */ if (wpdata->array_index != BACNET_ARRAY_ALL) { - apdu_len += - encode_context_unsigned(&apdu[apdu_len], 1, - wpdata->array_index); + apdu_len += encode_context_unsigned(&apdu[apdu_len], 1, + wpdata->array_index); } apdu_len += encode_opening_tag(&apdu[apdu_len], 2); for (len = 0; len < wpdata->application_data_len; len++) { @@ -256,18 +234,17 @@ int wpm_encode_apdu_object_property( return apdu_len; } -int wpm_encode_apdu( - uint8_t * apdu, - size_t max_apdu, - uint8_t invoke_id, - BACNET_WRITE_ACCESS_DATA * write_access_data) +int wpm_encode_apdu(uint8_t *apdu, size_t max_apdu, uint8_t invoke_id, + BACNET_WRITE_ACCESS_DATA *write_access_data) { int apdu_len = 0; int len = 0; - BACNET_WRITE_ACCESS_DATA *wpm_object; /* current object */ - uint8_t apdu_temp[MAX_APDU]; /* temp for data before copy */ - BACNET_PROPERTY_VALUE *wpm_property; /* current property */ - BACNET_WRITE_PROPERTY_DATA wpdata; /* for compatibility with wpm_encode_apdu_object_property function */ + BACNET_WRITE_ACCESS_DATA *wpm_object; /* current object */ + uint8_t apdu_temp[MAX_APDU]; /* temp for data before copy */ + BACNET_PROPERTY_VALUE *wpm_property; /* current property */ + BACNET_WRITE_PROPERTY_DATA + wpdata; /* for compatibility with wpm_encode_apdu_object_property + function */ if (apdu) { len = wpm_encode_apdu_init(&apdu[0], invoke_id); @@ -276,10 +253,9 @@ int wpm_encode_apdu( wpm_object = write_access_data; while (wpm_object) { - - len = - wpm_encode_apdu_object_begin(&apdu[apdu_len], - wpm_object->object_type, wpm_object->object_instance); + len = wpm_encode_apdu_object_begin(&apdu[apdu_len], + wpm_object->object_type, + wpm_object->object_instance); apdu_len += len; wpm_property = wpm_object->listOfProperties; @@ -288,12 +264,11 @@ int wpm_encode_apdu( wpdata.object_property = wpm_property->propertyIdentifier; wpdata.array_index = wpm_property->propertyArrayIndex; wpdata.priority = wpm_property->priority; - wpdata.application_data_len = bacapp_encode_data(&apdu_temp[0], - &wpm_property->value); - memcpy(&wpdata.application_data[0], &apdu_temp[0], - (size_t)wpdata.application_data_len); - len = - wpm_encode_apdu_object_property(&apdu[apdu_len], &wpdata); + wpdata.application_data_len = + bacapp_encode_data(&apdu_temp[0], &wpm_property->value); + memcpy(&wpdata.application_data[0], &apdu_temp[0], + (size_t)wpdata.application_data_len); + len = wpm_encode_apdu_object_property(&apdu[apdu_len], &wpdata); apdu_len += len; wpm_property = wpm_property->next; @@ -309,9 +284,7 @@ int wpm_encode_apdu( return apdu_len; } -int wpm_ack_encode_apdu_init( - uint8_t * apdu, - uint8_t invoke_id) +int wpm_ack_encode_apdu_init(uint8_t *apdu, uint8_t invoke_id) { int len = 0; @@ -324,10 +297,8 @@ int wpm_ack_encode_apdu_init( return len; } -int wpm_error_ack_encode_apdu( - uint8_t * apdu, - uint8_t invoke_id, - BACNET_WRITE_PROPERTY_DATA * wp_data) +int wpm_error_ack_encode_apdu(uint8_t *apdu, uint8_t invoke_id, + BACNET_WRITE_PROPERTY_DATA *wp_data) { int len = 0; @@ -342,15 +313,13 @@ int wpm_error_ack_encode_apdu( len += encode_closing_tag(&apdu[len], 0); len += encode_opening_tag(&apdu[len], 1); - len += - encode_context_object_id(&apdu[len], 0, wp_data->object_type, - wp_data->object_instance); + len += encode_context_object_id(&apdu[len], 0, wp_data->object_type, + wp_data->object_instance); len += encode_context_enumerated(&apdu[len], 1, wp_data->object_property); if (wp_data->array_index != BACNET_ARRAY_ALL) - len += - encode_context_unsigned(&apdu[len], 2, wp_data->array_index); + len += encode_context_unsigned(&apdu[len], 2, wp_data->array_index); len += encode_closing_tag(&apdu[len], 1); } return len;