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:
Kari Argillander
2024-08-30 19:20:58 +03:00
committed by GitHub
parent 622a9e609e
commit f806c5829b
547 changed files with 18286 additions and 16575 deletions
+15 -11
View File
@@ -67,19 +67,23 @@
* @ingroup BACEPICS
*/
typedef enum {
/** Initial state to establish a binding with the target device. */
/** Initial state to establish a binding with the target device. */
INITIAL_BINDING,
/** Get selected device information and put out the heading information. */
GET_HEADING_INFO, GET_HEADING_RESPONSE, PRINT_HEADING,
/** Getting ALL properties and values at once with RPM. */
GET_ALL_REQUEST, GET_ALL_RESPONSE,
/** Getting ALL properties with array index = 0, just to get the list. */
GET_LIST_OF_ALL_REQUEST, GET_LIST_OF_ALL_RESPONSE,
/** Processing the properties individually with ReadProperty. */
GET_PROPERTY_REQUEST, GET_PROPERTY_RESPONSE,
/** Done with this Object; move onto the next. */
/** Get selected device information and put out the heading information. */
GET_HEADING_INFO,
GET_HEADING_RESPONSE,
PRINT_HEADING,
/** Getting ALL properties and values at once with RPM. */
GET_ALL_REQUEST,
GET_ALL_RESPONSE,
/** Getting ALL properties with array index = 0, just to get the list. */
GET_LIST_OF_ALL_REQUEST,
GET_LIST_OF_ALL_RESPONSE,
/** Processing the properties individually with ReadProperty. */
GET_PROPERTY_REQUEST,
GET_PROPERTY_RESPONSE,
/** Done with this Object; move onto the next. */
NEXT_OBJECT
} EPICS_STATES;
#endif /* BACEPICS_H_ */
+89 -58
View File
@@ -11,7 +11,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h> /* for time */
#if (__STDC_VERSION__ >= 199901L) && defined (__STDC_ISO_10646__)
#if (__STDC_VERSION__ >= 199901L) && defined(__STDC_ISO_10646__)
#include <locale.h>
#endif
#include <errno.h>
@@ -117,10 +117,12 @@ struct property_value_list_t {
BACNET_APPLICATION_DATA_VALUE *value;
};
static struct property_value_list_t Property_Value_List[] = {
{ PROP_VENDOR_NAME, NULL }, { PROP_MODEL_NAME, NULL },
{ PROP_VENDOR_NAME, NULL },
{ PROP_MODEL_NAME, NULL },
{ PROP_MAX_APDU_LENGTH_ACCEPTED, NULL },
{ PROP_PROTOCOL_SERVICES_SUPPORTED, NULL },
{ PROP_PROTOCOL_OBJECT_TYPES_SUPPORTED, NULL }, { PROP_DESCRIPTION, NULL },
{ PROP_PROTOCOL_OBJECT_TYPES_SUPPORTED, NULL },
{ PROP_DESCRIPTION, NULL },
{ -1, NULL }
};
@@ -161,7 +163,8 @@ static bool Optional_Properties = false;
#define PRINT_ERRORS 1
#endif
static void MyErrorHandler(BACNET_ADDRESS *src,
static void MyErrorHandler(
BACNET_ADDRESS *src,
uint8_t invoke_id,
BACNET_ERROR_CLASS error_class,
BACNET_ERROR_CODE error_code)
@@ -170,7 +173,8 @@ static void MyErrorHandler(BACNET_ADDRESS *src,
(invoke_id == Request_Invoke_ID)) {
#if PRINT_ERRORS
if (ShowValues) {
fprintf(stderr, "-- BACnet Error: %s: %s\n",
fprintf(
stderr, "-- BACnet Error: %s: %s\n",
bactext_error_class_name(error_class),
bactext_error_code_name(error_code));
}
@@ -190,7 +194,8 @@ static void MyAbortHandler(
#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",
fprintf(
stderr, "-- BACnet Abort: %s \n",
bactext_abort_reason_name(abort_reason));
}
#endif
@@ -205,14 +210,15 @@ 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)
{
if (address_match(&Target_Address, src) &&
(invoke_id == Request_Invoke_ID)) {
#if PRINT_ERRORS
if (ShowValues) {
fprintf(stderr, "BACnet Reject: %s\n",
fprintf(
stderr, "BACnet Reject: %s\n",
bactext_reject_reason_name(reject_reason));
}
#endif
@@ -227,7 +233,8 @@ static void MyRejectHandler(
}
}
static void MyReadPropertyAckHandler(uint8_t *service_request,
static void MyReadPropertyAckHandler(
uint8_t *service_request,
uint16_t service_len,
BACNET_ADDRESS *src,
BACNET_CONFIRMED_SERVICE_ACK_DATA *service_data)
@@ -243,7 +250,8 @@ static void MyReadPropertyAckHandler(uint8_t *service_request,
service_request, service_len, rp_data);
}
if (len > 0) {
memmove(&Read_Property_Multiple_Data.service_data, service_data,
memmove(
&Read_Property_Multiple_Data.service_data, service_data,
sizeof(BACNET_CONFIRMED_SERVICE_ACK_DATA));
Read_Property_Multiple_Data.rpm_data = rp_data;
Read_Property_Multiple_Data.new_data = true;
@@ -256,7 +264,8 @@ static void MyReadPropertyAckHandler(uint8_t *service_request,
}
}
static void MyReadPropertyMultipleAckHandler(uint8_t *service_request,
static void MyReadPropertyMultipleAckHandler(
uint8_t *service_request,
uint16_t service_len,
BACNET_ADDRESS *src,
BACNET_CONFIRMED_SERVICE_ACK_DATA *service_data)
@@ -272,7 +281,8 @@ static void MyReadPropertyMultipleAckHandler(uint8_t *service_request,
service_request, service_len, rpm_data);
}
if (len > 0) {
memmove(&Read_Property_Multiple_Data.service_data, service_data,
memmove(
&Read_Property_Multiple_Data.service_data, service_data,
sizeof(BACNET_CONFIRMED_SERVICE_ACK_DATA));
Read_Property_Multiple_Data.rpm_data = rpm_data;
Read_Property_Multiple_Data.new_data = true;
@@ -372,11 +382,12 @@ static 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",
fprintf(
stream, "%s",
bitstring_bit(&value->type.Bit_String, (uint8_t)i) ? "T" : "F");
if (i < len - 1) {
fprintf(stream, ",");
@@ -395,7 +406,8 @@ static bool PrettyPrintPropertyValue(
stream, " %s,", bactext_object_type_name(j));
} else {
/* PROP_PROTOCOL_SERVICES_SUPPORTED */
fprintf(stream, " %s,",
fprintf(
stream, " %s,",
protocol_services_supported_text(j));
}
} else { /* not supported */
@@ -412,7 +424,8 @@ static 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,
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) {
@@ -436,7 +449,8 @@ static bool PrettyPrintPropertyValue(
* @param rpm_property [in] Points to structure holding the Property,
* Value, and Error information.
*/
static void PrintReadPropertyData(BACNET_OBJECT_TYPE object_type,
static void PrintReadPropertyData(
BACNET_OBJECT_TYPE object_type,
uint32_t object_instance,
BACNET_PROPERTY_REFERENCE *rpm_property)
{
@@ -452,7 +466,8 @@ static void PrintReadPropertyData(BACNET_OBJECT_TYPE object_type,
value = rpm_property->value;
if (value == NULL) {
/* Then we print the error information */
fprintf(stdout, "? -- BACnet Error: %s: %s\n",
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));
return;
@@ -516,7 +531,8 @@ static void PrintReadPropertyData(BACNET_OBJECT_TYPE object_type,
}
break;
} else {
assert(Walked_List_Index ==
assert(
Walked_List_Index ==
(uint32_t)rpm_property->propertyArrayIndex);
}
} else {
@@ -553,13 +569,14 @@ static void PrintReadPropertyData(BACNET_OBJECT_TYPE object_type,
}
/* Store the object list so we can interrogate
each object. */
object_list_element = KEY_ENCODE(value->type.Object_Id.type,
object_list_element = KEY_ENCODE(
value->type.Object_Id.type,
value->type.Object_Id.instance);
/* We don't have anything to put in the data pointer
* yet, so just leave it null. The key is Key here. */
Keylist_Data_Add(Object_List, object_list_element, NULL);
} else if (rpm_property->propertyIdentifier ==
PROP_STATE_TEXT) {
} 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. */
@@ -567,14 +584,15 @@ static void PrintReadPropertyData(BACNET_OBJECT_TYPE object_type,
int iLast15idx =
value->type.Character_String.length - 15;
value->type.Character_String.value[15] = '-';
memmove(&value->type.Character_String.value[16],
memmove(
&value->type.Character_String.value[16],
&value->type.Character_String.value[iLast15idx],
15);
value->type.Character_String.value[31] = 0;
value->type.Character_String.length = 31;
}
} else if (rpm_property->propertyIdentifier ==
PROP_SUBORDINATE_LIST) {
} else if (
rpm_property->propertyIdentifier == PROP_SUBORDINATE_LIST) {
if (value->tag !=
BACNET_APPLICATION_TAG_DEVICE_OBJECT_REFERENCE) {
break;
@@ -648,8 +666,8 @@ static void PrintReadPropertyData(BACNET_OBJECT_TYPE object_type,
/* Closing brace for this multi-valued array */
fprintf(stdout, " }");
}
if (property_list_writable_member(object_type,
rpm_property->propertyIdentifier)) {
if (property_list_writable_member(
object_type, rpm_property->propertyIdentifier)) {
fprintf(stdout, " Writable");
}
fprintf(stdout, "\n");
@@ -709,8 +727,8 @@ static void BuildPropRequest(BACNET_READ_ACCESS_DATA *rpm_object)
* @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, const BACNET_OBJECT_ID *pMyObject)
static uint8_t
Read_Properties(uint32_t device_instance, const BACNET_OBJECT_ID *pMyObject)
{
uint8_t invoke_id = 0;
struct special_property_list_t PropertyListStruct;
@@ -775,8 +793,9 @@ static uint8_t Read_Properties(
break;
}
}
invoke_id = Send_Read_Property_Request(device_instance, pMyObject->type,
pMyObject->instance, prop, array_index);
invoke_id = Send_Read_Property_Request(
device_instance, pMyObject->type, pMyObject->instance, prop,
array_index);
}
return invoke_id;
@@ -793,8 +812,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.
*/
static EPICS_STATES ProcessRPMData(
BACNET_READ_ACCESS_DATA *rpm_data, EPICS_STATES state)
static EPICS_STATES
ProcessRPMData(BACNET_READ_ACCESS_DATA *rpm_data, EPICS_STATES state)
{
BACNET_READ_ACCESS_DATA *old_rpm_data;
BACNET_PROPERTY_REFERENCE *rpm_property;
@@ -845,8 +864,9 @@ static EPICS_STATES ProcessRPMData(
fprintf(stdout, " ");
Print_Property_Identifier(rpm_property->propertyIdentifier);
fprintf(stdout, ": ");
PrintReadPropertyData(rpm_data->object_type,
rpm_data->object_instance, rpm_property);
PrintReadPropertyData(
rpm_data->object_type, rpm_data->object_instance,
rpm_property);
}
old_rpm_property = rpm_property;
rpm_property = rpm_property->next;
@@ -886,8 +906,9 @@ static EPICS_STATES ProcessRPMData(
static void print_usage(const char *filename)
{
printf("Usage: %s [-v] [-d] [-p sport] [-t target_mac [-n dnet]]"
" device-instance\n",
printf(
"Usage: %s [-v] [-d] [-p sport] [-t target_mac [-n dnet]]"
" device-instance\n",
filename);
printf(" [--version][--help]\n");
}
@@ -984,9 +1005,9 @@ static int CheckCommandLineArgs(int argc, char *argv[])
int count;
/* loop counter */
unsigned j;
count =
sscanf(argv[i], "%2x:%2x:%2x:%2x:%2x:%2x", &mac[0],
&mac[1], &mac[2], &mac[3], &mac[4], &mac[5]);
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 */
Target_Address.mac_len = count;
for (j = 0; j < 6; j++) {
@@ -1011,8 +1032,8 @@ static int CheckCommandLineArgs(int argc, char *argv[])
/* decode the Target Device Instance parameter */
Target_Device_Object_Instance = strtol(anArg, NULL, 0);
if (Target_Device_Object_Instance > BACNET_MAX_INSTANCE) {
fprintf(stdout,
"Error: device-instance=%u - not greater than %u\n",
fprintf(
stdout, "Error: device-instance=%u - not greater than %u\n",
Target_Device_Object_Instance, BACNET_MAX_INSTANCE);
print_usage(filename);
exit(0);
@@ -1045,7 +1066,8 @@ static void PrintHeading(void)
value = object_property_value(PROP_VENDOR_NAME);
if ((value != NULL) &&
(value->tag == BACNET_APPLICATION_TAG_CHARACTER_STRING)) {
printf("Vendor Name: \"%s\"\n",
printf(
"Vendor Name: \"%s\"\n",
characterstring_value(&value->type.Character_String));
} else {
printf("Vendor Name: \"your vendor name here\"\n");
@@ -1055,9 +1077,11 @@ static void PrintHeading(void)
/* Best we can do with Product Name and Model Number is use the same text */
if ((value != NULL) &&
(value->tag == BACNET_APPLICATION_TAG_CHARACTER_STRING)) {
printf("Product Name: \"%s\"\n",
printf(
"Product Name: \"%s\"\n",
characterstring_value(&value->type.Character_String));
printf("Product Model Number: \"%s\"\n",
printf(
"Product Model Number: \"%s\"\n",
characterstring_value(&value->type.Character_String));
} else {
printf("Product Name: \"your product name here\"\n");
@@ -1067,7 +1091,8 @@ static void PrintHeading(void)
value = object_property_value(PROP_DESCRIPTION);
if ((value != NULL) &&
(value->tag == BACNET_APPLICATION_TAG_CHARACTER_STRING)) {
printf("Product Description: \"%s\"\n\n",
printf(
"Product Description: \"%s\"\n\n",
characterstring_value(&value->type.Character_String));
} else {
printf("Product Description: "
@@ -1093,8 +1118,9 @@ static void PrintHeading(void)
printf("-- DM-UTC-B\n");
#ifdef BAC_ROUTING
/* Next line only for the gateway (ie, if not addressing a subNet) */
if (Target_Address.net == 0)
if (Target_Address.net == 0) {
printf("-- NM-RC-B\n");
}
#endif
printf("}\n\n");
printf("BACnet Standard Application Services Supported:\n");
@@ -1340,7 +1366,7 @@ int main(int argc, char *argv[])
address_init();
Init_Service_Handlers();
dlenv_init();
#if (__STDC_VERSION__ >= 199901L) && defined (__STDC_ISO_10646__)
#if (__STDC_VERSION__ >= 199901L) && defined(__STDC_ISO_10646__)
/* Internationalized programs must call setlocale()
* to initiate a specific language operation.
* This can be done by calling setlocale() as follows.
@@ -1371,8 +1397,8 @@ int main(int argc, char *argv[])
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,
Send_WhoIs_Remote(
&Target_Address, Target_Device_Object_Instance,
Target_Device_Object_Instance);
} else {
@@ -1418,7 +1444,8 @@ int main(int argc, char *argv[])
/* increment timer - exit if timed out */
elapsed_seconds += (current_seconds - last_seconds);
if (elapsed_seconds > timeout_seconds) {
fprintf(stderr,
fprintf(
stderr,
"\rError: Unable to bind to %u"
" after waiting %ld seconds.\n",
Target_Device_Object_Instance,
@@ -1492,7 +1519,7 @@ int main(int argc, char *argv[])
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);
@@ -1516,7 +1543,8 @@ int main(int argc, char *argv[])
/* 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);
@@ -1587,7 +1615,7 @@ int main(int argc, char *argv[])
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,
@@ -1684,10 +1712,12 @@ int main(int argc, char *argv[])
do {
Object_List_Index++;
if (Object_List_Index < Keylist_Count(Object_List)) {
if (Keylist_Index_Key(Object_List, Object_List_Index, &nextKey)) {
if (Keylist_Index_Key(
Object_List, Object_List_Index, &nextKey)) {
myObject.type = KEY_DECODE_TYPE(nextKey);
myObject.instance = KEY_DECODE_ID(nextKey);
/* Don't re-list the Device Object among its objects */
/* Don't re-list the Device Object among its objects
*/
if (myObject.type == OBJECT_DEVICE) {
continue;
}
@@ -1732,7 +1762,8 @@ int main(int argc, char *argv[])
/* increment timer - exit if timed out */
elapsed_seconds += (current_seconds - last_seconds);
if (elapsed_seconds > timeout_seconds) {
fprintf(stderr, "\rError: APDU Timeout! (%lds)\n",
fprintf(
stderr, "\rError: APDU Timeout! (%lds)\n",
(long int)elapsed_seconds);
break;
}