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:
+47
-36
@@ -63,22 +63,24 @@ static void MyPrintHandler(
|
||||
BACNET_ERROR_CODE error_code,
|
||||
uint32_t first_failed_element_number)
|
||||
{
|
||||
printf("[{\n \"%s\": {\n"
|
||||
printf(
|
||||
"[{\n \"%s\": {\n"
|
||||
" \"object-type\": \"%s\",\n \"object-instance\": %lu,\n"
|
||||
" \"error-class\": \"%s\",\n \"error-code\": \"%s\"",
|
||||
bactext_confirmed_service_name(SERVICE_CONFIRMED_CREATE_OBJECT),
|
||||
bactext_object_type_name(object_type),
|
||||
(unsigned long)object_instance,
|
||||
bactext_object_type_name(object_type), (unsigned long)object_instance,
|
||||
bactext_error_class_name((int)error_class),
|
||||
bactext_error_code_name((int)error_code));
|
||||
if (first_failed_element_number > 0) {
|
||||
printf(",\n \"first-failed-element-number\": %lu",
|
||||
printf(
|
||||
",\n \"first-failed-element-number\": %lu",
|
||||
(unsigned long)first_failed_element_number);
|
||||
}
|
||||
printf("\n }\n}]\n");
|
||||
}
|
||||
|
||||
static void MyCreateObjectErrorHandler(BACNET_ADDRESS *src,
|
||||
static void MyCreateObjectErrorHandler(
|
||||
BACNET_ADDRESS *src,
|
||||
uint8_t invoke_id,
|
||||
uint8_t service_choice,
|
||||
uint8_t *service_request,
|
||||
@@ -90,18 +92,19 @@ static void MyCreateObjectErrorHandler(BACNET_ADDRESS *src,
|
||||
(void)service_choice;
|
||||
if (address_match(&Target_Address, src) &&
|
||||
(invoke_id == Request_Invoke_ID)) {
|
||||
len = create_object_error_ack_service_decode(service_request,
|
||||
service_len, &data);
|
||||
len = create_object_error_ack_service_decode(
|
||||
service_request, service_len, &data);
|
||||
if (len > 0) {
|
||||
MyPrintHandler(data.object_type, data.object_instance,
|
||||
data.error_class, data.error_code,
|
||||
data.first_failed_element_number);
|
||||
MyPrintHandler(
|
||||
data.object_type, data.object_instance, data.error_class,
|
||||
data.error_code, data.first_failed_element_number);
|
||||
}
|
||||
Error_Detected = true;
|
||||
}
|
||||
}
|
||||
|
||||
static void MyCreateObjectAckHandler(uint8_t *service_request,
|
||||
static void MyCreateObjectAckHandler(
|
||||
uint8_t *service_request,
|
||||
uint16_t service_len,
|
||||
BACNET_ADDRESS *src,
|
||||
BACNET_CONFIRMED_SERVICE_ACK_DATA *service_data)
|
||||
@@ -114,11 +117,13 @@ static void MyCreateObjectAckHandler(uint8_t *service_request,
|
||||
len = create_object_ack_service_decode(
|
||||
service_request, service_len, &data);
|
||||
if (len < 0) {
|
||||
MyPrintHandler(Target_Object_Type, Target_Object_Instance,
|
||||
MyPrintHandler(
|
||||
Target_Object_Type, Target_Object_Instance,
|
||||
ERROR_CLASS_SERVICES, ERROR_CODE_REJECT_OTHER, 0);
|
||||
} else {
|
||||
MyPrintHandler(data.object_type, data.object_instance,
|
||||
ERROR_CLASS_SERVICES, ERROR_CODE_SUCCESS, 0);
|
||||
MyPrintHandler(
|
||||
data.object_type, data.object_instance, ERROR_CLASS_SERVICES,
|
||||
ERROR_CODE_SUCCESS, 0);
|
||||
}
|
||||
} else {
|
||||
if (Verbose) {
|
||||
@@ -133,20 +138,21 @@ static void MyAbortHandler(
|
||||
(void)server;
|
||||
if (address_match(&Target_Address, src) &&
|
||||
(invoke_id == Request_Invoke_ID)) {
|
||||
MyPrintHandler(Target_Object_Type, Target_Object_Instance,
|
||||
ERROR_CLASS_SERVICES, abort_convert_to_error_code(abort_reason), 0);
|
||||
MyPrintHandler(
|
||||
Target_Object_Type, Target_Object_Instance, ERROR_CLASS_SERVICES,
|
||||
abort_convert_to_error_code(abort_reason), 0);
|
||||
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 */
|
||||
if (address_match(&Target_Address, src) &&
|
||||
(invoke_id == Request_Invoke_ID)) {
|
||||
MyPrintHandler(Target_Object_Type, Target_Object_Instance,
|
||||
ERROR_CLASS_SERVICES,
|
||||
MyPrintHandler(
|
||||
Target_Object_Type, Target_Object_Instance, ERROR_CLASS_SERVICES,
|
||||
reject_convert_to_error_code(reject_reason), 0);
|
||||
Error_Detected = true;
|
||||
}
|
||||
@@ -207,10 +213,11 @@ static void print_help(const char *filename)
|
||||
"you are creating. For example, if you were writing\n"
|
||||
"Analog Output 2, the object-instance would be 2.\n");
|
||||
printf("\n");
|
||||
printf("Example:\n"
|
||||
"If you want to CreateObject of an Analog Input 1\n"
|
||||
"send the following command:\n"
|
||||
"%s 123 0 1\n",
|
||||
printf(
|
||||
"Example:\n"
|
||||
"If you want to CreateObject of an Analog Input 1\n"
|
||||
"send the following command:\n"
|
||||
"%s 123 0 1\n",
|
||||
filename);
|
||||
}
|
||||
|
||||
@@ -275,8 +282,8 @@ int main(int argc, char *argv[])
|
||||
if (target_args == 0) {
|
||||
object_instance = strtoul(argv[argi], NULL, 0);
|
||||
if (object_instance > BACNET_MAX_INSTANCE) {
|
||||
fprintf(stderr,
|
||||
"device-instance=%u - not greater than %u\n",
|
||||
fprintf(
|
||||
stderr, "device-instance=%u - not greater than %u\n",
|
||||
object_instance, BACNET_MAX_INSTANCE);
|
||||
return 1;
|
||||
}
|
||||
@@ -293,8 +300,8 @@ int main(int argc, char *argv[])
|
||||
} else if (target_args == 2) {
|
||||
object_instance = strtoul(argv[argi], NULL, 0);
|
||||
if (object_instance > BACNET_MAX_INSTANCE) {
|
||||
fprintf(stderr,
|
||||
"object-instance=%u - not greater than %u\n",
|
||||
fprintf(
|
||||
stderr, "object-instance=%u - not greater than %u\n",
|
||||
Target_Device_Object_Instance, BACNET_MAX_INSTANCE);
|
||||
return 1;
|
||||
}
|
||||
@@ -328,7 +335,8 @@ int main(int argc, char *argv[])
|
||||
Target_Device_Object_Instance, &max_apdu, &Target_Address);
|
||||
if (found) {
|
||||
if (Verbose) {
|
||||
printf("Found Device %u in address_cache.\n",
|
||||
printf(
|
||||
"Found Device %u in address_cache.\n",
|
||||
Target_Device_Object_Instance);
|
||||
}
|
||||
} else {
|
||||
@@ -341,16 +349,18 @@ int main(int argc, char *argv[])
|
||||
/* device is bound! */
|
||||
if (Request_Invoke_ID == 0) {
|
||||
if (Verbose) {
|
||||
printf("Sending CreateObject to Device %u.\n",
|
||||
printf(
|
||||
"Sending CreateObject to Device %u.\n",
|
||||
Target_Device_Object_Instance);
|
||||
}
|
||||
Request_Invoke_ID =
|
||||
Send_Create_Object_Request(Target_Device_Object_Instance,
|
||||
Target_Object_Type, Target_Object_Instance);
|
||||
Request_Invoke_ID = Send_Create_Object_Request(
|
||||
Target_Device_Object_Instance, Target_Object_Type,
|
||||
Target_Object_Instance);
|
||||
} else if (tsm_invoke_id_free(Request_Invoke_ID)) {
|
||||
break;
|
||||
} else if (tsm_invoke_id_failed(Request_Invoke_ID)) {
|
||||
MyPrintHandler(Target_Object_Type, Target_Object_Instance,
|
||||
MyPrintHandler(
|
||||
Target_Object_Type, Target_Object_Instance,
|
||||
ERROR_CLASS_COMMUNICATION, ERROR_CODE_ABORT_TSM_TIMEOUT, 0);
|
||||
tsm_free_invoke_id(Request_Invoke_ID);
|
||||
Error_Detected = true;
|
||||
@@ -371,10 +381,11 @@ int main(int argc, char *argv[])
|
||||
mstimer_reset(&maintenance_timer);
|
||||
tsm_timer_milliseconds(mstimer_interval(&maintenance_timer));
|
||||
datalink_maintenance_timer(
|
||||
mstimer_interval(&maintenance_timer)/1000L);
|
||||
mstimer_interval(&maintenance_timer) / 1000L);
|
||||
}
|
||||
if (mstimer_expired(&apdu_timer)) {
|
||||
MyPrintHandler(Target_Object_Type, Target_Object_Instance,
|
||||
MyPrintHandler(
|
||||
Target_Object_Type, Target_Object_Instance,
|
||||
ERROR_CLASS_COMMUNICATION,
|
||||
ERROR_CODE_ABORT_APPLICATION_EXCEEDED_REPLY_TIME, 0);
|
||||
Error_Detected = true;
|
||||
|
||||
Reference in New Issue
Block a user