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 DLT_LOG_TO_CONSOLE=0,
185 * The standard TCP Port used for DLT daemon
187 #define DLT_DAEMON_TCP_PORT 3490
190 /* Initi value for file descritpor */
191 #define DLT_FD_INIT -1
193 /* Minimum value for a file descriptor except the POSIX Standards: stdin=0, stdout=1, stderr=2 */
194 #define DLT_FD_MINIMUM 3
197 * The size of a DLT ID
199 #define DLT_ID_SIZE 4
201 #define DLT_SIZE_WEID DLT_ID_SIZE
202 #define DLT_SIZE_WSID (sizeof(uint32_t))
203 #define DLT_SIZE_WTMS (sizeof(uint32_t))
206 * Get the size of extra header parameters, depends on htyp.
208 #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) )
211 #if defined (__MSDOS__) || defined (_MSC_VER)
212 #define __func__ __FUNCTION__
215 #define PRINT_FUNCTION_VERBOSE(_verbose) \
217 static char _strbuf[255]; \
221 snprintf(_strbuf, 255, "%s()\n",__func__); \
222 dlt_log(LOG_INFO, _strbuf); \
227 #define NULL (char*)0
230 #define DLT_MSG_IS_CONTROL(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \
231 (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin)==DLT_TYPE_CONTROL))
233 #define DLT_MSG_IS_CONTROL_REQUEST(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \
234 (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin)==DLT_TYPE_CONTROL) && \
235 (DLT_GET_MSIN_MTIN((MSG)->extendedheader->msin)==DLT_CONTROL_REQUEST))
237 #define DLT_MSG_IS_CONTROL_RESPONSE(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \
238 (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin)==DLT_TYPE_CONTROL) && \
239 (DLT_GET_MSIN_MTIN((MSG)->extendedheader->msin)==DLT_CONTROL_RESPONSE))
241 #define DLT_MSG_IS_CONTROL_TIME(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \
242 (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin)==DLT_TYPE_CONTROL) && \
243 (DLT_GET_MSIN_MTIN((MSG)->extendedheader->msin)==DLT_CONTROL_TIME))
245 #define DLT_MSG_IS_NW_TRACE(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \
246 (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin)==DLT_TYPE_NW_TRACE))
248 #define DLT_MSG_IS_TRACE_MOST(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \
249 (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin)==DLT_TYPE_NW_TRACE) && \
250 (DLT_GET_MSIN_MTIN((MSG)->extendedheader->msin)==DLT_NW_TRACE_MOST))
252 #define DLT_MSG_IS_NONVERBOSE(MSG) (!(DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) || \
253 ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && (!(DLT_IS_MSIN_VERB((MSG)->extendedheader->msin)))))
257 * Definitions of DLT message buffer overflow
259 #define DLT_MESSAGE_BUFFER_NO_OVERFLOW 0x00 /**< Buffer overflow has not occured */
260 #define DLT_MESSAGE_BUFFER_OVERFLOW 0x01 /**< Buffer overflow has occured */
263 * Definition of DLT output variants
265 #define DLT_OUTPUT_HEX 1
266 #define DLT_OUTPUT_ASCII 2
267 #define DLT_OUTPUT_MIXED_FOR_PLAIN 3
268 #define DLT_OUTPUT_MIXED_FOR_HTML 4
269 #define DLT_OUTPUT_ASCII_LIMITED 5
271 #define DLT_FILTER_MAX 30 /**< Maximum number of filters */
273 #define DLT_MSG_READ_VALUE(dst,src,length,type) \
275 if((length<0) || ((length)<((int32_t)sizeof(type)))) \
278 { dst = *((type*)src);src+=sizeof(type);length-=sizeof(type); } \
281 #define DLT_MSG_READ_ID(dst,src,length) \
283 if((length<0) || ((length)<DLT_ID_SIZE)) \
286 { memcpy(dst,src,DLT_ID_SIZE);src+=DLT_ID_SIZE;length-=DLT_ID_SIZE; } \
289 #define DLT_MSG_READ_STRING(dst,src,maxlength,length) \
291 if(((maxlength)<0) || ((length)<0) || ((maxlength)<(length))) \
292 { maxlength = -1; } \
294 { memcpy(dst,src,length);dlt_clean_string(dst,length);dst[length]=0; \
295 src+=length;maxlength-=length; } \
298 #define DLT_MSG_READ_NULL(src,maxlength,length) \
300 if(((maxlength)<0) || ((length)<0) || ((maxlength)<(length))) \
303 { src+=length;maxlength-=length; } \
306 #define DLT_HEADER_SHOW_NONE 0x0000
307 #define DLT_HEADER_SHOW_TIME 0x0001
308 #define DLT_HEADER_SHOW_TMSTP 0x0002
309 #define DLT_HEADER_SHOW_MSGCNT 0x0004
310 #define DLT_HEADER_SHOW_ECUID 0x0008
311 #define DLT_HEADER_SHOW_APID 0x0010
312 #define DLT_HEADER_SHOW_CTID 0x0020
313 #define DLT_HEADER_SHOW_MSGTYPE 0x0040
314 #define DLT_HEADER_SHOW_MSGSUBTYPE 0x0080
315 #define DLT_HEADER_SHOW_VNVSTATUS 0x0100
316 #define DLT_HEADER_SHOW_NOARG 0x0200
317 #define DLT_HEADER_SHOW_ALL 0xFFFF
320 * The definition of the serial header containing the characters "DLS" + 0x01.
322 extern const char dltSerialHeader[DLT_ID_SIZE];
325 * The definition of the serial header containing the characters "DLS" + 0x01 as char.
327 extern char dltSerialHeaderChar[DLT_ID_SIZE];
331 * The type of a DLT ID (context id, application id, etc.)
333 typedef char ID4[DLT_ID_SIZE];
336 * The structure of the DLT file storage header. This header is used before each stored DLT message.
340 char pattern[DLT_ID_SIZE]; /**< This pattern should be DLT0x01 */
341 uint32_t seconds; /**< seconds since 1.1.1970 */
342 int32_t microseconds; /**< Microseconds */
343 char ecu[DLT_ID_SIZE]; /**< The ECU id is added, if it is not already in the DLT message itself */
344 } PACKED DltStorageHeader;
347 * The structure of the DLT standard header. This header is used in each DLT message.
351 uint8_t htyp; /**< This parameter contains several informations, see definitions below */
352 uint8_t mcnt; /**< The message counter is increased with each sent DLT message */
353 uint16_t len; /**< Length of the complete message, without storage header */
354 } PACKED DltStandardHeader;
357 * The structure of the DLT extra header parameters. Each parameter is sent only if enabled in htyp.
361 char ecu[DLT_ID_SIZE]; /**< ECU id */
362 uint32_t seid; /**< Session number */
363 uint32_t tmsp; /**< Timestamp since system start in 0.1 milliseconds */
364 } PACKED DltStandardHeaderExtra;
367 * The structure of the DLT extended header. This header is only sent if enabled in htyp parameter.
371 uint8_t msin; /**< messsage info */
372 uint8_t noar; /**< number of arguments */
373 char apid[DLT_ID_SIZE]; /**< application id */
374 char ctid[DLT_ID_SIZE]; /**< context id */
375 } PACKED DltExtendedHeader;
378 * The structure to organise the DLT messages.
379 * This structure is used by the corresponding functions.
381 typedef struct sDltMessage
384 int8_t found_serialheader;
387 int32_t resync_offset;
389 /* size parameters */
390 int32_t headersize; /**< size of complete header including storage header */
391 int32_t datasize; /**< size of complete payload */
393 /* buffer for current loaded message */
394 uint8_t headerbuffer[sizeof(DltStorageHeader)+
395 sizeof(DltStandardHeader)+sizeof(DltStandardHeaderExtra)+sizeof(DltExtendedHeader)]; /**< buffer for loading complete header */
396 uint8_t *databuffer; /**< buffer for loading payload */
397 int32_t databuffersize;
399 /* header values of current loaded message */
400 DltStorageHeader *storageheader; /**< pointer to storage header of current loaded header */
401 DltStandardHeader *standardheader; /**< pointer to standard header of current loaded header */
402 DltStandardHeaderExtra headerextra; /**< extra parameters of current loaded header */
403 DltExtendedHeader *extendedheader; /**< pointer to extended of current loaded header */
407 * The structure of the DLT Service Get Log Info.
411 uint32_t service_id; /**< service ID */
412 uint8_t options; /**< type of request */
413 char apid[DLT_ID_SIZE]; /**< application id */
414 char ctid[DLT_ID_SIZE]; /**< context id */
415 char com[DLT_ID_SIZE]; /**< communication interface */
416 } PACKED DltServiceGetLogInfoRequest;
419 * The structure of the DLT Service Set Log Level.
424 uint32_t service_id; /**< service ID */
425 char apid[DLT_ID_SIZE]; /**< application id */
426 char ctid[DLT_ID_SIZE]; /**< context id */
427 uint8_t log_level; /**< log level to be set */
428 char com[DLT_ID_SIZE]; /**< communication interface */
429 } PACKED DltServiceSetLogLevel;
432 * The structure of the DLT Service Set Default Log Level.
436 uint32_t service_id; /**< service ID */
437 uint8_t log_level; /**< default log level to be set */
438 char com[DLT_ID_SIZE]; /**< communication interface */
439 } PACKED DltServiceSetDefaultLogLevel;
442 * The structure of the DLT Service Set Verbose Mode
446 uint32_t service_id; /**< service ID */
447 uint8_t new_status; /**< new status to be set */
448 } PACKED DltServiceSetVerboseMode;
451 * The structure of the DLT Service Set Communication Interface Status
455 uint32_t service_id; /**< service ID */
456 char com[DLT_ID_SIZE]; /**< communication interface */
457 uint8_t new_status; /**< new status to be set */
458 } PACKED DltServiceSetCommunicationInterfaceStatus;
461 * The structure of the DLT Service Set Communication Maximum Bandwidth
465 uint32_t service_id; /**< service ID */
466 char com[DLT_ID_SIZE]; /**< communication interface */
467 uint32_t max_bandwidth; /**< maximum bandwith */
468 } PACKED DltServiceSetCommunicationMaximumBandwidth;
472 uint32_t service_id; /**< service ID */
473 uint8_t status; /**< reponse status */
474 } PACKED DltServiceResponse;
478 uint32_t service_id; /**< service ID */
479 uint8_t status; /**< reponse status */
480 uint8_t log_level; /**< log level */
481 } PACKED DltServiceGetDefaultLogLevelResponse;
485 uint32_t service_id; /**< service ID */
486 uint8_t status; /**< reponse status */
487 uint8_t overflow; /**< overflow status */
488 uint32_t overflow_counter; /**< overflow counter */
489 } PACKED DltServiceMessageBufferOverflowResponse;
493 uint32_t service_id; /**< service ID */
494 uint8_t status; /**< reponse status */
495 uint32_t length; /**< length of following payload */
496 /*char []Â payload;*/
497 } PACKED DltServiceGetSoftwareVersionResponse;
500 * The structure of the DLT Service Unregister Context.
504 uint32_t service_id; /**< service ID */
505 uint8_t status; /**< reponse status */
506 char apid[DLT_ID_SIZE]; /**< application id */
507 char ctid[DLT_ID_SIZE]; /**< context id */
508 char comid[DLT_ID_SIZE]; /**< communication interface */
509 } PACKED DltServiceUnregisterContext;
512 * The structure of the DLT Service Connection Info
516 uint32_t service_id; /**< service ID */
517 uint8_t status; /**< reponse status */
518 uint8_t state; /**< new state */
519 char comid[DLT_ID_SIZE]; /**< communication interface */
520 } PACKED DltServiceConnectionInfo;
523 * Structure to store filter parameters.
524 * ID are maximal four characters. Unused values are filled with zeros.
525 * If every value as filter is valid, the id should be empty by having only zero values.
529 char apid[DLT_FILTER_MAX][DLT_ID_SIZE]; /**< application id */
530 char ctid[DLT_FILTER_MAX][DLT_ID_SIZE]; /**< context id */
531 int counter; /**< number of filters */
535 * The structure to organise the access to DLT files.
536 * This structure is used by the corresponding functions.
538 typedef struct sDltFile
540 /* file handle and index for fast access */
541 FILE *handle; /**< file handle of opened DLT file */
542 long *index; /**< file positions of all DLT messages for fast access to file, only filtered messages */
544 /* size parameters */
545 int32_t counter; /**< number of messages in DLT file with filter */
546 int32_t counter_total; /**< number of messages in DLT file without filter */
547 int32_t position; /**< current index to message parsed in DLT file starting at 0 */
548 long file_length; /**< length of the file */
549 long file_position; /**< current position in the file */
552 int32_t error_messages; /**< number of incomplete DLT messages found during file parsing */
554 /* filter parameters */
555 DltFilter *filter; /**< pointer to filter list. Zero if no filter is set. */
556 int32_t filter_counter; /**< number of filter set */
558 /* current loaded message */
559 DltMessage msg; /**< pointer to message */
564 * The structure is used to organise the receiving of data
565 * including buffer handling.
566 * This structure is used by the corresponding functions.
570 int32_t lastBytesRcvd; /**< bytes received in last receive call */
571 int32_t bytesRcvd; /**< received bytes */
572 int32_t totalBytesRcvd; /**< total number of received bytes */
573 char *buffer; /**< pointer to receiver buffer */
574 char *buf; /**< pointer to position within receiver buffer */
575 int fd; /**< connection handle */
576 int32_t buffersize; /**< size of receiver buffer */
581 unsigned char* shm; /* pointer to beginning of shared memory */
582 int size; /* size of data area in shared memory */
583 unsigned char* mem; /* pointer to data area in shared memory */
585 uint32_t min_size; /**< Minimum size of buffer */
586 uint32_t max_size; /**< Maximum size of buffer */
587 uint32_t step_size; /**< Step size of buffer */
597 #define DLT_BUFFER_HEAD "SHM"
602 unsigned char status;
604 } DltBufferBlockHead;
612 * Helper function to print a byte array in hex.
613 * @param ptr pointer to the byte array.
614 * @param size number of bytes to be printed.
616 void dlt_print_hex(uint8_t *ptr,int size);
618 * Helper function to print a byte array in hex into a string.
619 * @param text pointer to a ASCII string, in which the text is written
620 * @param textlength maximal size of text buffer
621 * @param ptr pointer to the byte array.
622 * @param size number of bytes to be printed.
623 * @return negative value if there was an error
625 int dlt_print_hex_string(char *text,int textlength,uint8_t *ptr,int size);
627 * Helper function to print a byte array in hex and ascii into a string.
628 * @param text pointer to a ASCII string, in which the text is written
629 * @param textlength maximal size of text buffer
630 * @param ptr pointer to the byte array.
631 * @param size number of bytes to be printed.
632 * @param html output is html? 0 - false, 1 - true
633 * @return negative value if there was an error
635 int dlt_print_mixed_string(char *text,int textlength,uint8_t *ptr,int size,int html);
637 * Helper function to print a byte array in ascii into a string.
638 * @param text pointer to a ASCII string, in which the text is written
639 * @param textlength maximal size of text buffer
640 * @param ptr pointer to the byte array.
641 * @param size number of bytes to be printed.
642 * @return negative value if there was an error
644 int dlt_print_char_string(char **text,int textlength,uint8_t *ptr,int size);
647 * Helper function to print an id.
648 * @param text pointer to ASCII string where to write the id
649 * @param id four byte char array as used in DLT mesages as IDs.
651 void dlt_print_id(char *text,const char *id);
654 * Helper function to set an ID parameter.
655 * @param id four byte char array as used in DLT mesages as IDs.
656 * @param text string to be copied into char array.
658 void dlt_set_id(char *id,const char *text);
661 * Helper function to remove not nice to print characters, e.g. NULL or carage return.
662 * @param text pointer to string to be cleaned.
663 * @param length length of string excluding terminating zero.
665 void dlt_clean_string(char *text,int length);
668 * Initialise the filter list.
669 * This function must be called before using further dlt filter.
670 * @param filter pointer to structure of organising DLT filter
671 * @param verbose if set to true verbose information is printed out.
672 * @return negative value if there was an error
674 int dlt_filter_init(DltFilter *filter,int verbose);
676 * Free the used memory by the organising structure of filter.
677 * @param filter pointer to structure of organising DLT filter
678 * @param verbose if set to true verbose information is printed out.
679 * @return negative value if there was an error
681 int dlt_filter_free(DltFilter *filter,int verbose);
683 * Load filter list from file.
684 * @param filter pointer to structure of organising DLT filter
685 * @param filename filename to load filters from
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_load(DltFilter *filter,const char *filename,int verbose);
691 * Save filter list to file.
692 * @param filter pointer to structure of organising DLT filter
693 * @param filename filename to load filters from
694 * @param verbose if set to true verbose information is printed out.
695 * @return negative value if there was an error
697 int dlt_filter_save(DltFilter *filter,const char *filename,int verbose);
699 * Find index of filter in filter list
700 * @param filter pointer to structure of organising DLT filter
701 * @param apid application id to be found in filter list
702 * @param ctid context id to be found in filter list
703 * @param verbose if set to true verbose information is printed out.
704 * @return negative value if there was an error (or not found), else return index of filter
706 int dlt_filter_find(DltFilter *filter,const char *apid,const char *ctid, int verbose);
708 * Add new filter to filter list.
709 * @param filter pointer to structure of organising DLT filter
710 * @param apid application id to be added to filter list (must always be set).
711 * @param ctid context id to be added to filter list. empty equals don't care.
712 * @param verbose if set to true verbose information is printed out.
713 * @return negative value if there was an error
715 int dlt_filter_add(DltFilter *filter,const char *apid,const char *ctid,int verbose);
717 * Delete filter from filter list
718 * @param filter pointer to structure of organising DLT filter
719 * @param apid application id to be deleted from filter list
720 * @param ctid context id to be deleted from filter list
721 * @param verbose if set to true verbose information is printed out.
722 * @return negative value if there was an error
724 int dlt_filter_delete(DltFilter *filter,const char *apid,const char *ctid,int verbose);
727 * Initialise the structure used to access a DLT message.
728 * This function must be called before using further dlt_message functions.
729 * @param msg pointer to structure of organising access to DLT messages
730 * @param verbose if set to true verbose information is printed out.
731 * @return negative value if there was an error
733 int dlt_message_init(DltMessage *msg,int verbose);
735 * Free the used memory by the organising structure of file.
736 * @param msg pointer to structure of organising access to DLT messages
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_free(DltMessage *msg,int verbose);
742 * Print Header into an ASCII string.
743 * This function calls dlt_message_header_flags() with flags=DLT_HEADER_SHOW_ALL
744 * @param msg pointer to structure of organising access to DLT messages
745 * @param text pointer to a ASCII string, in which the header is written
746 * @param textlength maximal size of text buffer
747 * @param verbose if set to true verbose information is printed out.
748 * @return negative value if there was an error
750 int dlt_message_header(DltMessage *msg,char *text,int textlength,int verbose);
752 * Print Header into an ASCII string, selective.
753 * @param msg pointer to structure of organising access to DLT messages
754 * @param text pointer to a ASCII string, in which the header is written
755 * @param textlength maximal size of text buffer
756 * @param flags select, bit-field to select, what should be printed (DLT_HEADER_SHOW_...)
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_header_flags(DltMessage *msg,char *text,int textlength,int flags, int verbose);
762 * Print Payload into an ASCII string.
763 * @param msg pointer to structure of organising access to DLT messages
764 * @param text pointer to a ASCII string, in which the header is written
765 * @param textlength maximal size of text buffer
766 * @param type 1 = payload as hex, 2 = payload as ASCII.
767 * @param verbose if set to true verbose information is printed out.
768 * @return negative value if there was an error
770 int dlt_message_payload(DltMessage *msg,char *text,int textlength,int type,int verbose);
772 * Check if message is filtered or not. All filters are applied (logical OR).
773 * @param msg pointer to structure of organising access to DLT messages
774 * @param filter pointer to filter
775 * @param verbose if set to true verbose information is printed out.
776 * @return 1 = filter matches, 0 = filter does not match, negative value if there was an error
778 int dlt_message_filter_check(DltMessage *msg,DltFilter *filter,int verbose);
781 * Read message from memory buffer.
782 * Message in buffer has no storage header.
783 * @param msg pointer to structure of organising access to DLT messages
784 * @param buffer pointer to memory buffer
785 * @param length length of message in buffer
786 * @param resync if set to true resync to serial header is enforced
787 * @param verbose if set to true verbose information is printed out.
788 * @return negative value if there was an error
790 int dlt_message_read(DltMessage *msg,uint8_t *buffer,unsigned int length,int resync,int verbose);
793 * Get standard header extra parameters
794 * @param msg pointer to structure of organising access to DLT messages
795 * @param verbose if set to true verbose information is printed out.
796 * @return negative value if there was an error
798 int dlt_message_get_extraparameters(DltMessage *msg,int verbose);
801 * Set standard header extra parameters
802 * @param msg pointer to structure of organising access to DLT messages
803 * @param verbose if set to true verbose information is printed out.
804 * @return negative value if there was an error
806 int dlt_message_set_extraparameters(DltMessage *msg,int verbose);
809 * Initialise the structure used to access a DLT file.
810 * This function must be called before using further dlt_file functions.
811 * @param file pointer to structure of organising access to DLT file
812 * @param verbose if set to true verbose information is printed out.
813 * @return negative value if there was an error
815 int dlt_file_init(DltFile *file,int verbose);
817 * Set a list to filters.
818 * This function should be called before loading a DLT file, if filters should be used.
819 * A filter list is an array of filters. Several filters are combined logically by or operation.
820 * The filter list is not copied, so take care to keep list in memory.
821 * @param file pointer to structure of organising access to DLT file
822 * @param filter pointer to filter list array
823 * @param verbose if set to true verbose information is printed out.
824 * @return negative value if there was an error
826 int dlt_file_set_filter(DltFile *file,DltFilter *filter,int verbose);
828 * Initialising loading a DLT file.
829 * @param file pointer to structure of organising access to DLT file
830 * @param filename filename of DLT file
831 * @param verbose if set to true verbose information is printed out.
832 * @return negative value if there was an error
834 int dlt_file_open(DltFile *file,const char *filename,int verbose);
836 * Find next message in the DLT file and parse them.
837 * This function finds the next message in the DLT file.
838 * If a filter is set, the filter list is used.
839 * @param file pointer to structure of organising access to DLT file
840 * @param verbose if set to true verbose information is printed out.
841 * @return 0 = message does not match filter, 1 = message was read, negative value if there was an error
843 int dlt_file_read(DltFile *file,int verbose);
845 * Find next message in the DLT file in RAW format (without storage header) and parse them.
846 * This function finds the next message in the DLT file.
847 * If a filter is set, the filter list is used.
848 * @param file pointer to structure of organising access to DLT file
849 * @param resync Resync to serial header when set to true
850 * @param verbose if set to true verbose information is printed out.
851 * @return 0 = message does not match filter, 1 = message was read, negative value if there was an error
853 int dlt_file_read_raw(DltFile *file,int resync,int verbose);
855 * Closing loading a DLT file.
856 * @param file pointer to structure of organising access to DLT file
857 * @param verbose if set to true verbose information is printed out.
858 * @return negative value if there was an error
860 int dlt_file_close(DltFile *file,int verbose);
862 * Load standard header of a message from file
863 * @param file pointer to structure of organising access to DLT file
864 * @param verbose if set to true verbose information is printed out.
865 * @return negative value if there was an error
867 int dlt_file_read_header(DltFile *file,int verbose);
869 * Load standard header of a message from file in RAW format (without storage header)
870 * @param file pointer to structure of organising access to DLT file
871 * @param resync Resync to serial header when set to true
872 * @param verbose if set to true verbose information is printed out.
873 * @return negative value if there was an error
875 int dlt_file_read_header_raw(DltFile *file,int resync,int verbose);
877 * Load, if available in message, extra standard header fields and
878 * extended header of a message from file
879 * (dlt_file_read_header() must have been called before this call!)
880 * @param file pointer to structure of organising access to DLT file
881 * @param verbose if set to true verbose information is printed out.
882 * @return negative value if there was an error
884 int dlt_file_read_header_extended(DltFile *file, int verbose);
886 * Load payload of a message from file
887 * (dlt_file_read_header() must have been called before this call!)
888 * @param file pointer to structure of organising access to DLT file
889 * @param verbose if set to true verbose information is printed out.
890 * @return negative value if there was an error
892 int dlt_file_read_data(DltFile *file, int verbose);
894 * Load headers and payload of a message selected by the index.
895 * If filters are set, index is based on the filtered list.
896 * @param file pointer to structure of organising access to DLT file
897 * @param index position of message in the files beginning from zero
898 * @param verbose if set to true verbose information is printed out.
899 * @return number of messages loaded, negative value if there was an error
901 int dlt_file_message(DltFile *file,int index,int verbose);
903 * Free the used memory by the organising structure of file.
904 * @param file pointer to structure of organising access to DLT file
905 * @param verbose if set to true verbose information is printed out.
906 * @return negative value if there was an error
908 int dlt_file_free(DltFile *file,int verbose);
911 * Set internal logging filename if mode 2
912 * @param filename the filename
914 void dlt_log_set_filename(const char *filename);
916 * Set internal logging level
917 * @param level the level
919 void dlt_log_set_level(int level);
921 * Initialize (external) logging facility
922 * @param mode positive, 0 = log to stdout, 1 = log to syslog, 2 = log to file
924 void dlt_log_init(int mode);
926 * Log ASCII string with null-termination to (external) logging facility
927 * @param prio priority (see syslog() call)
928 * @param s Pointer to ASCII string with null-termination
929 * @return negative value if there was an error
931 int dlt_log(int prio, char *s);
933 * De-Initialize (external) logging facility
935 void dlt_log_free(void);
938 * Initialising a dlt receiver structure
939 * @param receiver pointer to dlt receiver structure
940 * @param _fd handle to file/socket/fifo, fram which the data should be received
941 * @param _buffersize size of data buffer for storing the received data
942 * @return negative value if there was an error
944 int dlt_receiver_init(DltReceiver *receiver,int _fd, int _buffersize);
946 * De-Initialize a dlt receiver structure
947 * @param receiver pointer to dlt receiver structure
948 * @return negative value if there was an error
950 int dlt_receiver_free(DltReceiver *receiver);
952 * Receive data from socket using the dlt receiver structure
953 * @param receiver pointer to dlt receiver structure
954 * @return negative value if there was an error
956 int dlt_receiver_receive_socket(DltReceiver *receiver);
958 * Receive data from file/fifo using the dlt receiver structure
959 * @param receiver pointer to dlt receiver structure
960 * @return negative value if there was an error
962 int dlt_receiver_receive_fd(DltReceiver *receiver);
964 * Remove a specific size of bytes from the received data
965 * @param receiver pointer to dlt receiver structure
966 * @param size amount of bytes to be removed
967 * @return negative value if there was an error
969 int dlt_receiver_remove(DltReceiver *receiver,int size);
971 * Move data from last receive call to front of receive buffer
972 * @param receiver pointer to dlt receiver structure
973 * @return negative value if there was an error
975 int dlt_receiver_move_to_begin(DltReceiver *receiver);
978 * Fill out storage header of a dlt message
979 * @param storageheader pointer to storage header of a dlt message
980 * @param ecu name of ecu to be set in storage header
981 * @return negative value if there was an error
983 int dlt_set_storageheader(DltStorageHeader *storageheader, const char *ecu);
985 * Check if a storage header contains its marker
986 * @param storageheader pointer to storage header of a dlt message
987 * @return 0 no, 1 yes, negative value if there was an error
989 int dlt_check_storageheader(DltStorageHeader *storageheader);
993 * Initialise static ringbuffer with a size of size.
994 * Initialise as server. Init counters.
995 * Memory is already allocated.
996 * @param buf Pointer to ringbuffer structure
997 * @param ptr Ptr to ringbuffer memory
998 * @param size Maximum size of buffer in bytes
999 * @return negative value if there was an error
1001 int dlt_buffer_init_static_server(DltBuffer *buf, const unsigned char *ptr, uint32_t size);
1004 * Initialize static ringbuffer with a size of size.
1005 * Initialise as a client. Do not change counters.
1006 * Memory is already allocated.
1007 * @param buf Pointer to ringbuffer structure
1008 * @param ptr Ptr to ringbuffer memory
1009 * @param size Maximum size of buffer in bytes
1010 * @return negative value if there was an error
1012 int dlt_buffer_init_static_client(DltBuffer *buf, const unsigned char *ptr, uint32_t size);
1015 * Initialize dynamic ringbuffer with a size of size.
1016 * Initialise as a client. Do not change counters.
1017 * Memory will be allocated starting with min_size.
1018 * If more memory is needed size is increased wit step_size.
1019 * The maximum size is max_size.
1020 * @param buf Pointer to ringbuffer structure
1021 * @param min_size Minimum size of buffer in bytes
1022 * @param max_size Maximum size of buffer in bytes
1023 * @param step_size size of which ringbuffer is increased
1024 * @return negative value if there was an error
1026 int dlt_buffer_init_dynamic(DltBuffer *buf, uint32_t min_size, uint32_t max_size,uint32_t step_size);
1029 * Deinitilaise usage of static ringbuffer
1030 * @param buf Pointer to ringbuffer structure
1031 * @return negative value if there was an error
1033 int dlt_buffer_free_static(DltBuffer *buf);
1036 * Release and free memory used by dynamic ringbuffer
1037 * @param buf Pointer to ringbuffer structure
1038 * @return negative value if there was an error
1040 int dlt_buffer_free_dynamic(DltBuffer *buf);
1043 * Write one entry to ringbuffer
1044 * @param buf Pointer to ringbuffer structure
1045 * @param data Pointer to data to be written to ringbuffer
1046 * @param size Size of data in bytes to be written to ringbuffer
1047 * @return negative value if there was an error
1049 int dlt_buffer_push(DltBuffer *buf,const unsigned char *data,unsigned int size);
1052 * Write up to three entries to ringbuffer.
1053 * Entries are joined to one block.
1054 * @param dlt Pointer to ringbuffer structure
1055 * @param data1 Pointer to data to be written to ringbuffer
1056 * @param size1 Size of data in bytes to be written to ringbuffer
1057 * @param data2 Pointer to data to be written to ringbuffer
1058 * @param size2 Size of data in bytes to be written to ringbuffer
1059 * @param data3 Pointer to data to be written to ringbuffer
1060 * @param size3 Size of data in bytes to be written to ringbuffer
1061 * @return negative value if there was an error
1063 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);
1066 * Read one entry from ringbuffer.
1067 * Remove it from ringbuffer.
1068 * @param buf Pointer to ringbuffer structure
1069 * @param data Pointer to data read from ringbuffer
1070 * @param max_size Max size of read data in bytes from ringbuffer
1071 * @return size of read data, zero if no data available, negative value if there was an error
1073 int dlt_buffer_pull(DltBuffer *buf,unsigned char *data, int max_size);
1076 * Read one entry from ringbuffer.
1077 * Do not remove it from ringbuffer.
1078 * @param buf Pointer to ringbuffer structure
1079 * @param data Pointer to data read from ringbuffer
1080 * @param max_size Max size of read data in bytes from ringbuffer
1081 * @return size of read data, zero if no data available, negative value if there was an error
1083 int dlt_buffer_copy(DltBuffer *buf,unsigned char *data, int max_size);
1086 * Remove entry from ringbuffer.
1087 * @param buf Pointer to ringbuffer structure
1088 * @return size of read data, zero if no data available, negative value if there was an error
1090 int dlt_buffer_remove(DltBuffer *buf);
1093 * Print information about buffer and log to internal DLT log.
1094 * @param buf Pointer to ringbuffer structure
1096 void dlt_buffer_info(DltBuffer *buf);
1099 * Print status of buffer and log to internal DLT log.
1100 * @param buf Pointer to ringbuffer structure
1102 void dlt_buffer_status(DltBuffer *buf);
1105 * Get total size in bytes of ringbuffer.
1106 * If buffer is dynamic, max size is returned.
1107 * @param buf Pointer to ringbuffer structure
1108 * @return total size of buffer
1110 int dlt_buffer_get_total_size(DltBuffer *buf);
1113 * Get used size in bytes of ringbuffer.
1114 * @param buf Pointer to ringbuffer structure
1115 * @return used size of buffer
1117 int dlt_buffer_get_used_size(DltBuffer *buf);
1120 * Get number of entries in ringbuffer.
1121 * @param buf Pointer to ringbuffer structure
1122 * @return number of entries
1124 int dlt_buffer_get_message_count(DltBuffer *buf);
1126 #if !defined (__WIN32__)
1129 * Helper function: Setup serial connection
1130 * @param fd File descriptor of serial tty device
1131 * @param speed Serial line speed, as defined in termios.h
1132 * @return negative value if there was an error
1134 int dlt_setup_serial(int fd, speed_t speed);
1137 * Helper function: Convert serial line baudrate (as number) to line speed (as defined in termios.h)
1138 * @param baudrate Serial line baudrate (as number)
1139 * @return Serial line speed, as defined in termios.h
1141 speed_t dlt_convert_serial_speed(int baudrate);
1144 * Print dlt version and dlt svn version to buffer
1145 * @param buf Pointer to buffer
1147 void dlt_get_version(char *buf);
1150 * Print dlt major version to buffer
1151 * @param buf Pointer to buffer
1153 void dlt_get_major_version(char *buf);
1156 * Print dlt minor version to buffer
1157 * @param buf Pointer to buffer
1159 void dlt_get_minor_version(char *buf);
1163 /* Function prototypes which should be used only internally */
1167 * Common part of initialisation
1168 * @return negative value if there was an error
1170 int dlt_init_common(void);
1173 * Return the uptime of the system in 0.1 ms resolution
1174 * @return 0 if there was an error
1176 uint32_t dlt_uptime(void);
1179 * Print header of a DLT message
1180 * @param message pointer to structure of organising access to DLT messages
1181 * @param text pointer to a ASCII string, in which the header 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_header(DltMessage *message, char *text, uint32_t size, int verbose);
1189 * Print payload of a DLT message as Hex-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_hex(DltMessage *message, char *text, uint32_t size, int verbose);
1199 * Print payload of a DLT message as ASCII-Output
1200 * @param message pointer to structure of organising access to DLT messages
1201 * @param text pointer to a ASCII string, in which the output is written
1202 * @param size maximal size of text buffer
1203 * @param verbose if set to true verbose information is printed out.
1204 * @return negative value if there was an error
1206 int dlt_message_print_ascii(DltMessage *message, char *text, uint32_t size, int verbose);
1209 * Print payload of a DLT message as Mixed-Ouput (Hex and ASCII), for plain text output
1210 * @param message pointer to structure of organising access to DLT messages
1211 * @param text pointer to a ASCII string, in which the output is written
1212 * @param size maximal size of text buffer
1213 * @param verbose if set to true verbose information is printed out.
1214 * @return negative value if there was an error
1216 int dlt_message_print_mixed_plain(DltMessage *message, char *text, uint32_t size, int verbose);
1219 * Print payload of a DLT message as Mixed-Ouput (Hex and ASCII), for HTML text output
1220 * @param message pointer to structure of organising access to DLT messages
1221 * @param text pointer to a ASCII string, in which the output is written
1222 * @param size maximal size of text buffer
1223 * @param verbose if set to true verbose information is printed out.
1224 * @return negative value if there was an error
1226 int dlt_message_print_mixed_html(DltMessage *message, char *text, uint32_t size, int verbose);
1229 * Decode and print a argument of a DLT message
1230 * @param msg pointer to structure of organising access to DLT messages
1231 * @param type_info Type of argument
1232 * @param ptr pointer to pointer to data (pointer to data is changed within this function)
1233 * @param datalength pointer to datalength (datalength is changed within this function)
1234 * @param text pointer to a ASCII string, in which the output is written
1235 * @param textlength maximal size of text buffer
1236 * @param byteLength If argument is a string, and this value is 0 or greater, this value will be taken as string length
1237 * @param verbose if set to true verbose information is printed out.
1238 * @return negative value if there was an error
1240 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);
1243 * Check environment variables.
1245 void dlt_check_envvar();
1255 #endif /* DLT_COMMON_H */