From 3fcd7400a003a3f694f1638a31e3a9fe6cf1595a Mon Sep 17 00:00:00 2001 From: Alexander Wenzel Date: Thu, 10 Nov 2011 13:42:57 +0100 Subject: Reverted old FIFO functions. Still SHM enabled by default. --- src/daemon/dlt-daemon.c | 297 +++++++++++++++++++++++++++++++++++++---- src/daemon/dlt-daemon.h | 2 + src/daemon/dlt.conf | 6 +- src/daemon/dlt_daemon_common.c | 18 ++- src/daemon/dlt_daemon_common.h | 1 + src/lib/dlt_filetransfer.c | 4 +- src/lib/dlt_user.c | 21 ++- src/system/dlt-system-log.c | 2 + src/system/dlt-system.c | 2 +- src/system/dlt-system.conf | 4 +- 10 files changed, 318 insertions(+), 39 deletions(-) (limited to 'src') diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c index fb8b2e6..f2ba0cb 100755 --- a/src/daemon/dlt-daemon.c +++ b/src/daemon/dlt-daemon.c @@ -1004,8 +1004,15 @@ int dlt_daemon_process_client_connect(DltDaemon *daemon, DltDaemonLocal *daemon_ if (daemon_local->client_connections==1) { - /* send ringbuffer done in old implementation */ - /* nothing to do with shared memory */ + if (daemon_local->flags.vflag) + { + dlt_log(LOG_INFO, "Send ring-buffer to client\n"); + } + if (dlt_daemon_send_ringbuffer_to_client(daemon, daemon_local, verbose)==-1) + { + dlt_log(LOG_ERR,"Can't send contents of ringbuffer to clients\n"); + return -1; + } /* send new log state to all applications */ daemon->state = 1; @@ -1235,7 +1242,6 @@ int dlt_daemon_process_user_messages(DltDaemon *daemon, DltDaemonLocal *daemon_l break; } case DLT_USER_MESSAGE_LOG: - case DLT_USER_MESSAGE_LOG_SHM: { if (dlt_daemon_process_user_message_log(daemon, daemon_local, daemon_local->flags.vflag)==-1) { @@ -1243,6 +1249,14 @@ int dlt_daemon_process_user_messages(DltDaemon *daemon, DltDaemonLocal *daemon_l } break; } + case DLT_USER_MESSAGE_LOG_SHM: + { + if (dlt_daemon_process_user_message_log_shm(daemon, daemon_local, daemon_local->flags.vflag)==-1) + { + run_loop=0; + } + break; + } case DLT_USER_MESSAGE_REGISTER_APPLICATION: { if (dlt_daemon_process_user_message_register_application(daemon, daemon_local, daemon_local->flags.vflag)==-1) @@ -1701,6 +1715,180 @@ int dlt_daemon_process_user_message_unregister_context(DltDaemon *daemon, DltDae } int dlt_daemon_process_user_message_log(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose) +{ + int bytes_to_be_removed; + int j,sent,third_value; + ssize_t ret; + + static char text[DLT_DAEMON_TEXTSIZE]; + + PRINT_FUNCTION_VERBOSE(verbose); + + if ((daemon==0) || (daemon_local==0)) + { + dlt_log(LOG_ERR, "Invalid function parameters used for function dlt_daemon_process_user_message_log()\n"); + return -1; + } + + if (dlt_message_read(&(daemon_local->msg),(unsigned char*)daemon_local->receiver.buf+sizeof(DltUserHeader),daemon_local->receiver.bytesRcvd-sizeof(DltUserHeader),0,verbose)==0) + { + /* set overwrite ecu id */ + if (daemon_local->flags.evalue!=0) + { + /* Set header extra parameters */ + dlt_set_id(daemon_local->msg.headerextra.ecu, daemon->ecuid ); + //msg.headerextra.seid = 0; + if (dlt_message_set_extraparameters(&(daemon_local->msg),0)==-1) + { + dlt_log(LOG_ERR,"Can't set message extra parameters in process user message log\n"); + return -1; + } + + /* Correct value of timestamp, this was changed by dlt_message_set_extraparameters() */ + daemon_local->msg.headerextra.tmsp = DLT_BETOH_32(daemon_local->msg.headerextra.tmsp); + } + + /* prepare storage header */ + if (DLT_IS_HTYP_WEID(daemon_local->msg.standardheader->htyp)) + { + if (dlt_set_storageheader(daemon_local->msg.storageheader,daemon_local->msg.headerextra.ecu)==-1) + { + dlt_log(LOG_ERR,"Can't set storage header in process user message log\n"); + return -1; + } + } + else + { + if (dlt_set_storageheader(daemon_local->msg.storageheader,daemon->ecuid)==-1) + { + dlt_log(LOG_ERR,"Can't set storage header in process user message log\n"); + return -1; + } + } + + { + /* if no filter set or filter is matching display message */ + if (daemon_local->flags.xflag) + { + if (dlt_message_print_hex(&(daemon_local->msg),text,DLT_DAEMON_TEXTSIZE,verbose)==-1) + { + dlt_log(LOG_ERR,"dlt_message_print_hex() failed!\n"); + } + } /* if */ + else if (daemon_local->flags.aflag) + { + if (dlt_message_print_ascii(&(daemon_local->msg),text,DLT_DAEMON_TEXTSIZE,verbose)==-1) + { + dlt_log(LOG_ERR,"dlt_message_print_ascii() failed!\n"); + } + } /* if */ + else if (daemon_local->flags.sflag) + { + if (dlt_message_print_header(&(daemon_local->msg),text,DLT_DAEMON_TEXTSIZE,verbose)==-1) + { + dlt_log(LOG_ERR,"dlt_message_print_header() failed!\n"); + } + /* print message header only */ + } /* if */ + + sent=0; + + /* write message to offline trace */ + if(((daemon->mode == DLT_USER_MODE_INTERNAL) || (daemon->mode == DLT_USER_MODE_BOTH)) && daemon_local->flags.offlineTraceDirectory[0]) + { + 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); + sent = 1; + } + + /* look if TCP connection to client is available */ + for (j = 0;((daemon->mode == DLT_USER_MODE_EXTERNAL) || (daemon->mode == DLT_USER_MODE_BOTH)) && (j <= daemon_local->fdmax); j++) + { + /* send to everyone! */ + if (FD_ISSET(j, &(daemon_local->master))) + { + /* except the listener and ourselves */ + if (daemon_local->flags.yvalue[0]) + { + third_value = daemon_local->fdserial; + } + else + { + third_value = daemon_local->sock; + } + + if ((j != daemon_local->fp) && (j != daemon_local->sock) && (j != third_value)) + { + DLT_DAEMON_SEM_LOCK(); + + if (daemon_local->flags.lflag) + { + send(j,dltSerialHeader,sizeof(dltSerialHeader),0); + } + + send(j,daemon_local->msg.headerbuffer+sizeof(DltStorageHeader),daemon_local->msg.headersize-sizeof(DltStorageHeader),0); + send(j,daemon_local->msg.databuffer,daemon_local->msg.datasize,0); + + DLT_DAEMON_SEM_FREE(); + + sent=1; + } /* if */ + else if ((j == daemon_local->fdserial) && (daemon_local->flags.yvalue!=0)) + { + DLT_DAEMON_SEM_LOCK(); + + if (daemon_local->flags.lflag) + { + ret=write(j,dltSerialHeader,sizeof(dltSerialHeader)); + } + + ret=write(j,daemon_local->msg.headerbuffer+sizeof(DltStorageHeader),daemon_local->msg.headersize-sizeof(DltStorageHeader)); + ret=write(j,daemon_local->msg.databuffer,daemon_local->msg.datasize); + + DLT_DAEMON_SEM_FREE(); + + sent=1; + } + } /* if */ + } /* for */ + + /* Message was not sent to client, so store it in client ringbuffer */ + if (sent==0) + { + if (dlt_ringbuffer_put3(&(daemon->client_ringbuffer), + daemon_local->msg.headerbuffer+sizeof(DltStorageHeader),daemon_local->msg.headersize-sizeof(DltStorageHeader), + daemon_local->msg.databuffer,daemon_local->msg.datasize, + 0, 0 + )<0) + { + dlt_log(LOG_ERR,"Storage of message in history buffer failed! Message discarded.\n"); + } + } + + } + /* keep not read data in buffer */ + bytes_to_be_removed = daemon_local->msg.headersize+daemon_local->msg.datasize-sizeof(DltStorageHeader)+sizeof(DltUserHeader); + if (daemon_local->msg.found_serialheader) + { + bytes_to_be_removed += sizeof(dltSerialHeader); + } + + if (dlt_receiver_remove(&(daemon_local->receiver),bytes_to_be_removed)==-1) + { + dlt_log(LOG_ERR,"Can't remove bytes from receiver\n"); + return -1; + } + } + else + { + dlt_log(LOG_ERR,"Can't read messages from receiver\n"); + return -1; + } + + return 0; +} + +int dlt_daemon_process_user_message_log_shm(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose) { int bytes_to_be_removed=0; int j,sent,third_value; @@ -1724,29 +1912,18 @@ int dlt_daemon_process_user_message_log(DltDaemon *daemon, DltDaemonLocal *daemo //dlt_shm_status(&(daemon_local->dlt_shm)); while (1) { - if(userheader->message == DLT_USER_MESSAGE_LOG_SHM) { - /* log message in SHM */ - if((size = dlt_shm_copy(&(daemon_local->dlt_shm),rcv_buffer,10000)) <= 0) - break; - if (dlt_message_read(&(daemon_local->msg),rcv_buffer,size,0,verbose)!=0) { - break; - dlt_log(LOG_ERR,"Can't read messages from shm\n"); - return -1; - } - bytes_to_be_removed = daemon_local->msg.headersize+daemon_local->msg.datasize-sizeof(DltStorageHeader)+sizeof(DltUserHeader); - if (daemon_local->msg.found_serialheader) - { - bytes_to_be_removed += sizeof(dltSerialHeader); - } - } - else { /* userheader->message == DLT_USER_MESSAGE_LOG */ - /* log message in FIFO */ - if(dlt_message_read(&(daemon_local->msg),(unsigned char*)daemon_local->receiver.buf+sizeof(DltUserHeader),daemon_local->receiver.bytesRcvd-sizeof(DltUserHeader),0,verbose)!=0) { - break; - dlt_log(LOG_ERR,"Can't read messages from receiver\n"); - return -1; - } ; - bytes_to_be_removed = sizeof(DltUserHeader); + /* log message in SHM */ + if((size = dlt_shm_copy(&(daemon_local->dlt_shm),rcv_buffer,10000)) <= 0) + break; + if (dlt_message_read(&(daemon_local->msg),rcv_buffer,size,0,verbose)!=0) { + break; + dlt_log(LOG_ERR,"Can't read messages from shm\n"); + return -1; + } + bytes_to_be_removed = daemon_local->msg.headersize+daemon_local->msg.datasize-sizeof(DltStorageHeader)+sizeof(DltUserHeader); + if (daemon_local->msg.found_serialheader) + { + bytes_to_be_removed += sizeof(dltSerialHeader); } /* set overwrite ecu id */ @@ -1827,7 +2004,7 @@ int dlt_daemon_process_user_message_log(DltDaemon *daemon, DltDaemonLocal *daemo if (FD_ISSET(j, &(daemon_local->master))) { /* except the listener and ourselves */ - if (daemon_local->flags.yvalue!=0) + if (daemon_local->flags.yvalue[0]) { third_value = daemon_local->fdserial; } @@ -2003,6 +2180,72 @@ int dlt_daemon_process_user_message_log_mode(DltDaemon *daemon, DltDaemonLocal * return 0; } +int dlt_daemon_send_ringbuffer_to_client(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose) +{ + static uint8_t data[DLT_DAEMON_RINGBUFFER_SIZE]; + size_t length=0; + int j, third_value; + ssize_t ret; + + PRINT_FUNCTION_VERBOSE(verbose); + + if ((daemon==0) || (daemon_local==0)) + { + dlt_log(LOG_ERR, "Invalid function parameters used for function dlt_daemon_send_ringbuffer_to_client()\n"); + return -1; + } + + /* Attention: If the message can't be send at this time, it will be silently discarded. */ + while ((dlt_ringbuffer_get(&(daemon->client_ringbuffer), data, &length ))!=-1) + { + /* look if TCP connection to client is available */ + for (j = 0; j <= daemon_local->fdmax; j++) + { + /* send to everyone! */ + if (FD_ISSET(j, &(daemon_local->master))) + { + /* except the listener and ourselves */ + if (daemon_local->flags.yvalue[0]) + { + third_value = daemon_local->fdserial; + } + else + { + third_value = daemon_local->sock; + } + + if ((j != daemon_local->fp) && (j != daemon_local->sock) && (j != third_value)) + { + DLT_DAEMON_SEM_LOCK(); + + if (daemon_local->flags.lflag) + { + send(j,dltSerialHeader,sizeof(dltSerialHeader),0); + } + send(j,data,length,0); + + DLT_DAEMON_SEM_FREE(); + + } /* if */ + else if ((j == daemon_local->fdserial) && (daemon_local->flags.yvalue[0])) + { + DLT_DAEMON_SEM_LOCK(); + + if (daemon_local->flags.lflag) + { + ret=write(j,dltSerialHeader,sizeof(dltSerialHeader)); + } + ret=write(j,data,length); + + DLT_DAEMON_SEM_LOCK(); + } + } /* if */ + } /* for */ + } + + return 0; +} + void dlt_daemon_timingpacket_thread(void *ptr) { DltDaemonPeriodicData info; diff --git a/src/daemon/dlt-daemon.h b/src/daemon/dlt-daemon.h index bc3ba39..5d15326 100755 --- a/src/daemon/dlt-daemon.h +++ b/src/daemon/dlt-daemon.h @@ -171,9 +171,11 @@ int dlt_daemon_process_user_message_unregister_application(DltDaemon *daemon, Dl int dlt_daemon_process_user_message_register_context(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose); int dlt_daemon_process_user_message_unregister_context(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose); int dlt_daemon_process_user_message_log(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose); +int dlt_daemon_process_user_message_log_shm(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose); int dlt_daemon_process_user_message_set_app_ll_ts(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose); int dlt_daemon_process_user_message_log_mode(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose); +int dlt_daemon_send_ringbuffer_to_client(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose); void dlt_daemon_timingpacket_thread(void *ptr); int dlt_daemon_make_periodic (unsigned int period, DltDaemonPeriodicData *info, int verbose); void dlt_daemon_wait_period(DltDaemonPeriodicData *info, int verbose); diff --git a/src/daemon/dlt.conf b/src/daemon/dlt.conf index a410d19..380e0bc 100644 --- a/src/daemon/dlt.conf +++ b/src/daemon/dlt.conf @@ -16,16 +16,16 @@ # SendSerialHeader = 1 # Send automatic get log info response during context registration -# SendContextRegistration = 1 +SendContextRegistration = 1 # Send automatic time packets every second if client is connected (Default: 0) -# SendMessageTime = 1 +SendMessageTime = 1 # Set ECU ID (Default: ECU1) ECUId = ENAT # Size of shared memory (Default: 100000) -SharedMemorySize = 40000 +SharedMemorySize = 4000000 # Directory where to store the persistant configuration (Default: /tmp) # PersistanceStoragePath = /tmp diff --git a/src/daemon/dlt_daemon_common.c b/src/daemon/dlt_daemon_common.c index 4877825..aaed7a2 100755 --- a/src/daemon/dlt_daemon_common.c +++ b/src/daemon/dlt_daemon_common.c @@ -187,6 +187,12 @@ int dlt_daemon_init(DltDaemon *daemon,const char *runtime_directory, int verbose dlt_set_id(daemon->ecuid,""); + /* initialize ring buffer for client connection */ + if (dlt_ringbuffer_init(&(daemon->client_ringbuffer), DLT_DAEMON_RINGBUFFER_SIZE)==-1) + { + return -1; + } + return 0; } @@ -2138,8 +2144,16 @@ void dlt_daemon_control_send_control_message( int sock, DltDaemon *daemon, DltMe } else { - /* message can not be sent */ - /* in old implementation control message was stored in buffer */ + /* Store message in history buffer */ + if (dlt_ringbuffer_put3(&(daemon->client_ringbuffer), + msg->headerbuffer+sizeof(DltStorageHeader),msg->headersize-sizeof(DltStorageHeader), + msg->databuffer,msg->datasize, + 0, 0 + )<0) + { + dlt_log(LOG_ERR,"Storage of message in history buffer failed! Message discarded.\n"); + return; + } } } diff --git a/src/daemon/dlt_daemon_common.h b/src/daemon/dlt_daemon_common.h index 2bdb637..17bc32f 100755 --- a/src/daemon/dlt_daemon_common.h +++ b/src/daemon/dlt_daemon_common.h @@ -149,6 +149,7 @@ typedef struct char ecuid[DLT_ID_SIZE]; /**< ECU ID of daemon */ int sendserialheader; /**< 1: send serial header; 0 don't send serial header */ int timingpackets; /**< 1: send continous timing packets; 0 don't send continous timing packets */ + DltRingBuffer client_ringbuffer; /**< Ring-buffer for storing received logs while no client connection is available */ char runtime_application_cfg[256]; /**< Path and filename of persistent application configuration */ char runtime_context_cfg[256]; /**< Path and filename of persistent context configuration */ char runtime_configuration[256]; /**< Path and filename of persistent configuration */ diff --git a/src/lib/dlt_filetransfer.c b/src/lib/dlt_filetransfer.c index 935573d..7377cb6 100644 --- a/src/lib/dlt_filetransfer.c +++ b/src/lib/dlt_filetransfer.c @@ -350,7 +350,7 @@ int dlt_user_log_file_data(DltContext *fileContext,const char *filename, int pac DLT_STRING("FLDA") ); - doTimeout(timeout); + //doTimeout(timeout); } else { pkgNumber = 0; @@ -367,7 +367,7 @@ int dlt_user_log_file_data(DltContext *fileContext,const char *filename, int pac DLT_STRING("FLDA") ); - doTimeout(timeout); + //doTimeout(timeout); } } diff --git a/src/lib/dlt_user.c b/src/lib/dlt_user.c index bdb9efe..eac0215 100755 --- a/src/lib/dlt_user.c +++ b/src/lib/dlt_user.c @@ -2048,7 +2048,11 @@ int dlt_user_log_send_log(DltContextData *log, int mtype) } /* also for Trace messages */ +#ifdef DLT_SHM_ENABLE if (dlt_user_set_userheader(&userheader, DLT_USER_MESSAGE_LOG_SHM)==-1) +#else + if (dlt_user_set_userheader(&userheader, DLT_USER_MESSAGE_LOG)==-1) +#endif { return -1; } @@ -2182,6 +2186,7 @@ int dlt_user_log_send_log(DltContextData *log, int mtype) } } +#ifdef DLT_SHM_ENABLE dlt_shm_push(&dlt_user.dlt_shm,msg.headerbuffer+sizeof(DltStorageHeader), msg.headersize-sizeof(DltStorageHeader), log->buffer, log->size,0,0); @@ -2190,7 +2195,14 @@ int dlt_user_log_send_log(DltContextData *log, int mtype) &(userheader), sizeof(DltUserHeader), 0, 0, 0, 0); - +#else + /* log to FIFO */ + ret = dlt_user_log_out3(dlt_user.dlt_log_handle, + &(userheader), sizeof(DltUserHeader), + msg.headerbuffer+sizeof(DltStorageHeader), msg.headersize-sizeof(DltStorageHeader), + log->buffer, log->size); + +#endif /* store message in ringbuffer, if an error has occured */ if (ret!=DLT_RETURN_OK) { @@ -2830,12 +2842,17 @@ void dlt_user_log_reattach_to_daemon(void) if (size>0) { +#ifdef DLT_SHM_ENABLE dlt_shm_push(&dlt_user.dlt_shm,buf+sizeof(DltUserHeader),size-sizeof(DltUserHeader),0,0,0,0); /* log to FIFO */ ret = dlt_user_log_out3(dlt_user.dlt_log_handle, buf,sizeof(DltUserHeader),0,0,0,0); +#else + /* log to FIFO */ + ret = dlt_user_log_out3(dlt_user.dlt_log_handle, buf,size,0,0,0,0); +#endif - /* in case of error, push message back to ringbuffer */ + /* in case of error, push message back to ringbuffer */ if (ret!=DLT_RETURN_OK) { DLT_SEM_LOCK(); diff --git a/src/system/dlt-system-log.c b/src/system/dlt-system-log.c index cf2b495..6a76221 100644 --- a/src/system/dlt-system-log.c +++ b/src/system/dlt-system-log.c @@ -181,9 +181,11 @@ void dlt_system_filetransfer_run(DltSystemOptions *options,DltSystemRuntime *run printf("Error: dlt_user_log_file_data\n"); return; } +#ifdef DLT_SHM_ENABLE /* wait sending next package if more than 50% of buffer used */ dlt_user_check_buffer(&total_size, &used_size); if((total_size - used_size) < (total_size/2)) +#endif break; } if(runtime->filetransferLastSentPackage==runtime->filetransferCountPackages) { diff --git a/src/system/dlt-system.c b/src/system/dlt-system.c index 2040aab..c2df24c 100755 --- a/src/system/dlt-system.c +++ b/src/system/dlt-system.c @@ -630,7 +630,7 @@ int main(int argc, char* argv[]) /* Wait up to one second. */ tv.tv_sec = 0; if(runtime.filetransferRunning) - tv.tv_usec = 10000; + tv.tv_usec = 20000; else tv.tv_usec = (dlt_uptime()-lasttime+10000)*100; diff --git a/src/system/dlt-system.conf b/src/system/dlt-system.conf index 1811fc3..235f00e 100644 --- a/src/system/dlt-system.conf +++ b/src/system/dlt-system.conf @@ -38,11 +38,11 @@ FiletransferContextId = FILE # Time after startup of dlt-system when first file is transfered (Default: 30) # Time in seconds -FiletransferTimeStartup = 30 +FiletransferTimeStartup = 10 # Time to wait when transfered file is deleted and next file transfer starts (Default: 10) # Time in seconds -FiletransferTimeDelay = 10 +FiletransferTimeDelay = 3 ######################################################################## # Log short files, expecially from proc filesystem -- cgit v1.2.1