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
+29 -44
View File
@@ -21,52 +21,37 @@
extern "C" {
#endif /* __cplusplus */
BACNET_STACK_EXPORT
void npdu_handler(
BACNET_ADDRESS * src,
uint8_t * pdu,
uint16_t pdu_len);
BACNET_STACK_EXPORT
void npdu_handler(BACNET_ADDRESS *src, uint8_t *pdu, uint16_t pdu_len);
BACNET_STACK_EXPORT
uint16_t npdu_network_number(void);
BACNET_STACK_EXPORT
void npdu_network_number_set(uint16_t net);
BACNET_STACK_EXPORT
int npdu_send_network_number_is(
BACNET_ADDRESS *dst,
uint16_t net,
uint8_t status);
BACNET_STACK_EXPORT
int npdu_send_what_is_network_number(
BACNET_ADDRESS *dst);
BACNET_STACK_EXPORT
uint16_t npdu_network_number(void);
BACNET_STACK_EXPORT
void npdu_network_number_set(uint16_t net);
BACNET_STACK_EXPORT
int npdu_send_network_number_is(
BACNET_ADDRESS *dst, uint16_t net, uint8_t status);
BACNET_STACK_EXPORT
int npdu_send_what_is_network_number(BACNET_ADDRESS *dst);
BACNET_STACK_EXPORT
void npdu_handler_cleanup(void);
BACNET_STACK_EXPORT
void npdu_handler_init(
uint16_t bip_net,
uint16_t mstp_net);
BACNET_STACK_EXPORT
void npdu_router_handler(
uint16_t snet,
BACNET_ADDRESS * src,
uint8_t * pdu,
uint16_t pdu_len);
BACNET_STACK_EXPORT
int npdu_router_send_pdu(
uint16_t dnet,
BACNET_ADDRESS * dest,
BACNET_NPDU_DATA * npdu_data,
uint8_t * pdu,
unsigned int pdu_len);
BACNET_STACK_EXPORT
void npdu_router_get_my_address(
uint16_t dnet,
BACNET_ADDRESS * my_address);
BACNET_STACK_EXPORT
int npdu_send_reject_message_to_network(
BACNET_ADDRESS *dst,
uint16_t net);
BACNET_STACK_EXPORT
void npdu_handler_cleanup(void);
BACNET_STACK_EXPORT
void npdu_handler_init(uint16_t bip_net, uint16_t mstp_net);
BACNET_STACK_EXPORT
void npdu_router_handler(
uint16_t snet, BACNET_ADDRESS *src, uint8_t *pdu, uint16_t pdu_len);
BACNET_STACK_EXPORT
int npdu_router_send_pdu(
uint16_t dnet,
BACNET_ADDRESS *dest,
BACNET_NPDU_DATA *npdu_data,
uint8_t *pdu,
unsigned int pdu_len);
BACNET_STACK_EXPORT
void npdu_router_get_my_address(uint16_t dnet, BACNET_ADDRESS *my_address);
BACNET_STACK_EXPORT
int npdu_send_reject_message_to_network(BACNET_ADDRESS *dst, uint16_t net);
#ifdef __cplusplus
}
+13 -7
View File
@@ -48,7 +48,8 @@
* 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,
static void network_control_handler(
BACNET_ADDRESS *src,
int *DNET_list,
BACNET_NPDU_DATA *npdu_data,
uint8_t *npdu,
@@ -86,7 +87,8 @@ static void network_control_handler(BACNET_ADDRESS *src,
* -- Unless we act upon NETWORK_MESSAGE_ROUTER_BUSY_TO_NETWORK
* later for congestion control - then it could matter.
*/
debug_printf("%s for Networks: ",
debug_printf(
"%s for Networks: ",
bactext_network_layer_msg_name(
NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK));
while (npdu_len >= 2) {
@@ -106,7 +108,8 @@ static void network_control_handler(BACNET_ADDRESS *src,
case NETWORK_MESSAGE_REJECT_MESSAGE_TO_NETWORK:
if (npdu_len >= 3) {
decode_unsigned16(&npdu[1], &dnet);
debug_printf("Received %s for Network: ",
debug_printf(
"Received %s for Network: ",
bactext_network_layer_msg_name(
NETWORK_MESSAGE_I_COULD_BE_ROUTER_TO_NETWORK));
debug_printf("%hu, Reason code: %d \n", dnet, npdu[0]);
@@ -175,7 +178,8 @@ static void network_control_handler(BACNET_ADDRESS *src,
* @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,
static void routed_apdu_handler(
BACNET_ADDRESS *src,
BACNET_ADDRESS *dest,
int *DNET_list,
uint8_t *apdu,
@@ -269,8 +273,9 @@ void routing_npdu_handler(
debug_printf("NPDU: Decoding failed; Discarded!\n");
} 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));
network_control_handler(
src, DNET_list, &npdu_data, &pdu[apdu_offset],
(uint16_t)(pdu_len - apdu_offset));
} else {
debug_printf("NPDU: message for our router? Discarded!\n");
/* The DNET is set, but we don't support downstream routers,
@@ -279,7 +284,8 @@ 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],
routed_apdu_handler(
src, &dest, DNET_list, &pdu[apdu_offset],
(uint16_t)(pdu_len - apdu_offset));
}
/* Else, hop_count bottomed out and we discard this one. */
+3 -6
View File
@@ -20,12 +20,9 @@
extern "C" {
#endif /* __cplusplus */
BACNET_STACK_EXPORT
void routing_npdu_handler(
BACNET_ADDRESS * src,
int *DNET_list,
uint8_t * pdu,
uint16_t pdu_len);
BACNET_STACK_EXPORT
void routing_npdu_handler(
BACNET_ADDRESS *src, int *DNET_list, uint8_t *pdu, uint16_t pdu_len);
#ifdef __cplusplus
}
+14 -9
View File
@@ -44,7 +44,8 @@
* 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,
int Send_Network_Layer_Message(
BACNET_NETWORK_MESSAGE_TYPE network_message_type,
BACNET_ADDRESS *dst,
const int *iArgs)
{
@@ -69,8 +70,9 @@ int Send_Network_Layer_Message(BACNET_NETWORK_MESSAGE_TYPE network_message_type,
if (network_message_type == NETWORK_MESSAGE_INIT_RT_TABLE) {
data_expecting_reply = true; /* DER in this one case */
}
npdu_encode_npdu_network(&npdu_data, network_message_type,
data_expecting_reply, MESSAGE_PRIORITY_NORMAL);
npdu_encode_npdu_network(
&npdu_data, network_message_type, data_expecting_reply,
MESSAGE_PRIORITY_NORMAL);
/* We don't need src information, since a message can't originate from
* our downstream BACnet network.
@@ -152,16 +154,19 @@ int Send_Network_Layer_Message(BACNET_NETWORK_MESSAGE_TYPE network_message_type,
break;
default:
debug_printf("Not sent: %s message unsupported \n",
debug_printf(
"Not sent: %s message unsupported \n",
bactext_network_layer_msg_name(network_message_type));
return 0;
}
if (dst != NULL) {
debug_printf("Sending %s message to BACnet network %u \n",
debug_printf(
"Sending %s message to BACnet network %u \n",
bactext_network_layer_msg_name(network_message_type), dst->net);
} else {
debug_printf("Sending %s message to local BACnet network \n",
debug_printf(
"Sending %s message to local BACnet network \n",
bactext_network_layer_msg_name(network_message_type));
}
@@ -171,7 +176,8 @@ int Send_Network_Layer_Message(BACNET_NETWORK_MESSAGE_TYPE network_message_type,
#if PRINT_ENABLED
if (bytes_sent <= 0) {
int wasErrno = errno; /* preserve the errno */
debug_printf("Failed to send %s message (%s)!\n",
debug_printf(
"Failed to send %s message (%s)!\n",
bactext_network_layer_msg_name(network_message_type),
strerror(wasErrno));
}
@@ -252,8 +258,7 @@ void Send_Reject_Message_To_Network(
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, DNET_list);
Send_Network_Layer_Message(NETWORK_MESSAGE_INIT_RT_TABLE, dst, DNET_list);
}
/** Sends our Routing Table, built from our DNET[] array, as an ACK.
+25 -36
View File
@@ -1,10 +1,10 @@
/**
* @file
* @author Steve Karg
* @date October 2019
* @brief Header file for a basic WritePropertyMultiple service send
* @copyright SPDX-License-Identifier: MIT
*/
* @file
* @author Steve Karg
* @date October 2019
* @brief Header file for a basic WritePropertyMultiple service send
* @copyright SPDX-License-Identifier: MIT
*/
#ifndef BACNET_BASIC_NPDU_SEND_ROUTER_H
#define BACNET_BASIC_NPDU_SEND_ROUTER_H
#include <stddef.h>
@@ -21,36 +21,25 @@
extern "C" {
#endif /* __cplusplus */
BACNET_STACK_EXPORT
int Send_Network_Layer_Message(
BACNET_NETWORK_MESSAGE_TYPE network_message_type,
BACNET_ADDRESS * dst,
const int *iArgs);
BACNET_STACK_EXPORT
void Send_Who_Is_Router_To_Network(
BACNET_ADDRESS * dst,
int dnet);
BACNET_STACK_EXPORT
void Send_I_Am_Router_To_Network(
const int DNET_list[]);
BACNET_STACK_EXPORT
void Send_Reject_Message_To_Network(
BACNET_ADDRESS * dst,
uint8_t reject_reason,
int dnet);
BACNET_STACK_EXPORT
void Send_Initialize_Routing_Table(
BACNET_ADDRESS * dst,
const int DNET_list[]);
BACNET_STACK_EXPORT
void Send_Initialize_Routing_Table_Ack(
BACNET_ADDRESS * dst,
const int DNET_list[]);
BACNET_STACK_EXPORT
void Send_Network_Number_Is(
BACNET_ADDRESS *dst,
int dnet,
int status);
BACNET_STACK_EXPORT
int Send_Network_Layer_Message(
BACNET_NETWORK_MESSAGE_TYPE network_message_type,
BACNET_ADDRESS *dst,
const int *iArgs);
BACNET_STACK_EXPORT
void Send_Who_Is_Router_To_Network(BACNET_ADDRESS *dst, int dnet);
BACNET_STACK_EXPORT
void Send_I_Am_Router_To_Network(const int DNET_list[]);
BACNET_STACK_EXPORT
void Send_Reject_Message_To_Network(
BACNET_ADDRESS *dst, uint8_t reject_reason, int dnet);
BACNET_STACK_EXPORT
void Send_Initialize_Routing_Table(BACNET_ADDRESS *dst, const int DNET_list[]);
BACNET_STACK_EXPORT
void Send_Initialize_Routing_Table_Ack(
BACNET_ADDRESS *dst, const int DNET_list[]);
BACNET_STACK_EXPORT
void Send_Network_Number_Is(BACNET_ADDRESS *dst, int dnet, int status);
#ifdef __cplusplus
}