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
+43 -27
View File
@@ -37,14 +37,22 @@ static TL_LOG_INFO LogInfo[MAX_TREND_LOGS];
/* These three arrays are used by the ReadPropertyMultiple handler */
static const int Trend_Log_Properties_Required[] = { PROP_OBJECT_IDENTIFIER,
PROP_OBJECT_NAME, PROP_OBJECT_TYPE, PROP_ENABLE, PROP_STOP_WHEN_FULL,
PROP_BUFFER_SIZE, PROP_LOG_BUFFER, PROP_RECORD_COUNT,
PROP_TOTAL_RECORD_COUNT, PROP_EVENT_STATE, PROP_LOGGING_TYPE,
PROP_STATUS_FLAGS, -1 };
PROP_OBJECT_NAME,
PROP_OBJECT_TYPE,
PROP_ENABLE,
PROP_STOP_WHEN_FULL,
PROP_BUFFER_SIZE,
PROP_LOG_BUFFER,
PROP_RECORD_COUNT,
PROP_TOTAL_RECORD_COUNT,
PROP_EVENT_STATE,
PROP_LOGGING_TYPE,
PROP_STATUS_FLAGS,
-1 };
static const int Trend_Log_Properties_Optional[] = { PROP_DESCRIPTION,
PROP_START_TIME, PROP_STOP_TIME, PROP_LOG_DEVICE_OBJECT_PROPERTY,
PROP_LOG_INTERVAL,
static const int Trend_Log_Properties_Optional[] = {
PROP_DESCRIPTION, PROP_START_TIME, PROP_STOP_TIME,
PROP_LOG_DEVICE_OBJECT_PROPERTY, PROP_LOG_INTERVAL,
/* Required if COV logging supported
PROP_COV_RESUBSCRIPTION_INTERVAL,
@@ -60,7 +68,8 @@ static const int Trend_Log_Properties_Optional[] = { PROP_DESCRIPTION,
PROP_NOTIFY_TYPE,
PROP_EVENT_TIME_STAMPS, */
PROP_ALIGN_INTERVALS, PROP_INTERVAL_OFFSET, PROP_TRIGGER, -1 };
PROP_ALIGN_INTERVALS, PROP_INTERVAL_OFFSET, PROP_TRIGGER, -1
};
static const int Trend_Log_Properties_Proprietary[] = { -1 };
@@ -234,7 +243,8 @@ bool Trend_Log_Object_Name(
bool status = false;
if (object_instance < MAX_TREND_LOGS) {
snprintf(text, sizeof(text), "Trend Log %lu",
snprintf(
text, sizeof(text), "Trend Log %lu",
(unsigned long)object_instance);
status = characterstring_init_ansi(object_name, text);
}
@@ -569,9 +579,9 @@ bool Trend_Log_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
}
start_date = value.type.Date;
/* Then decode the time part */
len =
bacapp_decode_application_data(wp_data->application_data + len,
wp_data->application_data_len - len, &value);
len = bacapp_decode_application_data(
wp_data->application_data + len,
wp_data->application_data_len - len, &value);
if (len) {
status = write_property_type_valid(
@@ -620,9 +630,9 @@ bool Trend_Log_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
}
stop_date = value.type.Date;
/* Then decode the time part */
len =
bacapp_decode_application_data(wp_data->application_data + len,
wp_data->application_data_len - len, &value);
len = bacapp_decode_application_data(
wp_data->application_data + len,
wp_data->application_data_len - len, &value);
if (len) {
status = write_property_type_valid(
@@ -664,7 +674,7 @@ bool Trend_Log_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
case PROP_LOG_DEVICE_OBJECT_PROPERTY:
len = bacnet_device_object_property_reference_decode(
wp_data->application_data,wp_data->application_data_len,
wp_data->application_data, wp_data->application_data_len,
&TempSource);
if (len <= 0) {
wp_data->error_class = ERROR_CLASS_PROPERTY;
@@ -674,7 +684,7 @@ bool Trend_Log_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
/* We only support references to objects in ourself for now */
if ((TempSource.deviceIdentifier.type == OBJECT_DEVICE) &&
(TempSource.deviceIdentifier.instance !=
Device_Object_Instance_Number())) {
Device_Object_Instance_Number())) {
wp_data->error_class = ERROR_CLASS_PROPERTY;
wp_data->error_code =
ERROR_CODE_OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED;
@@ -682,7 +692,8 @@ bool Trend_Log_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
}
/* Quick comparison if structures are packed ... */
if (memcmp(&TempSource, &CurrentLog->Source,
if (memcmp(
&TempSource, &CurrentLog->Source,
sizeof(BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE)) != 0) {
/* Clear buffer if property being logged is changed */
CurrentLog->ulRecordCount = 0;
@@ -866,7 +877,8 @@ bool TL_Is_Enabled(int iLog)
if (CurrentLog->bEnable == false) {
/* Not enabled so time is irrelevant */
bStatus = false;
} else if ((CurrentLog->ucTimeFlags == 0) &&
} else if (
(CurrentLog->ucTimeFlags == 0) &&
(CurrentLog->tStopTime < CurrentLog->tStartTime)) {
/* Start time was after stop time as per 12.25.6 and 12.25.7 */
bStatus = false;
@@ -1444,12 +1456,13 @@ int TL_encode_entry(uint8_t *apdu, int iLog, int iEntry)
* have limited to 32 bits maximum as allowed by the standard
*/
bitstring_init(&TempBits);
bitstring_set_bits_used(&TempBits,
(pSource->Datum.Bits.ucLen >> 4) & 0x0F,
bitstring_set_bits_used(
&TempBits, (pSource->Datum.Bits.ucLen >> 4) & 0x0F,
pSource->Datum.Bits.ucLen & 0x0F);
for (ucCount = pSource->Datum.Bits.ucLen >> 4; ucCount > 0;
ucCount--) {
bitstring_set_octet(&TempBits, ucCount - 1,
bitstring_set_octet(
&TempBits, ucCount - 1,
pSource->Datum.Bits.ucStore[ucCount - 1]);
}
@@ -1496,7 +1509,8 @@ int TL_encode_entry(uint8_t *apdu, int iLog, int iEntry)
return (iLen);
}
static int local_read_property(uint8_t *value,
static int local_read_property(
uint8_t *value,
uint8_t *status,
const BACNET_DEVICE_OBJECT_PROPERTY_REFERENCE *Source,
BACNET_ERROR_CLASS *error_class,
@@ -1699,12 +1713,13 @@ void trend_log_timer(uint16_t uSeconds)
* CurrentLog->ulLogInterval)) { */
if ((tNow % CurrentLog->ulLogInterval) ==
(CurrentLog->ulIntervalOffset %
CurrentLog->ulLogInterval)) {
CurrentLog->ulLogInterval)) {
/* Record value if time synchronised trigger condition
* is met and at least one period has elapsed.
*/
TL_fetch_property(iCount);
} else if ((tNow - CurrentLog->tLastDataTime) >
} else if (
(tNow - CurrentLog->tLastDataTime) >
CurrentLog->ulLogInterval) {
/* Also record value if we have waited more than a
* period since the last reading. This ensures we take a
@@ -1713,8 +1728,9 @@ void trend_log_timer(uint16_t uSeconds)
*/
TL_fetch_property(iCount);
}
} else if (((tNow - CurrentLog->tLastDataTime) >=
CurrentLog->ulLogInterval) ||
} else if (
((tNow - CurrentLog->tLastDataTime) >=
CurrentLog->ulLogInterval) ||
(CurrentLog->bTrigger == true)) {
/* If not aligned take a reading when we have either waited
* long enough or a trigger is set.