3 * @author sylvain.gaeremynck@parrot.com
6 #include <ardrone_testing_tool.h>
9 #include <ardrone_tool/ardrone_time.h>
10 #include <ardrone_tool/Navdata/ardrone_navdata_client.h>
11 #include <ardrone_tool/Control/ardrone_control.h>
12 #include <ardrone_tool/UI/ardrone_input.h>
13 #include <ardrone_tool/ardrone_tool_configuration.h>
17 #include <ardrone_api.h>
20 #include <ATcodec/ATcodec_api.h>
21 #include <VP_Os/vp_os_print.h>
22 #include <VP_Os/vp_os_thread.h>
23 #include <VP_Api/vp_api_thread_helper.h>
24 #include <VP_Os/vp_os_signal.h>
25 #include <VP_Os/vp_os_types.h>
26 #include <VP_Os/vp_os_delay.h>
29 #include <UI/gamepad.h>
30 #include <Video/video_stage.h>
32 #include <utils/ardrone_ftp.h>
34 #include <semaphore.h>
36 static int32_t exit_ihm_program = 1;
38 /* Implementing Custom methods for the main function of an ARDrone application */
40 /* The delegate object calls this method during initialization of an ARDrone application */
41 C_RESULT ardrone_tool_init_custom(int argc, char **argv)
43 /* Start all threads of your application */
44 START_THREAD( main_application_thread , NULL );
48 /* The delegate object calls this method when the event loop exit */
49 C_RESULT ardrone_tool_shutdown_custom()
51 /* Relinquish all threads of your application */
52 JOIN_THREAD( main_application_thread );
57 /* The event loop calls this method for the exit condition */
58 bool_t ardrone_tool_exit()
60 return exit_ihm_program == 0;
63 C_RESULT signal_exit()
70 PROTO_THREAD_ROUTINE(main_application_thread, data);
72 /* Implementing thread table in which you add routines of your application and those provided by the SDK */
74 THREAD_TABLE_ENTRY( main_application_thread, 20 )
79 #define BLUE { printf("%s","\033[34;01m"); }
80 #define RED { printf("%s","\033[31;01m"); }
81 #define GREEN { printf("%s","\033[32;01m"); }
82 #define RAZ { printf("%s","\033[0m"); }
84 #define TEST_RESULT(result, formatFAIL, formatOK, ...) \
87 _ftp_status locResult = (result); \
89 if (FTP_FAILED (locResult)) \
92 printf ("[%i : KO] : ", __LINE__); \
93 printf (formatFAIL, __VA_ARGS__); \
100 printf ("[%i : OK] : ", __LINE__); \
101 printf (formatOK, __VA_ARGS__); \
106 if ((FTP_TIMEOUT == locResult) || \
107 (FTP_BUSY == locResult)) \
118 #define COMPUTE_PERCENT_OK \
123 float percentOk = (100.0 * opOk) / (1.0 * totalOp); \
124 if (90.0 < percentOk) \
132 printf ("Success of %llu operations on %llu (%6.2f %%)\n", opOk, totalOp, percentOk); \
138 #define TEST_ABORTION(abortFunc) \
141 _ftp_status locStat = (abortFunc); \
147 printf ("[%i : OK] : ", __LINE__); \
148 printf ("Abortion successfull\n"); \
154 printf ("[%i : KO] : ", __LINE__); \
155 printf ("Abortion failed, op was not running\n"); \
161 printf ("[%i : KO] : ", __LINE__); \
162 printf ("Unknown result\n"); \
168 #define WAIT_COND(result) \
171 sem_wait (&synchroSem); \
178 sem_post (&synchroSem); \
182 _ftp_status globalStatus;
183 int runOperation = 1;
184 char *listBuffer = NULL;
187 ftpCallback (_ftp_status status, void *arg, _ftp_t *callingFtp)
189 float percent = (NULL != arg) ? *(float *)arg : -1.0;
190 if (NULL != arg && FTP_SUCCESS == status) { listBuffer = arg; }
191 globalStatus = status;
192 static int calls = 0;
193 #define CALLBACK_FORMAT "Callback called with status %s\n"
195 #define PRINT_CALLBACK_FORMAT(statusString) { printf (CALLBACK_FORMAT, statusString); calls++; }
197 #define PRINT_CALLBACK_FORMAT(statusString) { calls++; }
202 PRINT_CALLBACK_FORMAT ("FTP_BUSY");
206 PRINT_CALLBACK_FORMAT ("FTP_ABORT");
210 PRINT_CALLBACK_FORMAT ("FTP_FAIL");
214 PRINT_CALLBACK_FORMAT ("FTP_SUCCESS");
218 PRINT_CALLBACK_FORMAT ("FTP_TIMEOUT");
222 PRINT_CALLBACK_FORMAT ("FTP_BADSIZE");
226 PRINT_CALLBACK_FORMAT ("FTP_SAMESIZE");
230 printf ("\rProgress : %5.2f", percent);
232 if (100.0 <= percent)
237 default: // Should not happen ... kill the program in this case !
238 printf ("Callback called with unknown status : %d\n", status);
242 #undef CALLBACK_FORMAT
245 #define title(x) { BLUE; printf("[%i] %s",__LINE__,x); RAZ; }
247 #define _USE_EMENCIA_SERVER (0)
248 #if _USE_EMENCIA_SERVER
249 #define ARDRONE_IP "parrot02.nyx.emencia.net"
250 #define ARDRONE_PORT (21)
251 #define ARDRONE_USER "parrot"
252 #define ARDRONE_PASSWORD "parrot"
254 #define ARDRONE_IP "192.168.1.1"
255 #define ARDRONE_PORT (21)
256 #define ARDRONE_USER "anonymous"
257 #define ARDRONE_PASSWORD ""
260 #define _1MB_ORIGIN_FILE "origin.txt"
261 #define _512K_FAILED_FILE "half_file.txt"
262 #define _256K_FAILED_FILE "quarter_file.txt"
263 #define _1MB_MERGED_FILE "merged.txt"
264 #define LOCAL_RESULT_FILE "result.txt"
266 #define NOCB_NORESUME_RESULT "result_nocb_noresume.txt"
267 #define CB_NORESUME_RESULT "result_cb_noresume.txt"
268 #define NOCB_RESUME_RESULT "result_nocb_resume.txt"
269 #define CB_RESUME_RESULT "result_cb_resume.txt"
271 #define ARDRONE_FILE_BEFORE_RENAME "origin.txt"
272 #define ARDRONE_FILE_AFTER_RENAME "result.txt"
274 DEFINE_THREAD_ROUTINE(main_application_thread, data)
277 /* Semaphore for synchronisation */
278 sem_init (&synchroSem, 0, 0);
282 char buffer [512] = {0};
285 _ftp_t *droneFtp = NULL;
286 _ftp_status ftp_result = FTP_FAIL;
288 int runOperation = 1;
290 uint64_t totalOp = 0;
294 title ("\n\n------ CLEANING ------\n\n");
296 title ("--- Connecting to AR.Drone FTP ---\n");
298 for (runOperation = 1; runOperation;)
300 droneFtp = ftpConnect (ARDRONE_IP, ARDRONE_PORT, ARDRONE_USER, ARDRONE_PASSWORD, &ftp_result);
301 TEST_RESULT (ftp_result, "Unable to connect to %s@%s:%d (PASS : %s)", "Connected to %s@%s:%d (PASS : %s)", ARDRONE_USER, ARDRONE_IP, ARDRONE_PORT, ARDRONE_PASSWORD);
304 title ("--- Getting PWD ---\n");
306 char pwd [256] = {0};
307 ftp_result = ftpPwd (droneFtp, pwd, 256);
308 TEST_RESULT (ftp_result, "Unable to get PWD [%1s]", "Got PWD : %s", pwd);
310 title ("--- Removing previous file on AR.Drone ---\n");
312 for (runOperation = 1; runOperation;)
314 ftp_result = ftpRemove (droneFtp, ARDRONE_FILE_BEFORE_RENAME);
315 TEST_RESULT (ftp_result, " (STILL OK !) file %s does not exist", "Deleted file %s", ARDRONE_FILE_BEFORE_RENAME);
318 for (runOperation = 1; runOperation;)
320 ftp_result = ftpRemove (droneFtp, ARDRONE_FILE_AFTER_RENAME);
321 TEST_RESULT (ftp_result, " (STILL OK !) file %s does not exist", "Deleted file %s", ARDRONE_FILE_AFTER_RENAME);
324 title ("--- Removing local result file ---\n");
326 vp_os_memset (buffer, 0x0, 512);
327 snprintf (buffer, 512, "rm -f %s", LOCAL_RESULT_FILE);
328 systemRet = system (buffer);
329 printf ("System : %s\n", buffer);
331 title ("--- Disconnecting from AR.Drone FTP ---\n");
333 TEST_RESULT (ftpClose (&droneFtp), "AR.Drone FTP (%s:%d) was not opened", "Closed AR.Drone FTP (%s:%d)", ARDRONE_IP, ARDRONE_PORT);
338 title ("\n\n------ TESTS WITHOUT RESUME NOR CALLBACK ------\n\n");
340 title ("--- Connecting to AR.Drone FTP ---\n");
342 for (runOperation = 1; runOperation;)
344 droneFtp = ftpConnect (ARDRONE_IP, ARDRONE_PORT, ARDRONE_USER, ARDRONE_PASSWORD, &ftp_result);
345 TEST_RESULT (ftp_result, "Unable to connect to %s@%s:%d (PASS : %s)", "Connected to %s@%s:%d (PASS : %s)", ARDRONE_USER, ARDRONE_IP, ARDRONE_PORT, ARDRONE_PASSWORD);
348 title ("--- Sending origin file to the AR.Drone ---\n");
350 for (runOperation = 1; runOperation;)
352 ftp_result = ftpPut (droneFtp, _1MB_ORIGIN_FILE, ARDRONE_FILE_BEFORE_RENAME, 0, NULL);
353 TEST_RESULT (ftp_result, "Unable to send file %s->%s", "Sent file %s->%s", _1MB_ORIGIN_FILE, ARDRONE_FILE_BEFORE_RENAME);
356 title ("--- Renaming file on the AR.Drone ---\n");
358 for (runOperation = 1; runOperation;)
360 ftp_result = ftpRename (droneFtp, ARDRONE_FILE_BEFORE_RENAME, ARDRONE_FILE_AFTER_RENAME);
361 TEST_RESULT (ftp_result, "Impossible to rename %s->%s", "Renamed %s->%s", ARDRONE_FILE_BEFORE_RENAME, ARDRONE_FILE_AFTER_RENAME);
364 title ("--- Getting AR.Drone FTP Listing ---\n");
366 for (runOperation = 1; runOperation;)
368 ftp_result = ftpList (droneFtp, &listBuffer, NULL);
369 TEST_RESULT (ftp_result, "Unable to list FTP [%1s]", "Listed FTP :\n%s", listBuffer);
370 if (NULL != listBuffer) { vp_os_free (listBuffer); listBuffer = NULL; }
373 title ("--- Getting back result file ---\n");
375 for (runOperation = 1; runOperation;)
377 ftp_result = ftpGet (droneFtp, ARDRONE_FILE_AFTER_RENAME, LOCAL_RESULT_FILE, 0, NULL);
378 TEST_RESULT (ftp_result, "Unable to get file %s->%s", "Got back file %s->%s", ARDRONE_FILE_AFTER_RENAME, LOCAL_RESULT_FILE);
381 title ("--- Checking file ---\n");
383 vp_os_memset (buffer, 0x0, 512);
384 snprintf (buffer, 512, "diff %s %s > /dev/null", LOCAL_RESULT_FILE, _1MB_ORIGIN_FILE);
385 systemRet = system (buffer);
386 printf ("System : %s\n", buffer);
390 RED; printf ("[%d : KO] : Files are different !\n", __LINE__); RAZ;
395 GREEN; printf ("[%d : OK] : Files are the same\n", __LINE__); RAZ;
398 title ("--- Removing file on AR.Drone ---\n");
400 for (runOperation = 1; runOperation;)
402 ftp_result = ftpRemove (droneFtp, ARDRONE_FILE_AFTER_RENAME);
403 TEST_RESULT (ftp_result, "Unable to delete file %s", "Deleted file %s", ARDRONE_FILE_AFTER_RENAME);
406 title ("--- Local file backup ---\n");
408 vp_os_memset (buffer, 0x0, 512);
409 snprintf (buffer, 512, "mv %s %s", LOCAL_RESULT_FILE, NOCB_NORESUME_RESULT);
410 systemRet = system (buffer);
411 printf ("System : %s\n", buffer);
413 title ("--- Closing AR.Drone FTP ---\n");
415 TEST_RESULT (ftpClose (&droneFtp), "AR.Drone FTP (%s:%d) was not opened", "Closed AR.Drone FTP (%s:%d)", ARDRONE_IP, ARDRONE_PORT);
424 title ("\n\n------ TESTS WITHOUT RESUME / WITH CALLBACK ------\n\n");
426 title ("--- Connecting to AR.Drone FTP ---\n");
428 for (runOperation = 1; runOperation;)
430 droneFtp = ftpConnect (ARDRONE_IP, ARDRONE_PORT, ARDRONE_USER, ARDRONE_PASSWORD, &ftp_result);
431 TEST_RESULT (ftp_result, "Unable to connect to %s@%s:%d (PASS : %s)", "Connected to %s@%s:%d (PASS : %s)", ARDRONE_USER, ARDRONE_IP, ARDRONE_PORT, ARDRONE_PASSWORD);
434 title ("--- Sending origin file to the AR.Drone ---\n");
437 for (runOperation = 1; runOperation;)
439 ftp_result = ftpPut (droneFtp, _1MB_ORIGIN_FILE, ARDRONE_FILE_BEFORE_RENAME, 0, ftpCallback);
440 WAIT_COND (ftp_result);
441 TEST_RESULT (globalStatus, "Unable to send file %s->%s", "Sent file %s->%s", _1MB_ORIGIN_FILE, ARDRONE_FILE_BEFORE_RENAME);
444 title ("--- Renaming file on the AR.Drone ---\n");
446 ftp_result = ftpRename (droneFtp, ARDRONE_FILE_BEFORE_RENAME, ARDRONE_FILE_AFTER_RENAME);
447 TEST_RESULT (ftp_result, "Impossible to rename %s->%s", "Renamed %s->%s", ARDRONE_FILE_BEFORE_RENAME, ARDRONE_FILE_AFTER_RENAME);
449 title ("--- Getting AR.Drone FTP Listing ---\n");
451 for (runOperation = 1; runOperation;)
453 ftp_result = ftpList (droneFtp, NULL, ftpCallback);
454 WAIT_COND (ftp_result);
455 TEST_RESULT (globalStatus, "Unable to list FTP [%1s]", "Listed FTP :\n%s", listBuffer);
456 if (NULL != listBuffer) { vp_os_free (listBuffer); listBuffer = NULL; }
459 title ("--- Getting back result file ---\n");
461 for (runOperation = 1; runOperation;)
463 ftp_result = ftpGet (droneFtp, ARDRONE_FILE_AFTER_RENAME, LOCAL_RESULT_FILE, 0, ftpCallback);
464 WAIT_COND (ftp_result);
465 TEST_RESULT (globalStatus, "Unable to get file %s->%s", "Got back file %s->%s", ARDRONE_FILE_AFTER_RENAME, LOCAL_RESULT_FILE);
468 title ("--- Checking file ---\n");
470 vp_os_memset (buffer, 0x0, 512);
471 snprintf (buffer, 512, "diff %s %s > /dev/null", LOCAL_RESULT_FILE, _1MB_ORIGIN_FILE);
472 systemRet = system (buffer);
473 printf ("System : %s\n", buffer);
477 RED; printf ("[%d : KO] : Files are different !\n", __LINE__); RAZ;
482 GREEN; printf ("[%d : OK] : Files are the same\n", __LINE__); RAZ;
485 title ("--- Removing file on AR.Drone ---\n");
487 for (runOperation = 1; runOperation;)
489 ftp_result = ftpRemove (droneFtp, ARDRONE_FILE_AFTER_RENAME);
490 TEST_RESULT (ftp_result, "Unable to delete file %s", "Deleted file %s", ARDRONE_FILE_AFTER_RENAME);
493 title ("--- Local file backup ---\n");
495 vp_os_memset (buffer, 0x0, 512);
496 snprintf (buffer, 512, "mv %s %s", LOCAL_RESULT_FILE, CB_NORESUME_RESULT);
497 systemRet = system (buffer);
498 printf ("System : %s\n", buffer);
500 title ("--- Closing AR.Drone FTP ---\n");
502 TEST_RESULT (ftpClose (&droneFtp), "AR.Drone FTP (%s:%d) was not opened", "Closed AR.Drone FTP (%s:%d)", ARDRONE_IP, ARDRONE_PORT);
509 title ("\n\n------ TESTS WITH RESUME / NO CALLBACK ------\n\n");
511 title ("--- Preparing bad file (256K) locally ---\n");
513 vp_os_memset (buffer, 0x0, 512);
514 snprintf (buffer, 512, "cp %s %s", _256K_FAILED_FILE, LOCAL_RESULT_FILE);
515 systemRet = system (buffer);
516 printf ("System : %s\n", buffer);
518 title ("--- Connecting to AR.Drone FTP ---\n");
520 for (runOperation = 1; runOperation;)
522 droneFtp = ftpConnect (ARDRONE_IP, ARDRONE_PORT, ARDRONE_USER, ARDRONE_PASSWORD, &ftp_result);
523 TEST_RESULT (ftp_result, "Unable to connect to %s@%s:%d (PASS : %s)", "Connected to %s@%s:%d (PASS : %s)", ARDRONE_USER, ARDRONE_IP, ARDRONE_PORT, ARDRONE_PASSWORD);
526 title ("--- Preparing bad file (512K) on AR.Drone FTP ---\n");
528 for (runOperation = 1; runOperation;)
530 ftp_result = ftpPut (droneFtp, _512K_FAILED_FILE, ARDRONE_FILE_BEFORE_RENAME, 1, NULL);
531 TEST_RESULT (ftp_result, "Unable to send partial file %s->%s", "Sent partial file %s->%s", _512K_FAILED_FILE, ARDRONE_FILE_BEFORE_RENAME);
534 title ("--- Sending origin file to the AR.Drone ---\n");
536 for (runOperation = 1; runOperation;)
538 ftp_result = ftpPut (droneFtp, _1MB_ORIGIN_FILE, ARDRONE_FILE_BEFORE_RENAME, 1, NULL);
539 TEST_RESULT (ftp_result, "Unable to send file %s->%s", "Sent file %s->%s", _1MB_ORIGIN_FILE, ARDRONE_FILE_BEFORE_RENAME);
542 title ("--- Renaming file on the AR.Drone ---\n");
544 for (runOperation = 1; runOperation;)
546 ftp_result = ftpRename (droneFtp, ARDRONE_FILE_BEFORE_RENAME, ARDRONE_FILE_AFTER_RENAME);
547 TEST_RESULT (ftp_result, "Impossible to rename %s->%s", "Renamed %s->%s", ARDRONE_FILE_BEFORE_RENAME, ARDRONE_FILE_AFTER_RENAME);
550 title ("--- Getting AR.Drone FTP Listing ---\n");
552 for (runOperation = 1; runOperation;)
554 ftp_result = ftpList (droneFtp, &listBuffer, NULL);
555 TEST_RESULT (ftp_result, "Unable to list FTP [%1s]", "Listed FTP :\n%s", listBuffer);
556 if (NULL != listBuffer) { vp_os_free (listBuffer); listBuffer = NULL; }
559 title ("--- Getting back result file ---\n");
561 for (runOperation = 1; runOperation;)
563 ftp_result = ftpGet (droneFtp, ARDRONE_FILE_AFTER_RENAME, LOCAL_RESULT_FILE, 1, NULL);
564 TEST_RESULT (ftp_result, "Unable to get file %s->%s", "Got back file %s->%s", ARDRONE_FILE_AFTER_RENAME, LOCAL_RESULT_FILE);
567 title ("--- Checking file ---\n");
569 vp_os_memset (buffer, 0x0, 512);
570 snprintf (buffer, 512, "diff %s %s > /dev/null", LOCAL_RESULT_FILE, _1MB_MERGED_FILE);
571 systemRet = system (buffer);
572 printf ("System : %s\n", buffer);
576 RED; printf ("[%d : KO] : Files are different !\n", __LINE__); RAZ;
581 GREEN; printf ("[%d : OK] : Files are the same\n", __LINE__); RAZ;
584 title ("--- Removing file on AR.Drone ---\n");
586 for (runOperation = 1; runOperation;)
588 ftp_result = ftpRemove (droneFtp, ARDRONE_FILE_AFTER_RENAME);
589 TEST_RESULT (ftp_result, "Unable to delete file %s", "Deleted file %s", ARDRONE_FILE_AFTER_RENAME);
592 title ("--- Local file backup ---\n");
594 vp_os_memset (buffer, 0x0, 512);
595 snprintf (buffer, 512, "mv %s %s", LOCAL_RESULT_FILE, NOCB_RESUME_RESULT);
596 systemRet = system (buffer);
597 printf ("System : %s\n", buffer);
599 title ("--- Closing AR.Drone FTP ---\n");
601 TEST_RESULT (ftpClose (&droneFtp), "AR.Drone FTP (%s:%d) was not opened", "Closed AR.Drone FTP (%s:%d)", ARDRONE_IP, ARDRONE_PORT);
614 title ("\n\n------ TESTS WITH RESUME AND CALLBACK ------\n\n");
616 title ("--- Preparing bad file (256K) locally ---\n");
618 vp_os_memset (buffer, 0x0, 512);
619 snprintf (buffer, 512, "cp %s %s", _256K_FAILED_FILE, LOCAL_RESULT_FILE);
620 systemRet = system (buffer);
621 printf ("System : %s\n", buffer);
623 title ("--- Connecting to AR.Drone FTP ---\n");
625 for (runOperation = 1; runOperation;)
627 droneFtp = ftpConnect (ARDRONE_IP, ARDRONE_PORT, ARDRONE_USER, ARDRONE_PASSWORD, &ftp_result);
628 TEST_RESULT (ftp_result, "Unable to connect to %s@%s:%d (PASS : %s)", "Connected to %s@%s:%d (PASS : %s)", ARDRONE_USER, ARDRONE_IP, ARDRONE_PORT, ARDRONE_PASSWORD);
631 title ("--- Preparing bad file (512K) on AR.Drone FTP ---\n");
633 for (runOperation = 1; runOperation;)
635 ftp_result = ftpPut (droneFtp, _512K_FAILED_FILE, ARDRONE_FILE_BEFORE_RENAME, 1, ftpCallback);
636 WAIT_COND (ftp_result);
637 TEST_RESULT (globalStatus, "Unable to send partial file %s->%s", "Sent partial file %s->%s", _512K_FAILED_FILE, ARDRONE_FILE_BEFORE_RENAME);
640 title ("--- Sending origin file to the AR.Drone ---\n");
642 for (runOperation = 1; runOperation;)
644 ftp_result = ftpPut (droneFtp, _1MB_ORIGIN_FILE, ARDRONE_FILE_BEFORE_RENAME, 1, ftpCallback);
645 WAIT_COND (ftp_result);
646 TEST_RESULT (globalStatus, "Unable to send file %s->%s", "Sent file %s->%s", _1MB_ORIGIN_FILE, ARDRONE_FILE_BEFORE_RENAME);
649 title ("--- Renaming file on the AR.Drone ---\n");
651 for (runOperation = 1; runOperation;)
653 ftp_result = ftpRename (droneFtp, ARDRONE_FILE_BEFORE_RENAME, ARDRONE_FILE_AFTER_RENAME);
654 TEST_RESULT (ftp_result, "Impossible to rename %s->%s", "Renamed %s->%s", ARDRONE_FILE_BEFORE_RENAME, ARDRONE_FILE_AFTER_RENAME);
657 title ("--- Getting AR.Drone FTP Listing ---\n");
659 for (runOperation = 1; runOperation;)
661 ftp_result = ftpList (droneFtp, NULL, ftpCallback);
662 WAIT_COND (ftp_result);
663 TEST_RESULT (globalStatus, "Unable to list FTP [%1s]", "Listed FTP :\n%s", listBuffer);
664 if (NULL != listBuffer) { vp_os_free (listBuffer); listBuffer = NULL; }
667 title ("--- Getting back result file ---\n");
669 for (runOperation = 1; runOperation;)
671 ftp_result = ftpGet (droneFtp, ARDRONE_FILE_AFTER_RENAME, LOCAL_RESULT_FILE, 1, ftpCallback);
672 WAIT_COND (ftp_result);
673 TEST_RESULT (globalStatus, "Unable to get file %s->%s", "Got back file %s->%s", ARDRONE_FILE_AFTER_RENAME, LOCAL_RESULT_FILE);
676 title ("--- Checking file ---\n");
678 vp_os_memset (buffer, 0x0, 512);
679 snprintf (buffer, 512, "diff %s %s > /dev/null", LOCAL_RESULT_FILE, _1MB_MERGED_FILE);
680 systemRet = system (buffer);
681 printf ("System : %s\n", buffer);
685 RED; printf ("[%d : KO] : Files are different !\n", __LINE__); RAZ;
690 GREEN; printf ("[%d : OK] : Files are the same\n", __LINE__); RAZ;
693 title ("--- Removing file on AR.Drone ---\n");
695 for (runOperation = 1; runOperation;)
697 ftp_result = ftpRemove (droneFtp, ARDRONE_FILE_AFTER_RENAME);
698 TEST_RESULT (ftp_result, "Unable to delete file %s", "Deleted file %s", ARDRONE_FILE_AFTER_RENAME);
701 title ("--- Local file backup ---\n");
703 vp_os_memset (buffer, 0x0, 512);
704 snprintf (buffer, 512, "mv %s %s", LOCAL_RESULT_FILE, CB_RESUME_RESULT);
705 systemRet = system (buffer);
706 printf ("System : %s\n", buffer);
708 title ("--- Closing AR.Drone FTP ---\n");
710 TEST_RESULT (ftpClose (&droneFtp), "AR.Drone FTP (%s:%d) was not opened", "Closed AR.Drone FTP (%s:%d)", ARDRONE_IP, ARDRONE_PORT);
719 title ("\n\n------ ABORTION TESTS ------\n\n");
722 title ("--- Connecting to AR.Drone FTP ---\n");
724 for (runOperation = 1; runOperation;)
726 droneFtp = ftpConnect (ARDRONE_IP, ARDRONE_PORT, ARDRONE_USER, ARDRONE_PASSWORD, &ftp_result);
727 TEST_RESULT (ftp_result, "Unable to connect to %s@%s:%d (PASS : %s)", "Connected to %s@%s:%d (PASS : %s)", ARDRONE_USER, ARDRONE_IP, ARDRONE_PORT, ARDRONE_PASSWORD);
730 title ("--- Sending origin file to the AR.Drone ... aborted ---\n");
732 for (runOperation = 1; runOperation;)
734 ftp_result = ftpPut (droneFtp, _1MB_ORIGIN_FILE, ARDRONE_FILE_BEFORE_RENAME, 1, ftpCallback);
736 TEST_ABORTION (ftpAbort (droneFtp));
737 WAIT_COND (ftp_result);
738 TEST_RESULT ((FTP_ABORT == globalStatus) ? FTP_SUCCESS : FTP_FAIL, "Impossible to abort %s->%s transfert", "Aborted %s->%s transfert", _1MB_ORIGIN_FILE, ARDRONE_FILE_BEFORE_RENAME);
741 title ("--- Sending origin file to the AR.Drone ... complete previous operation ---\n");
743 for (runOperation = 1; runOperation;)
745 ftp_result = ftpPut (droneFtp, _1MB_ORIGIN_FILE, ARDRONE_FILE_BEFORE_RENAME, 1, ftpCallback);
746 WAIT_COND (ftp_result);
747 TEST_RESULT (globalStatus, "Unable to send file %s->%s", "Sent file %s->%s", _1MB_ORIGIN_FILE, ARDRONE_FILE_BEFORE_RENAME);
750 title ("--- Getting AR.Drone FTP Listing ... aborted ---\n");
752 for (runOperation = 1; runOperation;)
754 ftp_result = ftpList (droneFtp, NULL, ftpCallback);
756 TEST_ABORTION (ftpAbort (droneFtp));
757 WAIT_COND (ftp_result);
758 TEST_RESULT ((FTP_ABORT == globalStatus) ? FTP_SUCCESS : FTP_FAIL, "Impossible to abort %s", "Aborted %s", "listing");
759 if (NULL != listBuffer) { vp_os_free (listBuffer); listBuffer = NULL; }
762 title ("--- Getting AR.Drone FTP Listing ... ok ---\n");
764 for (runOperation = 1; runOperation;)
766 ftp_result = ftpList (droneFtp, NULL, ftpCallback);
767 WAIT_COND (ftp_result);
768 TEST_RESULT (globalStatus, "Unable to list FTP [%1s]", "Listed FTP :\n%s", listBuffer);
769 if (NULL != listBuffer) { vp_os_free (listBuffer); listBuffer = NULL; }
772 title ("--- Getting back origin file as result ... aborted ---\n");
774 for (runOperation = 1; runOperation;)
776 ftp_result = ftpGet (droneFtp, ARDRONE_FILE_BEFORE_RENAME, LOCAL_RESULT_FILE, 1, ftpCallback);
778 TEST_ABORTION (ftpAbort (droneFtp));
779 WAIT_COND (ftp_result);
780 TEST_RESULT ((FTP_ABORT == globalStatus) ? FTP_SUCCESS : FTP_FAIL, "Impossible to abort %s->%s transfert", "Aborted %s->%s transfert", ARDRONE_FILE_BEFORE_RENAME, LOCAL_RESULT_FILE);
783 title ("--- Getting back origin file as result ... complete previous operation ---\n");
785 for (runOperation = 1; runOperation;)
787 ftp_result = ftpGet (droneFtp, ARDRONE_FILE_BEFORE_RENAME, LOCAL_RESULT_FILE, 1, ftpCallback);
788 WAIT_COND (ftp_result);
789 TEST_RESULT (globalStatus, "Unable to get file %s->%s", "Got back file %s->%s", ARDRONE_FILE_BEFORE_RENAME, LOCAL_RESULT_FILE);
792 title ("--- Checking file ---\n");
794 vp_os_memset (buffer, 0x0, 512);
795 snprintf (buffer, 512, "diff %s %s > /dev/null", LOCAL_RESULT_FILE, _1MB_ORIGIN_FILE);
796 systemRet = system (buffer);
797 printf ("System : %s\n", buffer);
801 RED; printf ("[%d : KO] : Files are different !\n", __LINE__); RAZ;
806 GREEN; printf ("[%d : OK] : Files are the same\n", __LINE__); RAZ;
809 title ("--- Removing file on AR.Drone ---\n");
811 for (runOperation = 1; runOperation;)
813 ftp_result = ftpRemove (droneFtp, ARDRONE_FILE_BEFORE_RENAME);
814 TEST_RESULT (ftp_result, "Unable to delete file %s", "Deleted file %s", ARDRONE_FILE_BEFORE_RENAME);
817 title ("--- Closing AR.Drone FTP ---\n");
819 TEST_RESULT (ftpClose (&droneFtp), "AR.Drone FTP (%s:%d) was not opened", "Closed AR.Drone FTP (%s:%d)", ARDRONE_IP, ARDRONE_PORT);
827 title ("\n\n------ RESULT ------\n\n");
832 sem_destroy (&synchroSem);