added clang format C and H files.

This commit is contained in:
Steve Karg
2019-10-24 16:23:10 -05:00
parent da91a11454
commit 710173d6e0
205 changed files with 19377 additions and 25754 deletions
+100 -109
View File
@@ -1,26 +1,26 @@
/*************************************************************************
* Copyright (C) 2017 Steve Karg <skarg@users.sourceforge.net>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 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 <skarg@users.sourceforge.net>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 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 <stddef.h>
@@ -29,7 +29,7 @@
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#include <time.h> /* for time */
#include <time.h> /* 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;