diff options
Diffstat (limited to 'include/dlt')
-rwxr-xr-x | include/dlt/CMakeLists.txt | 40 | ||||
-rwxr-xr-x | include/dlt/dlt.h | 89 | ||||
-rwxr-xr-x | include/dlt/dlt_client.h | 164 | ||||
-rwxr-xr-x | include/dlt/dlt_common.h | 1117 | ||||
-rwxr-xr-x | include/dlt/dlt_protocol.h | 218 | ||||
-rwxr-xr-x | include/dlt/dlt_types.h | 97 | ||||
-rwxr-xr-x | include/dlt/dlt_user.h | 542 | ||||
-rwxr-xr-x | include/dlt/dlt_user_macros.h | 414 |
8 files changed, 2681 insertions, 0 deletions
diff --git a/include/dlt/CMakeLists.txt b/include/dlt/CMakeLists.txt new file mode 100755 index 0000000..fcdbaea --- /dev/null +++ b/include/dlt/CMakeLists.txt @@ -0,0 +1,40 @@ +####### +# Dlt - Diagnostic Log and Trace +# @licence make begin@ + # + # Copyright (C) 2011, BMW AG - Alexander Wenzel <alexander.wenzel@bmw.de> + # + # This program is free software; you can redistribute it and/or modify it under the terms of the + # GNU Lesser General Public License, version 2.1, as published by the Free Software Foundation. + # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + # the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + # Public License, version 2.1, for more details. + # + # You should have received a copy of the GNU Lesser General Public License, version 2.1, along + # with this program; if not, see <http://www.gnu.org/licenses/lgpl-2.1.html>. + # + # Note that the copyright holders assume that the GNU Lesser General Public License, version 2.1, may + # also be applicable to programs even in cases in which the program is not a library in the technical sense. + # + # Linking DLT statically or dynamically with other modules is making a combined work based on DLT. You may + # license such other modules under the GNU Lesser General Public License, version 2.1. If you do not want to + # license your linked modules under the GNU Lesser General Public License, version 2.1, you + # may use the program under the following exception. + # + # As a special exception, the copyright holders of DLT give you permission to combine DLT + # with software programs or libraries that are released under any license unless such a combination is not + # permitted by the license of such a software program or library. You may copy and distribute such a + # system following the terms of the GNU Lesser General Public License, version 2.1, including this + # special exception, for DLT and the licenses of the other code concerned. + # + # Note that people who make modified versions of DLT are not obligated to grant this special exception + # for their modified versions; it is their choice whether to do so. The GNU Lesser General Public License, + # version 2.1, gives permission to release a modified version without this exception; this exception + # also makes it possible to release a modified version which carries forward this exception. + # + # @licence end@ +######## + +install(FILES dlt.h dlt_user.h dlt_user_macros.h dlt_client.h dlt_protocol.h dlt_common.h dlt_types.h + DESTINATION include/dlt + COMPONENT devel) diff --git a/include/dlt/dlt.h b/include/dlt/dlt.h new file mode 100755 index 0000000..696fc46 --- /dev/null +++ b/include/dlt/dlt.h @@ -0,0 +1,89 @@ +/*
+ * Dlt- Diagnostic Log and Trace console apps
+ * @licence app begin@ + * + * Copyright (C) 2011, BMW AG - Alexander Wenzel <alexander.wenzel@bmw.de> + * + * This program is free software; you can redistribute it and/or modify it under the terms of the + * GNU Lesser General Public License, version 2.1, as published by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License, version 2.1, for more details. + * + * You should have received a copy of the GNU Lesser General Public License, version 2.1, along + * with this program; if not, see <http://www.gnu.org/licenses/lgpl-2.1.html>. + * + * Note that the copyright holders assume that the GNU Lesser General Public License, version 2.1, may + * also be applicable to programs even in cases in which the program is not a library in the technical sense. + * + * Linking DLT statically or dynamically with other modules is making a combined work based on DLT. You may + * license such other modules under the GNU Lesser General Public License, version 2.1. If you do not want to + * license your linked modules under the GNU Lesser General Public License, version 2.1, you + * may use the program under the following exception. + * + * As a special exception, the copyright holders of DLT give you permission to combine DLT + * with software programs or libraries that are released under any license unless such a combination is not + * permitted by the license of such a software program or library. You may copy and distribute such a + * system following the terms of the GNU Lesser General Public License, version 2.1, including this + * special exception, for DLT and the licenses of the other code concerned. + * + * Note that people who make modified versions of DLT are not obligated to grant this special exception + * for their modified versions; it is their choice whether to do so. The GNU Lesser General Public License, + * version 2.1, gives permission to release a modified version without this exception; this exception + * also makes it possible to release a modified version which carries forward this exception. + * + * @licence end@
+ */
+
+
+/*******************************************************************************
+** **
+** SRC-MODULE: dlt.h **
+** **
+** TARGET : linux ** +** ** +** PROJECT : DLT ** +** ** +** AUTHOR : Alexander Wenzel Alexander.AW.Wenzel@bmw.de ** +** Markus Klein ** +** ** +** PURPOSE : ** +** ** +** REMARKS : ** +** ** +** PLATFORM DEPENDANT [yes/no]: yes ** +** ** +** TO BE CHANGED BY USER [yes/no]: no ** +** ** +*******************************************************************************/ + +/******************************************************************************* +** Author Identity ** +******************************************************************************** +** ** +** Initials Name Company ** +** -------- ------------------------- ---------------------------------- ** +** aw Alexander Wenzel BMW ** +** mk Markus Klein Fraunhofer ESK ** +*******************************************************************************/
+
+/*******************************************************************************
+** Revision Control History **
+*******************************************************************************/
+
+/*
+ * $LastChangedRevision: 1670 $
+ * $LastChangedDate: 2011-04-08 15:12:06 +0200 (Fr, 08. Apr 2011) $
+ * $LastChangedBy$
+ Initials Date Comment
+ aw 13.01.2010 initial
+ */
+
+#ifndef DLT_H
+#define DLT_H
+ +#include "dlt_common.h"
+#include "dlt_user.h"
+
+#endif /* DLT_H */
+
diff --git a/include/dlt/dlt_client.h b/include/dlt/dlt_client.h new file mode 100755 index 0000000..e589469 --- /dev/null +++ b/include/dlt/dlt_client.h @@ -0,0 +1,164 @@ +/*
+ * Dlt- Diagnostic Log and Trace client library
+ * @licence app begin@ + * + * Copyright (C) 2011, BMW AG - Alexander Wenzel <alexander.wenzel@bmw.de> + * + * This program is free software; you can redistribute it and/or modify it under the terms of the + * GNU Lesser General Public License, version 2.1, as published by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License, version 2.1, for more details. + * + * You should have received a copy of the GNU Lesser General Public License, version 2.1, along + * with this program; if not, see <http://www.gnu.org/licenses/lgpl-2.1.html>. + * + * Note that the copyright holders assume that the GNU Lesser General Public License, version 2.1, may + * also be applicable to programs even in cases in which the program is not a library in the technical sense. + * + * Linking DLT statically or dynamically with other modules is making a combined work based on DLT. You may + * license such other modules under the GNU Lesser General Public License, version 2.1. If you do not want to + * license your linked modules under the GNU Lesser General Public License, version 2.1, you + * may use the program under the following exception. + * + * As a special exception, the copyright holders of DLT give you permission to combine DLT + * with software programs or libraries that are released under any license unless such a combination is not + * permitted by the license of such a software program or library. You may copy and distribute such a + * system following the terms of the GNU Lesser General Public License, version 2.1, including this + * special exception, for DLT and the licenses of the other code concerned. + * + * Note that people who make modified versions of DLT are not obligated to grant this special exception + * for their modified versions; it is their choice whether to do so. The GNU Lesser General Public License, + * version 2.1, gives permission to release a modified version without this exception; this exception + * also makes it possible to release a modified version which carries forward this exception. + * + * @licence end@
+ */
+
+
+/*******************************************************************************
+** **
+** SRC-MODULE: dlt_client.h **
+** **
+** TARGET : linux ** +** ** +** PROJECT : DLT ** +** ** +** AUTHOR : Alexander Wenzel Alexander.AW.Wenzel@bmw.de ** +** Markus Klein ** +** ** +** PURPOSE : ** +** ** +** REMARKS : ** +** ** +** PLATFORM DEPENDANT [yes/no]: yes ** +** ** +** TO BE CHANGED BY USER [yes/no]: no ** +** ** +*******************************************************************************/ + +/******************************************************************************* +** Author Identity ** +******************************************************************************** +** ** +** Initials Name Company ** +** -------- ------------------------- ---------------------------------- ** +** aw Alexander Wenzel BMW ** +** mk Markus Klein Fraunhofer ESK ** +*******************************************************************************/
+
+/*******************************************************************************
+** Revision Control History **
+*******************************************************************************/
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+#ifndef DLT_CLIENT_H
+#define DLT_CLIENT_H
+
+/**
+ \defgroup clientapi DLT Client API
+ \addtogroup clientapi
+ \{
+*/
+
+#include "dlt_types.h"
+#include "dlt_common.h"
+
+typedef struct
+{
+ DltReceiver receiver; /**< receiver pointer to dlt receiver structure */
+ int sock; /**< sock Connection handle/socket */
+ char *servIP; /**< servIP IP adress/Hostname of TCP/IP interface */
+ char *serialDevice; /**< serialDevice Devicename of serial device */
+ speed_t baudrate; /**< baudrate Baudrate of serial interface, as speed_t */
+ int serial_mode; /**< serial_mode Serial mode enabled =1, disabled =0 */
+} DltClient;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void dlt_client_register_message_callback(int (*registerd_callback) (DltMessage *message, void *data)); + +/** + * Initialising dlt client structure + * @param client pointer to dlt client structure + * @param verbose if set to true verbose information is printed out. + * @return negative value if there was an error + */
+int dlt_client_init(DltClient *client, int verbose); +/** + * Connect to dlt daemon using the information from the dlt client structure + * @param client pointer to dlt client structure + * @param verbose if set to true verbose information is printed out. + * @return negative value if there was an error + */
+int dlt_client_connect(DltClient *client, int verbose); +/** + * Cleanup dlt client structure + * @param client pointer to dlt client structure + * @param verbose if set to true verbose information is printed out. + * @return negative value if there was an error + */
+int dlt_client_cleanup(DltClient *client, int verbose); +/** + * Main Loop of dlt client application + * @param client pointer to dlt client structure + * @param data pointer to data to be provided to the main loop + * @param verbose if set to true verbose information is printed out. + * @return negative value if there was an error + */
+int dlt_client_main_loop(DltClient *client, void *data, int verbose); +/** + * Send an injection message to the dlt daemon + * @param client pointer to dlt client structure + * @param apid application id + * @param ctid context id + * @param serviceID service id + * @param buffer Buffer filled with injection message data + * @param size Size of injection data within buffer + * @return negative value if there was an error + */
+int dlt_client_send_inject_msg(DltClient *client, char *apid, char *ctid, uint32_t serviceID, uint8_t *buffer, uint32_t size); +/** + * Set baudrate within dlt client structure + * @param client pointer to dlt client structure + * @param baudrate Baudrate + * @return negative value if there was an error + */ +int dlt_client_setbaudrate(DltClient *client, int baudrate);
+
+#ifdef __cplusplus
+}
+#endif
+
+/**
+ \}
+*/
+
+#endif /* DLT_CLIENT_H */
diff --git a/include/dlt/dlt_common.h b/include/dlt/dlt_common.h new file mode 100755 index 0000000..a13787b --- /dev/null +++ b/include/dlt/dlt_common.h @@ -0,0 +1,1117 @@ +/* + * Dlt- Diagnostic Log and Trace + * @licence app begin@ + * + * Copyright (C) 2011, BMW AG - Alexander Wenzel <alexander.wenzel@bmw.de> + * + * This program is free software; you can redistribute it and/or modify it under the terms of the + * GNU Lesser General Public License, version 2.1, as published by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License, version 2.1, for more details. + * + * You should have received a copy of the GNU Lesser General Public License, version 2.1, along + * with this program; if not, see <http://www.gnu.org/licenses/lgpl-2.1.html>. + * + * Note that the copyright holders assume that the GNU Lesser General Public License, version 2.1, may + * also be applicable to programs even in cases in which the program is not a library in the technical sense. + * + * Linking DLT statically or dynamically with other modules is making a combined work based on DLT. You may + * license such other modules under the GNU Lesser General Public License, version 2.1. If you do not want to + * license your linked modules under the GNU Lesser General Public License, version 2.1, you + * may use the program under the following exception. + * + * As a special exception, the copyright holders of DLT give you permission to combine DLT + * with software programs or libraries that are released under any license unless such a combination is not + * permitted by the license of such a software program or library. You may copy and distribute such a + * system following the terms of the GNU Lesser General Public License, version 2.1, including this + * special exception, for DLT and the licenses of the other code concerned. + * + * Note that people who make modified versions of DLT are not obligated to grant this special exception + * for their modified versions; it is their choice whether to do so. The GNU Lesser General Public License, + * version 2.1, gives permission to release a modified version without this exception; this exception + * also makes it possible to release a modified version which carries forward this exception. + * + * @licence end@ + */ + + +/******************************************************************************* +** ** +** SRC-MODULE: dlt_common.h ** +** ** +** TARGET : linux ** +** ** +** PROJECT : DLT ** +** ** +** AUTHOR : Alexander Wenzel Alexander.AW.Wenzel@bmw.de ** +** Markus Klein ** +** ** +** PURPOSE : ** +** ** +** REMARKS : ** +** ** +** PLATFORM DEPENDANT [yes/no]: yes ** +** ** +** TO BE CHANGED BY USER [yes/no]: no ** +** ** +*******************************************************************************/ + +/******************************************************************************* +** Author Identity ** +******************************************************************************** +** ** +** Initials Name Company ** +** -------- ------------------------- ---------------------------------- ** +** aw Alexander Wenzel BMW ** +** mk Markus Klein Fraunhofer ESK ** +*******************************************************************************/ + +/******************************************************************************* +** Revision Control History ** +*******************************************************************************/ + +/* + * $LastChangedRevision: 1670 $ + * $LastChangedDate: 2011-04-08 15:12:06 +0200 (Fr, 08. Apr 2011) $ + * $LastChangedBy$ + Initials Date Comment + aw 13.01.2010 initial + */ +#ifndef DLT_COMMON_H +#define DLT_COMMON_H + +/** + \defgroup commonapi DLT Common API + \addtogroup commonapi + \{ +*/ + +#include <stdio.h> + +#if !defined(_MSC_VER) +#include <unistd.h> +#include <time.h> +#endif + +#if !defined (__WIN32__) && !defined(_MSC_VER) +#include <termios.h> +#endif + +#include "dlt_types.h" +#include "dlt_protocol.h" + +#if !defined (PACKED) +#define PACKED __attribute__((aligned(1),packed)) +#endif + +#if defined (__MSDOS__) || defined (_MSC_VER) +/* set instead /Zp8 flag in Visual C++ configuration */ +#undef PACKED +#define PACKED +#endif + +/* + * Macros to swap the byte order. + */ +#define DLT_SWAP_64(value) ((((uint64_t)DLT_SWAP_32((value)&0xffffffffull))<<32) | (DLT_SWAP_32((value)>>32))) + +#define DLT_SWAP_16(value) ((((value) >> 8)&0xff) | (((value) << 8)&0xff00)) +#define DLT_SWAP_32(value) ((((value) >> 24)&0xff) | (((value) << 8)&0xff0000) | (((value) >> 8)&0xff00) | (((value) << 24)&0xff000000)) + +/* Set Big Endian and Little Endian to a initial value, if not defined */ +#ifndef LITTLE_ENDIAN +#define LITTLE_ENDIAN 1234 +#endif + +#ifndef BIG_ENDIAN +#define BIG_ENDIAN 4321 +#endif + +/* If byte order is not defined, default to little endian */ +#ifndef BYTE_ORDER +#define BYTE_ORDER LITTLE_ENDIAN +#endif + +/* Check for byte-order */ +#if (BYTE_ORDER==BIG_ENDIAN) +/* #warning "Big Endian Architecture!" */ +#define DLT_HTOBE_16(x) ((x)) +#define DLT_HTOLE_16(x) DLT_SWAP_16((x)) +#define DLT_BETOH_16(x) ((x)) +#define DLT_LETOH_16(x) DLT_SWAP_16((x)) + +#define DLT_HTOBE_32(x) ((x)) +#define DLT_HTOLE_32(x) DLT_SWAP_32((x)) +#define DLT_BETOH_32(x) ((x)) +#define DLT_LETOH_32(x) DLT_SWAP_32((x)) + +#define DLT_HTOBE_64(x) ((x)) +#define DLT_HTOLE_64(x) DLT_SWAP_64((x)) +#define DLT_BETOH_64(x) ((x)) +#define DLT_LETOH_64(x) DLT_SWAP_64((x)) +#else +/* #warning "Litte Endian Architecture!" */ +#define DLT_HTOBE_16(x) DLT_SWAP_16((x)) +#define DLT_HTOLE_16(x) ((x)) +#define DLT_BETOH_16(x) DLT_SWAP_16((x)) +#define DLT_LETOH_16(x) ((x)) + +#define DLT_HTOBE_32(x) DLT_SWAP_32((x)) +#define DLT_HTOLE_32(x) ((x)) +#define DLT_BETOH_32(x) DLT_SWAP_32((x)) +#define DLT_LETOH_32(x) ((x)) + +#define DLT_HTOBE_64(x) DLT_SWAP_64((x)) +#define DLT_HTOLE_64(x) ((x)) +#define DLT_BETOH_64(x) DLT_SWAP_64((x)) +#define DLT_LETOH_64(x) ((x)) +#endif + +#define DLT_ENDIAN_GET_16(htyp,x) ((((htyp) & DLT_HTYP_MSBF)>0)?DLT_BETOH_16(x):DLT_LETOH_16(x)) +#define DLT_ENDIAN_GET_32(htyp,x) ((((htyp) & DLT_HTYP_MSBF)>0)?DLT_BETOH_32(x):DLT_LETOH_32(x)) +#define DLT_ENDIAN_GET_64(htyp,x) ((((htyp) & DLT_HTYP_MSBF)>0)?DLT_BETOH_64(x):DLT_LETOH_64(x)) + +#if defined (__WIN32__) || defined (_MSC_VER) +#define LOG_EMERG 0 +#define LOG_ALERT 1 +#define LOG_CRIT 2 +#define LOG_ERR 3 +#define LOG_WARNING 4 +#define LOG_NOTICE 5 +#define LOG_INFO 6 +#define LOG_DEBUG 7 + +#define LOG_PID 0x01 +#define LOG_DAEMON (3<<3) +#endif + +/** + * The standard TCP Port used for DLT daemon + */ +#define DLT_DAEMON_TCP_PORT 3490 + +/** + * The size of a DLT ID + */ +#define DLT_ID_SIZE 4 + +#define DLT_SIZE_WEID DLT_ID_SIZE +#define DLT_SIZE_WSID (sizeof(uint32_t)) +#define DLT_SIZE_WTMS (sizeof(uint32_t)) + +/** + * Get the size of extra header parameters, depends on htyp. + */ +#define DLT_STANDARD_HEADER_EXTRA_SIZE(htyp) ( (DLT_IS_HTYP_WEID(htyp) ? DLT_SIZE_WEID : 0) + (DLT_IS_HTYP_WSID(htyp) ? DLT_SIZE_WSID : 0) + (DLT_IS_HTYP_WTMS(htyp) ? DLT_SIZE_WTMS : 0) ) + + +#if defined (__MSDOS__) || defined (_MSC_VER) +#define __func__ __FUNCTION__ +#endif + +#define PRINT_FUNCTION_VERBOSE(_verbose) \ +{ \ + static char _strbuf[255]; \ + \ + if(_verbose) \ + { \ + sprintf(_strbuf, "%s()\n",__func__); \ + dlt_log(LOG_INFO, _strbuf); \ + } \ +} + +#ifndef NULL +#define NULL (char*)0 +#endif + +#define DLT_MSG_IS_CONTROL(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \ + (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin)==DLT_TYPE_CONTROL)) + +#define DLT_MSG_IS_CONTROL_REQUEST(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \ + (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin)==DLT_TYPE_CONTROL) && \ + (DLT_GET_MSIN_MTIN((MSG)->extendedheader->msin)==DLT_CONTROL_REQUEST)) + +#define DLT_MSG_IS_CONTROL_RESPONSE(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \ + (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin)==DLT_TYPE_CONTROL) && \ + (DLT_GET_MSIN_MTIN((MSG)->extendedheader->msin)==DLT_CONTROL_RESPONSE)) + +#define DLT_MSG_IS_CONTROL_TIME(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \ + (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin)==DLT_TYPE_CONTROL) && \ + (DLT_GET_MSIN_MTIN((MSG)->extendedheader->msin)==DLT_CONTROL_TIME)) + +#define DLT_MSG_IS_NW_TRACE(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \ + (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin)==DLT_TYPE_NW_TRACE)) + +#define DLT_MSG_IS_TRACE_MOST(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \ + (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin)==DLT_TYPE_NW_TRACE) && \ + (DLT_GET_MSIN_MTIN((MSG)->extendedheader->msin)==DLT_NW_TRACE_MOST)) + +#define DLT_MSG_IS_NONVERBOSE(MSG) (!(DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) || \ + ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && (!(DLT_IS_MSIN_VERB((MSG)->extendedheader->msin))))) + +/* + + * Definitions of DLT message buffer overflow + */ +#define DLT_MESSAGE_BUFFER_NO_OVERFLOW 0x00 /**< Buffer overflow has not occured */ +#define DLT_MESSAGE_BUFFER_OVERFLOW 0x01 /**< Buffer overflow has occured */ + +/* + * Definition of DLT output variants + */ +#define DLT_OUTPUT_HEX 1 +#define DLT_OUTPUT_ASCII 2 +#define DLT_OUTPUT_MIXED_FOR_PLAIN 3 +#define DLT_OUTPUT_MIXED_FOR_HTML 4 +#define DLT_OUTPUT_ASCII_LIMITED 5 + +#define DLT_FILTER_MAX 30 /**< Maximum number of filters */ + +#define DLT_MSG_READ_VALUE(dst,src,length,type) \ + { \ + if((length<0) || ((length)<((int32_t)sizeof(type)))) \ + { length = -1; } \ + else \ + { dst = *((type*)src);src+=sizeof(type);length-=sizeof(type); } \ + } + +#define DLT_MSG_READ_ID(dst,src,length) \ + { \ + if((length<0) || ((length)<DLT_ID_SIZE)) \ + { length = -1; } \ + else \ + { memcpy(dst,src,DLT_ID_SIZE);src+=DLT_ID_SIZE;length-=DLT_ID_SIZE; } \ + } + +#define DLT_MSG_READ_STRING(dst,src,maxlength,length) \ + { \ + if(((maxlength)<0) || ((length)<0) || ((maxlength)<(length))) \ + { maxlength = -1; } \ + else \ + { memcpy(dst,src,length);dlt_clean_string(dst,length);dst[length]=0; \ + src+=length;maxlength-=length; } \ + } + +#define DLT_MSG_READ_NULL(src,maxlength,length) \ + { \ + if(((maxlength)<0) || ((length)<0) || ((maxlength)<(length))) \ + { length = -1; } \ + else \ + { src+=length;maxlength-=length; } \ + } + +#define DLT_HEADER_SHOW_NONE 0x0000 +#define DLT_HEADER_SHOW_TIME 0x0001 +#define DLT_HEADER_SHOW_TMSTP 0x0002 +#define DLT_HEADER_SHOW_MSGCNT 0x0004 +#define DLT_HEADER_SHOW_ECUID 0x0008 +#define DLT_HEADER_SHOW_APID 0x0010 +#define DLT_HEADER_SHOW_CTID 0x0020 +#define DLT_HEADER_SHOW_MSGTYPE 0x0040 +#define DLT_HEADER_SHOW_MSGSUBTYPE 0x0080 +#define DLT_HEADER_SHOW_VNVSTATUS 0x0100 +#define DLT_HEADER_SHOW_NOARG 0x0200 +#define DLT_HEADER_SHOW_ALL 0xFFFF + +/** + * The definition of the serial header containing the characters "DLS" + 0x01. + */ +extern const char dltSerialHeader[DLT_ID_SIZE]; + +/** + * The definition of the serial header containing the characters "DLS" + 0x01 as char. + */ +extern char dltSerialHeaderChar[DLT_ID_SIZE]; + +/** + + * The type of a DLT ID (context id, application id, etc.) + */ +typedef char ID4[DLT_ID_SIZE]; + +/** + * The structure of the DLT file storage header. This header is used before each stored DLT message. + */ +typedef struct +{ + char pattern[DLT_ID_SIZE]; /**< This pattern should be DLT0x01 */ + time_t seconds; /**< seconds since 1.1.1970 */ + int32_t microseconds; /**< Microseconds */ + char ecu[DLT_ID_SIZE]; /**< The ECU id is added, if it is not already in the DLT message itself */ +} PACKED DltStorageHeader; + +/** + * The structure of the DLT standard header. This header is used in each DLT message. + */ +typedef struct +{ + uint8_t htyp; /**< This parameter contains several informations, see definitions below */ + uint8_t mcnt; /**< The message counter is increased with each sent DLT message */ + uint16_t len; /**< Length of the complete message, without storage header */ +} PACKED DltStandardHeader; + +/** + * The structure of the DLT extra header parameters. Each parameter is sent only if enabled in htyp. + */ +typedef struct +{ + char ecu[DLT_ID_SIZE]; /**< ECU id */ + uint32_t seid; /**< Session number */ + uint32_t tmsp; /**< Timestamp since system start in 0.1 milliseconds */ +} PACKED DltStandardHeaderExtra; + +/** + * The structure of the DLT extended header. This header is only sent if enabled in htyp parameter. + */ +typedef struct +{ + uint8_t msin; /**< messsage info */ + uint8_t noar; /**< number of arguments */ + char apid[DLT_ID_SIZE]; /**< application id */ + char ctid[DLT_ID_SIZE]; /**< context id */ +} PACKED DltExtendedHeader; + +/** + * The structure to organise the DLT messages. + * This structure is used by the corresponding functions. + */ +typedef struct sDltMessage +{ + /* flags */ + int8_t found_serialheader; + + /* offsets */ + int32_t resync_offset; + + /* size parameters */ + int32_t headersize; /**< size of complete header including storage header */ + int32_t datasize; /**< size of complete payload */ + + /* buffer for current loaded message */ + uint8_t headerbuffer[sizeof(DltStorageHeader)+ + sizeof(DltStandardHeader)+sizeof(DltStandardHeaderExtra)+sizeof(DltExtendedHeader)]; /**< buffer for loading complete header */ + uint8_t *databuffer; /**< buffer for loading payload */ + + /* header values of current loaded message */ + DltStorageHeader *storageheader; /**< pointer to storage header of current loaded header */ + DltStandardHeader *standardheader; /**< pointer to standard header of current loaded header */ + DltStandardHeaderExtra headerextra; /**< extra parameters of current loaded header */ + DltExtendedHeader *extendedheader; /**< pointer to extended of current loaded header */ +} DltMessage; + +/** + * The structure of the DLT Service Get Log Info. + */ +typedef struct +{ + uint32_t service_id; /**< service ID */ + uint8_t options; /**< type of request */ + char apid[DLT_ID_SIZE]; /**< application id */ + char ctid[DLT_ID_SIZE]; /**< context id */ + char com[DLT_ID_SIZE]; /**< communication interface */ +} PACKED DltServiceGetLogInfoRequest; + +/** + * The structure of the DLT Service Set Log Level. + */ +typedef struct +{ + uint32_t service_id; /**< service ID */ + char apid[DLT_ID_SIZE]; /**< application id */ + char ctid[DLT_ID_SIZE]; /**< context id */ + uint8_t log_level; /**< log level to be set */ + char com[DLT_ID_SIZE]; /**< communication interface */ +} PACKED DltServiceSetLogLevel; + +/** + * The structure of the DLT Service Set Default Log Level. + */ +typedef struct +{ + uint32_t service_id; /**< service ID */ + uint8_t log_level; /**< default log level to be set */ + char com[DLT_ID_SIZE]; /**< communication interface */ +} PACKED DltServiceSetDefaultLogLevel; + +/** + * The structure of the DLT Service Set Verbose Mode + */ +typedef struct +{ + uint32_t service_id; /**< service ID */ + uint8_t new_status; /**< new status to be set */ +} PACKED DltServiceSetVerboseMode; + +/** + * The structure of the DLT Service Set Communication Interface Status + */ +typedef struct +{ + uint32_t service_id; /**< service ID */ + char com[DLT_ID_SIZE]; /**< communication interface */ + uint8_t new_status; /**< new status to be set */ +} PACKED DltServiceSetCommunicationInterfaceStatus; + +/** + * The structure of the DLT Service Set Communication Maximum Bandwidth + */ +typedef struct +{ + uint32_t service_id; /**< service ID */ + char com[DLT_ID_SIZE]; /**< communication interface */ + uint32_t max_bandwidth; /**< maximum bandwith */ +} PACKED DltServiceSetCommunicationMaximumBandwidth; + +typedef struct +{ + uint32_t service_id; /**< service ID */ + uint8_t status; /**< reponse status */ +} PACKED DltServiceResponse; + +typedef struct +{ + uint32_t service_id; /**< service ID */ + uint8_t status; /**< reponse status */ + uint8_t log_level; /**< log level */ +} PACKED DltServiceGetDefaultLogLevelResponse; + +typedef struct +{ + uint32_t service_id; /**< service ID */ + uint8_t status; /**< reponse status */ + uint8_t overflow; /**< overflow status */ +} PACKED DltServiceMessageBufferOverflowResponse; + +typedef struct +{ + uint32_t service_id; /**< service ID */ + uint8_t status; /**< reponse status */ + uint32_t length; /**< length of following payload */ + /* char [] payload */ +} PACKED DltServiceGetSoftwareVersionResponse; + +/** + * Structure to store filter parameters. + * ID are maximal four characters. Unused values are filled with zeros. + * If every value as filter is valid, the id should be empty by having only zero values. + */ +typedef struct +{ + char apid[DLT_FILTER_MAX][DLT_ID_SIZE]; /**< application id */ + char ctid[DLT_FILTER_MAX][DLT_ID_SIZE]; /**< context id */ + int counter; /**< number of filters */ +} DltFilter; + +/** + * The structure to organise the access to DLT files. + * This structure is used by the corresponding functions. + */ +typedef struct sDltFile +{ + /* file handle and index for fast access */ + FILE *handle; /**< file handle of opened DLT file */ + long *index; /**< file positions of all DLT messages for fast access to file, only filtered messages */ + + /* size parameters */ + int32_t counter; /**< number of messages in DLT file with filter */ + int32_t counter_total; /**< number of messages in DLT file without filter */ + int32_t position; /**< current index to message parsed in DLT file starting at 0 */ + long file_length; /**< length of the file */ + long file_position; /**< current position in the file */ + + /* error counters */ + int32_t error_messages; /**< number of incomplete DLT messages found during file parsing */ + + /* filter parameters */ + DltFilter *filter; /**< pointer to filter list. Zero if no filter is set. */ + int32_t filter_counter; /**< number of filter set */ + + /* current loaded message */ + DltMessage msg; /**< pointer to message */ + +} DltFile; + +/** + * The structure is used to organise the receiving of data + * including buffer handling. + * This structure is used by the corresponding functions. + */ +typedef struct +{ + int32_t lastBytesRcvd; /**< bytes received in last receive call */ + int32_t bytesRcvd; /**< received bytes */ + int32_t totalBytesRcvd; /**< total number of received bytes */ + char *buffer; /**< pointer to receiver buffer */ + char *buf; /**< pointer to position within receiver buffer */ + int fd; /**< connection handle */ + int32_t buffersize; /**< size of receiver buffer */ +} DltReceiver; + +typedef struct +{ + char* buffer; /**< Ptr. to buffer */ + uint32_t size; /**< Maximum size of buffer */ + uint32_t pos_write; /**< current writing position in bytes*/ + uint32_t pos_read; /**< current reading position in bytes*/ + uint32_t count; /**< nr. of entries */ +} DltRingBuffer; + +#ifdef __cplusplus +extern "C" +{ +#endif + + /** + * Helper function to print a byte array in hex. + * @param ptr pointer to the byte array. + * @param size number of bytes to be printed. + */ + void dlt_print_hex(uint8_t *ptr,int size); + /** + * Helper function to print a byte array in hex into a string. + * @param text pointer to a ASCII string, in which the text is written + * @param textlength maximal size of text buffer + * @param ptr pointer to the byte array. + * @param size number of bytes to be printed. + * @return negative value if there was an error + */ + int dlt_print_hex_string(char *text,int textlength,uint8_t *ptr,int size); + /** + * Helper function to print a byte array in hex and ascii into a string. + * @param text pointer to a ASCII string, in which the text is written + * @param textlength maximal size of text buffer + * @param ptr pointer to the byte array. + * @param size number of bytes to be printed. + * @param html output is html? 0 - false, 1 - true + * @return negative value if there was an error + */ + int dlt_print_mixed_string(char *text,int textlength,uint8_t *ptr,int size,int html); + /** + * Helper function to print a byte array in ascii into a string. + * @param text pointer to a ASCII string, in which the text is written + * @param textlength maximal size of text buffer + * @param ptr pointer to the byte array. + * @param size number of bytes to be printed. + * @return negative value if there was an error + */ + int dlt_print_char_string(char **text,int textlength,uint8_t *ptr,int size); + + /** + * Helper function to print an id. + * @param text pointer to ASCII string where to write the id + * @param id four byte char array as used in DLT mesages as IDs. + */ + void dlt_print_id(char *text,const char *id); + + /** + * Helper function to set an ID parameter. + * @param id four byte char array as used in DLT mesages as IDs. + * @param text string to be copied into char array. + */ + void dlt_set_id(char *id,const char *text); + + /** + * Helper function to remove not nice to print characters, e.g. NULL or carage return. + * @param text pointer to string to be cleaned. + * @param length length of string excluding terminating zero. + */ + void dlt_clean_string(char *text,int length); + + /** + * Initialise the filter list. + * This function must be called before using further dlt filter. + * @param filter pointer to structure of organising DLT filter + * @param verbose if set to true verbose information is printed out. + * @return negative value if there was an error + */ + int dlt_filter_init(DltFilter *filter,int verbose); + /** + * Free the used memory by the organising structure of filter. + * @param filter pointer to structure of organising DLT filter + * @param verbose if set to true verbose information is printed out. + * @return negative value if there was an error + */ + int dlt_filter_free(DltFilter *filter,int verbose); + /** + * Load filter list from file. + * @param filter pointer to structure of organising DLT filter + * @param filename filename to load filters from + * @param verbose if set to true verbose information is printed out. + * @return negative value if there was an error + */ + int dlt_filter_load(DltFilter *filter,const char *filename,int verbose); + /** + * Save filter list to file. + * @param filter pointer to structure of organising DLT filter + * @param filename filename to load filters from + * @param verbose if set to true verbose information is printed out. + * @return negative value if there was an error + */ + int dlt_filter_save(DltFilter *filter,const char *filename,int verbose); + /** + * Find index of filter in filter list + * @param filter pointer to structure of organising DLT filter + * @param apid application id to be found in filter list + * @param ctid context id to be found in filter list + * @param verbose if set to true verbose information is printed out. + * @return negative value if there was an error (or not found), else return index of filter + */ + int dlt_filter_find(DltFilter *filter,const char *apid,const char *ctid, int verbose); + /** + * Add new filter to filter list. + * @param filter pointer to structure of organising DLT filter + * @param apid application id to be added to filter list (must always be set). + * @param ctid context id to be added to filter list. empty equals don't care. + * @param verbose if set to true verbose information is printed out. + * @return negative value if there was an error + */ + int dlt_filter_add(DltFilter *filter,const char *apid,const char *ctid,int verbose); + /** + * Delete filter from filter list + * @param filter pointer to structure of organising DLT filter + * @param apid application id to be deleted from filter list + * @param ctid context id to be deleted from filter list + * @param verbose if set to true verbose information is printed out. + * @return negative value if there was an error + */ + int dlt_filter_delete(DltFilter *filter,const char *apid,const char *ctid,int verbose); + + /** + * Initialise the structure used to access a DLT message. + * This function must be called before using further dlt_message functions. + * @param msg pointer to structure of organising access to DLT messages + * @param verbose if set to true verbose information is printed out. + * @return negative value if there was an error + */ + int dlt_message_init(DltMessage *msg,int verbose); + /** + * Free the used memory by the organising structure of file. + * @param msg pointer to structure of organising access to DLT messages + * @param verbose if set to true verbose information is printed out. + * @return negative value if there was an error + */ + int dlt_message_free(DltMessage *msg,int verbose); + /** + * Print Header into an ASCII string. + * This function calls dlt_message_header_flags() with flags=DLT_HEADER_SHOW_ALL + * @param msg pointer to structure of organising access to DLT messages + * @param text pointer to a ASCII string, in which the header is written + * @param textlength maximal size of text buffer + * @param verbose if set to true verbose information is printed out. + * @return negative value if there was an error + */ + int dlt_message_header(DltMessage *msg,char *text,int textlength,int verbose); + /** + * Print Header into an ASCII string, selective. + * @param msg pointer to structure of organising access to DLT messages + * @param text pointer to a ASCII string, in which the header is written + * @param textlength maximal size of text buffer + * @param flags select, bit-field to select, what should be printed (DLT_HEADER_SHOW_...) + * @param verbose if set to true verbose information is printed out. + * @return negative value if there was an error + */ + int dlt_message_header_flags(DltMessage *msg,char *text,int textlength,int flags, int verbose); + /** + * Print Payload into an ASCII string. + * @param msg pointer to structure of organising access to DLT messages + * @param text pointer to a ASCII string, in which the header is written + * @param textlength maximal size of text buffer + * @param type 1 = payload as hex, 2 = payload as ASCII. + * @param verbose if set to true verbose information is printed out. + * @return negative value if there was an error + */ + int dlt_message_payload(DltMessage *msg,char *text,int textlength,int type,int verbose); + /** + * Check if message is filtered or not. All filters are applied (logical OR). + * @param msg pointer to structure of organising access to DLT messages + * @param filter pointer to filter + * @param verbose if set to true verbose information is printed out. + * @return 1 = filter matches, 0 = filter does not match, negative value if there was an error + */ + int dlt_message_filter_check(DltMessage *msg,DltFilter *filter,int verbose); + + /** + * Read message from memory buffer. + * Message in buffer has no storage header. + * @param msg pointer to structure of organising access to DLT messages + * @param buffer pointer to memory buffer + * @param length length of message in buffer + * @param resync if set to true resync to serial header is enforced + * @param verbose if set to true verbose information is printed out. + * @return negative value if there was an error + */ + int dlt_message_read(DltMessage *msg,uint8_t *buffer,unsigned int length,int resync,int verbose); + + /** + * Get standard header extra parameters + * @param msg pointer to structure of organising access to DLT messages + * @param verbose if set to true verbose information is printed out. + * @return negative value if there was an error + */ + int dlt_message_get_extraparameters(DltMessage *msg,int verbose); + + /** + * Set standard header extra parameters + * @param msg pointer to structure of organising access to DLT messages + * @param verbose if set to true verbose information is printed out. + * @return negative value if there was an error + */ + int dlt_message_set_extraparameters(DltMessage *msg,int verbose); + + /** + * Initialise the structure used to access a DLT file. + * This function must be called before using further dlt_file functions. + * @param file pointer to structure of organising access to DLT file + * @param verbose if set to true verbose information is printed out. + * @return negative value if there was an error + */ + int dlt_file_init(DltFile *file,int verbose); + /** + * Set a list to filters. + * This function should be called before loading a DLT file, if filters should be used. + * A filter list is an array of filters. Several filters are combined logically by or operation. + * The filter list is not copied, so take care to keep list in memory. + * @param file pointer to structure of organising access to DLT file + * @param filter pointer to filter list array + * @param verbose if set to true verbose information is printed out. + * @return negative value if there was an error + */ + int dlt_file_set_filter(DltFile *file,DltFilter *filter,int verbose); + /** + * Initialising loading a DLT file. + * @param file pointer to structure of organising access to DLT file + * @param filename filename of DLT file + * @param verbose if set to true verbose information is printed out. + * @return negative value if there was an error + */ + int dlt_file_open(DltFile *file,const char *filename,int verbose); + /** + * Find next message in the DLT file and parse them. + * This function finds the next message in the DLT file. + * If a filter is set, the filter list is used. + * @param file pointer to structure of organising access to DLT file + * @param verbose if set to true verbose information is printed out. + * @return 0 = message does not match filter, 1 = message was read, negative value if there was an error + */ + int dlt_file_read(DltFile *file,int verbose); + /** + * Find next message in the DLT file in RAW format (without storage header) and parse them. + * This function finds the next message in the DLT file. + * If a filter is set, the filter list is used. + * @param file pointer to structure of organising access to DLT file + * @param resync Resync to serial header when set to true + * @param verbose if set to true verbose information is printed out. + * @return 0 = message does not match filter, 1 = message was read, negative value if there was an error + */ + int dlt_file_read_raw(DltFile *file,int resync,int verbose); + /** + * Closing loading a DLT file. + * @param file pointer to structure of organising access to DLT file + * @param verbose if set to true verbose information is printed out. + * @return negative value if there was an error + */ + int dlt_file_close(DltFile *file,int verbose); + /** + * Load standard header of a message from file + * @param file pointer to structure of organising access to DLT file + * @param verbose if set to true verbose information is printed out. + * @return negative value if there was an error + */ + int dlt_file_read_header(DltFile *file,int verbose); + /** + * Load standard header of a message from file in RAW format (without storage header) + * @param file pointer to structure of organising access to DLT file + * @param resync Resync to serial header when set to true + * @param verbose if set to true verbose information is printed out. + * @return negative value if there was an error + */ + int dlt_file_read_header_raw(DltFile *file,int resync,int verbose); + /** + * Load, if available in message, extra standard header fields and + * extended header of a message from file + * (dlt_file_read_header() must have been called before this call!) + * @param file pointer to structure of organising access to DLT file + * @param verbose if set to true verbose information is printed out. + * @return negative value if there was an error + */ + int dlt_file_read_header_extended(DltFile *file, int verbose); + /** + * Load payload of a message from file + * (dlt_file_read_header() must have been called before this call!) + * @param file pointer to structure of organising access to DLT file + * @param verbose if set to true verbose information is printed out. + * @return negative value if there was an error + */ + int dlt_file_read_data(DltFile *file, int verbose); + /** + * Load headers and payload of a message selected by the index. + * If filters are set, index is based on the filtered list. + * @param file pointer to structure of organising access to DLT file + * @param index position of message in the files beginning from zero + * @param verbose if set to true verbose information is printed out. + * @return number of messages loaded, negative value if there was an error + */ + int dlt_file_message(DltFile *file,int index,int verbose); + /** + * Free the used memory by the organising structure of file. + * @param file pointer to structure of organising access to DLT file + * @param verbose if set to true verbose information is printed out. + * @return negative value if there was an error + */ + int dlt_file_free(DltFile *file,int verbose); + + /** + * Initialize (external) logging facility + * @param mode positive, if syslog should be used; zero for console output + */ + void dlt_log_init(int mode); + /** + * Log ASCII string with null-termination to (external) logging facility + * @param prio priority (see syslog() call) + * @param s Pointer to ASCII string with null-termination + * @return negative value if there was an error + */ + int dlt_log(int prio, char *s); + /** + * De-Initialize (external) logging facility + */ + void dlt_log_free(void); + + /** + * Initialising a dlt receiver structure + * @param receiver pointer to dlt receiver structure + * @param _fd handle to file/socket/fifo, fram which the data should be received + * @param _buffersize size of data buffer for storing the received data + * @return negative value if there was an error + */ + int dlt_receiver_init(DltReceiver *receiver,int _fd, int _buffersize); + /** + * De-Initialize a dlt receiver structure + * @param receiver pointer to dlt receiver structure + * @return negative value if there was an error + */ + int dlt_receiver_free(DltReceiver *receiver); + /** + * Receive data from socket using the dlt receiver structure + * @param receiver pointer to dlt receiver structure + * @return negative value if there was an error + */ + int dlt_receiver_receive_socket(DltReceiver *receiver); + /** + * Receive data from file/fifo using the dlt receiver structure + * @param receiver pointer to dlt receiver structure + * @return negative value if there was an error + */ + int dlt_receiver_receive_fd(DltReceiver *receiver); + /** + * Remove a specific size of bytes from the received data + * @param receiver pointer to dlt receiver structure + * @param size amount of bytes to be removed + * @return negative value if there was an error + */ + int dlt_receiver_remove(DltReceiver *receiver,int size); + /** + * Move data from last receive call to front of receive buffer + * @param receiver pointer to dlt receiver structure + * @return negative value if there was an error + */ + int dlt_receiver_move_to_begin(DltReceiver *receiver); + + /** + * Fill out storage header of a dlt message + * @param storageheader pointer to storage header of a dlt message + * @param ecu name of ecu to be set in storage header + * @return negative value if there was an error + */ + int dlt_set_storageheader(DltStorageHeader *storageheader, const char *ecu); + /** + * Check if a storage header contains its marker + * @param storageheader pointer to storage header of a dlt message + * @return 0 no, 1 yes, negative value if there was an error + */ + int dlt_check_storageheader(DltStorageHeader *storageheader); + + /** + * Initialize ringbuffer of with a maximum size of size + * @param dltbuf Pointer to ringbuffer structure + * @param size Maximum size of buffer in bytes + * @return negative value if there was an error + */ + int dlt_ringbuffer_init(DltRingBuffer *dltbuf, uint32_t size); + + /** + * Release and free memory used by ringbuffer + * @param dltbuf Pointer to ringbuffer structure + * @return negative value if there was an error + */ + int dlt_ringbuffer_free(DltRingBuffer *dltbuf); + + /** + * Write one entry to ringbuffer + * @param dltbuf Pointer to ringbuffer structure + * @param data Pointer to data to be written to ringbuffer + * @param size Size of data in bytes to be written to ringbuffer + * @return negative value if there was an error + */ + int dlt_ringbuffer_put(DltRingBuffer *dltbuf, void *data, uint32_t size); + + /** + * Write one entry given as 3 chunks to ringbuffer + * @param dltbuf Pointer to ringbuffer structure + * @param data1 Pointer to data1 to be written to ringbuffer + * @param size1 Size of data1 in bytes to be written to ringbuffer + * @param data2 Pointer to data2 to be written to ringbuffer + * @param size2 Size of data2 in bytes to be written to ringbuffer + * @param data3 Pointer to data3 to be written to ringbuffer + * @param size3 Size of data3 in bytes to be written to ringbuffer + * @return negative value if there was an error + */ + int dlt_ringbuffer_put3(DltRingBuffer *dltbuf, void *data1, uint32_t size1, void *data2, uint32_t size2, void *data3, uint32_t size3); + + /** + * Read one entry from ringbuffer + * @param dltbuf Pointer to ringbuffer structure + * @param data Pointer to data read from ringbuffer + * @param size Size of read data in bytes from ringbuffer + * @return negative value if there was an error + */ + int dlt_ringbuffer_get(DltRingBuffer *dltbuf, void *data, size_t *size); + + /** + * Helper function: Skip one readable entry in ringbuffer + * @param dltbuf Pointer to ringbuffer structure + * @return negative value if there was an error + */ + int dlt_ringbuffer_get_skip(DltRingBuffer *dltbuf); + + /** + * Helper function: Get free space in bytes for writting between write and read position + * @param dltbuf Pointer to ringbuffer structure + * @param freespace Free Space in bytes for writting is returned + * @return negative value if there was an error + */ + int dlt_ringbuffer_freespacewrite(DltRingBuffer *dltbuf, uint32_t *freespace); + + /** + * Helper function: Check free space and if necessary discard entries, so that at least + * reqspace bytes are available for writting + * @param dltbuf Pointer to ringbuffer structure + * @param reqspace Requested space for writting in bytes + * @return negative value if there was an error + */ + int dlt_ringbuffer_checkandfreespace(DltRingBuffer *dltbuf, uint32_t reqspace); + +#if !defined (__WIN32__) + + /** + * Helper function: Setup serial connection + * @param fd File descriptor of serial tty device + * @param speed Serial line speed, as defined in termios.h + * @return negative value if there was an error + */ + int dlt_setup_serial(int fd, speed_t speed); + + /** + * Helper function: Convert serial line baudrate (as number) to line speed (as defined in termios.h) + * @param baudrate Serial line baudrate (as number) + * @return Serial line speed, as defined in termios.h + */ + speed_t dlt_convert_serial_speed(int baudrate); + + /** + * Print dlt version and dlt svn version to buffer + * @param buf Pointer to buffer + */ + void dlt_get_version(char *buf); + +#endif + + /* Function prototypes which should be used only internally */ + /* */ + + /** + * Common part of initialisation + * @return negative value if there was an error + */ + int dlt_init_common(void); + + /** + * Return the uptime of the system in 0.1 ms resolution + * @return 0 if there was an error + */ + uint32_t dlt_uptime(void); + + /** + * Print header of a DLT message + * @param message pointer to structure of organising access to DLT messages + * @param text pointer to a ASCII string, in which the header is written + * @param size maximal size of text buffer + * @param verbose if set to true verbose information is printed out. + * @return negative value if there was an error + */ + int dlt_message_print_header(DltMessage *message, char *text, uint32_t size, int verbose); + + /** + * Print payload of a DLT message as Hex-Output + * @param message pointer to structure of organising access to DLT messages + * @param text pointer to a ASCII string, in which the output is written + * @param size maximal size of text buffer + * @param verbose if set to true verbose information is printed out. + * @return negative value if there was an error + */ + int dlt_message_print_hex(DltMessage *message, char *text, uint32_t size, int verbose); + + /** + * Print payload of a DLT message as ASCII-Output + * @param message pointer to structure of organising access to DLT messages + * @param text pointer to a ASCII string, in which the output is written + * @param size maximal size of text buffer + * @param verbose if set to true verbose information is printed out. + * @return negative value if there was an error + */ + int dlt_message_print_ascii(DltMessage *message, char *text, uint32_t size, int verbose); + + /** + * Print payload of a DLT message as Mixed-Ouput (Hex and ASCII), for plain text output + * @param message pointer to structure of organising access to DLT messages + * @param text pointer to a ASCII string, in which the output is written + * @param size maximal size of text buffer + * @param verbose if set to true verbose information is printed out. + * @return negative value if there was an error + */ + int dlt_message_print_mixed_plain(DltMessage *message, char *text, uint32_t size, int verbose); + + /** + * Print payload of a DLT message as Mixed-Ouput (Hex and ASCII), for HTML text output + * @param message pointer to structure of organising access to DLT messages + * @param text pointer to a ASCII string, in which the output is written + * @param size maximal size of text buffer + * @param verbose if set to true verbose information is printed out. + * @return negative value if there was an error + */ + int dlt_message_print_mixed_html(DltMessage *message, char *text, uint32_t size, int verbose); + + /** + * Decode and print a argument of a DLT message + * @param msg pointer to structure of organising access to DLT messages + * @param type_info Type of argument + * @param ptr pointer to pointer to data (pointer to data is changed within this function) + * @param datalength pointer to datalength (datalength is changed within this function) + * @param text pointer to a ASCII string, in which the output is written + * @param textlength maximal size of text buffer + * @param byteLength If argument is a string, and this value is 0 or greater, this value will be taken as string length + * @param verbose if set to true verbose information is printed out. + * @return negative value if there was an error + */ + int dlt_message_argument_print(DltMessage *msg,uint32_t type_info,uint8_t **ptr,int32_t *datalength,char *text,int textlength,int byteLength,int verbose); + +#ifdef __cplusplus +} +#endif + +/** + \} +*/ + +#endif /* DLT_COMMON_H */ diff --git a/include/dlt/dlt_protocol.h b/include/dlt/dlt_protocol.h new file mode 100755 index 0000000..88f7d89 --- /dev/null +++ b/include/dlt/dlt_protocol.h @@ -0,0 +1,218 @@ +/*
+ * Dlt- Diagnostic Log and Trace protocol defines
+ * @licence app begin@ + * + * Copyright (C) 2011, BMW AG - Alexander Wenzel <alexander.wenzel@bmw.de> + * + * This program is free software; you can redistribute it and/or modify it under the terms of the + * GNU Lesser General Public License, version 2.1, as published by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License, version 2.1, for more details. + * + * You should have received a copy of the GNU Lesser General Public License, version 2.1, along + * with this program; if not, see <http://www.gnu.org/licenses/lgpl-2.1.html>. + * + * Note that the copyright holders assume that the GNU Lesser General Public License, version 2.1, may + * also be applicable to programs even in cases in which the program is not a library in the technical sense. + * + * Linking DLT statically or dynamically with other modules is making a combined work based on DLT. You may + * license such other modules under the GNU Lesser General Public License, version 2.1. If you do not want to + * license your linked modules under the GNU Lesser General Public License, version 2.1, you + * may use the program under the following exception. + * + * As a special exception, the copyright holders of DLT give you permission to combine DLT + * with software programs or libraries that are released under any license unless such a combination is not + * permitted by the license of such a software program or library. You may copy and distribute such a + * system following the terms of the GNU Lesser General Public License, version 2.1, including this + * special exception, for DLT and the licenses of the other code concerned. + * + * Note that people who make modified versions of DLT are not obligated to grant this special exception + * for their modified versions; it is their choice whether to do so. The GNU Lesser General Public License, + * version 2.1, gives permission to release a modified version without this exception; this exception + * also makes it possible to release a modified version which carries forward this exception. + * + * @licence end@
+ */
+
+
+/*******************************************************************************
+** **
+** SRC-MODULE: dlt_protocol.h **
+** **
+** TARGET : linux ** +** ** +** PROJECT : DLT ** +** ** +** AUTHOR : Alexander Wenzel Alexander.AW.Wenzel@bmw.de ** +** Markus Klein ** +** ** +** PURPOSE : ** +** ** +** REMARKS : ** +** ** +** PLATFORM DEPENDANT [yes/no]: yes ** +** ** +** TO BE CHANGED BY USER [yes/no]: no ** +** ** +*******************************************************************************/ + +/******************************************************************************* +** Author Identity ** +******************************************************************************** +** ** +** Initials Name Company ** +** -------- ------------------------- ---------------------------------- ** +** aw Alexander Wenzel BMW ** +** mk Markus Klein Fraunhofer ESK ** +*******************************************************************************/
+
+/*******************************************************************************
+** Revision Control History **
+*******************************************************************************/
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ Initials Date Comment
+ aw 13.01.2010 initial
+ */
+#ifndef DLT_PROTOCOL_H
+#define DLT_PROTOCOL_H
+
+/**
+ \defgroup protocolapi DLT Protocol API
+ \addtogroup protocolapi
+ \{
+*/
+
+/*
+ * Definitions of the htyp parameter in standard header.
+ */
+#define DLT_HTYP_UEH 0x01 /**< use extended header */
+#define DLT_HTYP_MSBF 0x02 /**< MSB first */
+#define DLT_HTYP_WEID 0x04 /**< with ECU ID */
+#define DLT_HTYP_WSID 0x08 /**< with session ID */
+#define DLT_HTYP_WTMS 0x10 /**< with timestamp */
+#define DLT_HTYP_VERS 0xe0 /**< version number, 0x1 */
+
+#define DLT_IS_HTYP_UEH(htyp) ((htyp) & DLT_HTYP_UEH)
+#define DLT_IS_HTYP_MSBF(htyp) ((htyp) & DLT_HTYP_MSBF)
+#define DLT_IS_HTYP_WEID(htyp) ((htyp) & DLT_HTYP_WEID)
+#define DLT_IS_HTYP_WSID(htyp) ((htyp) & DLT_HTYP_WSID)
+#define DLT_IS_HTYP_WTMS(htyp) ((htyp) & DLT_HTYP_WTMS)
+
+#define DLT_HTYP_PROTOCOL_VERSION1 (1<<5)
+
+/*
+ * Definitions of msin parameter in extended header.
+ */
+#define DLT_MSIN_VERB 0x01 /**< verbose */
+#define DLT_MSIN_MSTP 0x0e /**< message type */
+#define DLT_MSIN_MTIN 0xf0 /**< message type info */
+
+#define DLT_MSIN_MSTP_SHIFT 1 /**< shift right offset to get mstp value */
+#define DLT_MSIN_MTIN_SHIFT 4 /**< shift right offset to get mtin value */
+
+#define DLT_IS_MSIN_VERB(msin) ((msin) & DLT_MSIN_VERB)
+#define DLT_GET_MSIN_MSTP(msin) (((msin) & DLT_MSIN_MSTP) >> DLT_MSIN_MSTP_SHIFT)
+#define DLT_GET_MSIN_MTIN(msin) (((msin) & DLT_MSIN_MTIN) >> DLT_MSIN_MTIN_SHIFT)
+
+/*
+ * Definitions of mstp parameter in extended header.
+ */
+#define DLT_TYPE_LOG 0x00 /**< Log message type */
+#define DLT_TYPE_APP_TRACE 0x01 /**< Application trace message type */
+#define DLT_TYPE_NW_TRACE 0x02 /**< Network trace message type */
+#define DLT_TYPE_CONTROL 0x03 /**< Control message type */
+
+/*
+ * Definitions of msti parameter in extended header.
+ */
+#define DLT_TRACE_VARIABLE 0x01 /**< tracing of a variable */
+#define DLT_TRACE_FUNCTION_IN 0x02 /**< tracing of function calls */
+#define DLT_TRACE_FUNCTION_OUT 0x03 /**< tracing of function return values */
+#define DLT_TRACE_STATE 0x04 /**< tracing of states of a state machine */
+#define DLT_TRACE_VFB 0x05 /**< tracing of virtual function bus */
+
+/*
+ * Definitions of msbi parameter in extended header.
+ */ + +/* see file dlt_user.h */ +
+/*
+ * Definitions of msci parameter in extended header.
+ */
+#define DLT_CONTROL_REQUEST 0x01 /**< Request message */
+#define DLT_CONTROL_RESPONSE 0x02 /**< Response to request message */
+#define DLT_CONTROL_TIME 0x03 /**< keep-alive message */
+
+#define DLT_MSIN_CONTROL_REQUEST ((DLT_TYPE_CONTROL << DLT_MSIN_MSTP_SHIFT) | (DLT_CONTROL_REQUEST << DLT_MSIN_MTIN_SHIFT))
+#define DLT_MSIN_CONTROL_RESPONSE ((DLT_TYPE_CONTROL << DLT_MSIN_MSTP_SHIFT) | (DLT_CONTROL_RESPONSE << DLT_MSIN_MTIN_SHIFT)) +#define DLT_MSIN_CONTROL_TIME ((DLT_TYPE_CONTROL << DLT_MSIN_MSTP_SHIFT) | (DLT_CONTROL_TIME << DLT_MSIN_MTIN_SHIFT))
+
+/*
+ * Definitions of types of arguments in payload.
+ */
+#define DLT_TYPE_INFO_TYLE 0x0000000f /**< Length of standard data: 1 = 8bit, 2 = 16bit, 3 = 32 bit, 4 = 64 bit, 5 = 128 bit */
+#define DLT_TYPE_INFO_BOOL 0x00000010 /**< Boolean data */
+#define DLT_TYPE_INFO_SINT 0x00000020 /**< Signed integer data */
+#define DLT_TYPE_INFO_UINT 0x00000040 /**< Unsigned integer data */
+#define DLT_TYPE_INFO_FLOA 0x00000080 /**< Float data */
+#define DLT_TYPE_INFO_ARAY 0x00000100 /**< Array of standard types */
+#define DLT_TYPE_INFO_STRG 0x00000200 /**< String */
+#define DLT_TYPE_INFO_RAWD 0x00000400 /**< Raw data */
+#define DLT_TYPE_INFO_VARI 0x00000800 /**< Set, if additional information to a variable is available */
+#define DLT_TYPE_INFO_FIXP 0x00001000 /**< Set, if quantization and offset are added */
+#define DLT_TYPE_INFO_TRAI 0x00002000 /**< Set, if additional trace information is added */
+#define DLT_TYPE_INFO_STRU 0x00004000 /**< Struct */
+#define DLT_TYPE_INFO_SCOD 0x00038000 /**< coding of the type string: 0 = ASCII, 1 = UTF-8 */
+
+#define DLT_TYLE_8BIT 1
+#define DLT_TYLE_16BIT 2
+#define DLT_TYLE_32BIT 3
+#define DLT_TYLE_64BIT 4
+#define DLT_TYLE_128BIT 5
+
+#define DLT_SCOD_ASCII 0
+#define DLT_SCOD_UTF8 1
+
+/*
+ * Definitions of DLT services.
+ */
+#define DLT_SERVICE_ID_SET_LOG_LEVEL 0x01 /**< Service ID: Set log level */
+#define DLT_SERVICE_ID_SET_TRACE_STATUS 0x02 /**< Service ID: Set trace status */
+#define DLT_SERVICE_ID_GET_LOG_INFO 0x03 /**< Service ID: Get log info */
+#define DLT_SERVICE_ID_GET_DEFAULT_LOG_LEVEL 0x04 /**< Service ID: Get dafault log level */
+#define DLT_SERVICE_ID_STORE_CONFIG 0x05 /**< Service ID: Store configuration */
+#define DLT_SERVICE_ID_RESET_TO_FACTORY_DEFAULT 0x06 /**< Service ID: Reset to factory defaults */
+#define DLT_SERVICE_ID_SET_COM_INTERFACE_STATUS 0x07 /**< Service ID: Set communication interface status */
+#define DLT_SERVICE_ID_SET_COM_INTERFACE_MAX_BANDWIDTH 0x08 /**< Service ID: Set communication interface maximum bandwidth */
+#define DLT_SERVICE_ID_SET_VERBOSE_MODE 0x09 /**< Service ID: Set verbose mode */
+#define DLT_SERVICE_ID_SET_MESSAGE_FILTERING 0x0A /**< Service ID: Set message filtering */
+#define DLT_SERVICE_ID_SET_TIMING_PACKETS 0x0B /**< Service ID: Set timing packets */
+#define DLT_SERVICE_ID_GET_LOCAL_TIME 0x0C /**< Service ID: Get local time */
+#define DLT_SERVICE_ID_USE_ECU_ID 0x0D /**< Service ID: Use ECU id */
+#define DLT_SERVICE_ID_USE_SESSION_ID 0x0E /**< Service ID: Use session id */
+#define DLT_SERVICE_ID_USE_TIMESTAMP 0x0F /**< Service ID: Use timestamp */
+#define DLT_SERVICE_ID_USE_EXTENDED_HEADER 0x10 /**< Service ID: Use extended header */
+#define DLT_SERVICE_ID_SET_DEFAULT_LOG_LEVEL 0x11 /**< Service ID: Set default log level */
+#define DLT_SERVICE_ID_SET_DEFAULT_TRACE_STATUS 0x12 /**< Service ID: Set default trace status */
+#define DLT_SERVICE_ID_GET_SOFTWARE_VERSION 0x13 /**< Service ID: Get software version */
+#define DLT_SERVICE_ID_MESSAGE_BUFFER_OVERFLOW 0x14 /**< Service ID: Message buffer overflow */
+#define DLT_SERVICE_ID_CALLSW_CINJECTION 0xFFF /**< Service ID: Message Injection (minimal ID) */
+
+/*
+ * Definitions of DLT service response status
+ */
+#define DLT_SERVICE_RESPONSE_OK 0x00 /**< Control message response: OK */
+#define DLT_SERVICE_RESPONSE_NOT_SUPPORTED 0x01 /**< Control message response: Not supported */
+#define DLT_SERVICE_RESPONSE_ERROR 0x02 /**< Control message response: Error */
+
+/**
+ \}
+*/
+
+#endif /* DLT_PROTOCOL_H */
diff --git a/include/dlt/dlt_types.h b/include/dlt/dlt_types.h new file mode 100755 index 0000000..e1372ef --- /dev/null +++ b/include/dlt/dlt_types.h @@ -0,0 +1,97 @@ +/*
+ * Dlt- Diagnostic Log and Trace
+ * @licence app begin@ + * + * Copyright (C) 2011, BMW AG - Alexander Wenzel <alexander.wenzel@bmw.de> + * + * This program is free software; you can redistribute it and/or modify it under the terms of the + * GNU Lesser General Public License, version 2.1, as published by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License, version 2.1, for more details. + * + * You should have received a copy of the GNU Lesser General Public License, version 2.1, along + * with this program; if not, see <http://www.gnu.org/licenses/lgpl-2.1.html>. + * + * Note that the copyright holders assume that the GNU Lesser General Public License, version 2.1, may + * also be applicable to programs even in cases in which the program is not a library in the technical sense. + * + * Linking DLT statically or dynamically with other modules is making a combined work based on DLT. You may + * license such other modules under the GNU Lesser General Public License, version 2.1. If you do not want to + * license your linked modules under the GNU Lesser General Public License, version 2.1, you + * may use the program under the following exception. + * + * As a special exception, the copyright holders of DLT give you permission to combine DLT + * with software programs or libraries that are released under any license unless such a combination is not + * permitted by the license of such a software program or library. You may copy and distribute such a + * system following the terms of the GNU Lesser General Public License, version 2.1, including this + * special exception, for DLT and the licenses of the other code concerned. + * + * Note that people who make modified versions of DLT are not obligated to grant this special exception + * for their modified versions; it is their choice whether to do so. The GNU Lesser General Public License, + * version 2.1, gives permission to release a modified version without this exception; this exception + * also makes it possible to release a modified version which carries forward this exception. + * + * @licence end@
+ */
+
+
+/*******************************************************************************
+** **
+** SRC-MODULE: dlt_types.h **
+** **
+** TARGET : linux ** +** ** +** PROJECT : DLT ** +** ** +** AUTHOR : Alexander Wenzel Alexander.AW.Wenzel@bmw.de ** +** Markus Klein ** +** ** +** PURPOSE : ** +** ** +** REMARKS : ** +** ** +** PLATFORM DEPENDANT [yes/no]: yes ** +** ** +** TO BE CHANGED BY USER [yes/no]: no ** +** ** +*******************************************************************************/ + +/******************************************************************************* +** Author Identity ** +******************************************************************************** +** ** +** Initials Name Company ** +** -------- ------------------------- ---------------------------------- ** +** aw Alexander Wenzel BMW ** +** mk Markus Klein Fraunhofer ESK ** +*******************************************************************************/ + +#ifndef DLT_TYPES_H +#define DLT_TYPES_H + +#ifdef _MSC_VER
+ typedef __int64 int64_t;
+ typedef __int32 int32_t;
+ typedef __int16 int16_t;
+ typedef __int8 int8_t;
+
+ typedef unsigned __int64 uint64_t;
+ typedef unsigned __int32 uint32_t;
+ typedef unsigned __int16 uint16_t;
+ typedef unsigned __int8 uint8_t;
+
+ typedef int pid_t;
+ typedef unsigned int speed_t;
+ + #define UINT16_MAX 0xFFFF + + #include <varargs.h> +#else +#include <stdint.h> +#endif + +typedef float float32_t; +typedef double float64_t; + +#endif /* DLT_TYPES_H */ diff --git a/include/dlt/dlt_user.h b/include/dlt/dlt_user.h new file mode 100755 index 0000000..a1b6229 --- /dev/null +++ b/include/dlt/dlt_user.h @@ -0,0 +1,542 @@ +/* + * Dlt- Diagnostic Log and Trace console apps + * @licence app begin@ + * + * Copyright (C) 2011, BMW AG - Alexander Wenzel <alexander.wenzel@bmw.de> + * + * This program is free software; you can redistribute it and/or modify it under the terms of the + * GNU Lesser General Public License, version 2.1, as published by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License, version 2.1, for more details. + * + * You should have received a copy of the GNU Lesser General Public License, version 2.1, along + * with this program; if not, see <http://www.gnu.org/licenses/lgpl-2.1.html>. + * + * Note that the copyright holders assume that the GNU Lesser General Public License, version 2.1, may + * also be applicable to programs even in cases in which the program is not a library in the technical sense. + * + * Linking DLT statically or dynamically with other modules is making a combined work based on DLT. You may + * license such other modules under the GNU Lesser General Public License, version 2.1. If you do not want to + * license your linked modules under the GNU Lesser General Public License, version 2.1, you + * may use the program under the following exception. + * + * As a special exception, the copyright holders of DLT give you permission to combine DLT + * with software programs or libraries that are released under any license unless such a combination is not + * permitted by the license of such a software program or library. You may copy and distribute such a + * system following the terms of the GNU Lesser General Public License, version 2.1, including this + * special exception, for DLT and the licenses of the other code concerned. + * + * Note that people who make modified versions of DLT are not obligated to grant this special exception + * for their modified versions; it is their choice whether to do so. The GNU Lesser General Public License, + * version 2.1, gives permission to release a modified version without this exception; this exception + * also makes it possible to release a modified version which carries forward this exception. + * + * @licence end@ + */ + + +/******************************************************************************* +** ** +** SRC-MODULE: dlt_user.h ** +** ** +** TARGET : linux ** +** ** +** PROJECT : DLT ** +** ** +** AUTHOR : Alexander Wenzel Alexander.AW.Wenzel@bmw.de ** +** Markus Klein ** +** ** +** PURPOSE : ** +** ** +** REMARKS : ** +** ** +** PLATFORM DEPENDANT [yes/no]: yes ** +** ** +** TO BE CHANGED BY USER [yes/no]: no ** +** ** +*******************************************************************************/ + +/******************************************************************************* +** Author Identity ** +******************************************************************************** +** ** +** Initials Name Company ** +** -------- ------------------------- ---------------------------------- ** +** aw Alexander Wenzel BMW ** +** mk Markus Klein Fraunhofer ESK ** +*******************************************************************************/ + +/******************************************************************************* +** Revision Control History ** +*******************************************************************************/ + +/* + * $LastChangedRevision: 1670 $ + * $LastChangedDate: 2011-04-08 15:12:06 +0200 (Fr, 08. Apr 2011) $ + * $LastChangedBy$ + Initials Date Comment + aw 13.01.2010 initial + */ + +#ifndef DLT_USER_H +#define DLT_USER_H + +/** + \defgroup userapi DLT User API + \addtogroup userapi + \{ +*/ + +#include "dlt_types.h" +#include "dlt_common.h" +#include "dlt_user_macros.h" + +#if !defined (__WIN32__) +#include <semaphore.h> +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Definitions of DLT log level + */ +typedef enum +{ + DLT_LOG_DEFAULT = -1, /**< Default log level */ + DLT_LOG_OFF = 0x00, /**< Log level off */ + DLT_LOG_FATAL = 0x01, /**< fatal system error */ + DLT_LOG_ERROR = 0x02, /**< error with impact to correct functionality */ + DLT_LOG_WARN = 0x03, /**< warning, correct behaviour could not be ensured */ + DLT_LOG_INFO = 0x04, /**< informational */ + DLT_LOG_DEBUG = 0x05, /**< debug */ + DLT_LOG_VERBOSE = 0x06 /**< highest grade of information */ +} DltLogLevelType; + +/** + * Definitions of DLT trace status + */ +typedef enum +{ + DLT_TRACE_STATUS_DEFAULT = -1, /**< Default trace status */ + DLT_TRACE_STATUS_OFF = 0x00, /**< Trace status: Off */ + DLT_TRACE_STATUS_ON = 0x01 /**< Trace status: On */ +} DltTraceStatusType; + +/** + * Definitions for dlt_user_trace_network/DLT_TRACE_NETWORK() + * as defined in the DLT protocol + */ +typedef enum +{ + DLT_NW_TRACE_IPC = 0x01, /**< Interprocess communication */ + DLT_NW_TRACE_CAN = 0x02, /**< Controller Area Network Bus */ + DLT_NW_TRACE_FLEXRAY = 0x03, /**< Flexray Bus */ + DLT_NW_TRACE_MOST = 0x04, /**< Media Oriented System Transport Bus */ + DLT_NW_TRACE_RESERVED0 = 0x05, + DLT_NW_TRACE_RESERVED1 = 0x06, + DLT_NW_TRACE_RESERVED2 = 0x07, + DLT_NW_TRACE_USER_DEFINED0 = 0x08, + DLT_NW_TRACE_USER_DEFINED1 = 0x09, + DLT_NW_TRACE_USER_DEFINED2 = 0x0A, + DLT_NW_TRACE_USER_DEFINED3 = 0x0B, + DLT_NW_TRACE_USER_DEFINED4 = 0x0C, + DLT_NW_TRACE_USER_DEFINED5 = 0x0D, + DLT_NW_TRACE_USER_DEFINED6 = 0x0E, + DLT_NW_TRACE_USER_DEFINED7 = 0x0F +} DltNetworkTraceType; + +#define DLT_USER_BUF_MAX_SIZE 2048 /**< maximum size of each user buffer, also used for injection buffer */ + +/* Use a semaphore or mutex from your OS to prevent concurrent access to the DLT buffer. */ +#define DLT_SEM_LOCK() { sem_wait(&dlt_mutex); } +#define DLT_SEM_FREE() { sem_post(&dlt_mutex); } + +/** + * This structure is used for every context used in an application. + */ +typedef struct +{ + char contextID[4]; /**< context id */ + int32_t log_level_pos; /**< offset in user-application context field */ +} DltContext; + +/** + * This structure is used for context data used in an application. + */ +typedef struct +{ + DltContext *handle; /**< pointer to DltContext */ + unsigned char buffer[DLT_USER_BUF_MAX_SIZE]; /**< buffer for building log message*/ + int32_t size; /**< payload size */ + int32_t log_level; /**< log level */ + int32_t trace_status; /**< trace status */ + int32_t args_num; /**< number of arguments for extended header*/ + uint8_t mcnt; /**< message counter */ + char* context_description; /**< description of context */ +} DltContextData; + +typedef struct +{ + uint32_t service_id; + int (*injection_callback)(uint32_t service_id, void *data, uint32_t length); +} DltUserInjectionCallback; + +/** + * This structure is used in a table managing all contexts and the corresponding log levels in an application. + */ +typedef struct +{ + char contextID[DLT_ID_SIZE]; /**< Context ID */ + int8_t log_level; /**< Log level */ + int8_t trace_status; /**< Trace status */ + char *context_description; /**< description of context */ + DltUserInjectionCallback *injection_table; /**< Table with pointer to injection functions and service ids */ + uint32_t nrcallbacks; +} dlt_ll_ts_type; + +/** + * This structure is used once for one application. + */ +typedef struct +{ + char ecuID[DLT_ID_SIZE]; /**< ECU ID */ + char appID[DLT_ID_SIZE]; /**< Application ID */ + int dlt_log_handle; /**< Handle to fifo of dlt daemon */ + int dlt_user_handle; /**< Handle to own fifo */ + + int8_t dlt_is_file; /**< Target of logging: 1 to file, 0 to daemon */ + + dlt_ll_ts_type *dlt_ll_ts; //[MAX_DLT_LL_TS_ENTRIES]; /**< Internal management struct for all contexts */ + uint32_t dlt_ll_ts_max_num_entries; /**< Maximum number of contexts */ + + uint32_t dlt_ll_ts_num_entries; /**< Number of used contexts */ + + int8_t overflow; /**< Overflow marker, set to 1 on overflow, 0 otherwise */ + + char *application_description; /**< description of application */ + + DltReceiver receiver; /**< Receiver for internal user-defined messages from daemon */ + + int8_t verbose_mode; /**< Verbose mode enabled: 1 enabled, 0 disabled */ + + int8_t enable_local_print; /**< Local printing of log messages: 1 enabled, 0 disabled */ + int8_t local_print_mode; /**< Local print mode, controlled by environment variable */ + + DltRingBuffer rbuf; /**< Ring-buffer for buffering messages during startup and missing connection */ +} DltUser; + +/************************************************************************************************** +* The folowing API functions define a low level function interface for DLT +**************************************************************************************************/ + +/** + * Initialise the generation of a DLT log message (intended for usage in non-verbose mode) + * This function has to be called first, when an application wants to send a new log messages. + * @param handle pointer to an object containing information about one special logging context + * @param log pointer to an object containing information about logging context data + * @param loglevel this is the current log level of the log message to be sent + * @return negative value if there was an error + */ +int dlt_user_log_write_start(DltContext *handle, DltContextData *log, DltLogLevelType loglevel); + +/** + * Initialise the generation of a DLT log message (intended for usage in verbose mode) + * This function has to be called first, when an application wants to send a new log messages. + * @param handle pointer to an object containing information about one special logging context + * @param log pointer to an object containing information about logging context data + * @param loglevel this is the current log level of the log message to be sent + * @param messageid message id of message + * @return negative value if there was an error + */ +int dlt_user_log_write_start_id(DltContext *handle, DltContextData *log, DltLogLevelType loglevel, uint32_t messageid); + +/** + * Finishing the generation of a DLT log message and sending it to the DLT daemon. + * This function has to be called after writing all the log attributes of a log message. + * @param log pointer to an object containing information about logging context data + * @return negative value if there was an error + */ +int dlt_user_log_write_finish(DltContextData *log); + +/** + * Write a boolean parameter into a DLT log message. + * dlt_user_log_write_start has to be called before adding any attributes to the log message. + * Finish sending log message by calling dlt_user_log_write_finish. + * @param log pointer to an object containing information about logging context data + * @param data boolean parameter written into log message (mapped to uint8) + * @return negative value if there was an error + */ +int dlt_user_log_write_bool(DltContextData *log, uint8_t data); + +/** + * Write a float parameter into a DLT log message. + * dlt_user_log_write_start has to be called before adding any attributes to the log message. + * Finish sending log message by calling dlt_user_log_write_finish. + * @param log pointer to an object containing information about logging context data + * @param data float32_t parameter written into log message. + * @return negative value if there was an error + */ +int dlt_user_log_write_float32(DltContextData *log, float32_t data); + +/** + * Write a double parameter into a DLT log message. + * dlt_user_log_write_start has to be called before adding any attributes to the log message. + * Finish sending log message by calling dlt_user_log_write_finish. + * @param log pointer to an object containing information about logging context data + * @param data float64_t parameter written into log message. + * @return negative value if there was an error + */ +int dlt_user_log_write_float64(DltContextData *log, double data); + +/** + * Write a uint parameter into a DLT log message. + * dlt_user_log_write_start has to be called before adding any attributes to the log message. + * Finish sending log message by calling dlt_user_log_write_finish. + * @param log pointer to an object containing information about logging context data + * @param data unsigned int parameter written into log message. + * @return negative value if there was an error + */ +int dlt_user_log_write_uint(DltContextData *log, unsigned int data); +int dlt_user_log_write_uint8(DltContextData *log, uint8_t data); +int dlt_user_log_write_uint16(DltContextData *log, uint16_t data); +int dlt_user_log_write_uint32(DltContextData *log, uint32_t data); +int dlt_user_log_write_uint64(DltContextData *log, uint64_t data); +/** + * Write a int parameter into a DLT log message. + * dlt_user_log_write_start has to be called before adding any attributes to the log message. + * Finish sending log message by calling dlt_user_log_write_finish. + * @param log pointer to an object containing information about logging context data + * @param data int parameter written into log message. + * @return negative value if there was an error + */ +int dlt_user_log_write_int(DltContextData *log, int data); +int dlt_user_log_write_int8(DltContextData *log, int8_t data); +int dlt_user_log_write_int16(DltContextData *log, int16_t data); +int dlt_user_log_write_int32(DltContextData *log, int32_t data); +int dlt_user_log_write_int64(DltContextData *log, int64_t data); +/** + * Write a null terminated ASCII string into a DLT log message. + * dlt_user_log_write_start has to be called before adding any attributes to the log message. + * Finish sending log message by calling dlt_user_log_write_finish. + * @param log pointer to an object containing information about logging context data + * @param text pointer to the parameter written into log message containing null termination. + * @return negative value if there was an error + */ +int dlt_user_log_write_string( DltContextData *log, const char *text); + +/** + * Write a binary memory block into a DLT log message. + * dlt_user_log_write_start has to be called before adding any attributes to the log message. + * Finish sending log message by calling dlt_user_log_write_finish. + * @param log pointer to an object containing information about logging context data + * @param data pointer to the parameter written into log message. + * @param length length in bytes of the parameter written into log message. + * @return negative value if there was an error + */ +int dlt_user_log_write_raw(DltContextData *log,void *data,uint16_t length); + +/** + * Trace network message + * @param handle pointer to an object containing information about one special logging context + * @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) + * @param header_len length of network message header + * @param header pointer to network message header + * @param payload_len length of network message payload + * @param payload pointer to network message payload + * @return negative value if there was an error + */ +int dlt_user_trace_network(DltContext *handle, DltNetworkTraceType nw_trace_type, uint16_t header_len, void *header, uint16_t payload_len, void *payload); + +/************************************************************************************************** +* The folowing API functions define a high level function interface for DLT +**************************************************************************************************/ + +/** + * Initialise the user lib communication with daemon. + * This function has to be called first, before using any DLT user lib functions. + * @return negative value if there was an error + */ +int dlt_init(); + +/** + * Initialise the user lib writing only to file. + * This function has to be called first, before using any DLT user lib functions. + * @param name name of an optional log file + * @return negative value if there was an error + */ +int dlt_init_file(const char *name); + +/** + * Terminate the user lib. + * This function has to be called when finishing using the DLT user lib. + * @return negative value if there was an error + */ +int dlt_free(); + +/** + * Register an application in the daemon. + * @param appid four byte long character array with the application id + * @param description long name of the application + * @return negative value if there was an error + */ +int dlt_register_app(const char *appid, const char * description); + +/** + * Unregister an application in the daemon. + * This function has to be called when finishing using an application. + * @return negative value if there was an error + */ +int dlt_unregister_app(void); + +/** + * Register a context in the daemon. + * This function has to be called before first usage of the context. + * @param handle pointer to an object containing information about one special logging context + * @param contextid four byte long character array with the context id + * @param description long name of the context + * @return negative value if there was an error + */ +int dlt_register_context(DltContext *handle, const char *contextid, const char * description); + +/** + * Register a context in the daemon with pre-defined log level and pre-defined trace status. + * This function has to be called before first usage of the context. + * @param handle pointer to an object containing information about one special logging context + * @param contextid four byte long character array with the context id + * @param description long name of the context + * @param loglevel This is the log level to be pre-set for this context + (DLT_LOG_DEFAULT is not allowed here) + * @param tracestatus This is the trace status to be pre-set for this context + (DLT_TRACE_STATUS_DEFAULT is not allowed here) + * @return negative value if there was an error + */ +int dlt_register_context_ll_ts(DltContext *handle, const char *contextid, const char * description, int loglevel, int tracestatus); + +/** + * Unregister a context in the DLT daemon. + * This function has to be called when finishing using a context. + * @param handle pointer to an object containing information about one special logging context + * @return negative value if there was an error + */ +int dlt_unregister_context(DltContext *handle); + +/** + * Register callback function called when injection message was received + * @param handle pointer to an object containing information about one special logging context + * @param service_id the service id to be waited for + * @param (*dlt_injection_callback) function pointer to callback function + * @return negative value if there was an error + */ +int dlt_register_injection_callback(DltContext *handle, uint32_t service_id, + int (*dlt_injection_callback)(uint32_t service_id, void *data, uint32_t length)); + +/** + * Switch to verbose mode + * + */ +int dlt_verbose_mode(void); + +/** + * Switch to non-verbose mode + * + */ +int dlt_nonverbose_mode(void); + +/** + * Set maximum logged log level and trace status of application + * + * @param loglevel This is the log level to be set for the whole application + * @param tracestatus This is the trace status to be set for the whole application + * @return negative value if there was an error + */ +int dlt_set_application_ll_ts_limit(DltLogLevelType loglevel, DltTraceStatusType tracestatus); + +/** + * Enable local printing of messages + * + */ +int dlt_enable_local_print(void); + +/** + * Disable local printing of messages + * + */ +int dlt_disable_local_print(void); + +/** + * Write a null terminated ASCII string into a DLT log message. + * @param handle pointer to an object containing information about one special logging context + * @param loglevel this is the current log level of the log message to be sent + * @param text pointer to the ASCII string written into log message containing null termination. + * @return negative value if there was an error + */ +int dlt_log_string(DltContext *handle,DltLogLevelType loglevel, const char *text); + +/** + * Write a null terminated ASCII string and an integer value into a DLT log message. + * @param handle pointer to an object containing information about one special logging context + * @param loglevel this is the current log level of the log message to be sent + * @param text pointer to the ASCII string written into log message containing null termination. + * @param data integer value written into the log message + * @return negative value if there was an error + */ +int dlt_log_string_int(DltContext *handle,DltLogLevelType loglevel, const char *text, int data); + +/** + * Write a null terminated ASCII string and an unsigned integer value into a DLT log message. + * @param handle pointer to an object containing information about one special logging context + * @param loglevel this is the current log level of the log message to be sent + * @param text pointer to the ASCII string written into log message containing null termination. + * @param data unsigned integer value written into the log message + * @return negative value if there was an error + */ +int dlt_log_string_uint(DltContext *handle,DltLogLevelType loglevel, const char *text, unsigned int data); + +/** + * Write an integer value into a DLT log message. + * @param handle pointer to an object containing information about one special logging context + * @param loglevel this is the current log level of the log message to be sent + * @param data integer value written into the log message + * @return negative value if there was an error + */ +int dlt_log_int(DltContext *handle,DltLogLevelType loglevel, int data); + +/** + * Write an unsigned integer value into a DLT log message. + * @param handle pointer to an object containing information about one special logging context + * @param loglevel this is the current log level of the log message to be sent + * @param data unsigned integer value written into the log message + * @return negative value if there was an error + */ +int dlt_log_uint(DltContext *handle,DltLogLevelType loglevel, unsigned int data); + +/** + * Write an unsigned integer value into a DLT log message. + * @param handle pointer to an object containing information about one special logging context + * @param loglevel this is the current log level of the log message to be sent + * @param data pointer to the parameter written into log message. + * @param length length in bytes of the parameter written into log message. + * @return negative value if there was an error + */ +int dlt_log_raw(DltContext *handle,DltLogLevelType loglevel, void *data,uint16_t length); + +/** + * Forward a complete DLT message to the DLT daemon + * @param msgdata Message data of DLT message + * @param size Size of DLT message + * @return negative value if there was an error + */ +int dlt_forward_msg(void *msgdata,size_t size); + +#ifdef __cplusplus +} +#endif + +/** + \} +*/ + +#endif /* DLT_USER_H */ diff --git a/include/dlt/dlt_user_macros.h b/include/dlt/dlt_user_macros.h new file mode 100755 index 0000000..78ef66d --- /dev/null +++ b/include/dlt/dlt_user_macros.h @@ -0,0 +1,414 @@ +/* + * Dlt- Diagnostic Log and Trace console apps + * @licence app begin@ + * + * Copyright (C) 2011, BMW AG - Alexander Wenzel <alexander.wenzel@bmw.de> + * + * This program is free software; you can redistribute it and/or modify it under the terms of the + * GNU Lesser General Public License, version 2.1, as published by the Free Software Foundation. + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General + * Public License, version 2.1, for more details. + * + * You should have received a copy of the GNU Lesser General Public License, version 2.1, along + * with this program; if not, see <http://www.gnu.org/licenses/lgpl-2.1.html>. + * + * Note that the copyright holders assume that the GNU Lesser General Public License, version 2.1, may + * also be applicable to programs even in cases in which the program is not a library in the technical sense. + * + * Linking DLT statically or dynamically with other modules is making a combined work based on DLT. You may + * license such other modules under the GNU Lesser General Public License, version 2.1. If you do not want to + * license your linked modules under the GNU Lesser General Public License, version 2.1, you + * may use the program under the following exception. + * + * As a special exception, the copyright holders of DLT give you permission to combine DLT + * with software programs or libraries that are released under any license unless such a combination is not + * permitted by the license of such a software program or library. You may copy and distribute such a + * system following the terms of the GNU Lesser General Public License, version 2.1, including this + * special exception, for DLT and the licenses of the other code concerned. + * + * Note that people who make modified versions of DLT are not obligated to grant this special exception + * for their modified versions; it is their choice whether to do so. The GNU Lesser General Public License, + * version 2.1, gives permission to release a modified version without this exception; this exception + * also makes it possible to release a modified version which carries forward this exception. + * + * @licence end@ + */ + + +/******************************************************************************* +** ** +** SRC-MODULE: dlt_user_macros.h ** +** ** +** TARGET : linux ** +** ** +** PROJECT : DLT ** +** ** +** AUTHOR : Alexander Wenzel Alexander.AW.Wenzel@bmw.de ** +** Markus Klein ** +** ** +** PURPOSE : ** +** ** +** REMARKS : ** +** ** +** PLATFORM DEPENDANT [yes/no]: yes ** +** ** +** TO BE CHANGED BY USER [yes/no]: no ** +** ** +*******************************************************************************/ + +/******************************************************************************* +** Author Identity ** +******************************************************************************** +** ** +** Initials Name Company ** +** -------- ------------------------- ---------------------------------- ** +** aw Alexander Wenzel BMW ** +** mk Markus Klein Fraunhofer ESK ** +*******************************************************************************/ + +/******************************************************************************* +** Revision Control History ** +*******************************************************************************/ + +/* + * $LastChangedRevision: 1515 $ + * $LastChangedDate: 2010-12-13 09:18:54 +0100 (Mon, 13 Dec 2010) $ + * $LastChangedBy$ + Initials Date Comment + aw 13.01.2010 initial + */ + +#ifndef DLT_USER_MACROS_H +#define DLT_USER_MACORS_H + +/** + \defgroup userapi DLT User API + \addtogroup userapi + \{ +*/ + +/************************************************************************************************** +* The folowing macros define a macro interface for DLT +**************************************************************************************************/ + +/** + * Create an object for a new context. + * This macro has to be called first for every. + * @param CONTEXT object containing information about one special logging context + */ +#define DLT_DECLARE_CONTEXT(CONTEXT) \ +DltContext CONTEXT; + +/** + * Use an object of a new context created in another module. + * This macro has to be called first for every. + * @param CONTEXT object containing information about one special logging context + */ +#define DLT_IMPORT_CONTEXT(CONTEXT) \ +extern DltContext CONTEXT; + +/** + * Register application. + * @param APPID application id with maximal four characters + * @param DESCRIPTION ASCII string containing description + */ +#define DLT_REGISTER_APP(APPID,DESCRIPTION) \ + dlt_register_app( APPID, DESCRIPTION); + +/** + * Unregister application. + */ +#define DLT_UNREGISTER_APP() \ + dlt_unregister_app(); + +/** + * Register context (with default log level and default trace status) + * @param CONTEXT object containing information about one special logging context + * @param CONTEXTID context id with maximal four characters + * @param DESCRIPTION ASCII string containing description + */ +#define DLT_REGISTER_CONTEXT(CONTEXT,CONTEXTID,DESCRIPTION) \ + dlt_register_context(&(CONTEXT), CONTEXTID, DESCRIPTION); + +/** + * Register context with pre-defined log level and pre-defined trace status. + * @param CONTEXT object containing information about one special logging context + * @param CONTEXTID context id with maximal four characters + * @param DESCRIPTION ASCII string containing description + * @param LOGLEVEL log level to be pre-set for this context + (DLT_LOG_DEFAULT is not allowed here) + * @param TRACESTATUS trace status to be pre-set for this context + (DLT_TRACE_STATUS_DEFAULT is not allowed here) + */ +#define DLT_REGISTER_CONTEXT_LL_TS(CONTEXT,CONTEXTID,DESCRIPTION,LOGLEVEL,TRACESTATUS) \ + dlt_register_context_ll_ts(&(CONTEXT), CONTEXTID, DESCRIPTION, LOGLEVEL, TRACESTATUS); + +/** + * Unregister context. + * @param CONTEXT object containing information about one special logging context + */ +#define DLT_UNREGISTER_CONTEXT(CONTEXT) \ + dlt_unregister_context(&(CONTEXT)); + +/** + * Register callback function called when injection message was received + * @param CONTEXT object containing information about one special logging context + * @param SERVICEID service id of the injection message + * @param CALLBACK function pointer to callback function + */ +#define DLT_REGISTER_INJECTION_CALLBACK(CONTEXT, SERVICEID, CALLBACK) \ + dlt_register_injection_callback(&(CONTEXT),SERVICEID, CALLBACK); + +/** + * Send log message with variable list of messages (intended for verbose mode) + * @param CONTEXT object containing information about one special logging context + * @param LOGLEVEL the log level of the log message + * @param ARGS variable list of arguments + */ +#ifdef _MSC_VER + /* DLT_LOG is not supported by MS Visual C++ */ + /* use function interface instead */ +#else +#define DLT_LOG(CONTEXT,LOGLEVEL,ARGS...) \ + { \ + DltContextData log; \ + if (dlt_user_log_write_start(&CONTEXT,&log,LOGLEVEL)) \ + { \ + ARGS; \ + dlt_user_log_write_finish(&log); \ + } \ + } +#endif + +/** + * Send log message with variable list of messages (intended for non-verbose mode) + * @param CONTEXT object containing information about one special logging context + * @param LOGLEVEL the log level of the log message + * @param MSGID the message id of log message + * @param ARGS variable list of arguments: + calls to DLT_STRING(), DLT_BOOL(), DLT_FLOAT32(), DLT_FLOAT64(), + DLT_INT(), DLT_UINT(), DLT_RAW() + */ +#ifdef _MSC_VER + /* DLT_LOG_ID is not supported by MS Visual C++ */ + /* use function interface instead */ +#else +#define DLT_LOG_ID(CONTEXT,LOGLEVEL,MSGID,ARGS...) \ + { \ + DltContextData log; \ + if (dlt_user_log_write_start_id(&CONTEXT,&log,LOGLEVEL,MSGID)) \ + { \ + ARGS; \ + dlt_user_log_write_finish(&log); \ + } \ + } +#endif + +/** + * Add string parameter to the log messsage. + * @param TEXT ASCII string + */ +#define DLT_STRING(TEXT) ({ \ + dlt_user_log_write_string(&log,TEXT); \ + }) + +/** + * Add boolean parameter to the log messsage. + * @param BOOL_VAR Boolean value (mapped to uint8) + */ +#define DLT_BOOL(BOOL_VAR) ({ \ + dlt_user_log_write_bool(&log,BOOL_VAR); \ + }) + +/** + * Add float32 parameter to the log messsage. + * @param FLOAT32_VAR Float32 value (mapped to float) + */ +#define DLT_FLOAT32(FLOAT32_VAR) ({ \ + dlt_user_log_write_float32(&log,FLOAT32_VAR); \ + }) + +/** + * Add float64 parameter to the log messsage. + * @param FLOAT64_VAR Float64 value (mapped to double) + */ +#define DLT_FLOAT64(FLOAT64_VAR) ({ \ + dlt_user_log_write_float64(&log,FLOAT64_VAR); \ + }) + +/** + * Add integer parameter to the log messsage. + * @param INT_VAR integer value + */ +#define DLT_INT(INT_VAR) ({ \ + dlt_user_log_write_int(&log,INT_VAR); \ + }) +#define DLT_INT8(INT_VAR) ({ \ + dlt_user_log_write_int8(&log,INT_VAR); \ + }) +#define DLT_INT16(INT_VAR) ({ \ + dlt_user_log_write_int16(&log,INT_VAR); \ + }) +#define DLT_INT32(INT_VAR) ({ \ + dlt_user_log_write_int32(&log,INT_VAR); \ + }) +#define DLT_INT64(INT_VAR) ({ \ + dlt_user_log_write_int64(&log,INT_VAR); \ + }) + +/** + * Add unsigned integer parameter to the log messsage. + * @param UINT_VAR unsigned integer value + */ +#define DLT_UINT(UINT_VAR) ({ \ + dlt_user_log_write_uint(&log,UINT_VAR); \ + }) +#define DLT_UINT8(UINT_VAR) ({ \ + dlt_user_log_write_uint8(&log,UINT_VAR); \ + }) +#define DLT_UINT16(UINT_VAR) ({ \ + dlt_user_log_write_uint16(&log,UINT_VAR); \ + }) +#define DLT_UINT32(UINT_VAR) ({ \ + dlt_user_log_write_uint32(&log,UINT_VAR); \ + }) +#define DLT_UINT64(UINT_VAR) ({ \ + dlt_user_log_write_uint64(&log,UINT_VAR); \ + }) + +/** + * Add binary memory block to the log messages. + * @param BUF pointer to memory block + * @param LEN length of memory block + */ +#define DLT_RAW(BUF,LEN) ({ \ + dlt_user_log_write_raw(&log,BUF,LEN); \ + }) + +/** + * Trace network message + * @param CONTEXT object containing information about one special logging context + * @param TYPE type of network trace message + * @param HEADERLEN length of network message header + * @param HEADER pointer to network message header + * @param PAYLOADLEN length of network message payload + * @param PAYLOAD pointer to network message payload + */ +#define DLT_TRACE_NETWORK(CONTEXT,TYPE,HEADERLEN,HEADER,PAYLOADLEN,PAYLOAD) \ + { \ + dlt_user_trace_network(&(CONTEXT),TYPE,HEADERLEN,HEADER,PAYLOADLEN,PAYLOAD); \ + } + +/** + * Send log message with string parameter. + * @param CONTEXT object containing information about one special logging context + * @param LOGLEVEL the log level of the log message + * @param TEXT ASCII string + */ +#define DLT_LOG_STRING(CONTEXT,LOGLEVEL,TEXT) \ + { \ + dlt_log_string(&(CONTEXT), LOGLEVEL, TEXT); \ + } + + +/** + * Send log message with string parameter and integer parameter. + * @param CONTEXT object containing information about one special logging context + * @param LOGLEVEL the log level of the log messages + * @param TEXT ASCII string + * @param INT_VAR integer value + */ +#define DLT_LOG_STRING_INT(CONTEXT,LOGLEVEL,TEXT,INT_VAR) \ + { \ + dlt_log_string_int(&(CONTEXT), LOGLEVEL, TEXT, INT_VAR); \ + } + +/** + * Send log message with string parameter and unsigned integer parameter. + * @param CONTEXT object containing information about one special logging context + * @param LOGLEVEL the log level of the log message + * @param TEXT ASCII string + * @param UINT_VAR unsigned integer value + */ +#define DLT_LOG_STRING_UINT(CONTEXT,LOGLEVEL,TEXT,UINT_VAR) \ + { \ + dlt_log_string_uint(&(CONTEXT),LOGLEVEL,TEXT,UINT_VAR); \ + } + +/** + * Send log message with unsigned integer parameter. + * @param CONTEXT object containing information about one special logging context + * @param LOGLEVEL the log level of the log message + * @param UINT_VAR unsigned integer value + */ +#define DLT_LOG_UINT(CONTEXT,LOGLEVEL,UINT_VAR) \ + { \ + dlt_log_uint(&(CONTEXT),LOGLEVEL,UINT_VAR); \ + } + +/** + * Send log message with integer parameter. + * @param CONTEXT object containing information about one special logging context + * @param LOGLEVEL the log level of the log message + * @param INT_VAR integer value + */ +#define DLT_LOG_INT(CONTEXT,LOGLEVEL,INT_VAR) \ + { \ + dlt_log_int(&(CONTEXT),LOGLEVEL,INT_VAR); \ + } + +/** + * Send log message with binary memory block. + * @param CONTEXT object containing information about one special logging context + * @param LOGLEVEL the log level of the log message + * @param BUF pointer to memory block + * @param LEN length of memory block + */ +#define DLT_LOG_RAW(CONTEXT,LOGLEVEL,BUF,LEN) \ + { \ + dlt_log_raw(&(CONTEXT),LOGLEVEL,BUF,LEN); \ + } + +/** + * Switch to verbose mode + * + */ +#define DLT_VERBOSE_MODE() \ + dlt_verbose_mode(); + +/** + * Switch to non-verbose mode + * + */ +#define DLT_NONVERBOSE_MODE() \ + dlt_nonverbose_mode(); + +/** + * Set maximum logged log level and trace status of application + * + * @param LOGLEVEL This is the log level to be set for the whole application + * @param TRACESTATUS This is the trace status to be set for the whole application + */ +#define DLT_SET_APPLICATION_LL_TS_LIMIT(LOGLEVEL, TRACESTATUS) \ + dlt_set_application_ll_ts_limit(LOGLEVEL, TRACESTATUS); + +/** + * Enable local printing of messages + * + */ +#define DLT_ENABLE_LOCAL_PRINT() \ + dlt_enable_local_print(); + +/** + * Disable local printing of messages + * + */ +#define DLT_DISABLE_LOCAL_PRINT() \ + dlt_disable_local_print(); + +/** + \} +*/ + +#endif /* DLT_USER_MACROS_H */ |