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 #if !defined __USE_BSD
108 #ifndef LITTLE_ENDIAN
109 #define LITTLE_ENDIAN 1234
113 #define BIG_ENDIAN 4321
115 #endif /* __USE_BSD */
117 /* If byte order is not defined, default to little endian */
118 #if !defined __USE_BSD
120 #define BYTE_ORDER LITTLE_ENDIAN
122 #endif /* __USE_BSD */
124 /* Check for byte-order */
125 #if (BYTE_ORDER==BIG_ENDIAN)
126 /* #warning "Big Endian Architecture!" */
127 #define DLT_HTOBE_16(x) ((x))
128 #define DLT_HTOLE_16(x) DLT_SWAP_16((x))
129 #define DLT_BETOH_16(x) ((x))
130 #define DLT_LETOH_16(x) DLT_SWAP_16((x))
132 #define DLT_HTOBE_32(x) ((x))
133 #define DLT_HTOLE_32(x) DLT_SWAP_32((x))
134 #define DLT_BETOH_32(x) ((x))
135 #define DLT_LETOH_32(x) DLT_SWAP_32((x))
137 #define DLT_HTOBE_64(x) ((x))
138 #define DLT_HTOLE_64(x) DLT_SWAP_64((x))
139 #define DLT_BETOH_64(x) ((x))
140 #define DLT_LETOH_64(x) DLT_SWAP_64((x))
142 /* #warning "Litte Endian Architecture!" */
143 #define DLT_HTOBE_16(x) DLT_SWAP_16((x))
144 #define DLT_HTOLE_16(x) ((x))
145 #define DLT_BETOH_16(x) DLT_SWAP_16((x))
146 #define DLT_LETOH_16(x) ((x))
148 #define DLT_HTOBE_32(x) DLT_SWAP_32((x))
149 #define DLT_HTOLE_32(x) ((x))
150 #define DLT_BETOH_32(x) DLT_SWAP_32((x))
151 #define DLT_LETOH_32(x) ((x))
153 #define DLT_HTOBE_64(x) DLT_SWAP_64((x))
154 #define DLT_HTOLE_64(x) ((x))
155 #define DLT_BETOH_64(x) DLT_SWAP_64((x))
156 #define DLT_LETOH_64(x) ((x))
159 #define DLT_ENDIAN_GET_16(htyp,x) ((((htyp) & DLT_HTYP_MSBF)>0)?DLT_BETOH_16(x):DLT_LETOH_16(x))
160 #define DLT_ENDIAN_GET_32(htyp,x) ((((htyp) & DLT_HTYP_MSBF)>0)?DLT_BETOH_32(x):DLT_LETOH_32(x))
161 #define DLT_ENDIAN_GET_64(htyp,x) ((((htyp) & DLT_HTYP_MSBF)>0)?DLT_BETOH_64(x):DLT_LETOH_64(x))
163 #if defined (__WIN32__) || defined (_MSC_VER)
168 #define LOG_WARNING 4
174 #define LOG_DAEMON (3<<3)
178 * The standard TCP Port used for DLT daemon
180 #define DLT_DAEMON_TCP_PORT 3490
183 /* Initi value for file descritpor */
184 #define DLT_FD_INIT -1
186 /* Minimum value for a file descriptor except the POSIX Standards: stdin=0, stdout=1, stderr=2 */
187 #define DLT_FD_MINIMUM 3
190 * The size of a DLT ID
192 #define DLT_ID_SIZE 4
194 #define DLT_SIZE_WEID DLT_ID_SIZE
195 #define DLT_SIZE_WSID (sizeof(uint32_t))
196 #define DLT_SIZE_WTMS (sizeof(uint32_t))
199 * Get the size of extra header parameters, depends on htyp.
201 #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) )
204 #if defined (__MSDOS__) || defined (_MSC_VER)
205 #define __func__ __FUNCTION__
208 #define PRINT_FUNCTION_VERBOSE(_verbose) \
210 static char _strbuf[255]; \
214 snprintf(_strbuf, 255, "%s()\n",__func__); \
215 dlt_log(LOG_INFO, _strbuf); \
220 #define NULL (char*)0
223 #define DLT_MSG_IS_CONTROL(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \
224 (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin)==DLT_TYPE_CONTROL))
226 #define DLT_MSG_IS_CONTROL_REQUEST(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_REQUEST))
230 #define DLT_MSG_IS_CONTROL_RESPONSE(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_RESPONSE))
234 #define DLT_MSG_IS_CONTROL_TIME(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \
235 (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin)==DLT_TYPE_CONTROL) && \
236 (DLT_GET_MSIN_MTIN((MSG)->extendedheader->msin)==DLT_CONTROL_TIME))
238 #define DLT_MSG_IS_NW_TRACE(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \
239 (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin)==DLT_TYPE_NW_TRACE))
241 #define DLT_MSG_IS_TRACE_MOST(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \
242 (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin)==DLT_TYPE_NW_TRACE) && \
243 (DLT_GET_MSIN_MTIN((MSG)->extendedheader->msin)==DLT_NW_TRACE_MOST))
245 #define DLT_MSG_IS_NONVERBOSE(MSG) (!(DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) || \
246 ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && (!(DLT_IS_MSIN_VERB((MSG)->extendedheader->msin)))))
250 * Definitions of DLT message buffer overflow
252 #define DLT_MESSAGE_BUFFER_NO_OVERFLOW 0x00 /**< Buffer overflow has not occured */
253 #define DLT_MESSAGE_BUFFER_OVERFLOW 0x01 /**< Buffer overflow has occured */
256 * Definition of DLT output variants
258 #define DLT_OUTPUT_HEX 1
259 #define DLT_OUTPUT_ASCII 2
260 #define DLT_OUTPUT_MIXED_FOR_PLAIN 3
261 #define DLT_OUTPUT_MIXED_FOR_HTML 4
262 #define DLT_OUTPUT_ASCII_LIMITED 5
264 #define DLT_FILTER_MAX 30 /**< Maximum number of filters */
266 #define DLT_MSG_READ_VALUE(dst,src,length,type) \
268 if((length<0) || ((length)<((int32_t)sizeof(type)))) \
271 { dst = *((type*)src);src+=sizeof(type);length-=sizeof(type); } \
274 #define DLT_MSG_READ_ID(dst,src,length) \
276 if((length<0) || ((length)<DLT_ID_SIZE)) \
279 { memcpy(dst,src,DLT_ID_SIZE);src+=DLT_ID_SIZE;length-=DLT_ID_SIZE; } \
282 #define DLT_MSG_READ_STRING(dst,src,maxlength,length) \
284 if(((maxlength)<0) || ((length)<0) || ((maxlength)<(length))) \
285 { maxlength = -1; } \
287 { memcpy(dst,src,length);dlt_clean_string(dst,length);dst[length]=0; \
288 src+=length;maxlength-=length; } \
291 #define DLT_MSG_READ_NULL(src,maxlength,length) \
293 if(((maxlength)<0) || ((length)<0) || ((maxlength)<(length))) \
296 { src+=length;maxlength-=length; } \
299 #define DLT_HEADER_SHOW_NONE 0x0000
300 #define DLT_HEADER_SHOW_TIME 0x0001
301 #define DLT_HEADER_SHOW_TMSTP 0x0002
302 #define DLT_HEADER_SHOW_MSGCNT 0x0004
303 #define DLT_HEADER_SHOW_ECUID 0x0008
304 #define DLT_HEADER_SHOW_APID 0x0010
305 #define DLT_HEADER_SHOW_CTID 0x0020
306 #define DLT_HEADER_SHOW_MSGTYPE 0x0040
307 #define DLT_HEADER_SHOW_MSGSUBTYPE 0x0080
308 #define DLT_HEADER_SHOW_VNVSTATUS 0x0100
309 #define DLT_HEADER_SHOW_NOARG 0x0200
310 #define DLT_HEADER_SHOW_ALL 0xFFFF
313 * The definition of the serial header containing the characters "DLS" + 0x01.
315 extern const char dltSerialHeader[DLT_ID_SIZE];
318 * The definition of the serial header containing the characters "DLS" + 0x01 as char.
320 extern char dltSerialHeaderChar[DLT_ID_SIZE];
324 * The type of a DLT ID (context id, application id, etc.)
326 typedef char ID4[DLT_ID_SIZE];
329 * The structure of the DLT file storage header. This header is used before each stored DLT message.
333 char pattern[DLT_ID_SIZE]; /**< This pattern should be DLT0x01 */
334 uint32_t seconds; /**< seconds since 1.1.1970 */
335 int32_t microseconds; /**< Microseconds */
336 char ecu[DLT_ID_SIZE]; /**< The ECU id is added, if it is not already in the DLT message itself */
337 } PACKED DltStorageHeader;
340 * The structure of the DLT standard header. This header is used in each DLT message.
344 uint8_t htyp; /**< This parameter contains several informations, see definitions below */
345 uint8_t mcnt; /**< The message counter is increased with each sent DLT message */
346 uint16_t len; /**< Length of the complete message, without storage header */
347 } PACKED DltStandardHeader;
350 * The structure of the DLT extra header parameters. Each parameter is sent only if enabled in htyp.
354 char ecu[DLT_ID_SIZE]; /**< ECU id */
355 uint32_t seid; /**< Session number */
356 uint32_t tmsp; /**< Timestamp since system start in 0.1 milliseconds */
357 } PACKED DltStandardHeaderExtra;
360 * The structure of the DLT extended header. This header is only sent if enabled in htyp parameter.
364 uint8_t msin; /**< messsage info */
365 uint8_t noar; /**< number of arguments */
366 char apid[DLT_ID_SIZE]; /**< application id */
367 char ctid[DLT_ID_SIZE]; /**< context id */
368 } PACKED DltExtendedHeader;
371 * The structure to organise the DLT messages.
372 * This structure is used by the corresponding functions.
374 typedef struct sDltMessage
377 int8_t found_serialheader;
380 int32_t resync_offset;
382 /* size parameters */
383 int32_t headersize; /**< size of complete header including storage header */
384 int32_t datasize; /**< size of complete payload */
386 /* buffer for current loaded message */
387 uint8_t headerbuffer[sizeof(DltStorageHeader)+
388 sizeof(DltStandardHeader)+sizeof(DltStandardHeaderExtra)+sizeof(DltExtendedHeader)]; /**< buffer for loading complete header */
389 uint8_t *databuffer; /**< buffer for loading payload */
390 int32_t databuffersize;
392 /* header values of current loaded message */
393 DltStorageHeader *storageheader; /**< pointer to storage header of current loaded header */
394 DltStandardHeader *standardheader; /**< pointer to standard header of current loaded header */
395 DltStandardHeaderExtra headerextra; /**< extra parameters of current loaded header */
396 DltExtendedHeader *extendedheader; /**< pointer to extended of current loaded header */
400 * The structure of the DLT Service Get Log Info.
404 uint32_t service_id; /**< service ID */
405 uint8_t options; /**< type of request */
406 char apid[DLT_ID_SIZE]; /**< application id */
407 char ctid[DLT_ID_SIZE]; /**< context id */
408 char com[DLT_ID_SIZE]; /**< communication interface */
409 } PACKED DltServiceGetLogInfoRequest;
412 * The structure of the DLT Service Set Log Level.
417 uint32_t service_id; /**< service ID */
418 char apid[DLT_ID_SIZE]; /**< application id */
419 char ctid[DLT_ID_SIZE]; /**< context id */
420 uint8_t log_level; /**< log level to be set */
421 char com[DLT_ID_SIZE]; /**< communication interface */
422 } PACKED DltServiceSetLogLevel;
425 * The structure of the DLT Service Set Default Log Level.
429 uint32_t service_id; /**< service ID */
430 uint8_t log_level; /**< default log level to be set */
431 char com[DLT_ID_SIZE]; /**< communication interface */
432 } PACKED DltServiceSetDefaultLogLevel;
435 * The structure of the DLT Service Set Verbose Mode
439 uint32_t service_id; /**< service ID */
440 uint8_t new_status; /**< new status to be set */
441 } PACKED DltServiceSetVerboseMode;
444 * The structure of the DLT Service Set Communication Interface Status
448 uint32_t service_id; /**< service ID */
449 char com[DLT_ID_SIZE]; /**< communication interface */
450 uint8_t new_status; /**< new status to be set */
451 } PACKED DltServiceSetCommunicationInterfaceStatus;
454 * The structure of the DLT Service Set Communication Maximum Bandwidth
458 uint32_t service_id; /**< service ID */
459 char com[DLT_ID_SIZE]; /**< communication interface */
460 uint32_t max_bandwidth; /**< maximum bandwith */
461 } PACKED DltServiceSetCommunicationMaximumBandwidth;
465 uint32_t service_id; /**< service ID */
466 uint8_t status; /**< reponse status */
467 } PACKED DltServiceResponse;
471 uint32_t service_id; /**< service ID */
472 uint8_t status; /**< reponse status */
473 uint8_t log_level; /**< log level */
474 } PACKED DltServiceGetDefaultLogLevelResponse;
478 uint32_t service_id; /**< service ID */
479 uint8_t status; /**< reponse status */
480 uint8_t overflow; /**< overflow status */
481 uint32_t overflow_counter; /**< overflow counter */
482 } PACKED DltServiceMessageBufferOverflowResponse;
486 uint32_t service_id; /**< service ID */
487 uint8_t status; /**< reponse status */
488 uint32_t length; /**< length of following payload */
489 /*char []Â payload;*/
490 } PACKED DltServiceGetSoftwareVersionResponse;
493 * Structure to store filter parameters.
494 * ID are maximal four characters. Unused values are filled with zeros.
495 * If every value as filter is valid, the id should be empty by having only zero values.
499 char apid[DLT_FILTER_MAX][DLT_ID_SIZE]; /**< application id */
500 char ctid[DLT_FILTER_MAX][DLT_ID_SIZE]; /**< context id */
501 int counter; /**< number of filters */
505 * The structure to organise the access to DLT files.
506 * This structure is used by the corresponding functions.
508 typedef struct sDltFile
510 /* file handle and index for fast access */
511 FILE *handle; /**< file handle of opened DLT file */
512 long *index; /**< file positions of all DLT messages for fast access to file, only filtered messages */
514 /* size parameters */
515 int32_t counter; /**< number of messages in DLT file with filter */
516 int32_t counter_total; /**< number of messages in DLT file without filter */
517 int32_t position; /**< current index to message parsed in DLT file starting at 0 */
518 long file_length; /**< length of the file */
519 long file_position; /**< current position in the file */
522 int32_t error_messages; /**< number of incomplete DLT messages found during file parsing */
524 /* filter parameters */
525 DltFilter *filter; /**< pointer to filter list. Zero if no filter is set. */
526 int32_t filter_counter; /**< number of filter set */
528 /* current loaded message */
529 DltMessage msg; /**< pointer to message */
534 * The structure is used to organise the receiving of data
535 * including buffer handling.
536 * This structure is used by the corresponding functions.
540 int32_t lastBytesRcvd; /**< bytes received in last receive call */
541 int32_t bytesRcvd; /**< received bytes */
542 int32_t totalBytesRcvd; /**< total number of received bytes */
543 char *buffer; /**< pointer to receiver buffer */
544 char *buf; /**< pointer to position within receiver buffer */
545 int fd; /**< connection handle */
546 int32_t buffersize; /**< size of receiver buffer */
551 unsigned char* shm; /* pointer to beginning of shared memory */
552 int size; /* size of data area in shared memory */
553 unsigned char* mem; /* pointer to data area in shared memory */
555 uint32_t min_size; /**< Minimum size of buffer */
556 uint32_t max_size; /**< Maximum size of buffer */
557 uint32_t step_size; /**< Step size of buffer */
567 #define DLT_BUFFER_HEAD "SHM"
572 unsigned char status;
574 } DltBufferBlockHead;
582 * Helper function to print a byte array in hex.
583 * @param ptr pointer to the byte array.
584 * @param size number of bytes to be printed.
586 void dlt_print_hex(uint8_t *ptr,int size);
588 * Helper function to print a byte array in hex into a string.
589 * @param text pointer to a ASCII string, in which the text is written
590 * @param textlength maximal size of text buffer
591 * @param ptr pointer to the byte array.
592 * @param size number of bytes to be printed.
593 * @return negative value if there was an error
595 int dlt_print_hex_string(char *text,int textlength,uint8_t *ptr,int size);
597 * Helper function to print a byte array in hex and ascii into a string.
598 * @param text pointer to a ASCII string, in which the text is written
599 * @param textlength maximal size of text buffer
600 * @param ptr pointer to the byte array.
601 * @param size number of bytes to be printed.
602 * @param html output is html? 0 - false, 1 - true
603 * @return negative value if there was an error
605 int dlt_print_mixed_string(char *text,int textlength,uint8_t *ptr,int size,int html);
607 * Helper function to print a byte array in ascii into a string.
608 * @param text pointer to a ASCII string, in which the text is written
609 * @param textlength maximal size of text buffer
610 * @param ptr pointer to the byte array.
611 * @param size number of bytes to be printed.
612 * @return negative value if there was an error
614 int dlt_print_char_string(char **text,int textlength,uint8_t *ptr,int size);
617 * Helper function to print an id.
618 * @param text pointer to ASCII string where to write the id
619 * @param id four byte char array as used in DLT mesages as IDs.
621 void dlt_print_id(char *text,const char *id);
624 * Helper function to set an ID parameter.
625 * @param id four byte char array as used in DLT mesages as IDs.
626 * @param text string to be copied into char array.
628 void dlt_set_id(char *id,const char *text);
631 * Helper function to remove not nice to print characters, e.g. NULL or carage return.
632 * @param text pointer to string to be cleaned.
633 * @param length length of string excluding terminating zero.
635 void dlt_clean_string(char *text,int length);
638 * Initialise the filter list.
639 * This function must be called before using further dlt filter.
640 * @param filter pointer to structure of organising DLT filter
641 * @param verbose if set to true verbose information is printed out.
642 * @return negative value if there was an error
644 int dlt_filter_init(DltFilter *filter,int verbose);
646 * Free the used memory by the organising structure of filter.
647 * @param filter pointer to structure of organising DLT filter
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_free(DltFilter *filter,int verbose);
653 * Load filter list from file.
654 * @param filter pointer to structure of organising DLT filter
655 * @param filename filename to load filters from
656 * @param verbose if set to true verbose information is printed out.
657 * @return negative value if there was an error
659 int dlt_filter_load(DltFilter *filter,const char *filename,int verbose);
661 * Save filter list to file.
662 * @param filter pointer to structure of organising DLT filter
663 * @param filename filename to load filters from
664 * @param verbose if set to true verbose information is printed out.
665 * @return negative value if there was an error
667 int dlt_filter_save(DltFilter *filter,const char *filename,int verbose);
669 * Find index of filter in filter list
670 * @param filter pointer to structure of organising DLT filter
671 * @param apid application id to be found in filter list
672 * @param ctid context id to be found in filter list
673 * @param verbose if set to true verbose information is printed out.
674 * @return negative value if there was an error (or not found), else return index of filter
676 int dlt_filter_find(DltFilter *filter,const char *apid,const char *ctid, int verbose);
678 * Add new filter to filter list.
679 * @param filter pointer to structure of organising DLT filter
680 * @param apid application id to be added to filter list (must always be set).
681 * @param ctid context id to be added to filter list. empty equals don't care.
682 * @param verbose if set to true verbose information is printed out.
683 * @return negative value if there was an error
685 int dlt_filter_add(DltFilter *filter,const char *apid,const char *ctid,int verbose);
687 * Delete filter from filter list
688 * @param filter pointer to structure of organising DLT filter
689 * @param apid application id to be deleted from filter list
690 * @param ctid context id to be deleted from filter list
691 * @param verbose if set to true verbose information is printed out.
692 * @return negative value if there was an error
694 int dlt_filter_delete(DltFilter *filter,const char *apid,const char *ctid,int verbose);
697 * Initialise the structure used to access a DLT message.
698 * This function must be called before using further dlt_message functions.
699 * @param msg pointer to structure of organising access to DLT messages
700 * @param verbose if set to true verbose information is printed out.
701 * @return negative value if there was an error
703 int dlt_message_init(DltMessage *msg,int verbose);
705 * Free the used memory by the organising structure of file.
706 * @param msg pointer to structure of organising access to DLT messages
707 * @param verbose if set to true verbose information is printed out.
708 * @return negative value if there was an error
710 int dlt_message_free(DltMessage *msg,int verbose);
712 * Print Header into an ASCII string.
713 * This function calls dlt_message_header_flags() with flags=DLT_HEADER_SHOW_ALL
714 * @param msg pointer to structure of organising access to DLT messages
715 * @param text pointer to a ASCII string, in which the header is written
716 * @param textlength maximal size of text buffer
717 * @param verbose if set to true verbose information is printed out.
718 * @return negative value if there was an error
720 int dlt_message_header(DltMessage *msg,char *text,int textlength,int verbose);
722 * Print Header into an ASCII string, selective.
723 * @param msg pointer to structure of organising access to DLT messages
724 * @param text pointer to a ASCII string, in which the header is written
725 * @param textlength maximal size of text buffer
726 * @param flags select, bit-field to select, what should be printed (DLT_HEADER_SHOW_...)
727 * @param verbose if set to true verbose information is printed out.
728 * @return negative value if there was an error
730 int dlt_message_header_flags(DltMessage *msg,char *text,int textlength,int flags, int verbose);
732 * Print Payload into an ASCII string.
733 * @param msg pointer to structure of organising access to DLT messages
734 * @param text pointer to a ASCII string, in which the header is written
735 * @param textlength maximal size of text buffer
736 * @param type 1 = payload as hex, 2 = payload as ASCII.
737 * @param verbose if set to true verbose information is printed out.
738 * @return negative value if there was an error
740 int dlt_message_payload(DltMessage *msg,char *text,int textlength,int type,int verbose);
742 * Check if message is filtered or not. All filters are applied (logical OR).
743 * @param msg pointer to structure of organising access to DLT messages
744 * @param filter pointer to filter
745 * @param verbose if set to true verbose information is printed out.
746 * @return 1 = filter matches, 0 = filter does not match, negative value if there was an error
748 int dlt_message_filter_check(DltMessage *msg,DltFilter *filter,int verbose);
751 * Read message from memory buffer.
752 * Message in buffer has no storage header.
753 * @param msg pointer to structure of organising access to DLT messages
754 * @param buffer pointer to memory buffer
755 * @param length length of message in buffer
756 * @param resync if set to true resync to serial header is enforced
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_read(DltMessage *msg,uint8_t *buffer,unsigned int length,int resync,int verbose);
763 * Get standard header extra parameters
764 * @param msg pointer to structure of organising access to DLT messages
765 * @param verbose if set to true verbose information is printed out.
766 * @return negative value if there was an error
768 int dlt_message_get_extraparameters(DltMessage *msg,int verbose);
771 * Set standard header extra parameters
772 * @param msg pointer to structure of organising access to DLT messages
773 * @param verbose if set to true verbose information is printed out.
774 * @return negative value if there was an error
776 int dlt_message_set_extraparameters(DltMessage *msg,int verbose);
779 * Initialise the structure used to access a DLT file.
780 * This function must be called before using further dlt_file functions.
781 * @param file pointer to structure of organising access to DLT file
782 * @param verbose if set to true verbose information is printed out.
783 * @return negative value if there was an error
785 int dlt_file_init(DltFile *file,int verbose);
787 * Set a list to filters.
788 * This function should be called before loading a DLT file, if filters should be used.
789 * A filter list is an array of filters. Several filters are combined logically by or operation.
790 * The filter list is not copied, so take care to keep list in memory.
791 * @param file pointer to structure of organising access to DLT file
792 * @param filter pointer to filter list array
793 * @param verbose if set to true verbose information is printed out.
794 * @return negative value if there was an error
796 int dlt_file_set_filter(DltFile *file,DltFilter *filter,int verbose);
798 * Initialising loading a DLT file.
799 * @param file pointer to structure of organising access to DLT file
800 * @param filename filename of DLT file
801 * @param verbose if set to true verbose information is printed out.
802 * @return negative value if there was an error
804 int dlt_file_open(DltFile *file,const char *filename,int verbose);
806 * Find next message in the DLT file and parse them.
807 * This function finds the next message in the DLT file.
808 * If a filter is set, the filter list is used.
809 * @param file pointer to structure of organising access to DLT file
810 * @param verbose if set to true verbose information is printed out.
811 * @return 0 = message does not match filter, 1 = message was read, negative value if there was an error
813 int dlt_file_read(DltFile *file,int verbose);
815 * Find next message in the DLT file in RAW format (without storage header) and parse them.
816 * This function finds the next message in the DLT file.
817 * If a filter is set, the filter list is used.
818 * @param file pointer to structure of organising access to DLT file
819 * @param resync Resync to serial header when set to true
820 * @param verbose if set to true verbose information is printed out.
821 * @return 0 = message does not match filter, 1 = message was read, negative value if there was an error
823 int dlt_file_read_raw(DltFile *file,int resync,int verbose);
825 * Closing loading a DLT file.
826 * @param file pointer to structure of organising access to DLT file
827 * @param verbose if set to true verbose information is printed out.
828 * @return negative value if there was an error
830 int dlt_file_close(DltFile *file,int verbose);
832 * Load standard header of a message from file
833 * @param file pointer to structure of organising access to DLT file
834 * @param verbose if set to true verbose information is printed out.
835 * @return negative value if there was an error
837 int dlt_file_read_header(DltFile *file,int verbose);
839 * Load standard header of a message from file in RAW format (without storage header)
840 * @param file pointer to structure of organising access to DLT file
841 * @param resync Resync to serial header when set to true
842 * @param verbose if set to true verbose information is printed out.
843 * @return negative value if there was an error
845 int dlt_file_read_header_raw(DltFile *file,int resync,int verbose);
847 * Load, if available in message, extra standard header fields and
848 * extended header of a message from file
849 * (dlt_file_read_header() must have been called before this call!)
850 * @param file pointer to structure of organising access to DLT file
851 * @param verbose if set to true verbose information is printed out.
852 * @return negative value if there was an error
854 int dlt_file_read_header_extended(DltFile *file, int verbose);
856 * Load payload of a message from file
857 * (dlt_file_read_header() must have been called before this call!)
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_read_data(DltFile *file, int verbose);
864 * Load headers and payload of a message selected by the index.
865 * If filters are set, index is based on the filtered list.
866 * @param file pointer to structure of organising access to DLT file
867 * @param index position of message in the files beginning from zero
868 * @param verbose if set to true verbose information is printed out.
869 * @return number of messages loaded, negative value if there was an error
871 int dlt_file_message(DltFile *file,int index,int verbose);
873 * Free the used memory by the organising structure of file.
874 * @param file pointer to structure of organising access to DLT file
875 * @param verbose if set to true verbose information is printed out.
876 * @return negative value if there was an error
878 int dlt_file_free(DltFile *file,int verbose);
881 * Set internal logging filename if mode 2
882 * @param filename the filename
884 void dlt_log_set_filename(const char *filename);
886 * Set internal logging level
887 * @param level the level
889 void dlt_log_set_level(int level);
891 * Initialize (external) logging facility
892 * @param mode positive, 0 = log to stdout, 1 = log to syslog, 2 = log to file
894 void dlt_log_init(int mode);
896 * Log ASCII string with null-termination to (external) logging facility
897 * @param prio priority (see syslog() call)
898 * @param s Pointer to ASCII string with null-termination
899 * @return negative value if there was an error
901 int dlt_log(int prio, char *s);
903 * De-Initialize (external) logging facility
905 void dlt_log_free(void);
908 * Initialising a dlt receiver structure
909 * @param receiver pointer to dlt receiver structure
910 * @param _fd handle to file/socket/fifo, fram which the data should be received
911 * @param _buffersize size of data buffer for storing the received data
912 * @return negative value if there was an error
914 int dlt_receiver_init(DltReceiver *receiver,int _fd, int _buffersize);
916 * De-Initialize a dlt receiver structure
917 * @param receiver pointer to dlt receiver structure
918 * @return negative value if there was an error
920 int dlt_receiver_free(DltReceiver *receiver);
922 * Receive data from socket using the dlt receiver structure
923 * @param receiver pointer to dlt receiver structure
924 * @return negative value if there was an error
926 int dlt_receiver_receive_socket(DltReceiver *receiver);
928 * Receive data from file/fifo using the dlt receiver structure
929 * @param receiver pointer to dlt receiver structure
930 * @return negative value if there was an error
932 int dlt_receiver_receive_fd(DltReceiver *receiver);
934 * Remove a specific size of bytes from the received data
935 * @param receiver pointer to dlt receiver structure
936 * @param size amount of bytes to be removed
937 * @return negative value if there was an error
939 int dlt_receiver_remove(DltReceiver *receiver,int size);
941 * Move data from last receive call to front of receive buffer
942 * @param receiver pointer to dlt receiver structure
943 * @return negative value if there was an error
945 int dlt_receiver_move_to_begin(DltReceiver *receiver);
948 * Fill out storage header of a dlt message
949 * @param storageheader pointer to storage header of a dlt message
950 * @param ecu name of ecu to be set in storage header
951 * @return negative value if there was an error
953 int dlt_set_storageheader(DltStorageHeader *storageheader, const char *ecu);
955 * Check if a storage header contains its marker
956 * @param storageheader pointer to storage header of a dlt message
957 * @return 0 no, 1 yes, negative value if there was an error
959 int dlt_check_storageheader(DltStorageHeader *storageheader);
963 * Initialise static ringbuffer with a size of size.
964 * Initialise as server. Init counters.
965 * Memory is already allocated.
966 * @param buf Pointer to ringbuffer structure
967 * @param ptr Ptr to ringbuffer memory
968 * @param size Maximum size of buffer in bytes
969 * @return negative value if there was an error
971 int dlt_buffer_init_static_server(DltBuffer *buf, const unsigned char *ptr, uint32_t size);
974 * Initialize static ringbuffer with a size of size.
975 * Initialise as a client. Do not change counters.
976 * Memory is already allocated.
977 * @param buf Pointer to ringbuffer structure
978 * @param ptr Ptr to ringbuffer memory
979 * @param size Maximum size of buffer in bytes
980 * @return negative value if there was an error
982 int dlt_buffer_init_static_client(DltBuffer *buf, const unsigned char *ptr, uint32_t size);
985 * Initialize dynamic ringbuffer with a size of size.
986 * Initialise as a client. Do not change counters.
987 * Memory will be allocated starting with min_size.
988 * If more memory is needed size is increased wit step_size.
989 * The maximum size is max_size.
990 * @param buf Pointer to ringbuffer structure
991 * @param min_size Minimum size of buffer in bytes
992 * @param max_size Maximum size of buffer in bytes
993 * @param step_size size of which ringbuffer is increased
994 * @return negative value if there was an error
996 int dlt_buffer_init_dynamic(DltBuffer *buf, uint32_t min_size, uint32_t max_size,uint32_t step_size);
999 * Deinitilaise usage of static ringbuffer
1000 * @param buf Pointer to ringbuffer structure
1001 * @return negative value if there was an error
1003 int dlt_buffer_free_static(DltBuffer *buf);
1006 * Release and free memory used by dynamic ringbuffer
1007 * @param buf Pointer to ringbuffer structure
1008 * @return negative value if there was an error
1010 int dlt_buffer_free_dynamic(DltBuffer *buf);
1013 * Write one entry to ringbuffer
1014 * @param buf Pointer to ringbuffer structure
1015 * @param data Pointer to data to be written to ringbuffer
1016 * @param size Size of data in bytes to be written to ringbuffer
1017 * @return negative value if there was an error
1019 int dlt_buffer_push(DltBuffer *buf,const unsigned char *data,unsigned int size);
1022 * Write up to three entries to ringbuffer.
1023 * Entries are joined to one block.
1024 * @param dlt Pointer to ringbuffer structure
1025 * @param data1 Pointer to data to be written to ringbuffer
1026 * @param size1 Size of data in bytes to be written to ringbuffer
1027 * @param data2 Pointer to data to be written to ringbuffer
1028 * @param size2 Size of data in bytes to be written to ringbuffer
1029 * @param data3 Pointer to data to be written to ringbuffer
1030 * @param size3 Size of data in bytes to be written to ringbuffer
1031 * @return negative value if there was an error
1033 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);
1036 * Read one entry from ringbuffer.
1037 * Remove it from ringbuffer.
1038 * @param buf Pointer to ringbuffer structure
1039 * @param data Pointer to data read from ringbuffer
1040 * @param max_size Max size of read data in bytes from ringbuffer
1041 * @return size of read data, zero if no data available, negative value if there was an error
1043 int dlt_buffer_pull(DltBuffer *buf,unsigned char *data, int max_size);
1046 * Read one entry from ringbuffer.
1047 * Do not remove it from ringbuffer.
1048 * @param buf Pointer to ringbuffer structure
1049 * @param data Pointer to data read from ringbuffer
1050 * @param max_size Max size of read data in bytes from ringbuffer
1051 * @return size of read data, zero if no data available, negative value if there was an error
1053 int dlt_buffer_copy(DltBuffer *buf,unsigned char *data, int max_size);
1056 * Remove entry from ringbuffer.
1057 * @param buf Pointer to ringbuffer structure
1058 * @return size of read data, zero if no data available, negative value if there was an error
1060 int dlt_buffer_remove(DltBuffer *buf);
1063 * Print information about buffer and log to internal DLT log.
1064 * @param buf Pointer to ringbuffer structure
1066 void dlt_buffer_info(DltBuffer *buf);
1069 * Print status of buffer and log to internal DLT log.
1070 * @param buf Pointer to ringbuffer structure
1072 void dlt_buffer_status(DltBuffer *buf);
1075 * Get total size in bytes of ringbuffer.
1076 * If buffer is dynamic, max size is returned.
1077 * @param buf Pointer to ringbuffer structure
1078 * @return total size of buffer
1080 int dlt_buffer_get_total_size(DltBuffer *buf);
1083 * Get used size in bytes of ringbuffer.
1084 * @param buf Pointer to ringbuffer structure
1085 * @return used size of buffer
1087 int dlt_buffer_get_used_size(DltBuffer *buf);
1090 * Get number of entries in ringbuffer.
1091 * @param buf Pointer to ringbuffer structure
1092 * @return number of entries
1094 int dlt_buffer_get_message_count(DltBuffer *buf);
1096 #if !defined (__WIN32__)
1099 * Helper function: Setup serial connection
1100 * @param fd File descriptor of serial tty device
1101 * @param speed Serial line speed, as defined in termios.h
1102 * @return negative value if there was an error
1104 int dlt_setup_serial(int fd, speed_t speed);
1107 * Helper function: Convert serial line baudrate (as number) to line speed (as defined in termios.h)
1108 * @param baudrate Serial line baudrate (as number)
1109 * @return Serial line speed, as defined in termios.h
1111 speed_t dlt_convert_serial_speed(int baudrate);
1114 * Print dlt version and dlt svn version to buffer
1115 * @param buf Pointer to buffer
1117 void dlt_get_version(char *buf);
1120 * Print dlt major version to buffer
1121 * @param buf Pointer to buffer
1123 void dlt_get_major_version(char *buf);
1126 * Print dlt minor version to buffer
1127 * @param buf Pointer to buffer
1129 void dlt_get_minor_version(char *buf);
1133 /* Function prototypes which should be used only internally */
1137 * Common part of initialisation
1138 * @return negative value if there was an error
1140 int dlt_init_common(void);
1143 * Return the uptime of the system in 0.1 ms resolution
1144 * @return 0 if there was an error
1146 uint32_t dlt_uptime(void);
1149 * Print header of a DLT message
1150 * @param message pointer to structure of organising access to DLT messages
1151 * @param text pointer to a ASCII string, in which the header is written
1152 * @param size maximal size of text buffer
1153 * @param verbose if set to true verbose information is printed out.
1154 * @return negative value if there was an error
1156 int dlt_message_print_header(DltMessage *message, char *text, uint32_t size, int verbose);
1159 * Print payload of a DLT message as Hex-Output
1160 * @param message pointer to structure of organising access to DLT messages
1161 * @param text pointer to a ASCII string, in which the output is written
1162 * @param size maximal size of text buffer
1163 * @param verbose if set to true verbose information is printed out.
1164 * @return negative value if there was an error
1166 int dlt_message_print_hex(DltMessage *message, char *text, uint32_t size, int verbose);
1169 * Print payload of a DLT message as ASCII-Output
1170 * @param message pointer to structure of organising access to DLT messages
1171 * @param text pointer to a ASCII string, in which the output is written
1172 * @param size maximal size of text buffer
1173 * @param verbose if set to true verbose information is printed out.
1174 * @return negative value if there was an error
1176 int dlt_message_print_ascii(DltMessage *message, char *text, uint32_t size, int verbose);
1179 * Print payload of a DLT message as Mixed-Ouput (Hex and ASCII), for plain text output
1180 * @param message pointer to structure of organising access to DLT messages
1181 * @param text pointer to a ASCII string, in which the output is written
1182 * @param size maximal size of text buffer
1183 * @param verbose if set to true verbose information is printed out.
1184 * @return negative value if there was an error
1186 int dlt_message_print_mixed_plain(DltMessage *message, char *text, uint32_t size, int verbose);
1189 * Print payload of a DLT message as Mixed-Ouput (Hex and ASCII), for HTML text output
1190 * @param message pointer to structure of organising access to DLT messages
1191 * @param text pointer to a ASCII string, in which the output is written
1192 * @param size maximal size of text buffer
1193 * @param verbose if set to true verbose information is printed out.
1194 * @return negative value if there was an error
1196 int dlt_message_print_mixed_html(DltMessage *message, char *text, uint32_t size, int verbose);
1199 * Decode and print a argument of a DLT message
1200 * @param msg pointer to structure of organising access to DLT messages
1201 * @param type_info Type of argument
1202 * @param ptr pointer to pointer to data (pointer to data is changed within this function)
1203 * @param datalength pointer to datalength (datalength is changed within this function)
1204 * @param text pointer to a ASCII string, in which the output is written
1205 * @param textlength maximal size of text buffer
1206 * @param byteLength If argument is a string, and this value is 0 or greater, this value will be taken as string length
1207 * @param verbose if set to true verbose information is printed out.
1208 * @return negative value if there was an error
1210 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);
1220 #endif /* DLT_COMMON_H */