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.

tasks.h 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * Copyright (C) 2018 dimercur
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef __TASKS_H__
  18. #define __TASKS_H__
  19. #ifndef __WITH_PTHREAD__
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <unistd.h>
  23. #include <sys/mman.h>
  24. #include <alchemy/task.h>
  25. #include <alchemy/timer.h>
  26. #include <alchemy/mutex.h>
  27. #include <alchemy/sem.h>
  28. #include <alchemy/queue.h>
  29. //#include "monitor.h"
  30. //#include "robot.h"
  31. //#include "image.h"
  32. //#include "message.h"
  33. //#include "server.h"
  34. #include "messages.h"
  35. #include "commonitor.h"
  36. #include "comrobot.h"
  37. using namespace std;
  38. class Tasks {
  39. public:
  40. /**
  41. * @brief Initialisation des structures de l'application (tâches, mutex,
  42. * semaphore, etc.)
  43. */
  44. void Init();
  45. /**
  46. * @brief Démarrage des tâches
  47. */
  48. void Run();
  49. /**
  50. * @brief Arrêt des tâches
  51. */
  52. void Stop();
  53. /**
  54. */
  55. void Join() {
  56. rt_sem_broadcast(&sem_barrier);
  57. pause();
  58. }
  59. /**
  60. */
  61. bool AcceptClient() {
  62. return false;
  63. }
  64. private:
  65. ComMonitor monitor;
  66. ComRobot robot;
  67. RT_TASK th_server;
  68. RT_TASK th_sendToMon;
  69. RT_TASK th_receiveFromMon;
  70. RT_TASK th_openComRobot;
  71. RT_TASK th_startRobot;
  72. RT_TASK th_move;
  73. RT_MUTEX mutex_robotStarted;
  74. RT_MUTEX mutex_move;
  75. RT_SEM sem_barrier;
  76. RT_SEM sem_openComRobot;
  77. RT_SEM sem_serverOk;
  78. RT_SEM sem_startRobot;
  79. RT_QUEUE q_messageToMon;
  80. int etatCommMoniteur;
  81. int robotStarted;
  82. char robotMove;
  83. int MSG_QUEUE_SIZE;
  84. /**
  85. * \brief Thread handling server communication.
  86. */
  87. void f_server(void *arg);
  88. /**
  89. * \brief Thread handling communication to monitor.
  90. */
  91. void f_sendToMon(void *arg);
  92. /**
  93. * \brief Thread handling communication from monitor.
  94. */
  95. void f_receiveFromMon(void *arg);
  96. /**
  97. * \brief Thread handling opening of robot communication.
  98. */
  99. void f_openComRobot(void * arg);
  100. /**
  101. * \brief Thread handling robot mouvements.
  102. */
  103. void f_move(void *arg);
  104. /**
  105. * \brief Thread handling robot activation.
  106. */
  107. void f_startRobot(void *arg);
  108. };
  109. #endif // __WITH_PTHREAD__
  110. #endif // __TASKS_H__