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:
+38
-27
@@ -324,7 +324,8 @@ static void datalink_get_broadcast_address(BACNET_ADDRESS *dest)
|
||||
*
|
||||
* @return number of bytes sent
|
||||
*/
|
||||
static int datalink_send_pdu(uint16_t snet,
|
||||
static int datalink_send_pdu(
|
||||
uint16_t snet,
|
||||
BACNET_ADDRESS *dest,
|
||||
BACNET_NPDU_DATA *npdu_data,
|
||||
uint8_t *pdu,
|
||||
@@ -368,7 +369,8 @@ static void send_i_am_router_to_network(uint16_t snet, uint16_t net)
|
||||
DNET *dnet = NULL;
|
||||
|
||||
datalink_get_broadcast_address(&dest);
|
||||
npdu_encode_npdu_network(&npdu_data, NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK,
|
||||
npdu_encode_npdu_network(
|
||||
&npdu_data, NETWORK_MESSAGE_I_AM_ROUTER_TO_NETWORK,
|
||||
data_expecting_reply, MESSAGE_PRIORITY_NORMAL);
|
||||
/* We don't need src information, since a message can't originate from
|
||||
our downstream BACnet network. */
|
||||
@@ -419,8 +421,8 @@ static void send_i_am_router_to_network(uint16_t snet, uint16_t net)
|
||||
* Optionally may designate a particular router destination,
|
||||
* especially when ACKing receipt of this message type.
|
||||
*/
|
||||
static void send_initialize_routing_table_ack(
|
||||
uint8_t snet, const BACNET_ADDRESS *dst)
|
||||
static void
|
||||
send_initialize_routing_table_ack(uint8_t snet, const BACNET_ADDRESS *dst)
|
||||
{
|
||||
BACNET_ADDRESS dest;
|
||||
bool data_expecting_reply = false;
|
||||
@@ -436,8 +438,9 @@ static void send_initialize_routing_table_ack(
|
||||
} else {
|
||||
datalink_get_broadcast_address(&dest);
|
||||
}
|
||||
npdu_encode_npdu_network(&npdu_data, NETWORK_MESSAGE_INIT_RT_TABLE_ACK,
|
||||
data_expecting_reply, MESSAGE_PRIORITY_NORMAL);
|
||||
npdu_encode_npdu_network(
|
||||
&npdu_data, NETWORK_MESSAGE_INIT_RT_TABLE_ACK, data_expecting_reply,
|
||||
MESSAGE_PRIORITY_NORMAL);
|
||||
/* We don't need src information, since a message can't originate from
|
||||
our downstream BACnet network. */
|
||||
pdu_len = npdu_encode_pdu(&Tx_Buffer[0], &dest, NULL, &npdu_data);
|
||||
@@ -496,9 +499,9 @@ static void send_reject_message_to_network(
|
||||
} else {
|
||||
datalink_get_broadcast_address(&dest);
|
||||
}
|
||||
npdu_encode_npdu_network(&npdu_data,
|
||||
NETWORK_MESSAGE_REJECT_MESSAGE_TO_NETWORK, data_expecting_reply,
|
||||
MESSAGE_PRIORITY_NORMAL);
|
||||
npdu_encode_npdu_network(
|
||||
&npdu_data, NETWORK_MESSAGE_REJECT_MESSAGE_TO_NETWORK,
|
||||
data_expecting_reply, MESSAGE_PRIORITY_NORMAL);
|
||||
/* We don't need src information, since a message can't originate from
|
||||
our downstream BACnet network. */
|
||||
pdu_len = npdu_encode_pdu(&Tx_Buffer[0], &dest, NULL, &npdu_data);
|
||||
@@ -527,9 +530,9 @@ static void send_who_is_router_to_network(uint16_t snet, uint16_t dnet)
|
||||
int len = 0;
|
||||
|
||||
datalink_get_broadcast_address(&dest);
|
||||
npdu_encode_npdu_network(&npdu_data,
|
||||
NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK, data_expecting_reply,
|
||||
MESSAGE_PRIORITY_NORMAL);
|
||||
npdu_encode_npdu_network(
|
||||
&npdu_data, NETWORK_MESSAGE_WHO_IS_ROUTER_TO_NETWORK,
|
||||
data_expecting_reply, MESSAGE_PRIORITY_NORMAL);
|
||||
pdu_len = npdu_encode_pdu(&Tx_Buffer[0], &dest, NULL, &npdu_data);
|
||||
if (dnet) {
|
||||
len = encode_unsigned16(&Tx_Buffer[pdu_len], dnet);
|
||||
@@ -595,7 +598,8 @@ static void send_who_is_router_to_network(uint16_t snet, uint16_t dnet)
|
||||
* bytes that have already been decoded.
|
||||
* @param npdu_len [in] The length of the remaining NPDU message in npdu[].
|
||||
*/
|
||||
static void who_is_router_to_network_handler(uint16_t snet,
|
||||
static void who_is_router_to_network_handler(
|
||||
uint16_t snet,
|
||||
const BACNET_ADDRESS *src,
|
||||
const BACNET_NPDU_DATA *npdu_data,
|
||||
const uint8_t *npdu,
|
||||
@@ -648,7 +652,8 @@ static void who_is_router_to_network_handler(uint16_t snet,
|
||||
* bytes that have already been decoded.
|
||||
* @param npdu_len [in] The length of the remaining NPDU message in npdu[].
|
||||
*/
|
||||
static void network_control_handler(uint16_t snet,
|
||||
static void network_control_handler(
|
||||
uint16_t snet,
|
||||
BACNET_ADDRESS *src,
|
||||
BACNET_NPDU_DATA *npdu_data,
|
||||
uint8_t *npdu,
|
||||
@@ -826,7 +831,8 @@ static void routed_src_address(
|
||||
* @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(uint16_t snet,
|
||||
static void routed_apdu_handler(
|
||||
uint16_t snet,
|
||||
BACNET_NPDU_DATA *npdu,
|
||||
BACNET_ADDRESS *src,
|
||||
BACNET_ADDRESS *dest,
|
||||
@@ -865,7 +871,8 @@ static void routed_apdu_handler(uint16_t snet,
|
||||
port = Router_Table_Head;
|
||||
while (port != NULL) {
|
||||
if (port->net != snet) {
|
||||
datalink_send_pdu(port->net, &local_dest, npdu, &Tx_Buffer[0],
|
||||
datalink_send_pdu(
|
||||
port->net, &local_dest, npdu, &Tx_Buffer[0],
|
||||
npdu_len + apdu_len);
|
||||
}
|
||||
port = port->next;
|
||||
@@ -892,7 +899,8 @@ static void routed_apdu_handler(uint16_t snet,
|
||||
npdu_len =
|
||||
npdu_encode_pdu(&Tx_Buffer[0], &local_dest, &router_src, npdu);
|
||||
memmove(&Tx_Buffer[npdu_len], apdu, apdu_len);
|
||||
datalink_send_pdu(port->net, &local_dest, npdu, &Tx_Buffer[0],
|
||||
datalink_send_pdu(
|
||||
port->net, &local_dest, npdu, &Tx_Buffer[0],
|
||||
npdu_len + apdu_len);
|
||||
} else {
|
||||
log_printf(
|
||||
@@ -909,7 +917,8 @@ static void routed_apdu_handler(uint16_t snet,
|
||||
npdu_len =
|
||||
npdu_encode_pdu(&Tx_Buffer[0], &remote_dest, &router_src, npdu);
|
||||
memmove(&Tx_Buffer[npdu_len], apdu, apdu_len);
|
||||
datalink_send_pdu(port->net, &remote_dest, npdu, &Tx_Buffer[0],
|
||||
datalink_send_pdu(
|
||||
port->net, &remote_dest, npdu, &Tx_Buffer[0],
|
||||
npdu_len + apdu_len);
|
||||
}
|
||||
} else if (dest->net) {
|
||||
@@ -925,8 +934,8 @@ static void routed_apdu_handler(uint16_t snet,
|
||||
port = Router_Table_Head;
|
||||
while (port != NULL) {
|
||||
if (port->net != snet) {
|
||||
datalink_send_pdu(port->net, dest, npdu, &Tx_Buffer[0],
|
||||
npdu_len + apdu_len);
|
||||
datalink_send_pdu(
|
||||
port->net, dest, npdu, &Tx_Buffer[0], npdu_len + apdu_len);
|
||||
}
|
||||
port = port->next;
|
||||
}
|
||||
@@ -966,8 +975,9 @@ static void my_routing_npdu_handler(
|
||||
fprintf(stderr, "NPDU: Decoding failed; Discarded!\n");
|
||||
} else if (npdu_data.network_layer_message) {
|
||||
if ((dest.net == 0) || (dest.net == BACNET_BROADCAST_NETWORK)) {
|
||||
network_control_handler(snet, src, &npdu_data,
|
||||
&pdu[apdu_offset], (uint16_t)(pdu_len - apdu_offset));
|
||||
network_control_handler(
|
||||
snet, src, &npdu_data, &pdu[apdu_offset],
|
||||
(uint16_t)(pdu_len - apdu_offset));
|
||||
} else {
|
||||
/* The DNET is set, but we don't support downstream routers,
|
||||
* so we just silently drop this network layer message,
|
||||
@@ -981,17 +991,19 @@ static void my_routing_npdu_handler(
|
||||
routing information cause they are not for us */
|
||||
if ((dest.net == BACNET_BROADCAST_NETWORK) &&
|
||||
((pdu[apdu_offset] & 0xF0) ==
|
||||
PDU_TYPE_CONFIRMED_SERVICE_REQUEST)) {
|
||||
PDU_TYPE_CONFIRMED_SERVICE_REQUEST)) {
|
||||
/* hack for 5.4.5.1 - IDLE */
|
||||
/* ConfirmedBroadcastReceived */
|
||||
/* then enter IDLE - ignore the PDU */
|
||||
} else {
|
||||
routed_apdu_handler(snet, &npdu_data, src, &dest,
|
||||
&pdu[apdu_offset], (uint16_t)(pdu_len - apdu_offset));
|
||||
routed_apdu_handler(
|
||||
snet, &npdu_data, src, &dest, &pdu[apdu_offset],
|
||||
(uint16_t)(pdu_len - apdu_offset));
|
||||
/* add a Device object and application layer */
|
||||
if ((dest.net == 0) ||
|
||||
(dest.net == BACNET_BROADCAST_NETWORK)) {
|
||||
apdu_handler(src, &pdu[apdu_offset],
|
||||
apdu_handler(
|
||||
src, &pdu[apdu_offset],
|
||||
(uint16_t)(pdu_len - apdu_offset));
|
||||
}
|
||||
}
|
||||
@@ -1151,7 +1163,6 @@ static void control_c_hooks(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef FUZZING
|
||||
/**
|
||||
* Main function of simple router demo.
|
||||
|
||||
Reference in New Issue
Block a user