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 -10
View File
@@ -122,7 +122,8 @@ static void ProcessPT(BACNET_PRIVATE_TRANSFER_DATA *data)
data->serviceParametersLen = 0;
return;
}
iLen += decode_real(&data->serviceParameters[iLen],
iLen += decode_real(
&data->serviceParameters[iLen],
&MyData[(int8_t)cBlockNumber].fMyReal);
tag_len = decode_tag_number_and_value(
@@ -135,7 +136,8 @@ static void ProcessPT(BACNET_PRIVATE_TRANSFER_DATA *data)
decode_character_string(
&data->serviceParameters[iLen], len_value_type, &bsTemp);
/* Only copy as much as we can accept */
strncpy((char *)MyData[(int8_t)cBlockNumber].sMyString,
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';
@@ -160,7 +162,8 @@ static void ProcessPT(BACNET_PRIVATE_TRANSFER_DATA *data)
*
*/
void handler_conf_private_trans(uint8_t *service_request,
void handler_conf_private_trans(
uint8_t *service_request,
uint16_t service_len,
BACNET_ADDRESS *src,
BACNET_CONFIRMED_SERVICE_DATA *service_data)
@@ -194,9 +197,9 @@ void handler_conf_private_trans(uint8_t *service_request,
&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
@@ -206,8 +209,9 @@ void handler_conf_private_trans(uint8_t *service_request,
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
@@ -247,8 +251,9 @@ void handler_conf_private_trans(uint8_t *service_request,
}
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:
pdu_len += len;
+14 -14
View File
@@ -1,13 +1,13 @@
/**
* @file
* @author Steve Karg
* @date October 2019
* @brief Header file for a basic ConfirmedPrivateTransfer service handler
*
* @section LICENSE
*
* SPDX-License-Identifier: MIT
*/
* @file
* @author Steve Karg
* @date October 2019
* @brief Header file for a basic ConfirmedPrivateTransfer service handler
*
* @section LICENSE
*
* SPDX-License-Identifier: MIT
*/
#ifndef HANDLER_CONFIRMED_PRIVATE_TRANSFER_H
#define HANDLER_CONFIRMED_PRIVATE_TRANSFER_H
@@ -24,11 +24,11 @@
extern "C" {
#endif /* __cplusplus */
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);
#ifdef __cplusplus
}
+10 -5
View File
@@ -36,8 +36,9 @@ static void DecodeBlock(char cBlockNum, uint8_t *pData)
iLen = 0;
if (cBlockNum >= MY_MAX_BLOCK)
if (cBlockNum >= MY_MAX_BLOCK) {
return;
}
tag_len =
decode_tag_number_and_value(&pData[iLen], &tag_number, &len_value_type);
@@ -136,12 +137,14 @@ static void ProcessPTA(BACNET_PRIVATE_TRANSFER_DATA *data)
cBlockNumber = (char)ulTemp;
DecodeBlock(cBlockNumber, &data->serviceParameters[iLen]);
} else { /* Read error */
printf("Private Transfer read operation returned error code: %lu\n",
printf(
"Private Transfer read operation returned error code: %lu\n",
(unsigned long)uiErrorCode);
return;
}
} else { /* Write I/O block - should just be an OK type message */
printf("Private Transfer write operation returned error code: %lu\n",
printf(
"Private Transfer write operation returned error code: %lu\n",
(unsigned long)uiErrorCode);
}
}
@@ -152,7 +155,8 @@ static void ProcessPTA(BACNET_PRIVATE_TRANSFER_DATA *data)
* and decide what to do next...
*/
void handler_conf_private_trans_ack(uint8_t *service_request,
void handler_conf_private_trans_ack(
uint8_t *service_request,
uint16_t service_len,
BACNET_ADDRESS *src,
BACNET_CONFIRMED_SERVICE_ACK_DATA *service_data)
@@ -176,7 +180,8 @@ void handler_conf_private_trans_ack(uint8_t *service_request,
printf("Received Confirmed Private Transfer Ack!\n");
#endif
len = ptransfer_decode_service_request(service_request, service_len,
len = ptransfer_decode_service_request(
service_request, service_len,
&data); /* Same decode for ack as for service request! */
if (len < 0) {
#if PRINT_ENABLED
+14 -14
View File
@@ -1,13 +1,13 @@
/**
* @file
* @author Steve Karg
* @date October 2019
* @brief Header file for a basic ConfirmedPrivateTransfer-Ack service handler
*
* @section LICENSE
*
* SPDX-License-Identifier: MIT
*/
* @file
* @author Steve Karg
* @date October 2019
* @brief Header file for a basic ConfirmedPrivateTransfer-Ack service handler
*
* @section LICENSE
*
* SPDX-License-Identifier: MIT
*/
#ifndef HANDLER_CONFIRMED_PRIVATE_TRANSFER_ACK_H
#define HANDLER_CONFIRMED_PRIVATE_TRANSFER_ACK_H
@@ -25,11 +25,11 @@
extern "C" {
#endif /* __cplusplus */
void handler_conf_private_trans_ack(
uint8_t * service_request,
uint16_t service_len,
BACNET_ADDRESS * src,
BACNET_CONFIRMED_SERVICE_ACK_DATA * service_data);
void handler_conf_private_trans_ack(
uint8_t *service_request,
uint16_t service_len,
BACNET_ADDRESS *src,
BACNET_CONFIRMED_SERVICE_ACK_DATA *service_data);
#ifdef __cplusplus
}
+18 -12
View File
@@ -68,7 +68,8 @@ static int Target_Mode = 0;
static BACNET_ADDRESS Target_Address;
static bool Error_Detected = false;
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)
@@ -76,14 +77,15 @@ static void MyErrorHandler(BACNET_ADDRESS *src,
/* FIXME: verify src and invoke id */
(void)src;
(void)invoke_id;
printf("BACnet Error: %s: %s\r\n",
bactext_error_class_name((int)error_class),
printf(
"BACnet Error: %s: %s\r\n", bactext_error_class_name((int)error_class),
bactext_error_code_name((int)error_code));
/* Error_Detected = true; */
}
/* complex error reply function */
static void MyPrivateTransferErrorHandler(BACNET_ADDRESS *src,
static void MyPrivateTransferErrorHandler(
BACNET_ADDRESS *src,
uint8_t invoke_id,
uint8_t service_choice,
uint8_t *service_request,
@@ -108,13 +110,14 @@ static void MyAbortHandler(
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;
printf("BACnet Reject: %s\r\n",
printf(
"BACnet Reject: %s\r\n",
bactext_reject_reason_name((int)reject_reason));
Error_Detected = true;
}
@@ -184,8 +187,9 @@ int main(int argc, char *argv[])
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"
" %s remote-device-instance\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(
@@ -220,7 +224,8 @@ int main(int argc, char *argv[])
Target_Device_Object_Instance = strtol(argv[1 + Target_Mode], NULL, 0);
if (Target_Device_Object_Instance > BACNET_MAX_INSTANCE) {
fprintf(stderr, "device-instance=%u - not greater than %u\r\n",
fprintf(
stderr, "device-instance=%u - not greater than %u\r\n",
Target_Device_Object_Instance, BACNET_MAX_INSTANCE);
return 1;
}
@@ -349,8 +354,9 @@ int main(int argc, char *argv[])
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,
+11 -6
View File
@@ -25,7 +25,8 @@
#include "bacnet/datalink/datalink.h"
#include "bacnet/basic/services.h"
uint8_t Send_Private_Transfer_Request(uint32_t device_id,
uint8_t Send_Private_Transfer_Request(
uint32_t device_id,
uint16_t vendor_id,
uint32_t service_number,
unsigned int block_number,
@@ -81,21 +82,25 @@ uint8_t Send_Private_Transfer_Request(uint32_t device_id,
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);
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,
if (bytes_sent <= 0) {
fprintf(
stderr,
"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,
fprintf(
stderr,
"Failed to Send Private Transfer Request "
"(exceeds destination maximum APDU)!\n");
#endif
+15 -12
View File
@@ -1,13 +1,13 @@
/**
* @file
* @author Steve Karg
* @date October 2019
* @brief Header file for a basic WritePropertyMultiple service send
*
* @section LICENSE
*
* SPDX-License-Identifier: MIT
*/
* @file
* @author Steve Karg
* @date October 2019
* @brief Header file for a basic WritePropertyMultiple service send
*
* @section LICENSE
*
* SPDX-License-Identifier: MIT
*/
#ifndef SEND_WRITE_PROPERTY_MULTIPLE_H
#define SEND_WRITE_PROPERTY_MULTIPLE_H
@@ -25,9 +25,12 @@
extern "C" {
#endif /* __cplusplus */
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);
#ifdef __cplusplus
}