2 * Dlt- Diagnostic Log and Trace console apps
5 * Copyright (C) 2011, BMW AG - Alexander Wenzel <alexander.wenzel@bmw.de>
7 * This program is free software; you can redistribute it and/or modify it under the terms of the
8 * GNU Lesser General Public License, version 2.1, as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
10 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
11 * Public License, version 2.1, for more details.
13 * You should have received a copy of the GNU Lesser General Public License, version 2.1, along
14 * with this program; if not, see <http://www.gnu.org/licenses/lgpl-2.1.html>.
16 * Note that the copyright holders assume that the GNU Lesser General Public License, version 2.1, may
17 * also be applicable to programs even in cases in which the program is not a library in the technical sense.
19 * Linking DLT statically or dynamically with other modules is making a combined work based on DLT. You may
20 * license such other modules under the GNU Lesser General Public License, version 2.1. If you do not want to
21 * license your linked modules under the GNU Lesser General Public License, version 2.1, you
22 * may use the program under the following exception.
24 * As a special exception, the copyright holders of DLT give you permission to combine DLT
25 * with software programs or libraries that are released under any license unless such a combination is not
26 * permitted by the license of such a software program or library. You may copy and distribute such a
27 * system following the terms of the GNU Lesser General Public License, version 2.1, including this
28 * special exception, for DLT and the licenses of the other code concerned.
30 * Note that people who make modified versions of DLT are not obligated to grant this special exception
31 * for their modified versions; it is their choice whether to do so. The GNU Lesser General Public License,
32 * version 2.1, gives permission to release a modified version without this exception; this exception
33 * also makes it possible to release a modified version which carries forward this exception.
39 /*******************************************************************************
41 ** SRC-MODULE: dlt_user.h **
47 ** AUTHOR : Alexander Wenzel Alexander.AW.Wenzel@bmw.de **
54 ** PLATFORM DEPENDANT [yes/no]: yes **
56 ** TO BE CHANGED BY USER [yes/no]: no **
58 *******************************************************************************/
60 /*******************************************************************************
62 ********************************************************************************
64 ** Initials Name Company **
65 ** -------- ------------------------- ---------------------------------- **
66 ** aw Alexander Wenzel BMW **
67 ** mk Markus Klein Fraunhofer ESK **
68 *******************************************************************************/
70 /*******************************************************************************
71 ** Revision Control History **
72 *******************************************************************************/
75 * $LastChangedRevision: 1670 $
76 * $LastChangedDate: 2011-04-08 15:12:06 +0200 (Fr, 08. Apr 2011) $
86 \defgroup userapi DLT User API
91 #include "dlt_types.h"
92 #include "dlt_common.h"
93 #include "dlt_user_macros.h"
95 #if !defined (__WIN32__)
96 #include <semaphore.h>
104 * Definitions of DLT log level
108 DLT_LOG_DEFAULT = -1, /**< Default log level */
109 DLT_LOG_OFF = 0x00, /**< Log level off */
110 DLT_LOG_FATAL = 0x01, /**< fatal system error */
111 DLT_LOG_ERROR = 0x02, /**< error with impact to correct functionality */
112 DLT_LOG_WARN = 0x03, /**< warning, correct behaviour could not be ensured */
113 DLT_LOG_INFO = 0x04, /**< informational */
114 DLT_LOG_DEBUG = 0x05, /**< debug */
115 DLT_LOG_VERBOSE = 0x06 /**< highest grade of information */
119 * Definitions of DLT trace status
123 DLT_TRACE_STATUS_DEFAULT = -1, /**< Default trace status */
124 DLT_TRACE_STATUS_OFF = 0x00, /**< Trace status: Off */
125 DLT_TRACE_STATUS_ON = 0x01 /**< Trace status: On */
126 } DltTraceStatusType;
129 * Definitions for dlt_user_trace_network/DLT_TRACE_NETWORK()
130 * as defined in the DLT protocol
134 DLT_NW_TRACE_IPC = 0x01, /**< Interprocess communication */
135 DLT_NW_TRACE_CAN = 0x02, /**< Controller Area Network Bus */
136 DLT_NW_TRACE_FLEXRAY = 0x03, /**< Flexray Bus */
137 DLT_NW_TRACE_MOST = 0x04, /**< Media Oriented System Transport Bus */
138 DLT_NW_TRACE_RESERVED0 = 0x05,
139 DLT_NW_TRACE_RESERVED1 = 0x06,
140 DLT_NW_TRACE_RESERVED2 = 0x07,
141 DLT_NW_TRACE_USER_DEFINED0 = 0x08,
142 DLT_NW_TRACE_USER_DEFINED1 = 0x09,
143 DLT_NW_TRACE_USER_DEFINED2 = 0x0A,
144 DLT_NW_TRACE_USER_DEFINED3 = 0x0B,
145 DLT_NW_TRACE_USER_DEFINED4 = 0x0C,
146 DLT_NW_TRACE_USER_DEFINED5 = 0x0D,
147 DLT_NW_TRACE_USER_DEFINED6 = 0x0E,
148 DLT_NW_TRACE_USER_DEFINED7 = 0x0F
149 } DltNetworkTraceType;
151 #define DLT_USER_BUF_MAX_SIZE 2048 /**< maximum size of each user buffer, also used for injection buffer */
153 /* Use a semaphore or mutex from your OS to prevent concurrent access to the DLT buffer. */
154 #define DLT_SEM_LOCK() { sem_wait(&dlt_mutex); }
155 #define DLT_SEM_FREE() { sem_post(&dlt_mutex); }
158 * This structure is used for every context used in an application.
162 char contextID[4]; /**< context id */
163 int32_t log_level_pos; /**< offset in user-application context field */
167 * This structure is used for context data used in an application.
171 DltContext *handle; /**< pointer to DltContext */
172 unsigned char buffer[DLT_USER_BUF_MAX_SIZE]; /**< buffer for building log message*/
173 int32_t size; /**< payload size */
174 int32_t log_level; /**< log level */
175 int32_t trace_status; /**< trace status */
176 int32_t args_num; /**< number of arguments for extended header*/
177 uint8_t mcnt; /**< message counter */
178 char* context_description; /**< description of context */
184 int (*injection_callback)(uint32_t service_id, void *data, uint32_t length);
185 } DltUserInjectionCallback;
188 * This structure is used in a table managing all contexts and the corresponding log levels in an application.
192 char contextID[DLT_ID_SIZE]; /**< Context ID */
193 int8_t log_level; /**< Log level */
194 int8_t trace_status; /**< Trace status */
195 char *context_description; /**< description of context */
196 DltUserInjectionCallback *injection_table; /**< Table with pointer to injection functions and service ids */
197 uint32_t nrcallbacks;
201 * This structure is used once for one application.
205 char ecuID[DLT_ID_SIZE]; /**< ECU ID */
206 char appID[DLT_ID_SIZE]; /**< Application ID */
207 int dlt_log_handle; /**< Handle to fifo of dlt daemon */
208 int dlt_user_handle; /**< Handle to own fifo */
210 int8_t dlt_is_file; /**< Target of logging: 1 to file, 0 to daemon */
212 dlt_ll_ts_type *dlt_ll_ts; //[MAX_DLT_LL_TS_ENTRIES]; /**< Internal management struct for all contexts */
213 uint32_t dlt_ll_ts_max_num_entries; /**< Maximum number of contexts */
215 uint32_t dlt_ll_ts_num_entries; /**< Number of used contexts */
217 int8_t overflow; /**< Overflow marker, set to 1 on overflow, 0 otherwise */
219 char *application_description; /**< description of application */
221 DltReceiver receiver; /**< Receiver for internal user-defined messages from daemon */
223 int8_t verbose_mode; /**< Verbose mode enabled: 1 enabled, 0 disabled */
225 int8_t enable_local_print; /**< Local printing of log messages: 1 enabled, 0 disabled */
226 int8_t local_print_mode; /**< Local print mode, controlled by environment variable */
228 DltRingBuffer rbuf; /**< Ring-buffer for buffering messages during startup and missing connection */
231 /**************************************************************************************************
232 * The folowing API functions define a low level function interface for DLT
233 **************************************************************************************************/
236 * Initialise the generation of a DLT log message (intended for usage in non-verbose mode)
237 * This function has to be called first, when an application wants to send a new log messages.
238 * @param handle pointer to an object containing information about one special logging context
239 * @param log pointer to an object containing information about logging context data
240 * @param loglevel this is the current log level of the log message to be sent
241 * @return negative value if there was an error
243 int dlt_user_log_write_start(DltContext *handle, DltContextData *log, DltLogLevelType loglevel);
246 * Initialise the generation of a DLT log message (intended for usage in verbose mode)
247 * This function has to be called first, when an application wants to send a new log messages.
248 * @param handle pointer to an object containing information about one special logging context
249 * @param log pointer to an object containing information about logging context data
250 * @param loglevel this is the current log level of the log message to be sent
251 * @param messageid message id of message
252 * @return negative value if there was an error
254 int dlt_user_log_write_start_id(DltContext *handle, DltContextData *log, DltLogLevelType loglevel, uint32_t messageid);
257 * Finishing the generation of a DLT log message and sending it to the DLT daemon.
258 * This function has to be called after writing all the log attributes of a log message.
259 * @param log pointer to an object containing information about logging context data
260 * @return negative value if there was an error
262 int dlt_user_log_write_finish(DltContextData *log);
265 * Write a boolean parameter into a DLT log message.
266 * dlt_user_log_write_start has to be called before adding any attributes to the log message.
267 * Finish sending log message by calling dlt_user_log_write_finish.
268 * @param log pointer to an object containing information about logging context data
269 * @param data boolean parameter written into log message (mapped to uint8)
270 * @return negative value if there was an error
272 int dlt_user_log_write_bool(DltContextData *log, uint8_t data);
275 * Write a float parameter into a DLT log message.
276 * dlt_user_log_write_start has to be called before adding any attributes to the log message.
277 * Finish sending log message by calling dlt_user_log_write_finish.
278 * @param log pointer to an object containing information about logging context data
279 * @param data float32_t parameter written into log message.
280 * @return negative value if there was an error
282 int dlt_user_log_write_float32(DltContextData *log, float32_t data);
285 * Write a double parameter into a DLT log message.
286 * dlt_user_log_write_start has to be called before adding any attributes to the log message.
287 * Finish sending log message by calling dlt_user_log_write_finish.
288 * @param log pointer to an object containing information about logging context data
289 * @param data float64_t parameter written into log message.
290 * @return negative value if there was an error
292 int dlt_user_log_write_float64(DltContextData *log, double data);
295 * Write a uint parameter into a DLT log message.
296 * dlt_user_log_write_start has to be called before adding any attributes to the log message.
297 * Finish sending log message by calling dlt_user_log_write_finish.
298 * @param log pointer to an object containing information about logging context data
299 * @param data unsigned int parameter written into log message.
300 * @return negative value if there was an error
302 int dlt_user_log_write_uint(DltContextData *log, unsigned int data);
303 int dlt_user_log_write_uint8(DltContextData *log, uint8_t data);
304 int dlt_user_log_write_uint16(DltContextData *log, uint16_t data);
305 int dlt_user_log_write_uint32(DltContextData *log, uint32_t data);
306 int dlt_user_log_write_uint64(DltContextData *log, uint64_t data);
308 * Write a int parameter into a DLT log message.
309 * dlt_user_log_write_start has to be called before adding any attributes to the log message.
310 * Finish sending log message by calling dlt_user_log_write_finish.
311 * @param log pointer to an object containing information about logging context data
312 * @param data int parameter written into log message.
313 * @return negative value if there was an error
315 int dlt_user_log_write_int(DltContextData *log, int data);
316 int dlt_user_log_write_int8(DltContextData *log, int8_t data);
317 int dlt_user_log_write_int16(DltContextData *log, int16_t data);
318 int dlt_user_log_write_int32(DltContextData *log, int32_t data);
319 int dlt_user_log_write_int64(DltContextData *log, int64_t data);
321 * Write a null terminated ASCII string into a DLT log message.
322 * dlt_user_log_write_start has to be called before adding any attributes to the log message.
323 * Finish sending log message by calling dlt_user_log_write_finish.
324 * @param log pointer to an object containing information about logging context data
325 * @param text pointer to the parameter written into log message containing null termination.
326 * @return negative value if there was an error
328 int dlt_user_log_write_string( DltContextData *log, const char *text);
331 * Write a binary memory block into a DLT log message.
332 * dlt_user_log_write_start has to be called before adding any attributes to the log message.
333 * Finish sending log message by calling dlt_user_log_write_finish.
334 * @param log pointer to an object containing information about logging context data
335 * @param data pointer to the parameter written into log message.
336 * @param length length in bytes of the parameter written into log message.
337 * @return negative value if there was an error
339 int dlt_user_log_write_raw(DltContextData *log,void *data,uint16_t length);
342 * Trace network message
343 * @param handle pointer to an object containing information about one special logging context
344 * @param nw_trace_type type of network trace (DLT_NW_TRACE_IPC, DLT_NW_TRACE_CAN, DLT_NW_TRACE_FLEXRAY, or DLT_NW_TRACE_MOST)
345 * @param header_len length of network message header
346 * @param header pointer to network message header
347 * @param payload_len length of network message payload
348 * @param payload pointer to network message payload
349 * @return negative value if there was an error
351 int dlt_user_trace_network(DltContext *handle, DltNetworkTraceType nw_trace_type, uint16_t header_len, void *header, uint16_t payload_len, void *payload);
353 /**************************************************************************************************
354 * The folowing API functions define a high level function interface for DLT
355 **************************************************************************************************/
358 * Initialise the user lib communication with daemon.
359 * This function has to be called first, before using any DLT user lib functions.
360 * @return negative value if there was an error
365 * Initialise the user lib writing only to file.
366 * This function has to be called first, before using any DLT user lib functions.
367 * @param name name of an optional log file
368 * @return negative value if there was an error
370 int dlt_init_file(const char *name);
373 * Terminate the user lib.
374 * This function has to be called when finishing using the DLT user lib.
375 * @return negative value if there was an error
380 * Register an application in the daemon.
381 * @param appid four byte long character array with the application id
382 * @param description long name of the application
383 * @return negative value if there was an error
385 int dlt_register_app(const char *appid, const char * description);
388 * Unregister an application in the daemon.
389 * This function has to be called when finishing using an application.
390 * @return negative value if there was an error
392 int dlt_unregister_app(void);
395 * Register a context in the daemon.
396 * This function has to be called before first usage of the context.
397 * @param handle pointer to an object containing information about one special logging context
398 * @param contextid four byte long character array with the context id
399 * @param description long name of the context
400 * @return negative value if there was an error
402 int dlt_register_context(DltContext *handle, const char *contextid, const char * description);
405 * Register a context in the daemon with pre-defined log level and pre-defined trace status.
406 * This function has to be called before first usage of the context.
407 * @param handle pointer to an object containing information about one special logging context
408 * @param contextid four byte long character array with the context id
409 * @param description long name of the context
410 * @param loglevel This is the log level to be pre-set for this context
411 (DLT_LOG_DEFAULT is not allowed here)
412 * @param tracestatus This is the trace status to be pre-set for this context
413 (DLT_TRACE_STATUS_DEFAULT is not allowed here)
414 * @return negative value if there was an error
416 int dlt_register_context_ll_ts(DltContext *handle, const char *contextid, const char * description, int loglevel, int tracestatus);
419 * Unregister a context in the DLT daemon.
420 * This function has to be called when finishing using a context.
421 * @param handle pointer to an object containing information about one special logging context
422 * @return negative value if there was an error
424 int dlt_unregister_context(DltContext *handle);
427 * Register callback function called when injection message was received
428 * @param handle pointer to an object containing information about one special logging context
429 * @param service_id the service id to be waited for
430 * @param (*dlt_injection_callback) function pointer to callback function
431 * @return negative value if there was an error
433 int dlt_register_injection_callback(DltContext *handle, uint32_t service_id,
434 int (*dlt_injection_callback)(uint32_t service_id, void *data, uint32_t length));
437 * Switch to verbose mode
440 int dlt_verbose_mode(void);
443 * Switch to non-verbose mode
446 int dlt_nonverbose_mode(void);
449 * Set maximum logged log level and trace status of application
451 * @param loglevel This is the log level to be set for the whole application
452 * @param tracestatus This is the trace status to be set for the whole application
453 * @return negative value if there was an error
455 int dlt_set_application_ll_ts_limit(DltLogLevelType loglevel, DltTraceStatusType tracestatus);
458 * Enable local printing of messages
461 int dlt_enable_local_print(void);
464 * Disable local printing of messages
467 int dlt_disable_local_print(void);
470 * Write a null terminated ASCII string into a DLT log message.
471 * @param handle pointer to an object containing information about one special logging context
472 * @param loglevel this is the current log level of the log message to be sent
473 * @param text pointer to the ASCII string written into log message containing null termination.
474 * @return negative value if there was an error
476 int dlt_log_string(DltContext *handle,DltLogLevelType loglevel, const char *text);
479 * Write a null terminated ASCII string and an integer value into a DLT log message.
480 * @param handle pointer to an object containing information about one special logging context
481 * @param loglevel this is the current log level of the log message to be sent
482 * @param text pointer to the ASCII string written into log message containing null termination.
483 * @param data integer value written into the log message
484 * @return negative value if there was an error
486 int dlt_log_string_int(DltContext *handle,DltLogLevelType loglevel, const char *text, int data);
489 * Write a null terminated ASCII string and an unsigned integer value into a DLT log message.
490 * @param handle pointer to an object containing information about one special logging context
491 * @param loglevel this is the current log level of the log message to be sent
492 * @param text pointer to the ASCII string written into log message containing null termination.
493 * @param data unsigned integer value written into the log message
494 * @return negative value if there was an error
496 int dlt_log_string_uint(DltContext *handle,DltLogLevelType loglevel, const char *text, unsigned int data);
499 * Write an integer value into a DLT log message.
500 * @param handle pointer to an object containing information about one special logging context
501 * @param loglevel this is the current log level of the log message to be sent
502 * @param data integer value written into the log message
503 * @return negative value if there was an error
505 int dlt_log_int(DltContext *handle,DltLogLevelType loglevel, int data);
508 * Write an unsigned integer value into a DLT log message.
509 * @param handle pointer to an object containing information about one special logging context
510 * @param loglevel this is the current log level of the log message to be sent
511 * @param data unsigned integer value written into the log message
512 * @return negative value if there was an error
514 int dlt_log_uint(DltContext *handle,DltLogLevelType loglevel, unsigned int data);
517 * Write an unsigned integer value into a DLT log message.
518 * @param handle pointer to an object containing information about one special logging context
519 * @param loglevel this is the current log level of the log message to be sent
520 * @param data pointer to the parameter written into log message.
521 * @param length length in bytes of the parameter written into log message.
522 * @return negative value if there was an error
524 int dlt_log_raw(DltContext *handle,DltLogLevelType loglevel, void *data,uint16_t length);
527 * Forward a complete DLT message to the DLT daemon
528 * @param msgdata Message data of DLT message
529 * @param size Size of DLT message
530 * @return negative value if there was an error
532 int dlt_forward_msg(void *msgdata,size_t size);
542 #endif /* DLT_USER_H */