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
+33 -25
View File
@@ -36,7 +36,8 @@ static int printf_stderr(const char *format, ...)
return length;
}
#else
static int printf_stderr(const char *format, ...) {
static int printf_stderr(const char *format, ...)
{
(void)format;
return 0;
}
@@ -113,8 +114,8 @@ void bvlc6_maintenance_timer(uint16_t seconds)
*
* @return true if the address was set
*/
static bool bbmd6_address_from_vmac(
BACNET_IP6_ADDRESS *addr, const struct vmac_data *vmac)
static bool
bbmd6_address_from_vmac(BACNET_IP6_ADDRESS *addr, const struct vmac_data *vmac)
{
bool status = false;
unsigned int i = 0;
@@ -138,8 +139,8 @@ static bool bbmd6_address_from_vmac(
*
* @return true if the address was set
*/
static bool bbmd6_address_to_vmac(
struct vmac_data *vmac, const BACNET_IP6_ADDRESS *addr)
static bool
bbmd6_address_to_vmac(struct vmac_data *vmac, const BACNET_IP6_ADDRESS *addr)
{
bool status = false;
unsigned int i = 0;
@@ -178,13 +179,15 @@ static void bbmd6_add_vmac(uint32_t device_id, const BACNET_IP6_ADDRESS *addr)
} else {
/* VMAC exists, but device ID changed */
VMAC_Delete(list_device_id);
PRINTF("BVLC6: VMAC existed for %u [",
PRINTF(
"BVLC6: VMAC existed for %u [",
(unsigned int)list_device_id);
for (i = 0; i < new_vmac.mac_len; i++) {
PRINTF("%02X", new_vmac.mac[i]);
}
PRINTF("]\n");
PRINTF("BVLC6: Removed VMAC for %lu.\n",
PRINTF(
"BVLC6: Removed VMAC for %lu.\n",
(unsigned long)list_device_id);
}
}
@@ -193,25 +196,23 @@ static void bbmd6_add_vmac(uint32_t device_id, const BACNET_IP6_ADDRESS *addr)
if (vmac) {
/* device ID already exists. Update MAC. */
memmove(vmac, &new_vmac, sizeof(struct vmac_data));
PRINTF("BVLC6: VMAC for %u [",
(unsigned int)device_id);
PRINTF("BVLC6: VMAC for %u [", (unsigned int)device_id);
for (i = 0; i < new_vmac.mac_len; i++) {
PRINTF("%02X", new_vmac.mac[i]);
}
PRINTF("]\n");
PRINTF("BVLC6: Updated VMAC for %lu.\n",
(unsigned long)device_id);
PRINTF(
"BVLC6: Updated VMAC for %lu.\n", (unsigned long)device_id);
} else {
/* new entry - add it! */
VMAC_Add(device_id, &new_vmac);
PRINTF("BVLC6: VMAC for %u [",
(unsigned int)device_id);
PRINTF("BVLC6: VMAC for %u [", (unsigned int)device_id);
for (i = 0; i < new_vmac.mac_len; i++) {
PRINTF("%02X", new_vmac.mac[i]);
}
PRINTF("]\n");
PRINTF("BVLC6: Added VMAC for %lu.\n",
(unsigned long)device_id);
PRINTF(
"BVLC6: Added VMAC for %lu.\n", (unsigned long)device_id);
}
}
}
@@ -260,7 +261,8 @@ static bool bbmd6_address_from_bacnet_address(
if (status) {
vmac = VMAC_Find_By_Key(device_id);
if (vmac) {
PRINTF("BVLC6: Found VMAC %lu (len=%u).\n",
PRINTF(
"BVLC6: Found VMAC %lu (len=%u).\n",
(unsigned long)device_id, (unsigned)vmac->mac_len);
status = bbmd6_address_from_vmac(addr, vmac);
if (vmac_src) {
@@ -285,7 +287,8 @@ static bool bbmd6_address_from_bacnet_address(
* @return Upon successful completion, returns the number of bytes sent.
* Otherwise, -1 shall be returned and errno set to indicate the error.
*/
int bvlc6_send_pdu(const BACNET_ADDRESS *dest,
int bvlc6_send_pdu(
const BACNET_ADDRESS *dest,
const BACNET_NPDU_DATA *npdu_data,
const uint8_t *pdu,
unsigned pdu_len)
@@ -408,7 +411,8 @@ static void bbmd6_send_pdu_fdt(uint8_t *mtu, unsigned int mtu_len)
* @param npdu - the bytes of NPDU+APDU data to send
* @param npdu_len - the number of bytes of NPDU+APDU data to send
*/
static void bbmd6_send_forward_npdu(BACNET_IP6_ADDRESS *address,
static void bbmd6_send_forward_npdu(
BACNET_IP6_ADDRESS *address,
uint32_t vmac_src,
uint8_t *npdu,
unsigned int npdu_len)
@@ -647,7 +651,8 @@ static void bbmd6_address_resolution_ack_handler(
*
* @return number of bytes offset into the NPDU for APDU, or 0 if handled
*/
int bvlc6_bbmd_disabled_handler(BACNET_IP6_ADDRESS *addr,
int bvlc6_bbmd_disabled_handler(
BACNET_IP6_ADDRESS *addr,
BACNET_ADDRESS *src,
uint8_t *mtu,
uint16_t mtu_len)
@@ -766,8 +771,9 @@ int bvlc6_bbmd_disabled_handler(BACNET_IP6_ADDRESS *addr,
/* ignore messages from my IPv6 address */
PRINTF("BIP6: Forwarded-NPDU is me!\n");
} else {
function_len = bvlc6_decode_forwarded_npdu(pdu, pdu_len,
&vmac_src, &fwd_address, NULL, 0, &npdu_len);
function_len = bvlc6_decode_forwarded_npdu(
pdu, pdu_len, &vmac_src, &fwd_address, NULL, 0,
&npdu_len);
if (function_len) {
/* The Virtual MAC address table shall be updated
using the respective parameter values of the
@@ -825,7 +831,8 @@ int bvlc6_bbmd_disabled_handler(BACNET_IP6_ADDRESS *addr,
*
* @return number of bytes offset into the NPDU for APDU, or 0 if handled
*/
int bvlc6_bbmd_enabled_handler(BACNET_IP6_ADDRESS *addr,
int bvlc6_bbmd_enabled_handler(
BACNET_IP6_ADDRESS *addr,
BACNET_ADDRESS *src,
uint8_t *mtu,
uint16_t mtu_len)
@@ -1020,7 +1027,8 @@ int bvlc6_bbmd_enabled_handler(BACNET_IP6_ADDRESS *addr,
*
* @return number of bytes offset into the NPDU for APDU, or 0 if handled
*/
int bvlc6_handler(BACNET_IP6_ADDRESS *addr,
int bvlc6_handler(
BACNET_IP6_ADDRESS *addr,
BACNET_ADDRESS *src,
uint8_t *npdu,
uint16_t npdu_len)
@@ -1041,8 +1049,8 @@ int bvlc6_handler(BACNET_IP6_ADDRESS *addr,
* 0 if no registration request is sent, or
* -1 if registration fails.
*/
int bvlc6_register_with_bbmd(const BACNET_IP6_ADDRESS *bbmd_addr,
uint16_t ttl_seconds)
int bvlc6_register_with_bbmd(
const BACNET_IP6_ADDRESS *bbmd_addr, uint16_t ttl_seconds)
{
uint8_t mtu[BIP6_MPDU_MAX] = { 0 };
uint16_t mtu_len = 0;
+44 -48
View File
@@ -20,66 +20,62 @@
extern "C" {
#endif /* __cplusplus */
/* user application function prototypes */
BACNET_STACK_EXPORT
int bvlc6_handler(
BACNET_IP6_ADDRESS *addr,
BACNET_ADDRESS * src,
uint8_t * npdu,
uint16_t npdu_len);
/* user application function prototypes */
BACNET_STACK_EXPORT
int bvlc6_handler(
BACNET_IP6_ADDRESS *addr,
BACNET_ADDRESS *src,
uint8_t *npdu,
uint16_t npdu_len);
BACNET_STACK_EXPORT
int bvlc6_bbmd_enabled_handler(BACNET_IP6_ADDRESS *addr,
BACNET_ADDRESS *src,
uint8_t *mtu,
uint16_t mtu_len);
BACNET_STACK_EXPORT
int bvlc6_bbmd_enabled_handler(
BACNET_IP6_ADDRESS *addr,
BACNET_ADDRESS *src,
uint8_t *mtu,
uint16_t mtu_len);
BACNET_STACK_EXPORT
int bvlc6_bbmd_disabled_handler(BACNET_IP6_ADDRESS *addr,
BACNET_ADDRESS *src,
uint8_t *mtu,
uint16_t mtu_len);
BACNET_STACK_EXPORT
int bvlc6_bbmd_disabled_handler(
BACNET_IP6_ADDRESS *addr,
BACNET_ADDRESS *src,
uint8_t *mtu,
uint16_t mtu_len);
BACNET_STACK_EXPORT
int bvlc6_send_pdu(const BACNET_ADDRESS *dest,
const BACNET_NPDU_DATA *npdu_data,
const uint8_t *pdu,
unsigned pdu_len);
BACNET_STACK_EXPORT
int bvlc6_send_pdu(
const BACNET_ADDRESS *dest,
const BACNET_NPDU_DATA *npdu_data,
const uint8_t *pdu,
unsigned pdu_len);
BACNET_STACK_EXPORT
int bvlc6_register_with_bbmd(
const BACNET_IP6_ADDRESS *bbmd_addr,
uint16_t time_to_live_seconds);
BACNET_STACK_EXPORT
int bvlc6_register_with_bbmd(
const BACNET_IP6_ADDRESS *bbmd_addr, uint16_t time_to_live_seconds);
BACNET_STACK_EXPORT
void bvlc6_remote_bbmd_address(
BACNET_IP6_ADDRESS *bbmd_addr);
BACNET_STACK_EXPORT
void bvlc6_remote_bbmd_address(BACNET_IP6_ADDRESS *bbmd_addr);
BACNET_STACK_EXPORT
uint16_t bvlc6_remote_bbmd_lifetime(
void);
BACNET_STACK_EXPORT
uint16_t bvlc6_remote_bbmd_lifetime(void);
BACNET_STACK_EXPORT
uint16_t bvlc6_get_last_result(
void);
BACNET_STACK_EXPORT
uint16_t bvlc6_get_last_result(void);
BACNET_STACK_EXPORT
uint8_t bvlc6_get_function_code(
void);
BACNET_STACK_EXPORT
uint8_t bvlc6_get_function_code(void);
BACNET_STACK_EXPORT
void bvlc6_maintenance_timer(
uint16_t seconds);
BACNET_STACK_EXPORT
void bvlc6_maintenance_timer(uint16_t seconds);
BACNET_STACK_EXPORT
void bvlc6_debug_enable(
void);
BACNET_STACK_EXPORT
void bvlc6_debug_enable(void);
BACNET_STACK_EXPORT
void bvlc6_cleanup(void);
BACNET_STACK_EXPORT
void bvlc6_cleanup(void);
BACNET_STACK_EXPORT
void bvlc6_init(void);
BACNET_STACK_EXPORT
void bvlc6_init(void);
#ifdef __cplusplus
}
+2 -5
View File
@@ -127,8 +127,7 @@ struct vmac_data *VMAC_Find_By_Key(uint32_t device_id)
* @return true if the addresses are different
*/
bool VMAC_Different(
const struct vmac_data *vmac1,
const struct vmac_data *vmac2)
const struct vmac_data *vmac1, const struct vmac_data *vmac2)
{
bool status = false;
unsigned int i = 0;
@@ -159,9 +158,7 @@ bool VMAC_Different(
*
* @return true if the addresses are the same
*/
bool VMAC_Match(
const struct vmac_data *vmac1,
const struct vmac_data *vmac2)
bool VMAC_Match(const struct vmac_data *vmac1, const struct vmac_data *vmac2)
{
bool status = false;
unsigned int i = 0;
+25 -28
View File
@@ -16,10 +16,10 @@
/* define the max MAC as big as IPv6 + port number */
#define VMAC_MAC_MAX 18
/**
* VMAC data structure
*
* @{
*/
* VMAC data structure
*
* @{
*/
struct vmac_data {
uint8_t mac[VMAC_MAC_MAX];
uint8_t mac_len;
@@ -30,30 +30,27 @@ struct vmac_data {
extern "C" {
#endif /* __cplusplus */
BACNET_STACK_EXPORT
unsigned int VMAC_Count(void);
BACNET_STACK_EXPORT
struct vmac_data *VMAC_Find_By_Key(uint32_t device_id);
BACNET_STACK_EXPORT
bool VMAC_Find_By_Data(const struct vmac_data *vmac, uint32_t *device_id);
BACNET_STACK_EXPORT
bool VMAC_Add(uint32_t device_id, const struct vmac_data *pVMAC);
BACNET_STACK_EXPORT
bool VMAC_Delete(uint32_t device_id);
BACNET_STACK_EXPORT
bool VMAC_Different(
const struct vmac_data *vmac1,
const struct vmac_data *vmac2);
BACNET_STACK_EXPORT
bool VMAC_Match(
const struct vmac_data *vmac1,
const struct vmac_data *vmac2);
BACNET_STACK_EXPORT
void VMAC_Cleanup(void);
BACNET_STACK_EXPORT
void VMAC_Init(void);
BACNET_STACK_EXPORT
void VMAC_Debug_Enable(void);
BACNET_STACK_EXPORT
unsigned int VMAC_Count(void);
BACNET_STACK_EXPORT
struct vmac_data *VMAC_Find_By_Key(uint32_t device_id);
BACNET_STACK_EXPORT
bool VMAC_Find_By_Data(const struct vmac_data *vmac, uint32_t *device_id);
BACNET_STACK_EXPORT
bool VMAC_Add(uint32_t device_id, const struct vmac_data *pVMAC);
BACNET_STACK_EXPORT
bool VMAC_Delete(uint32_t device_id);
BACNET_STACK_EXPORT
bool VMAC_Different(
const struct vmac_data *vmac1, const struct vmac_data *vmac2);
BACNET_STACK_EXPORT
bool VMAC_Match(const struct vmac_data *vmac1, const struct vmac_data *vmac2);
BACNET_STACK_EXPORT
void VMAC_Cleanup(void);
BACNET_STACK_EXPORT
void VMAC_Init(void);
BACNET_STACK_EXPORT
void VMAC_Debug_Enable(void);
#ifdef __cplusplus
}