summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLassi Marttala <Lassi.LM.Marttala@partner.bmw.de>2013-01-18 11:44:02 +0100
committerAlexander Wenzel <Alexander.AW.Wenzel@bmw.de>2013-07-19 16:54:16 +0200
commiteaf180bbe2cd7134cf31f2a8627fa861519d95ad (patch)
tree0fb40d6d77ced47b9332fe89ceb293864c7495d1
parent3774bc35a6491de7bd82e5f955b78f3a9ee70116 (diff)
downloadDLT-daemon-eaf180bbe2cd7134cf31f2a8627fa861519d95ad.tar.gz
Unify ECU version sending functions
Review changes: Lower log level when opening fails. It might be deliberately set to non-existent file. Give name to period time in ECU version sending Merge branch 'LM-GSWD-162' Signed-off-by: Alexander Wenzel <Alexander.AW.Wenzel@bmw.de>
-rw-r--r--src/daemon/dlt-daemon.c122
-rwxr-xr-xsrc/daemon/dlt-daemon.h5
-rw-r--r--src/daemon/dlt_daemon_common.c58
-rw-r--r--src/daemon/dlt_daemon_common.h16
4 files changed, 84 insertions, 117 deletions
diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c
index 221527d..ca45aab 100644
--- a/src/daemon/dlt-daemon.c
+++ b/src/daemon/dlt-daemon.c
@@ -739,7 +739,14 @@ 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 */
+ /* Get ECU version info from a file. If it fails, use dlt_version as fallback. */
+ if(dlt_daemon_local_ecu_version_init(daemon, daemon_local, daemon_local->flags.vflag) < 0)
+ {
+ daemon->ECUVersionString = malloc(DLT_DAEMON_TEXTBUFSIZE);
+ dlt_get_version(daemon->ECUVersionString);
+ }
+
+ /* start thread for ECU version, if enabled */
if(daemon_local->flags.sendECUSoftwareVersion > 0)
{
dlt_daemon_ecu_version_thread_data.daemon = daemon;
@@ -750,7 +757,7 @@ int dlt_daemon_local_init_p2(DltDaemon *daemon, DltDaemonLocal *daemon_local, in
(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");
+ dlt_log(LOG_ERR,"Could not initialize ECU version thread\n");
return -1;
}
}
@@ -918,6 +925,69 @@ int dlt_daemon_local_connection_init(DltDaemon *daemon, DltDaemonLocal *daemon_l
return 0;
}
+int dlt_daemon_local_ecu_version_init(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose)
+{
+ char *version = NULL;
+ FILE *f = NULL;
+
+ PRINT_FUNCTION_VERBOSE(verbose);
+
+ /* By default, version string is null. */
+ daemon->ECUVersionString = NULL;
+
+ /* Open the file. Bail out if error occurs */
+ f = fopen(daemon_local->flags.pathToECUSoftwareVersion, "r");
+ if(f == NULL)
+ {
+ /* Error level notice, because this might be deliberate choice */
+ dlt_log(LOG_NOTICE, "Failed to open ECU Software version file.\n");
+ return -1;
+ }
+
+ /* Get the file size. Bail out if stat fails. */
+ int fd = fileno(f);
+ struct stat s_buf;
+ if(fstat(fd, &s_buf) < 0)
+ {
+ dlt_log(LOG_ERR, "Failed to stat ECU Software version file.\n");
+ return -1;
+ }
+
+ /* Bail out if file is too large. Use DLT_DAEMON_TEXTBUFSIZE max.
+ * Reserve one byte for trailing '\0' */
+ off_t size = s_buf.st_size;
+ if(size >= DLT_DAEMON_TEXTBUFSIZE)
+ {
+ dlt_log(LOG_ERR, "Too large file for ECU version.\n");
+ return -1;
+ }
+
+ /* Allocate permanent buffer for version info */
+ version = malloc(size + 1);
+ off_t offset = 0;
+ while(!feof(f))
+ {
+ offset += fread(version + offset, 1, size, f);
+ if(ferror(f))
+ {
+ dlt_log(LOG_ERR, "Failed to read ECU Software version file.\n");
+ free(version);
+ fclose(f);
+ return -1;
+ }
+ if(offset > size)
+ {
+ dlt_log(LOG_ERR, "Too long file for ECU Software version info.\n");
+ free(version);
+ fclose(f);
+ return -1;
+ }
+ }
+ version[offset] = '\0';//append null termination at end of version string
+ daemon->ECUVersionString = version;
+ fclose(f);
+ return 0;
+}
void dlt_daemon_local_cleanup(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose)
{
@@ -2451,50 +2521,9 @@ 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;
- }
+ const unsigned int DLT_ECU_VERSION_PERIOD_TIME = 1000000*60; // 60 Seconds
- while(!feof(f))
- {
- char buf[DLT_DAEMON_TEXTBUFSIZE];
- read = fread(buf, 1, DLT_DAEMON_TEXTBUFSIZE - 1, f);
- buf [read] = '\0';//append null termination at end of version string. Read is definitely max: DLT_DAEMON_TEXTBUFSIZE - 1
- read++;//Include the appended null termination position
-
- if(ferror(f))
- {
- dlt_log(LOG_ERR, "Failed to read ECU Software version file.\n");
- fclose(f);
- return;
- }
- if(bufpos + read > ( DLT_DAEMON_TEXTBUFSIZE - 1))
- {
- dlt_log(LOG_ERR, "Too long file for ecu version info.\n");
- fclose(f);
- return;
- }
- strncpy(version+bufpos, buf, read);
- bufpos += read;
- }
- version[bufpos] = '\0';//append null termination at end of version string
- fclose(f);
- }
-
- if (dlt_daemon_make_periodic (1000000*60, &info, data->daemon_local->flags.vflag)<0)
+ if (dlt_daemon_make_periodic (DLT_ECU_VERSION_PERIOD_TIME, &info, data->daemon_local->flags.vflag)<0)
{
dlt_log(LOG_CRIT,"Can't initialize thread timer!\n");
return;
@@ -2511,13 +2540,12 @@ void dlt_daemon_ecu_version_thread(void *ptr)
/* 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_control_get_software_version(i, data->daemon, data->daemon_local->flags.vflag);
}
}
}
dlt_daemon_wait_period (&info, data->daemon_local->flags.vflag);
}
-
}
#if defined(DLT_SYSTEMD_WATCHDOG_ENABLE)
diff --git a/src/daemon/dlt-daemon.h b/src/daemon/dlt-daemon.h
index 37c82ac..b256cc3 100755
--- a/src/daemon/dlt-daemon.h
+++ b/src/daemon/dlt-daemon.h
@@ -103,8 +103,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];
+ int sendECUSoftwareVersion; /**< (Boolean) Send ECU software version perdiodically */
+ char pathToECUSoftwareVersion[256]; /**< (String: Filename) The file from which to read the ECU version from. */
} DltDaemonFlags;
/**
@@ -155,6 +155,7 @@ void dlt_daemon_local_cleanup(DltDaemon *daemon, DltDaemonLocal *daemon_local, i
int dlt_daemon_local_init_p1(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose);
int dlt_daemon_local_init_p2(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose);
int dlt_daemon_local_connection_init(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose);
+int dlt_daemon_local_ecu_version_init(DltDaemon *daemon, DltDaemonLocal *daemon_local, int verbose);
void dlt_daemon_daemonize(int verbose);
void dlt_daemon_signal_handler(int sig);
diff --git a/src/daemon/dlt_daemon_common.c b/src/daemon/dlt_daemon_common.c
index 28e9d54..69aecdc 100644
--- a/src/daemon/dlt_daemon_common.c
+++ b/src/daemon/dlt_daemon_common.c
@@ -1562,7 +1562,6 @@ void dlt_daemon_control_set_timing_packets(int sock, DltDaemon *daemon, DltMessa
void dlt_daemon_control_get_software_version(int sock, DltDaemon *daemon, int verbose)
{
- char version[DLT_DAEMON_COMMON_TEXTBUFSIZE];
DltMessage msg;
uint32_t len;
DltServiceGetSoftwareVersionResponse *resp;
@@ -1582,8 +1581,7 @@ void dlt_daemon_control_get_software_version(int sock, DltDaemon *daemon, int ve
}
/* prepare payload of data */
- dlt_get_version(version);
- len = strlen(version);
+ len = strlen(daemon->ECUVersionString);
msg.datasize = sizeof(DltServiceGetSoftwareVersionResponse) + len;
if (msg.databuffer && (msg.databuffersize < msg.datasize))
@@ -1605,7 +1603,7 @@ void dlt_daemon_control_get_software_version(int sock, DltDaemon *daemon, int ve
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);
+ memcpy(msg.databuffer+sizeof(DltServiceGetSoftwareVersionResponse),daemon->ECUVersionString,len);
/* send message */
dlt_daemon_control_send_control_message(sock, daemon, &msg,"","", verbose);
@@ -2139,58 +2137,6 @@ 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;
diff --git a/src/daemon/dlt_daemon_common.h b/src/daemon/dlt_daemon_common.h
index 8f5a36f..2798491 100644
--- a/src/daemon/dlt_daemon_common.h
+++ b/src/daemon/dlt_daemon_common.h
@@ -138,11 +138,12 @@ typedef struct
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 */
DltBuffer client_ringbuffer; /**< Ring-buffer for storing received logs while no client connection is available */
- char runtime_application_cfg[PATH_MAX + 1]; /**< Path and filename of persistent application configuration. Set to path max, as it specifies a full path*/
- char runtime_context_cfg[PATH_MAX + 1]; /**< Path and filename of persistent context configuration */
- char runtime_configuration[PATH_MAX + 1]; /**< Path and filename of persistent configuration */
+ char runtime_application_cfg[PATH_MAX + 1]; /**< Path and filename of persistent application configuration. Set to path max, as it specifies a full path*/
+ char runtime_context_cfg[PATH_MAX + 1]; /**< Path and filename of persistent context configuration */
+ char runtime_configuration[PATH_MAX + 1]; /**< Path and filename of persistent configuration */
DltUserLogMode mode; /**< Mode used for tracing: off, external, internal, both */
char state; /**< state for tracing: 0 = no client connected, 1 = client connected */
+ char *ECUVersionString; /**< Version string to send to client. Loaded from a file at startup. May be null. */
} DltDaemon;
/**
@@ -454,15 +455,6 @@ void dlt_daemon_control_reset_to_factory_default(DltDaemon *daemon,const char *f
* @param verbose if set to true verbose information is printed out.
*/
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