Run clang-format and enable CI check for it (#755)
* pre-commit: Update and enable clang-format check There is newer version from clang-format so use that. We do not yet want 18 as that is little bit too new. * Format some thing by hand which clang-format "breaks" Clang-format will format some things little bit off in some cases. Format some things by hand so we get cleaner end result. * Run clang-format with ``` pre-commit run --all-files clang-format ``` We have already in previously checked places where clang-format does not make good format and ignored those (hopefully most of the things). --------- Co-authored-by: Kari Argillander <kari.argillander@fidelix.com>
This commit is contained in:
+88
-67
@@ -57,7 +57,8 @@ static bool Error_Detected = false;
|
||||
/* Used for verbose */
|
||||
static bool Verbose = false;
|
||||
|
||||
static void MyWritePropertyMultipleErrorHandler(BACNET_ADDRESS *src,
|
||||
static void MyWritePropertyMultipleErrorHandler(
|
||||
BACNET_ADDRESS *src,
|
||||
uint8_t invoke_id,
|
||||
uint8_t service_choice,
|
||||
uint8_t *service_request,
|
||||
@@ -71,10 +72,12 @@ static void MyWritePropertyMultipleErrorHandler(BACNET_ADDRESS *src,
|
||||
(invoke_id == Request_Invoke_ID)) {
|
||||
len = wpm_error_ack_decode_apdu(service_request, service_len, &wp_data);
|
||||
if (len > 0) {
|
||||
printf("BACnet Error: %s: %s\n",
|
||||
printf(
|
||||
"BACnet Error: %s: %s\n",
|
||||
bactext_error_class_name((int)wp_data.error_class),
|
||||
bactext_error_code_name((int)wp_data.error_code));
|
||||
printf("BACnet Error: %s %u: %s\n",
|
||||
printf(
|
||||
"BACnet Error: %s %u: %s\n",
|
||||
bactext_object_type_name((int)wp_data.object_type),
|
||||
(unsigned)wp_data.object_instance,
|
||||
bactext_property_name((int)wp_data.object_property));
|
||||
@@ -95,20 +98,21 @@ static void MyAbortHandler(
|
||||
}
|
||||
}
|
||||
|
||||
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 */
|
||||
if (address_match(&Target_Address, src) &&
|
||||
(invoke_id == Request_Invoke_ID)) {
|
||||
printf("BACnet Reject: %s\n",
|
||||
printf(
|
||||
"BACnet Reject: %s\n",
|
||||
bactext_reject_reason_name((int)reject_reason));
|
||||
Error_Detected = true;
|
||||
}
|
||||
}
|
||||
|
||||
static void MyWritePropertyMultipleSimpleAckHandler(
|
||||
BACNET_ADDRESS *src, uint8_t invoke_id)
|
||||
static void
|
||||
MyWritePropertyMultipleSimpleAckHandler(BACNET_ADDRESS *src, uint8_t invoke_id)
|
||||
{
|
||||
if (address_match(&Target_Address, src) &&
|
||||
(invoke_id == Request_Invoke_ID)) {
|
||||
@@ -131,10 +135,12 @@ static void Init_Service_Handlers(void)
|
||||
apdu_set_confirmed_handler(
|
||||
SERVICE_CONFIRMED_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_complex_error_handler(SERVICE_CONFIRMED_WRITE_PROP_MULTIPLE,
|
||||
apdu_set_complex_error_handler(
|
||||
SERVICE_CONFIRMED_WRITE_PROP_MULTIPLE,
|
||||
MyWritePropertyMultipleErrorHandler);
|
||||
apdu_set_abort_handler(MyAbortHandler);
|
||||
apdu_set_reject_handler(MyRejectHandler);
|
||||
@@ -164,9 +170,10 @@ static void cleanup(void)
|
||||
|
||||
static void print_usage(const 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");
|
||||
}
|
||||
@@ -174,65 +181,69 @@ static void print_usage(const char *filename)
|
||||
static void print_help(const char *filename)
|
||||
{
|
||||
printf("Write one or more properties to one or more objects\n"
|
||||
"in a BACnet device.\n");
|
||||
"in a BACnet device.\n");
|
||||
printf("\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"
|
||||
"I-Am services. For example, if you were writing\n"
|
||||
"Device Object 123, the device-instance would be 123.\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"
|
||||
"I-Am services. For example, if you were writing\n"
|
||||
"Device Object 123, the device-instance would be 123.\n");
|
||||
printf("\n");
|
||||
printf("object-type:\n"
|
||||
"The object type is object that you are writing. It\n"
|
||||
"can be defined either as the object-type name string\n"
|
||||
"as defined in the BACnet specification, or as the\n"
|
||||
"integer value of the enumeration BACNET_OBJECT_TYPE\n"
|
||||
"in bacenum.h. For example if you were writing Analog\n"
|
||||
"Output 2, the object-type would be analog-output or 1.\n");
|
||||
"The object type is object that you are writing. It\n"
|
||||
"can be defined either as the object-type name string\n"
|
||||
"as defined in the BACnet specification, or as the\n"
|
||||
"integer value of the enumeration BACNET_OBJECT_TYPE\n"
|
||||
"in bacenum.h. For example if you were writing Analog\n"
|
||||
"Output 2, the object-type would be analog-output or 1.\n");
|
||||
printf("\n");
|
||||
printf("object-instance:\n"
|
||||
"This is the object instance number of the object that\n"
|
||||
"you are writing. For example, if you were writing\n"
|
||||
"Analog Output 2, the object-instance would be 2.\n");
|
||||
"This is the object instance number of the object that\n"
|
||||
"you are writing. For example, if you were writing\n"
|
||||
"Analog Output 2, the object-instance would be 2.\n");
|
||||
printf("\n");
|
||||
printf("property:\n"
|
||||
"The property is an integer value of the enumeration\n"
|
||||
"BACNET_PROPERTY_ID in bacenum.h. It is the property\n"
|
||||
"you are writing. For example, if you were writing the\n"
|
||||
"Present Value property, use 85 as the property.\n");
|
||||
"The property is an integer value of the enumeration\n"
|
||||
"BACNET_PROPERTY_ID in bacenum.h. It is the property\n"
|
||||
"you are writing. For example, if you were writing the\n"
|
||||
"Present Value property, use 85 as the property.\n");
|
||||
printf("\n");
|
||||
printf("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");
|
||||
"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");
|
||||
printf("\n");
|
||||
printf("index:\n"
|
||||
printf(
|
||||
"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");
|
||||
printf("\n");
|
||||
printf("tag:\n"
|
||||
printf(
|
||||
"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");
|
||||
printf(
|
||||
"Complex data use the property argument and a tag number -1 to\n"
|
||||
"lookup the appropriate internal application tag for the value.\n"
|
||||
"The complex data value argument varies in its construction.\n");
|
||||
"is preceded by a C. Ctag tag. C2 4 creates a context 2 tagged "
|
||||
"REAL.\n");
|
||||
printf("Complex data use the property argument and a tag number -1 to\n"
|
||||
"lookup the appropriate internal application tag for the value.\n"
|
||||
"The complex data value argument varies in its construction.\n");
|
||||
printf("\n");
|
||||
printf("value:\n"
|
||||
printf(
|
||||
"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");
|
||||
printf("\n");
|
||||
printf("Here is a brief overview of BACnet property and tags:\n"
|
||||
printf(
|
||||
"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"
|
||||
"with each property of each object. It is almost safe to say that\n"
|
||||
@@ -241,11 +252,12 @@ static void print_help(const char *filename)
|
||||
"the Any property type in the schedule object and the Present Value\n"
|
||||
"accepting REAL, BOOLEAN, NULL, etc.\n");
|
||||
printf("Perhaps it would be simpler for the demo to use this\n"
|
||||
"kind of table - but this tool can also be used for negative\n"
|
||||
"testing by passing the wrong tag to validate that the server\n"
|
||||
"returns an error, reject, or abort message.\n");
|
||||
"kind of table - but this tool can also be used for negative\n"
|
||||
"testing by passing the wrong tag to validate that the server\n"
|
||||
"returns an error, reject, or abort message.\n");
|
||||
printf("\n");
|
||||
printf("Example:\n"
|
||||
printf(
|
||||
"Example:\n"
|
||||
"If you want write 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"
|
||||
@@ -304,7 +316,8 @@ int main(int argc, char *argv[])
|
||||
/* decode the command line parameters */
|
||||
Target_Device_Object_Instance = strtol(argv[1], NULL, 0);
|
||||
if (Target_Device_Object_Instance > BACNET_MAX_INSTANCE) {
|
||||
fprintf(stderr, "device-instance=%u - not greater than %u\n",
|
||||
fprintf(
|
||||
stderr, "device-instance=%u - not greater than %u\n",
|
||||
Target_Device_Object_Instance, BACNET_MAX_INSTANCE);
|
||||
return 1;
|
||||
}
|
||||
@@ -332,7 +345,8 @@ int main(int argc, char *argv[])
|
||||
return 1;
|
||||
}
|
||||
if (wpm_object->object_type >= MAX_BACNET_OBJECT_TYPE) {
|
||||
fprintf(stderr, "object-type=%u - it must be less than %u\n",
|
||||
fprintf(
|
||||
stderr, "object-type=%u - it must be less than %u\n",
|
||||
wpm_object->object_type, MAX_BACNET_OBJECT_TYPE);
|
||||
return 1;
|
||||
}
|
||||
@@ -347,7 +361,8 @@ int main(int argc, char *argv[])
|
||||
return 1;
|
||||
}
|
||||
if (wpm_object->object_instance > BACNET_MAX_INSTANCE) {
|
||||
fprintf(stderr, "object-instance=%u - not greater than %u\n",
|
||||
fprintf(
|
||||
stderr, "object-instance=%u - not greater than %u\n",
|
||||
wpm_object->object_instance, BACNET_MAX_INSTANCE);
|
||||
return 1;
|
||||
}
|
||||
@@ -356,20 +371,22 @@ int main(int argc, char *argv[])
|
||||
wpm_object->listOfProperties = wpm_property;
|
||||
if (wpm_property) {
|
||||
/* Property[index] */
|
||||
scan_count = sscanf(argv[tag_value_arg], "%u[%u]", &property_id,
|
||||
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",
|
||||
printf(
|
||||
"property-identifier=%u, array-index=%u\n",
|
||||
property_id, property_array_index);
|
||||
}
|
||||
if (wpm_property->propertyIdentifier >
|
||||
MAX_BACNET_PROPERTY_ID) {
|
||||
fprintf(stderr,
|
||||
"property=%u - it must be less than %u\n",
|
||||
fprintf(
|
||||
stderr, "property=%u - it must be less than %u\n",
|
||||
wpm_property->propertyIdentifier,
|
||||
MAX_BACNET_PROPERTY_ID + 1);
|
||||
return 1;
|
||||
@@ -381,7 +398,8 @@ int main(int argc, char *argv[])
|
||||
wpm_property->propertyArrayIndex = BACNET_ARRAY_ALL;
|
||||
}
|
||||
if (args_remaining <= 0) {
|
||||
fprintf(stderr,
|
||||
fprintf(
|
||||
stderr,
|
||||
"Error: missing priority and tag value pair.\n");
|
||||
return 1;
|
||||
}
|
||||
@@ -428,12 +446,12 @@ int main(int argc, char *argv[])
|
||||
printf("tag=%ld value=%s\n", property_tag, value_string);
|
||||
}
|
||||
if (property_tag < 0) {
|
||||
property_tag =
|
||||
bacapp_known_property_tag(wpm_object->object_type,
|
||||
wpm_property->propertyIdentifier);
|
||||
property_tag = bacapp_known_property_tag(
|
||||
wpm_object->object_type,
|
||||
wpm_property->propertyIdentifier);
|
||||
} else if (property_tag >= MAX_BACNET_APPLICATION_TAG) {
|
||||
fprintf(stderr,
|
||||
"Error: tag=%ld - it must be less than %u\n",
|
||||
fprintf(
|
||||
stderr, "Error: tag=%ld - it must be less than %u\n",
|
||||
property_tag, MAX_BACNET_APPLICATION_TAG);
|
||||
return 1;
|
||||
}
|
||||
@@ -447,10 +465,11 @@ int main(int argc, char *argv[])
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr,
|
||||
fprintf(
|
||||
stderr,
|
||||
"Error: parser for property %s is not implemented\n",
|
||||
bactext_property_name(
|
||||
wpm_property->propertyIdentifier));
|
||||
wpm_property->propertyIdentifier));
|
||||
return 1;
|
||||
}
|
||||
wpm_property->value.next = NULL;
|
||||
@@ -480,7 +499,8 @@ int main(int argc, char *argv[])
|
||||
Target_Device_Object_Instance, &max_apdu, &Target_Address);
|
||||
if (found) {
|
||||
if (Verbose) {
|
||||
printf("Found Device %u in address_cache.\n",
|
||||
printf(
|
||||
"Found Device %u in address_cache.\n",
|
||||
Target_Device_Object_Instance);
|
||||
}
|
||||
} else {
|
||||
@@ -508,7 +528,8 @@ int main(int argc, char *argv[])
|
||||
if (found) {
|
||||
if (Request_Invoke_ID == 0) {
|
||||
if (Verbose) {
|
||||
printf("Sending WritePropertyMultiple to Device %u.\n",
|
||||
printf(
|
||||
"Sending WritePropertyMultiple to Device %u.\n",
|
||||
Target_Device_Object_Instance);
|
||||
}
|
||||
Request_Invoke_ID = Send_Write_Property_Multiple_Request(
|
||||
|
||||
Reference in New Issue
Block a user