2 * Dlt- Diagnostic Log and Trace
5 * Copyright (C) 2011, BMW AG - Alexander Wenzel <alexander.wenzel@bmw.de>
7 * This program is free software; you can redistribute it and/or modify it under the terms of the
8 * GNU Lesser General Public License, version 2.1, as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
10 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
11 * Public License, version 2.1, for more details.
13 * You should have received a copy of the GNU Lesser General Public License, version 2.1, along
14 * with this program; if not, see <http://www.gnu.org/licenses/lgpl-2.1.html>.
16 * Note that the copyright holders assume that the GNU Lesser General Public License, version 2.1, may
17 * also be applicable to programs even in cases in which the program is not a library in the technical sense.
19 * Linking DLT statically or dynamically with other modules is making a combined work based on DLT. You may
20 * license such other modules under the GNU Lesser General Public License, version 2.1. If you do not want to
21 * license your linked modules under the GNU Lesser General Public License, version 2.1, you
22 * may use the program under the following exception.
24 * As a special exception, the copyright holders of DLT give you permission to combine DLT
25 * with software programs or libraries that are released under any license unless such a combination is not
26 * permitted by the license of such a software program or library. You may copy and distribute such a
27 * system following the terms of the GNU Lesser General Public License, version 2.1, including this
28 * special exception, for DLT and the licenses of the other code concerned.
30 * Note that people who make modified versions of DLT are not obligated to grant this special exception
31 * for their modified versions; it is their choice whether to do so. The GNU Lesser General Public License,
32 * version 2.1, gives permission to release a modified version without this exception; this exception
33 * also makes it possible to release a modified version which carries forward this exception.
39 /*******************************************************************************
41 ** SRC-MODULE: dlt_common.h **
47 ** AUTHOR : Alexander Wenzel Alexander.AW.Wenzel@bmw.de **
54 ** PLATFORM DEPENDANT [yes/no]: yes **
56 ** TO BE CHANGED BY USER [yes/no]: no **
58 *******************************************************************************/
60 /*******************************************************************************
62 ********************************************************************************
64 ** Initials Name Company **
65 ** -------- ------------------------- ---------------------------------- **
66 ** aw Alexander Wenzel BMW **
67 ** mk Markus Klein Fraunhofer ESK **
68 *******************************************************************************/
70 /*******************************************************************************
71 ** Revision Control History **
72 *******************************************************************************/
75 * $LastChangedRevision: 1670 $
76 * $LastChangedDate: 2011-04-08 15:12:06 +0200 (Fr, 08. Apr 2011) $
85 \defgroup commonapi DLT Common API
92 #if !defined(_MSC_VER)
97 #if !defined (__WIN32__) && !defined(_MSC_VER)
101 #include "dlt_types.h"
102 #include "dlt_protocol.h"
104 #if !defined (PACKED)
105 #define PACKED __attribute__((aligned(1),packed))
108 #if defined (__MSDOS__) || defined (_MSC_VER)
109 /* set instead /Zp8 flag in Visual C++ configuration */
115 * Macros to swap the byte order.
117 #define DLT_SWAP_64(value) ((((uint64_t)DLT_SWAP_32((value)&0xffffffffull))<<32) | (DLT_SWAP_32((value)>>32)))
119 #define DLT_SWAP_16(value) ((((value) >> 8)&0xff) | (((value) << 8)&0xff00))
120 #define DLT_SWAP_32(value) ((((value) >> 24)&0xff) | (((value) << 8)&0xff0000) | (((value) >> 8)&0xff00) | (((value) << 24)&0xff000000))
122 /* Set Big Endian and Little Endian to a initial value, if not defined */
123 #ifndef LITTLE_ENDIAN
124 #define LITTLE_ENDIAN 1234
128 #define BIG_ENDIAN 4321
131 /* If byte order is not defined, default to little endian */
133 #define BYTE_ORDER LITTLE_ENDIAN
136 /* Check for byte-order */
137 #if (BYTE_ORDER==BIG_ENDIAN)
138 /* #warning "Big Endian Architecture!" */
139 #define DLT_HTOBE_16(x) ((x))
140 #define DLT_HTOLE_16(x) DLT_SWAP_16((x))
141 #define DLT_BETOH_16(x) ((x))
142 #define DLT_LETOH_16(x) DLT_SWAP_16((x))
144 #define DLT_HTOBE_32(x) ((x))
145 #define DLT_HTOLE_32(x) DLT_SWAP_32((x))
146 #define DLT_BETOH_32(x) ((x))
147 #define DLT_LETOH_32(x) DLT_SWAP_32((x))
149 #define DLT_HTOBE_64(x) ((x))
150 #define DLT_HTOLE_64(x) DLT_SWAP_64((x))
151 #define DLT_BETOH_64(x) ((x))
152 #define DLT_LETOH_64(x) DLT_SWAP_64((x))
154 /* #warning "Litte Endian Architecture!" */
155 #define DLT_HTOBE_16(x) DLT_SWAP_16((x))
156 #define DLT_HTOLE_16(x) ((x))
157 #define DLT_BETOH_16(x) DLT_SWAP_16((x))
158 #define DLT_LETOH_16(x) ((x))
160 #define DLT_HTOBE_32(x) DLT_SWAP_32((x))
161 #define DLT_HTOLE_32(x) ((x))
162 #define DLT_BETOH_32(x) DLT_SWAP_32((x))
163 #define DLT_LETOH_32(x) ((x))
165 #define DLT_HTOBE_64(x) DLT_SWAP_64((x))
166 #define DLT_HTOLE_64(x) ((x))
167 #define DLT_BETOH_64(x) DLT_SWAP_64((x))
168 #define DLT_LETOH_64(x) ((x))
171 #define DLT_ENDIAN_GET_16(htyp,x) ((((htyp) & DLT_HTYP_MSBF)>0)?DLT_BETOH_16(x):DLT_LETOH_16(x))
172 #define DLT_ENDIAN_GET_32(htyp,x) ((((htyp) & DLT_HTYP_MSBF)>0)?DLT_BETOH_32(x):DLT_LETOH_32(x))
173 #define DLT_ENDIAN_GET_64(htyp,x) ((((htyp) & DLT_HTYP_MSBF)>0)?DLT_BETOH_64(x):DLT_LETOH_64(x))
175 #if defined (__WIN32__) || defined (_MSC_VER)
180 #define LOG_WARNING 4
186 #define LOG_DAEMON (3<<3)
190 * The standard TCP Port used for DLT daemon
192 #define DLT_DAEMON_TCP_PORT 3490
195 * The size of a DLT ID
197 #define DLT_ID_SIZE 4
199 #define DLT_SIZE_WEID DLT_ID_SIZE
200 #define DLT_SIZE_WSID (sizeof(uint32_t))
201 #define DLT_SIZE_WTMS (sizeof(uint32_t))
204 * Get the size of extra header parameters, depends on htyp.
206 #define DLT_STANDARD_HEADER_EXTRA_SIZE(htyp) ( (DLT_IS_HTYP_WEID(htyp) ? DLT_SIZE_WEID : 0) + (DLT_IS_HTYP_WSID(htyp) ? DLT_SIZE_WSID : 0) + (DLT_IS_HTYP_WTMS(htyp) ? DLT_SIZE_WTMS : 0) )
209 #if defined (__MSDOS__) || defined (_MSC_VER)
210 #define __func__ __FUNCTION__
213 #define PRINT_FUNCTION_VERBOSE(_verbose) \
215 static char _strbuf[255]; \
219 sprintf(_strbuf, "%s()\n",__func__); \
220 dlt_log(LOG_INFO, _strbuf); \
225 #define NULL (char*)0
228 #define DLT_MSG_IS_CONTROL(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \
229 (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin)==DLT_TYPE_CONTROL))
231 #define DLT_MSG_IS_CONTROL_REQUEST(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \
232 (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin)==DLT_TYPE_CONTROL) && \
233 (DLT_GET_MSIN_MTIN((MSG)->extendedheader->msin)==DLT_CONTROL_REQUEST))
235 #define DLT_MSG_IS_CONTROL_RESPONSE(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \
236 (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin)==DLT_TYPE_CONTROL) && \
237 (DLT_GET_MSIN_MTIN((MSG)->extendedheader->msin)==DLT_CONTROL_RESPONSE))
239 #define DLT_MSG_IS_CONTROL_TIME(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \
240 (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin)==DLT_TYPE_CONTROL) && \
241 (DLT_GET_MSIN_MTIN((MSG)->extendedheader->msin)==DLT_CONTROL_TIME))
243 #define DLT_MSG_IS_NW_TRACE(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \
244 (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin)==DLT_TYPE_NW_TRACE))
246 #define DLT_MSG_IS_TRACE_MOST(MSG) ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && \
247 (DLT_GET_MSIN_MSTP((MSG)->extendedheader->msin)==DLT_TYPE_NW_TRACE) && \
248 (DLT_GET_MSIN_MTIN((MSG)->extendedheader->msin)==DLT_NW_TRACE_MOST))
250 #define DLT_MSG_IS_NONVERBOSE(MSG) (!(DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) || \
251 ((DLT_IS_HTYP_UEH((MSG)->standardheader->htyp)) && (!(DLT_IS_MSIN_VERB((MSG)->extendedheader->msin)))))
255 * Definitions of DLT message buffer overflow
257 #define DLT_MESSAGE_BUFFER_NO_OVERFLOW 0x00 /**< Buffer overflow has not occured */
258 #define DLT_MESSAGE_BUFFER_OVERFLOW 0x01 /**< Buffer overflow has occured */
261 * Definition of DLT output variants
263 #define DLT_OUTPUT_HEX 1
264 #define DLT_OUTPUT_ASCII 2
265 #define DLT_OUTPUT_MIXED_FOR_PLAIN 3
266 #define DLT_OUTPUT_MIXED_FOR_HTML 4
267 #define DLT_OUTPUT_ASCII_LIMITED 5
269 #define DLT_FILTER_MAX 30 /**< Maximum number of filters */
271 #define DLT_MSG_READ_VALUE(dst,src,length,type) \
273 if((length<0) || ((length)<((int32_t)sizeof(type)))) \
276 { dst = *((type*)src);src+=sizeof(type);length-=sizeof(type); } \
279 #define DLT_MSG_READ_ID(dst,src,length) \
281 if((length<0) || ((length)<DLT_ID_SIZE)) \
284 { memcpy(dst,src,DLT_ID_SIZE);src+=DLT_ID_SIZE;length-=DLT_ID_SIZE; } \
287 #define DLT_MSG_READ_STRING(dst,src,maxlength,length) \
289 if(((maxlength)<0) || ((length)<0) || ((maxlength)<(length))) \
290 { maxlength = -1; } \
292 { memcpy(dst,src,length);dlt_clean_string(dst,length);dst[length]=0; \
293 src+=length;maxlength-=length; } \
296 #define DLT_MSG_READ_NULL(src,maxlength,length) \
298 if(((maxlength)<0) || ((length)<0) || ((maxlength)<(length))) \
301 { src+=length;maxlength-=length; } \
304 #define DLT_HEADER_SHOW_NONE 0x0000
305 #define DLT_HEADER_SHOW_TIME 0x0001
306 #define DLT_HEADER_SHOW_TMSTP 0x0002
307 #define DLT_HEADER_SHOW_MSGCNT 0x0004
308 #define DLT_HEADER_SHOW_ECUID 0x0008
309 #define DLT_HEADER_SHOW_APID 0x0010
310 #define DLT_HEADER_SHOW_CTID 0x0020
311 #define DLT_HEADER_SHOW_MSGTYPE 0x0040
312 #define DLT_HEADER_SHOW_MSGSUBTYPE 0x0080
313 #define DLT_HEADER_SHOW_VNVSTATUS 0x0100
314 #define DLT_HEADER_SHOW_NOARG 0x0200
315 #define DLT_HEADER_SHOW_ALL 0xFFFF
318 * The definition of the serial header containing the characters "DLS" + 0x01.
320 extern const char dltSerialHeader[DLT_ID_SIZE];
323 * The definition of the serial header containing the characters "DLS" + 0x01 as char.
325 extern char dltSerialHeaderChar[DLT_ID_SIZE];
329 * The type of a DLT ID (context id, application id, etc.)
331 typedef char ID4[DLT_ID_SIZE];
334 * The structure of the DLT file storage header. This header is used before each stored DLT message.
338 char pattern[DLT_ID_SIZE]; /**< This pattern should be DLT0x01 */
339 time_t seconds; /**< seconds since 1.1.1970 */
340 int32_t microseconds; /**< Microseconds */
341 char ecu[DLT_ID_SIZE]; /**< The ECU id is added, if it is not already in the DLT message itself */
342 } PACKED DltStorageHeader;
345 * The structure of the DLT standard header. This header is used in each DLT message.
349 uint8_t htyp; /**< This parameter contains several informations, see definitions below */
350 uint8_t mcnt; /**< The message counter is increased with each sent DLT message */
351 uint16_t len; /**< Length of the complete message, without storage header */
352 } PACKED DltStandardHeader;
355 * The structure of the DLT extra header parameters. Each parameter is sent only if enabled in htyp.
359 char ecu[DLT_ID_SIZE]; /**< ECU id */
360 uint32_t seid; /**< Session number */
361 uint32_t tmsp; /**< Timestamp since system start in 0.1 milliseconds */
362 } PACKED DltStandardHeaderExtra;
365 * The structure of the DLT extended header. This header is only sent if enabled in htyp parameter.
369 uint8_t msin; /**< messsage info */
370 uint8_t noar; /**< number of arguments */
371 char apid[DLT_ID_SIZE]; /**< application id */
372 char ctid[DLT_ID_SIZE]; /**< context id */
373 } PACKED DltExtendedHeader;
376 * The structure to organise the DLT messages.
377 * This structure is used by the corresponding functions.
379 typedef struct sDltMessage
382 int8_t found_serialheader;
385 int32_t resync_offset;
387 /* size parameters */
388 int32_t headersize; /**< size of complete header including storage header */
389 int32_t datasize; /**< size of complete payload */
391 /* buffer for current loaded message */
392 uint8_t headerbuffer[sizeof(DltStorageHeader)+
393 sizeof(DltStandardHeader)+sizeof(DltStandardHeaderExtra)+sizeof(DltExtendedHeader)]; /**< buffer for loading complete header */
394 uint8_t *databuffer; /**< buffer for loading payload */
396 /* header values of current loaded message */
397 DltStorageHeader *storageheader; /**< pointer to storage header of current loaded header */
398 DltStandardHeader *standardheader; /**< pointer to standard header of current loaded header */
399 DltStandardHeaderExtra headerextra; /**< extra parameters of current loaded header */
400 DltExtendedHeader *extendedheader; /**< pointer to extended of current loaded header */
404 * The structure of the DLT Service Get Log Info.
408 uint32_t service_id; /**< service ID */
409 uint8_t options; /**< type of request */
410 char apid[DLT_ID_SIZE]; /**< application id */
411 char ctid[DLT_ID_SIZE]; /**< context id */
412 char com[DLT_ID_SIZE]; /**< communication interface */
413 } PACKED DltServiceGetLogInfoRequest;
416 * The structure of the DLT Service Set Log Level.
420 uint32_t service_id; /**< service ID */
421 char apid[DLT_ID_SIZE]; /**< application id */
422 char ctid[DLT_ID_SIZE]; /**< context id */
423 uint8_t log_level; /**< log level to be set */
424 char com[DLT_ID_SIZE]; /**< communication interface */
425 } PACKED DltServiceSetLogLevel;
428 * The structure of the DLT Service Set Default Log Level.
432 uint32_t service_id; /**< service ID */
433 uint8_t log_level; /**< default log level to be set */
434 char com[DLT_ID_SIZE]; /**< communication interface */
435 } PACKED DltServiceSetDefaultLogLevel;
438 * The structure of the DLT Service Set Verbose Mode
442 uint32_t service_id; /**< service ID */
443 uint8_t new_status; /**< new status to be set */
444 } PACKED DltServiceSetVerboseMode;
447 * The structure of the DLT Service Set Communication Interface Status
451 uint32_t service_id; /**< service ID */
452 char com[DLT_ID_SIZE]; /**< communication interface */
453 uint8_t new_status; /**< new status to be set */
454 } PACKED DltServiceSetCommunicationInterfaceStatus;
457 * The structure of the DLT Service Set Communication Maximum Bandwidth
461 uint32_t service_id; /**< service ID */
462 char com[DLT_ID_SIZE]; /**< communication interface */
463 uint32_t max_bandwidth; /**< maximum bandwith */
464 } PACKED DltServiceSetCommunicationMaximumBandwidth;
468 uint32_t service_id; /**< service ID */
469 uint8_t status; /**< reponse status */
470 } PACKED DltServiceResponse;
474 uint32_t service_id; /**< service ID */
475 uint8_t status; /**< reponse status */
476 uint8_t log_level; /**< log level */
477 } PACKED DltServiceGetDefaultLogLevelResponse;
481 uint32_t service_id; /**< service ID */
482 uint8_t status; /**< reponse status */
483 uint8_t overflow; /**< overflow status */
484 } PACKED DltServiceMessageBufferOverflowResponse;
488 uint32_t service_id; /**< service ID */
489 uint8_t status; /**< reponse status */
490 uint32_t length; /**< length of following payload */
491 /* char [] payload */
492 } PACKED DltServiceGetSoftwareVersionResponse;
495 * Structure to store filter parameters.
496 * ID are maximal four characters. Unused values are filled with zeros.
497 * If every value as filter is valid, the id should be empty by having only zero values.
501 char apid[DLT_FILTER_MAX][DLT_ID_SIZE]; /**< application id */
502 char ctid[DLT_FILTER_MAX][DLT_ID_SIZE]; /**< context id */
503 int counter; /**< number of filters */
507 * The structure to organise the access to DLT files.
508 * This structure is used by the corresponding functions.
510 typedef struct sDltFile
512 /* file handle and index for fast access */
513 FILE *handle; /**< file handle of opened DLT file */
514 long *index; /**< file positions of all DLT messages for fast access to file, only filtered messages */
516 /* size parameters */
517 int32_t counter; /**< number of messages in DLT file with filter */
518 int32_t counter_total; /**< number of messages in DLT file without filter */
519 int32_t position; /**< current index to message parsed in DLT file starting at 0 */
520 long file_length; /**< length of the file */
521 long file_position; /**< current position in the file */
524 int32_t error_messages; /**< number of incomplete DLT messages found during file parsing */
526 /* filter parameters */
527 DltFilter *filter; /**< pointer to filter list. Zero if no filter is set. */
528 int32_t filter_counter; /**< number of filter set */
530 /* current loaded message */
531 DltMessage msg; /**< pointer to message */
536 * The structure is used to organise the receiving of data
537 * including buffer handling.
538 * This structure is used by the corresponding functions.
542 int32_t lastBytesRcvd; /**< bytes received in last receive call */
543 int32_t bytesRcvd; /**< received bytes */
544 int32_t totalBytesRcvd; /**< total number of received bytes */
545 char *buffer; /**< pointer to receiver buffer */
546 char *buf; /**< pointer to position within receiver buffer */
547 int fd; /**< connection handle */
548 int32_t buffersize; /**< size of receiver buffer */
553 char* buffer; /**< Ptr. to buffer */
554 uint32_t size; /**< Maximum size of buffer */
555 uint32_t pos_write; /**< current writing position in bytes*/
556 uint32_t pos_read; /**< current reading position in bytes*/
557 uint32_t count; /**< nr. of entries */
558 uint32_t minimum_size; /**< minimum value for the buffer */
559 uint32_t increasing_size; /**< increasing value for the buffer */
560 uint32_t maximum_size; /**< maximum value for the buffer*/
570 * Helper function to print a byte array in hex.
571 * @param ptr pointer to the byte array.
572 * @param size number of bytes to be printed.
574 void dlt_print_hex(uint8_t *ptr,int size);
576 * Helper function to print a byte array in hex into a string.
577 * @param text pointer to a ASCII string, in which the text is written
578 * @param textlength maximal size of text buffer
579 * @param ptr pointer to the byte array.
580 * @param size number of bytes to be printed.
581 * @return negative value if there was an error
583 int dlt_print_hex_string(char *text,int textlength,uint8_t *ptr,int size);
585 * Helper function to print a byte array in hex and ascii into a string.
586 * @param text pointer to a ASCII string, in which the text is written
587 * @param textlength maximal size of text buffer
588 * @param ptr pointer to the byte array.
589 * @param size number of bytes to be printed.
590 * @param html output is html? 0 - false, 1 - true
591 * @return negative value if there was an error
593 int dlt_print_mixed_string(char *text,int textlength,uint8_t *ptr,int size,int html);
595 * Helper function to print a byte array in ascii into a string.
596 * @param text pointer to a ASCII string, in which the text is written
597 * @param textlength maximal size of text buffer
598 * @param ptr pointer to the byte array.
599 * @param size number of bytes to be printed.
600 * @return negative value if there was an error
602 int dlt_print_char_string(char **text,int textlength,uint8_t *ptr,int size);
605 * Helper function to print an id.
606 * @param text pointer to ASCII string where to write the id
607 * @param id four byte char array as used in DLT mesages as IDs.
609 void dlt_print_id(char *text,const char *id);
612 * Helper function to set an ID parameter.
613 * @param id four byte char array as used in DLT mesages as IDs.
614 * @param text string to be copied into char array.
616 void dlt_set_id(char *id,const char *text);
619 * Helper function to remove not nice to print characters, e.g. NULL or carage return.
620 * @param text pointer to string to be cleaned.
621 * @param length length of string excluding terminating zero.
623 void dlt_clean_string(char *text,int length);
626 * Initialise the filter list.
627 * This function must be called before using further dlt filter.
628 * @param filter pointer to structure of organising DLT filter
629 * @param verbose if set to true verbose information is printed out.
630 * @return negative value if there was an error
632 int dlt_filter_init(DltFilter *filter,int verbose);
634 * Free the used memory by the organising structure of filter.
635 * @param filter pointer to structure of organising DLT filter
636 * @param verbose if set to true verbose information is printed out.
637 * @return negative value if there was an error
639 int dlt_filter_free(DltFilter *filter,int verbose);
641 * Load filter list from file.
642 * @param filter pointer to structure of organising DLT filter
643 * @param filename filename to load filters from
644 * @param verbose if set to true verbose information is printed out.
645 * @return negative value if there was an error
647 int dlt_filter_load(DltFilter *filter,const char *filename,int verbose);
649 * Save filter list to file.
650 * @param filter pointer to structure of organising DLT filter
651 * @param filename filename to load filters from
652 * @param verbose if set to true verbose information is printed out.
653 * @return negative value if there was an error
655 int dlt_filter_save(DltFilter *filter,const char *filename,int verbose);
657 * Find index of filter in filter list
658 * @param filter pointer to structure of organising DLT filter
659 * @param apid application id to be found in filter list
660 * @param ctid context id to be found in filter list
661 * @param verbose if set to true verbose information is printed out.
662 * @return negative value if there was an error (or not found), else return index of filter
664 int dlt_filter_find(DltFilter *filter,const char *apid,const char *ctid, int verbose);
666 * Add new filter to filter list.
667 * @param filter pointer to structure of organising DLT filter
668 * @param apid application id to be added to filter list (must always be set).
669 * @param ctid context id to be added to filter list. empty equals don't care.
670 * @param verbose if set to true verbose information is printed out.
671 * @return negative value if there was an error
673 int dlt_filter_add(DltFilter *filter,const char *apid,const char *ctid,int verbose);
675 * Delete filter from filter list
676 * @param filter pointer to structure of organising DLT filter
677 * @param apid application id to be deleted from filter list
678 * @param ctid context id to be deleted from filter list
679 * @param verbose if set to true verbose information is printed out.
680 * @return negative value if there was an error
682 int dlt_filter_delete(DltFilter *filter,const char *apid,const char *ctid,int verbose);
685 * Initialise the structure used to access a DLT message.
686 * This function must be called before using further dlt_message functions.
687 * @param msg pointer to structure of organising access to DLT messages
688 * @param verbose if set to true verbose information is printed out.
689 * @return negative value if there was an error
691 int dlt_message_init(DltMessage *msg,int verbose);
693 * Free the used memory by the organising structure of file.
694 * @param msg pointer to structure of organising access to DLT messages
695 * @param verbose if set to true verbose information is printed out.
696 * @return negative value if there was an error
698 int dlt_message_free(DltMessage *msg,int verbose);
700 * Print Header into an ASCII string.
701 * This function calls dlt_message_header_flags() with flags=DLT_HEADER_SHOW_ALL
702 * @param msg pointer to structure of organising access to DLT messages
703 * @param text pointer to a ASCII string, in which the header is written
704 * @param textlength maximal size of text buffer
705 * @param verbose if set to true verbose information is printed out.
706 * @return negative value if there was an error
708 int dlt_message_header(DltMessage *msg,char *text,int textlength,int verbose);
710 * Print Header into an ASCII string, selective.
711 * @param msg pointer to structure of organising access to DLT messages
712 * @param text pointer to a ASCII string, in which the header is written
713 * @param textlength maximal size of text buffer
714 * @param flags select, bit-field to select, what should be printed (DLT_HEADER_SHOW_...)
715 * @param verbose if set to true verbose information is printed out.
716 * @return negative value if there was an error
718 int dlt_message_header_flags(DltMessage *msg,char *text,int textlength,int flags, int verbose);
720 * Print Payload into an ASCII string.
721 * @param msg pointer to structure of organising access to DLT messages
722 * @param text pointer to a ASCII string, in which the header is written
723 * @param textlength maximal size of text buffer
724 * @param type 1 = payload as hex, 2 = payload as ASCII.
725 * @param verbose if set to true verbose information is printed out.
726 * @return negative value if there was an error
728 int dlt_message_payload(DltMessage *msg,char *text,int textlength,int type,int verbose);
730 * Check if message is filtered or not. All filters are applied (logical OR).
731 * @param msg pointer to structure of organising access to DLT messages
732 * @param filter pointer to filter
733 * @param verbose if set to true verbose information is printed out.
734 * @return 1 = filter matches, 0 = filter does not match, negative value if there was an error
736 int dlt_message_filter_check(DltMessage *msg,DltFilter *filter,int verbose);
739 * Read message from memory buffer.
740 * Message in buffer has no storage header.
741 * @param msg pointer to structure of organising access to DLT messages
742 * @param buffer pointer to memory buffer
743 * @param length length of message in buffer
744 * @param resync if set to true resync to serial header is enforced
745 * @param verbose if set to true verbose information is printed out.
746 * @return negative value if there was an error
748 int dlt_message_read(DltMessage *msg,uint8_t *buffer,unsigned int length,int resync,int verbose);
751 * Get standard header extra parameters
752 * @param msg pointer to structure of organising access to DLT messages
753 * @param verbose if set to true verbose information is printed out.
754 * @return negative value if there was an error
756 int dlt_message_get_extraparameters(DltMessage *msg,int verbose);
759 * Set standard header extra parameters
760 * @param msg pointer to structure of organising access to DLT messages
761 * @param verbose if set to true verbose information is printed out.
762 * @return negative value if there was an error
764 int dlt_message_set_extraparameters(DltMessage *msg,int verbose);
767 * Initialise the structure used to access a DLT file.
768 * This function must be called before using further dlt_file functions.
769 * @param file pointer to structure of organising access to DLT file
770 * @param verbose if set to true verbose information is printed out.
771 * @return negative value if there was an error
773 int dlt_file_init(DltFile *file,int verbose);
775 * Set a list to filters.
776 * This function should be called before loading a DLT file, if filters should be used.
777 * A filter list is an array of filters. Several filters are combined logically by or operation.
778 * The filter list is not copied, so take care to keep list in memory.
779 * @param file pointer to structure of organising access to DLT file
780 * @param filter pointer to filter list array
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_set_filter(DltFile *file,DltFilter *filter,int verbose);
786 * Initialising loading a DLT file.
787 * @param file pointer to structure of organising access to DLT file
788 * @param filename filename of DLT file
789 * @param verbose if set to true verbose information is printed out.
790 * @return negative value if there was an error
792 int dlt_file_open(DltFile *file,const char *filename,int verbose);
794 * Find next message in the DLT file and parse them.
795 * This function finds the next message in the DLT file.
796 * If a filter is set, the filter list is used.
797 * @param file pointer to structure of organising access to DLT file
798 * @param verbose if set to true verbose information is printed out.
799 * @return 0 = message does not match filter, 1 = message was read, negative value if there was an error
801 int dlt_file_read(DltFile *file,int verbose);
803 * Find next message in the DLT file in RAW format (without storage header) and parse them.
804 * This function finds the next message in the DLT file.
805 * If a filter is set, the filter list is used.
806 * @param file pointer to structure of organising access to DLT file
807 * @param resync Resync to serial header when set to true
808 * @param verbose if set to true verbose information is printed out.
809 * @return 0 = message does not match filter, 1 = message was read, negative value if there was an error
811 int dlt_file_read_raw(DltFile *file,int resync,int verbose);
813 * Closing loading a DLT file.
814 * @param file pointer to structure of organising access to DLT file
815 * @param verbose if set to true verbose information is printed out.
816 * @return negative value if there was an error
818 int dlt_file_close(DltFile *file,int verbose);
820 * Load standard header of a message from file
821 * @param file pointer to structure of organising access to DLT file
822 * @param verbose if set to true verbose information is printed out.
823 * @return negative value if there was an error
825 int dlt_file_read_header(DltFile *file,int verbose);
827 * Load standard header of a message from file in RAW format (without storage header)
828 * @param file pointer to structure of organising access to DLT file
829 * @param resync Resync to serial header when set to true
830 * @param verbose if set to true verbose information is printed out.
831 * @return negative value if there was an error
833 int dlt_file_read_header_raw(DltFile *file,int resync,int verbose);
835 * Load, if available in message, extra standard header fields and
836 * extended header of a message from file
837 * (dlt_file_read_header() must have been called before this call!)
838 * @param file pointer to structure of organising access to DLT file
839 * @param verbose if set to true verbose information is printed out.
840 * @return negative value if there was an error
842 int dlt_file_read_header_extended(DltFile *file, int verbose);
844 * Load payload of a message from file
845 * (dlt_file_read_header() must have been called before this call!)
846 * @param file pointer to structure of organising access to DLT file
847 * @param verbose if set to true verbose information is printed out.
848 * @return negative value if there was an error
850 int dlt_file_read_data(DltFile *file, int verbose);
852 * Load headers and payload of a message selected by the index.
853 * If filters are set, index is based on the filtered list.
854 * @param file pointer to structure of organising access to DLT file
855 * @param index position of message in the files beginning from zero
856 * @param verbose if set to true verbose information is printed out.
857 * @return number of messages loaded, negative value if there was an error
859 int dlt_file_message(DltFile *file,int index,int verbose);
861 * Free the used memory by the organising structure of file.
862 * @param file pointer to structure of organising access to DLT file
863 * @param verbose if set to true verbose information is printed out.
864 * @return negative value if there was an error
866 int dlt_file_free(DltFile *file,int verbose);
869 * Initialize (external) logging facility
870 * @param mode positive, if syslog should be used; zero for console output
872 void dlt_log_init(int mode);
874 * Log ASCII string with null-termination to (external) logging facility
875 * @param prio priority (see syslog() call)
876 * @param s Pointer to ASCII string with null-termination
877 * @return negative value if there was an error
879 int dlt_log(int prio, char *s);
881 * De-Initialize (external) logging facility
883 void dlt_log_free(void);
886 * Initialising a dlt receiver structure
887 * @param receiver pointer to dlt receiver structure
888 * @param _fd handle to file/socket/fifo, fram which the data should be received
889 * @param _buffersize size of data buffer for storing the received data
890 * @return negative value if there was an error
892 int dlt_receiver_init(DltReceiver *receiver,int _fd, int _buffersize);
894 * De-Initialize a dlt receiver structure
895 * @param receiver pointer to dlt receiver structure
896 * @return negative value if there was an error
898 int dlt_receiver_free(DltReceiver *receiver);
900 * Receive data from socket using the dlt receiver structure
901 * @param receiver pointer to dlt receiver structure
902 * @return negative value if there was an error
904 int dlt_receiver_receive_socket(DltReceiver *receiver);
906 * Receive data from file/fifo using the dlt receiver structure
907 * @param receiver pointer to dlt receiver structure
908 * @return negative value if there was an error
910 int dlt_receiver_receive_fd(DltReceiver *receiver);
912 * Remove a specific size of bytes from the received data
913 * @param receiver pointer to dlt receiver structure
914 * @param size amount of bytes to be removed
915 * @return negative value if there was an error
917 int dlt_receiver_remove(DltReceiver *receiver,int size);
919 * Move data from last receive call to front of receive buffer
920 * @param receiver pointer to dlt receiver structure
921 * @return negative value if there was an error
923 int dlt_receiver_move_to_begin(DltReceiver *receiver);
926 * Fill out storage header of a dlt message
927 * @param storageheader pointer to storage header of a dlt message
928 * @param ecu name of ecu to be set in storage header
929 * @return negative value if there was an error
931 int dlt_set_storageheader(DltStorageHeader *storageheader, const char *ecu);
933 * Check if a storage header contains its marker
934 * @param storageheader pointer to storage header of a dlt message
935 * @return 0 no, 1 yes, negative value if there was an error
937 int dlt_check_storageheader(DltStorageHeader *storageheader);
940 * Initialize ringbuffer of with a maximum size of size
941 * @param dltbuf Pointer to ringbuffer structure
942 * @param size Maximum size of buffer in bytes
943 * @return negative value if there was an error
945 int dlt_ringbuffer_init(DltRingBuffer *dltbuf, uint32_t size, uint32_t increase_size, uint32_t max_size);
948 * Release and free memory used by ringbuffer
949 * @param dltbuf Pointer to ringbuffer structure
950 * @return negative value if there was an error
952 int dlt_ringbuffer_free(DltRingBuffer *dltbuf);
955 * Write one entry to ringbuffer
956 * @param dltbuf Pointer to ringbuffer structure
957 * @param data Pointer to data to be written to ringbuffer
958 * @param size Size of data in bytes to be written to ringbuffer
959 * @return negative value if there was an error
961 int dlt_ringbuffer_put(DltRingBuffer *dltbuf, void *data, uint32_t size);
964 * Write one entry given as 3 chunks to ringbuffer
965 * @param dltbuf Pointer to ringbuffer structure
966 * @param data1 Pointer to data1 to be written to ringbuffer
967 * @param size1 Size of data1 in bytes to be written to ringbuffer
968 * @param data2 Pointer to data2 to be written to ringbuffer
969 * @param size2 Size of data2 in bytes to be written to ringbuffer
970 * @param data3 Pointer to data3 to be written to ringbuffer
971 * @param size3 Size of data3 in bytes to be written to ringbuffer
972 * @return negative value if there was an error
974 int dlt_ringbuffer_put3(DltRingBuffer *dltbuf, void *data1, uint32_t size1, void *data2, uint32_t size2, void *data3, uint32_t size3);
977 * This method writes the size of message
978 * @param dltbuf Pointer to ringbuffer structure
979 * @param data_size Pointer to size of data to be written
980 * @param unit_size Size of uint32_t
982 void dlt_ringbuffer_putMessageSize(DltRingBuffer *dltbuf,uint32_t * data_size, uint32_t unit_size);
985 * This method reads the size of a message
986 * @param dltbuf Pointer to ringbuffer structure
987 * @param unit_size Size of uint32_t
988 * @return size of the message
990 int dlt_ringbuffer_getMessageSize(DltRingBuffer *dltbuf, uint32_t unit_size);
992 * Read one entry from ringbuffer
993 * @param dltbuf Pointer to ringbuffer structure
994 * @param data Pointer to data read from ringbuffer
995 * @param size Size of read data in bytes from ringbuffer
996 * @return negative value if there was an error
998 int dlt_ringbuffer_get(DltRingBuffer *dltbuf, void *data, size_t *size);
1001 * Helper function: Skip one readable entry in ringbuffer
1002 * @param dltbuf Pointer to ringbuffer structure
1003 * @return negative value if there was an error
1005 int dlt_ringbuffer_get_skip(DltRingBuffer *dltbuf);
1008 * Helper function: Get free space in bytes for writting between write and read position
1009 * @param dltbuf Pointer to ringbuffer structure
1010 * @param freespace Free Space in bytes for writting is returned
1011 * @return negative value if there was an error
1013 int dlt_ringbuffer_freespacewrite(DltRingBuffer *dltbuf, uint32_t *freespace);
1016 * Helper function: Check free space and if necessary discard entries, so that at least
1017 * reqspace bytes are available for writting
1018 * @param dltbuf Pointer to ringbuffer structure
1019 * @param reqspace Requested space for writting in bytes
1020 * @return negative value if there was an error
1022 int dlt_ringbuffer_checkandfreespace(DltRingBuffer *dltbuf, uint32_t reqspace);
1024 #if !defined (__WIN32__)
1027 * Helper function: Setup serial connection
1028 * @param fd File descriptor of serial tty device
1029 * @param speed Serial line speed, as defined in termios.h
1030 * @return negative value if there was an error
1032 int dlt_setup_serial(int fd, speed_t speed);
1035 * Helper function: Convert serial line baudrate (as number) to line speed (as defined in termios.h)
1036 * @param baudrate Serial line baudrate (as number)
1037 * @return Serial line speed, as defined in termios.h
1039 speed_t dlt_convert_serial_speed(int baudrate);
1042 * Print dlt version and dlt svn version to buffer
1043 * @param buf Pointer to buffer
1045 void dlt_get_version(char *buf);
1049 /* Function prototypes which should be used only internally */
1053 * Common part of initialisation
1054 * @return negative value if there was an error
1056 int dlt_init_common(void);
1059 * Return the uptime of the system in 0.1 ms resolution
1060 * @return 0 if there was an error
1062 uint32_t dlt_uptime(void);
1065 * Print header of a DLT message
1066 * @param message pointer to structure of organising access to DLT messages
1067 * @param text pointer to a ASCII string, in which the header is written
1068 * @param size maximal size of text buffer
1069 * @param verbose if set to true verbose information is printed out.
1070 * @return negative value if there was an error
1072 int dlt_message_print_header(DltMessage *message, char *text, uint32_t size, int verbose);
1075 * Print payload of a DLT message as Hex-Output
1076 * @param message pointer to structure of organising access to DLT messages
1077 * @param text pointer to a ASCII string, in which the output is written
1078 * @param size maximal size of text buffer
1079 * @param verbose if set to true verbose information is printed out.
1080 * @return negative value if there was an error
1082 int dlt_message_print_hex(DltMessage *message, char *text, uint32_t size, int verbose);
1085 * Print payload of a DLT message as ASCII-Output
1086 * @param message pointer to structure of organising access to DLT messages
1087 * @param text pointer to a ASCII string, in which the output is written
1088 * @param size maximal size of text buffer
1089 * @param verbose if set to true verbose information is printed out.
1090 * @return negative value if there was an error
1092 int dlt_message_print_ascii(DltMessage *message, char *text, uint32_t size, int verbose);
1095 * Print payload of a DLT message as Mixed-Ouput (Hex and ASCII), for plain text output
1096 * @param message pointer to structure of organising access to DLT messages
1097 * @param text pointer to a ASCII string, in which the output is written
1098 * @param size maximal size of text buffer
1099 * @param verbose if set to true verbose information is printed out.
1100 * @return negative value if there was an error
1102 int dlt_message_print_mixed_plain(DltMessage *message, char *text, uint32_t size, int verbose);
1105 * Print payload of a DLT message as Mixed-Ouput (Hex and ASCII), for HTML text output
1106 * @param message pointer to structure of organising access to DLT messages
1107 * @param text pointer to a ASCII string, in which the output is written
1108 * @param size maximal size of text buffer
1109 * @param verbose if set to true verbose information is printed out.
1110 * @return negative value if there was an error
1112 int dlt_message_print_mixed_html(DltMessage *message, char *text, uint32_t size, int verbose);
1115 * Decode and print a argument of a DLT message
1116 * @param msg pointer to structure of organising access to DLT messages
1117 * @param type_info Type of argument
1118 * @param ptr pointer to pointer to data (pointer to data is changed within this function)
1119 * @param datalength pointer to datalength (datalength is changed within this function)
1120 * @param text pointer to a ASCII string, in which the output is written
1121 * @param textlength maximal size of text buffer
1122 * @param byteLength If argument is a string, and this value is 0 or greater, this value will be taken as string length
1123 * @param verbose if set to true verbose information is printed out.
1124 * @return negative value if there was an error
1126 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);
1136 #endif /* DLT_COMMON_H */