5 #include <dlt_filetransfer.h> /*Needed for transferring files with the dlt protocol*/
6 #include <dlt.h> /*Needed for dlt logging*/
11 #define FLTR_APP_DESC "Filetransfer application"
12 #define FLTR_CONTEXT_DESC "Filetransfer context"
14 #define FLTR_APP "FLTR"
15 #define FLTR_CONTEXT "FLTR"
19 //!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.
20 DLT_DECLARE_CONTEXT(fileContext);
24 * Print usage information of tool.
30 dlt_get_version(version);
32 printf("Usage: dlt-example-filetransfer [options] <command>\n");
33 printf("Filetransfer example");
34 printf("%s \n", version);
36 printf("-f file - File to transfer (absolute path)\n");
38 printf("-a apid - Set application id to apid (default: FLTR)\n");
39 printf("-c ctid - Set context id to ctid (default: FLTR)\n");
40 printf("-t ms - Timeout between file packages in ms (minimum 1 ms)\n");
41 printf("-d - Flag to delete the file after the transfer (default: false)\n");
42 printf("-i - Flag to log file infos to DLT before transfer file (default: false)\n");
43 printf("-h - This help\n");
48 //!Main program dlt-test-filestransfer starts here
49 int main(int argc, char* argv[])
51 //char str[MAXSTRLEN];
52 int opt, timeout, dltResult;;
54 char apid[DLT_ID_SIZE];
55 char ctid[DLT_ID_SIZE];
64 dlt_set_id(apid, FLTR_APP);
65 dlt_set_id(ctid, FLTR_CONTEXT);
67 while ((opt = getopt(argc, argv, "idf:t:a:c:h")) != -1)
93 dlt_set_id(apid,optarg);
98 dlt_set_id(ctid,optarg);
108 if (optopt == 'a' || optopt == 'c' || optopt == 'f' || optopt == 't')
110 fprintf (stderr, "Option -%c requires an argument.\n", optopt);
112 else if (isprint (optopt))
114 fprintf (stderr, "Unknown option `-%c'.\n", optopt);
118 fprintf (stderr, "Unknown option character `\\x%x'.\n",optopt);
120 /* unknown or wrong option used, show usage information and terminate */
129 timeout = atoi(tvalue);
142 //Register the application at the dlt-daemon
143 dltResult = DLT_REGISTER_APP(apid,FLTR_APP_DESC);
145 //Register the context of the main program at the dlt-daemon
146 dltResult = DLT_REGISTER_CONTEXT(fileContext,ctid,FLTR_CONTEXT_DESC);
148 //More details in corresponding methods
149 if( dltResult == 0 ){
152 dlt_user_log_file_infoAbout(&fileContext,fvalue);
155 if( dlt_user_log_file_complete(&fileContext,fvalue,dflag,timeout) < 0 )
157 printf("File couldn't be transferred. Please check the dlt log messages.\n");
163 printf("Filetransfer didn't start...error with dlt daemon. Please check the daemon.\n");
166 //Unregister the context in which the file transfer happened from the dlt-daemon
167 DLT_UNREGISTER_CONTEXT(fileContext);
168 //Unregister the context of the main program from the dlt-daemon
169 DLT_UNREGISTER_APP();