2 * Dlt- Diagnostic Log and Trace
5 * Copyright (C) 2011, BMW AG - Alexander Wenzel <alexander.wenzel@bmw.de>
7 * This program is free software; you can redistribute it and/or modify it under the terms of the
8 * GNU Lesser General Public License, version 2.1, as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
10 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
11 * Public License, version 2.1, for more details.
13 * You should have received a copy of the GNU Lesser General Public License, version 2.1, along
14 * with this program; if not, see <http://www.gnu.org/licenses/lgpl-2.1.html>.
16 * Note that the copyright holders assume that the GNU Lesser General Public License, version 2.1, may
17 * also be applicable to programs even in cases in which the program is not a library in the technical sense.
19 * Linking DLT statically or dynamically with other modules is making a combined work based on DLT. You may
20 * license such other modules under the GNU Lesser General Public License, version 2.1. If you do not want to
21 * license your linked modules under the GNU Lesser General Public License, version 2.1, you
22 * may use the program under the following exception.
24 * As a special exception, the copyright holders of DLT give you permission to combine DLT
25 * with software programs or libraries that are released under any license unless such a combination is not
26 * permitted by the license of such a software program or library. You may copy and distribute such a
27 * system following the terms of the GNU Lesser General Public License, version 2.1, including this
28 * special exception, for DLT and the licenses of the other code concerned.
30 * Note that people who make modified versions of DLT are not obligated to grant this special exception
31 * for their modified versions; it is their choice whether to do so. The GNU Lesser General Public License,
32 * version 2.1, gives permission to release a modified version without this exception; this exception
33 * also makes it possible to release a modified version which carries forward this exception.
39 /*******************************************************************************
41 ** SRC-MODULE: dlt_common.h **
47 ** AUTHOR : Alexander Wenzel Alexander.AW.Wenzel@bmw.de **
54 ** PLATFORM DEPENDANT [yes/no]: yes **
56 ** TO BE CHANGED BY USER [yes/no]: no **
58 *******************************************************************************/
60 /*******************************************************************************
62 ********************************************************************************
64 ** Initials Name Company **
65 ** -------- ------------------------- ---------------------------------- **
66 ** aw Alexander Wenzel BMW **
67 ** mk Markus Klein Fraunhofer ESK **
68 *******************************************************************************/
70 /*******************************************************************************
71 ** Revision Control History **
72 *******************************************************************************/
75 * $LastChangedRevision: 1670 $
76 * $LastChangedDate: 2011-04-08 15:12:06 +0200 (Fr, 08. Apr 2011) $
85 \defgroup commonapi DLT Common API
92 #if !defined(_MSC_VER)
97 #if !defined (__WIN32__) && !defined(_MSC_VER)
101 #include "dlt_types.h"
102 #include "dlt_protocol.h"
104 #if !defined (PACKED)
105 #define PACKED __attribute__((aligned(1),packed))
108 #if defined (__MSDOS__) || defined (_MSC_VER)
109 /* set instead /Zp8 flag in Visual C++ configuration */
115 * Macros to swap the byte order.
117 #define DLT_SWAP_64(value) ((((uint64_t)DLT_SWAP_32((value)&0xffffffffull))<<32) | (DLT_SWAP_32((value)>>32)))
119 #define DLT_SWAP_16(value) ((((value) >> 8)&0xff) | (((value) << 8)&0xff00))
120 #define DLT_SWAP_32(value) ((((value) >> 24)&0xff) | (((value) << 8)&0xff0000) | (((value) >> 8)&0xff00) | (((value) << 24)&0xff000000))
122 /* Set Big Endian and Little Endian to a initial value, if not defined */
123 #ifndef LITTLE_ENDIAN
124 #define LITTLE_ENDIAN 1234
128 #define BIG_ENDIAN 4321
131 /* If byte order is not defined, default to little endian */
133 #define BYTE_ORDER LITTLE_ENDIAN
136 /* Check for byte-order */
137 #if (BYTE_ORDER==BIG_ENDIAN)
138 /* #warning "Big Endian Architecture!" */
139 #define DLT_HTOBE_16(x) ((x))
140 #define DLT_HTOLE_16(x) DLT_SWAP_16((x))
141 #define DLT_BETOH_16(x) ((x))
142 #define DLT_LETOH_16(x) DLT_SWAP_16((x))
144 #define DLT_HTOBE_32(x) ((x))
145 #define DLT_HTOLE_32(x) DLT_SWAP_32((x))
146 #define DLT_BETOH_32(x) ((x))
147 #define DLT_LETOH_32(x) DLT_SWAP_32((x))
149 #define DLT_HTOBE_64(x) ((x))
150 #define DLT_HTOLE_64(x) DLT_SWAP_64((x))
151 #define DLT_BETOH_64(x) ((x))
152 #define DLT_LETOH_64(x) DLT_SWAP_64((x))
154 /* #warning "Litte Endian Architecture!" */
155 #define DLT_HTOBE_16(x) DLT_SWAP_16((x))
156 #define DLT_HTOLE_16(x) ((x))
157 #define DLT_BETOH_16(x) DLT_SWAP_16((x))
158 #define DLT_LETOH_16(x) ((x))
160 #define DLT_HTOBE_32(x) DLT_SWAP_32((x))
161 #define DLT_HTOLE_32(x) ((x))
162 #define DLT_BETOH_32(x) DLT_SWAP_32((x))
163 #define DLT_LETOH_32(x) ((x))
165 #define DLT_HTOBE_64(x) DLT_SWAP_64((x))
166 #define DLT_HTOLE_64(x) ((x))
167 #define DLT_BETOH_64(x) DLT_SWAP_64((x))
168 #define DLT_LETOH_64(x) ((x))
171 #define DLT_ENDIAN_GET_16(htyp,x) ((((htyp) & DLT_HTYP_MSBF)>0)?DLT_BETOH_16(x):DLT_LETOH_16(x))
172 #define DLT_ENDIAN_GET_32(htyp,x) ((((htyp) & DLT_HTYP_MSBF)>0)?DLT_BETOH_32(x):DLT_LETOH_32(x))
173 #define DLT_ENDIAN_GET_64(htyp,x) ((((htyp) & DLT_HTYP_MSBF)>0)?DLT_BETOH_64(x):DLT_LETOH_64(x))
175 #if defined (__WIN32__) || defined (_MSC_VER)
180 #define LOG_WARNING 4
186 #define LOG_DAEMON (3<<3)
190 * The standard TCP Port used for DLT daemon
192 #define DLT_DAEMON_TCP_PORT 3490
195 * The size of a DLT ID
197 #define DLT_ID_SIZE 4
199 #define DLT_SIZE_WEID DLT_ID_SIZE
200 #define DLT_SIZE_WSID (sizeof(uint32_t))
201 #define DLT_SIZE_WTMS (sizeof(uint32_t))
204 * Get the size of extra header parameters, depends on htyp.
206 #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) )
209 #if defined (__MSDOS__) || defined (_MSC_VER)
210 #define __func__ __FUNCTION__
213 #define PRINT_FUNCTION_VERBOSE(_verbose) \
215 static char _strbuf[255]; \
219 sprintf(_strbuf, "%s()\n",__func__); \
220 dlt_log(LOG_INFO, _strbuf); \
225 #define NULL (char*)0
228 #define DLT_MSG_IS_CONTROL(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \
229 (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin)==DLT_TYPE_CONTROL))
231 #define DLT_MSG_IS_CONTROL_REQUEST(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \
232 (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin)==DLT_TYPE_CONTROL) && \
233 (DLT_GET_MSIN_MTIN((MSG)->extendedheader->msin)==DLT_CONTROL_REQUEST))
235 #define DLT_MSG_IS_CONTROL_RESPONSE(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \
236 (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin)==DLT_TYPE_CONTROL) && \
237 (DLT_GET_MSIN_MTIN((MSG)->extendedheader->msin)==DLT_CONTROL_RESPONSE))
239 #define DLT_MSG_IS_CONTROL_TIME(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \
240 (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin)==DLT_TYPE_CONTROL) && \
241 (DLT_GET_MSIN_MTIN((MSG)->extendedheader->msin)==DLT_CONTROL_TIME))
243 #define DLT_MSG_IS_NW_TRACE(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \
244 (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin)==DLT_TYPE_NW_TRACE))
246 #define DLT_MSG_IS_TRACE_MOST(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \
247 (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin)==DLT_TYPE_NW_TRACE) && \
248 (DLT_GET_MSIN_MTIN((MSG)->extendedheader->msin)==DLT_NW_TRACE_MOST))
250 #define DLT_MSG_IS_NONVERBOSE(MSG) (!(DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) || \
251 ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && (!(DLT_IS_MSIN_VERB((MSG)->extendedheader->msin)))))
255 * Definitions of DLT message buffer overflow
257 #define DLT_MESSAGE_BUFFER_NO_OVERFLOW 0x00 /**< Buffer overflow has not occured */
258 #define DLT_MESSAGE_BUFFER_OVERFLOW 0x01 /**< Buffer overflow has occured */
261 * Definition of DLT output variants
263 #define DLT_OUTPUT_HEX 1
264 #define DLT_OUTPUT_ASCII 2
265 #define DLT_OUTPUT_MIXED_FOR_PLAIN 3
266 #define DLT_OUTPUT_MIXED_FOR_HTML 4
267 #define DLT_OUTPUT_ASCII_LIMITED 5
269 #define DLT_FILTER_MAX 30 /**< Maximum number of filters */
271 #define DLT_MSG_READ_VALUE(dst,src,length,type) \
273 if((length<0) || ((length)<((int32_t)sizeof(type)))) \
276 { dst = *((type*)src);src+=sizeof(type);length-=sizeof(type); } \
279 #define DLT_MSG_READ_ID(dst,src,length) \
281 if((length<0) || ((length)<DLT_ID_SIZE)) \
284 { memcpy(dst,src,DLT_ID_SIZE);src+=DLT_ID_SIZE;length-=DLT_ID_SIZE; } \
287 #define DLT_MSG_READ_STRING(dst,src,maxlength,length) \
289 if(((maxlength)<0) || ((length)<0) || ((maxlength)<(length))) \
290 { maxlength = -1; } \
292 { memcpy(dst,src,length);dlt_clean_string(dst,length);dst[length]=0; \
293 src+=length;maxlength-=length; } \
296 #define DLT_MSG_READ_NULL(src,maxlength,length) \
298 if(((maxlength)<0) || ((length)<0) || ((maxlength)<(length))) \
301 { src+=length;maxlength-=length; } \
304 #define DLT_HEADER_SHOW_NONE 0x0000
305 #define DLT_HEADER_SHOW_TIME 0x0001
306 #define DLT_HEADER_SHOW_TMSTP 0x0002
307 #define DLT_HEADER_SHOW_MSGCNT 0x0004
308 #define DLT_HEADER_SHOW_ECUID 0x0008
309 #define DLT_HEADER_SHOW_APID 0x0010
310 #define DLT_HEADER_SHOW_CTID 0x0020
311 #define DLT_HEADER_SHOW_MSGTYPE 0x0040
312 #define DLT_HEADER_SHOW_MSGSUBTYPE 0x0080
313 #define DLT_HEADER_SHOW_VNVSTATUS 0x0100
314 #define DLT_HEADER_SHOW_NOARG 0x0200
315 #define DLT_HEADER_SHOW_ALL 0xFFFF
318 * The definition of the serial header containing the characters "DLS" + 0x01.
320 extern const char dltSerialHeader[DLT_ID_SIZE];
323 * The definition of the serial header containing the characters "DLS" + 0x01 as char.
325 extern char dltSerialHeaderChar[DLT_ID_SIZE];
329 * The type of a DLT ID (context id, application id, etc.)
331 typedef char ID4[DLT_ID_SIZE];
334 * The structure of the DLT file storage header. This header is used before each stored DLT message.
338 char pattern[DLT_ID_SIZE]; /**< This pattern should be DLT0x01 */
339 time_t seconds; /**< seconds since 1.1.1970 */
340 int32_t microseconds; /**< Microseconds */
341 char ecu[DLT_ID_SIZE]; /**< The ECU id is added, if it is not already in the DLT message itself */
342 } PACKED DltStorageHeader;
345 * The structure of the DLT standard header. This header is used in each DLT message.
349 uint8_t htyp; /**< This parameter contains several informations, see definitions below */
350 uint8_t mcnt; /**< The message counter is increased with each sent DLT message */
351 uint16_t len; /**< Length of the complete message, without storage header */
352 } PACKED DltStandardHeader;
355 * The structure of the DLT extra header parameters. Each parameter is sent only if enabled in htyp.
359 char ecu[DLT_ID_SIZE]; /**< ECU id */
360 uint32_t seid; /**< Session number */
361 uint32_t tmsp; /**< Timestamp since system start in 0.1 milliseconds */
362 } PACKED DltStandardHeaderExtra;
365 * The structure of the DLT extended header. This header is only sent if enabled in htyp parameter.
369 uint8_t msin; /**< messsage info */
370 uint8_t noar; /**< number of arguments */
371 char apid[DLT_ID_SIZE]; /**< application id */
372 char ctid[DLT_ID_SIZE]; /**< context id */
373 } PACKED DltExtendedHeader;
376 * The structure to organise the DLT messages.
377 * This structure is used by the corresponding functions.
379 typedef struct sDltMessage
382 int8_t found_serialheader;
385 int32_t resync_offset;
387 /* size parameters */
388 int32_t headersize; /**< size of complete header including storage header */
389 int32_t datasize; /**< size of complete payload */
391 /* buffer for current loaded message */
392 uint8_t headerbuffer[sizeof(DltStorageHeader)+
393 sizeof(DltStandardHeader)+sizeof(DltStandardHeaderExtra)+sizeof(DltExtendedHeader)]; /**< buffer for loading complete header */
394 uint8_t *databuffer; /**< buffer for loading payload */
396 /* header values of current loaded message */
397 DltStorageHeader *storageheader; /**< pointer to storage header of current loaded header */
398 DltStandardHeader *standardheader; /**< pointer to standard header of current loaded header */
399 DltStandardHeaderExtra headerextra; /**< extra parameters of current loaded header */
400 DltExtendedHeader *extendedheader; /**< pointer to extended of current loaded header */
404 * The structure of the DLT Service Get Log Info.
408 uint32_t service_id; /**< service ID */
409 uint8_t options; /**< type of request */
410 char apid[DLT_ID_SIZE]; /**< application id */
411 char ctid[DLT_ID_SIZE]; /**< context id */
412 char com[DLT_ID_SIZE]; /**< communication interface */
413 } PACKED DltServiceGetLogInfoRequest;
416 * The structure of the DLT Service Set Log Level.
420 uint32_t service_id; /**< service ID */
421 char apid[DLT_ID_SIZE]; /**< application id */
422 char ctid[DLT_ID_SIZE]; /**< context id */
423 uint8_t log_level; /**< log level to be set */
424 char com[DLT_ID_SIZE]; /**< communication interface */
425 } PACKED DltServiceSetLogLevel;
428 * The structure of the DLT Service Set Default Log Level.
432 uint32_t service_id; /**< service ID */
433 uint8_t log_level; /**< default log level to be set */
434 char com[DLT_ID_SIZE]; /**< communication interface */
435 } PACKED DltServiceSetDefaultLogLevel;
438 * The structure of the DLT Service Set Verbose Mode
442 uint32_t service_id; /**< service ID */
443 uint8_t new_status; /**< new status to be set */
444 } PACKED DltServiceSetVerboseMode;
447 * The structure of the DLT Service Set Communication Interface Status
451 uint32_t service_id; /**< service ID */
452 char com[DLT_ID_SIZE]; /**< communication interface */
453 uint8_t new_status; /**< new status to be set */
454 } PACKED DltServiceSetCommunicationInterfaceStatus;
457 * The structure of the DLT Service Set Communication Maximum Bandwidth
461 uint32_t service_id; /**< service ID */
462 char com[DLT_ID_SIZE]; /**< communication interface */
463 uint32_t max_bandwidth; /**< maximum bandwith */
464 } PACKED DltServiceSetCommunicationMaximumBandwidth;
468 uint32_t service_id; /**< service ID */
469 uint8_t status; /**< reponse status */
470 } PACKED DltServiceResponse;
474 uint32_t service_id; /**< service ID */
475 uint8_t status; /**< reponse status */
476 uint8_t log_level; /**< log level */
477 } PACKED DltServiceGetDefaultLogLevelResponse;
481 uint32_t service_id; /**< service ID */
482 uint8_t status; /**< reponse status */
483 uint8_t overflow; /**< overflow status */
484 } PACKED DltServiceMessageBufferOverflowResponse;
488 uint32_t service_id; /**< service ID */
489 uint8_t status; /**< reponse status */
490 uint32_t length; /**< length of following payload */
491 /* char [] payload */
492 } PACKED DltServiceGetSoftwareVersionResponse;
495 * Structure to store filter parameters.
496 * ID are maximal four characters. Unused values are filled with zeros.
497 * If every value as filter is valid, the id should be empty by having only zero values.
501 char apid[DLT_FILTER_MAX][DLT_ID_SIZE]; /**< application id */
502 char ctid[DLT_FILTER_MAX][DLT_ID_SIZE]; /**< context id */
503 int counter; /**< number of filters */
507 * The structure to organise the access to DLT files.
508 * This structure is used by the corresponding functions.
510 typedef struct sDltFile
512 /* file handle and index for fast access */
513 FILE *handle; /**< file handle of opened DLT file */
514 long *index; /**< file positions of all DLT messages for fast access to file, only filtered messages */
516 /* size parameters */
517 int32_t counter; /**< number of messages in DLT file with filter */
518 int32_t counter_total; /**< number of messages in DLT file without filter */
519 int32_t position; /**< current index to message parsed in DLT file starting at 0 */
520 long file_length; /**< length of the file */
521 long file_position; /**< current position in the file */
524 int32_t error_messages; /**< number of incomplete DLT messages found during file parsing */
526 /* filter parameters */
527 DltFilter *filter; /**< pointer to filter list. Zero if no filter is set. */
528 int32_t filter_counter; /**< number of filter set */
530 /* current loaded message */
531 DltMessage msg; /**< pointer to message */
536 * The structure is used to organise the receiving of data
537 * including buffer handling.
538 * This structure is used by the corresponding functions.
542 int32_t lastBytesRcvd; /**< bytes received in last receive call */
543 int32_t bytesRcvd; /**< received bytes */
544 int32_t totalBytesRcvd; /**< total number of received bytes */
545 char *buffer; /**< pointer to receiver buffer */
546 char *buf; /**< pointer to position within receiver buffer */
547 int fd; /**< connection handle */
548 int32_t buffersize; /**< size of receiver buffer */
553 char* buffer; /**< Ptr. to buffer */
554 uint32_t size; /**< Maximum size of buffer */
555 uint32_t pos_write; /**< current writing position in bytes*/
556 uint32_t pos_read; /**< current reading position in bytes*/
557 uint32_t count; /**< nr. of entries */
566 * Helper function to print a byte array in hex.
567 * @param ptr pointer to the byte array.
568 * @param size number of bytes to be printed.
570 void dlt_print_hex(uint8_t *ptr,int size);
572 * Helper function to print a byte array in hex into a string.
573 * @param text pointer to a ASCII string, in which the text is written
574 * @param textlength maximal size of text buffer
575 * @param ptr pointer to the byte array.
576 * @param size number of bytes to be printed.
577 * @return negative value if there was an error
579 int dlt_print_hex_string(char *text,int textlength,uint8_t *ptr,int size);
581 * Helper function to print a byte array in hex and ascii into a string.
582 * @param text pointer to a ASCII string, in which the text is written
583 * @param textlength maximal size of text buffer
584 * @param ptr pointer to the byte array.
585 * @param size number of bytes to be printed.
586 * @param html output is html? 0 - false, 1 - true
587 * @return negative value if there was an error
589 int dlt_print_mixed_string(char *text,int textlength,uint8_t *ptr,int size,int html);
591 * Helper function to print a byte array in ascii into a string.
592 * @param text pointer to a ASCII string, in which the text is written
593 * @param textlength maximal size of text buffer
594 * @param ptr pointer to the byte array.
595 * @param size number of bytes to be printed.
596 * @return negative value if there was an error
598 int dlt_print_char_string(char **text,int textlength,uint8_t *ptr,int size);
601 * Helper function to print an id.
602 * @param text pointer to ASCII string where to write the id
603 * @param id four byte char array as used in DLT mesages as IDs.
605 void dlt_print_id(char *text,const char *id);
608 * Helper function to set an ID parameter.
609 * @param id four byte char array as used in DLT mesages as IDs.
610 * @param text string to be copied into char array.
612 void dlt_set_id(char *id,const char *text);
615 * Helper function to remove not nice to print characters, e.g. NULL or carage return.
616 * @param text pointer to string to be cleaned.
617 * @param length length of string excluding terminating zero.
619 void dlt_clean_string(char *text,int length);
622 * Initialise the filter list.
623 * This function must be called before using further dlt filter.
624 * @param filter pointer to structure of organising DLT filter
625 * @param verbose if set to true verbose information is printed out.
626 * @return negative value if there was an error
628 int dlt_filter_init(DltFilter *filter,int verbose);
630 * Free the used memory by the organising structure of filter.
631 * @param filter pointer to structure of organising DLT filter
632 * @param verbose if set to true verbose information is printed out.
633 * @return negative value if there was an error
635 int dlt_filter_free(DltFilter *filter,int verbose);
637 * Load filter list from file.
638 * @param filter pointer to structure of organising DLT filter
639 * @param filename filename to load filters from
640 * @param verbose if set to true verbose information is printed out.
641 * @return negative value if there was an error
643 int dlt_filter_load(DltFilter *filter,const char *filename,int verbose);
645 * Save filter list to file.
646 * @param filter pointer to structure of organising DLT filter
647 * @param filename filename to load filters from
648 * @param verbose if set to true verbose information is printed out.
649 * @return negative value if there was an error
651 int dlt_filter_save(DltFilter *filter,const char *filename,int verbose);
653 * Find index of filter in filter list
654 * @param filter pointer to structure of organising DLT filter
655 * @param apid application id to be found in filter list
656 * @param ctid context id to be found in filter list
657 * @param verbose if set to true verbose information is printed out.
658 * @return negative value if there was an error (or not found), else return index of filter
660 int dlt_filter_find(DltFilter *filter,const char *apid,const char *ctid, int verbose);
662 * Add new filter to filter list.
663 * @param filter pointer to structure of organising DLT filter
664 * @param apid application id to be added to filter list (must always be set).
665 * @param ctid context id to be added to filter list. empty equals don't care.
666 * @param verbose if set to true verbose information is printed out.
667 * @return negative value if there was an error
669 int dlt_filter_add(DltFilter *filter,const char *apid,const char *ctid,int verbose);
671 * Delete filter from filter list
672 * @param filter pointer to structure of organising DLT filter
673 * @param apid application id to be deleted from filter list
674 * @param ctid context id to be deleted from filter list
675 * @param verbose if set to true verbose information is printed out.
676 * @return negative value if there was an error
678 int dlt_filter_delete(DltFilter *filter,const char *apid,const char *ctid,int verbose);
681 * Initialise the structure used to access a DLT message.
682 * This function must be called before using further dlt_message functions.
683 * @param msg pointer to structure of organising access to DLT messages
684 * @param verbose if set to true verbose information is printed out.
685 * @return negative value if there was an error
687 int dlt_message_init(DltMessage *msg,int verbose);
689 * Free the used memory by the organising structure of file.
690 * @param msg pointer to structure of organising access to DLT messages
691 * @param verbose if set to true verbose information is printed out.
692 * @return negative value if there was an error
694 int dlt_message_free(DltMessage *msg,int verbose);
696 * Print Header into an ASCII string.
697 * This function calls dlt_message_header_flags() with flags=DLT_HEADER_SHOW_ALL
698 * @param msg pointer to structure of organising access to DLT messages
699 * @param text pointer to a ASCII string, in which the header is written
700 * @param textlength maximal size of text buffer
701 * @param verbose if set to true verbose information is printed out.
702 * @return negative value if there was an error
704 int dlt_message_header(DltMessage *msg,char *text,int textlength,int verbose);
706 * Print Header into an ASCII string, selective.
707 * @param msg pointer to structure of organising access to DLT messages
708 * @param text pointer to a ASCII string, in which the header is written
709 * @param textlength maximal size of text buffer
710 * @param flags select, bit-field to select, what should be printed (DLT_HEADER_SHOW_...)
711 * @param verbose if set to true verbose information is printed out.
712 * @return negative value if there was an error
714 int dlt_message_header_flags(DltMessage *msg,char *text,int textlength,int flags, int verbose);
716 * Print Payload into an ASCII string.
717 * @param msg pointer to structure of organising access to DLT messages
718 * @param text pointer to a ASCII string, in which the header is written
719 * @param textlength maximal size of text buffer
720 * @param type 1 = payload as hex, 2 = payload as ASCII.
721 * @param verbose if set to true verbose information is printed out.
722 * @return negative value if there was an error
724 int dlt_message_payload(DltMessage *msg,char *text,int textlength,int type,int verbose);
726 * Check if message is filtered or not. All filters are applied (logical OR).
727 * @param msg pointer to structure of organising access to DLT messages
728 * @param filter pointer to filter
729 * @param verbose if set to true verbose information is printed out.
730 * @return 1 = filter matches, 0 = filter does not match, negative value if there was an error
732 int dlt_message_filter_check(DltMessage *msg,DltFilter *filter,int verbose);
735 * Read message from memory buffer.
736 * Message in buffer has no storage header.
737 * @param msg pointer to structure of organising access to DLT messages
738 * @param buffer pointer to memory buffer
739 * @param length length of message in buffer
740 * @param resync if set to true resync to serial header is enforced
741 * @param verbose if set to true verbose information is printed out.
742 * @return negative value if there was an error
744 int dlt_message_read(DltMessage *msg,uint8_t *buffer,unsigned int length,int resync,int verbose);
747 * Get standard header extra parameters
748 * @param msg pointer to structure of organising access to DLT messages
749 * @param verbose if set to true verbose information is printed out.
750 * @return negative value if there was an error
752 int dlt_message_get_extraparameters(DltMessage *msg,int verbose);
755 * Set standard header extra parameters
756 * @param msg pointer to structure of organising access to DLT messages
757 * @param verbose if set to true verbose information is printed out.
758 * @return negative value if there was an error
760 int dlt_message_set_extraparameters(DltMessage *msg,int verbose);
763 * Initialise the structure used to access a DLT file.
764 * This function must be called before using further dlt_file functions.
765 * @param file pointer to structure of organising access to DLT file
766 * @param verbose if set to true verbose information is printed out.
767 * @return negative value if there was an error
769 int dlt_file_init(DltFile *file,int verbose);
771 * Set a list to filters.
772 * This function should be called before loading a DLT file, if filters should be used.
773 * A filter list is an array of filters. Several filters are combined logically by or operation.
774 * The filter list is not copied, so take care to keep list in memory.
775 * @param file pointer to structure of organising access to DLT file
776 * @param filter pointer to filter list array
777 * @param verbose if set to true verbose information is printed out.
778 * @return negative value if there was an error
780 int dlt_file_set_filter(DltFile *file,DltFilter *filter,int verbose);
782 * Initialising loading a DLT file.
783 * @param file pointer to structure of organising access to DLT file
784 * @param filename filename of DLT file
785 * @param verbose if set to true verbose information is printed out.
786 * @return negative value if there was an error
788 int dlt_file_open(DltFile *file,const char *filename,int verbose);
790 * Find next message in the DLT file and parse them.
791 * This function finds the next message in the DLT file.
792 * If a filter is set, the filter list is used.
793 * @param file pointer to structure of organising access to DLT file
794 * @param verbose if set to true verbose information is printed out.
795 * @return 0 = message does not match filter, 1 = message was read, negative value if there was an error
797 int dlt_file_read(DltFile *file,int verbose);
799 * Find next message in the DLT file in RAW format (without storage header) and parse them.
800 * This function finds the next message in the DLT file.
801 * If a filter is set, the filter list is used.
802 * @param file pointer to structure of organising access to DLT file
803 * @param resync Resync to serial header when set to true
804 * @param verbose if set to true verbose information is printed out.
805 * @return 0 = message does not match filter, 1 = message was read, negative value if there was an error
807 int dlt_file_read_raw(DltFile *file,int resync,int verbose);
809 * Closing loading a DLT file.
810 * @param file pointer to structure of organising access to DLT file
811 * @param verbose if set to true verbose information is printed out.
812 * @return negative value if there was an error
814 int dlt_file_close(DltFile *file,int verbose);
816 * Load standard header of a message from file
817 * @param file pointer to structure of organising access to DLT file
818 * @param verbose if set to true verbose information is printed out.
819 * @return negative value if there was an error
821 int dlt_file_read_header(DltFile *file,int verbose);
823 * Load standard header of a message from file in RAW format (without storage header)
824 * @param file pointer to structure of organising access to DLT file
825 * @param resync Resync to serial header when set to true
826 * @param verbose if set to true verbose information is printed out.
827 * @return negative value if there was an error
829 int dlt_file_read_header_raw(DltFile *file,int resync,int verbose);
831 * Load, if available in message, extra standard header fields and
832 * extended header of a message from file
833 * (dlt_file_read_header() must have been called before this call!)
834 * @param file pointer to structure of organising access to DLT file
835 * @param verbose if set to true verbose information is printed out.
836 * @return negative value if there was an error
838 int dlt_file_read_header_extended(DltFile *file, int verbose);
840 * Load payload of a message from file
841 * (dlt_file_read_header() must have been called before this call!)
842 * @param file pointer to structure of organising access to DLT file
843 * @param verbose if set to true verbose information is printed out.
844 * @return negative value if there was an error
846 int dlt_file_read_data(DltFile *file, int verbose);
848 * Load headers and payload of a message selected by the index.
849 * If filters are set, index is based on the filtered list.
850 * @param file pointer to structure of organising access to DLT file
851 * @param index position of message in the files beginning from zero
852 * @param verbose if set to true verbose information is printed out.
853 * @return number of messages loaded, negative value if there was an error
855 int dlt_file_message(DltFile *file,int index,int verbose);
857 * Free the used memory by the organising structure of file.
858 * @param file pointer to structure of organising access to DLT file
859 * @param verbose if set to true verbose information is printed out.
860 * @return negative value if there was an error
862 int dlt_file_free(DltFile *file,int verbose);
865 * Initialize (external) logging facility
866 * @param mode positive, if syslog should be used; zero for console output
868 void dlt_log_init(int mode);
870 * Log ASCII string with null-termination to (external) logging facility
871 * @param prio priority (see syslog() call)
872 * @param s Pointer to ASCII string with null-termination
873 * @return negative value if there was an error
875 int dlt_log(int prio, char *s);
877 * De-Initialize (external) logging facility
879 void dlt_log_free(void);
882 * Initialising a dlt receiver structure
883 * @param receiver pointer to dlt receiver structure
884 * @param _fd handle to file/socket/fifo, fram which the data should be received
885 * @param _buffersize size of data buffer for storing the received data
886 * @return negative value if there was an error
888 int dlt_receiver_init(DltReceiver *receiver,int _fd, int _buffersize);
890 * De-Initialize a dlt receiver structure
891 * @param receiver pointer to dlt receiver structure
892 * @return negative value if there was an error
894 int dlt_receiver_free(DltReceiver *receiver);
896 * Receive data from socket using the dlt receiver structure
897 * @param receiver pointer to dlt receiver structure
898 * @return negative value if there was an error
900 int dlt_receiver_receive_socket(DltReceiver *receiver);
902 * Receive data from file/fifo using the dlt receiver structure
903 * @param receiver pointer to dlt receiver structure
904 * @return negative value if there was an error
906 int dlt_receiver_receive_fd(DltReceiver *receiver);
908 * Remove a specific size of bytes from the received data
909 * @param receiver pointer to dlt receiver structure
910 * @param size amount of bytes to be removed
911 * @return negative value if there was an error
913 int dlt_receiver_remove(DltReceiver *receiver,int size);
915 * Move data from last receive call to front of receive buffer
916 * @param receiver pointer to dlt receiver structure
917 * @return negative value if there was an error
919 int dlt_receiver_move_to_begin(DltReceiver *receiver);
922 * Fill out storage header of a dlt message
923 * @param storageheader pointer to storage header of a dlt message
924 * @param ecu name of ecu to be set in storage header
925 * @return negative value if there was an error
927 int dlt_set_storageheader(DltStorageHeader *storageheader, const char *ecu);
929 * Check if a storage header contains its marker
930 * @param storageheader pointer to storage header of a dlt message
931 * @return 0 no, 1 yes, negative value if there was an error
933 int dlt_check_storageheader(DltStorageHeader *storageheader);
935 #if !defined (__WIN32__)
938 * Helper function: Setup serial connection
939 * @param fd File descriptor of serial tty device
940 * @param speed Serial line speed, as defined in termios.h
941 * @return negative value if there was an error
943 int dlt_setup_serial(int fd, speed_t speed);
946 * Helper function: Convert serial line baudrate (as number) to line speed (as defined in termios.h)
947 * @param baudrate Serial line baudrate (as number)
948 * @return Serial line speed, as defined in termios.h
950 speed_t dlt_convert_serial_speed(int baudrate);
953 * Print dlt version and dlt svn version to buffer
954 * @param buf Pointer to buffer
956 void dlt_get_version(char *buf);
959 * Print dlt major version to buffer
960 * @param buf Pointer to buffer
962 void dlt_get_major_version(char *buf);
965 * Print dlt minor version to buffer
966 * @param buf Pointer to buffer
968 void dlt_get_minor_version(char *buf);
972 /* Function prototypes which should be used only internally */
976 * Common part of initialisation
977 * @return negative value if there was an error
979 int dlt_init_common(void);
982 * Return the uptime of the system in 0.1 ms resolution
983 * @return 0 if there was an error
985 uint32_t dlt_uptime(void);
988 * Print header of a DLT message
989 * @param message pointer to structure of organising access to DLT messages
990 * @param text pointer to a ASCII string, in which the header is written
991 * @param size maximal size of text buffer
992 * @param verbose if set to true verbose information is printed out.
993 * @return negative value if there was an error
995 int dlt_message_print_header(DltMessage *message, char *text, uint32_t size, int verbose);
998 * Print payload of a DLT message as Hex-Output
999 * @param message pointer to structure of organising access to DLT messages
1000 * @param text pointer to a ASCII string, in which the output is written
1001 * @param size maximal size of text buffer
1002 * @param verbose if set to true verbose information is printed out.
1003 * @return negative value if there was an error
1005 int dlt_message_print_hex(DltMessage *message, char *text, uint32_t size, int verbose);
1008 * Print payload of a DLT message as ASCII-Output
1009 * @param message pointer to structure of organising access to DLT messages
1010 * @param text pointer to a ASCII string, in which the output is written
1011 * @param size maximal size of text buffer
1012 * @param verbose if set to true verbose information is printed out.
1013 * @return negative value if there was an error
1015 int dlt_message_print_ascii(DltMessage *message, char *text, uint32_t size, int verbose);
1018 * Print payload of a DLT message as Mixed-Ouput (Hex and ASCII), for plain text output
1019 * @param message pointer to structure of organising access to DLT messages
1020 * @param text pointer to a ASCII string, in which the output is written
1021 * @param size maximal size of text buffer
1022 * @param verbose if set to true verbose information is printed out.
1023 * @return negative value if there was an error
1025 int dlt_message_print_mixed_plain(DltMessage *message, char *text, uint32_t size, int verbose);
1028 * Print payload of a DLT message as Mixed-Ouput (Hex and ASCII), for HTML text output
1029 * @param message pointer to structure of organising access to DLT messages
1030 * @param text pointer to a ASCII string, in which the output is written
1031 * @param size maximal size of text buffer
1032 * @param verbose if set to true verbose information is printed out.
1033 * @return negative value if there was an error
1035 int dlt_message_print_mixed_html(DltMessage *message, char *text, uint32_t size, int verbose);
1038 * Decode and print a argument of a DLT message
1039 * @param msg pointer to structure of organising access to DLT messages
1040 * @param type_info Type of argument
1041 * @param ptr pointer to pointer to data (pointer to data is changed within this function)
1042 * @param datalength pointer to datalength (datalength is changed within this function)
1043 * @param text pointer to a ASCII string, in which the output is written
1044 * @param textlength maximal size of text buffer
1045 * @param byteLength If argument is a string, and this value is 0 or greater, this value will be taken as string length
1046 * @param verbose if set to true verbose information is printed out.
1047 * @return negative value if there was an error
1049 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);
1059 #endif /* DLT_COMMON_H */