Definition des threads, des mutex, semaphores et messagequeue
This commit is contained in:
parent
cdf4ce64e9
commit
f76171f0b3
2 changed files with 29 additions and 3 deletions
|
@ -28,6 +28,8 @@
|
||||||
#define PRIORITY_TCAMERA 21
|
#define PRIORITY_TCAMERA 21
|
||||||
#define PRIORITY_TBATTERY 31
|
#define PRIORITY_TBATTERY 31
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Some remarks:
|
* Some remarks:
|
||||||
* 1- This program is mostly a template. It shows you how to create tasks, semaphore
|
* 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;
|
cerr << "Error msg queue create: " << strerror(-err) << endl << flush;
|
||||||
exit(EXIT_FAILURE);
|
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;
|
cout << "Queues created successfully" << endl << flush;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -455,7 +470,6 @@ void Tasks::ReadBattery(void *arg){
|
||||||
monitor.Write(msg);
|
monitor.Write(msg);
|
||||||
rt_mutex_release(&mutex_monitor);
|
rt_mutex_release(&mutex_monitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << endl << flush;
|
cout << endl << flush;
|
||||||
|
|
|
@ -77,6 +77,9 @@ private:
|
||||||
RT_TASK th_startRobot;
|
RT_TASK th_startRobot;
|
||||||
RT_TASK th_move;
|
RT_TASK th_move;
|
||||||
RT_TASK th_getBattery;
|
RT_TASK th_getBattery;
|
||||||
|
RT_TASK th_watchDog;
|
||||||
|
RT_TASK th_controlCamera;
|
||||||
|
RT_TASK th_picture;
|
||||||
|
|
||||||
/**********************************************************************/
|
/**********************************************************************/
|
||||||
/* Mutex */
|
/* Mutex */
|
||||||
|
@ -85,7 +88,10 @@ private:
|
||||||
RT_MUTEX mutex_robot;
|
RT_MUTEX mutex_robot;
|
||||||
RT_MUTEX mutex_robotStarted;
|
RT_MUTEX mutex_robotStarted;
|
||||||
RT_MUTEX mutex_move;
|
RT_MUTEX mutex_move;
|
||||||
|
|
||||||
|
RT_MUTEX mutex_camera;
|
||||||
|
RT_MUTEX mutex_controlStruct;
|
||||||
|
|
||||||
/**********************************************************************/
|
/**********************************************************************/
|
||||||
/* Semaphores */
|
/* Semaphores */
|
||||||
/**********************************************************************/
|
/**********************************************************************/
|
||||||
|
@ -93,6 +99,8 @@ private:
|
||||||
RT_SEM sem_openComRobot;
|
RT_SEM sem_openComRobot;
|
||||||
RT_SEM sem_serverOk;
|
RT_SEM sem_serverOk;
|
||||||
RT_SEM sem_startRobot;
|
RT_SEM sem_startRobot;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**********************************************************************/
|
/**********************************************************************/
|
||||||
/* Message queues */
|
/* Message queues */
|
||||||
|
@ -100,6 +108,10 @@ private:
|
||||||
int MSG_QUEUE_SIZE;
|
int MSG_QUEUE_SIZE;
|
||||||
RT_QUEUE q_messageToMon;
|
RT_QUEUE q_messageToMon;
|
||||||
|
|
||||||
|
RT_QUEUE q_messageComRobot;
|
||||||
|
RT_QUEUE q_messageControlRobot;
|
||||||
|
RT_QUEUE q_messageControlCam;
|
||||||
|
|
||||||
/**********************************************************************/
|
/**********************************************************************/
|
||||||
/* Tasks' functions */
|
/* Tasks' functions */
|
||||||
/**********************************************************************/
|
/**********************************************************************/
|
||||||
|
|
Loading…
Reference in a new issue