From f76171f0b31f6337cf4b769b9fc3632febef38d8 Mon Sep 17 00:00:00 2001 From: moukhlis Date: Mon, 15 Mar 2021 10:20:40 +0100 Subject: [PATCH] Definition des threads, des mutex, semaphores et messagequeue --- software/raspberry/superviseur-robot/tasks.cpp | 18 ++++++++++++++++-- software/raspberry/superviseur-robot/tasks.h | 14 +++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/software/raspberry/superviseur-robot/tasks.cpp b/software/raspberry/superviseur-robot/tasks.cpp index 2094c5d..126e0b9 100644 --- a/software/raspberry/superviseur-robot/tasks.cpp +++ b/software/raspberry/superviseur-robot/tasks.cpp @@ -28,6 +28,8 @@ #define PRIORITY_TCAMERA 21 #define PRIORITY_TBATTERY 31 + + /* * Some remarks: * 1- This program is mostly a template. It shows you how to create tasks, semaphore @@ -137,8 +139,21 @@ void Tasks::Init() { cerr << "Error msg queue create: " << strerror(-err) << endl << flush; exit(EXIT_FAILURE); } + if ((err = rt_queue_create(&q_messageComRobot, "q_messageComRobot", sizeof (Message*)*50, Q_UNLIMITED, Q_FIFO)) < 0) { + cerr << "Error messageComRobot queue create: " << strerror(-err) << endl << flush; + exit(EXIT_FAILURE); + } + + if ((err = rt_queue_create(&q_messageControlRobot, "q_messageControlRobot", sizeof (Message*)*50, Q_UNLIMITED, Q_FIFO)) < 0) { + cerr << "Error messageControlRobot queue create: " << strerror(-err) << endl << flush; + exit(EXIT_FAILURE); + } + + if ((err = rt_queue_create(&q_messageControlCam, "q_messageControlCam", sizeof (Message*)*50, Q_UNLIMITED, Q_FIFO)) < 0) { + cerr << "Error messageControlCam queue create: " << strerror(-err) << endl << flush; + exit(EXIT_FAILURE); + } cout << "Queues created successfully" << endl << flush; - } /** @@ -455,7 +470,6 @@ void Tasks::ReadBattery(void *arg){ monitor.Write(msg); rt_mutex_release(&mutex_monitor); } - } cout << endl << flush; diff --git a/software/raspberry/superviseur-robot/tasks.h b/software/raspberry/superviseur-robot/tasks.h index 4176b3d..d042d1c 100644 --- a/software/raspberry/superviseur-robot/tasks.h +++ b/software/raspberry/superviseur-robot/tasks.h @@ -77,6 +77,9 @@ private: RT_TASK th_startRobot; RT_TASK th_move; RT_TASK th_getBattery; + RT_TASK th_watchDog; + RT_TASK th_controlCamera; + RT_TASK th_picture; /**********************************************************************/ /* Mutex */ @@ -85,7 +88,10 @@ private: RT_MUTEX mutex_robot; RT_MUTEX mutex_robotStarted; RT_MUTEX mutex_move; - + + RT_MUTEX mutex_camera; + RT_MUTEX mutex_controlStruct; + /**********************************************************************/ /* Semaphores */ /**********************************************************************/ @@ -93,6 +99,8 @@ private: RT_SEM sem_openComRobot; RT_SEM sem_serverOk; RT_SEM sem_startRobot; + + /**********************************************************************/ /* Message queues */ @@ -100,6 +108,10 @@ private: int MSG_QUEUE_SIZE; RT_QUEUE q_messageToMon; + RT_QUEUE q_messageComRobot; + RT_QUEUE q_messageControlRobot; + RT_QUEUE q_messageControlCam; + /**********************************************************************/ /* Tasks' functions */ /**********************************************************************/