automotive-dlt
dlt_user.h
Go to the documentation of this file.
1 /*
2  * @licence app begin@
3  * SPDX license identifier: MPL-2.0
4  *
5  * Copyright (C) 2011-2015, BMW AG
6  *
7  * This file is part of GENIVI Project DLT - Diagnostic Log and Trace.
8  *
9  * This Source Code Form is subject to the terms of the
10  * Mozilla Public License (MPL), v. 2.0.
11  * If a copy of the MPL was not distributed with this file,
12  * You can obtain one at http://mozilla.org/MPL/2.0/.
13  *
14  * For further information see http://www.genivi.org/.
15  * @licence end@
16  */
17 
27 /*******************************************************************************
28 ** **
29 ** SRC-MODULE: dlt_user.h **
30 ** **
31 ** TARGET : linux **
32 ** **
33 ** PROJECT : DLT **
34 ** **
35 ** AUTHOR : Alexander Wenzel Alexander.AW.Wenzel@bmw.de **
36 ** Markus Klein **
37 ** **
38 ** PURPOSE : **
39 ** **
40 ** REMARKS : **
41 ** **
42 ** PLATFORM DEPENDANT [yes/no]: yes **
43 ** **
44 ** TO BE CHANGED BY USER [yes/no]: no **
45 ** **
46 *******************************************************************************/
47 
48 /*******************************************************************************
49 ** Author Identity **
50 ********************************************************************************
51 ** **
52 ** Initials Name Company **
53 ** -------- ------------------------- ---------------------------------- **
54 ** aw Alexander Wenzel BMW **
55 ** mk Markus Klein Fraunhofer ESK **
56 *******************************************************************************/
57 
58 /*******************************************************************************
59 ** Revision Control History **
60 *******************************************************************************/
61 
62 /*
63  * $LastChangedRevision: 1670 $
64  * $LastChangedDate: 2011-04-08 15:12:06 +0200 (Fr, 08. Apr 2011) $
65  * $LastChangedBy$
66  Initials Date Comment
67  aw 13.01.2010 initial
68  */
69 
70 #ifndef DLT_USER_H
71 #define DLT_USER_H
72 
78 #include <mqueue.h>
79 
80 #if !defined (__WIN32__)
81 #include <semaphore.h>
82 #endif
83 
84 #include "dlt_types.h"
85 #include "dlt_user_macros.h"
86 #include "dlt_shm.h"
87 
88 #ifdef __cplusplus
89 extern "C" {
90 #endif
91 
92 #define DLT_USER_BUF_MAX_SIZE 1390
94 #define DLT_USER_RESENDBUF_MAX_SIZE (DLT_USER_BUF_MAX_SIZE + 100)
96 /* Use a semaphore or mutex from your OS to prevent concurrent access to the DLT buffer. */
97 #define DLT_SEM_LOCK() { sem_wait(&dlt_mutex); }
98 #define DLT_SEM_FREE() { sem_post(&dlt_mutex); }
99 
103 typedef struct
104 {
105  char contextID[DLT_ID_SIZE];
106  int32_t log_level_pos;
107  int8_t *log_level_ptr;
109  uint8_t mcnt;
110 } DltContext;
111 
115 typedef struct
116 {
118  unsigned char buffer[DLT_USER_BUF_MAX_SIZE];
119  int32_t size;
120  int32_t log_level;
121  int32_t trace_status;
122  int32_t args_num;
125 
126 typedef struct
127 {
128  uint32_t service_id;
129  int (*injection_callback)(uint32_t service_id, void *data, uint32_t length);
131 
132 typedef struct
133 {
134  char contextID[DLT_ID_SIZE];
135  int8_t log_level;
136  int8_t trace_status;
137  void (*log_level_changed_callback) (char context_id[DLT_ID_SIZE],uint8_t log_level,uint8_t trace_status);
139 
143 typedef struct
144 {
145  char contextID[DLT_ID_SIZE];
146  int8_t log_level;
147  int8_t *log_level_ptr;
148  int8_t trace_status;
152  uint32_t nrcallbacks;
153 
154  /* Log Level changed callback */
155  void (*log_level_changed_callback) (char context_id[DLT_ID_SIZE],uint8_t log_level,uint8_t trace_status);
156 
158 
162 typedef struct
163 {
164  char appId[DLT_ID_SIZE];
165  char ctxId[DLT_ID_SIZE];
166  int8_t ll;
168 
169 
173 typedef struct
174 {
176  size_t array_size;
177  size_t num_elem;
179 
180 
184 typedef struct
185 {
186  char ecuID[DLT_ID_SIZE];
187  char appID[DLT_ID_SIZE];
194  int8_t dlt_is_file;
202  int8_t overflow;
203  uint32_t overflow_counter;
209  int8_t verbose_mode;
212  int8_t with_timestamp;
213  int8_t with_ecu_id;
218  int8_t log_state;
224  /* Buffer used for resending, locked by DLT semaphore */
225  uint8_t resend_buffer[DLT_USER_RESENDBUF_MAX_SIZE];
226 
229 
230 #ifdef DLT_SHM_ENABLE
231  DltShm dlt_shm;
232 #endif
233 #ifdef DLT_TEST_ENABLE
234  int corrupt_user_header;
235  int corrupt_message_size;
236  int16_t corrupt_message_size_size;
237 #endif
238 } DltUser;
239 
240 /**************************************************************************************************
241 * The following API functions define a low level function interface for DLT
242 **************************************************************************************************/
243 
255 
267 DltReturnValue dlt_user_log_write_start_id(DltContext *handle, DltContextData *log, DltLogLevelType loglevel, uint32_t messageid);
268 
276 
286 
296 
306 
320 
334 
344 
367 
378 
388 
398 DltReturnValue dlt_user_log_write_raw(DltContextData *log,void *data,uint16_t length);
399 
411 
422 DltReturnValue dlt_user_trace_network(DltContext *handle, DltNetworkTraceType nw_trace_type, uint16_t header_len, void *header, uint16_t payload_len, void *payload);
423 
435 DltReturnValue dlt_user_trace_network_truncated(DltContext *handle, DltNetworkTraceType nw_trace_type, uint16_t header_len, void *header, uint16_t payload_len, void *payload, int allow_truncate);
436 
450 DltReturnValue dlt_user_trace_network_segmented(DltContext *handle, DltNetworkTraceType nw_trace_type, uint16_t header_len, void *header, uint16_t payload_len, void *payload);
451 
452 /**************************************************************************************************
453  * The following API functions define a high level function interface for DLT
454  **************************************************************************************************/
455 
462 
469 DltReturnValue dlt_init_file(const char *name);
470 
477 
484 DltReturnValue dlt_check_library_version(const char * user_major_version, const char * user_minor_version);
485 
492 DltReturnValue dlt_register_app(const char *appid, const char * description);
493 
500 
509 DltReturnValue dlt_register_context(DltContext *handle, const char *contextid, const char * description);
510 
523 DltReturnValue dlt_register_context_ll_ts(DltContext *handle, const char *contextid, const char * description, int loglevel, int tracestatus);
524 
532 
533 
538 int dlt_set_resend_timeout_atexit(uint32_t timeout_in_milliseconds);
539 
548 
557 int dlt_get_log_state();
558 
567  int (*dlt_injection_callback)(uint32_t service_id, void *data, uint32_t length));
568 
576  void (*dlt_log_level_changed_callback)(char context_id[DLT_ID_SIZE],uint8_t log_level, uint8_t trace_status));
577 
583 
590 DltReturnValue dlt_user_check_library_version(const char *user_major_version,const char *user_minor_version);
591 
597 
604 DltReturnValue dlt_use_extended_header_for_non_verbose(int8_t use_extende_header_for_non_verbose);
605 
612 DltReturnValue dlt_with_session_id(int8_t with_session_id);
613 
620 DltReturnValue dlt_with_timestamp(int8_t with_timestamp);
621 
628 DltReturnValue dlt_with_ecu_id(int8_t with_ecu_id);
629 
638 
639 
655 int dlt_env_adjust_ll_from_env(dlt_env_ll_set const * const ll_set, char const * const apid, char const * const ctid, int const ll);
656 
669 int dlt_env_extract_ll_set(char ** const env, dlt_env_ll_set * const ll_set);
670 
671 void dlt_env_free_ll_set(dlt_env_ll_set * const ll_set);
672 
678 
684 
692 DltReturnValue dlt_log_string(DltContext *handle,DltLogLevelType loglevel, const char *text);
693 
702 DltReturnValue dlt_log_string_int(DltContext *handle,DltLogLevelType loglevel, const char *text, int data);
703 
712 DltReturnValue dlt_log_string_uint(DltContext *handle,DltLogLevelType loglevel, const char *text, unsigned int data);
713 
722 
730 DltReturnValue dlt_log_uint(DltContext *handle,DltLogLevelType loglevel, unsigned int data);
731 
740 DltReturnValue dlt_log_raw(DltContext *handle,DltLogLevelType loglevel, void *data,uint16_t length);
741 
747 
754 DltReturnValue dlt_forward_msg(void *msgdata,size_t size);
755 
764 DltReturnValue dlt_user_check_buffer(int *total_size, int *used_size);
765 
773 
779 
789 {
790  if (handle == NULL || handle->log_level_ptr == NULL)
791  {
793  }
794 
795  if (loglevel <= (DltLogLevelType)(*(handle->log_level_ptr)) && loglevel != DLT_LOG_OFF)
796  {
797  return DLT_RETURN_TRUE;
798  }
799 
801 }
802 
803 #ifdef DLT_TEST_ENABLE
804  void dlt_user_test_corrupt_user_header(int enable);
805  void dlt_user_test_corrupt_message_size(int enable,int16_t size);
806 #endif /* DLT_TEST_ENABLE */
807 
808 #ifdef __cplusplus
809 }
810 #endif
811 
816 #endif /* DLT_USER_H */
int dlt_set_resend_timeout_atexit(uint32_t timeout_in_milliseconds)
Definition: dlt_user.c:1301
DltReturnValue dlt_user_log_write_float32(DltContextData *log, float32_t data)
Definition: dlt_user.c:1559
int8_t trace_status
Definition: dlt_user.h:148
DltNetworkTraceType
Definition: dlt_types.h:145
DltReturnValue dlt_user_log_write_int16(DltContextData *log, int16_t data)
Definition: dlt_user.c:2140
DltReturnValue dlt_user_log_write_string(DltContextData *log, const char *text)
Definition: dlt_user.c:2280
DltLogLevelType
Definition: dlt_types.h:102
int dlt_user_atexit_blow_out_user_buffer(void)
Definition: dlt_user.c:621
dlt_ll_ts_type * dlt_ll_ts
Definition: dlt_user.h:196
DltReturnValue dlt_verbose_mode(void)
Definition: dlt_user.c:3178
#define DLT_ID_SIZE
Definition: dlt_common.h:204
DltReturnValue
Definition: dlt_types.h:86
DltReturnValue dlt_user_log_write_int(DltContextData *log, int data)
Definition: dlt_user.c:2062
mqd_t dlt_segmented_queue_read_handle
Definition: dlt_user.h:190
DltReturnValue dlt_unregister_app(void)
Definition: dlt_user.c:1118
pthread_t dlt_segmented_nwt_handle
Definition: dlt_user.h:192
DltReturnValue dlt_register_context_ll_ts(DltContext *handle, const char *contextid, const char *description, int loglevel, int tracestatus)
Definition: dlt_user.c:911
DltContext * handle
Definition: dlt_user.h:117
DltReturnValue dlt_free()
Definition: dlt_user.c:676
DltTraceStatusType
Definition: dlt_types.h:133
DltUserLogMode
Definition: dlt_types.h:168
DltReturnValue dlt_register_app(const char *appid, const char *description)
Definition: dlt_user.c:800
Definition: dlt_shm.h:78
int dlt_user_handle
Definition: dlt_user.h:189
DltReturnValue dlt_register_context(DltContext *handle, const char *contextid, const char *description)
Definition: dlt_user.c:883
DltReturnValue dlt_user_log_write_uint64_formatted(DltContextData *log, uint64_t data, DltFormatType type)
Definition: dlt_user.c:1978
DltReturnValue dlt_use_extended_header_for_non_verbose(int8_t use_extende_header_for_non_verbose)
Definition: dlt_user.c:3212
DltReturnValue dlt_user_log_write_int32(DltContextData *log, int32_t data)
Definition: dlt_user.c:2175
int8_t with_timestamp
Definition: dlt_user.h:212
DltReturnValue dlt_with_session_id(int8_t with_session_id)
Definition: dlt_user.c:3229
int dlt_env_adjust_ll_from_env(dlt_env_ll_set const *const ll_set, char const *const apid, char const *const ctid, int const ll)
adjust log-level based on values given through environment
Definition: dlt_env_ll.c:537
DltReturnValue dlt_user_log_write_uint16_formatted(DltContextData *log, uint16_t data, DltFormatType type)
Definition: dlt_user.c:1874
DltReturnValue dlt_init_file(const char *name)
Definition: dlt_user.c:350
int8_t overflow
Definition: dlt_user.h:202
uint32_t dlt_ll_ts_max_num_entries
Definition: dlt_user.h:198
mqd_t dlt_segmented_queue_write_handle
Definition: dlt_user.h:191
DltReturnValue dlt_enable_local_print(void)
Definition: dlt_user.c:3280
char * context_description
Definition: dlt_user.h:150
DltReturnValue dlt_register_log_level_changed_callback(DltContext *handle, void(*dlt_log_level_changed_callback)(char context_id[DLT_ID_SIZE], uint8_t log_level, uint8_t trace_status))
Definition: dlt_user.c:2463
int32_t trace_status
Definition: dlt_user.h:121
uint32_t overflow_counter
Definition: dlt_user.h:203
int32_t log_level
Definition: dlt_user.h:120
int dlt_env_extract_ll_set(char **const env, dlt_env_ll_set *const ll_set)
extract log-level settings from given string
Definition: dlt_env_ll.c:408
char * application_description
Definition: dlt_user.h:205
int dlt_get_log_state()
Definition: dlt_user.c:1276
dlt_env_ll_set initial_ll_set
Definition: dlt_user.h:228
uint32_t timeout_at_exit_handler
Definition: dlt_user.h:227
static char * service_id[]
Definition: dlt_common.c:85
DltReturnValue dlt_check_library_version(const char *user_major_version, const char *user_minor_version)
Definition: dlt_user.c:795
DltFormatType
Definition: dlt_types.h:118
DltReturnValue dlt_log_uint(DltContext *handle, DltLogLevelType loglevel, unsigned int data)
Definition: dlt_user.c:3092
static char data[kDataSize]
Definition: city-test.cc:40
DltReturnValue dlt_user_log_write_raw_formatted(DltContextData *log, void *data, uint16_t length, DltFormatType type)
Definition: dlt_user.c:1495
int8_t log_state
Definition: dlt_user.h:218
char * nw_trace_type[]
Definition: dlt_common.c:83
int8_t log_level
Definition: dlt_user.h:146
int8_t enable_local_print
Definition: dlt_user.h:215
DltReturnValue dlt_user_log_write_ptr(DltContextData *log, void *data)
Definition: dlt_user.c:2030
DltReturnValue dlt_user_log_write_utf8_string(DltContextData *log, const char *text)
Definition: dlt_user.c:2332
DltReturnValue dlt_user_check_buffer(int *total_size, int *used_size)
Definition: dlt_user.c:4512
DltReturnValue dlt_user_log_write_int64(DltContextData *log, int64_t data)
Definition: dlt_user.c:2210
int8_t * log_level_ptr
Definition: dlt_user.h:147
unsigned char buffer[BUFFER_SIZE]
Buffer for dlt file transfer. The size is defined by BUFFER_SIZE.
DltReturnValue dlt_init()
Definition: dlt_user.c:188
DltReturnValue dlt_user_log_write_uint8(DltContextData *log, uint8_t data)
Definition: dlt_user.c:1682
int8_t dlt_is_file
Definition: dlt_user.h:194
int8_t local_print_mode
Definition: dlt_user.h:216
DltReturnValue dlt_log_int(DltContext *handle, DltLogLevelType loglevel, int data)
Definition: dlt_user.c:3056
DltReturnValue dlt_user_log_write_uint32_formatted(DltContextData *log, uint32_t data, DltFormatType type)
Definition: dlt_user.c:1926
DltReturnValue dlt_disable_local_print(void)
Definition: dlt_user.c:3296
DltReturnValue dlt_user_log_write_uint(DltContextData *log, unsigned int data)
Definition: dlt_user.c:1639
dlt_env_ll_item * item
Definition: dlt_user.h:175
DltReturnValue dlt_user_log_write_uint32(DltContextData *log, uint32_t data)
Definition: dlt_user.c:1752
DltReturnValue dlt_user_trace_network_segmented(DltContext *handle, DltNetworkTraceType nw_trace_type, uint16_t header_len, void *header, uint16_t payload_len, void *payload)
Definition: dlt_user.c:2770
int8_t with_session_id
Definition: dlt_user.h:211
int8_t use_extende_header_for_non_verbose
Definition: dlt_user.h:210
DltReturnValue dlt_user_log_write_start_id(DltContext *handle, DltContextData *log, DltLogLevelType loglevel, uint32_t messageid)
Definition: dlt_user.c:1433
DltReturnValue dlt_user_check_library_version(const char *user_major_version, const char *user_minor_version)
Definition: dlt_user.c:165
uint32_t nrcallbacks
Definition: dlt_user.h:152
DltReturnValue dlt_user_trace_network_truncated(DltContext *handle, DltNetworkTraceType nw_trace_type, uint16_t header_len, void *header, uint16_t payload_len, void *payload, int allow_truncate)
Definition: dlt_user.c:2855
DltReturnValue dlt_log_string(DltContext *handle, DltLogLevelType loglevel, const char *text)
Definition: dlt_user.c:2940
DltReturnValue dlt_with_timestamp(int8_t with_timestamp)
Definition: dlt_user.c:3246
DltReturnValue dlt_set_application_ll_ts_limit(DltLogLevelType loglevel, DltTraceStatusType tracestatus)
Definition: dlt_user.c:1208
int32_t size
Definition: dlt_user.h:119
#define DLT_USER_RESENDBUF_MAX_SIZE
Definition: dlt_user.h:94
DltReturnValue dlt_log_string_int(DltContext *handle, DltLogLevelType loglevel, const char *text, int data)
Definition: dlt_user.c:2976
int8_t with_ecu_id
Definition: dlt_user.h:213
size_t array_size
Definition: dlt_user.h:176
int8_t * log_level_ptr
Definition: dlt_user.h:107
void dlt_env_free_ll_set(dlt_env_ll_set *const ll_set)
release ll_set
Definition: dlt_env_ll.c:350
DltReturnValue dlt_user_log_write_int8(DltContextData *log, int8_t data)
Definition: dlt_user.c:2105
DltReturnValue dlt_log_marker()
Definition: dlt_user.c:3164
static DltReturnValue dlt_user_is_logLevel_enabled(DltContext *handle, DltLogLevelType loglevel)
Definition: dlt_user.h:788
#define DLT_USER_BUF_MAX_SIZE
Definition: dlt_user.h:92
DltReturnValue dlt_user_log_write_uint8_formatted(DltContextData *log, uint8_t data, DltFormatType type)
Definition: dlt_user.c:1822
holds all initial log-levels given via environment variable DLT_INITIAL_LOG_LEVEL ...
Definition: dlt_user.h:173
DltReturnValue dlt_log_string_uint(DltContext *handle, DltLogLevelType loglevel, const char *text, unsigned int data)
Definition: dlt_user.c:3016
DltReturnValue dlt_register_injection_callback(DltContext *handle, uint32_t service_id, int(*dlt_injection_callback)(uint32_t service_id, void *data, uint32_t length))
Definition: dlt_user.c:2377
int8_t * trace_status_ptr
Definition: dlt_user.h:149
DltReceiver receiver
Definition: dlt_user.h:207
uint8_t mcnt
Definition: dlt_user.h:109
size_t num_elem
Definition: dlt_user.h:177
DltReturnValue dlt_set_log_mode(DltUserLogMode mode)
Definition: dlt_user.c:1281
DltReturnValue dlt_user_log_write_uint64(DltContextData *log, uint64_t data)
Definition: dlt_user.c:1787
DltReturnValue dlt_user_log_write_uint16(DltContextData *log, uint16_t data)
Definition: dlt_user.c:1717
DltReturnValue dlt_nonverbose_mode(void)
Definition: dlt_user.c:3195
char * context_description
Definition: dlt_user.h:123
holds initial log-level for given appId:ctxId pair
Definition: dlt_user.h:162
uint32_t dlt_ll_ts_num_entries
Definition: dlt_user.h:200
DltReturnValue dlt_user_log_write_constant_string(DltContextData *log, const char *text)
Definition: dlt_user.c:2326
int32_t log_level_pos
Definition: dlt_user.h:106
DltReturnValue dlt_user_trace_network(DltContext *handle, DltNetworkTraceType nw_trace_type, uint16_t header_len, void *header, uint16_t payload_len, void *payload)
Definition: dlt_user.c:2850
DltReturnValue dlt_unregister_context(DltContext *handle)
Definition: dlt_user.c:1148
int8_t verbose_mode
Definition: dlt_user.h:209
DltReturnValue dlt_log_raw(DltContext *handle, DltLogLevelType loglevel, void *data, uint16_t length)
Definition: dlt_user.c:3128
DltUserInjectionCallback * injection_table
Definition: dlt_user.h:151
DltReturnValue dlt_user_log_write_bool(DltContextData *log, uint8_t data)
Definition: dlt_user.c:2245
DltReturnValue dlt_user_log_write_raw(DltContextData *log, void *data, uint16_t length)
Definition: dlt_user.c:1490
DltReturnValue dlt_user_log_write_finish(DltContextData *log)
Definition: dlt_user.c:1482
DltReturnValue dlt_user_log_write_float64(DltContextData *log, double data)
Definition: dlt_user.c:1599
float float32_t
Definition: dlt_types.h:178
int dlt_log_handle
Definition: dlt_user.h:188
DltReturnValue dlt_user_log_resend_buffer(void)
Definition: dlt_user.c:4321
#define NULL
Definition: dlt_common.h:232
DltReturnValue dlt_with_ecu_id(int8_t with_ecu_id)
Definition: dlt_user.c:3263
DltReturnValue dlt_user_log_write_start(DltContext *handle, DltContextData *log, DltLogLevelType loglevel)
Definition: dlt_user.c:1428
int8_t * trace_status_ptr
Definition: dlt_user.h:108
DltReturnValue dlt_forward_msg(void *msgdata, size_t size)
Definition: dlt_user.c:1315
int32_t args_num
Definition: dlt_user.h:122
DltBuffer startup_buffer
Definition: dlt_user.h:223