automotive-dlt
|
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include "dlt_filetransfer.h"
#include "dlt_common.h"
Go to the source code of this file.
Macros | |
#define | BUFFER_SIZE 1024 |
Defines the buffer size of a single file package which will be logged to dlt. More... | |
#define | MIN_TIMEOUT 20 |
Defines the minimum timeout between two dlt logs. This is important because dlt should not be flooded with too many logs in a short period of time. More... | |
#define | DLT_FILETRANSFER_TRANSFER_ALL_PACKAGES INT_MAX |
Functions | |
uint32_t | getFilesize (const char *file, int *ok) |
Get some information about the file size of a file. More... | |
void | stringHash (const char *str, uint32_t *hash) |
uint32_t | getFileSerialNumber (const char *file, int *ok) |
Get some information about the file serial number of a file. More... | |
time_t | getFileCreationDate (const char *file, int *ok) |
Returns the creation date of a file. More... | |
char * | getFileCreationDate2 (const char *file, int *ok) |
Returns the creation date of a file. More... | |
int | isFile (const char *file) |
Checks if the file exists. More... | |
void | doTimeout (int timeout) |
Waits a period of time. More... | |
int | checkUserBufferForFreeSpace () |
Checks free space of the user buffer. More... | |
int | doRemoveFile (const char *filename) |
Deletes the given file. More... | |
void | dlt_user_log_file_errorMessage (DltContext *fileContext, const char *filename, int errorCode) |
int | dlt_user_log_file_infoAbout (DltContext *fileContext, const char *filename) |
Logs specific file inforamtions to dlt. More... | |
int | dlt_user_log_file_complete (DltContext *fileContext, const char *filename, int deleteFlag, int timeout) |
Transfer the complete file as several dlt logs. More... | |
int | dlt_user_log_file_packagesCount (DltContext *fileContext, const char *filename) |
This method gives information about the number of packages the file have. More... | |
int | dlt_user_log_file_header_alias (DltContext *fileContext, const char *filename, const char *alias) |
Transfer the head of the file as a dlt logs. More... | |
int | dlt_user_log_file_header (DltContext *fileContext, const char *filename) |
Transfer the head of the file as a dlt logs. More... | |
int | dlt_user_log_file_data (DltContext *fileContext, const char *filename, int packageToTransfer, int timeout) |
Transfer the content data of a file. More... | |
int | dlt_user_log_file_end (DltContext *fileContext, const char *filename, int deleteFlag) |
Transfer the end of the file as a dlt logs. More... | |
Variables | |
unsigned char | buffer [BUFFER_SIZE] |
Buffer for dlt file transfer. The size is defined by BUFFER_SIZE. More... | |
Definition in file dlt_filetransfer.c.
#define BUFFER_SIZE 1024 |
Defines the buffer size of a single file package which will be logged to dlt.
Definition at line 63 of file dlt_filetransfer.c.
Referenced by dlt_user_log_file_data(), dlt_user_log_file_errorMessage(), dlt_user_log_file_header(), dlt_user_log_file_header_alias(), and dlt_user_log_file_packagesCount().
#define DLT_FILETRANSFER_TRANSFER_ALL_PACKAGES INT_MAX |
Definition at line 69 of file dlt_filetransfer.c.
Referenced by dlt_user_log_file_complete(), and dlt_user_log_file_data().
#define MIN_TIMEOUT 20 |
Defines the minimum timeout between two dlt logs. This is important because dlt should not be flooded with too many logs in a short period of time.
Definition at line 66 of file dlt_filetransfer.c.
int checkUserBufferForFreeSpace | ( | ) |
Checks free space of the user buffer.
returns | -1 if more than 50% space in the user buffer is free. Otherwise 1 will be returned. |
Definition at line 200 of file dlt_filetransfer.c.
References dlt_user_check_buffer().
Referenced by dlt_user_log_file_data().
int dlt_user_log_file_complete | ( | DltContext * | fileContext, |
const char * | filename, | ||
int | deleteFlag, | ||
int | timeout | ||
) |
Transfer the complete file as several dlt logs.
This method transfer the complete file as several dlt logs. At first it will be checked that the file exist. In the next step some generic informations about the file will be logged to dlt. Now the header will be logged to dlt. See the method dlt_user_log_file_header for more informations. Then the method dlt_user_log_data will be called with the parameter to log all packages in a loop with some timeout. At last dlt_user_log_end is called to signal that the complete file transfer was okey. This is important for the plugin of the dlt viewer.
fileContext | Specific context to log the file to dlt |
filename | Absolute file path |
deleteFlag | Flag if the file will be deleted after transfer. 1->delete, 0->notDelete |
timeout | Timeout in ms to wait between some logs. Important that the FIFO of dlt will not be flooded with to many messages in a short period of time. |
Definition at line 317 of file dlt_filetransfer.c.
References DLT_FILETRANSFER_ERROR_FILE_COMPLETE, DLT_FILETRANSFER_ERROR_FILE_COMPLETE1, DLT_FILETRANSFER_ERROR_FILE_COMPLETE2, DLT_FILETRANSFER_ERROR_FILE_COMPLETE3, DLT_FILETRANSFER_TRANSFER_ALL_PACKAGES, dlt_user_log_file_data(), dlt_user_log_file_end(), dlt_user_log_file_errorMessage(), dlt_user_log_file_header(), and isFile().
Referenced by main(), testFile1Run1(), testFile2Run1(), and testFile3Run1().
int dlt_user_log_file_data | ( | DltContext * | fileContext, |
const char * | filename, | ||
int | packageToTransfer, | ||
int | timeout | ||
) |
Transfer the content data of a file.
See the Mainpages.c for more informations.
fileContext | Specific context to log the file to dlt |
filename | Absolute file path |
packageToTransfer | Package number to transfer. If this param is LONG_MAX, the whole file will be transferred with a specific timeout |
timeout | Timeout to wait between dlt logs. Important because the dlt FIFO should not be flooded. Default is defined by MIN_TIMEOUT. The given timeout in ms can not be smaller than MIN_TIMEOUT. |
Definition at line 496 of file dlt_filetransfer.c.
References buffer, BUFFER_SIZE, checkUserBufferForFreeSpace(), DLT_FILETRANSFER_ERROR_FILE_DATA, DLT_FILETRANSFER_TRANSFER_ALL_PACKAGES, DLT_INT, DLT_LOG, DLT_LOG_ERROR, DLT_LOG_INFO, DLT_RAW, DLT_STRING, DLT_UINT, dlt_user_log_file_errorMessage(), dlt_user_log_file_packagesCount(), doTimeout(), getFileSerialNumber(), isFile(), and NULL.
Referenced by dlt_user_log_file_complete(), send_dumped_file(), testFile1Run2(), testFile2Run2(), and testFile3Run2().
int dlt_user_log_file_end | ( | DltContext * | fileContext, |
const char * | filename, | ||
int | deleteFlag | ||
) |
Transfer the end of the file as a dlt logs.
The end of the file must be logged to dlt because the end contains inforamtion about the file serial number. This informations is needed from the plugin of the dlt viewer. See the Mainpages.c for more informations.
fileContext | Specific context to log the file to dlt |
filename | Absolute file path |
deleteFlag | Flag to delete the file after the whole file is transferred (logged to dlt).1->delete,0->NotDelete |
Definition at line 621 of file dlt_filetransfer.c.
References DLT_FILETRANSFER_ERROR_FILE_END, DLT_LOG, DLT_LOG_ERROR, DLT_LOG_INFO, DLT_STRING, DLT_UINT, dlt_user_log_file_errorMessage(), doRemoveFile(), getFileSerialNumber(), and isFile().
Referenced by dlt_user_log_file_complete(), send_dumped_file(), testFile1Run2(), testFile2Run2(), and testFile3Run2().
void dlt_user_log_file_errorMessage | ( | DltContext * | fileContext, |
const char * | filename, | ||
int | errorCode | ||
) |
Definition at line 222 of file dlt_filetransfer.c.
References BUFFER_SIZE, DLT_INT, DLT_LOG, DLT_LOG_ERROR, DLT_STRING, DLT_UINT, dlt_user_log_file_packagesCount(), getFileCreationDate2(), getFileSerialNumber(), and getFilesize().
Referenced by dlt_user_log_file_complete(), dlt_user_log_file_data(), dlt_user_log_file_end(), dlt_user_log_file_header(), dlt_user_log_file_header_alias(), and dlt_user_log_file_infoAbout().
int dlt_user_log_file_header | ( | DltContext * | fileContext, |
const char * | filename | ||
) |
Transfer the head of the file as a dlt logs.
The head of the file must be logged to dlt because the head contains inforamtion about the file serial number, the file name, the file size, package number the file have and the buffer size. All these informations are needed from the plugin of the dlt viewer. See the Mainpages.c for more informations.
fileContext | Specific context to log the file to dlt |
filename | Absolute file path |
Definition at line 447 of file dlt_filetransfer.c.
References BUFFER_SIZE, DLT_FILETRANSFER_ERROR_FILE_HEAD, DLT_LOG, DLT_LOG_ERROR, DLT_LOG_INFO, DLT_STRING, DLT_UINT, dlt_user_log_file_errorMessage(), dlt_user_log_file_packagesCount(), getFileCreationDate2(), getFileSerialNumber(), getFilesize(), and isFile().
Referenced by dlt_user_log_file_complete(), testFile1Run2(), testFile2Run2(), and testFile3Run2().
int dlt_user_log_file_header_alias | ( | DltContext * | fileContext, |
const char * | filename, | ||
const char * | alias | ||
) |
Transfer the head of the file as a dlt logs.
The head of the file must be logged to dlt because the head contains inforamtion about the file serial number, the file name, the file size, package number the file have and the buffer size. All these informations are needed from the plugin of the dlt viewer. See the Mainpages.c for more informations.
fileContext | Specific context to log the file to dlt |
filename | Absolute file path |
alias | Alias for the file. An alternative name to show in the receiving end |
Definition at line 398 of file dlt_filetransfer.c.
References BUFFER_SIZE, DLT_FILETRANSFER_ERROR_FILE_HEAD, DLT_LOG, DLT_LOG_ERROR, DLT_LOG_INFO, DLT_STRING, DLT_UINT, dlt_user_log_file_errorMessage(), dlt_user_log_file_packagesCount(), getFileCreationDate2(), getFileSerialNumber(), getFilesize(), and isFile().
Referenced by send_dumped_file().
int dlt_user_log_file_infoAbout | ( | DltContext * | fileContext, |
const char * | filename | ||
) |
Logs specific file inforamtions to dlt.
The filename, file size, file serial number and the number of packages will be logged to dlt.
fileContext | Specific context |
filename | Absolute file path |
Definition at line 270 of file dlt_filetransfer.c.
References DLT_FILETRANSFER_ERROR_INFO_ABOUT, DLT_LOG, DLT_LOG_ERROR, DLT_LOG_INFO, DLT_STRING, DLT_UINT, dlt_user_log_file_errorMessage(), dlt_user_log_file_packagesCount(), getFileCreationDate2(), getFileSerialNumber(), getFilesize(), and isFile().
Referenced by main(), and testFile3Run3().
int dlt_user_log_file_packagesCount | ( | DltContext * | fileContext, |
const char * | filename | ||
) |
This method gives information about the number of packages the file have.
Every file will be divided into several packages. Every package will be logged as a single dlt log. The number of packages depends on the BUFFER_SIZE. At first it will be checked if the file exist. Then the file will be divided into several packages depending on the buffer size.
fileContext | Specific context to log the file to dlt |
filename | Absolute file path |
Definition at line 352 of file dlt_filetransfer.c.
References BUFFER_SIZE, DLT_FILETRANSFER_ERROR_PACKAGE_COUNT, DLT_INT, DLT_LOG, DLT_LOG_ERROR, DLT_STRING, getFilesize(), and isFile().
Referenced by dlt_user_log_file_data(), dlt_user_log_file_errorMessage(), dlt_user_log_file_header(), dlt_user_log_file_header_alias(), dlt_user_log_file_infoAbout(), send_dumped_file(), testFile1Run2(), testFile2Run2(), and testFile3Run2().
int doRemoveFile | ( | const char * | filename | ) |
Deletes the given file.
filename | Absolute file path |
Definition at line 218 of file dlt_filetransfer.c.
Referenced by dlt_user_log_file_end().
void doTimeout | ( | int | timeout | ) |
Waits a period of time.
Waits a period of time. The minimal time to wait is MIN_TIMEOUT. This makes sure that the FIFO of dlt is not flooded.
timeout | Timeout to in ms but can not be smaller as MIN_TIMEOUT |
Definition at line 191 of file dlt_filetransfer.c.
Referenced by dlt_user_log_file_data().
time_t getFileCreationDate | ( | const char * | file, |
int * | ok | ||
) |
Returns the creation date of a file.
See stat(2) for more informations.
file | Absolute file path |
Definition at line 149 of file dlt_filetransfer.c.
char* getFileCreationDate2 | ( | const char * | file, |
int * | ok | ||
) |
Returns the creation date of a file.
Format of the creation date is Day Mon dd hh:mm:ss yyyy
file | Absolute file path |
Definition at line 165 of file dlt_filetransfer.c.
Referenced by dlt_user_log_file_errorMessage(), dlt_user_log_file_header(), dlt_user_log_file_header_alias(), and dlt_user_log_file_infoAbout().
uint32_t getFileSerialNumber | ( | const char * | file, |
int * | ok | ||
) |
Get some information about the file serial number of a file.
See stat(2) for more informations.
file | Absolute file path |
value | *ok == 0 -> error; *ok == 1 -> ok |
Definition at line 124 of file dlt_filetransfer.c.
References stringHash().
Referenced by dlt_user_log_file_data(), dlt_user_log_file_end(), dlt_user_log_file_errorMessage(), dlt_user_log_file_header(), dlt_user_log_file_header_alias(), dlt_user_log_file_infoAbout(), and unique_name().
uint32_t getFilesize | ( | const char * | file, |
int * | ok | ||
) |
Get some information about the file size of a file.
See stat(2) for more informations.
file | Absolute file path |
Definition at line 81 of file dlt_filetransfer.c.
Referenced by dlt_user_log_file_errorMessage(), dlt_user_log_file_header(), dlt_user_log_file_header_alias(), dlt_user_log_file_infoAbout(), and dlt_user_log_file_packagesCount().
int isFile | ( | const char * | file | ) |
Checks if the file exists.
file | Absolute file path |
Definition at line 181 of file dlt_filetransfer.c.
Referenced by dlt_user_log_file_complete(), dlt_user_log_file_data(), dlt_user_log_file_end(), dlt_user_log_file_header(), dlt_user_log_file_header_alias(), dlt_user_log_file_infoAbout(), and dlt_user_log_file_packagesCount().
void stringHash | ( | const char * | str, |
uint32_t * | hash | ||
) |
A simple Hash function for C-strings
str | input string. E.g. a file path. |
hash | start and result value for hash computation |
Definition at line 99 of file dlt_filetransfer.c.
Referenced by getFileSerialNumber().
unsigned char buffer[BUFFER_SIZE] |
Buffer for dlt file transfer. The size is defined by BUFFER_SIZE.
Definition at line 73 of file dlt_filetransfer.c.
Referenced by DLT_IMPORT_CONTEXT(), dlt_kpi_log_interrupts(), dlt_kpi_log_list(), dlt_kpi_process_update_ctx_switches(), dlt_kpi_process_update_io_bytes(), dlt_kpi_read_cpu_count(), dlt_kpi_read_file_compact(), dlt_kpi_read_process_stat_to_ulong(), dlt_message_header_flags(), dlt_user_log_file_data(), main(), stress3(), test2f(), test2m(), test3f(), test3m(), test4f(), test4m(), test5f(), test5m(), test7f(), test7m(), test8f(), test8m(), test9f(), test9m(), and testall().