0782ab2f290aa53ccef6c919f44141531e886956
[mardrone] / mardrone / ARDrone_SDK_Version_1_8_20110726 / Examples / Linux / Navigation / Sources / utils / remote_console.c
1
2 #include <stdlib.h>
3 #include <ctype.h>
4 #include <sys/time.h>
5
6 #include <VP_Api/vp_api.h>
7 #include <VP_Api/vp_api_error.h>
8 #include <VP_Stages/vp_stages_configs.h>
9 #include <VP_Stages/vp_stages_io_console.h>
10 #include <VP_Stages/vp_stages_io_com.h>
11 #include <VP_Stages/vp_stages_io_file.h>
12 #include <VP_Os/vp_os_print.h>
13 #include <VP_Os/vp_os_malloc.h>
14
15 #include <ardrone_tool/Com/config_com.h>
16 #include <ardrone_tool/ardrone_tool.h>
17
18
19 #define NB_STAGES 3
20
21
22 static PIPELINE_HANDLE pipeline_handle;
23 static char filename[100];
24
25
26 DEFINE_THREAD_ROUTINE(remote_console, data)
27 {
28   vp_api_io_pipeline_t    pipeline;
29   vp_api_io_data_t        out;
30   vp_api_io_stage_t       stages[NB_STAGES];
31
32   vp_stages_input_com_config_t     icc;
33   vp_stages_output_file_config_t   ofc;
34
35   struct timeval tv;
36   struct tm atm;
37
38   gettimeofday(&tv,NULL);
39   localtime_r(&tv.tv_sec, &atm);
40   sprintf(&filename[0], "logs_%04d%02d%02d_%02d%02d%02d.txt",
41           atm.tm_year+1900, atm.tm_mon+1, atm.tm_mday,
42           atm.tm_hour, atm.tm_min, atm.tm_sec);
43
44   vp_os_memset( &icc,         0, sizeof(vp_stages_input_com_config_t));
45   vp_os_memset( &ofc,         0, sizeof(vp_stages_output_file_config_t));
46
47   icc.com                 = COM_REMOTE_CONSOLE();
48   icc.config              = COM_CONFIG_REMOTE_CONSOLE();
49   icc.connection          = COM_CONNECTION_REMOTE_CONSOLE();
50   icc.buffer_size         = 1024;
51   COM_CONFIG_SOCKET_REMOTE_CONSOLE(&icc.socket, VP_COM_CLIENT, PRINTF_PORT, wifi_ardrone_ip);
52
53   ofc.name = &filename[0];
54
55   stages[0].type = VP_API_INPUT_SOCKET;
56   stages[0].cfg = (void *)&icc;
57   stages[0].funcs = vp_stages_input_com_funcs;
58
59   stages[1].type = VP_API_OUTPUT_CONSOLE;
60   stages[1].cfg = NULL;
61   stages[1].funcs = vp_stages_output_console_funcs;
62
63   stages[2].type = VP_API_OUTPUT_FILE;
64   stages[2].cfg = (void *)&ofc;
65   stages[2].funcs = vp_stages_output_file_funcs;
66
67   pipeline.nb_stages = NB_STAGES;
68   pipeline.stages = &stages[0];
69
70   if(SUCCEED(vp_api_open(&pipeline, &pipeline_handle)))
71     {
72       out.status = VP_API_STATUS_PROCESSING;
73       while(SUCCEED(vp_api_run(&pipeline, &out)) && (out.status == VP_API_STATUS_PROCESSING || out.status == VP_API_STATUS_STILL_RUNNING) && !ardrone_tool_exit());
74       vp_api_close(&pipeline, &pipeline_handle);
75     }
76
77   return EXIT_SUCCESS;
78 }
79