summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorS. Hameed <shameed@jp.adit-jv.com>2015-07-28 16:26:00 +0900
committerAlexander Wenzel <Alexander.AW.Wenzel@bmw.de>2015-07-30 10:22:17 +0200
commit81d76cfeaa3588069887a19f9be7d4337c567c65 (patch)
tree4e00527db6efd632fc0559e8bcc505c9bcee1b39 /src
parent4092d77b78cd3b1e6805c4c32d9842de83d23e7f (diff)
downloadDLT-daemon-81d76cfeaa3588069887a19f9be7d4337c567c65.tar.gz
Offline Logstorage [1/4]: DLT preparation to enable offline logstorage
Signed-off-by: S. Hameed <shameed@jp.adit-jv.com>
Diffstat (limited to 'src')
-rwxr-xr-xsrc/daemon/CMakeLists.txt2
-rw-r--r--src/daemon/dlt-daemon.c27
-rwxr-xr-xsrc/daemon/dlt-daemon.h2
-rw-r--r--src/daemon/dlt.conf9
-rw-r--r--src/daemon/dlt_daemon_client.c89
-rw-r--r--src/daemon/dlt_daemon_client.h9
-rw-r--r--src/daemon/dlt_daemon_common.c10
-rw-r--r--src/daemon/dlt_daemon_common.h3
8 files changed, 147 insertions, 4 deletions
diff --git a/src/daemon/CMakeLists.txt b/src/daemon/CMakeLists.txt
index 1955273..a3c7439 100755
--- a/src/daemon/CMakeLists.txt
+++ b/src/daemon/CMakeLists.txt
@@ -20,7 +20,7 @@ if(WITH_SYSTEMD_WATCHDOG OR WITH_SYSTEMD)
message( STATUS "Added ${systemd_SRCS} to dlt-daemon")
endif(WITH_SYSTEMD_WATCHDOG OR WITH_SYSTEMD)
-set(dlt_daemon_SRCS dlt-daemon.c dlt_daemon_common.c dlt_daemon_socket.c dlt_daemon_serial.c dlt_daemon_client.c ${CMAKE_SOURCE_DIR}/src/shared/dlt_user_shared.c ${CMAKE_SOURCE_DIR}/src/shared/dlt_common.c ${CMAKE_SOURCE_DIR}/src/shared/dlt_shm.c ${CMAKE_SOURCE_DIR}/src/shared/dlt_offline_trace.c)
+set(dlt_daemon_SRCS dlt-daemon.c dlt_daemon_common.c dlt_daemon_socket.c dlt_daemon_serial.c dlt_daemon_client.c dlt_daemon_offline_logstorage.c ${CMAKE_SOURCE_DIR}/src/shared/dlt_user_shared.c ${CMAKE_SOURCE_DIR}/src/shared/dlt_common.c ${CMAKE_SOURCE_DIR}/src/shared/dlt_shm.c ${CMAKE_SOURCE_DIR}/src/shared/dlt_offline_trace.c ${CMAKE_SOURCE_DIR}/src/offlinelogstorage/dlt_offline_logstorage.c)
add_executable(dlt-daemon ${dlt_daemon_SRCS} ${systemd_SRCS})
target_link_libraries(dlt-daemon rt ${CMAKE_THREAD_LIBS_INIT})
diff --git a/src/daemon/dlt-daemon.c b/src/daemon/dlt-daemon.c
index 41cc807..0c70cde 100644
--- a/src/daemon/dlt-daemon.c
+++ b/src/daemon/dlt-daemon.c
@@ -195,6 +195,7 @@ int option_file_parser(DltDaemonLocal *daemon_local)
daemon_local->flags.sendECUSoftwareVersion = 0;
memset(daemon_local->flags.pathToECUSoftwareVersion, 0, sizeof(daemon_local->flags.pathToECUSoftwareVersion));
daemon_local->flags.sendTimezone = 0;
+ daemon_local->flags.offlineLogstorageMaxDevices = 0;
/* open configuration file */
if(daemon_local->flags.cvalue[0])
@@ -377,6 +378,10 @@ int option_file_parser(DltDaemonLocal *daemon_local)
daemon_local->flags.sendTimezone = atoi(value);
//printf("Option: %s=%s\n",token,value);
}
+ else if(strcmp(token, "OfflineLogstorageMaxDevices")==0)
+ {
+ daemon_local->flags.offlineLogstorageMaxDevices = atoi(value);
+ }
else
{
fprintf(stderr, "Unknown option: %s=%s\n",token,value);
@@ -736,6 +741,19 @@ int dlt_daemon_local_init_p2(DltDaemon *daemon, DltDaemonLocal *daemon_local, in
}
}
+ /* Init offline logstorage for MAX devices */
+ if(daemon_local->flags.offlineLogstorageMaxDevices > 0)
+ {
+ daemon->storage_handle = malloc(sizeof(DltLogStorage) * daemon_local->flags.offlineLogstorageMaxDevices);
+
+ if(daemon->storage_handle == NULL)
+ {
+ dlt_log(LOG_ERR,"Could not initialize offline logstorage\n");
+ return -1;
+ }
+ memset(daemon->storage_handle, 0, (sizeof(DltLogStorage) * daemon_local->flags.offlineLogstorageMaxDevices));
+ }
+
/* Set ECU id of daemon */
if (daemon_local->flags.evalue[0])
{
@@ -1863,6 +1881,15 @@ int dlt_daemon_process_user_message_register_context(DltDaemon *daemon, DltDaemo
dlt_daemon_log_internal(daemon, daemon_local, str, daemon_local->flags.vflag);
dlt_log(LOG_DEBUG,str);
}
+ if(daemon_local->flags.offlineLogstorageMaxDevices)
+ {
+ /* Store log level set for offline logstorage into context structure*/
+ context->storage_log_level = dlt_daemon_logstorage_get_loglevel(daemon, daemon_local->flags.offlineLogstorageMaxDevices, usercontext->apid, usercontext->ctid);
+ }
+ else
+ {
+ context->storage_log_level = DLT_LOG_DEFAULT;
+ }
/* Create automatic get log info response for registered context */
if (daemon_local->flags.rflag)
{
diff --git a/src/daemon/dlt-daemon.h b/src/daemon/dlt-daemon.h
index 424dec4..fee6767 100755
--- a/src/daemon/dlt-daemon.h
+++ b/src/daemon/dlt-daemon.h
@@ -79,6 +79,7 @@
#include <dlt_offline_trace.h>
#include <sys/time.h>
+#include "dlt_daemon_offline_logstorage.h"
/**
* The flags of a dlt daemon.
@@ -110,6 +111,7 @@ typedef struct
int sendECUSoftwareVersion; /**< (Boolean) Send ECU software version perdiodically */
char pathToECUSoftwareVersion[256]; /**< (String: Filename) The file from which to read the ECU version from. */
int sendTimezone; /**< (Boolean) Send Timezone perdiodically */
+ int offlineLogstorageMaxDevices; /**< (int) Maximum devices to be used as offline logstorage devices */
} DltDaemonFlags;
/**
diff --git a/src/daemon/dlt.conf b/src/daemon/dlt.conf
index d3ba7f3..5976c1f 100644
--- a/src/daemon/dlt.conf
+++ b/src/daemon/dlt.conf
@@ -116,4 +116,11 @@ RingbufferStepSize = 500000
########################################################################
# Send periodic timezone info (Default: 0)
-# SendTimezone = 0 \ No newline at end of file
+# SendTimezone = 0
+
+##############################################################################
+# Offline logstorage #
+##############################################################################
+# Store DLT log messages, if not set offline logstorage is off (Default: off)
+# Maximum devices to be used as offline logstorage devices
+# OfflineLogstorageMaxDevices = 1
diff --git a/src/daemon/dlt_daemon_client.c b/src/daemon/dlt_daemon_client.c
index c28f098..b792e73 100644
--- a/src/daemon/dlt_daemon_client.c
+++ b/src/daemon/dlt_daemon_client.c
@@ -60,6 +60,7 @@
#include "dlt_daemon_client.h"
+#include "dlt_daemon_offline_logstorage.h"
/** Global text output buffer, mainly used for creation of error/warning strings */
static char str[DLT_DAEMON_TEXTBUFSIZE];
@@ -120,6 +121,13 @@ int dlt_daemon_client_send(int sock,DltDaemon *daemon,DltDaemonLocal *daemon_loc
//return DLT_DAEMON_ERROR_WRITE_FAILED;
}
}
+ /* write messages to offline logstorage only if there is an extended header set
+ * this need to be checked because the function is dlt_daemon_client_send is called by
+ * newly introduced dlt_daemon_log_internal */
+ if(daemon_local->flags.offlineLogstorageMaxDevices > 0)
+ {
+ dlt_daemon_logstorage_write(daemon, daemon_local->flags.offlineLogstorageMaxDevices, storage_header, storage_header_size, data1, size1, data2, size2);
+ }
}
/* send messages to daemon socket */
@@ -304,7 +312,7 @@ int dlt_daemon_client_process_control(int sock, DltDaemon *daemon, DltDaemonLoca
id_tmp = *((uint32_t*)(msg->databuffer));
id=DLT_ENDIAN_GET_32(msg->standardheader->htyp ,id_tmp);
- if ((id > 0) && (id < DLT_SERVICE_ID_LAST_ENTRY))
+ if ((id > 0) && ((id < DLT_SERVICE_ID_LAST_ENTRY) || ((id == DLT_SERVICE_ID_OFFLINE_LOGSTORAGE))))
{
/* Control message handling */
switch (id)
@@ -427,6 +435,11 @@ int dlt_daemon_client_process_control(int sock, DltDaemon *daemon, DltDaemonLoca
dlt_daemon_control_message_buffer_overflow(sock, daemon, daemon_local, daemon->overflow_counter,"",verbose);
break;
}
+ case DLT_SERVICE_ID_OFFLINE_LOGSTORAGE:
+ {
+ dlt_daemon_control_service_logstorage(sock, daemon, daemon_local, msg, verbose);
+ break;
+ }
default:
{
dlt_daemon_control_service_response(sock, daemon, daemon_local, id, DLT_SERVICE_RESPONSE_NOT_SUPPORTED, verbose);
@@ -1627,3 +1640,77 @@ void dlt_daemon_control_message_time(int sock, DltDaemon *daemon, DltDaemonLocal
}
+void dlt_daemon_control_service_logstorage(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, DltMessage *msg, int verbose)
+{
+ DltServiceOfflineLogstorage *req;
+ int ret;
+
+ PRINT_FUNCTION_VERBOSE(verbose);
+
+ if ((daemon==0) ||(msg == 0) ||(daemon_local == 0))
+ {
+ dlt_log(LOG_ERR, "Invalid function parameters used for dlt_daemon_control_service_logstorage\n");
+ return ;
+ }
+
+ if(daemon_local->flags.offlineLogstorageMaxDevices <= 0)
+ {
+ dlt_daemon_control_service_response(sock, daemon, daemon_local, DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, DLT_SERVICE_RESPONSE_ERROR, verbose);
+ dlt_log(LOG_INFO, "Offline logstorage functionality not enabled or MAX device set is 0\n");
+ return;
+ }
+
+ req = (DltServiceOfflineLogstorage*) (msg->databuffer);
+
+ /* Check for device connection request from log storage ctrl app */
+ if (req->connection_type == DLT_OFFLINE_LOGSTORAGE_DEVICE_CONNECTED)
+ {
+ if(req->dev_num > daemon_local->flags.offlineLogstorageMaxDevices)
+ {
+ dlt_daemon_control_service_response(sock, daemon, daemon_local, DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, DLT_SERVICE_RESPONSE_ERROR, verbose);
+ dlt_log(LOG_INFO, "Device number received is greater than MAX device configured \n");
+ return;
+ }
+ /* Adding +1 to device number as ctrl app sends device number 1 less (to support indexing of storage_handle */
+ ret = dlt_logstorage_device_connected(&(daemon->storage_handle[req->dev_num]), req->dev_num+1);
+ if(ret != 0)
+ {
+ dlt_daemon_control_service_response(sock, daemon, daemon_local, DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, DLT_SERVICE_RESPONSE_ERROR, verbose);
+ return;
+ }
+
+ /* Setup logstorage with config file settings */
+ ret = dlt_logstorage_load_config(&(daemon->storage_handle[req->dev_num]));
+ if(ret != 0)
+ {
+ dlt_daemon_control_service_response(sock, daemon, daemon_local, DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, DLT_SERVICE_RESPONSE_ERROR, verbose);
+ return;
+ }
+
+ dlt_daemon_control_service_response(sock, daemon, daemon_local, DLT_SERVICE_ID_OFFLINE_LOGSTORAGE,DLT_SERVICE_RESPONSE_OK, verbose);
+
+ /* Check if log level of running application needs an update */
+ dlt_daemon_logstorage_update_application_loglevel(daemon, req->dev_num, verbose);
+
+ }
+ /* Check for device disconnection request from log storage ctrl app */
+ else if(req->connection_type == DLT_OFFLINE_LOGSTORAGE_DEVICE_DISCONNECTED)
+ {
+ if(req->dev_num > daemon_local->flags.offlineLogstorageMaxDevices)
+ {
+ dlt_log(LOG_INFO, "Device number received is greater than MAX device configured \n");
+ return;
+ }
+
+ /* Check if log level of running application needs to be reset */
+ dlt_daemon_logstorage_reset_application_loglevel(daemon, req->dev_num, daemon_local->flags.offlineLogstorageMaxDevices, verbose);
+
+ dlt_logstorage_device_disconnected(&(daemon->storage_handle[req->dev_num]));
+
+ dlt_daemon_control_service_response(sock, daemon, daemon_local, DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, DLT_SERVICE_RESPONSE_OK, verbose);
+ }
+ else
+ {
+ dlt_daemon_control_service_response(sock, daemon, daemon_local, DLT_SERVICE_ID_OFFLINE_LOGSTORAGE, DLT_SERVICE_RESPONSE_ERROR, verbose);
+ }
+}
diff --git a/src/daemon/dlt_daemon_client.h b/src/daemon/dlt_daemon_client.h
index 0eae719..c7ec9e9 100644
--- a/src/daemon/dlt_daemon_client.h
+++ b/src/daemon/dlt_daemon_client.h
@@ -246,5 +246,14 @@ void dlt_daemon_control_set_timing_packets(int sock, DltDaemon *daemon, DltDaemo
* @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);
+/**
+ * Service offline logstorage command request
+ * @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.
+ */
+void dlt_daemon_control_service_logstorage(int sock, DltDaemon *daemon, DltDaemonLocal *daemon_local, DltMessage *msg, int verbose);
#endif /* DLT_DAEMON_CLIENT_H */
diff --git a/src/daemon/dlt_daemon_common.c b/src/daemon/dlt_daemon_common.c
index ad1256e..2064e94 100644
--- a/src/daemon/dlt_daemon_common.c
+++ b/src/daemon/dlt_daemon_common.c
@@ -217,6 +217,7 @@ int dlt_daemon_init(DltDaemon *daemon,unsigned long RingbufferMinSize,unsigned l
return -1;
}
+ daemon->storage_handle = NULL;
return 0;
}
@@ -1131,8 +1132,15 @@ int dlt_daemon_user_send_log_level(DltDaemon *daemon,DltDaemonContext *context,i
{
return -1;
}
+ if(context->storage_log_level != DLT_LOG_DEFAULT)
+ {
+ usercontext.log_level = context->log_level > context->storage_log_level ? context->log_level:context->storage_log_level;
+ }
+ else /* Storage log level is not updated (is DEFAULT) then no device is yet connected so ignore */
+ {
+ usercontext.log_level = ((context->log_level == DLT_LOG_DEFAULT)?daemon->default_log_level:context->log_level);
+ }
- usercontext.log_level = ((context->log_level == DLT_LOG_DEFAULT)?daemon->default_log_level:context->log_level);
usercontext.trace_status = ((context->trace_status == DLT_TRACE_STATUS_DEFAULT)?daemon->default_trace_status:context->trace_status);
usercontext.log_level_pos = context->log_level_pos;
diff --git a/src/daemon/dlt_daemon_common.h b/src/daemon/dlt_daemon_common.h
index 9a5e6c1..1ad1ce6 100644
--- a/src/daemon/dlt_daemon_common.h
+++ b/src/daemon/dlt_daemon_common.h
@@ -81,6 +81,7 @@
#include <semaphore.h>
#include "dlt_common.h"
#include "dlt_user.h"
+#include "dlt_offline_logstorage.h"
#ifdef __cplusplus
extern "C" {
@@ -135,6 +136,7 @@ typedef struct
int log_level_pos; /**< offset of context in context field on user application */
int user_handle; /**< connection handle for connection to user application */
char *context_description; /**< context description */
+ int8_t storage_log_level; /**< log level set for offline logstorage */
} DltDaemonContext;
/**
@@ -161,6 +163,7 @@ typedef struct
char connectionState; /**< 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. */
DltDaemonState state; /**< the current logging state of dlt daemon. */
+ DltLogStorage *storage_handle;
} DltDaemon;
/**