[GDLT-94]: Send periodic software version messages.
authorLassi Marttala <lassi.lm.marttala@partner.bmw.de>
Tue, 5 Jun 2012 11:11:23 +0000 (13:11 +0200)
committerChristian Muck <christian.muck@bmw.de>
Wed, 13 Jun 2012 21:53:21 +0000 (23:53 +0200)
Signed-off-by: Christian Muck <christian.muck@bmw.de>
include/dlt/dlt_common.h
src/daemon/dlt-daemon.c
src/daemon/dlt-daemon.h
src/daemon/dlt-daemon_cfg.h
src/daemon/dlt.conf
src/daemon/dlt_daemon_common.c
src/daemon/dlt_daemon_common.h

index 690c2bd..5af6332 100755 (executable)
@@ -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;
 
 /**
index 57a3d02..24d327e 100644 (file)
@@ -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)
 {
index 40159f4..f595e8d 100755 (executable)
@@ -98,6 +98,8 @@ typedef struct
     int  loggingMode;  /**< (int) The logging console for internal logging of dlt-daemon (Default: 0) */\r
     int  loggingLevel; /**< (int) The logging level for internal logging of dlt-daemon (Default: 6) */\r
     char loggingFilename[256]; /**< (String: Filename) The logging filename if internal logging mode is log to file (Default: /tmp/log) */\r
+    int  sendECUSoftwareVersion;\r
+    char pathToECUSoftwareVersion[256];\r
 } DltDaemonFlags;\r
 \r
 /**\r
@@ -138,6 +140,8 @@ typedef struct
     DltDaemonLocal *daemon_local;\r
 } DltDaemonTimingPacketThreadData;\r
 \r
+typedef DltDaemonTimingPacketThreadData DltDaemonECUVersionThreadData;\r
+\r
 /* Function prototypes */\r
 void dlt_daemon_local_cleanup(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose);\r
 int dlt_daemon_local_init_p1(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose);\r
@@ -166,6 +170,7 @@ int dlt_daemon_process_user_message_log_mode(DltDaemon *daemon, DltDaemonLocal *
 \r
 int dlt_daemon_send_ringbuffer_to_client(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose);\r
 void dlt_daemon_timingpacket_thread(void *ptr);\r
+void dlt_daemon_ecu_version_thread(void *ptr);\r
 #if defined(DLT_SYSTEMD_WATCHDOG_ENABLE)\r
        void dlt_daemon_systemd_watchdog_thread(void *ptr);\r
 #endif\r
index a038070..24ad20e 100755 (executable)
@@ -72,6 +72,9 @@
 /* Stack size of timing packet thread */\r
 #define DLT_DAEMON_TIMINGPACKET_THREAD_STACKSIZE 100000\r
 \r
+/* Stack size of ecu version thread */\r
+#define DLT_DAEMON_ECU_VERSION_THREAD_STACKSIZE 100000\r
+\r
 /* Size of receive buffer for fifo connection  (from user application) */\r
 #define DLT_DAEMON_RCVBUFSIZE       10024 \r
 /* Size of receive buffer for socket connection (from dlt client) */\r
index 17b30ac..2e8ba18 100644 (file)
@@ -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
index be472a3..7b96a9d 100644 (file)
@@ -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);
 }
-
index 48c8868..8f0c910 100644 (file)
@@ -454,6 +454,14 @@ void dlt_daemon_control_reset_to_factory_default(DltDaemon *daemon,const char *f
  */\r
 void dlt_daemon_control_message_time(int sock, DltDaemon *daemon, int verbose);\r
 \r
+/**\r
+ * Send ECU version information\r
+ * @param sock connection handle used for sending response\r
+ * @param daemon pointer to dlt daemon structure\r
+ * @param version string containing the version information\r
+ * @param verbose if set to true verbose information is printed out.\r
+ */\r
+void dlt_daemon_control_send_ecu_version(int sock, DltDaemon *daemon, const char *version, int verbose);\r
 #ifdef __cplusplus\r
 }\r
 #endif\r