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 } PACKED DltServiceMessageBufferOverflowResponse;
485 uint32_t service_id; /**< service ID */
486 uint8_t status; /**< reponse status */
487 uint32_t length; /**< length of following payload */
488 /*char []Â payload;*/
489 } PACKED DltServiceGetSoftwareVersionResponse;
492 * Structure to store filter parameters.
493 * ID are maximal four characters. Unused values are filled with zeros.
494 * If every value as filter is valid, the id should be empty by having only zero values.
498 char apid[DLT_FILTER_MAX][DLT_ID_SIZE]; /**< application id */
499 char ctid[DLT_FILTER_MAX][DLT_ID_SIZE]; /**< context id */
500 int counter; /**< number of filters */
504 * The structure to organise the access to DLT files.
505 * This structure is used by the corresponding functions.
507 typedef struct sDltFile
509 /* file handle and index for fast access */
510 FILE *handle; /**< file handle of opened DLT file */
511 long *index; /**< file positions of all DLT messages for fast access to file, only filtered messages */
513 /* size parameters */
514 int32_t counter; /**< number of messages in DLT file with filter */
515 int32_t counter_total; /**< number of messages in DLT file without filter */
516 int32_t position; /**< current index to message parsed in DLT file starting at 0 */
517 long file_length; /**< length of the file */
518 long file_position; /**< current position in the file */
521 int32_t error_messages; /**< number of incomplete DLT messages found during file parsing */
523 /* filter parameters */
524 DltFilter *filter; /**< pointer to filter list. Zero if no filter is set. */
525 int32_t filter_counter; /**< number of filter set */
527 /* current loaded message */
528 DltMessage msg; /**< pointer to message */
533 * The structure is used to organise the receiving of data
534 * including buffer handling.
535 * This structure is used by the corresponding functions.
539 int32_t lastBytesRcvd; /**< bytes received in last receive call */
540 int32_t bytesRcvd; /**< received bytes */
541 int32_t totalBytesRcvd; /**< total number of received bytes */
542 char *buffer; /**< pointer to receiver buffer */
543 char *buf; /**< pointer to position within receiver buffer */
544 int fd; /**< connection handle */
545 int32_t buffersize; /**< size of receiver buffer */
550 unsigned char* shm; /* pointer to beginning of shared memory */
551 int size; /* size of data area in shared memory */
552 unsigned char* mem; /* pointer to data area in shared memory */
554 uint32_t min_size; /**< Minimum size of buffer */
555 uint32_t max_size; /**< Maximum size of buffer */
556 uint32_t step_size; /**< Step size of buffer */
566 #define DLT_BUFFER_HEAD "SHM"
571 unsigned char status;
573 } DltBufferBlockHead;
581 * Helper function to print a byte array in hex.
582 * @param ptr pointer to the byte array.
583 * @param size number of bytes to be printed.
585 void dlt_print_hex(uint8_t *ptr,int size);
587 * Helper function to print a byte array in hex into a string.
588 * @param text pointer to a ASCII string, in which the text is written
589 * @param textlength maximal size of text buffer
590 * @param ptr pointer to the byte array.
591 * @param size number of bytes to be printed.
592 * @return negative value if there was an error
594 int dlt_print_hex_string(char *text,int textlength,uint8_t *ptr,int size);
596 * Helper function to print a byte array in hex and ascii into a string.
597 * @param text pointer to a ASCII string, in which the text is written
598 * @param textlength maximal size of text buffer
599 * @param ptr pointer to the byte array.
600 * @param size number of bytes to be printed.
601 * @param html output is html? 0 - false, 1 - true
602 * @return negative value if there was an error
604 int dlt_print_mixed_string(char *text,int textlength,uint8_t *ptr,int size,int html);
606 * Helper function to print a byte array in ascii into a string.
607 * @param text pointer to a ASCII string, in which the text is written
608 * @param textlength maximal size of text buffer
609 * @param ptr pointer to the byte array.
610 * @param size number of bytes to be printed.
611 * @return negative value if there was an error
613 int dlt_print_char_string(char **text,int textlength,uint8_t *ptr,int size);
616 * Helper function to print an id.
617 * @param text pointer to ASCII string where to write the id
618 * @param id four byte char array as used in DLT mesages as IDs.
620 void dlt_print_id(char *text,const char *id);
623 * Helper function to set an ID parameter.
624 * @param id four byte char array as used in DLT mesages as IDs.
625 * @param text string to be copied into char array.
627 void dlt_set_id(char *id,const char *text);
630 * Helper function to remove not nice to print characters, e.g. NULL or carage return.
631 * @param text pointer to string to be cleaned.
632 * @param length length of string excluding terminating zero.
634 void dlt_clean_string(char *text,int length);
637 * Initialise the filter list.
638 * This function must be called before using further dlt filter.
639 * @param filter pointer to structure of organising DLT filter
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_init(DltFilter *filter,int verbose);
645 * Free the used memory by the organising structure of filter.
646 * @param filter pointer to structure of organising DLT filter
647 * @param verbose if set to true verbose information is printed out.
648 * @return negative value if there was an error
650 int dlt_filter_free(DltFilter *filter,int verbose);
652 * Load filter list from file.
653 * @param filter pointer to structure of organising DLT filter
654 * @param filename filename to load filters from
655 * @param verbose if set to true verbose information is printed out.
656 * @return negative value if there was an error
658 int dlt_filter_load(DltFilter *filter,const char *filename,int verbose);
660 * Save filter list to file.
661 * @param filter pointer to structure of organising DLT filter
662 * @param filename filename to load filters from
663 * @param verbose if set to true verbose information is printed out.
664 * @return negative value if there was an error
666 int dlt_filter_save(DltFilter *filter,const char *filename,int verbose);
668 * Find index of filter in filter list
669 * @param filter pointer to structure of organising DLT filter
670 * @param apid application id to be found in filter list
671 * @param ctid context id to be found in filter list
672 * @param verbose if set to true verbose information is printed out.
673 * @return negative value if there was an error (or not found), else return index of filter
675 int dlt_filter_find(DltFilter *filter,const char *apid,const char *ctid, int verbose);
677 * Add new filter to filter list.
678 * @param filter pointer to structure of organising DLT filter
679 * @param apid application id to be added to filter list (must always be set).
680 * @param ctid context id to be added to filter list. empty equals don't care.
681 * @param verbose if set to true verbose information is printed out.
682 * @return negative value if there was an error
684 int dlt_filter_add(DltFilter *filter,const char *apid,const char *ctid,int verbose);
686 * Delete filter from filter list
687 * @param filter pointer to structure of organising DLT filter
688 * @param apid application id to be deleted from filter list
689 * @param ctid context id to be deleted from filter list
690 * @param verbose if set to true verbose information is printed out.
691 * @return negative value if there was an error
693 int dlt_filter_delete(DltFilter *filter,const char *apid,const char *ctid,int verbose);
696 * Initialise the structure used to access a DLT message.
697 * This function must be called before using further dlt_message functions.
698 * @param msg pointer to structure of organising access to DLT messages
699 * @param verbose if set to true verbose information is printed out.
700 * @return negative value if there was an error
702 int dlt_message_init(DltMessage *msg,int verbose);
704 * Free the used memory by the organising structure of file.
705 * @param msg pointer to structure of organising access to DLT messages
706 * @param verbose if set to true verbose information is printed out.
707 * @return negative value if there was an error
709 int dlt_message_free(DltMessage *msg,int verbose);
711 * Print Header into an ASCII string.
712 * This function calls dlt_message_header_flags() with flags=DLT_HEADER_SHOW_ALL
713 * @param msg pointer to structure of organising access to DLT messages
714 * @param text pointer to a ASCII string, in which the header is written
715 * @param textlength maximal size of text buffer
716 * @param verbose if set to true verbose information is printed out.
717 * @return negative value if there was an error
719 int dlt_message_header(DltMessage *msg,char *text,int textlength,int verbose);
721 * Print Header into an ASCII string, selective.
722 * @param msg pointer to structure of organising access to DLT messages
723 * @param text pointer to a ASCII string, in which the header is written
724 * @param textlength maximal size of text buffer
725 * @param flags select, bit-field to select, what should be printed (DLT_HEADER_SHOW_...)
726 * @param verbose if set to true verbose information is printed out.
727 * @return negative value if there was an error
729 int dlt_message_header_flags(DltMessage *msg,char *text,int textlength,int flags, int verbose);
731 * Print Payload into an ASCII string.
732 * @param msg pointer to structure of organising access to DLT messages
733 * @param text pointer to a ASCII string, in which the header is written
734 * @param textlength maximal size of text buffer
735 * @param type 1 = payload as hex, 2 = payload as ASCII.
736 * @param verbose if set to true verbose information is printed out.
737 * @return negative value if there was an error
739 int dlt_message_payload(DltMessage *msg,char *text,int textlength,int type,int verbose);
741 * Check if message is filtered or not. All filters are applied (logical OR).
742 * @param msg pointer to structure of organising access to DLT messages
743 * @param filter pointer to filter
744 * @param verbose if set to true verbose information is printed out.
745 * @return 1 = filter matches, 0 = filter does not match, negative value if there was an error
747 int dlt_message_filter_check(DltMessage *msg,DltFilter *filter,int verbose);
750 * Read message from memory buffer.
751 * Message in buffer has no storage header.
752 * @param msg pointer to structure of organising access to DLT messages
753 * @param buffer pointer to memory buffer
754 * @param length length of message in buffer
755 * @param resync if set to true resync to serial header is enforced
756 * @param verbose if set to true verbose information is printed out.
757 * @return negative value if there was an error
759 int dlt_message_read(DltMessage *msg,uint8_t *buffer,unsigned int length,int resync,int verbose);
762 * Get standard header extra parameters
763 * @param msg pointer to structure of organising access to DLT messages
764 * @param verbose if set to true verbose information is printed out.
765 * @return negative value if there was an error
767 int dlt_message_get_extraparameters(DltMessage *msg,int verbose);
770 * Set standard header extra parameters
771 * @param msg pointer to structure of organising access to DLT messages
772 * @param verbose if set to true verbose information is printed out.
773 * @return negative value if there was an error
775 int dlt_message_set_extraparameters(DltMessage *msg,int verbose);
778 * Initialise the structure used to access a DLT file.
779 * This function must be called before using further dlt_file functions.
780 * @param file pointer to structure of organising access to DLT file
781 * @param verbose if set to true verbose information is printed out.
782 * @return negative value if there was an error
784 int dlt_file_init(DltFile *file,int verbose);
786 * Set a list to filters.
787 * This function should be called before loading a DLT file, if filters should be used.
788 * A filter list is an array of filters. Several filters are combined logically by or operation.
789 * The filter list is not copied, so take care to keep list in memory.
790 * @param file pointer to structure of organising access to DLT file
791 * @param filter pointer to filter list array
792 * @param verbose if set to true verbose information is printed out.
793 * @return negative value if there was an error
795 int dlt_file_set_filter(DltFile *file,DltFilter *filter,int verbose);
797 * Initialising loading a DLT file.
798 * @param file pointer to structure of organising access to DLT file
799 * @param filename filename of DLT file
800 * @param verbose if set to true verbose information is printed out.
801 * @return negative value if there was an error
803 int dlt_file_open(DltFile *file,const char *filename,int verbose);
805 * Find next message in the DLT file and parse them.
806 * This function finds the next message in the DLT file.
807 * If a filter is set, the filter list is used.
808 * @param file pointer to structure of organising access to DLT file
809 * @param verbose if set to true verbose information is printed out.
810 * @return 0 = message does not match filter, 1 = message was read, negative value if there was an error
812 int dlt_file_read(DltFile *file,int verbose);
814 * Find next message in the DLT file in RAW format (without storage header) and parse them.
815 * This function finds the next message in the DLT file.
816 * If a filter is set, the filter list is used.
817 * @param file pointer to structure of organising access to DLT file
818 * @param resync Resync to serial header when set to true
819 * @param verbose if set to true verbose information is printed out.
820 * @return 0 = message does not match filter, 1 = message was read, negative value if there was an error
822 int dlt_file_read_raw(DltFile *file,int resync,int verbose);
824 * Closing loading a DLT file.
825 * @param file pointer to structure of organising access to DLT file
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_close(DltFile *file,int verbose);
831 * Load standard header of a message from file
832 * @param file pointer to structure of organising access to DLT file
833 * @param verbose if set to true verbose information is printed out.
834 * @return negative value if there was an error
836 int dlt_file_read_header(DltFile *file,int verbose);
838 * Load standard header of a message from file in RAW format (without storage header)
839 * @param file pointer to structure of organising access to DLT file
840 * @param resync Resync to serial header when set to true
841 * @param verbose if set to true verbose information is printed out.
842 * @return negative value if there was an error
844 int dlt_file_read_header_raw(DltFile *file,int resync,int verbose);
846 * Load, if available in message, extra standard header fields and
847 * extended header of a message from file
848 * (dlt_file_read_header() must have been called before this call!)
849 * @param file pointer to structure of organising access to DLT file
850 * @param verbose if set to true verbose information is printed out.
851 * @return negative value if there was an error
853 int dlt_file_read_header_extended(DltFile *file, int verbose);
855 * Load payload of a message from file
856 * (dlt_file_read_header() must have been called before this call!)
857 * @param file pointer to structure of organising access to DLT file
858 * @param verbose if set to true verbose information is printed out.
859 * @return negative value if there was an error
861 int dlt_file_read_data(DltFile *file, int verbose);
863 * Load headers and payload of a message selected by the index.
864 * If filters are set, index is based on the filtered list.
865 * @param file pointer to structure of organising access to DLT file
866 * @param index position of message in the files beginning from zero
867 * @param verbose if set to true verbose information is printed out.
868 * @return number of messages loaded, negative value if there was an error
870 int dlt_file_message(DltFile *file,int index,int verbose);
872 * Free the used memory by the organising structure of file.
873 * @param file pointer to structure of organising access to DLT file
874 * @param verbose if set to true verbose information is printed out.
875 * @return negative value if there was an error
877 int dlt_file_free(DltFile *file,int verbose);
880 * Set internal logging filename if mode 2
881 * @param filename the filename
883 void dlt_log_set_filename(const char *filename);
885 * Set internal logging level
886 * @param level the level
888 void dlt_log_set_level(int level);
890 * Initialize (external) logging facility
891 * @param mode positive, 0 = log to stdout, 1 = log to syslog, 2 = log to file
893 void dlt_log_init(int mode);
895 * Log ASCII string with null-termination to (external) logging facility
896 * @param prio priority (see syslog() call)
897 * @param s Pointer to ASCII string with null-termination
898 * @return negative value if there was an error
900 int dlt_log(int prio, char *s);
902 * De-Initialize (external) logging facility
904 void dlt_log_free(void);
907 * Initialising a dlt receiver structure
908 * @param receiver pointer to dlt receiver structure
909 * @param _fd handle to file/socket/fifo, fram which the data should be received
910 * @param _buffersize size of data buffer for storing the received data
911 * @return negative value if there was an error
913 int dlt_receiver_init(DltReceiver *receiver,int _fd, int _buffersize);
915 * De-Initialize a dlt receiver structure
916 * @param receiver pointer to dlt receiver structure
917 * @return negative value if there was an error
919 int dlt_receiver_free(DltReceiver *receiver);
921 * Receive data from socket using the dlt receiver structure
922 * @param receiver pointer to dlt receiver structure
923 * @return negative value if there was an error
925 int dlt_receiver_receive_socket(DltReceiver *receiver);
927 * Receive data from file/fifo using the dlt receiver structure
928 * @param receiver pointer to dlt receiver structure
929 * @return negative value if there was an error
931 int dlt_receiver_receive_fd(DltReceiver *receiver);
933 * Remove a specific size of bytes from the received data
934 * @param receiver pointer to dlt receiver structure
935 * @param size amount of bytes to be removed
936 * @return negative value if there was an error
938 int dlt_receiver_remove(DltReceiver *receiver,int size);
940 * Move data from last receive call to front of receive buffer
941 * @param receiver pointer to dlt receiver structure
942 * @return negative value if there was an error
944 int dlt_receiver_move_to_begin(DltReceiver *receiver);
947 * Fill out storage header of a dlt message
948 * @param storageheader pointer to storage header of a dlt message
949 * @param ecu name of ecu to be set in storage header
950 * @return negative value if there was an error
952 int dlt_set_storageheader(DltStorageHeader *storageheader, const char *ecu);
954 * Check if a storage header contains its marker
955 * @param storageheader pointer to storage header of a dlt message
956 * @return 0 no, 1 yes, negative value if there was an error
958 int dlt_check_storageheader(DltStorageHeader *storageheader);
962 * Initialise static ringbuffer with a size of size.
963 * Initialise as server. Init counters.
964 * Memory is already allocated.
965 * @param buf Pointer to ringbuffer structure
966 * @param ptr Ptr to ringbuffer memory
967 * @param size Maximum size of buffer in bytes
968 * @return negative value if there was an error
970 int dlt_buffer_init_static_server(DltBuffer *buf, const unsigned char *ptr, uint32_t size);
973 * Initialize static ringbuffer with a size of size.
974 * Initialise as a client. Do not change counters.
975 * Memory is already allocated.
976 * @param buf Pointer to ringbuffer structure
977 * @param ptr Ptr to ringbuffer memory
978 * @param size Maximum size of buffer in bytes
979 * @return negative value if there was an error
981 int dlt_buffer_init_static_client(DltBuffer *buf, const unsigned char *ptr, uint32_t size);
984 * Initialize dynamic ringbuffer with a size of size.
985 * Initialise as a client. Do not change counters.
986 * Memory will be allocated starting with min_size.
987 * If more memory is needed size is increased wit step_size.
988 * The maximum size is max_size.
989 * @param buf Pointer to ringbuffer structure
990 * @param min_size Minimum size of buffer in bytes
991 * @param max_size Maximum size of buffer in bytes
992 * @param step_size size of which ringbuffer is increased
993 * @return negative value if there was an error
995 int dlt_buffer_init_dynamic(DltBuffer *buf, uint32_t min_size, uint32_t max_size,uint32_t step_size);
998 * Deinitilaise usage of static ringbuffer
999 * @param buf Pointer to ringbuffer structure
1000 * @return negative value if there was an error
1002 int dlt_buffer_free_static(DltBuffer *buf);
1005 * Release and free memory used by dynamic ringbuffer
1006 * @param buf Pointer to ringbuffer structure
1007 * @return negative value if there was an error
1009 int dlt_buffer_free_dynamic(DltBuffer *buf);
1012 * Write one entry to ringbuffer
1013 * @param buf Pointer to ringbuffer structure
1014 * @param data Pointer to data to be written to ringbuffer
1015 * @param size Size of data in bytes to be written to ringbuffer
1016 * @return negative value if there was an error
1018 int dlt_buffer_push(DltBuffer *buf,const unsigned char *data,unsigned int size);
1021 * Write up to three entries to ringbuffer.
1022 * Entries are joined to one block.
1023 * @param dlt Pointer to ringbuffer structure
1024 * @param data1 Pointer to data to be written to ringbuffer
1025 * @param size1 Size of data in bytes to be written to ringbuffer
1026 * @param data2 Pointer to data to be written to ringbuffer
1027 * @param size2 Size of data in bytes to be written to ringbuffer
1028 * @param data3 Pointer to data to be written to ringbuffer
1029 * @param size3 Size of data in bytes to be written to ringbuffer
1030 * @return negative value if there was an error
1032 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);
1035 * Read one entry from ringbuffer.
1036 * Remove it from ringbuffer.
1037 * @param buf Pointer to ringbuffer structure
1038 * @param data Pointer to data read from ringbuffer
1039 * @param max_size Max size of read data in bytes from ringbuffer
1040 * @return size of read data, zero if no data available, negative value if there was an error
1042 int dlt_buffer_pull(DltBuffer *buf,unsigned char *data, int max_size);
1045 * Read one entry from ringbuffer.
1046 * Do not remove it from ringbuffer.
1047 * @param buf Pointer to ringbuffer structure
1048 * @param data Pointer to data read from ringbuffer
1049 * @param max_size Max size of read data in bytes from ringbuffer
1050 * @return size of read data, zero if no data available, negative value if there was an error
1052 int dlt_buffer_copy(DltBuffer *buf,unsigned char *data, int max_size);
1055 * Remove entry from ringbuffer.
1056 * @param buf Pointer to ringbuffer structure
1057 * @return size of read data, zero if no data available, negative value if there was an error
1059 int dlt_buffer_remove(DltBuffer *buf);
1062 * Print information about buffer and log to internal DLT log.
1063 * @param buf Pointer to ringbuffer structure
1065 void dlt_buffer_info(DltBuffer *buf);
1068 * Print status of buffer and log to internal DLT log.
1069 * @param buf Pointer to ringbuffer structure
1071 void dlt_buffer_status(DltBuffer *buf);
1074 * Get total size in bytes of ringbuffer.
1075 * If buffer is dynamic, max size is returned.
1076 * @param buf Pointer to ringbuffer structure
1077 * @return total size of buffer
1079 int dlt_buffer_get_total_size(DltBuffer *buf);
1082 * Get used size in bytes of ringbuffer.
1083 * @param buf Pointer to ringbuffer structure
1084 * @return used size of buffer
1086 int dlt_buffer_get_used_size(DltBuffer *buf);
1089 * Get number of entries in ringbuffer.
1090 * @param buf Pointer to ringbuffer structure
1091 * @return number of entries
1093 int dlt_buffer_get_message_count(DltBuffer *buf);
1095 #if !defined (__WIN32__)
1098 * Helper function: Setup serial connection
1099 * @param fd File descriptor of serial tty device
1100 * @param speed Serial line speed, as defined in termios.h
1101 * @return negative value if there was an error
1103 int dlt_setup_serial(int fd, speed_t speed);
1106 * Helper function: Convert serial line baudrate (as number) to line speed (as defined in termios.h)
1107 * @param baudrate Serial line baudrate (as number)
1108 * @return Serial line speed, as defined in termios.h
1110 speed_t dlt_convert_serial_speed(int baudrate);
1113 * Print dlt version and dlt svn version to buffer
1114 * @param buf Pointer to buffer
1116 void dlt_get_version(char *buf);
1119 * Print dlt major version to buffer
1120 * @param buf Pointer to buffer
1122 void dlt_get_major_version(char *buf);
1125 * Print dlt minor version to buffer
1126 * @param buf Pointer to buffer
1128 void dlt_get_minor_version(char *buf);
1132 /* Function prototypes which should be used only internally */
1136 * Common part of initialisation
1137 * @return negative value if there was an error
1139 int dlt_init_common(void);
1142 * Return the uptime of the system in 0.1 ms resolution
1143 * @return 0 if there was an error
1145 uint32_t dlt_uptime(void);
1148 * Print header of a DLT message
1149 * @param message pointer to structure of organising access to DLT messages
1150 * @param text pointer to a ASCII string, in which the header is written
1151 * @param size maximal size of text buffer
1152 * @param verbose if set to true verbose information is printed out.
1153 * @return negative value if there was an error
1155 int dlt_message_print_header(DltMessage *message, char *text, uint32_t size, int verbose);
1158 * Print payload of a DLT message as Hex-Output
1159 * @param message pointer to structure of organising access to DLT messages
1160 * @param text pointer to a ASCII string, in which the output is written
1161 * @param size maximal size of text buffer
1162 * @param verbose if set to true verbose information is printed out.
1163 * @return negative value if there was an error
1165 int dlt_message_print_hex(DltMessage *message, char *text, uint32_t size, int verbose);
1168 * Print payload of a DLT message as ASCII-Output
1169 * @param message pointer to structure of organising access to DLT messages
1170 * @param text pointer to a ASCII string, in which the output is written
1171 * @param size maximal size of text buffer
1172 * @param verbose if set to true verbose information is printed out.
1173 * @return negative value if there was an error
1175 int dlt_message_print_ascii(DltMessage *message, char *text, uint32_t size, int verbose);
1178 * Print payload of a DLT message as Mixed-Ouput (Hex and ASCII), for plain text output
1179 * @param message pointer to structure of organising access to DLT messages
1180 * @param text pointer to a ASCII string, in which the output is written
1181 * @param size maximal size of text buffer
1182 * @param verbose if set to true verbose information is printed out.
1183 * @return negative value if there was an error
1185 int dlt_message_print_mixed_plain(DltMessage *message, char *text, uint32_t size, int verbose);
1188 * Print payload of a DLT message as Mixed-Ouput (Hex and ASCII), for HTML text output
1189 * @param message pointer to structure of organising access to DLT messages
1190 * @param text pointer to a ASCII string, in which the output is written
1191 * @param size maximal size of text buffer
1192 * @param verbose if set to true verbose information is printed out.
1193 * @return negative value if there was an error
1195 int dlt_message_print_mixed_html(DltMessage *message, char *text, uint32_t size, int verbose);
1198 * Decode and print a argument of a DLT message
1199 * @param msg pointer to structure of organising access to DLT messages
1200 * @param type_info Type of argument
1201 * @param ptr pointer to pointer to data (pointer to data is changed within this function)
1202 * @param datalength pointer to datalength (datalength is changed within this function)
1203 * @param text pointer to a ASCII string, in which the output is written
1204 * @param textlength maximal size of text buffer
1205 * @param byteLength If argument is a string, and this value is 0 or greater, this value will be taken as string length
1206 * @param verbose if set to true verbose information is printed out.
1207 * @return negative value if there was an error
1209 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);
1219 #endif /* DLT_COMMON_H */