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-example-user.c **
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) $
83 #include <stdio.h> /* for printf() and fprintf() */
84 #include <stdlib.h> /* for atoi() and exit() */
85 #include <string.h> /* for memset() */
86 #include <unistd.h> /* for close() */
89 #include "dlt_common.h" /* for dlt_get_version() */
91 int dlt_user_injection_callback(uint32_t service_id, void *data, uint32_t length);
93 DLT_DECLARE_CONTEXT(mycontext);
96 * Print usage information of tool.
102 dlt_get_version(version);
104 printf("Usage: dlt-example-user [options] message\n");
105 printf("Generate DLT messages and store them to file or send them to daemon.\n");
106 printf("%s \n", version);
107 printf("Options:\n");
108 printf(" -v Verbose mode\n");
109 printf(" -d delay Milliseconds to wait between sending messages (Default: 500)\n");
110 printf(" -f filename Use local log file instead of sending to daemon\n");
111 printf(" -n count Number of messages to be generated (Default: 10)\n");
112 printf(" -g Switch to non-verbose mode (Default: verbose mode)\n");
113 printf(" -a Enable local printing of DLT messages (Default: disabled)\n");
114 printf(" -m mode Set log mode 0=off,1=external,2=internal,3=both\n");
115 #ifdef DLT_TEST_ENABLE
116 printf(" -c Corrupt user header\n");
117 printf(" -s size Corrupt message size\n");
118 printf(" -z size Size of message\n");
119 #endif /* DLT_TEST_ENABLE */
123 * Main function of tool.
125 int main(int argc, char* argv[])
130 #ifdef DLT_TEST_ENABLE
134 #endif /* DLT_TEST_ENABLE */
148 int state=-1,newstate;
151 #ifdef DLT_TEST_ENABLE
152 while ((c = getopt (argc, argv, "vgacd:f:n:m:z:s:")) != -1)
154 while ((c = getopt (argc, argv, "vgad:f:n:m:")) != -1)
155 #endif /* DLT_TEST_ENABLE */
174 #ifdef DLT_TEST_ENABLE
190 #endif /* DLT_TEST_ENABLE */
213 if (optopt == 'd' || optopt == 'f' || optopt == 'n')
215 fprintf (stderr, "Option -%c requires an argument.\n", optopt);
217 else if (isprint (optopt))
219 fprintf (stderr, "Unknown option `-%c'.\n", optopt);
223 fprintf (stderr, "Unknown option character `\\x%x'.\n",optopt);
226 /* unknown or wrong option used, show usage information and terminate */
237 for (index = optind; index < argc; index++)
239 message = argv[index];
244 /* no message, show usage and terminate */
245 fprintf(stderr,"ERROR: No message selected\n");
252 /* DLT is intialised automatically, except another output target will be used */
253 if (dlt_init_file(fvalue)<0) /* log to file */
259 DLT_REGISTER_APP("LOG","Test Application for Logging");
260 DLT_REGISTER_CONTEXT(mycontext,"TEST","Test Context for Logging");
262 DLT_REGISTER_INJECTION_CALLBACK(mycontext, 0xFFF, dlt_user_injection_callback);
268 printf("Set log mode to %d\n",atoi(mvalue));
269 dlt_set_log_mode(atoi(mvalue));
275 DLT_NONVERBOSE_MODE();
280 DLT_ENABLE_LOCAL_PRINT();
285 maxnum = atoi(nvalue);
294 delay = atoi(dvalue) * 1000;
303 /* DLT messages to test Fibex non-verbose description: dlt-example-non-verbose.xml */
304 DLT_LOG_ID(mycontext,DLT_LOG_INFO,10);
305 DLT_LOG_ID(mycontext,DLT_LOG_INFO,11,DLT_UINT16(1011));
306 DLT_LOG_ID(mycontext,DLT_LOG_INFO,12,DLT_UINT32(1012),DLT_UINT32(1013));
307 DLT_LOG_ID(mycontext,DLT_LOG_INFO,13,DLT_UINT8(123),DLT_FLOAT32(1.12));
308 DLT_LOG_ID(mycontext,DLT_LOG_INFO,14,DLT_STRING("DEAD BEEF"));
311 #ifdef DLT_TEST_ENABLE
314 dlt_user_test_corrupt_user_header(1);
318 dlt_user_test_corrupt_message_size(1,atoi(svalue));
322 char* buffer = malloc(atoi(zvalue));
323 DLT_LOG(mycontext,DLT_LOG_WARN,DLT_STRING(text),DLT_RAW(buffer,atoi(zvalue)));
326 #endif /* DLT_TEST_ENABLE */
328 for (num=0;num<maxnum;num++)
330 printf("Send %d %s\n",num,text);
332 newstate = dlt_get_log_state();
337 printf("Client unknown state!\n");
339 else if(state == 0) {
340 printf("Client disconnected!\n");
342 else if(state == 1) {
343 printf("Client connected!\n");
349 /* Non-verbose mode */
350 DLT_LOG_ID(mycontext,DLT_LOG_WARN,num,DLT_INT(num),DLT_STRING(text));
355 DLT_LOG(mycontext,DLT_LOG_WARN,DLT_INT(num),DLT_STRING(text));
366 DLT_UNREGISTER_CONTEXT(mycontext);
368 DLT_UNREGISTER_APP();
376 int dlt_user_injection_callback(uint32_t service_id, void *data, uint32_t length)
380 printf("Injection %d, Length=%d \n",service_id,length);
383 dlt_print_mixed_string(text,1024,data,length,0);
384 printf("%s \n", text);