No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

videoExample.cpp 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #include "../src/imagerie.h"
  2. #include "../src/serial.h"
  3. #include "../src/tcpServer.h" // include himself imagerie.h
  4. #include <pthread.h>
  5. #include <unistd.h>
  6. using namespace std;
  7. using namespace cv;
  8. #ifndef __STUB__
  9. using namespace raspicam;
  10. #endif
  11. void * threadVideo(void *arg)
  12. {
  13. printf("Thread lancé ... \n");
  14. Camera rpiCam;
  15. Image imgVideo;
  16. Arene monArene;
  17. Position positionRobots[20];
  18. Jpg compress;
  19. openCamera(&rpiCam);
  20. do
  21. {
  22. #ifndef __STUB__
  23. getImg(&rpiCam, &imgVideo);
  24. #else
  25. getImg(&rpiCam, &imgVideo, "/home/pehladik/C-TP-RT/src/mondrian22.jpeg");
  26. #endif
  27. /*if(detectArena(&imgVideo, &monArene)==0)
  28. {
  29. detectPosition(&imgVideo,positionRobots,&monArene);
  30. drawArena(&imgVideo,&imgVideo,&monArene);
  31. }
  32. else
  33. detectPosition(&imgVideo,positionRobots);
  34. drawPosition(&imgVideo,&imgVideo,&positionRobots[0]);*/
  35. imgCompress(&imgVideo,&compress);
  36. sendToUI("IMG",&compress);
  37. sendToUI("POS",&positionRobots[0]);
  38. }while(waitKey(30)!='q');
  39. closeCam(&rpiCam);
  40. pthread_exit(NULL);
  41. }
  42. void * threadClient(void *arg){
  43. char * args [] = {"nodejs", "/home/pehladik/Interface-TP-RT/interface.js", NULL};
  44. if (execv("/usr/bin/nodejs", args)== -1){
  45. perror("execv");
  46. return EXIT_FAILURE;
  47. }
  48. }
  49. int main() {
  50. pthread_t threadClient;
  51. if(pthread_create(&threadClient,NULL, threadClient, NULL) == -1)
  52. perror("erreur lors de la creation du thread\n");
  53. serverOpen();
  54. robotOpenCom();
  55. char header[4];
  56. char data[20];
  57. memset(data, '\0',20);
  58. memset(header,'\0',4);
  59. pthread_t thread1;
  60. if(pthread_create(&thread1,NULL, threadVideo, NULL) == -1)
  61. perror("erreur lors de la creation du thread\n");
  62. do
  63. { receptionFromUI(header,data);
  64. printf("Msg reçu : %s %s", header, data);
  65. if(strcmp(header, DMB) == 0)
  66. {
  67. printf("EVENEMENT DUMBER DETECTE AVEC LE MESSAGE :%s \n",data);
  68. int a = sendCmdToRobot(data[0]);
  69. printf("Resultat CMD : %d \n", a);
  70. if(data[0] == WITHOUT_WD && a == 0)
  71. {
  72. sendToUI(ACK);
  73. }
  74. else if(data[0] == BACKIDLE && a == 0)
  75. {
  76. sendToUI(ACK);
  77. }
  78. }
  79. if(strcmp(header, MES) == 0)
  80. {
  81. printf("EVENEMENT MESSAGE DETECTE AVEC LE MESSAGE :%s \n",data);
  82. }
  83. if(strcmp(header,POS)==0)
  84. {
  85. printf("EVENEMENT POSITION DETECTE AVEC LE MESSAGE :%s \n",data);
  86. }
  87. }while((strcmp(header,MES)!=0) || (data[0] != 'C'));
  88. robotCloseCom();
  89. serverClose();
  90. return 0;
  91. }