From 2f105312020b9afd8364df2addab1096e2bf061e Mon Sep 17 00:00:00 2001 From: Alexander Wenzel Date: Tue, 18 Mar 2014 11:29:08 +0100 Subject: Fixed: Fixed offline trace and new send functions issues Signed-off-by: Alexander Wenzel --- src/daemon/dlt-daemon.c | 18 +++----- src/daemon/dlt_daemon_client.c | 99 ++++++++++++++++++++++-------------------- src/daemon/dlt_daemon_client.h | 29 +++++++++++++ 3 files changed, 88 insertions(+), 58 deletions(-) diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c index 80cd38e..2fb9f2f 100644 --- a/src/daemon/dlt-daemon.c +++ b/src/daemon/dlt-daemon.c @@ -488,7 +488,7 @@ int main(int argc, char* argv[]) create_timer_fd(&daemon_local, 60, 60, &daemon_local.timer_sixty_s, "ECU version"); } - if(daemon_local.flags.yvalue[0]) + if(daemon_local.flags.yvalue[0] || (daemon_local.flags.offlineTraceDirectory[0])) dlt_daemon_change_state(&daemon,DLT_DAEMON_STATE_SEND_DIRECT); else dlt_daemon_change_state(&daemon,DLT_DAEMON_STATE_BUFFER); @@ -2021,17 +2021,13 @@ int dlt_daemon_process_user_message_log(DltDaemon *daemon, DltDaemonLocal *daemo } } - /* look if TCP connection to client is available */ - if((daemon->mode == DLT_USER_MODE_EXTERNAL) || (daemon->mode == DLT_USER_MODE_BOTH)) + /* send message to client or write to log file */ + if((ret = dlt_daemon_client_send(DLT_DAEMON_SEND_TO_ALL,daemon,daemon_local,daemon_local->msg.headerbuffer+sizeof(DltStorageHeader),daemon_local->msg.headersize-sizeof(DltStorageHeader), + daemon_local->msg.databuffer,daemon_local->msg.datasize,verbose))) { - - if((ret = dlt_daemon_client_send(DLT_DAEMON_SEND_TO_ALL,daemon,daemon_local,daemon_local->msg.headerbuffer+sizeof(DltStorageHeader),daemon_local->msg.headersize-sizeof(DltStorageHeader), - daemon_local->msg.databuffer,daemon_local->msg.datasize,verbose))) + if(ret == DLT_DAEMON_ERROR_BUFFER_FULL) { - if(ret == DLT_DAEMON_ERROR_BUFFER_FULL) - { - daemon->overflow_counter++; - } + daemon->overflow_counter++; } } @@ -2321,7 +2317,7 @@ int dlt_daemon_process_user_message_log_mode(DltDaemon *daemon, DltDaemonLocal * return -1; } - if (daemon_local->receiver.bytesRcvd < (int32_t)(sizeof(DltUserHeader)+sizeof(DltUserControlMsgUnregisterContext))) + if (daemon_local->receiver.bytesRcvd < (int32_t)(sizeof(DltUserHeader)+sizeof(DltUserControlMsgLogMode))) { /* Not enough bytes received */ return -1; diff --git a/src/daemon/dlt_daemon_client.c b/src/daemon/dlt_daemon_client.c index e122f87..a209975 100644 --- a/src/daemon/dlt_daemon_client.c +++ b/src/daemon/dlt_daemon_client.c @@ -84,7 +84,7 @@ static char str[DLT_DAEMON_TEXTBUFSIZE]; int dlt_daemon_client_send(int sock,DltDaemon *daemon,DltDaemonLocal *daemon_local,void* data1,int size1,void* data2,int size2,int verbose) { int ret; - int j,third_value; + int j; if (sock!=DLT_DAEMON_SEND_TO_ALL && sock!=DLT_DAEMON_SEND_FORCE) { @@ -119,73 +119,82 @@ int dlt_daemon_client_send(int sock,DltDaemon *daemon,DltDaemonLocal *daemon_loc } /* write message to offline trace */ - if ((sock!=DLT_DAEMON_SEND_FORCE) && (daemon->state == DLT_DAEMON_STATE_SEND_DIRECT)) - { + if ((sock!=DLT_DAEMON_SEND_FORCE) && (daemon->state == DLT_DAEMON_STATE_SEND_DIRECT)) + { if(((daemon->mode == DLT_USER_MODE_INTERNAL) || (daemon->mode == DLT_USER_MODE_BOTH)) && daemon_local->flags.offlineTraceDirectory[0]) { if(dlt_offline_trace_write(&(daemon_local->offlineTrace),daemon_local->msg.headerbuffer,daemon_local->msg.headersize, daemon_local->msg.databuffer,daemon_local->msg.datasize,0,0)) { - return DLT_DAEMON_ERROR_WRITE_FAILED; + static int error_dlt_offline_trace_write_failed = 0; + if(!error_dlt_offline_trace_write_failed) + { + dlt_log(LOG_ERR,"dlt_daemon_client_send: dlt_offline_trace_write failed!\n"); + error_dlt_offline_trace_write_failed = 1; + } + //return DLT_DAEMON_ERROR_WRITE_FAILED; } } - } + } - /* send messages to daemon socket */ - if ((sock==DLT_DAEMON_SEND_FORCE) || (daemon->state == DLT_DAEMON_STATE_SEND_DIRECT)) - { - int sent = 0; - /* look if TCP connection to client is available */ - for (j = 0; j <= daemon_local->fdmax; j++) + /* send messages to daemon socket */ + if((daemon->mode == DLT_USER_MODE_EXTERNAL) || (daemon->mode == DLT_USER_MODE_BOTH)) + { + if ((sock==DLT_DAEMON_SEND_FORCE) || (daemon->state == DLT_DAEMON_STATE_SEND_DIRECT)) { - /* send to everyone! */ - if (FD_ISSET(j, &(daemon_local->master))) + int sent = 0; + /* look if TCP connection to client is available */ + for (j = 0; j <= daemon_local->fdmax; j++) { - if ((j != daemon_local->fp) && (j != daemon_local->sock) && (j != daemon_local->sock) - #ifdef DLT_SYSTEMD_WATCHDOG_ENABLE - && (j!=daemon_local->timer_wd) - #endif - && (j!=daemon_local->timer_one_s) && (j!=daemon_local->timer_sixty_s)) + /* send to everyone! */ + if (FD_ISSET(j, &(daemon_local->master))) { - /* Send message */ - if (isatty(j)) + if ((j != daemon_local->fp) && (j != daemon_local->sock) && (j != daemon_local->sock) + #ifdef DLT_SYSTEMD_WATCHDOG_ENABLE + && (j!=daemon_local->timer_wd) + #endif + && (j!=daemon_local->timer_one_s) && (j!=daemon_local->timer_sixty_s)) { - DLT_DAEMON_SEM_LOCK(); - - if((ret=dlt_daemon_serial_send(j,data1,size1,data2,size2,daemon->sendserialheader))) + /* Send message */ + if (isatty(j)) { + DLT_DAEMON_SEM_LOCK(); + + if((ret=dlt_daemon_serial_send(j,data1,size1,data2,size2,daemon->sendserialheader))) + { + DLT_DAEMON_SEM_FREE(); + dlt_log(LOG_WARNING,"dlt_daemon_client_send: serial send dlt message failed\n"); + return ret; + } + DLT_DAEMON_SEM_FREE(); - dlt_log(LOG_WARNING,"dlt_daemon_client_send: serial send dlt message failed\n"); - return ret; } + else + { + DLT_DAEMON_SEM_LOCK(); - DLT_DAEMON_SEM_FREE(); - } - else - { - DLT_DAEMON_SEM_LOCK(); + if((ret=dlt_daemon_socket_send(j,data1,size1,data2,size2,daemon->sendserialheader))) + { + DLT_DAEMON_SEM_FREE(); + dlt_log(LOG_WARNING,"dlt_daemon_client_send: socket send dlt message failed\n"); + dlt_daemon_close_socket(j, daemon, daemon_local, verbose); + return ret; + } - if((ret=dlt_daemon_socket_send(j,data1,size1,data2,size2,daemon->sendserialheader))) - { DLT_DAEMON_SEM_FREE(); - dlt_log(LOG_WARNING,"dlt_daemon_client_send: socket send dlt message failed\n"); - dlt_daemon_close_socket(j, daemon, daemon_local, verbose); - return ret; } + sent=1; - DLT_DAEMON_SEM_FREE(); } - sent=1; - } } + if((sock==DLT_DAEMON_SEND_FORCE) && !sent) + { + return DLT_DAEMON_ERROR_SEND_FAILED; + } } - if((sock==DLT_DAEMON_SEND_FORCE) && !sent) - { - return DLT_DAEMON_ERROR_SEND_FAILED; - } - } + } /* Message was not sent to client, so store it in client ringbuffer */ if ((sock!=DLT_DAEMON_SEND_FORCE) && (daemon->state == DLT_DAEMON_STATE_BUFFER || daemon->state == DLT_DAEMON_STATE_SEND_BUFFER || daemon->state == DLT_DAEMON_STATE_BUFFER_FULL)) @@ -285,7 +294,6 @@ int dlt_daemon_client_send_control_message( int sock, DltDaemon *daemon, DltDaem if((ret=dlt_daemon_client_send(sock,daemon,daemon_local,msg->headerbuffer+sizeof(DltStorageHeader),msg->headersize-sizeof(DltStorageHeader), msg->databuffer,msg->datasize,verbose))) { - DLT_DAEMON_SEM_FREE(); dlt_log(LOG_DEBUG,"dlt_daemon_control_send_control_message: DLT message send to all failed!.\n"); return ret; } @@ -1047,7 +1055,6 @@ int dlt_daemon_control_message_unregister_context(int sock, DltDaemon *daemon, D /* initialise new message */ if (dlt_message_init(&msg,0)==-1) { - dlt_daemon_control_service_response(sock, daemon,daemon_local, DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW, DLT_SERVICE_RESPONSE_ERROR, verbose); return -1; } @@ -1102,7 +1109,6 @@ int dlt_daemon_control_message_connection_info(int sock, DltDaemon *daemon, DltD /* initialise new message */ if (dlt_message_init(&msg,0)==-1) { - dlt_daemon_control_service_response(sock, daemon,daemon_local, DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW, DLT_SERVICE_RESPONSE_ERROR, verbose); return -1; } @@ -1156,7 +1162,6 @@ int dlt_daemon_control_message_timezone(int sock, DltDaemon *daemon, DltDaemonLo /* initialise new message */ if (dlt_message_init(&msg,0)==-1) { - dlt_daemon_control_service_response(sock, daemon,daemon_local, DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW, DLT_SERVICE_RESPONSE_ERROR, verbose); return -1; } diff --git a/src/daemon/dlt_daemon_client.h b/src/daemon/dlt_daemon_client.h index b46d8c7..34715c9 100644 --- a/src/daemon/dlt_daemon_client.h +++ b/src/daemon/dlt_daemon_client.h @@ -62,12 +62,25 @@ #include #include +/** + * Send out message to client or store message in offline trace. + * @param sock connection handle used for sending response + * @param daemon pointer to dlt daemon structure + * @param daemon_local pointer to dlt daemon local structure + * @param data1 pointer to data + * @param size1 size of data + * @param data2 pointer to data + * @param size2 size of data + * @param verbose if set to true verbose information is printed out. + * @return unequal 0 if there is an error or buffer is full + */ int dlt_daemon_client_send(int sock,DltDaemon *daemon,DltDaemonLocal *daemon_local,void* data1,int size1,void* data2,int size2,int verbose); /** * Send out response message to dlt client * @param sock connection handle used for sending response * @param daemon pointer to dlt daemon structure + * @param daemon_local pointer to dlt daemon local structure * @param msg pointer to response message * @param appid pointer to application id to be used in response message * @param contid pointer to context id to be used in response message @@ -79,6 +92,7 @@ int dlt_daemon_client_send_control_message(int sock, DltDaemon *daemon, DltDaemo * Process and generate response to received get log info control message * @param sock connection handle used for sending response * @param daemon pointer to dlt daemon structure + * @param daemon_local pointer to dlt daemon local structure * @param msg pointer to received control message * @param verbose if set to true verbose information is printed out. */ @@ -87,6 +101,7 @@ void dlt_daemon_control_get_log_info(int sock, DltDaemon *daemon,DltDaemonLocal * Process and generate response to received get software version control message * @param sock connection handle used for sending response * @param daemon pointer to dlt daemon structure + * @param daemon_local pointer to dlt daemon local structure * @param verbose if set to true verbose information is printed out. */ void dlt_daemon_control_get_software_version(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose); @@ -94,6 +109,7 @@ void dlt_daemon_control_get_software_version(int sock, DltDaemon *daemon, DltDae * Process and generate response to received get default log level control message * @param sock connection handle used for sending response * @param daemon pointer to dlt daemon structure + * @param daemon_local pointer to dlt daemon local structure * @param verbose if set to true verbose information is printed out. */ void dlt_daemon_control_get_default_log_level(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose); @@ -101,6 +117,7 @@ void dlt_daemon_control_get_default_log_level(int sock, DltDaemon *daemon, DltDa * Process and generate response to message buffer overflow control message * @param sock connection handle used for sending response * @param daemon pointer to dlt daemon structure + * @param daemon_local pointer to dlt daemon local structure * @param verbose if set to true verbose information is printed out. * @return -1 if there is an error or buffer overflow, else 0 */ @@ -109,6 +126,7 @@ int dlt_daemon_control_message_buffer_overflow(int sock, DltDaemon *daemon, DltD * Generate response to control message from dlt client * @param sock connection handle used for sending response * @param daemon pointer to dlt daemon structure + * @param daemon_local pointer to dlt daemon local structure * @param service_id service id of control message * @param status status of response (e.g. ok, not supported, error) * @param verbose if set to true verbose information is printed out. @@ -118,6 +136,7 @@ void dlt_daemon_control_service_response(int sock, DltDaemon *daemon, DltDaemonL * Send control message unregister context (add on to AUTOSAR standard) * @param sock connection handle used for sending response * @param daemon pointer to dlt daemon structure + * @param daemon_local pointer to dlt daemon local structure * @param apid application id to be unregisteres * @param ctid context id to be unregistered * @param comid Communication id where apid is unregistered @@ -128,6 +147,7 @@ int dlt_daemon_control_message_unregister_context(int sock, DltDaemon *daemon, D * Send control message connection info (add on to AUTOSAR standard) * @param sock connection handle used for sending response * @param daemon pointer to dlt daemon structure + * @param daemon_local pointer to dlt daemon local structure * @param state state of connection * @param comid Communication id where connection state changed * @param verbose if set to true verbose information is printed out. @@ -137,6 +157,7 @@ int dlt_daemon_control_message_connection_info(int sock, DltDaemon *daemon, DltD * Send control message connection info (add on to AUTOSAR standard) * @param sock connection handle used for sending response * @param daemon pointer to dlt daemon structure + * @param daemon_local pointer to dlt daemon local structure * @param timezone timezone on target * @param verbose if set to true verbose information is printed out. */ @@ -145,6 +166,7 @@ int dlt_daemon_control_message_timezone(int sock, DltDaemon *daemon, DltDaemonLo * Process received control message from dlt client * @param sock connection handle used for sending response * @param daemon pointer to dlt daemon structure + * @param daemon_local pointer to dlt daemon local structure * @param msg pointer to received control message * @param verbose if set to true verbose information is printed out. */ @@ -153,6 +175,7 @@ int dlt_daemon_client_process_control(int sock, DltDaemon *daemon, DltDaemonLoca * Process and generate response to received sw injection control message * @param sock connection handle used for sending response * @param daemon pointer to dlt daemon structure + * @param daemon_local pointer to dlt daemon local structure * @param msg pointer to received sw injection control message * @param verbose if set to true verbose information is printed out. */ @@ -161,6 +184,7 @@ void dlt_daemon_control_callsw_cinjection(int sock, DltDaemon *daemon, DltDaemon * Process and generate response to received set log level control message * @param sock connection handle used for sending response * @param daemon pointer to dlt daemon structure + * @param daemon_local pointer to dlt daemon local structure * @param msg pointer to received control message * @param verbose if set to true verbose information is printed out. */ @@ -169,6 +193,7 @@ void dlt_daemon_control_set_log_level(int sock, DltDaemon *daemon, DltDaemonLoca * Process and generate response to received set trace status control message * @param sock connection handle used for sending response * @param daemon pointer to dlt daemon structure + * @param daemon_local pointer to dlt daemon local structure * @param msg pointer to received control message * @param verbose if set to true verbose information is printed out. */ @@ -177,6 +202,7 @@ void dlt_daemon_control_set_trace_status(int sock, DltDaemon *daemon, DltDaemonL * Process and generate response to received set default log level control message * @param sock connection handle used for sending response * @param daemon pointer to dlt daemon structure + * @param daemon_local pointer to dlt daemon local structure * @param msg pointer to received control message * @param verbose if set to true verbose information is printed out. */ @@ -185,6 +211,7 @@ void dlt_daemon_control_set_default_log_level(int sock, DltDaemon *daemon, DltDa * Process and generate response to received set default trace status control message * @param sock connection handle used for sending response * @param daemon pointer to dlt daemon structure + * @param daemon_local pointer to dlt daemon local structure * @param msg pointer to received control message * @param verbose if set to true verbose information is printed out. */ @@ -193,6 +220,7 @@ void dlt_daemon_control_set_default_trace_status(int sock, DltDaemon *daemon, Dl * Process and generate response to set timing packets control message * @param sock connection handle used for sending response * @param daemon pointer to dlt daemon structure + * @param daemon_local pointer to dlt daemon local structure * @param msg pointer to received control message * @param verbose if set to true verbose information is printed out. */ @@ -201,6 +229,7 @@ void dlt_daemon_control_set_timing_packets(int sock, DltDaemon *daemon, DltDaemo * Send time control message * @param sock connection handle used for sending response * @param daemon pointer to dlt daemon structure + * @param daemon_local pointer to dlt daemon local structure * @param verbose if set to true verbose information is printed out. */ void dlt_daemon_control_message_time(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose); -- cgit v1.2.1