summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xinclude/dlt/dlt_common.h148
-rwxr-xr-xsrc/shared/dlt_common.c479
-rw-r--r--src/shared/dlt_shm.c20
-rw-r--r--src/system/dlt-system-log.c51
-rw-r--r--src/system/dlt-system.h1
-rwxr-xr-xsrc/tests/dlt-test-internal.c123
6 files changed, 153 insertions, 669 deletions
diff --git a/include/dlt/dlt_common.h b/include/dlt/dlt_common.h
index ba553c4..f6a46d5 100755
--- a/include/dlt/dlt_common.h
+++ b/include/dlt/dlt_common.h
@@ -971,91 +971,139 @@ extern "C"
int dlt_check_storageheader(DltStorageHeader *storageheader);
+ /**
+ * Initialise static ringbuffer with a size of size.
+ * Initialise as server. Init counters.
+ * Memory is already allocated.
+ * @param buf Pointer to ringbuffer structure
+ * @param ptr Ptr to ringbuffer memory
+ * @param size Maximum size of buffer in bytes
+ * @return negative value if there was an error
+ */
int dlt_buffer_init_static_server(DltBuffer *buf, const unsigned char *ptr, uint32_t size);
+
+ /**
+ * Initialize static ringbuffer with a size of size.
+ * Initialise as a client. Do not change counters.
+ * Memory is already allocated.
+ * @param buf Pointer to ringbuffer structure
+ * @param ptr Ptr to ringbuffer memory
+ * @param size Maximum size of buffer in bytes
+ * @return negative value if there was an error
+ */
int dlt_buffer_init_static_client(DltBuffer *buf, const unsigned char *ptr, uint32_t size);
+
+ /**
+ * Initialize dynamic ringbuffer with a size of size.
+ * Initialise as a client. Do not change counters.
+ * Memory will be allocated starting with min_size.
+ * If more memory is needed size is increased wit step_size.
+ * The maximum size is max_size.
+ * @param buf Pointer to ringbuffer structure
+ * @param min_size Minimum size of buffer in bytes
+ * @param max_size Maximum size of buffer in bytes
+ * @param step_size size of which ringbuffer is increased
+ * @return negative value if there was an error
+ */
int dlt_buffer_init_dynamic(DltBuffer *buf, uint32_t min_size, uint32_t max_size,uint32_t step_size);
- int dlt_buffer_free_static(DltBuffer *buf);
- int dlt_buffer_free_dynamic(DltBuffer *buf);
- int dlt_buffer_push(DltBuffer *buf,const unsigned char *data,unsigned int size);
- int dlt_buffer_push3(DltBuffer *buf,const unsigned char *data1,unsigned int size1,const unsigned char *data2,unsigned int size2,const unsigned char *data3,unsigned int size3);
- int dlt_buffer_pull(DltBuffer *buf,unsigned char *data, int max_size);
- int dlt_buffer_copy(DltBuffer *buf,unsigned char *data, int max_size);
- int dlt_buffer_remove(DltBuffer *buf);
- void dlt_buffer_info(DltBuffer *buf);
- void dlt_buffer_status(DltBuffer *buf);
- int dlt_buffer_get_total_size(DltBuffer *buf);
- int dlt_buffer_get_used_size(DltBuffer *buf);
- int dlt_buffer_get_message_count(DltBuffer *buf);
/**
- * Initialize ringbuffer of with a maximum size of size
- * @param dltbuf Pointer to ringbuffer structure
- * @param size Maximum size of buffer in bytes
+ * Deinitilaise usage of static ringbuffer
+ * @param buf Pointer to ringbuffer structure
* @return negative value if there was an error
*/
- int dlt_ringbuffer_init(DltRingBuffer *dltbuf, uint32_t size);
+ int dlt_buffer_free_static(DltBuffer *buf);
/**
- * Release and free memory used by ringbuffer
- * @param dltbuf Pointer to ringbuffer structure
+ * Release and free memory used by dynamic ringbuffer
+ * @param buf Pointer to ringbuffer structure
* @return negative value if there was an error
*/
- int dlt_ringbuffer_free(DltRingBuffer *dltbuf);
+ int dlt_buffer_free_dynamic(DltBuffer *buf);
/**
* Write one entry to ringbuffer
- * @param dltbuf Pointer to ringbuffer structure
+ * @param buf Pointer to ringbuffer structure
* @param data Pointer to data to be written to ringbuffer
* @param size Size of data in bytes to be written to ringbuffer
* @return negative value if there was an error
*/
- int dlt_ringbuffer_put(DltRingBuffer *dltbuf, void *data, uint32_t size);
+ int dlt_buffer_push(DltBuffer *buf,const unsigned char *data,unsigned int size);
/**
- * Write one entry given as 3 chunks to ringbuffer
- * @param dltbuf Pointer to ringbuffer structure
- * @param data1 Pointer to data1 to be written to ringbuffer
- * @param size1 Size of data1 in bytes to be written to ringbuffer
- * @param data2 Pointer to data2 to be written to ringbuffer
- * @param size2 Size of data2 in bytes to be written to ringbuffer
- * @param data3 Pointer to data3 to be written to ringbuffer
- * @param size3 Size of data3 in bytes to be written to ringbuffer
+ * Write up to three entries to ringbuffer.
+ * Entries are joined to one block.
+ * @param dlt Pointer to ringbuffer structure
+ * @param data1 Pointer to data to be written to ringbuffer
+ * @param size1 Size of data in bytes to be written to ringbuffer
+ * @param data2 Pointer to data to be written to ringbuffer
+ * @param size2 Size of data in bytes to be written to ringbuffer
+ * @param data3 Pointer to data to be written to ringbuffer
+ * @param size3 Size of data in bytes to be written to ringbuffer
* @return negative value if there was an error
*/
- int dlt_ringbuffer_put3(DltRingBuffer *dltbuf, void *data1, uint32_t size1, void *data2, uint32_t size2, void *data3, uint32_t size3);
+ int dlt_buffer_push3(DltBuffer *buf,const unsigned char *data1,unsigned int size1,const unsigned char *data2,unsigned int size2,const unsigned char *data3,unsigned int size3);
/**
- * Read one entry from ringbuffer
- * @param dltbuf Pointer to ringbuffer structure
+ * Read one entry from ringbuffer.
+ * Remove it from ringbuffer.
+ * @param buf Pointer to ringbuffer structure
* @param data Pointer to data read from ringbuffer
- * @param size Size of read data in bytes from ringbuffer
- * @return negative value if there was an error
+ * @param max_size Max size of read data in bytes from ringbuffer
+ * @return size of read data, zero if no data available, negative value if there was an error
*/
- int dlt_ringbuffer_get(DltRingBuffer *dltbuf, void *data, size_t *size);
+ int dlt_buffer_pull(DltBuffer *buf,unsigned char *data, int max_size);
/**
- * Helper function: Skip one readable entry in ringbuffer
- * @param dltbuf Pointer to ringbuffer structure
- * @return negative value if there was an error
+ * Read one entry from ringbuffer.
+ * Do not remove it from ringbuffer.
+ * @param buf Pointer to ringbuffer structure
+ * @param data Pointer to data read from ringbuffer
+ * @param max_size Max size of read data in bytes from ringbuffer
+ * @return size of read data, zero if no data available, negative value if there was an error
+ */
+ int dlt_buffer_copy(DltBuffer *buf,unsigned char *data, int max_size);
+
+ /**
+ * Remove entry from ringbuffer.
+ * @param buf Pointer to ringbuffer structure
+ * @return size of read data, zero if no data available, negative value if there was an error
*/
- int dlt_ringbuffer_get_skip(DltRingBuffer *dltbuf);
+ int dlt_buffer_remove(DltBuffer *buf);
/**
- * Helper function: Get free space in bytes for writting between write and read position
- * @param dltbuf Pointer to ringbuffer structure
- * @param freespace Free Space in bytes for writting is returned
- * @return negative value if there was an error
+ * Print information about buffer and log to internal DLT log.
+ * @param buf Pointer to ringbuffer structure
*/
- int dlt_ringbuffer_freespacewrite(DltRingBuffer *dltbuf, uint32_t *freespace);
+ void dlt_buffer_info(DltBuffer *buf);
/**
- * Helper function: Check free space and if necessary discard entries, so that at least
- * reqspace bytes are available for writting
- * @param dltbuf Pointer to ringbuffer structure
- * @param reqspace Requested space for writting in bytes
- * @return negative value if there was an error
+ * Print status of buffer and log to internal DLT log.
+ * @param buf Pointer to ringbuffer structure
*/
- int dlt_ringbuffer_checkandfreespace(DltRingBuffer *dltbuf, uint32_t reqspace);
+ void dlt_buffer_status(DltBuffer *buf);
+
+ /**
+ * Get total size in bytes of ringbuffer.
+ * If buffer is dynamic, max size is returned.
+ * @param buf Pointer to ringbuffer structure
+ * @return total size of buffer
+ */
+ int dlt_buffer_get_total_size(DltBuffer *buf);
+
+ /**
+ * Get used size in bytes of ringbuffer.
+ * @param buf Pointer to ringbuffer structure
+ * @return used size of buffer
+ */
+ int dlt_buffer_get_used_size(DltBuffer *buf);
+
+ /**
+ * Get number of entries in ringbuffer.
+ * @param buf Pointer to ringbuffer structure
+ * @return number of entries
+ */
+ int dlt_buffer_get_message_count(DltBuffer *buf);
#if !defined (__WIN32__)
diff --git a/src/shared/dlt_common.c b/src/shared/dlt_common.c
index f744702..8e2b6d4 100755
--- a/src/shared/dlt_common.c
+++ b/src/shared/dlt_common.c
@@ -2790,485 +2790,6 @@ int dlt_buffer_get_message_count(DltBuffer *buf)
return ((int*)(buf->shm))[2];
}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-int dlt_ringbuffer_init(DltRingBuffer *dltbuf, uint32_t size)
-{
-
- if (dltbuf==0)
- {
- return -1;
- }
-
- if (size<=sizeof(uint32_t))
- {
- return -1;
- }
-
- dltbuf->buffer=(char*)malloc(size);
- if (dltbuf->buffer==0)
- {
- return -1;
- }
-
- dltbuf->size=size;
-
- dltbuf->pos_write=0;
- dltbuf->pos_read=0;
-
- dltbuf->count=0;
-
- return 0;
-}
-
-int dlt_ringbuffer_free(DltRingBuffer *dltbuf)
-{
-
- if (dltbuf==0)
- {
- return -1;
- }
-
- if (dltbuf->buffer)
- {
- free(dltbuf->buffer);
- }
-
- dltbuf->buffer=0;
-
- dltbuf->size=0;
-
- dltbuf->pos_write=0;
- dltbuf->pos_read=0;
-
- dltbuf->count=0;
-
- return 0;
-}
-
-int dlt_ringbuffer_put(DltRingBuffer *dltbuf, void *data, uint32_t size)
-{
- uint32_t sui, part1, part2;
-
- if (dltbuf==0)
- {
- return -1;
- }
-
- if (dltbuf->buffer==0)
- {
- return -1;
- }
-
- if (data==0)
- {
- return -1;
- }
-
- sui = sizeof(uint32_t);
-
- if ((size+sui)>dltbuf->size)
- {
- return -1;
- }
-
- dlt_ringbuffer_checkandfreespace(dltbuf, (size+sui));
-
- if (dltbuf->pos_write >= dltbuf->size)
- {
- dltbuf->pos_write = 0;
- }
-
- /* Not enough space for one uint available before end of linear buffer */
- /* Start at begin of linear buffer */
- if ((dltbuf->size - dltbuf->pos_write) < sui)
- {
- dltbuf->pos_write = 0;
- }
-
- /* Write length of following data to buffer */
- memcpy(&(dltbuf->buffer[dltbuf->pos_write]), &size, sui);
- dltbuf->pos_write+=sui;
-
- if (dltbuf->pos_write >= dltbuf->size)
- {
- dltbuf->pos_write = 0;
- }
-
- if ((dltbuf->size - dltbuf->pos_write) < size)
- {
- /* Not enough space til end of linear buffer, */
- /* split up write call */
- part1 = dltbuf->size - dltbuf->pos_write;
- part2 = size - part1;
-
- memcpy(dltbuf->buffer + dltbuf->pos_write, data, part1);
- memcpy(dltbuf->buffer, ((char*)data) + part1, part2);
- dltbuf->pos_write = part2;
-
- }
- else
- {
- /* Enough space til end of linear buffer */
- memcpy(&(dltbuf->buffer[dltbuf->pos_write]), data, size);
- dltbuf->pos_write+=size;
- }
-
- dltbuf->count++;
-
- return 0;
-}
-
-
-int dlt_ringbuffer_put3(DltRingBuffer *dltbuf, void *data1, uint32_t size1, void *data2, uint32_t size2, void *data3, uint32_t size3)
-{
- uint32_t sui, part1, part2;
- uint32_t total_size;
-
- if (dltbuf==0)
- {
- return -1;
- }
-
- if (dltbuf->buffer==0)
- {
- return -1;
- }
-
- sui = sizeof(uint32_t);
-
- total_size = size1+size2+size3;
-
- if ((total_size+sui)>dltbuf->size)
- {
- return -1;
- }
-
- dlt_ringbuffer_checkandfreespace(dltbuf, (total_size+sui));
-
- if (dltbuf->pos_write >= dltbuf->size)
- {
- dltbuf->pos_write = 0;
- }
-
- /* Not enough space for one uint available before end of linear buffer */
- /* Start at begin of linear buffer */
- if ((dltbuf->size - dltbuf->pos_write) < sui)
- {
- dltbuf->pos_write = 0;
- }
-
- /* Write length of following data to buffer */
- memcpy(&(dltbuf->buffer[dltbuf->pos_write]), &total_size, sui);
- dltbuf->pos_write+=sui;
-
- if (dltbuf->pos_write >= dltbuf->size)
- {
- dltbuf->pos_write = 0;
- }
-
- /* First chunk of data (data1, size1) */
- if ((dltbuf->size - dltbuf->pos_write) < size1)
- {
- /* Not enough space til end of linear buffer, */
- /* split up write call */
- part1 = dltbuf->size - dltbuf->pos_write;
- part2 = size1 - part1;
-
- memcpy(dltbuf->buffer + dltbuf->pos_write, data1, part1);
- memcpy(dltbuf->buffer, ((char*)data1) + part1, part2);
- dltbuf->pos_write = part2;
-
- }
- else
- {
- /* Enough space til end of linear buffer */
- memcpy(&(dltbuf->buffer[dltbuf->pos_write]), data1, size1);
- dltbuf->pos_write+=size1;
- }
-
- if (dltbuf->pos_write >= dltbuf->size)
- {
- dltbuf->pos_write = 0;
- }
-
- /* Second chunk of data (data2, size2) */
- if ((dltbuf->size - dltbuf->pos_write) < size2)
- {
- /* Not enough space til end of linear buffer, */
- /* split up write call */
- part1 = dltbuf->size - dltbuf->pos_write;
- part2 = size2 - part1;
-
- memcpy(dltbuf->buffer + dltbuf->pos_write, data2, part1);
- memcpy(dltbuf->buffer, ((char*)data2) + part1, part2);
- dltbuf->pos_write = part2;
-
- }
- else
- {
- /* Enough space til end of linear buffer */
- memcpy(&(dltbuf->buffer[dltbuf->pos_write]), data2, size2);
- dltbuf->pos_write+=size2;
- }
-
- if (dltbuf->pos_write >= dltbuf->size)
- {
- dltbuf->pos_write = 0;
- }
-
- /* Third chunk of data (data3, size3) */
- if ((dltbuf->size - dltbuf->pos_write) < size3)
- {
- /* Not enough space til end of linear buffer, */
- /* split up write call */
- part1 = dltbuf->size - dltbuf->pos_write;
- part2 = size3 - part1;
-
- memcpy(dltbuf->buffer + dltbuf->pos_write, data3, part1);
- memcpy(dltbuf->buffer, ((char*)data3) + part1, part2);
- dltbuf->pos_write = part2;
-
- }
- else
- {
- /* Enough space til end of linear buffer */
- memcpy(dltbuf->buffer + dltbuf->pos_write, data3, size3);
- dltbuf->pos_write+=size3;
- }
-
- dltbuf->count++;
-
- return 0;
-}
-
-int dlt_ringbuffer_get(DltRingBuffer *dltbuf, void *data, size_t *size)
-{
- uint32_t tmpsize=0;
- uint32_t sui;
-
- uint32_t part1, part2;
-
- if (dltbuf==0)
- {
- return -1;
- }
-
- if (dltbuf->buffer==0)
- {
- return -1;
- }
-
- if (dltbuf->count==0)
- {
- return -1;
- }
-
- sui = sizeof(uint32_t);
-
- if (dltbuf->pos_read >= dltbuf->size)
- {
- dltbuf->pos_read = 0;
- }
-
- if ((dltbuf->size - dltbuf->pos_read) < sui)
- {
- dltbuf->pos_read = 0;
- }
-
- /* printf("Reading at offset: %d\n", dltbuf->pos_read); */
-
- memcpy(&tmpsize,&(dltbuf->buffer[dltbuf->pos_read]), sui);
- dltbuf->pos_read += sui;
-
- if (dltbuf->pos_read >= dltbuf->size)
- {
- dltbuf->pos_read = 0;
- }
-
- if ((tmpsize>0) && ((tmpsize+sizeof(uint32_t))<=dltbuf->size))
- {
- if ((dltbuf->size - dltbuf->pos_read) < tmpsize)
- {
- /* Not enough space til end of linear buffer, */
- /* split up read call */
- part1 = dltbuf->size - dltbuf->pos_read;
- part2 = tmpsize - part1;
-
- memcpy(data, dltbuf->buffer + dltbuf->pos_read, part1);
- memcpy(((char*)data)+part1, dltbuf->buffer, part2);
- dltbuf->pos_read = part2;
- }
- else
- {
- /* Enough space til end of linear buffer */
- /* no split up read call */
- memcpy(data, &(dltbuf->buffer[dltbuf->pos_read]), tmpsize);
- dltbuf->pos_read+=tmpsize;
- }
- *size = tmpsize;
- }
- else
- {
- data=0;
- *size=0;
- }
-
- dltbuf->count--;
-
- return 0;
-}
-
-int dlt_ringbuffer_get_skip(DltRingBuffer *dltbuf)
-{
- uint32_t tmpsize=0;
- uint32_t sui;
-
- uint32_t part1, part2;
-
- if (dltbuf==0)
- {
- return -1;
- }
-
- if (dltbuf->buffer==0)
- {
- return -1;
- }
-
- if (dltbuf->count==0)
- {
- return -1;
- }
-
- sui = sizeof(uint32_t);
-
- if (dltbuf->pos_read >= dltbuf->size)
- {
- dltbuf->pos_read = 0;
- }
-
- if ((dltbuf->size - dltbuf->pos_read) < sui)
- {
- dltbuf->pos_read = 0;
- }
-
- memcpy(&tmpsize,&(dltbuf->buffer[dltbuf->pos_read]), sui);
- dltbuf->pos_read += sui;
-
- if (dltbuf->pos_read >= dltbuf->size)
- {
- dltbuf->pos_read = 0;
- }
-
- if ((tmpsize>0) && ((tmpsize+sui)<=dltbuf->size))
- {
- if ((dltbuf->size - dltbuf->pos_read) < tmpsize)
- {
- /* Not enough space til end of linear buffer */
- part1 = dltbuf->size - dltbuf->pos_read;
- part2 = tmpsize - part1;
-
- dltbuf->pos_read = part2;
- }
- else
- {
- /* Enough space til end of linear buffer */
- dltbuf->pos_read+=tmpsize;
- }
- }
-
- dltbuf->count--;
-
- return 0;
-}
-
-int dlt_ringbuffer_freespacewrite(DltRingBuffer *dltbuf, uint32_t *freespace)
-{
- if ((dltbuf==0) || (freespace==0))
- {
- return -1;
- }
-
- *freespace=0;
-
- /* Space til pos_read */
- if (dltbuf->pos_read > dltbuf->pos_write)
- {
- *freespace=(dltbuf->pos_read - dltbuf->pos_write);
- return 0;
- }
- else if (dltbuf->pos_read < dltbuf->pos_write)
- {
- *freespace=(dltbuf->size - dltbuf->pos_write + dltbuf->pos_read );
- return 0;
- }
- else
- {
- if (dltbuf->count)
- {
- return 0;
- }
- else
- {
- *freespace=dltbuf->size;
- return 0;
- }
- }
- return 0;
-}
-
-int dlt_ringbuffer_checkandfreespace(DltRingBuffer *dltbuf, uint32_t reqspace)
-{
- uint32_t space_left;
-
- if (dltbuf==0)
- {
- return -1;
- }
-
- if (dlt_ringbuffer_freespacewrite(dltbuf,&space_left) == -1)
- {
- return -1;
- }
-
- /* printf("Now reading at: %d, space_left = %d, req = %d, r=%d, w=%d, count=%d \n",
- dltbuf->pos_read,space_left, reqspace, dltbuf->pos_read, dltbuf->pos_write, dltbuf->count); */
-
- while (space_left<reqspace)
- {
- /* Overwrite, correct read position */
-
- /* Read and skip one element */
- dlt_ringbuffer_get_skip(dltbuf);
-
- /* Space until pos_read */
- if (dlt_ringbuffer_freespacewrite(dltbuf,&space_left) == -1)
- {
- return -1;
- }
-
- /* printf("Overwrite: Now reading at: %d, space_left = %d, req = %d, r=%d, w=%d, count=%d \n",
- dltbuf->pos_read,space_left, reqspace, dltbuf->pos_read, dltbuf->pos_write, dltbuf->count); */
- }
-
- return 0;
-}
-
#if !defined (__WIN32__)
int dlt_setup_serial(int fd, speed_t speed)
diff --git a/src/shared/dlt_shm.c b/src/shared/dlt_shm.c
index 5f54f88..f330864 100644
--- a/src/shared/dlt_shm.c
+++ b/src/shared/dlt_shm.c
@@ -211,6 +211,10 @@ int dlt_shm_get_used_size(DltShm *buf)
{
int ret;
+ /* check if buffer available */
+ if(!buf->buffer.mem)
+ return -1;
+
DLT_SHM_SEM_GET(buf->semid);
ret = dlt_buffer_get_used_size(&(buf->buffer));
DLT_SHM_SEM_FREE(buf->semid);
@@ -227,6 +231,10 @@ int dlt_shm_push(DltShm *buf,const unsigned char *data1,unsigned int size1,const
{
int ret;
+ /* check if buffer available */
+ if(!buf->buffer.mem)
+ return -1;
+
DLT_SHM_SEM_GET(buf->semid);
ret = dlt_buffer_push3(&(buf->buffer),data1,size1,data2,size2,data3,size3);
DLT_SHM_SEM_FREE(buf->semid);
@@ -238,6 +246,10 @@ int dlt_shm_pull(DltShm *buf,unsigned char *data, int max_size)
{
int ret;
+ /* check if buffer available */
+ if(!buf->buffer.mem)
+ return -1;
+
DLT_SHM_SEM_GET(buf->semid);
ret = dlt_buffer_pull(&(buf->buffer),data,max_size);
DLT_SHM_SEM_FREE(buf->semid);
@@ -249,6 +261,10 @@ int dlt_shm_copy(DltShm *buf,unsigned char *data, int max_size)
{
int ret;
+ /* check if buffer available */
+ if(!buf->buffer.mem)
+ return -1;
+
DLT_SHM_SEM_GET(buf->semid);
ret = dlt_buffer_copy(&(buf->buffer),data,max_size);
DLT_SHM_SEM_FREE(buf->semid);
@@ -260,6 +276,10 @@ int dlt_shm_remove(DltShm *buf)
{
int ret;
+ /* check if buffer available */
+ if(!buf->buffer.mem)
+ return -1;
+
DLT_SHM_SEM_GET(buf->semid);
ret = dlt_buffer_remove(&(buf->buffer));
DLT_SHM_SEM_FREE(buf->semid);
diff --git a/src/system/dlt-system-log.c b/src/system/dlt-system-log.c
index cf2b495..6c9f2bc 100644
--- a/src/system/dlt-system-log.c
+++ b/src/system/dlt-system-log.c
@@ -106,10 +106,16 @@ void dlt_system_filetransfer_run(DltSystemOptions *options,DltSystemRuntime *run
if(runtime->filetransferRunning == 0) {
/* delete last transmitted file */
if(runtime->filetransferFile[0]!=0) {
- printf("Remove File: %s\n",runtime->filetransferFile);
- if(remove(runtime->filetransferFile)) {
- printf("Remove file %s failed!\n",runtime->filetransferFile);
- return;
+ if(stat(runtime->filetransferFile,&status)==0)
+ {
+ if(runtime->filetransferFilesize == status.st_size)
+ {
+ /* delete file only if size is not changed since starting transfer */
+ printf("Remove File: %s\n",runtime->filetransferFile);
+ if(remove(runtime->filetransferFile)) {
+ printf("Remove file %s failed!\n",runtime->filetransferFile);
+ }
+ }
}
runtime->filetransferFile[0]=0;
}
@@ -121,10 +127,13 @@ void dlt_system_filetransfer_run(DltSystemOptions *options,DltSystemRuntime *run
while ((dp=readdir(dir)) != NULL) {
if(strcmp(dp->d_name,".")!=0 && strcmp(dp->d_name,"..")!=0) {
sprintf(filename,"%s/%s",options->FiletransferDirectory1,dp->d_name);
- stat(filename,&status);
- if(time_oldest == 0 || status.st_mtime < time_oldest) {
- time_oldest = status.st_mtime;
- strcpy(runtime->filetransferFile,filename);
+ if(stat(filename,&status)==0)
+ {
+ if((time_oldest == 0 || status.st_mtime < time_oldest) && (status.st_size != 0) ) {
+ time_oldest = status.st_mtime;
+ strcpy(runtime->filetransferFile,filename);
+ runtime->filetransferFilesize = status.st_size;
+ }
}
}
}
@@ -135,10 +144,13 @@ void dlt_system_filetransfer_run(DltSystemOptions *options,DltSystemRuntime *run
while ((dp=readdir(dir)) != NULL) {
if(strcmp(dp->d_name,".")!=0 && strcmp(dp->d_name,"..")!=0) {
sprintf(filename,"%s/%s",options->FiletransferDirectory2,dp->d_name);
- stat(filename,&status);
- if(time_oldest == 0 || status.st_mtime < time_oldest) {
- time_oldest = status.st_mtime;
- strcpy(runtime->filetransferFile,filename);
+ if(stat(filename,&status)==0)
+ {
+ if((time_oldest == 0 || status.st_mtime < time_oldest) && (status.st_size != 0) ) {
+ time_oldest = status.st_mtime;
+ strcpy(runtime->filetransferFile,filename);
+ runtime->filetransferFilesize = status.st_size;
+ }
}
}
}
@@ -151,8 +163,10 @@ void dlt_system_filetransfer_run(DltSystemOptions *options,DltSystemRuntime *run
runtime->filetransferCountPackages = dlt_user_log_file_packagesCount(context,runtime->filetransferFile);
if(runtime->filetransferCountPackages < 0 )
{
+ /* a problem occured; stop filetransfer and continue with next file after timeout */
printf("Error: dlt_user_log_file_packagesCount\n");
runtime->filetransferCountPackages = 0;
+ runtime->filetransferRunning = 0;
runtime->timeFiletransferDelay = options->FiletransferTimeDelay;
return;
}
@@ -160,6 +174,7 @@ void dlt_system_filetransfer_run(DltSystemOptions *options,DltSystemRuntime *run
transferResult = dlt_user_log_file_header(context,runtime->filetransferFile);
if(transferResult < 0)
{
+ /* a problem occured; stop filetransfer and continue with next file after timeout */
printf("Error: dlt_user_log_file_header\n");
runtime->filetransferCountPackages = 0;
runtime->filetransferRunning = 0;
@@ -178,7 +193,11 @@ void dlt_system_filetransfer_run(DltSystemOptions *options,DltSystemRuntime *run
transferResult = dlt_user_log_file_data(context,runtime->filetransferFile,runtime->filetransferLastSentPackage,0);
if(transferResult < 0)
{
+ /* a problem occured; stop filetransfer and continue with next file after timeout */
printf("Error: dlt_user_log_file_data\n");
+ runtime->filetransferCountPackages = 0;
+ runtime->filetransferRunning = 0;
+ runtime->timeFiletransferDelay = options->FiletransferTimeDelay;
return;
}
/* wait sending next package if more than 50% of buffer used */
@@ -198,12 +217,8 @@ void dlt_system_filetransfer_run(DltSystemOptions *options,DltSystemRuntime *run
}
runtime->timeFiletransferDelay = options->FiletransferTimeDelay;
runtime->filetransferRunning = 0;
- }
-
- }
-
-
-
+ }
+ }
}
void dlt_system_log_file(DltSystemOptions *options,DltContext *context,int num) {
diff --git a/src/system/dlt-system.h b/src/system/dlt-system.h
index 0a4b7d5..8fca0ae 100644
--- a/src/system/dlt-system.h
+++ b/src/system/dlt-system.h
@@ -114,6 +114,7 @@ typedef struct {
int timeStartup; /* time in seconds since startup of dlt-system */
int timeFiletransferDelay; /* time in seconds to start next filetransfer */
char filetransferFile[256];
+ long int filetransferFilesize;
int timeLogFileDelay[DLT_SYSTEM_LOG_FILE_MAX]; /* time in seconds to start next file log */
int timeLogProcessDelay[DLT_SYSTEM_LOG_PROCESSES_MAX]; /* time in seconds to start next process log */
int filetransferRunning; /* 0 = stooped, 1 = running */
diff --git a/src/tests/dlt-test-internal.c b/src/tests/dlt-test-internal.c
index 462a23e..c716905 100755
--- a/src/tests/dlt-test-internal.c
+++ b/src/tests/dlt-test-internal.c
@@ -109,7 +109,6 @@ void usage()
printf("%s \n", version);
printf("Options:\n");
printf(" -v Verbose mode\n");
- printf(" -1 Execute test 1 (Test ringbuffer)\n");
}
/**
@@ -128,7 +127,7 @@ int main(int argc, char* argv[])
opterr = 0;
- while ((c = getopt (argc, argv, "v1")) != -1)
+ while ((c = getopt (argc, argv, "v")) != -1)
{
switch (c)
{
@@ -137,11 +136,6 @@ int main(int argc, char* argv[])
vflag = 1;
break;
}
- case '1':
- {
- test[0] = 1;
- break;
- }
case '?':
{
if (isprint (optopt))
@@ -190,118 +184,3 @@ int main(int argc, char* argv[])
return 0;
}
-
-void internal1(void)
-{
- int index,result_index;
- size_t c;
- unsigned int size;
-
- char buf[1024],result[1024];
-
- DltRingBuffer mybuf;
-
- printf("Test1i: Ringbuffer, writing and reading \n");
-
- for (size=8;size<=30;size++)
- {
-
- dlt_ringbuffer_init(&mybuf, size);
-
- memset(result,0,1024);
-
- if (vflag)
- {
- printf("\nRingbuffer Size = %d \n\n",size);
- }
-
- /* Write several times to ringbuffer */
- for (index=0; index<6; index++)
- {
- memset(buf,0,1024);
-
- sprintf(buf,"%d",index);
- dlt_ringbuffer_put(&mybuf,buf,strlen(buf));
-
- if (vflag)
- {
- printf("W[%d], Bytes = %d, Hex: ", index, (int)strlen(buf));
- dlt_print_hex((uint8_t *)buf, strlen(buf));
- printf("\n");
- }
- }
-
- if (vflag)
- {
- printf("\nCount=%d, Max. by buffer size %d = %d\n",mybuf.count, size, (int)(size/(strlen(buf)+sizeof(unsigned int))));
- }
-
- /* Check value of mybuf.count, counting the elements in ringbuffer */
- if (mybuf.count!=(int)(size/(strlen(buf)+sizeof(unsigned int))))
- {
- tests_failed++;
- printf("Test1i FAILED\n");
-
- break;
- }
-
- result_index = 0;
-
- /* Read several times from ringbuffer */
- for (index=0; index<6; index++)
- {
- memset(buf,0,1024);
-
- if (dlt_ringbuffer_get(&mybuf,buf,&c)!=-1)
- {
- if (vflag)
- {
- printf("R[%d], Bytes = %d, Hex: ", index, (int)c);
- dlt_print_hex((uint8_t *)buf, c);
- printf("\n");
- }
-
- if (c==1)
- {
- result[result_index] = buf[0];
- }
- result_index++;
- }
- }
-
- /* Check value of mybuf.count, counting the elements in ringbuffer, must be 0 now */
- if (mybuf.count!=0)
- {
- tests_failed++;
- printf("Test1i FAILED\n");
-
- dlt_ringbuffer_free(&mybuf);
- return;
- }
-
- /* Check the read elements */
- for (index=0; index<result_index; index++)
- {
- sprintf(buf,"%d",((6-result_index)+index));
- if (result[index]!=buf[0])
- {
- tests_failed++;
- printf("Test1i FAILED\n");
-
- dlt_ringbuffer_free(&mybuf);
- return;
- }
- }
-
- if (vflag)
- {
- printf("\n");
- }
-
- dlt_ringbuffer_free(&mybuf);
- }
-
- tests_passed++;
- printf("Test1i PASSED\n");
-}
-