From 8fc9c8b59cfde03330fab649a5a084b8c95c08ed Mon Sep 17 00:00:00 2001 From: Lassi Marttala Date: Tue, 5 Jun 2012 13:11:23 +0200 Subject: [GDLT-94]: Send periodic software version messages. Signed-off-by: Christian Muck --- include/dlt/dlt_common.h | 2 +- src/daemon/dlt-daemon.c | 101 ++++++++++++++++++++++++++++++++++++++++- src/daemon/dlt-daemon.h | 5 ++ src/daemon/dlt-daemon_cfg.h | 3 ++ src/daemon/dlt.conf | 7 ++- src/daemon/dlt_daemon_common.c | 53 ++++++++++++++++++++- src/daemon/dlt_daemon_common.h | 8 ++++ 7 files changed, 175 insertions(+), 4 deletions(-) diff --git a/include/dlt/dlt_common.h b/include/dlt/dlt_common.h index 690c2bd..5af6332 100755 --- a/include/dlt/dlt_common.h +++ b/include/dlt/dlt_common.h @@ -481,7 +481,7 @@ typedef struct uint32_t service_id; /**< service ID */ uint8_t status; /**< reponse status */ uint32_t length; /**< length of following payload */ - /* char [] payload */ + /*char [] payload;*/ } PACKED DltServiceGetSoftwareVersionResponse; /** diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c index 57a3d02..24d327e 100644 --- a/src/daemon/dlt-daemon.c +++ b/src/daemon/dlt-daemon.c @@ -104,6 +104,9 @@ static DltDaemonTimingPacketThreadData dlt_daemon_timingpacket_thread_data; static pthread_t dlt_daemon_timingpacket_thread_handle; static pthread_attr_t dlt_daemon_timingpacket_thread_attr; +static DltDaemonECUVersionThreadData dlt_daemon_ecu_version_thread_data; +static pthread_t dlt_daemon_ecu_version_thread_handle; + #if defined(DLT_SYSTEMD_WATCHDOG_ENABLE) static DltDaemonTimingPacketThreadData dlt_daemon_systemd_watchdog_thread_data; static pthread_t dlt_daemon_systemd_watchdog_thread_handle; @@ -119,7 +122,7 @@ void usage() //printf("DLT logging daemon %s %s\n", _DLT_PACKAGE_VERSION, _DLT_PACKAGE_VERSION_STATE); //printf("Compile options: %s %s %s %s",_DLT_SYSTEMD_ENABLE, _DLT_SYSTEMD_WATCHDOG_ENABLE, _DLT_TEST_ENABLE, _DLT_SHM_ENABLE); - printf(version); + printf("%s", version); printf("Usage: dlt-daemon [options]\n"); printf("Options:\n"); printf(" -d Daemonize\n"); @@ -215,6 +218,8 @@ int option_file_parser(DltDaemonLocal *daemon_local) daemon_local->flags.loggingMode = 0; daemon_local->flags.loggingLevel = 6; strncpy(daemon_local->flags.loggingFilename, DLT_USER_DIR "/dlt.log",sizeof(daemon_local->flags.loggingFilename)); + daemon_local->flags.sendECUSoftwareVersion = 0; + memset(daemon_local->flags.pathToECUSoftwareVersion, 0, sizeof(daemon_local->flags.pathToECUSoftwareVersion)); /* open configuration file */ if(daemon_local->flags.cvalue[0]) @@ -356,6 +361,17 @@ int option_file_parser(DltDaemonLocal *daemon_local) daemon_local->flags.offlineTraceMaxSize = atoi(value); //printf("Option: %s=%s\n",token,value); } + else if(strcmp(token,"SendECUSoftwareVersion")==0) + { + daemon_local->flags.sendECUSoftwareVersion = atoi(value); + //printf("Option: %s=%s\n",token,value); + } + else if(strcmp(token,"PathToECUSoftwareVersion")==0) + { + strncpy(daemon_local->flags.pathToECUSoftwareVersion,value,sizeof(daemon_local->flags.pathToECUSoftwareVersion)); + //printf("Option: %s=%s\n",token,value); + } + else { fprintf(stderr, "Unknown option: %s=%s\n",token,value); @@ -684,7 +700,21 @@ int dlt_daemon_local_init_p2(DltDaemon *daemon, DltDaemonLocal *daemon_local, in pthread_attr_destroy(&dlt_daemon_timingpacket_thread_attr); + /* start thread for ecu version, if enabled */ + if(daemon_local->flags.sendECUSoftwareVersion > 0) + { + dlt_daemon_ecu_version_thread_data.daemon = daemon; + dlt_daemon_ecu_version_thread_data.daemon_local = daemon_local; + if (pthread_create(&(dlt_daemon_ecu_version_thread_handle), + NULL, + (void *) &dlt_daemon_ecu_version_thread, + (void *)&dlt_daemon_ecu_version_thread_data)!=0) + { + dlt_log(LOG_ERR,"Could not initialize ecu version thread\n"); + return -1; + } + } #if defined(DLT_SYSTEMD_WATCHDOG_ENABLE) @@ -2350,6 +2380,75 @@ void dlt_daemon_timingpacket_thread(void *ptr) dlt_daemon_wait_period (&info, daemon_local->flags.vflag); } } + +void dlt_daemon_ecu_version_thread(void *ptr) +{ + DltDaemonECUVersionThreadData *data = (DltDaemonECUVersionThreadData *)ptr; + DltDaemonPeriodicData info; + char version[DLT_DAEMON_TEXTBUFSIZE]; + if(data->daemon_local->flags.pathToECUSoftwareVersion[0] == 0) + { + dlt_get_version(version); + } + else + { + size_t bufpos = 0; + size_t read = 0; + FILE *f = fopen(data->daemon_local->flags.pathToECUSoftwareVersion, "r"); + + if(f == NULL) + { + dlt_log(LOG_ERR, "Failed to open ECU Software version file.\n"); + return; + } + + while(!feof(f)) + { + char buf[DLT_DAEMON_TEXTBUFSIZE]; + read = fread(buf, 1, DLT_DAEMON_TEXTBUFSIZE, f); + if(ferror(f)) + { + dlt_log(LOG_ERR, "Failed to read ECU Software version file.\n"); + return; + } + if(bufpos + read > DLT_DAEMON_TEXTBUFSIZE) + { + dlt_log(LOG_ERR, "Too long file for ecu version info.\n"); + fclose(f); + return; + } + strncpy(version+bufpos, buf, read); + bufpos += read; + } + fclose(f); + } + + if (dlt_daemon_make_periodic (1000000*60, &info, data->daemon_local->flags.vflag)<0) + { + dlt_log(LOG_CRIT,"Can't initialize thread timer!\n"); + return; + } + + while(1) + { + int i; + for (i = 0; i <= data->daemon_local->fdmax; i++) + { + /* send to everyone! */ + if (FD_ISSET(i, &(data->daemon_local->master))) + { + /* except the listener and ourselves */ + if ((i != data->daemon_local->fp) && (i != data->daemon_local->sock)) + { + dlt_daemon_control_send_ecu_version(i, data->daemon, version, data->daemon_local->flags.vflag); + } + } + } + dlt_daemon_wait_period (&info, data->daemon_local->flags.vflag); + } + +} + #if defined(DLT_SYSTEMD_WATCHDOG_ENABLE) void dlt_daemon_systemd_watchdog_thread(void *ptr) { diff --git a/src/daemon/dlt-daemon.h b/src/daemon/dlt-daemon.h index 40159f4..f595e8d 100755 --- a/src/daemon/dlt-daemon.h +++ b/src/daemon/dlt-daemon.h @@ -98,6 +98,8 @@ typedef struct int loggingMode; /**< (int) The logging console for internal logging of dlt-daemon (Default: 0) */ int loggingLevel; /**< (int) The logging level for internal logging of dlt-daemon (Default: 6) */ char loggingFilename[256]; /**< (String: Filename) The logging filename if internal logging mode is log to file (Default: /tmp/log) */ + int sendECUSoftwareVersion; + char pathToECUSoftwareVersion[256]; } DltDaemonFlags; /** @@ -138,6 +140,8 @@ typedef struct DltDaemonLocal *daemon_local; } DltDaemonTimingPacketThreadData; +typedef DltDaemonTimingPacketThreadData DltDaemonECUVersionThreadData; + /* Function prototypes */ void dlt_daemon_local_cleanup(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose); int dlt_daemon_local_init_p1(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose); @@ -166,6 +170,7 @@ int dlt_daemon_process_user_message_log_mode(DltDaemon *daemon, DltDaemonLocal * int dlt_daemon_send_ringbuffer_to_client(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose); void dlt_daemon_timingpacket_thread(void *ptr); +void dlt_daemon_ecu_version_thread(void *ptr); #if defined(DLT_SYSTEMD_WATCHDOG_ENABLE) void dlt_daemon_systemd_watchdog_thread(void *ptr); #endif diff --git a/src/daemon/dlt-daemon_cfg.h b/src/daemon/dlt-daemon_cfg.h index a038070..24ad20e 100755 --- a/src/daemon/dlt-daemon_cfg.h +++ b/src/daemon/dlt-daemon_cfg.h @@ -72,6 +72,9 @@ /* Stack size of timing packet thread */ #define DLT_DAEMON_TIMINGPACKET_THREAD_STACKSIZE 100000 +/* Stack size of ecu version thread */ +#define DLT_DAEMON_ECU_VERSION_THREAD_STACKSIZE 100000 + /* Size of receive buffer for fifo connection (from user application) */ #define DLT_DAEMON_RCVBUFSIZE 10024 /* Size of receive buffer for socket connection (from dlt client) */ diff --git a/src/daemon/dlt.conf b/src/daemon/dlt.conf index 17b30ac..2e8ba18 100644 --- a/src/daemon/dlt.conf +++ b/src/daemon/dlt.conf @@ -83,10 +83,15 @@ OfflineTraceMaxSize = 4000000 # RS232SyncSerialHeader = 1 ######################################################################## -# TCP Serial port configuration # +# TCP Serial port configuration # ######################################################################## # Sync to serial header on all TCP connections # TCPSyncSerialHeader = 1 +######################################################################## +# ECU Software version info # +######################################################################## +SendECUSoftwareVersion = 1 +PathToECUSoftwareVersion = /etc/ecu.version diff --git a/src/daemon/dlt_daemon_common.c b/src/daemon/dlt_daemon_common.c index be472a3..7b96a9d 100644 --- a/src/daemon/dlt_daemon_common.c +++ b/src/daemon/dlt_daemon_common.c @@ -2117,6 +2117,58 @@ void dlt_daemon_control_service_response( int sock, DltDaemon *daemon, uint32_t dlt_message_free(&msg,0); } +void dlt_daemon_control_send_ecu_version(int sock, DltDaemon *daemon, const char *version, int verbose) +{ + DltMessage msg; + uint32_t len; + DltServiceGetSoftwareVersionResponse *resp; + + PRINT_FUNCTION_VERBOSE(verbose); + + if (daemon==0 || version == NULL) + { + return; + } + + /* initialise new message */ + if (dlt_message_init(&msg,0)==-1) + { + dlt_daemon_control_service_response(sock, daemon, DLT_SERVICE_ID_GET_SOFTWARE_VERSION, DLT_SERVICE_RESPONSE_ERROR, verbose); + return; + } + + /* prepare payload of data */ + len = strlen(version); + + msg.datasize = sizeof(DltServiceGetSoftwareVersionResponse) + len; + if (msg.databuffer && (msg.databuffersize < msg.datasize)) + { + free(msg.databuffer); + msg.databuffer=0; + } + if (msg.databuffer == 0){ + msg.databuffer = (uint8_t *) malloc(msg.datasize); + msg.databuffersize = msg.datasize; + } + if (msg.databuffer==0) + { + dlt_daemon_control_service_response(sock, daemon, DLT_SERVICE_ID_GET_SOFTWARE_VERSION, DLT_SERVICE_RESPONSE_ERROR, verbose); + return; + } + + resp = (DltServiceGetSoftwareVersionResponse*) msg.databuffer; + resp->service_id = DLT_SERVICE_ID_GET_SOFTWARE_VERSION; + resp->status = DLT_SERVICE_RESPONSE_OK; + resp->length = len; + memcpy(msg.databuffer+sizeof(DltServiceGetSoftwareVersionResponse),version,len); + + /* send message */ + dlt_daemon_control_send_control_message(sock, daemon, &msg,"","", verbose); + + /* free message */ + dlt_message_free(&msg,0); +} + void dlt_daemon_control_send_control_message( int sock, DltDaemon *daemon, DltMessage *msg, char* appid, char* ctid, int verbose) { ssize_t ret; @@ -2457,4 +2509,3 @@ void dlt_daemon_control_message_time(int sock, DltDaemon *daemon, int verbose) /* free message */ dlt_message_free(&msg,0); } - diff --git a/src/daemon/dlt_daemon_common.h b/src/daemon/dlt_daemon_common.h index 48c8868..8f0c910 100644 --- a/src/daemon/dlt_daemon_common.h +++ b/src/daemon/dlt_daemon_common.h @@ -454,6 +454,14 @@ void dlt_daemon_control_reset_to_factory_default(DltDaemon *daemon,const char *f */ void dlt_daemon_control_message_time(int sock, DltDaemon *daemon, int verbose); +/** + * Send ECU version information + * @param sock connection handle used for sending response + * @param daemon pointer to dlt daemon structure + * @param version string containing the version information + * @param verbose if set to true verbose information is printed out. + */ +void dlt_daemon_control_send_ecu_version(int sock, DltDaemon *daemon, const char *version, int verbose); #ifdef __cplusplus } #endif -- cgit v1.2.1