automotive-dlt
dlt_filetransfer.c File Reference
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include "dlt_filetransfer.h"
#include "dlt_common.h"
Include dependency graph for dlt_filetransfer.c:

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...
 

Detailed Description

Author
Alexander Wenzel alexa.nosp@m.nder.nosp@m..aw.w.nosp@m.enze.nosp@m.l@bmw.nosp@m..de

Definition in file dlt_filetransfer.c.

Macro Definition Documentation

#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.

Function Documentation

int checkUserBufferForFreeSpace ( )

Checks free space of the user buffer.

Parameters
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.

Parameters
fileContextSpecific context to log the file to dlt
filenameAbsolute file path
deleteFlagFlag if the file will be deleted after transfer. 1->delete, 0->notDelete
timeoutTimeout 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.
Returns
Returns 0 if everything was okey. If there was a failure a value < 0 will be returned.

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.

Parameters
fileContextSpecific context to log the file to dlt
filenameAbsolute file path
packageToTransferPackage number to transfer. If this param is LONG_MAX, the whole file will be transferred with a specific timeout
timeoutTimeout 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.
Returns
Returns 0 if everything was okey. If there was a failure a value < 0 will be returned.

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.

Parameters
fileContextSpecific context to log the file to dlt
filenameAbsolute file path
deleteFlagFlag to delete the file after the whole file is transferred (logged to dlt).1->delete,0->NotDelete
Returns
Returns 0 if everything was okey. If there was a failure a value < 0 will be returned.

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().

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.

Parameters
fileContextSpecific context to log the file to dlt
filenameAbsolute file path
Returns
Returns 0 if everything was okey. If there was a failure a value < 0 will be returned.

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.

Parameters
fileContextSpecific context to log the file to dlt
filenameAbsolute file path
aliasAlias for the file. An alternative name to show in the receiving end
Returns
Returns 0 if everything was okey. If there was a failure a value < 0 will be returned.

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.

Parameters
fileContextSpecific context
filenameAbsolute file path
Returns
Returns 0 if everything was okey.If there was a failure a value < 0 will be returned.

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.

Parameters
fileContextSpecific context to log the file to dlt
filenameAbsolute file path
Returns
Returns the number of packages if everything was okey. If there was a failure a value < 0 will be returned.

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.

Parameters
filenameAbsolute file path
Returns
If the file is successfully deleted, a zero value is returned.If the file can not be deleted a nonzero value is returned.

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.

Parameters
timeoutTimeout 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.

Parameters
fileAbsolute file path
Returns
Returns the creation date of a file

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

Parameters
fileAbsolute file path
Returns
Returns the creation date of a file

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.

Parameters
fileAbsolute file path
value*ok == 0 -> error; *ok == 1 -> ok
Returns
Returns a unique number associated with each filename

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.

Parameters
fileAbsolute file path
Returns
Returns the size of the file (if it is a regular file or a symbolic link) in bytes.

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.

Parameters
fileAbsolute file path
Returns
Returns 1 if the file exists, 0 if the file does not exist

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

Parameters
strinput string. E.g. a file path.
hashstart and result value for hash computation

Definition at line 99 of file dlt_filetransfer.c.

Referenced by getFileSerialNumber().

Variable Documentation