2 * Dlt Client console utilities - 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-convert.cpp **
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 /*******************************************************************************
72 ********************************************************************************
74 ** Initials Name Company **
75 ** -------- ------------------------- ---------------------------------- **
76 ** aw Alexander Wenzel BMW **
77 *******************************************************************************/
79 /*******************************************************************************
80 ** Revision Control History **
81 *******************************************************************************/
84 * $LastChangedRevision: 1670 $
85 * $LastChangedDate: 2011-04-08 15:12:06 +0200 (Fr, 08. Apr 2011) $
99 #include <sys/uio.h> /* writev() */
101 #include "dlt_common.h"
103 #define DLT_CONVERT_TEXTBUFSIZE 10024 /* Size of buffer for text output */
106 * Print usage information of tool.
110 char version[DLT_CONVERT_TEXTBUFSIZE];
112 dlt_get_version(version);
114 printf("Usage: dlt-convert [options] [commands] file1 [file2]\n");
115 printf("Read DLT files, print DLT messages as ASCII and store the messages again.\n");
116 printf("Use filters to filter DLT messages.\n");
117 printf("Use Ranges and Output file to cut DLT files.\n");
118 printf("Use two files and Output file to join DLT files.\n");
119 printf("%s \n", version);
120 printf("Commands:\n");
121 printf(" -h Usage\n");
122 printf(" -a Print DLT file; payload as ASCII\n");
123 printf(" -x Print DLT file; payload as hex\n");
124 printf(" -m Print DLT file; payload as hex and ASCII\n");
125 printf(" -s Print DLT file; only headers\n");
126 printf(" -o filename Output messages in new DLT file\n");
127 printf("Options:\n");
128 printf(" -v Verbose mode\n");
129 printf(" -c Count number of messages\n");
130 printf(" -f filename Enable filtering of messages\n");
131 printf(" -b number First messages to be handled\n");
132 printf(" -e number Last message to be handled\n");
133 printf(" -w Follow dlt file while file is increasing\n");
137 * Main function of tool.
139 int main(int argc, char* argv[])
163 char text[DLT_CONVERT_TEXTBUFSIZE];
170 while ((c = getopt (argc, argv, "vcashxmwf:b:e:o:")) != -1)
235 if (optopt == 'f' || optopt == 'b' || optopt == 'e' || optopt == 'o')
237 fprintf (stderr, "Option -%c requires an argument.\n", optopt);
239 else if (isprint (optopt))
241 fprintf (stderr, "Unknown option `-%c'.\n", optopt);
245 fprintf (stderr, "Unknown option character `\\x%x'.\n",optopt);
247 /* unknown or wrong option used, show usage information and terminate */
257 /* initialise structure to use DLT file */
258 dlt_file_init(&file,vflag);
260 /* first parse filter file if filter parameter is used */
263 if (dlt_filter_load(&filter,fvalue,vflag)<0)
265 dlt_file_free(&file,vflag);
269 dlt_file_set_filter(&file,&filter,vflag);
274 ohandle = open(ovalue,O_WRONLY|O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); /* mode: wb */
277 dlt_file_free(&file,vflag);
278 fprintf(stderr,"ERROR: Output file %s cannot be opened!\n",ovalue);
284 for (index = optind; index < argc; index++)
286 /* load, analyse data file and create index list */
287 if (dlt_file_open(&file,argv[index],vflag)>=0)
289 while (dlt_file_read(&file,vflag)>=0)
294 if (aflag || sflag || xflag || mflag || ovalue)
298 begin = atoi(bvalue);
305 if (evalue && (wflag==0))
311 end = file.counter-1;
314 if (begin<0 || begin>=file.counter)
316 fprintf(stderr,"ERROR: Selected first message %d is out of range!\n",begin);
319 if (end<0 || end>=file.counter || end<begin)
321 fprintf(stderr,"ERROR: Selected end message %d is out of range!\n",end);
324 for (num = begin; num <= end ;num++)
326 dlt_file_message(&file,num,vflag);
331 dlt_message_print_hex(&(file.msg),text,DLT_CONVERT_TEXTBUFSIZE,vflag);
337 dlt_message_header(&(file.msg),text,DLT_CONVERT_TEXTBUFSIZE,vflag);
341 dlt_message_payload(&file.msg,text,DLT_CONVERT_TEXTBUFSIZE,DLT_OUTPUT_ASCII,vflag);
343 printf("[%s]\n",text);
348 dlt_message_print_mixed_plain(&(file.msg),text,DLT_CONVERT_TEXTBUFSIZE,vflag);
354 dlt_message_header(&(file.msg),text,DLT_CONVERT_TEXTBUFSIZE,vflag);
356 printf("%s \n",text);
359 /* if file output enabled write message */
362 iov[0].iov_base = file.msg.headerbuffer;
363 iov[0].iov_len = file.msg.headersize;
364 iov[1].iov_base = file.msg.databuffer;
365 iov[1].iov_len = file.msg.datasize;
367 bytes_written = writev(ohandle, iov, 2);
370 /* check for new messages if follow flag set */
371 if (wflag && num==end)
375 while (dlt_file_read(&file,0)>=0)
378 if (end == (file.counter-1))
380 /* Sleep if no new message was received */
385 /* set new end of log file and continue reading */
386 end = file.counter-1;
395 printf("Total number of messages: %d\n",file.counter_total);
398 printf("Filtered number of messages: %d\n",file.counter);
408 /* no file selected, show usage and terminate */
409 fprintf(stderr,"ERROR: No file selected\n");
414 dlt_file_free(&file,vflag);