automotive-dlt
dlt-example-filetransfer.c
Go to the documentation of this file.
1 /*
2  * @licence app begin@
3  * SPDX license identifier: MPL-2.0
4  *
5  * Copyright (C) 2011-2015, BMW AG
6  *
7  * This file is part of GENIVI Project DLT - Diagnostic Log and Trace.
8  *
9  * This Source Code Form is subject to the terms of the
10  * Mozilla Public License (MPL), v. 2.0.
11  * If a copy of the MPL was not distributed with this file,
12  * You can obtain one at http://mozilla.org/MPL/2.0/.
13  *
14  * For further information see http://www.genivi.org/.
15  * @licence end@
16  */
17 
27 /*******************************************************************************
28 ** **
29 ** SRC-MODULE: dlt-test-client.c **
30 ** **
31 ** TARGET : linux **
32 ** **
33 ** PROJECT : DLT **
34 ** **
35 ** AUTHOR : Alexander Wenzel Alexander.AW.Wenzel@bmw.de **
36 ** **
37 ** PURPOSE : **
38 ** **
39 ** REMARKS : **
40 ** **
41 ** PLATFORM DEPENDANT [yes/no]: yes **
42 ** **
43 ** TO BE CHANGED BY USER [yes/no]: no **
44 ** **
45 *******************************************************************************/
46 
47 /*******************************************************************************
48 ** Author Identity **
49 ********************************************************************************
50 ** **
51 ** Initials Name Company **
52 ** -------- ------------------------- ---------------------------------- **
53 ** aw Alexander Wenzel BMW **
54 *******************************************************************************/
55 
56 
57 #include <stdlib.h>
58 #include <stdio.h>
59 #include <ctype.h>
60 
61 #include <dlt_filetransfer.h> /*Needed for transferring files with the dlt protocol*/
62 #include <dlt.h> /*Needed for dlt logging*/
63 
64 
65 #define MAXSTRLEN 1024
66 
67 #define FLTR_APP_DESC "Filetransfer application"
68 #define FLTR_CONTEXT_DESC "Filetransfer context"
69 
70 #define FLTR_APP "FLTR"
71 #define FLTR_CONTEXT "FLTR"
72 
73 #define TIMEOUT 1
74 
76 DLT_DECLARE_CONTEXT(fileContext)
77 
78 
79 
82 void usage()
83 {
84  char version[255];
85 
86  dlt_get_version(version,255);
87 
88  printf("Usage: dlt-example-filetransfer [options] absolute-path-to-file\n");
89  printf("Simple filetransfer example");
90  printf("%s \n", version);
91  printf("Options:\n");
92  printf("-a apid - Set application id to apid (default: FLTR)\n");
93  printf("-c ctid - Set context id to ctid (default: FLTR)\n");
94  printf("-t ms - Timeout between file packages in ms (minimum 1 ms)\n");
95  printf("-d - Flag to delete the file after the transfer (default: false)\n");
96  printf("-i - Flag to log file infos to DLT before transfer file (default: false)\n");
97  printf("-h - This help\n");
98 
99 }
100 
101 
103 int main(int argc, char* argv[])
104 {
105  //char str[MAXSTRLEN];
106  int opt, timeout;
107 
108  char apid[DLT_ID_SIZE];
109  char ctid[DLT_ID_SIZE];
110 
111  //char version[255];
112  int index;
113  int dflag = 0;
114  int iflag = 0;
115  char *file = 0;
116  char *tvalue = 0;
117 
118  dlt_set_id(apid, FLTR_APP);
119  dlt_set_id(ctid, FLTR_CONTEXT);
120 
121  while ((opt = getopt(argc, argv, "idf:t:a:c:h")) != -1)
122  {
123  switch (opt)
124  {
125  case 'd':
126  {
127  dflag = 1;
128  break;
129  }
130  case 'i':
131  {
132  iflag = 1;
133  break;
134  }
135  case 't':
136  {
137  tvalue = optarg;
138  break;
139  }
140  case 'a':
141  {
142  dlt_set_id(apid,optarg);
143  break;
144  }
145  case 'c':
146  {
147  dlt_set_id(ctid,optarg);
148  break;
149  }
150  case 'h':
151  {
152  usage();
153  break;
154  }
155  case '?':
156  {
157  if (optopt == 'a' || optopt == 'c' || optopt == 't')
158  {
159  fprintf (stderr, "Option -%c requires an argument.\n", optopt);
160  }
161  else if (isprint (optopt))
162  {
163  fprintf (stderr, "Unknown option `-%c'.\n", optopt);
164  }
165  else
166  {
167  fprintf (stderr, "Unknown option character `\\x%x'.\n",optopt);
168  }
169  /* unknown or wrong option used, show usage information and terminate */
170  usage();
171  return -1;
172  }
173  }
174  }
175 
176  for (index = optind; index < argc; index++)
177  {
178  file = argv[index];
179  }
180 
181  if (file == 0)
182  {
183  /* no message, show usage and terminate */
184  fprintf(stderr,"ERROR: No absolute path to file specified\n");
185  usage();
186  return -1;
187  }
188 
189 
190  if (tvalue)
191  {
192  timeout = atoi(tvalue);
193  }
194  else
195  {
196  timeout = TIMEOUT;
197  }
198 
199  //Register the application at the dlt-daemon
201 
202  //Register the context of the main program at the dlt-daemon
203  DLT_REGISTER_CONTEXT(fileContext,ctid,FLTR_CONTEXT_DESC);
204 
205  //More details in corresponding methods
206  if( iflag )
207  {
208  dlt_user_log_file_infoAbout(&fileContext,file);
209  }
210 
211  if( dlt_user_log_file_complete(&fileContext,file,dflag,timeout) < 0 )
212  {
213  printf("File couldn't be transferred. Please check the dlt log messages.\n");
214  }
215 
216  //Unregister the context in which the file transfer happened from the dlt-daemon
217  DLT_UNREGISTER_CONTEXT(fileContext);
218  //Unregister the context of the main program from the dlt-daemon
220 
221  return 0;
222 }
DLT_DECLARE_CONTEXT(fileContext)
Declare some context for the file transfer. It&#39;s not a must have to do this, but later you can set a ...
int main(int argc, char *argv[])
Main program dlt-test-filestransfer starts here.
int dlt_user_log_file_complete(DltContext *fileContext, const char *filename, int deleteFlag, int timeout)
Transfer the complete file as several dlt logs.
#define DLT_UNREGISTER_APP()
#define DLT_ID_SIZE
Definition: dlt_common.h:204
void dlt_set_id(char *id, const char *text)
Definition: dlt_common.c:324
void usage()
Definition: dlt-control.c:190
#define FLTR_CONTEXT
#define FLTR_APP_DESC
#define TIMEOUT
#define DLT_REGISTER_APP(APPID, DESCRIPTION)
#define DLT_REGISTER_CONTEXT(CONTEXT, CONTEXTID, DESCRIPTION)
#define DLT_UNREGISTER_CONTEXT(CONTEXT)
#define FLTR_APP
int dlt_user_log_file_infoAbout(DltContext *fileContext, const char *filename)
Logs specific file inforamtions to dlt.
void dlt_get_version(char *buf, size_t size)
Definition: dlt_common.c:3239
#define FLTR_CONTEXT_DESC