2 * Dlt Test Client - 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-test-client.c **
47 ** AUTHOR : Alexander Wenzel Alexander.AW.Wenzel@bmw.de **
53 ** PLATFORM DEPENDANT [yes/no]: yes **
55 ** TO BE CHANGED BY USER [yes/no]: no **
57 *******************************************************************************/
59 /*******************************************************************************
61 ********************************************************************************
63 ** Initials Name Company **
64 ** -------- ------------------------- ---------------------------------- **
65 ** aw Alexander Wenzel BMW **
66 *******************************************************************************/
73 #include <dlt_filetransfer.h> /*Needed for transferring files with the dlt protocol*/
74 #include <dlt.h> /*Needed for dlt logging*/
77 #define MAXSTRLEN 1024
79 #define FLTR_APP_DESC "Filetransfer application"
80 #define FLTR_CONTEXT_DESC "Filetransfer context"
82 #define FLTR_APP "FLTR"
83 #define FLTR_CONTEXT "FLTR"
87 //!Declare some context for the file transfer. It's not a must have to do this, but later you can set a filter on this context in the dlt viewer.
88 DLT_DECLARE_CONTEXT(fileContext);
92 * Print usage information of tool.
98 dlt_get_version(version);
100 printf("Usage: dlt-example-filetransfer [options] <command>\n");
101 printf("Filetransfer example");
102 printf("%s \n", version);
103 printf("Command:\n");
104 printf("-f file - File to transfer (absolute path)\n");
105 printf("Options:\n");
106 printf("-a apid - Set application id to apid (default: FLTR)\n");
107 printf("-c ctid - Set context id to ctid (default: FLTR)\n");
108 printf("-t ms - Timeout between file packages in ms (minimum 1 ms)\n");
109 printf("-d - Flag to delete the file after the transfer (default: false)\n");
110 printf("-i - Flag to log file infos to DLT before transfer file (default: false)\n");
111 printf("-h - This help\n");
116 //!Main program dlt-test-filestransfer starts here
117 int main(int argc, char* argv[])
119 //char str[MAXSTRLEN];
120 int opt, timeout, dltResult;;
122 char apid[DLT_ID_SIZE];
123 char ctid[DLT_ID_SIZE];
132 dlt_set_id(apid, FLTR_APP);
133 dlt_set_id(ctid, FLTR_CONTEXT);
135 while ((opt = getopt(argc, argv, "idf:t:a:c:h")) != -1)
161 dlt_set_id(apid,optarg);
166 dlt_set_id(ctid,optarg);
176 if (optopt == 'a' || optopt == 'c' || optopt == 'f' || optopt == 't')
178 fprintf (stderr, "Option -%c requires an argument.\n", optopt);
180 else if (isprint (optopt))
182 fprintf (stderr, "Unknown option `-%c'.\n", optopt);
186 fprintf (stderr, "Unknown option character `\\x%x'.\n",optopt);
188 /* unknown or wrong option used, show usage information and terminate */
197 timeout = atoi(tvalue);
210 //Register the application at the dlt-daemon
211 dltResult = DLT_REGISTER_APP(apid,FLTR_APP_DESC);
213 //Register the context of the main program at the dlt-daemon
214 dltResult = DLT_REGISTER_CONTEXT(fileContext,ctid,FLTR_CONTEXT_DESC);
216 //More details in corresponding methods
217 if( dltResult == 0 ){
220 dlt_user_log_file_infoAbout(&fileContext,fvalue);
223 if( dlt_user_log_file_complete(&fileContext,fvalue,dflag,timeout) < 0 )
225 printf("File couldn't be transferred. Please check the dlt log messages.\n");
231 printf("Filetransfer didn't start...error with dlt daemon. Please check the daemon.\n");
234 //Unregister the context in which the file transfer happened from the dlt-daemon
235 DLT_UNREGISTER_CONTEXT(fileContext);
236 //Unregister the context of the main program from the dlt-daemon
237 DLT_UNREGISTER_APP();