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:
+32
-21
@@ -50,14 +50,16 @@ static bool End_Of_File_Detected = false;
|
||||
static bool Error_Detected = false;
|
||||
static uint8_t Request_Invoke_ID = 0;
|
||||
|
||||
static void Atomic_Read_File_Error_Handler(BACNET_ADDRESS *src,
|
||||
static void Atomic_Read_File_Error_Handler(
|
||||
BACNET_ADDRESS *src,
|
||||
uint8_t invoke_id,
|
||||
BACNET_ERROR_CLASS error_class,
|
||||
BACNET_ERROR_CODE error_code)
|
||||
{
|
||||
if (address_match(&Target_Address, src) &&
|
||||
(invoke_id == Request_Invoke_ID)) {
|
||||
printf("BACnet Error: %s: %s\n",
|
||||
printf(
|
||||
"BACnet Error: %s: %s\n",
|
||||
bactext_error_class_name((int)error_class),
|
||||
bactext_error_code_name((int)error_code));
|
||||
Error_Detected = true;
|
||||
@@ -76,18 +78,20 @@ static void MyAbortHandler(
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (address_match(&Target_Address, src) &&
|
||||
(invoke_id == Request_Invoke_ID)) {
|
||||
printf("BACnet Reject: %s\n",
|
||||
printf(
|
||||
"BACnet Reject: %s\n",
|
||||
bactext_reject_reason_name((int)reject_reason));
|
||||
Error_Detected = true;
|
||||
}
|
||||
}
|
||||
|
||||
static void AtomicReadFileAckHandler(uint8_t *service_request,
|
||||
static void AtomicReadFileAckHandler(
|
||||
uint8_t *service_request,
|
||||
uint16_t service_len,
|
||||
BACNET_ADDRESS *src,
|
||||
BACNET_CONFIRMED_SERVICE_ACK_DATA *service_data)
|
||||
@@ -128,7 +132,8 @@ static void AtomicReadFileAckHandler(uint8_t *service_request,
|
||||
octets_written =
|
||||
fwrite(octet_buffer, 1, octet_count, pFile);
|
||||
if (octets_written != octet_count) {
|
||||
fprintf(stderr,
|
||||
fprintf(
|
||||
stderr,
|
||||
"Unable to write data to file \"%s\".\n",
|
||||
Local_File_Name);
|
||||
} else {
|
||||
@@ -140,7 +145,8 @@ static void AtomicReadFileAckHandler(uint8_t *service_request,
|
||||
}
|
||||
fflush(pFile);
|
||||
} else {
|
||||
fprintf(stderr, "Unable to seek to %d!\n",
|
||||
fprintf(
|
||||
stderr, "Unable to seek to %d!\n",
|
||||
data.type.stream.fileStartPosition);
|
||||
}
|
||||
}
|
||||
@@ -154,7 +160,8 @@ static void AtomicReadFileAckHandler(uint8_t *service_request,
|
||||
fprintf(stderr, "Decode error! %d bytes decoded.\n", len);
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "Address & Invoke ID mismatch! Invoke ID=%d\n",
|
||||
fprintf(
|
||||
stderr, "Address & Invoke ID mismatch! Invoke ID=%d\n",
|
||||
Request_Invoke_ID);
|
||||
}
|
||||
}
|
||||
@@ -213,24 +220,26 @@ static void print_usage(const char *filename)
|
||||
|
||||
static void print_help(const char *filename)
|
||||
{
|
||||
printf(
|
||||
"Read a file from a BACnet device and save it locally.\n");
|
||||
printf("Read a file from a BACnet device and save it locally.\n");
|
||||
printf("\n");
|
||||
printf("device-instance:\n"
|
||||
printf(
|
||||
"device-instance:\n"
|
||||
"BACnet Device Object Instance number that you are trying to\n"
|
||||
"communicate to. This number will be used to try and bind with\n"
|
||||
"the device using Who-Is and I-Am services. For example, if you were\n"
|
||||
"reading from Device Object 123, the device-instance would be 123.\n");
|
||||
printf("\n");
|
||||
printf("file-instance:\n"
|
||||
printf(
|
||||
"file-instance:\n"
|
||||
"This is the file object instance number that you are reading from.\n"
|
||||
"For example, if you were reading from File 2, \n"
|
||||
"the file-instance would be 2.\n");
|
||||
printf("\n");
|
||||
printf("local-name:\n"
|
||||
"The name of the file that will be stored locally.\n");
|
||||
"The name of the file that will be stored locally.\n");
|
||||
printf("\n");
|
||||
printf("Example:\n"
|
||||
printf(
|
||||
"Example:\n"
|
||||
"If you want read File 2 from Device 123 and save it to temp.txt,\n"
|
||||
"use the following command:\n"
|
||||
"%s 123 2 temp.txt\n",
|
||||
@@ -280,12 +289,14 @@ int main(int argc, char *argv[])
|
||||
Target_File_Object_Instance = strtol(argv[2], NULL, 0);
|
||||
Local_File_Name = argv[3];
|
||||
if (Target_Device_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",
|
||||
Target_Device_Object_Instance, BACNET_MAX_INSTANCE);
|
||||
return 1;
|
||||
}
|
||||
if (Target_File_Object_Instance > BACNET_MAX_INSTANCE) {
|
||||
fprintf(stderr, "file-instance=%u - not greater than %u\n",
|
||||
fprintf(
|
||||
stderr, "file-instance=%u - not greater than %u\n",
|
||||
Target_File_Object_Instance, BACNET_MAX_INSTANCE);
|
||||
return 1;
|
||||
}
|
||||
@@ -356,10 +367,10 @@ int main(int argc, char *argv[])
|
||||
/* the ACK will increment the start position if OK */
|
||||
/* we'll read the file in chunks
|
||||
less than max_apdu to keep unsegmented */
|
||||
invoke_id =
|
||||
Send_Atomic_Read_File_Stream(Target_Device_Object_Instance,
|
||||
Target_File_Object_Instance, Target_File_Start_Position,
|
||||
Target_File_Requested_Octet_Count);
|
||||
invoke_id = Send_Atomic_Read_File_Stream(
|
||||
Target_Device_Object_Instance, Target_File_Object_Instance,
|
||||
Target_File_Start_Position,
|
||||
Target_File_Requested_Octet_Count);
|
||||
Request_Invoke_ID = invoke_id;
|
||||
} else if (tsm_invoke_id_failed(invoke_id)) {
|
||||
fprintf(stderr, "\rError: TSM Timeout!\n");
|
||||
|
||||
Reference in New Issue
Block a user