summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/dlt/dlt_common.h31
-rw-r--r--include/dlt/dlt_user.h10
-rw-r--r--include/dlt/dlt_user_macros.h30
-rw-r--r--src/daemon/dlt-daemon.c9
-rw-r--r--src/daemon/dlt_daemon_common.c7
-rw-r--r--src/daemon/dlt_daemon_connection.c21
-rw-r--r--src/examples/dlt-example-user.c34
-rw-r--r--src/gateway/dlt_gateway.c2
-rw-r--r--src/lib/dlt_client.c12
-rw-r--r--src/lib/dlt_user.c454
-rw-r--r--src/lib/dlt_user_cfg.h6
-rw-r--r--src/shared/dlt_common.c115
12 files changed, 472 insertions, 259 deletions
diff --git a/include/dlt/dlt_common.h b/include/dlt/dlt_common.h
index f939329..4803663 100644
--- a/include/dlt/dlt_common.h
+++ b/include/dlt/dlt_common.h
@@ -381,6 +381,16 @@ enum {
#else
#define DLT_STATIC
#endif
+
+/**
+ * Type to specify whether received data is from socket or file/fifo
+ */
+typedef enum
+{
+ DLT_RECEIVE_SOCKET,
+ DLT_RECEIVE_FD
+} DltReceiverType;
+
/**
* The definition of the serial header containing the characters "DLS" + 0x01.
*/
@@ -753,6 +763,7 @@ typedef struct
int32_t totalBytesRcvd; /**< total number of received bytes */
char *buffer; /**< pointer to receiver buffer */
char *buf; /**< pointer to position within receiver buffer */
+ char *backup_buf; /** pointer to the buffer with partial messages if any **/
int fd; /**< connection handle */
int32_t buffersize; /**< size of receiver buffer */
} DltReceiver;
@@ -1150,24 +1161,26 @@ extern "C"
*/
DltReturnValue dlt_receiver_free(DltReceiver *receiver);
/**
- * Receive data from socket using the dlt receiver structure
+ * Initialising a dlt receiver structure
* @param receiver pointer to dlt receiver structure
- * @return number of received bytes or negative value if there was an error
+ * @param fd handle to file/socket/fifo, fram which the data should be received
+ * @param buffer data buffer for storing the received data
+ * @return negative value if there was an error and zero if success
*/
- int dlt_receiver_receive_socket(DltReceiver *receiver);
+ DltReturnValue dlt_receiver_init_unix_socket(DltReceiver *receiver, int fd, char **buffer);
/**
- * Receive data from file/fifo using the dlt receiver structure
+ * De-Initialize a dlt receiver structure
* @param receiver pointer to dlt receiver structure
- * @return number of received bytes or negative value if there was an error
+ * @return negative value if there was an error and zero if success
*/
- int dlt_receiver_receive_fd(DltReceiver *receiver);
+ DltReturnValue dlt_receiver_free_unix_socket(DltReceiver *receiver);
/**
- * Receive data from file/fifo/socket, calls corresponding function based on
- * CMake configuration.
+ * Receive data from socket or file/fifo using the dlt receiver structure
* @param receiver pointer to dlt receiver structure
+ * @param from_src specify whether received data is from socket or file/fifo
* @return number of received bytes or negative value if there was an error
*/
- int dlt_receiver_receive(DltReceiver *receiver);
+ int dlt_receiver_receive(DltReceiver *receiver, DltReceiverType from_src);
/**
* Remove a specific size of bytes from the received data
* @param receiver pointer to dlt receiver structure
diff --git a/include/dlt/dlt_user.h b/include/dlt/dlt_user.h
index 82e5e31..8e676c6 100644
--- a/include/dlt/dlt_user.h
+++ b/include/dlt/dlt_user.h
@@ -115,7 +115,7 @@ typedef struct
typedef struct
{
DltContext *handle; /**< pointer to DltContext */
- unsigned char buffer[DLT_USER_BUF_MAX_SIZE]; /**< buffer for building log message*/
+ unsigned char *buffer; /**< buffer for building log message*/
int32_t size; /**< payload size */
int32_t log_level; /**< log level */
int32_t trace_status; /**< trace status */
@@ -222,7 +222,7 @@ typedef struct
DltBuffer startup_buffer; /**< Ring-buffer for buffering messages during startup and missing connection */
/* Buffer used for resending, locked by DLT semaphore */
- uint8_t resend_buffer[DLT_USER_RESENDBUF_MAX_SIZE];
+ uint8_t *resend_buffer;
uint32_t timeout_at_exit_handler; /**< timeout used in dlt_user_atexit_blow_out_user_buffer, in 0.1 milliseconds */
dlt_env_ll_set initial_ll_set;
@@ -236,6 +236,7 @@ typedef struct
int16_t corrupt_message_size_size;
#endif
DltUserConnectionState connection_state;
+ uint16_t log_buf_len; /**< length of message buffer, by default: DLT_USER_BUF_MAX_SIZE */
} DltUser;
/**************************************************************************************************
@@ -795,6 +796,11 @@ DltReturnValue dlt_user_log_resend_buffer(void);
*/
static inline DltReturnValue dlt_user_is_logLevel_enabled(DltContext *handle,DltLogLevelType loglevel)
{
+ if (loglevel < DLT_LOG_OFF || loglevel >= DLT_LOG_MAX)
+ {
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+
if (handle == NULL || handle->log_level_ptr == NULL)
{
return DLT_RETURN_WRONG_PARAMETER;
diff --git a/include/dlt/dlt_user_macros.h b/include/dlt/dlt_user_macros.h
index d50b335..e1b1267 100644
--- a/include/dlt/dlt_user_macros.h
+++ b/include/dlt/dlt_user_macros.h
@@ -187,16 +187,13 @@
#else
#define DLT_LOG(CONTEXT,LOGLEVEL,ARGS...) \
do { \
- if(dlt_user_is_logLevel_enabled(&CONTEXT,LOGLEVEL)==DLT_RETURN_TRUE) \
+ DltContextData log_local; \
+ int dlt_local; \
+ dlt_local = dlt_user_log_write_start(&CONTEXT,&log_local,LOGLEVEL); \
+ if (dlt_local == DLT_RETURN_TRUE) \
{ \
- DltContextData log_local; \
- int dlt_local; \
- dlt_local = dlt_user_log_write_start(&CONTEXT,&log_local,LOGLEVEL); \
- if (dlt_local > 0) \
- { \
- ARGS; \
- (void)dlt_user_log_write_finish(&log_local); \
- } \
+ ARGS; \
+ (void)dlt_user_log_write_finish(&log_local); \
} \
} while(0)
#endif
@@ -219,16 +216,13 @@
#else
#define DLT_LOG_ID(CONTEXT,LOGLEVEL,MSGID,ARGS...) \
do { \
- if(dlt_user_is_logLevel_enabled(&CONTEXT,LOGLEVEL)==DLT_RETURN_TRUE) \
+ DltContextData log_local; \
+ int dlt_local; \
+ dlt_local = dlt_user_log_write_start_id(&CONTEXT,&log_local,LOGLEVEL,MSGID); \
+ if (dlt_local == DLT_RETURN_TRUE) \
{ \
- DltContextData log_local; \
- int dlt_local; \
- dlt_local = dlt_user_log_write_start_id(&CONTEXT,&log_local,LOGLEVEL,MSGID); \
- if (dlt_local > 0) \
- { \
- ARGS; \
- (void)dlt_user_log_write_finish(&log_local); \
- } \
+ ARGS; \
+ (void)dlt_user_log_write_finish(&log_local); \
} \
} while(0)
#endif
diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c
index 9956e3b..db932d0 100644
--- a/src/daemon/dlt-daemon.c
+++ b/src/daemon/dlt-daemon.c
@@ -1714,7 +1714,7 @@ int dlt_daemon_process_client_messages(DltDaemon *daemon,
return -1;
}
- must_close_socket = dlt_receiver_receive_socket(receiver);
+ must_close_socket = dlt_receiver_receive(receiver, DLT_RECEIVE_SOCKET);
if (must_close_socket < 0)
{
dlt_daemon_close_socket(receiver->fd,
@@ -1801,7 +1801,7 @@ int dlt_daemon_process_client_messages_serial(DltDaemon *daemon,
return -1;
}
- if (dlt_receiver_receive_fd(receiver) <= 0)
+ if (dlt_receiver_receive(receiver, DLT_RECEIVE_FD) <= 0)
{
dlt_log(LOG_WARNING,
"dlt_receiver_receive_fd() for messages from serial interface "
@@ -1993,7 +1993,7 @@ int dlt_daemon_process_control_messages(
return -1;
}
- if (dlt_receiver_receive_socket(receiver) <= 0)
+ if (dlt_receiver_receive(receiver, DLT_RECEIVE_SOCKET) <= 0)
{
dlt_daemon_close_socket(receiver->fd,
daemon,
@@ -2127,8 +2127,8 @@ int dlt_daemon_process_user_messages(DltDaemon *daemon,
return -1;
}
- recv = dlt_receiver_receive(receiver);
#ifdef DLT_USE_UNIX_SOCKET_IPC
+ recv = dlt_receiver_receive(receiver, DLT_RECEIVE_SOCKET);
if (recv <= 0)
{
dlt_daemon_close_socket(receiver->fd,
@@ -2139,6 +2139,7 @@ int dlt_daemon_process_user_messages(DltDaemon *daemon,
return 0;
}
#else
+ recv = dlt_receiver_receive(receiver, DLT_RECEIVE_FD);
if (recv < 0)
{
dlt_log(LOG_WARNING,
diff --git a/src/daemon/dlt_daemon_common.c b/src/daemon/dlt_daemon_common.c
index 990c029..ce2de71 100644
--- a/src/daemon/dlt_daemon_common.c
+++ b/src/daemon/dlt_daemon_common.c
@@ -89,7 +89,7 @@
#include "dlt_daemon_serial.h"
static char str[DLT_DAEMON_COMMON_TEXTBUFSIZE];
-
+char *app_recv_buffer = NULL; /* pointer to receiver buffer for application msges */
sem_t dlt_daemon_mutex;
static int dlt_daemon_cmp_apid(const void *m1, const void *m2)
@@ -280,7 +280,10 @@ int dlt_daemon_free(DltDaemon *daemon, int verbose)
}
free(daemon->user_list);
-
+ if (app_recv_buffer)
+ {
+ free(app_recv_buffer);
+ }
/* free ringbuffer */
dlt_buffer_free_dynamic(&(daemon->client_ringbuffer));
diff --git a/src/daemon/dlt_daemon_connection.c b/src/daemon/dlt_daemon_connection.c
index 7e823fb..4287623 100644
--- a/src/daemon/dlt_daemon_connection.c
+++ b/src/daemon/dlt_daemon_connection.c
@@ -49,6 +49,7 @@
#include "dlt_daemon_socket.h"
static DltConnectionId connectionId;
+extern char *app_recv_buffer;
/** @brief Generic sending function.
*
@@ -168,6 +169,11 @@ DLT_STATIC void dlt_connection_destroy_receiver(DltConnection *con)
case DLT_CONNECTION_GATEWAY:
/* We rely on the gateway for clean-up */
break;
+ case DLT_CONNECTION_APP_MSG:
+ dlt_receiver_free_unix_socket(con->receiver);
+ free(con->receiver);
+ con->receiver = NULL;
+ break;
default:
(void) dlt_receiver_free(con->receiver);
free(con->receiver);
@@ -216,11 +222,18 @@ DLT_STATIC DltReceiver *dlt_connection_get_receiver(DltDaemonLocal *daemon_local
dlt_receiver_init(ret, fd, DLT_DAEMON_RCVBUFSIZESERIAL);
}
break;
-#ifdef DLT_USE_UNIX_SOCKET_IPC
- case DLT_CONNECTION_APP_CONNECT:
- /* FALL THROUGH */
-#endif
case DLT_CONNECTION_APP_MSG:
+ ret = calloc(1, sizeof(DltReceiver));
+ if (ret)
+ {
+ #ifdef DLT_USE_UNIX_SOCKET_IPC
+ dlt_receiver_init_unix_socket(ret, fd, &app_recv_buffer);
+ #else
+ dlt_receiver_init(ret, fd, DLT_APP_RCV_BUF_MAX);
+ #endif
+ }
+ break;
+ case DLT_CONNECTION_APP_CONNECT:
/* FALL THROUGH */
case DLT_CONNECTION_ONE_S_TIMER:
/* FALL THROUGH */
diff --git a/src/examples/dlt-example-user.c b/src/examples/dlt-example-user.c
index 532402a..12d9c37 100644
--- a/src/examples/dlt-example-user.c
+++ b/src/examples/dlt-example-user.c
@@ -103,6 +103,7 @@ void usage()
printf(" -m mode Set log mode 0=off,1=external,2=internal,3=both\n");
printf(" -l level Set log level to <level>, level=-1..6\n");
printf(" -t timeout Set timeout when sending messages at exit, in ms (Default: 10000 = 10sec)\n");
+ printf(" -r size Send raw data with specified size instead of string\n");
#ifdef DLT_TEST_ENABLE
printf(" -c Corrupt user header\n");
printf(" -s size Corrupt message size\n");
@@ -130,6 +131,7 @@ int main(int argc, char* argv[])
char *message = 0;
int lvalue = DLT_LOG_WARN;
char *tvalue = 0;
+ int rvalue = -1;
int index;
int c;
@@ -142,9 +144,9 @@ int main(int argc, char* argv[])
opterr = 0;
#ifdef DLT_TEST_ENABLE
- while ((c = getopt (argc, argv, "vgakcd:f:n:m:z:s:l:t:")) != -1)
+ while ((c = getopt (argc, argv, "vgakcd:f:n:m:z:r:s:l:t:")) != -1)
#else
- while ((c = getopt (argc, argv, "vgakd:f:n:m:l:t:")) != -1)
+ while ((c = getopt (argc, argv, "vgakd:f:n:m:l:r:t:")) != -1)
#endif /* DLT_TEST_ENABLE */
{
switch (c)
@@ -211,6 +213,11 @@ int main(int argc, char* argv[])
tvalue = optarg;
break;
}
+ case 'r':
+ {
+ rvalue = atoi(optarg);
+ break;
+ }
case '?':
{
if (optopt == 'd' || optopt == 'f' || optopt == 'n'|| optopt == 'l' || optopt == 't')
@@ -238,9 +245,17 @@ int main(int argc, char* argv[])
}
}
- for (index = optind; index < argc; index++)
+ if (rvalue == -1)
+ {
+ for (index = optind; index < argc; index++)
+ {
+ message = argv[index];
+ }
+ }
+ else /* allocate raw buffer */
{
- message = argv[index];
+ message = calloc(sizeof(char), rvalue);
+ memset(message, 'X', rvalue-1);
}
if (message == 0)
@@ -377,8 +392,15 @@ int main(int argc, char* argv[])
}
else
{
- /* Verbose mode */
- DLT_LOG(mycontext,lvalue,DLT_INT(num),DLT_STRING(text));
+ if (rvalue == -1)
+ {
+ /* Verbose mode */
+ DLT_LOG(mycontext,lvalue,DLT_INT(num),DLT_STRING(text));
+ }
+ else
+ {
+ DLT_LOG(mycontext,lvalue,DLT_RAW(text, rvalue));
+ }
}
if (delay>0)
diff --git a/src/gateway/dlt_gateway.c b/src/gateway/dlt_gateway.c
index 4784bed..7edf6b7 100644
--- a/src/gateway/dlt_gateway.c
+++ b/src/gateway/dlt_gateway.c
@@ -1321,7 +1321,7 @@ DltReturnValue dlt_gateway_process_passive_node_messages(DltDaemon *daemon,
}
/* nearly copy and paste of dlt_client_main_loop function */
- if (dlt_receiver_receive_socket(receiver) <= 0)
+ if (dlt_receiver_receive(receiver, DLT_RECEIVE_SOCKET) <= 0)
{
/* No more data to be received */
if (dlt_message_free(&msg, verbose) < 0)
diff --git a/src/lib/dlt_client.c b/src/lib/dlt_client.c
index efac848..0b22890 100644
--- a/src/lib/dlt_client.c
+++ b/src/lib/dlt_client.c
@@ -340,16 +340,8 @@ DltReturnValue dlt_client_main_loop(DltClient *client, void *data, int verbose)
while (1)
{
- if (client->mode==0)
- {
- /* wait for data from socket */
- ret = dlt_receiver_receive_socket(&(client->receiver));
- }
- else
- {
- /* wait for data from serial connection */
- ret = dlt_receiver_receive_fd(&(client->receiver));
- }
+ /* wait for data from socket or serial connection */
+ ret = dlt_receiver_receive(&(client->receiver), client->mode);
if (ret<=0)
{
diff --git a/src/lib/dlt_user.c b/src/lib/dlt_user.c
index 0e4c42b..2e147f5 100644
--- a/src/lib/dlt_user.c
+++ b/src/lib/dlt_user.c
@@ -538,6 +538,8 @@ DltReturnValue dlt_init_common(void)
uint32_t buffer_max = DLT_USER_RINGBUFFER_MAX_SIZE;
char *env_buffer_step;
uint32_t buffer_step = DLT_USER_RINGBUFFER_STEP_SIZE;
+ char *env_log_buffer_len;
+ uint32_t buffer_max_configured = 0;
/* Binary semaphore for threads */
if (sem_init(&dlt_mutex, 0, 1)==-1)
@@ -653,6 +655,39 @@ DltReturnValue dlt_init_common(void)
}
}
+ /* init log buffer size */
+ dlt_user.log_buf_len = DLT_USER_BUF_MAX_SIZE;
+ env_log_buffer_len = getenv(DLT_USER_ENV_LOG_MSG_BUF_LEN);
+
+ if (env_log_buffer_len != NULL)
+ {
+ buffer_max_configured = (uint32_t) strtol(env_log_buffer_len, NULL, 10);
+
+ if (buffer_max_configured > DLT_LOG_MSG_BUF_MAX_SIZE)
+ {
+ dlt_user.log_buf_len = DLT_LOG_MSG_BUF_MAX_SIZE;
+ dlt_vlog(LOG_WARNING,
+ "Configured size exceeds maximum allowed size,restricting to max [65535 bytes]\n");
+ }
+ else
+ {
+ dlt_user.log_buf_len = buffer_max_configured;
+ dlt_vlog(LOG_INFO,
+ "Configured buffer size to [%d bytes]\n",
+ buffer_max_configured);
+ }
+ }
+ if (dlt_user.resend_buffer == NULL)
+ {
+ dlt_user.resend_buffer = calloc(sizeof(unsigned char), dlt_user.log_buf_len);
+ if (dlt_user.resend_buffer == NULL)
+ {
+ dlt_user_initialised = false;
+ DLT_SEM_FREE();
+ dlt_vlog(LOG_ERR, "cannot allocate memory for resend buffer\n");
+ return DLT_RETURN_ERROR;
+ }
+ }
if (dlt_buffer_init_dynamic(&(dlt_user.startup_buffer),
buffer_min,
buffer_max,
@@ -761,6 +796,15 @@ int dlt_user_atexit_blow_out_user_buffer(void){
return count;
}
+static void dlt_user_free_buffer(unsigned char **buffer)
+{
+ if (*buffer)
+ {
+ free(*buffer);
+ *buffer = NULL;
+ }
+}
+
DltReturnValue dlt_free(void)
{
uint32_t i;
@@ -813,6 +857,7 @@ DltReturnValue dlt_free(void)
/* Ignore return value */
DLT_SEM_LOCK();
+ dlt_user_free_buffer(&(dlt_user.resend_buffer));
dlt_buffer_free_dynamic(&(dlt_user.startup_buffer));
DLT_SEM_FREE();
@@ -1555,53 +1600,58 @@ DltReturnValue dlt_user_log_write_start_id(DltContext *handle, DltContextData *l
if (handle == NULL || log == NULL)
return DLT_RETURN_WRONG_PARAMETER;
- if (loglevel < DLT_USER_LOG_LEVEL_NOT_SET || loglevel >= DLT_LOG_MAX)
- {
- dlt_vlog(LOG_ERR, "Loglevel %d is outside valid range", loglevel);
- return DLT_RETURN_WRONG_PARAMETER;
- }
+ /* check log levels */
+ if (dlt_user_is_logLevel_enabled(handle, loglevel) < DLT_RETURN_TRUE)
+ return DLT_RETURN_OK;
+ /* initialize values */
if (dlt_user_log_init(handle, log) < DLT_RETURN_OK || dlt_user.dlt_ll_ts == NULL)
return DLT_RETURN_ERROR;
/* initialize values */
+ if (log->buffer == NULL)
+ {
+ log->buffer = calloc(sizeof(unsigned char), dlt_user.log_buf_len);
+ if (log->buffer == NULL)
+ {
+ dlt_vlog(LOG_ERR, "Cannot allocate buffer for DLT Log message\n");
+ return DLT_RETURN_ERROR;
+ }
+ }
+
log->args_num = 0;
log->log_level = loglevel;
log->size = 0;
- /* check log levels */
- if (dlt_user_is_logLevel_enabled(handle, loglevel) == DLT_RETURN_TRUE)
+ /* In non-verbose mode, insert message id */
+ if (dlt_user.verbose_mode == 0)
{
- /* In non-verbose mode, insert message id */
- if (dlt_user.verbose_mode == 0)
- {
- if ((sizeof(uint32_t)) > DLT_USER_BUF_MAX_SIZE)
- return DLT_RETURN_USER_BUFFER_FULL;
-
- /* Write message id */
- memcpy(log->buffer, &(messageid), sizeof(uint32_t));
- log->size = sizeof(uint32_t);
+ if ((sizeof(uint32_t)) > dlt_user.log_buf_len)
+ return DLT_RETURN_USER_BUFFER_FULL;
- /* as the message id is part of each message in non-verbose mode,
- it doesn't increment the argument counter in extended header (if used) */
- }
+ /* Write message id */
+ memcpy(log->buffer, &(messageid), sizeof(uint32_t));
+ log->size = sizeof(uint32_t);
- return DLT_RETURN_TRUE;
- }
- else
- {
- return DLT_RETURN_OK;
+ /* as the message id is part of each message in non-verbose mode,
+ it doesn't increment the argument counter in extended header (if used) */
}
- return DLT_RETURN_ERROR;
+ return DLT_RETURN_TRUE;
}
DltReturnValue dlt_user_log_write_finish(DltContextData *log)
{
+ int ret = DLT_RETURN_ERROR;
+
if (log == NULL)
return DLT_RETURN_WRONG_PARAMETER;
- return dlt_user_log_send_log(log, DLT_TYPE_LOG);
+ ret = dlt_user_log_send_log(log, DLT_TYPE_LOG);
+
+ dlt_user_free_buffer(&(log->buffer));
+
+ return ret;
}
DltReturnValue dlt_user_log_write_raw(DltContextData *log, void *data, uint16_t length)
@@ -1633,16 +1683,17 @@ DltReturnValue dlt_user_log_write_raw_formatted(DltContextData *log, void *data,
new_log_size = log->size + length + sizeof(uint16_t);
- if (new_log_size > DLT_USER_BUF_MAX_SIZE)
+ if (new_log_size > dlt_user.log_buf_len)
return DLT_RETURN_USER_BUFFER_FULL;
if (dlt_user.verbose_mode)
{
new_log_size = log->size + length + sizeof(uint32_t) + sizeof(uint16_t);
- if (new_log_size > DLT_USER_BUF_MAX_SIZE)
+ if (new_log_size > dlt_user.log_buf_len)
return DLT_RETURN_USER_BUFFER_FULL;
+
/* Transmit type information */
type_info = DLT_TYPE_INFO_RAWD;
@@ -1691,12 +1742,12 @@ DltReturnValue dlt_user_log_write_float32(DltContextData *log, float32_t data)
return DLT_RETURN_ERROR;
}
- if ((log->size+sizeof(float32_t))>DLT_USER_BUF_MAX_SIZE)
+ if ((log->size+sizeof(float32_t))>dlt_user.log_buf_len)
return DLT_RETURN_USER_BUFFER_FULL;
if (dlt_user.verbose_mode)
{
- if ((log->size+sizeof(uint32_t)+sizeof(float32_t))>DLT_USER_BUF_MAX_SIZE)
+ if ((log->size+sizeof(uint32_t)+sizeof(float32_t))>dlt_user.log_buf_len)
return DLT_RETURN_USER_BUFFER_FULL;
type_info = DLT_TYPE_INFO_FLOA | DLT_TYLE_32BIT;
@@ -1731,12 +1782,12 @@ DltReturnValue dlt_user_log_write_float64(DltContextData *log, float64_t data)
return DLT_RETURN_ERROR;
}
- if ((log->size+sizeof(float64_t))>DLT_USER_BUF_MAX_SIZE)
+ if ((log->size+sizeof(float64_t))>dlt_user.log_buf_len)
return DLT_RETURN_USER_BUFFER_FULL;
if (dlt_user.verbose_mode)
{
- if ((log->size+sizeof(uint32_t)+sizeof(float64_t))>DLT_USER_BUF_MAX_SIZE)
+ if ((log->size+sizeof(uint32_t)+sizeof(float64_t))>dlt_user.log_buf_len)
return DLT_RETURN_USER_BUFFER_FULL;
type_info = DLT_TYPE_INFO_FLOA | DLT_TYLE_64BIT;
@@ -1809,12 +1860,12 @@ DltReturnValue dlt_user_log_write_uint8(DltContextData *log, uint8_t data)
return DLT_RETURN_ERROR;
}
- if ((log->size+sizeof(uint8_t))>DLT_USER_BUF_MAX_SIZE)
+ if ((log->size+sizeof(uint8_t))>dlt_user.log_buf_len)
return DLT_RETURN_USER_BUFFER_FULL;
if (dlt_user.verbose_mode)
{
- if ((log->size+sizeof(uint32_t)+sizeof(uint8_t))>DLT_USER_BUF_MAX_SIZE)
+ if ((log->size+sizeof(uint32_t)+sizeof(uint8_t))>dlt_user.log_buf_len)
return DLT_RETURN_USER_BUFFER_FULL;
type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_8BIT;
@@ -1844,12 +1895,12 @@ DltReturnValue dlt_user_log_write_uint16(DltContextData *log, uint16_t data)
return DLT_RETURN_ERROR;
}
- if ((log->size+sizeof(uint16_t))>DLT_USER_BUF_MAX_SIZE)
+ if ((log->size+sizeof(uint16_t))>dlt_user.log_buf_len)
return DLT_RETURN_USER_BUFFER_FULL;
if (dlt_user.verbose_mode)
{
- if ((log->size+sizeof(uint32_t)+sizeof(uint16_t))>DLT_USER_BUF_MAX_SIZE)
+ if ((log->size+sizeof(uint32_t)+sizeof(uint16_t))>dlt_user.log_buf_len)
return DLT_RETURN_USER_BUFFER_FULL;
type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_16BIT;
@@ -1879,12 +1930,12 @@ DltReturnValue dlt_user_log_write_uint32(DltContextData *log, uint32_t data)
return DLT_RETURN_ERROR;
}
- if ((log->size+sizeof(uint32_t))>DLT_USER_BUF_MAX_SIZE)
+ if ((log->size+sizeof(uint32_t))>dlt_user.log_buf_len)
return DLT_RETURN_USER_BUFFER_FULL;
if (dlt_user.verbose_mode)
{
- if ((log->size+sizeof(uint32_t)+sizeof(uint32_t))>DLT_USER_BUF_MAX_SIZE)
+ if ((log->size+sizeof(uint32_t)+sizeof(uint32_t))>dlt_user.log_buf_len)
return DLT_RETURN_USER_BUFFER_FULL;
type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_32BIT;
@@ -1914,12 +1965,12 @@ DltReturnValue dlt_user_log_write_uint64(DltContextData *log, uint64_t data)
return DLT_RETURN_ERROR;
}
- if ((log->size+sizeof(uint64_t))>DLT_USER_BUF_MAX_SIZE)
+ if ((log->size+sizeof(uint64_t))>dlt_user.log_buf_len)
return DLT_RETURN_USER_BUFFER_FULL;
if (dlt_user.verbose_mode)
{
- if ((log->size+sizeof(uint32_t)+sizeof(uint64_t))>DLT_USER_BUF_MAX_SIZE)
+ if ((log->size+sizeof(uint32_t)+sizeof(uint64_t))>dlt_user.log_buf_len)
return DLT_RETURN_USER_BUFFER_FULL;
type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_64BIT;
@@ -1956,12 +2007,12 @@ DltReturnValue dlt_user_log_write_uint8_formatted(DltContextData *log, uint8_t d
return DLT_RETURN_ERROR;
}
- if ((log->size+sizeof(uint16_t))>DLT_USER_BUF_MAX_SIZE)
+ if ((log->size+sizeof(uint16_t))>dlt_user.log_buf_len)
return DLT_RETURN_USER_BUFFER_FULL;
if (dlt_user.verbose_mode)
{
- if ((log->size+sizeof(uint32_t)+sizeof(uint16_t))>DLT_USER_BUF_MAX_SIZE)
+ if ((log->size+sizeof(uint32_t)+sizeof(uint16_t))>dlt_user.log_buf_len)
return DLT_RETURN_USER_BUFFER_FULL;
type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_8BIT;
@@ -2008,12 +2059,12 @@ DltReturnValue dlt_user_log_write_uint16_formatted(DltContextData *log, uint16_t
return DLT_RETURN_ERROR;
}
- if ((log->size+sizeof(uint16_t))>DLT_USER_BUF_MAX_SIZE)
+ if ((log->size+sizeof(uint16_t))>dlt_user.log_buf_len)
return DLT_RETURN_USER_BUFFER_FULL;
if (dlt_user.verbose_mode)
{
- if ((log->size+sizeof(uint32_t)+sizeof(uint16_t))>DLT_USER_BUF_MAX_SIZE)
+ if ((log->size+sizeof(uint32_t)+sizeof(uint16_t))>dlt_user.log_buf_len)
return DLT_RETURN_USER_BUFFER_FULL;
type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_16BIT;
@@ -2060,12 +2111,12 @@ DltReturnValue dlt_user_log_write_uint32_formatted(DltContextData *log, uint32_t
return DLT_RETURN_ERROR;
}
- if ((log->size+sizeof(uint16_t))>DLT_USER_BUF_MAX_SIZE)
+ if ((log->size+sizeof(uint16_t))>dlt_user.log_buf_len)
return DLT_RETURN_USER_BUFFER_FULL;
if (dlt_user.verbose_mode)
{
- if ((log->size+sizeof(uint32_t)+sizeof(uint16_t))>DLT_USER_BUF_MAX_SIZE)
+ if ((log->size+sizeof(uint32_t)+sizeof(uint16_t))>dlt_user.log_buf_len)
return DLT_RETURN_USER_BUFFER_FULL;
type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_32BIT;
@@ -2112,12 +2163,12 @@ DltReturnValue dlt_user_log_write_uint64_formatted(DltContextData *log, uint64_t
return DLT_RETURN_ERROR;
}
- if ((log->size+sizeof(uint16_t))>DLT_USER_BUF_MAX_SIZE)
+ if ((log->size+sizeof(uint16_t))>dlt_user.log_buf_len)
return DLT_RETURN_USER_BUFFER_FULL;
if (dlt_user.verbose_mode)
{
- if ((log->size+sizeof(uint32_t)+sizeof(uint16_t))>DLT_USER_BUF_MAX_SIZE)
+ if ((log->size+sizeof(uint32_t)+sizeof(uint16_t))>dlt_user.log_buf_len)
return DLT_RETURN_USER_BUFFER_FULL;
type_info = DLT_TYPE_INFO_UINT | DLT_TYLE_64BIT;
@@ -2232,12 +2283,12 @@ DltReturnValue dlt_user_log_write_int8(DltContextData *log, int8_t data)
return DLT_RETURN_ERROR;
}
- if ((log->size+sizeof(int8_t))>DLT_USER_BUF_MAX_SIZE)
+ if ((log->size+sizeof(int8_t))>dlt_user.log_buf_len)
return DLT_RETURN_USER_BUFFER_FULL;
if (dlt_user.verbose_mode)
{
- if ((log->size+sizeof(uint32_t)+sizeof(int8_t))>DLT_USER_BUF_MAX_SIZE)
+ if ((log->size+sizeof(uint32_t)+sizeof(int8_t))>dlt_user.log_buf_len)
return DLT_RETURN_USER_BUFFER_FULL;
type_info = DLT_TYPE_INFO_SINT | DLT_TYLE_8BIT;
@@ -2267,12 +2318,12 @@ DltReturnValue dlt_user_log_write_int16(DltContextData *log, int16_t data)
return DLT_RETURN_ERROR;
}
- if ((log->size+sizeof(int16_t))>DLT_USER_BUF_MAX_SIZE)
+ if ((log->size+sizeof(int16_t))>dlt_user.log_buf_len)
return DLT_RETURN_USER_BUFFER_FULL;
if (dlt_user.verbose_mode)
{
- if ((log->size+sizeof(uint32_t)+sizeof(int16_t))>DLT_USER_BUF_MAX_SIZE)
+ if ((log->size+sizeof(uint32_t)+sizeof(int16_t))>dlt_user.log_buf_len)
return DLT_RETURN_USER_BUFFER_FULL;
type_info = DLT_TYPE_INFO_SINT | DLT_TYLE_16BIT;
@@ -2302,12 +2353,12 @@ DltReturnValue dlt_user_log_write_int32(DltContextData *log, int32_t data)
return DLT_RETURN_ERROR;
}
- if ((log->size+sizeof(int32_t))>DLT_USER_BUF_MAX_SIZE)
+ if ((log->size+sizeof(int32_t))>dlt_user.log_buf_len)
return DLT_RETURN_USER_BUFFER_FULL;
if (dlt_user.verbose_mode)
{
- if ((log->size+sizeof(uint32_t)+sizeof(int32_t))>DLT_USER_BUF_MAX_SIZE)
+ if ((log->size+sizeof(uint32_t)+sizeof(int32_t))>dlt_user.log_buf_len)
return DLT_RETURN_USER_BUFFER_FULL;
type_info = DLT_TYPE_INFO_SINT | DLT_TYLE_32BIT;
@@ -2337,12 +2388,12 @@ DltReturnValue dlt_user_log_write_int64(DltContextData *log, int64_t data)
return DLT_RETURN_ERROR;
}
- if ((log->size+sizeof(int64_t))>DLT_USER_BUF_MAX_SIZE)
+ if ((log->size+sizeof(int64_t))>dlt_user.log_buf_len)
return DLT_RETURN_USER_BUFFER_FULL;
if (dlt_user.verbose_mode)
{
- if ((log->size+sizeof(uint32_t)+sizeof(int64_t))>DLT_USER_BUF_MAX_SIZE)
+ if ((log->size+sizeof(uint32_t)+sizeof(int64_t))>dlt_user.log_buf_len)
return DLT_RETURN_USER_BUFFER_FULL;
type_info = DLT_TYPE_INFO_SINT | DLT_TYLE_64BIT;
@@ -2372,12 +2423,12 @@ DltReturnValue dlt_user_log_write_bool(DltContextData *log, uint8_t data)
return DLT_RETURN_ERROR;
}
- if ((log->size+sizeof(uint8_t))>DLT_USER_BUF_MAX_SIZE)
+ if ((log->size+sizeof(uint8_t))>dlt_user.log_buf_len)
return DLT_RETURN_USER_BUFFER_FULL;
if (dlt_user.verbose_mode)
{
- if ((log->size+sizeof(uint32_t)+sizeof(uint8_t))>DLT_USER_BUF_MAX_SIZE)
+ if ((log->size+sizeof(uint32_t)+sizeof(uint8_t))>dlt_user.log_buf_len)
return DLT_RETURN_USER_BUFFER_FULL;
type_info = DLT_TYPE_INFO_BOOL;
@@ -2413,14 +2464,14 @@ DltReturnValue dlt_user_log_write_string(DltContextData *log, const char *text)
new_log_size = log->size + arg_size + sizeof(uint16_t);
- if (new_log_size > DLT_USER_BUF_MAX_SIZE)
+ if (new_log_size > dlt_user.log_buf_len)
return DLT_RETURN_USER_BUFFER_FULL;
if (dlt_user.verbose_mode)
{
new_log_size = log->size + arg_size + sizeof(uint32_t) + sizeof(uint16_t);
- if (new_log_size > DLT_USER_BUF_MAX_SIZE)
+ if (new_log_size > dlt_user.log_buf_len)
return DLT_RETURN_USER_BUFFER_FULL;
type_info = DLT_TYPE_INFO_STRG | DLT_SCOD_ASCII;
@@ -2464,14 +2515,14 @@ DltReturnValue dlt_user_log_write_utf8_string(DltContextData *log, const char *t
arg_size = strlen(text) + 1;
new_log_size = log->size + arg_size + sizeof(uint16_t);
- if (new_log_size > DLT_USER_BUF_MAX_SIZE)
+ if (new_log_size > dlt_user.log_buf_len)
return DLT_RETURN_USER_BUFFER_FULL;
if (dlt_user.verbose_mode)
{
new_log_size = log->size + arg_size + sizeof(uint32_t) + sizeof(uint16_t);
- if (new_log_size > DLT_USER_BUF_MAX_SIZE)
+ if (new_log_size > dlt_user.log_buf_len)
return DLT_RETURN_USER_BUFFER_FULL;
type_info = DLT_TYPE_INFO_STRG | DLT_SCOD_UTF8;
@@ -2631,7 +2682,7 @@ DltReturnValue dlt_user_trace_network_segmented_start(uint32_t *id, DltContext *
{
DltContextData log;
struct timeval tv;
-
+ int ret = DLT_RETURN_ERROR;
// check null pointer
if(id == NULL)
return DLT_RETURN_WRONG_PARAMETER;
@@ -2642,14 +2693,23 @@ DltReturnValue dlt_user_trace_network_segmented_start(uint32_t *id, DltContext *
return DLT_RETURN_WRONG_PARAMETER;
}
- if (dlt_user_log_init(handle, &log) < DLT_RETURN_OK)
- return DLT_RETURN_ERROR;
-
if (dlt_user.dlt_ll_ts == NULL)
return DLT_RETURN_ERROR;
if (handle->trace_status_ptr && *(handle->trace_status_ptr) == DLT_TRACE_STATUS_ON)
{
+ /* initialize values */
+ if (dlt_user_log_init(handle, &log) < DLT_RETURN_OK)
+ return DLT_RETURN_ERROR;
+ if (log.buffer == NULL)
+ {
+ log.buffer = calloc(sizeof(unsigned char), dlt_user.log_buf_len);
+ if (log.buffer == NULL)
+ {
+ dlt_vlog(LOG_ERR, "Cannot allocate buffer for DLT Log message\n");
+ return DLT_RETURN_ERROR;
+ }
+ }
log.args_num = 0;
log.trace_status = nw_trace_type;
@@ -2660,19 +2720,35 @@ DltReturnValue dlt_user_trace_network_segmented_start(uint32_t *id, DltContext *
/* Write identifier */
if(dlt_user_log_write_string(&log, "NWST") < 0)
+ {
+ dlt_user_free_buffer(&(log.buffer));
return DLT_RETURN_ERROR;
+ }
+
/* Write stream handle */
if(dlt_user_log_write_uint32(&log, *id) < 0)
+ {
+ dlt_user_free_buffer(&(log.buffer));
return DLT_RETURN_ERROR;
+ }
+
/* Write header */
if(dlt_user_log_write_raw(&log, header, header_len) < 0)
+ {
+ dlt_user_free_buffer(&(log.buffer));
return DLT_RETURN_ERROR;
+ }
+
/* Write size of payload */
if(dlt_user_log_write_uint32(&log, payload_len) < 0)
+ {
+ dlt_user_free_buffer(&(log.buffer));
return DLT_RETURN_ERROR;
+ }
+
/* Write expected segment count */
uint16_t segment_count = payload_len/DLT_MAX_TRACE_SEGMENT_SIZE+1;
@@ -2682,14 +2758,26 @@ DltReturnValue dlt_user_trace_network_segmented_start(uint32_t *id, DltContext *
segment_count--;
if(dlt_user_log_write_uint16(&log, segment_count) < 0)
+ {
+ dlt_user_free_buffer(&(log.buffer));
return DLT_RETURN_ERROR;
+ }
+
/* Write length of one segment */
if(dlt_user_log_write_uint16(&log, DLT_MAX_TRACE_SEGMENT_SIZE) < 0)
+ {
+ dlt_user_free_buffer(&(log.buffer));
return DLT_RETURN_ERROR;
+ }
+
/* Send log */
- return dlt_user_log_send_log(&log, DLT_TYPE_NW_TRACE);
+ ret = dlt_user_log_send_log(&log, DLT_TYPE_NW_TRACE);
+
+ dlt_user_free_buffer(&(log.buffer));
+
+ return ret;
}
return DLT_RETURN_OK;
@@ -2697,6 +2785,7 @@ DltReturnValue dlt_user_trace_network_segmented_start(uint32_t *id, DltContext *
DltReturnValue dlt_user_trace_network_segmented_segment(uint32_t id, DltContext *handle, DltNetworkTraceType nw_trace_type, int sequence, uint16_t payload_len, void *payload)
{
+ int ret = DLT_RETURN_ERROR;
if (nw_trace_type < DLT_NW_TRACE_IPC || nw_trace_type >= DLT_NW_TRACE_MAX)
{
dlt_vlog(LOG_ERR, "Network trace type %d is outside valid range", nw_trace_type);
@@ -2709,16 +2798,24 @@ DltReturnValue dlt_user_trace_network_segmented_segment(uint32_t id, DltContext
dlt_user_log_resend_buffer();
}
- DltContextData log;
-
- if (dlt_user_log_init(handle, &log) < DLT_RETURN_OK)
- return DLT_RETURN_ERROR;
-
if (dlt_user.dlt_ll_ts == NULL)
return DLT_RETURN_ERROR;
if (handle->trace_status_ptr && *(handle->trace_status_ptr) == DLT_TRACE_STATUS_ON)
{
+ DltContextData log;
+ if (dlt_user_log_init(handle, &log) < DLT_RETURN_OK)
+ return DLT_RETURN_ERROR;
+ /* initialize values */
+ if (log.buffer == NULL)
+ {
+ log.buffer = calloc(sizeof(unsigned char), dlt_user.log_buf_len);
+ if (log.buffer == NULL)
+ {
+ dlt_vlog(LOG_ERR, "Cannot allocate buffer for DLT Log message\n");
+ return DLT_RETURN_ERROR;
+ }
+ }
log.args_num = 0;
log.trace_status = nw_trace_type;
@@ -2726,22 +2823,40 @@ DltReturnValue dlt_user_trace_network_segmented_segment(uint32_t id, DltContext
/* Write identifier */
if(dlt_user_log_write_string(&log, "NWCH") < DLT_RETURN_OK)
+ {
+ dlt_user_free_buffer(&(log.buffer));
return DLT_RETURN_ERROR;
-
+ }
/* Write stream handle */
if(dlt_user_log_write_uint32(&log, id) < DLT_RETURN_OK)
+ {
+ dlt_user_free_buffer(&(log.buffer));
return DLT_RETURN_ERROR;
+ }
+
/* Write segment sequence number */
if(dlt_user_log_write_uint16(&log, sequence) < DLT_RETURN_OK)
+ {
+ dlt_user_free_buffer(&(log.buffer));
return DLT_RETURN_ERROR;
+ }
+
/* Write data */
if(dlt_user_log_write_raw(&log, payload, payload_len) < DLT_RETURN_OK)
+ {
+ dlt_user_free_buffer(&(log.buffer));
return DLT_RETURN_ERROR;
+ }
+
+ ret = dlt_user_log_send_log(&log, DLT_TYPE_NW_TRACE);
/* Send log */
- return dlt_user_log_send_log(&log, DLT_TYPE_NW_TRACE);
+
+ dlt_user_free_buffer(&(log.buffer));
+
+ return ret;
}
/* Allow other threads to log between chunks */
@@ -2752,6 +2867,7 @@ DltReturnValue dlt_user_trace_network_segmented_segment(uint32_t id, DltContext
DltReturnValue dlt_user_trace_network_segmented_end(uint32_t id, DltContext *handle, DltNetworkTraceType nw_trace_type)
{
DltContextData log;
+ int ret = DLT_RETURN_ERROR;
if (nw_trace_type < DLT_NW_TRACE_IPC || nw_trace_type >= DLT_NW_TRACE_MAX)
{
@@ -2759,28 +2875,52 @@ DltReturnValue dlt_user_trace_network_segmented_end(uint32_t id, DltContext *han
return DLT_RETURN_WRONG_PARAMETER;
}
- if (dlt_user_log_init(handle, &log) < DLT_RETURN_OK)
- return DLT_RETURN_ERROR;
-
if (dlt_user.dlt_ll_ts == NULL)
return DLT_RETURN_ERROR;
if (handle->trace_status_ptr && *(handle->trace_status_ptr) == DLT_TRACE_STATUS_ON)
{
+ /* initialize values */
+ if (dlt_user_log_init(handle, &log) < DLT_RETURN_OK)
+ return DLT_RETURN_ERROR;
+
+ /* initialize values */
+ if (log.buffer == NULL)
+ {
+ log.buffer = calloc(sizeof(unsigned char), dlt_user.log_buf_len);
+ if (log.buffer == NULL)
+ {
+ dlt_vlog(LOG_ERR, "Cannot allocate buffer for DLT Log message\n");
+ return DLT_RETURN_ERROR;
+ }
+ }
log.args_num = 0;
log.trace_status = nw_trace_type;
log.size = 0;
/* Write identifier */
if(dlt_user_log_write_string(&log, "NWEN") < DLT_RETURN_OK)
+ {
+ dlt_user_free_buffer(&(log.buffer));
return DLT_RETURN_ERROR;
+ }
+
/* Write stream handle */
if(dlt_user_log_write_uint32(&log, id) < DLT_RETURN_OK)
+ {
+ dlt_user_free_buffer(&(log.buffer));
return DLT_RETURN_ERROR;
+ }
+
+ ret = dlt_user_log_send_log(&log, DLT_TYPE_NW_TRACE);
/* Send log */
- return dlt_user_log_send_log(&log, DLT_TYPE_NW_TRACE);
+
+ dlt_user_free_buffer(&(log.buffer));
+
+ return ret;
+
}
return DLT_RETURN_OK;
@@ -2899,7 +3039,7 @@ void dlt_user_trace_network_segmented_thread_segmenter(s_segmented_data *data)
DltReturnValue dlt_user_trace_network_segmented(DltContext *handle, DltNetworkTraceType nw_trace_type, uint16_t header_len, void *header, uint16_t payload_len, void *payload)
{
/* Send as normal trace if possible */
- if(header_len+payload_len+sizeof(uint16_t) < DLT_USER_BUF_MAX_SIZE) {
+ if(header_len+payload_len+sizeof(uint16_t) < dlt_user.log_buf_len) {
return dlt_user_trace_network(handle, nw_trace_type, header_len, header, payload_len, payload);
}
@@ -2983,6 +3123,7 @@ DltReturnValue dlt_user_trace_network(DltContext *handle, DltNetworkTraceType nw
DltReturnValue dlt_user_trace_network_truncated(DltContext *handle, DltNetworkTraceType nw_trace_type, uint16_t header_len, void *header, uint16_t payload_len, void *payload, int allow_truncate)
{
+ int ret = DLT_RETURN_ERROR;
if(payload == NULL && payload_len > 0)
return DLT_RETURN_WRONG_PARAMETER;
@@ -2994,18 +3135,6 @@ DltReturnValue dlt_user_trace_network_truncated(DltContext *handle, DltNetworkTr
return DLT_RETURN_WRONG_PARAMETER;
}
- if (dlt_user_log_init(handle, &log) < DLT_RETURN_OK || dlt_user.dlt_ll_ts == NULL)
- return DLT_RETURN_ERROR;
-
- /* Commented out because of DltNetworkTraceType:
-
- if ((nw_trace_type<=0) || (nw_trace_type>0x15))
- {
- return DLT_RETURN_ERROR;
- }
-
- */
-
if (dlt_user.dlt_ll_ts==0)
{
return DLT_RETURN_ERROR;
@@ -3013,6 +3142,19 @@ DltReturnValue dlt_user_trace_network_truncated(DltContext *handle, DltNetworkTr
if (handle->trace_status_ptr && *(handle->trace_status_ptr)==DLT_TRACE_STATUS_ON)
{
+ if ((dlt_user_log_init(handle, &log) < DLT_RETURN_OK) || (dlt_user.dlt_ll_ts == NULL))
+ return DLT_RETURN_ERROR;
+
+ /* initialize values */
+ if (log.buffer == NULL)
+ {
+ log.buffer = calloc(sizeof(unsigned char), dlt_user.log_buf_len);
+ if (log.buffer == NULL)
+ {
+ dlt_vlog(LOG_ERR, "Cannot allocate buffer for DLT Log message\n");
+ return DLT_RETURN_ERROR;
+ }
+ }
log.args_num = 0;
log.trace_status = nw_trace_type;
log.size = 0;
@@ -3021,46 +3163,73 @@ DltReturnValue dlt_user_trace_network_truncated(DltContext *handle, DltNetworkTr
header_len = 0;
/* If truncation is allowed, check if we must do it */
- if(allow_truncate > 0 && (header_len+payload_len+sizeof(uint16_t))>DLT_USER_BUF_MAX_SIZE)
+ if(allow_truncate > 0 && (header_len+payload_len+sizeof(uint16_t))>dlt_user.log_buf_len)
{
/* Identify as truncated */
if(dlt_user_log_write_string(&log, "NWTR") < DLT_RETURN_OK)
+ {
+ dlt_user_free_buffer(&(log.buffer));
return DLT_RETURN_ERROR;
+ }
+
/* Write header and its length */
if (dlt_user_log_write_raw(&log, header, header_len) < DLT_RETURN_OK)
+ {
+ dlt_user_free_buffer(&(log.buffer));
return DLT_RETURN_ERROR;
+ }
+
/* Write original size of payload */
if(dlt_user_log_write_uint32(&log, payload_len) < DLT_RETURN_OK)
+ {
+ dlt_user_free_buffer(&(log.buffer));
return DLT_RETURN_ERROR;
+ }
+
/**
* Calculate maximum available space in sending buffer after headers.
*/
- int truncated_payload_len = DLT_USER_BUF_MAX_SIZE - log.size - sizeof(uint16_t) - sizeof(uint32_t);
+ int truncated_payload_len = dlt_user.log_buf_len - log.size - sizeof(uint16_t) - sizeof(uint32_t);
/* Write truncated payload */
if (dlt_user_log_write_raw(&log, payload, truncated_payload_len) < DLT_RETURN_OK)
+ {
+ dlt_user_free_buffer(&(log.buffer));
return DLT_RETURN_ERROR;
+ }
+
}
else /* Truncation not allowed or data short enough */
{
/* Write header and its length */
if (dlt_user_log_write_raw(&log, header, header_len) < DLT_RETURN_OK)
+ {
+ dlt_user_free_buffer(&(log.buffer));
return DLT_RETURN_ERROR;
+ }
+
if (payload == NULL)
payload_len = 0;
/* Write payload and its length */
if (dlt_user_log_write_raw(&log, payload, payload_len) < DLT_RETURN_OK)
+ {
+ dlt_user_free_buffer(&(log.buffer));
return DLT_RETURN_ERROR;
+ }
+
}
+ ret = dlt_user_log_send_log(&log, DLT_TYPE_NW_TRACE);
+
+ dlt_user_free_buffer(&(log.buffer));
/* Send log */
- return dlt_user_log_send_log(&log, DLT_TYPE_NW_TRACE);
+ return ret;
}
return DLT_RETURN_OK;
@@ -3069,30 +3238,21 @@ DltReturnValue dlt_user_trace_network_truncated(DltContext *handle, DltNetworkTr
DltReturnValue dlt_log_string(DltContext *handle, DltLogLevelType loglevel, const char *text)
{
DltContextData log;
- DltReturnValue ret = DLT_RETURN_OK;
if (dlt_user.verbose_mode==0)
{
return DLT_RETURN_ERROR;
}
- if (loglevel < DLT_USER_LOG_LEVEL_NOT_SET || loglevel >= DLT_LOG_MAX)
- {
- dlt_vlog(LOG_ERR, "Loglevel %d is outside valid range", loglevel);
- return DLT_RETURN_WRONG_PARAMETER;
- }
-
if ((handle == NULL) || (text == NULL))
{
return DLT_RETURN_WRONG_PARAMETER;
}
- if (dlt_user_log_write_start(handle,&log,loglevel) > 0)
+ if (dlt_user_log_write_start(handle, &log, loglevel) == DLT_RETURN_TRUE)
{
- if ( (ret = dlt_user_log_write_string(&log,text)) < DLT_RETURN_OK)
- {
- return ret;
- }
+ dlt_user_log_write_string(&log, text);
+
if (dlt_user_log_write_finish(&log) < DLT_RETURN_OK)
{
return DLT_RETURN_ERROR;
@@ -3105,34 +3265,22 @@ DltReturnValue dlt_log_string(DltContext *handle, DltLogLevelType loglevel, cons
DltReturnValue dlt_log_string_int(DltContext *handle, DltLogLevelType loglevel, const char *text, int data)
{
DltContextData log;
- DltReturnValue ret = DLT_RETURN_OK;
if (dlt_user.verbose_mode==0)
{
return DLT_RETURN_ERROR;
}
- if (loglevel < DLT_USER_LOG_LEVEL_NOT_SET || loglevel >= DLT_LOG_MAX)
- {
- dlt_vlog(LOG_ERR, "Loglevel %d is outside valid range", loglevel);
- return DLT_RETURN_WRONG_PARAMETER;
- }
-
if ((handle == NULL) || (text == NULL))
{
return DLT_RETURN_WRONG_PARAMETER;
}
- if (dlt_user_log_write_start(handle, &log, loglevel) > 0)
+ if (dlt_user_log_write_start(handle, &log, loglevel) == DLT_RETURN_TRUE)
{
- if ( (ret = dlt_user_log_write_string(&log, text)) < DLT_RETURN_OK)
- {
- return ret;
- }
- if ( (ret = dlt_user_log_write_int(&log, data)) < DLT_RETURN_OK)
- {
- return ret;
- }
+ dlt_user_log_write_string(&log, text);
+ dlt_user_log_write_int(&log, data);
+
if (dlt_user_log_write_finish(&log) < DLT_RETURN_OK)
{
return DLT_RETURN_ERROR;
@@ -3145,34 +3293,22 @@ DltReturnValue dlt_log_string_int(DltContext *handle, DltLogLevelType loglevel,
DltReturnValue dlt_log_string_uint(DltContext *handle, DltLogLevelType loglevel, const char *text, unsigned int data)
{
DltContextData log;
- DltReturnValue ret = DLT_RETURN_OK;
if (dlt_user.verbose_mode==0)
{
return DLT_RETURN_ERROR;
}
- if (loglevel < DLT_USER_LOG_LEVEL_NOT_SET || loglevel >= DLT_LOG_MAX)
- {
- dlt_vlog(LOG_ERR, "Loglevel %d is outside valid range", loglevel);
- return DLT_RETURN_WRONG_PARAMETER;
- }
-
if ((handle == NULL) || (text == NULL))
{
return DLT_RETURN_WRONG_PARAMETER;
}
- if (dlt_user_log_write_start(handle,&log,loglevel) > 0)
+ if (dlt_user_log_write_start(handle, &log, loglevel) == DLT_RETURN_TRUE)
{
- if ( (ret = dlt_user_log_write_string(&log,text)) < DLT_RETURN_OK)
- {
- return ret;
- }
- if ( (ret = dlt_user_log_write_uint(&log,data)) < DLT_RETURN_OK)
- {
- return ret;
- }
+ dlt_user_log_write_string(&log, text);
+ dlt_user_log_write_uint(&log, data);
+
if (dlt_user_log_write_finish(&log) < DLT_RETURN_OK)
{
return DLT_RETURN_ERROR;
@@ -3185,30 +3321,21 @@ DltReturnValue dlt_log_string_uint(DltContext *handle, DltLogLevelType loglevel,
DltReturnValue dlt_log_int(DltContext *handle, DltLogLevelType loglevel, int data)
{
DltContextData log;
- DltReturnValue ret = DLT_RETURN_OK;
if (dlt_user.verbose_mode==0)
{
return DLT_RETURN_ERROR;
}
- if (loglevel < DLT_USER_LOG_LEVEL_NOT_SET || loglevel >= DLT_LOG_MAX)
- {
- dlt_vlog(LOG_ERR, "Loglevel %d is outside valid range", loglevel);
- return DLT_RETURN_WRONG_PARAMETER;
- }
-
if (handle == NULL)
{
return DLT_RETURN_ERROR;
}
- if (dlt_user_log_write_start(handle,&log,loglevel) > 0)
+ if (dlt_user_log_write_start(handle, &log, loglevel) == DLT_RETURN_TRUE)
{
- if ( (ret = dlt_user_log_write_int(&log,data)) < DLT_RETURN_OK)
- {
- return ret;
- }
+ dlt_user_log_write_int(&log, data);
+
if (dlt_user_log_write_finish(&log) < DLT_RETURN_OK)
{
return DLT_RETURN_ERROR;
@@ -3221,30 +3348,21 @@ DltReturnValue dlt_log_int(DltContext *handle, DltLogLevelType loglevel, int dat
DltReturnValue dlt_log_uint(DltContext *handle, DltLogLevelType loglevel, unsigned int data)
{
DltContextData log;
- DltReturnValue ret = DLT_RETURN_OK;
if (dlt_user.verbose_mode==0)
{
return DLT_RETURN_ERROR;
}
- if (loglevel < DLT_USER_LOG_LEVEL_NOT_SET || loglevel >= DLT_LOG_MAX)
- {
- dlt_vlog(LOG_ERR, "Loglevel %d is outside valid range", loglevel);
- return DLT_RETURN_ERROR;
- }
-
if (handle == NULL)
{
return DLT_RETURN_WRONG_PARAMETER;
}
- if (dlt_user_log_write_start(handle,&log,loglevel) > 0)
+ if (dlt_user_log_write_start(handle, &log, loglevel) == DLT_RETURN_TRUE)
{
- if ( (ret = dlt_user_log_write_uint(&log,data)) < DLT_RETURN_OK)
- {
- return ret;
- }
+ dlt_user_log_write_uint(&log, data);
+
if (dlt_user_log_write_finish(&log) < DLT_RETURN_OK)
{
return DLT_RETURN_ERROR;
@@ -3264,12 +3382,6 @@ DltReturnValue dlt_log_raw(DltContext *handle, DltLogLevelType loglevel, void *d
return DLT_RETURN_ERROR;
}
- if (loglevel < DLT_USER_LOG_LEVEL_NOT_SET || loglevel >= DLT_LOG_MAX)
- {
- dlt_vlog(LOG_ERR, "Loglevel %d is outside valid range", loglevel);
- return DLT_RETURN_WRONG_PARAMETER;
- }
-
if (handle == NULL)
{
return DLT_RETURN_WRONG_PARAMETER;
@@ -3473,6 +3585,7 @@ DltReturnValue dlt_user_log_init(DltContext *handle, DltContextData *log)
}
log->handle = handle;
+ log->buffer = NULL;
return DLT_RETURN_OK;
}
@@ -3744,6 +3857,7 @@ DltReturnValue dlt_user_log_send_log(DltContextData *log, int mtype)
msg.standardheader->len = DLT_HTOBE_16(dlt_user.corrupt_message_size_size);
}
#endif
+
ret = dlt_user_log_out3(dlt_user.dlt_log_handle,
&(userheader), sizeof(DltUserHeader),
msg.headerbuffer+sizeof(DltStorageHeader), msg.headersize-sizeof(DltStorageHeader),
@@ -4246,7 +4360,7 @@ DltReturnValue dlt_user_log_check_user_message(void)
{
while (1)
{
- if (dlt_receiver_receive_fd(receiver)<=0)
+ if (dlt_receiver_receive(receiver, DLT_RECEIVE_FD)<=0)
{
/* No new message available */
return DLT_RETURN_OK;
@@ -4477,7 +4591,7 @@ DltReturnValue dlt_user_log_resend_buffer(void)
{
DLT_SEM_LOCK();
- size = dlt_buffer_copy(&(dlt_user.startup_buffer),dlt_user.resend_buffer,sizeof(dlt_user.resend_buffer));
+ size = dlt_buffer_copy(&(dlt_user.startup_buffer),dlt_user.resend_buffer,dlt_user.log_buf_len);
if (size>0)
{
diff --git a/src/lib/dlt_user_cfg.h b/src/lib/dlt_user_cfg.h
index 60f887b..83fa157 100644
--- a/src/lib/dlt_user_cfg.h
+++ b/src/lib/dlt_user_cfg.h
@@ -144,6 +144,12 @@
#define DLT_USER_MQ_ERROR_RETRY_INTERVAL 100000
+/* Name of environment variable to change the dlt log message buffer size */
+#define DLT_USER_ENV_LOG_MSG_BUF_LEN "DLT_LOG_MSG_BUF_LEN"
+
+/* Maximum msg size as per autosar standard */
+#define DLT_LOG_MSG_BUF_MAX_SIZE 65535
+
/************************/
/* Don't change please! */
/************************/
diff --git a/src/shared/dlt_common.c b/src/shared/dlt_common.c
index d2f86f4..0b3c49e 100644
--- a/src/shared/dlt_common.c
+++ b/src/shared/dlt_common.c
@@ -2137,6 +2137,7 @@ DltReturnValue dlt_receiver_init(DltReceiver *receiver, int fd, int buffersize)
receiver->buffersize = buffersize;
receiver->fd = fd;
receiver->buffer = (char*)malloc(receiver->buffersize);
+ receiver->backup_buf = NULL;
if (receiver->buffer == NULL)
{
@@ -2151,6 +2152,35 @@ DltReturnValue dlt_receiver_init(DltReceiver *receiver, int fd, int buffersize)
return DLT_RETURN_OK;
}
+DltReturnValue dlt_receiver_init_unix_socket(DltReceiver *receiver, int fd, char **buffer)
+{
+ if (receiver == NULL)
+ {
+ return DLT_RETURN_WRONG_PARAMETER;
+ }
+ if (*buffer == NULL)
+ {
+ /* allocating the buffer once and using it for all application receivers
+ * by keeping allocated buffer in app_recv_buffer global handle
+ */
+ *buffer = (char*)malloc(DLT_APP_RCV_BUF_MAX);
+ if (*buffer == NULL)
+ {
+ return DLT_RETURN_ERROR;
+ }
+ }
+ receiver->lastBytesRcvd = 0;
+ receiver->bytesRcvd = 0;
+ receiver->totalBytesRcvd = 0;
+ receiver->buffersize = DLT_APP_RCV_BUF_MAX;
+ receiver->fd = fd;
+ receiver->buffer = *buffer;
+ receiver->backup_buf = NULL;
+ receiver->buf = receiver->buffer;
+
+ return DLT_RETURN_OK;
+}
+
DltReturnValue dlt_receiver_free(DltReceiver *receiver)
{
@@ -2164,44 +2194,39 @@ DltReturnValue dlt_receiver_free(DltReceiver *receiver)
free(receiver->buffer);
}
+ if (receiver->backup_buf)
+ {
+ free(receiver->backup_buf);
+ }
+
receiver->buffer = NULL;
receiver->buf = NULL;
+ receiver->backup_buf = NULL;
return DLT_RETURN_OK;
}
-#ifndef QT_VIEWER
-int dlt_receiver_receive_socket(DltReceiver *receiver)
+DltReturnValue dlt_receiver_free_unix_socket(DltReceiver *receiver)
{
+
if (receiver == NULL)
{
- return -1;
+ return DLT_RETURN_WRONG_PARAMETER;
}
- if (receiver->buffer == NULL)
+ if (receiver->backup_buf)
{
- return -1;
+ free(receiver->backup_buf);
}
- receiver->buf = (char *)receiver->buffer;
- receiver->lastBytesRcvd = receiver->bytesRcvd;
-
- /* wait for data from socket */
- if ((receiver->bytesRcvd = recv(receiver->fd, receiver->buf + receiver->lastBytesRcvd, receiver->buffersize - receiver->lastBytesRcvd , 0)) <= 0)
- {
- receiver->bytesRcvd = 0;
-
- return receiver->bytesRcvd;
- } /* if */
-
- receiver->totalBytesRcvd += receiver->bytesRcvd;
- receiver->bytesRcvd += receiver->lastBytesRcvd;
+ receiver->buffer = NULL;
+ receiver->buf = NULL;
+ receiver->backup_buf = NULL;
- return receiver->bytesRcvd;
+ return DLT_RETURN_OK;
}
-#endif
-int dlt_receiver_receive_fd(DltReceiver *receiver)
+int dlt_receiver_receive(DltReceiver *receiver, DltReceiverType from_src)
{
if (receiver == NULL)
{
@@ -2216,8 +2241,30 @@ int dlt_receiver_receive_fd(DltReceiver *receiver)
receiver->buf = (char *)receiver->buffer;
receiver->lastBytesRcvd = receiver->bytesRcvd;
- /* wait for data from fd */
- if ((receiver->bytesRcvd = read(receiver->fd, receiver->buf + receiver->lastBytesRcvd, receiver->buffersize - receiver->lastBytesRcvd)) <= 0)
+ if ((receiver->lastBytesRcvd) && (receiver->backup_buf != NULL))
+ {
+ memcpy(receiver->buf, receiver->backup_buf, receiver->lastBytesRcvd);
+ free(receiver->backup_buf);
+ receiver->backup_buf = NULL;
+ }
+
+ if (from_src == DLT_RECEIVE_SOCKET)
+ {
+ /* wait for data from socket */
+ receiver->bytesRcvd = recv(receiver->fd,
+ receiver->buf + receiver->lastBytesRcvd,
+ receiver->buffersize - receiver->lastBytesRcvd,
+ 0);
+ }
+ else
+ {
+ /* wait for data from fd */
+ receiver->bytesRcvd = read(receiver->fd,
+ receiver->buf + receiver->lastBytesRcvd,
+ receiver->buffersize - receiver->lastBytesRcvd);
+ }
+
+ if (receiver->bytesRcvd <= 0)
{
receiver->bytesRcvd = 0;
@@ -2230,15 +2277,6 @@ int dlt_receiver_receive_fd(DltReceiver *receiver)
return receiver->bytesRcvd;
}
-int dlt_receiver_receive(DltReceiver *receiver)
-{
-#ifdef DLT_USE_UNIX_SOCKET_IPC
- return dlt_receiver_receive_socket(receiver);
-#else
- return dlt_receiver_receive_fd(receiver);
-#endif
-}
-
DltReturnValue dlt_receiver_remove(DltReceiver *receiver, int size)
{
if (receiver == NULL)
@@ -2278,7 +2316,18 @@ DltReturnValue dlt_receiver_move_to_begin(DltReceiver *receiver)
if ((receiver->buffer!=receiver->buf) && (receiver->bytesRcvd!=0))
{
- memmove(receiver->buffer,receiver->buf,receiver->bytesRcvd);
+ receiver->backup_buf = calloc(receiver->bytesRcvd + 1, sizeof(char));
+
+ if (receiver->backup_buf == NULL)
+ {
+ dlt_vlog(LOG_WARNING,
+ "Can't allocate memory for backup buf, there will be atleast"
+ "one corrupted message for fd[%d] \n", receiver->fd);
+ }
+ else
+ {
+ memcpy(receiver->backup_buf, receiver->buf, receiver->bytesRcvd);
+ }
}
return DLT_RETURN_OK;