3 * Copyright (C) 2012 BMW AG
5 * This file is part of GENIVI Project Dlt - Diagnostic Log and Trace console apps.
7 * Contributions are licensed to the GENIVI Alliance under one or more
8 * Contribution License Agreements.
11 * This Source Code Form is subject to the terms of the
12 * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with
13 * this file, You can obtain one at http://mozilla.org/MPL/2.0/.
16 * \author Alexander Wenzel <alexander.aw.wenzel@bmw.de> BMW 2011-2012
19 * For further information see http://www.genivi.org/.
23 /*******************************************************************************
25 ** SRC-MODULE: dlt_common.h **
31 ** AUTHOR : Alexander Wenzel Alexander.AW.Wenzel@bmw.de **
38 ** PLATFORM DEPENDANT [yes/no]: yes **
40 ** TO BE CHANGED BY USER [yes/no]: no **
42 *******************************************************************************/
44 /*******************************************************************************
46 ********************************************************************************
48 ** Initials Name Company **
49 ** -------- ------------------------- ---------------------------------- **
50 ** aw Alexander Wenzel BMW **
51 ** mk Markus Klein Fraunhofer ESK **
52 *******************************************************************************/
54 /*******************************************************************************
55 ** Revision Control History **
56 *******************************************************************************/
59 * $LastChangedRevision: 1670 $
60 * $LastChangedDate: 2011-04-08 15:12:06 +0200 (Fr, 08. Apr 2011) $
69 \defgroup commonapi DLT Common API
76 #if !defined(_MSC_VER)
81 #if !defined (__WIN32__) && !defined(_MSC_VER)
85 #include "dlt_types.h"
86 #include "dlt_protocol.h"
89 #define PACKED __attribute__((aligned(1),packed))
92 #if defined (__MSDOS__) || defined (_MSC_VER)
93 /* set instead /Zp8 flag in Visual C++ configuration */
99 * Macros to swap the byte order.
101 #define DLT_SWAP_64(value) ((((uint64_t)DLT_SWAP_32((value)&0xffffffffull))<<32) | (DLT_SWAP_32((value)>>32)))
103 #define DLT_SWAP_16(value) ((((value) >> 8)&0xff) | (((value) << 8)&0xff00))
104 #define DLT_SWAP_32(value) ((((value) >> 24)&0xff) | (((value) << 8)&0xff0000) | (((value) >> 8)&0xff00) | (((value) << 24)&0xff000000))
106 /* Set Big Endian and Little Endian to a initial value, if not defined */
107 #ifndef LITTLE_ENDIAN
108 #define LITTLE_ENDIAN 1234
112 #define BIG_ENDIAN 4321
115 /* If byte order is not defined, default to little endian */
117 #define BYTE_ORDER LITTLE_ENDIAN
120 /* Check for byte-order */
121 #if (BYTE_ORDER==BIG_ENDIAN)
122 /* #warning "Big Endian Architecture!" */
123 #define DLT_HTOBE_16(x) ((x))
124 #define DLT_HTOLE_16(x) DLT_SWAP_16((x))
125 #define DLT_BETOH_16(x) ((x))
126 #define DLT_LETOH_16(x) DLT_SWAP_16((x))
128 #define DLT_HTOBE_32(x) ((x))
129 #define DLT_HTOLE_32(x) DLT_SWAP_32((x))
130 #define DLT_BETOH_32(x) ((x))
131 #define DLT_LETOH_32(x) DLT_SWAP_32((x))
133 #define DLT_HTOBE_64(x) ((x))
134 #define DLT_HTOLE_64(x) DLT_SWAP_64((x))
135 #define DLT_BETOH_64(x) ((x))
136 #define DLT_LETOH_64(x) DLT_SWAP_64((x))
138 /* #warning "Litte Endian Architecture!" */
139 #define DLT_HTOBE_16(x) DLT_SWAP_16((x))
140 #define DLT_HTOLE_16(x) ((x))
141 #define DLT_BETOH_16(x) DLT_SWAP_16((x))
142 #define DLT_LETOH_16(x) ((x))
144 #define DLT_HTOBE_32(x) DLT_SWAP_32((x))
145 #define DLT_HTOLE_32(x) ((x))
146 #define DLT_BETOH_32(x) DLT_SWAP_32((x))
147 #define DLT_LETOH_32(x) ((x))
149 #define DLT_HTOBE_64(x) DLT_SWAP_64((x))
150 #define DLT_HTOLE_64(x) ((x))
151 #define DLT_BETOH_64(x) DLT_SWAP_64((x))
152 #define DLT_LETOH_64(x) ((x))
155 #define DLT_ENDIAN_GET_16(htyp,x) ((((htyp) & DLT_HTYP_MSBF)>0)?DLT_BETOH_16(x):DLT_LETOH_16(x))
156 #define DLT_ENDIAN_GET_32(htyp,x) ((((htyp) & DLT_HTYP_MSBF)>0)?DLT_BETOH_32(x):DLT_LETOH_32(x))
157 #define DLT_ENDIAN_GET_64(htyp,x) ((((htyp) & DLT_HTYP_MSBF)>0)?DLT_BETOH_64(x):DLT_LETOH_64(x))
159 #if defined (__WIN32__) || defined (_MSC_VER)
164 #define LOG_WARNING 4
170 #define LOG_DAEMON (3<<3)
174 * The standard TCP Port used for DLT daemon
176 #define DLT_DAEMON_TCP_PORT 3490
179 /* Initi value for file descritpor */
180 #define DLT_FD_INIT -1
182 /* Minimum value for a file descriptor except the POSIX Standards: stdin=0, stdout=1, stderr=2 */
183 #define DLT_FD_MINIMUM 3
186 * The size of a DLT ID
188 #define DLT_ID_SIZE 4
190 #define DLT_SIZE_WEID DLT_ID_SIZE
191 #define DLT_SIZE_WSID (sizeof(uint32_t))
192 #define DLT_SIZE_WTMS (sizeof(uint32_t))
195 * Get the size of extra header parameters, depends on htyp.
197 #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) )
200 #if defined (__MSDOS__) || defined (_MSC_VER)
201 #define __func__ __FUNCTION__
204 #define PRINT_FUNCTION_VERBOSE(_verbose) \
206 static char _strbuf[255]; \
210 snprintf(_strbuf, 255, "%s()\n",__func__); \
211 dlt_log(LOG_INFO, _strbuf); \
216 #define NULL (char*)0
219 #define DLT_MSG_IS_CONTROL(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \
220 (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin)==DLT_TYPE_CONTROL))
222 #define DLT_MSG_IS_CONTROL_REQUEST(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \
223 (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin)==DLT_TYPE_CONTROL) && \
224 (DLT_GET_MSIN_MTIN((MSG)->extendedheader->msin)==DLT_CONTROL_REQUEST))
226 #define DLT_MSG_IS_CONTROL_RESPONSE(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \
227 (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin)==DLT_TYPE_CONTROL) && \
228 (DLT_GET_MSIN_MTIN((MSG)->extendedheader->msin)==DLT_CONTROL_RESPONSE))
230 #define DLT_MSG_IS_CONTROL_TIME(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \
231 (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin)==DLT_TYPE_CONTROL) && \
232 (DLT_GET_MSIN_MTIN((MSG)->extendedheader->msin)==DLT_CONTROL_TIME))
234 #define DLT_MSG_IS_NW_TRACE(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \
235 (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin)==DLT_TYPE_NW_TRACE))
237 #define DLT_MSG_IS_TRACE_MOST(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \
238 (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin)==DLT_TYPE_NW_TRACE) && \
239 (DLT_GET_MSIN_MTIN((MSG)->extendedheader->msin)==DLT_NW_TRACE_MOST))
241 #define DLT_MSG_IS_NONVERBOSE(MSG) (!(DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) || \
242 ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && (!(DLT_IS_MSIN_VERB((MSG)->extendedheader->msin)))))
246 * Definitions of DLT message buffer overflow
248 #define DLT_MESSAGE_BUFFER_NO_OVERFLOW 0x00 /**< Buffer overflow has not occured */
249 #define DLT_MESSAGE_BUFFER_OVERFLOW 0x01 /**< Buffer overflow has occured */
252 * Definition of DLT output variants
254 #define DLT_OUTPUT_HEX 1
255 #define DLT_OUTPUT_ASCII 2
256 #define DLT_OUTPUT_MIXED_FOR_PLAIN 3
257 #define DLT_OUTPUT_MIXED_FOR_HTML 4
258 #define DLT_OUTPUT_ASCII_LIMITED 5
260 #define DLT_FILTER_MAX 30 /**< Maximum number of filters */
262 #define DLT_MSG_READ_VALUE(dst,src,length,type) \
264 if((length<0) || ((length)<((int32_t)sizeof(type)))) \
267 { dst = *((type*)src);src+=sizeof(type);length-=sizeof(type); } \
270 #define DLT_MSG_READ_ID(dst,src,length) \
272 if((length<0) || ((length)<DLT_ID_SIZE)) \
275 { memcpy(dst,src,DLT_ID_SIZE);src+=DLT_ID_SIZE;length-=DLT_ID_SIZE; } \
278 #define DLT_MSG_READ_STRING(dst,src,maxlength,length) \
280 if(((maxlength)<0) || ((length)<0) || ((maxlength)<(length))) \
281 { maxlength = -1; } \
283 { memcpy(dst,src,length);dlt_clean_string(dst,length);dst[length]=0; \
284 src+=length;maxlength-=length; } \
287 #define DLT_MSG_READ_NULL(src,maxlength,length) \
289 if(((maxlength)<0) || ((length)<0) || ((maxlength)<(length))) \
292 { src+=length;maxlength-=length; } \
295 #define DLT_HEADER_SHOW_NONE 0x0000
296 #define DLT_HEADER_SHOW_TIME 0x0001
297 #define DLT_HEADER_SHOW_TMSTP 0x0002
298 #define DLT_HEADER_SHOW_MSGCNT 0x0004
299 #define DLT_HEADER_SHOW_ECUID 0x0008
300 #define DLT_HEADER_SHOW_APID 0x0010
301 #define DLT_HEADER_SHOW_CTID 0x0020
302 #define DLT_HEADER_SHOW_MSGTYPE 0x0040
303 #define DLT_HEADER_SHOW_MSGSUBTYPE 0x0080
304 #define DLT_HEADER_SHOW_VNVSTATUS 0x0100
305 #define DLT_HEADER_SHOW_NOARG 0x0200
306 #define DLT_HEADER_SHOW_ALL 0xFFFF
309 * The definition of the serial header containing the characters "DLS" + 0x01.
311 extern const char dltSerialHeader[DLT_ID_SIZE];
314 * The definition of the serial header containing the characters "DLS" + 0x01 as char.
316 extern char dltSerialHeaderChar[DLT_ID_SIZE];
320 * The type of a DLT ID (context id, application id, etc.)
322 typedef char ID4[DLT_ID_SIZE];
325 * The structure of the DLT file storage header. This header is used before each stored DLT message.
329 char pattern[DLT_ID_SIZE]; /**< This pattern should be DLT0x01 */
330 uint32_t seconds; /**< seconds since 1.1.1970 */
331 int32_t microseconds; /**< Microseconds */
332 char ecu[DLT_ID_SIZE]; /**< The ECU id is added, if it is not already in the DLT message itself */
333 } PACKED DltStorageHeader;
336 * The structure of the DLT standard header. This header is used in each DLT message.
340 uint8_t htyp; /**< This parameter contains several informations, see definitions below */
341 uint8_t mcnt; /**< The message counter is increased with each sent DLT message */
342 uint16_t len; /**< Length of the complete message, without storage header */
343 } PACKED DltStandardHeader;
346 * The structure of the DLT extra header parameters. Each parameter is sent only if enabled in htyp.
350 char ecu[DLT_ID_SIZE]; /**< ECU id */
351 uint32_t seid; /**< Session number */
352 uint32_t tmsp; /**< Timestamp since system start in 0.1 milliseconds */
353 } PACKED DltStandardHeaderExtra;
356 * The structure of the DLT extended header. This header is only sent if enabled in htyp parameter.
360 uint8_t msin; /**< messsage info */
361 uint8_t noar; /**< number of arguments */
362 char apid[DLT_ID_SIZE]; /**< application id */
363 char ctid[DLT_ID_SIZE]; /**< context id */
364 } PACKED DltExtendedHeader;
367 * The structure to organise the DLT messages.
368 * This structure is used by the corresponding functions.
370 typedef struct sDltMessage
373 int8_t found_serialheader;
376 int32_t resync_offset;
378 /* size parameters */
379 int32_t headersize; /**< size of complete header including storage header */
380 int32_t datasize; /**< size of complete payload */
382 /* buffer for current loaded message */
383 uint8_t headerbuffer[sizeof(DltStorageHeader)+
384 sizeof(DltStandardHeader)+sizeof(DltStandardHeaderExtra)+sizeof(DltExtendedHeader)]; /**< buffer for loading complete header */
385 uint8_t *databuffer; /**< buffer for loading payload */
386 int32_t databuffersize;
388 /* header values of current loaded message */
389 DltStorageHeader *storageheader; /**< pointer to storage header of current loaded header */
390 DltStandardHeader *standardheader; /**< pointer to standard header of current loaded header */
391 DltStandardHeaderExtra headerextra; /**< extra parameters of current loaded header */
392 DltExtendedHeader *extendedheader; /**< pointer to extended of current loaded header */
396 * The structure of the DLT Service Get Log Info.
400 uint32_t service_id; /**< service ID */
401 uint8_t options; /**< type of request */
402 char apid[DLT_ID_SIZE]; /**< application id */
403 char ctid[DLT_ID_SIZE]; /**< context id */
404 char com[DLT_ID_SIZE]; /**< communication interface */
405 } PACKED DltServiceGetLogInfoRequest;
408 * The structure of the DLT Service Set Log Level.
413 uint32_t service_id; /**< service ID */
414 char apid[DLT_ID_SIZE]; /**< application id */
415 char ctid[DLT_ID_SIZE]; /**< context id */
416 uint8_t log_level; /**< log level to be set */
417 char com[DLT_ID_SIZE]; /**< communication interface */
418 } PACKED DltServiceSetLogLevel;
421 * The structure of the DLT Service Set Default Log Level.
425 uint32_t service_id; /**< service ID */
426 uint8_t log_level; /**< default log level to be set */
427 char com[DLT_ID_SIZE]; /**< communication interface */
428 } PACKED DltServiceSetDefaultLogLevel;
431 * The structure of the DLT Service Set Verbose Mode
435 uint32_t service_id; /**< service ID */
436 uint8_t new_status; /**< new status to be set */
437 } PACKED DltServiceSetVerboseMode;
440 * The structure of the DLT Service Set Communication Interface Status
444 uint32_t service_id; /**< service ID */
445 char com[DLT_ID_SIZE]; /**< communication interface */
446 uint8_t new_status; /**< new status to be set */
447 } PACKED DltServiceSetCommunicationInterfaceStatus;
450 * The structure of the DLT Service Set Communication Maximum Bandwidth
454 uint32_t service_id; /**< service ID */
455 char com[DLT_ID_SIZE]; /**< communication interface */
456 uint32_t max_bandwidth; /**< maximum bandwith */
457 } PACKED DltServiceSetCommunicationMaximumBandwidth;
461 uint32_t service_id; /**< service ID */
462 uint8_t status; /**< reponse status */
463 } PACKED DltServiceResponse;
467 uint32_t service_id; /**< service ID */
468 uint8_t status; /**< reponse status */
469 uint8_t log_level; /**< log level */
470 } PACKED DltServiceGetDefaultLogLevelResponse;
474 uint32_t service_id; /**< service ID */
475 uint8_t status; /**< reponse status */
476 uint8_t overflow; /**< overflow status */
477 } PACKED DltServiceMessageBufferOverflowResponse;
481 uint32_t service_id; /**< service ID */
482 uint8_t status; /**< reponse status */
483 uint32_t length; /**< length of following payload */
484 /* char [] payload */
485 } PACKED DltServiceGetSoftwareVersionResponse;
488 * Structure to store filter parameters.
489 * ID are maximal four characters. Unused values are filled with zeros.
490 * If every value as filter is valid, the id should be empty by having only zero values.
494 char apid[DLT_FILTER_MAX][DLT_ID_SIZE]; /**< application id */
495 char ctid[DLT_FILTER_MAX][DLT_ID_SIZE]; /**< context id */
496 int counter; /**< number of filters */
500 * The structure to organise the access to DLT files.
501 * This structure is used by the corresponding functions.
503 typedef struct sDltFile
505 /* file handle and index for fast access */
506 FILE *handle; /**< file handle of opened DLT file */
507 long *index; /**< file positions of all DLT messages for fast access to file, only filtered messages */
509 /* size parameters */
510 int32_t counter; /**< number of messages in DLT file with filter */
511 int32_t counter_total; /**< number of messages in DLT file without filter */
512 int32_t position; /**< current index to message parsed in DLT file starting at 0 */
513 long file_length; /**< length of the file */
514 long file_position; /**< current position in the file */
517 int32_t error_messages; /**< number of incomplete DLT messages found during file parsing */
519 /* filter parameters */
520 DltFilter *filter; /**< pointer to filter list. Zero if no filter is set. */
521 int32_t filter_counter; /**< number of filter set */
523 /* current loaded message */
524 DltMessage msg; /**< pointer to message */
529 * The structure is used to organise the receiving of data
530 * including buffer handling.
531 * This structure is used by the corresponding functions.
535 int32_t lastBytesRcvd; /**< bytes received in last receive call */
536 int32_t bytesRcvd; /**< received bytes */
537 int32_t totalBytesRcvd; /**< total number of received bytes */
538 char *buffer; /**< pointer to receiver buffer */
539 char *buf; /**< pointer to position within receiver buffer */
540 int fd; /**< connection handle */
541 int32_t buffersize; /**< size of receiver buffer */
546 unsigned char* shm; /* pointer to beginning of shared memory */
547 int size; /* size of data area in shared memory */
548 unsigned char* mem; /* pointer to data area in shared memory */
550 uint32_t min_size; /**< Minimum size of buffer */
551 uint32_t max_size; /**< Maximum size of buffer */
552 uint32_t step_size; /**< Step size of buffer */
562 #define DLT_BUFFER_HEAD "SHM"
567 unsigned char status;
569 } DltBufferBlockHead;
577 * Helper function to print a byte array in hex.
578 * @param ptr pointer to the byte array.
579 * @param size number of bytes to be printed.
581 void dlt_print_hex(uint8_t *ptr,int size);
583 * Helper function to print a byte array in hex into a string.
584 * @param text pointer to a ASCII string, in which the text is written
585 * @param textlength maximal size of text buffer
586 * @param ptr pointer to the byte array.
587 * @param size number of bytes to be printed.
588 * @return negative value if there was an error
590 int dlt_print_hex_string(char *text,int textlength,uint8_t *ptr,int size);
592 * Helper function to print a byte array in hex and ascii into a string.
593 * @param text pointer to a ASCII string, in which the text is written
594 * @param textlength maximal size of text buffer
595 * @param ptr pointer to the byte array.
596 * @param size number of bytes to be printed.
597 * @param html output is html? 0 - false, 1 - true
598 * @return negative value if there was an error
600 int dlt_print_mixed_string(char *text,int textlength,uint8_t *ptr,int size,int html);
602 * Helper function to print a byte array in ascii into a string.
603 * @param text pointer to a ASCII string, in which the text is written
604 * @param textlength maximal size of text buffer
605 * @param ptr pointer to the byte array.
606 * @param size number of bytes to be printed.
607 * @return negative value if there was an error
609 int dlt_print_char_string(char **text,int textlength,uint8_t *ptr,int size);
612 * Helper function to print an id.
613 * @param text pointer to ASCII string where to write the id
614 * @param id four byte char array as used in DLT mesages as IDs.
616 void dlt_print_id(char *text,const char *id);
619 * Helper function to set an ID parameter.
620 * @param id four byte char array as used in DLT mesages as IDs.
621 * @param text string to be copied into char array.
623 void dlt_set_id(char *id,const char *text);
626 * Helper function to remove not nice to print characters, e.g. NULL or carage return.
627 * @param text pointer to string to be cleaned.
628 * @param length length of string excluding terminating zero.
630 void dlt_clean_string(char *text,int length);
633 * Initialise the filter list.
634 * This function must be called before using further dlt filter.
635 * @param filter pointer to structure of organising DLT filter
636 * @param verbose if set to true verbose information is printed out.
637 * @return negative value if there was an error
639 int dlt_filter_init(DltFilter *filter,int verbose);
641 * Free the used memory by the organising structure of filter.
642 * @param filter pointer to structure of organising DLT filter
643 * @param verbose if set to true verbose information is printed out.
644 * @return negative value if there was an error
646 int dlt_filter_free(DltFilter *filter,int verbose);
648 * Load filter list from file.
649 * @param filter pointer to structure of organising DLT filter
650 * @param filename filename to load filters from
651 * @param verbose if set to true verbose information is printed out.
652 * @return negative value if there was an error
654 int dlt_filter_load(DltFilter *filter,const char *filename,int verbose);
656 * Save filter list to file.
657 * @param filter pointer to structure of organising DLT filter
658 * @param filename filename to load filters from
659 * @param verbose if set to true verbose information is printed out.
660 * @return negative value if there was an error
662 int dlt_filter_save(DltFilter *filter,const char *filename,int verbose);
664 * Find index of filter in filter list
665 * @param filter pointer to structure of organising DLT filter
666 * @param apid application id to be found in filter list
667 * @param ctid context id to be found in filter list
668 * @param verbose if set to true verbose information is printed out.
669 * @return negative value if there was an error (or not found), else return index of filter
671 int dlt_filter_find(DltFilter *filter,const char *apid,const char *ctid, int verbose);
673 * Add new filter to filter list.
674 * @param filter pointer to structure of organising DLT filter
675 * @param apid application id to be added to filter list (must always be set).
676 * @param ctid context id to be added to filter list. empty equals don't care.
677 * @param verbose if set to true verbose information is printed out.
678 * @return negative value if there was an error
680 int dlt_filter_add(DltFilter *filter,const char *apid,const char *ctid,int verbose);
682 * Delete filter from filter list
683 * @param filter pointer to structure of organising DLT filter
684 * @param apid application id to be deleted from filter list
685 * @param ctid context id to be deleted from filter list
686 * @param verbose if set to true verbose information is printed out.
687 * @return negative value if there was an error
689 int dlt_filter_delete(DltFilter *filter,const char *apid,const char *ctid,int verbose);
692 * Initialise the structure used to access a DLT message.
693 * This function must be called before using further dlt_message functions.
694 * @param msg pointer to structure of organising access to DLT messages
695 * @param verbose if set to true verbose information is printed out.
696 * @return negative value if there was an error
698 int dlt_message_init(DltMessage *msg,int verbose);
700 * Free the used memory by the organising structure of file.
701 * @param msg pointer to structure of organising access to DLT messages
702 * @param verbose if set to true verbose information is printed out.
703 * @return negative value if there was an error
705 int dlt_message_free(DltMessage *msg,int verbose);
707 * Print Header into an ASCII string.
708 * This function calls dlt_message_header_flags() with flags=DLT_HEADER_SHOW_ALL
709 * @param msg pointer to structure of organising access to DLT messages
710 * @param text pointer to a ASCII string, in which the header is written
711 * @param textlength maximal size of text buffer
712 * @param verbose if set to true verbose information is printed out.
713 * @return negative value if there was an error
715 int dlt_message_header(DltMessage *msg,char *text,int textlength,int verbose);
717 * Print Header into an ASCII string, selective.
718 * @param msg pointer to structure of organising access to DLT messages
719 * @param text pointer to a ASCII string, in which the header is written
720 * @param textlength maximal size of text buffer
721 * @param flags select, bit-field to select, what should be printed (DLT_HEADER_SHOW_...)
722 * @param verbose if set to true verbose information is printed out.
723 * @return negative value if there was an error
725 int dlt_message_header_flags(DltMessage *msg,char *text,int textlength,int flags, int verbose);
727 * Print Payload into an ASCII string.
728 * @param msg pointer to structure of organising access to DLT messages
729 * @param text pointer to a ASCII string, in which the header is written
730 * @param textlength maximal size of text buffer
731 * @param type 1 = payload as hex, 2 = payload as ASCII.
732 * @param verbose if set to true verbose information is printed out.
733 * @return negative value if there was an error
735 int dlt_message_payload(DltMessage *msg,char *text,int textlength,int type,int verbose);
737 * Check if message is filtered or not. All filters are applied (logical OR).
738 * @param msg pointer to structure of organising access to DLT messages
739 * @param filter pointer to filter
740 * @param verbose if set to true verbose information is printed out.
741 * @return 1 = filter matches, 0 = filter does not match, negative value if there was an error
743 int dlt_message_filter_check(DltMessage *msg,DltFilter *filter,int verbose);
746 * Read message from memory buffer.
747 * Message in buffer has no storage header.
748 * @param msg pointer to structure of organising access to DLT messages
749 * @param buffer pointer to memory buffer
750 * @param length length of message in buffer
751 * @param resync if set to true resync to serial header is enforced
752 * @param verbose if set to true verbose information is printed out.
753 * @return negative value if there was an error
755 int dlt_message_read(DltMessage *msg,uint8_t *buffer,unsigned int length,int resync,int verbose);
758 * Get standard header extra parameters
759 * @param msg pointer to structure of organising access to DLT messages
760 * @param verbose if set to true verbose information is printed out.
761 * @return negative value if there was an error
763 int dlt_message_get_extraparameters(DltMessage *msg,int verbose);
766 * Set standard header extra parameters
767 * @param msg pointer to structure of organising access to DLT messages
768 * @param verbose if set to true verbose information is printed out.
769 * @return negative value if there was an error
771 int dlt_message_set_extraparameters(DltMessage *msg,int verbose);
774 * Initialise the structure used to access a DLT file.
775 * This function must be called before using further dlt_file functions.
776 * @param file pointer to structure of organising access to DLT file
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_init(DltFile *file,int verbose);
782 * Set a list to filters.
783 * This function should be called before loading a DLT file, if filters should be used.
784 * A filter list is an array of filters. Several filters are combined logically by or operation.
785 * The filter list is not copied, so take care to keep list in memory.
786 * @param file pointer to structure of organising access to DLT file
787 * @param filter pointer to filter list array
788 * @param verbose if set to true verbose information is printed out.
789 * @return negative value if there was an error
791 int dlt_file_set_filter(DltFile *file,DltFilter *filter,int verbose);
793 * Initialising loading a DLT file.
794 * @param file pointer to structure of organising access to DLT file
795 * @param filename filename of DLT file
796 * @param verbose if set to true verbose information is printed out.
797 * @return negative value if there was an error
799 int dlt_file_open(DltFile *file,const char *filename,int verbose);
801 * Find next message in the DLT file and parse them.
802 * This function finds the next message in the DLT file.
803 * If a filter is set, the filter list is used.
804 * @param file pointer to structure of organising access to DLT file
805 * @param verbose if set to true verbose information is printed out.
806 * @return 0 = message does not match filter, 1 = message was read, negative value if there was an error
808 int dlt_file_read(DltFile *file,int verbose);
810 * Find next message in the DLT file in RAW format (without storage header) and parse them.
811 * This function finds the next message in the DLT file.
812 * If a filter is set, the filter list is used.
813 * @param file pointer to structure of organising access to DLT file
814 * @param resync Resync to serial header when set to true
815 * @param verbose if set to true verbose information is printed out.
816 * @return 0 = message does not match filter, 1 = message was read, negative value if there was an error
818 int dlt_file_read_raw(DltFile *file,int resync,int verbose);
820 * Closing loading a DLT file.
821 * @param file pointer to structure of organising access to DLT file
822 * @param verbose if set to true verbose information is printed out.
823 * @return negative value if there was an error
825 int dlt_file_close(DltFile *file,int verbose);
827 * Load standard header of a message from file
828 * @param file pointer to structure of organising access to DLT file
829 * @param verbose if set to true verbose information is printed out.
830 * @return negative value if there was an error
832 int dlt_file_read_header(DltFile *file,int verbose);
834 * Load standard header of a message from file in RAW format (without storage header)
835 * @param file pointer to structure of organising access to DLT file
836 * @param resync Resync to serial header when set to true
837 * @param verbose if set to true verbose information is printed out.
838 * @return negative value if there was an error
840 int dlt_file_read_header_raw(DltFile *file,int resync,int verbose);
842 * Load, if available in message, extra standard header fields and
843 * extended header of a message from file
844 * (dlt_file_read_header() must have been called before this call!)
845 * @param file pointer to structure of organising access to DLT file
846 * @param verbose if set to true verbose information is printed out.
847 * @return negative value if there was an error
849 int dlt_file_read_header_extended(DltFile *file, int verbose);
851 * Load payload of a message from file
852 * (dlt_file_read_header() must have been called before this call!)
853 * @param file pointer to structure of organising access to DLT file
854 * @param verbose if set to true verbose information is printed out.
855 * @return negative value if there was an error
857 int dlt_file_read_data(DltFile *file, int verbose);
859 * Load headers and payload of a message selected by the index.
860 * If filters are set, index is based on the filtered list.
861 * @param file pointer to structure of organising access to DLT file
862 * @param index position of message in the files beginning from zero
863 * @param verbose if set to true verbose information is printed out.
864 * @return number of messages loaded, negative value if there was an error
866 int dlt_file_message(DltFile *file,int index,int verbose);
868 * Free the used memory by the organising structure of file.
869 * @param file pointer to structure of organising access to DLT file
870 * @param verbose if set to true verbose information is printed out.
871 * @return negative value if there was an error
873 int dlt_file_free(DltFile *file,int verbose);
876 * Set internal logging filename if mode 2
877 * @param filename the filename
879 void dlt_log_set_filename(const char *filename);
881 * Set internal logging level
882 * @param level the level
884 void dlt_log_set_level(int level);
886 * Initialize (external) logging facility
887 * @param mode positive, 0 = log to stdout, 1 = log to syslog, 2 = log to file
889 void dlt_log_init(int mode);
891 * Log ASCII string with null-termination to (external) logging facility
892 * @param prio priority (see syslog() call)
893 * @param s Pointer to ASCII string with null-termination
894 * @return negative value if there was an error
896 int dlt_log(int prio, char *s);
898 * De-Initialize (external) logging facility
900 void dlt_log_free(void);
903 * Initialising a dlt receiver structure
904 * @param receiver pointer to dlt receiver structure
905 * @param _fd handle to file/socket/fifo, fram which the data should be received
906 * @param _buffersize size of data buffer for storing the received data
907 * @return negative value if there was an error
909 int dlt_receiver_init(DltReceiver *receiver,int _fd, int _buffersize);
911 * De-Initialize a dlt receiver structure
912 * @param receiver pointer to dlt receiver structure
913 * @return negative value if there was an error
915 int dlt_receiver_free(DltReceiver *receiver);
917 * Receive data from socket using the dlt receiver structure
918 * @param receiver pointer to dlt receiver structure
919 * @return negative value if there was an error
921 int dlt_receiver_receive_socket(DltReceiver *receiver);
923 * Receive data from file/fifo using the dlt receiver structure
924 * @param receiver pointer to dlt receiver structure
925 * @return negative value if there was an error
927 int dlt_receiver_receive_fd(DltReceiver *receiver);
929 * Remove a specific size of bytes from the received data
930 * @param receiver pointer to dlt receiver structure
931 * @param size amount of bytes to be removed
932 * @return negative value if there was an error
934 int dlt_receiver_remove(DltReceiver *receiver,int size);
936 * Move data from last receive call to front of receive buffer
937 * @param receiver pointer to dlt receiver structure
938 * @return negative value if there was an error
940 int dlt_receiver_move_to_begin(DltReceiver *receiver);
943 * Fill out storage header of a dlt message
944 * @param storageheader pointer to storage header of a dlt message
945 * @param ecu name of ecu to be set in storage header
946 * @return negative value if there was an error
948 int dlt_set_storageheader(DltStorageHeader *storageheader, const char *ecu);
950 * Check if a storage header contains its marker
951 * @param storageheader pointer to storage header of a dlt message
952 * @return 0 no, 1 yes, negative value if there was an error
954 int dlt_check_storageheader(DltStorageHeader *storageheader);
958 * Initialise static ringbuffer with a size of size.
959 * Initialise as server. Init counters.
960 * Memory is already allocated.
961 * @param buf Pointer to ringbuffer structure
962 * @param ptr Ptr to ringbuffer memory
963 * @param size Maximum size of buffer in bytes
964 * @return negative value if there was an error
966 int dlt_buffer_init_static_server(DltBuffer *buf, const unsigned char *ptr, uint32_t size);
969 * Initialize static ringbuffer with a size of size.
970 * Initialise as a client. Do not change counters.
971 * Memory is already allocated.
972 * @param buf Pointer to ringbuffer structure
973 * @param ptr Ptr to ringbuffer memory
974 * @param size Maximum size of buffer in bytes
975 * @return negative value if there was an error
977 int dlt_buffer_init_static_client(DltBuffer *buf, const unsigned char *ptr, uint32_t size);
980 * Initialize dynamic ringbuffer with a size of size.
981 * Initialise as a client. Do not change counters.
982 * Memory will be allocated starting with min_size.
983 * If more memory is needed size is increased wit step_size.
984 * The maximum size is max_size.
985 * @param buf Pointer to ringbuffer structure
986 * @param min_size Minimum size of buffer in bytes
987 * @param max_size Maximum size of buffer in bytes
988 * @param step_size size of which ringbuffer is increased
989 * @return negative value if there was an error
991 int dlt_buffer_init_dynamic(DltBuffer *buf, uint32_t min_size, uint32_t max_size,uint32_t step_size);
994 * Deinitilaise usage of static ringbuffer
995 * @param buf Pointer to ringbuffer structure
996 * @return negative value if there was an error
998 int dlt_buffer_free_static(DltBuffer *buf);
1001 * Release and free memory used by dynamic ringbuffer
1002 * @param buf Pointer to ringbuffer structure
1003 * @return negative value if there was an error
1005 int dlt_buffer_free_dynamic(DltBuffer *buf);
1008 * Write one entry to ringbuffer
1009 * @param buf Pointer to ringbuffer structure
1010 * @param data Pointer to data to be written to ringbuffer
1011 * @param size Size of data in bytes to be written to ringbuffer
1012 * @return negative value if there was an error
1014 int dlt_buffer_push(DltBuffer *buf,const unsigned char *data,unsigned int size);
1017 * Write up to three entries to ringbuffer.
1018 * Entries are joined to one block.
1019 * @param dlt Pointer to ringbuffer structure
1020 * @param data1 Pointer to data to be written to ringbuffer
1021 * @param size1 Size of data in bytes to be written to ringbuffer
1022 * @param data2 Pointer to data to be written to ringbuffer
1023 * @param size2 Size of data in bytes to be written to ringbuffer
1024 * @param data3 Pointer to data to be written to ringbuffer
1025 * @param size3 Size of data in bytes to be written to ringbuffer
1026 * @return negative value if there was an error
1028 int dlt_buffer_push3(DltBuffer *buf,const unsigned char *data1,unsigned int size1,const unsigned char *data2,unsigned int size2,const unsigned char *data3,unsigned int size3);
1031 * Read one entry from ringbuffer.
1032 * Remove it from ringbuffer.
1033 * @param buf Pointer to ringbuffer structure
1034 * @param data Pointer to data read from ringbuffer
1035 * @param max_size Max size of read data in bytes from ringbuffer
1036 * @return size of read data, zero if no data available, negative value if there was an error
1038 int dlt_buffer_pull(DltBuffer *buf,unsigned char *data, int max_size);
1041 * Read one entry from ringbuffer.
1042 * Do not remove it from ringbuffer.
1043 * @param buf Pointer to ringbuffer structure
1044 * @param data Pointer to data read from ringbuffer
1045 * @param max_size Max size of read data in bytes from ringbuffer
1046 * @return size of read data, zero if no data available, negative value if there was an error
1048 int dlt_buffer_copy(DltBuffer *buf,unsigned char *data, int max_size);
1051 * Remove entry from ringbuffer.
1052 * @param buf Pointer to ringbuffer structure
1053 * @return size of read data, zero if no data available, negative value if there was an error
1055 int dlt_buffer_remove(DltBuffer *buf);
1058 * Print information about buffer and log to internal DLT log.
1059 * @param buf Pointer to ringbuffer structure
1061 void dlt_buffer_info(DltBuffer *buf);
1064 * Print status of buffer and log to internal DLT log.
1065 * @param buf Pointer to ringbuffer structure
1067 void dlt_buffer_status(DltBuffer *buf);
1070 * Get total size in bytes of ringbuffer.
1071 * If buffer is dynamic, max size is returned.
1072 * @param buf Pointer to ringbuffer structure
1073 * @return total size of buffer
1075 int dlt_buffer_get_total_size(DltBuffer *buf);
1078 * Get used size in bytes of ringbuffer.
1079 * @param buf Pointer to ringbuffer structure
1080 * @return used size of buffer
1082 int dlt_buffer_get_used_size(DltBuffer *buf);
1085 * Get number of entries in ringbuffer.
1086 * @param buf Pointer to ringbuffer structure
1087 * @return number of entries
1089 int dlt_buffer_get_message_count(DltBuffer *buf);
1091 #if !defined (__WIN32__)
1094 * Helper function: Setup serial connection
1095 * @param fd File descriptor of serial tty device
1096 * @param speed Serial line speed, as defined in termios.h
1097 * @return negative value if there was an error
1099 int dlt_setup_serial(int fd, speed_t speed);
1102 * Helper function: Convert serial line baudrate (as number) to line speed (as defined in termios.h)
1103 * @param baudrate Serial line baudrate (as number)
1104 * @return Serial line speed, as defined in termios.h
1106 speed_t dlt_convert_serial_speed(int baudrate);
1109 * Print dlt version and dlt svn version to buffer
1110 * @param buf Pointer to buffer
1112 void dlt_get_version(char *buf);
1115 * Print dlt major version to buffer
1116 * @param buf Pointer to buffer
1118 void dlt_get_major_version(char *buf);
1121 * Print dlt minor version to buffer
1122 * @param buf Pointer to buffer
1124 void dlt_get_minor_version(char *buf);
1128 /* Function prototypes which should be used only internally */
1132 * Common part of initialisation
1133 * @return negative value if there was an error
1135 int dlt_init_common(void);
1138 * Return the uptime of the system in 0.1 ms resolution
1139 * @return 0 if there was an error
1141 uint32_t dlt_uptime(void);
1144 * Print header of a DLT message
1145 * @param message pointer to structure of organising access to DLT messages
1146 * @param text pointer to a ASCII string, in which the header is written
1147 * @param size maximal size of text buffer
1148 * @param verbose if set to true verbose information is printed out.
1149 * @return negative value if there was an error
1151 int dlt_message_print_header(DltMessage *message, char *text, uint32_t size, int verbose);
1154 * Print payload of a DLT message as Hex-Output
1155 * @param message pointer to structure of organising access to DLT messages
1156 * @param text pointer to a ASCII string, in which the output is written
1157 * @param size maximal size of text buffer
1158 * @param verbose if set to true verbose information is printed out.
1159 * @return negative value if there was an error
1161 int dlt_message_print_hex(DltMessage *message, char *text, uint32_t size, int verbose);
1164 * Print payload of a DLT message as ASCII-Output
1165 * @param message pointer to structure of organising access to DLT messages
1166 * @param text pointer to a ASCII string, in which the output is written
1167 * @param size maximal size of text buffer
1168 * @param verbose if set to true verbose information is printed out.
1169 * @return negative value if there was an error
1171 int dlt_message_print_ascii(DltMessage *message, char *text, uint32_t size, int verbose);
1174 * Print payload of a DLT message as Mixed-Ouput (Hex and ASCII), for plain text output
1175 * @param message pointer to structure of organising access to DLT messages
1176 * @param text pointer to a ASCII string, in which the output is written
1177 * @param size maximal size of text buffer
1178 * @param verbose if set to true verbose information is printed out.
1179 * @return negative value if there was an error
1181 int dlt_message_print_mixed_plain(DltMessage *message, char *text, uint32_t size, int verbose);
1184 * Print payload of a DLT message as Mixed-Ouput (Hex and ASCII), for HTML text output
1185 * @param message pointer to structure of organising access to DLT messages
1186 * @param text pointer to a ASCII string, in which the output is written
1187 * @param size maximal size of text buffer
1188 * @param verbose if set to true verbose information is printed out.
1189 * @return negative value if there was an error
1191 int dlt_message_print_mixed_html(DltMessage *message, char *text, uint32_t size, int verbose);
1194 * Decode and print a argument of a DLT message
1195 * @param msg pointer to structure of organising access to DLT messages
1196 * @param type_info Type of argument
1197 * @param ptr pointer to pointer to data (pointer to data is changed within this function)
1198 * @param datalength pointer to datalength (datalength is changed within this function)
1199 * @param text pointer to a ASCII string, in which the output is written
1200 * @param textlength maximal size of text buffer
1201 * @param byteLength If argument is a string, and this value is 0 or greater, this value will be taken as string length
1202 * @param verbose if set to true verbose information is printed out.
1203 * @return negative value if there was an error
1205 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);
1215 #endif /* DLT_COMMON_H */