2018-08-27 16:39:49 +02:00
|
|
|
/*
|
2018-11-13 15:48:02 +01:00
|
|
|
* Copyright (C) 2018 dimercur
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2018-08-27 16:39:49 +02:00
|
|
|
*/
|
|
|
|
|
2018-12-19 09:15:42 +01:00
|
|
|
#ifndef __TASKS_H__
|
|
|
|
#define __TASKS_H__
|
2018-08-27 16:39:49 +02:00
|
|
|
|
|
|
|
#include <unistd.h>
|
2019-01-17 15:18:19 +01:00
|
|
|
#include <iostream>
|
2018-08-27 16:39:49 +02:00
|
|
|
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <alchemy/task.h>
|
|
|
|
#include <alchemy/timer.h>
|
|
|
|
#include <alchemy/mutex.h>
|
|
|
|
#include <alchemy/sem.h>
|
|
|
|
#include <alchemy/queue.h>
|
|
|
|
|
2018-12-21 16:36:52 +01:00
|
|
|
#include "messages.h"
|
|
|
|
#include "commonitor.h"
|
|
|
|
#include "comrobot.h"
|
2019-01-17 15:18:19 +01:00
|
|
|
#include "camera.h"
|
|
|
|
#include "img.h"
|
2018-12-21 16:36:52 +01:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
class Tasks {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* @brief Initialisation des structures de l'application (tâches, mutex,
|
|
|
|
* semaphore, etc.)
|
|
|
|
*/
|
|
|
|
void Init();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Démarrage des tâches
|
|
|
|
*/
|
|
|
|
void Run();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Arrêt des tâches
|
|
|
|
*/
|
|
|
|
void Stop();
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
2019-01-17 15:18:19 +01:00
|
|
|
void Join();
|
2018-12-21 16:36:52 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
bool AcceptClient() {
|
2019-01-17 15:18:19 +01:00
|
|
|
return monitor.AcceptClient();
|
2018-12-21 16:36:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
ComMonitor monitor;
|
|
|
|
ComRobot robot;
|
|
|
|
|
2019-01-17 15:18:19 +01:00
|
|
|
bool sendImage=false;
|
|
|
|
bool sendPosition=false;
|
|
|
|
|
|
|
|
int counter;
|
|
|
|
bool flag;
|
|
|
|
|
|
|
|
bool showArena=false;
|
|
|
|
|
2018-12-21 16:36:52 +01:00
|
|
|
RT_TASK th_server;
|
|
|
|
RT_TASK th_sendToMon;
|
|
|
|
RT_TASK th_receiveFromMon;
|
|
|
|
RT_TASK th_openComRobot;
|
|
|
|
RT_TASK th_startRobot;
|
|
|
|
RT_TASK th_move;
|
2019-01-17 15:18:19 +01:00
|
|
|
RT_TASK th_camera;
|
2018-12-21 16:36:52 +01:00
|
|
|
|
|
|
|
RT_MUTEX mutex_robotStarted;
|
|
|
|
RT_MUTEX mutex_move;
|
|
|
|
|
|
|
|
RT_SEM sem_barrier;
|
|
|
|
RT_SEM sem_openComRobot;
|
|
|
|
RT_SEM sem_serverOk;
|
|
|
|
RT_SEM sem_startRobot;
|
|
|
|
|
|
|
|
RT_QUEUE q_messageToMon;
|
|
|
|
|
|
|
|
int etatCommMoniteur;
|
|
|
|
int robotStarted;
|
|
|
|
char robotMove;
|
|
|
|
|
|
|
|
int MSG_QUEUE_SIZE;
|
|
|
|
|
2019-01-17 15:18:19 +01:00
|
|
|
char mode_start;
|
|
|
|
|
2018-12-21 16:36:52 +01:00
|
|
|
/**
|
2019-01-17 15:18:19 +01:00
|
|
|
* Write a message in a given queue
|
|
|
|
* @param queue Queue identifier
|
|
|
|
* @param msg Message to be stored
|
2018-12-21 16:36:52 +01:00
|
|
|
*/
|
2019-01-17 15:18:19 +01:00
|
|
|
void WriteInQueue(RT_QUEUE *queue, Message *msg);
|
2018-12-21 16:36:52 +01:00
|
|
|
|
|
|
|
/**
|
2019-01-17 15:18:19 +01:00
|
|
|
* Read a message from a given queue, block if empty
|
|
|
|
* @param queue Queue identifier
|
|
|
|
* @return Message read
|
2018-12-21 16:36:52 +01:00
|
|
|
*/
|
2019-01-17 15:18:19 +01:00
|
|
|
Message *ReadInQueue(RT_QUEUE *queue);
|
|
|
|
|
2018-12-21 16:36:52 +01:00
|
|
|
/**
|
2019-01-17 15:18:19 +01:00
|
|
|
* @brief Thread handling server communication.
|
2018-12-21 16:36:52 +01:00
|
|
|
*/
|
2019-01-17 15:18:19 +01:00
|
|
|
void ReceiveFromMonTask(void *arg);
|
2018-12-21 16:36:52 +01:00
|
|
|
|
|
|
|
/**
|
2019-01-17 15:18:19 +01:00
|
|
|
* @brief Thread handling periodic image capture.
|
2018-12-21 16:36:52 +01:00
|
|
|
*/
|
2019-01-17 15:18:19 +01:00
|
|
|
void CameraTask(void *arg);
|
|
|
|
|
2018-12-21 16:36:52 +01:00
|
|
|
/**
|
2019-01-17 15:18:19 +01:00
|
|
|
* @brief Thread sending data to monitor.
|
2018-12-21 16:36:52 +01:00
|
|
|
*/
|
2019-01-17 15:18:19 +01:00
|
|
|
void SendToMonTask(void *arg);
|
|
|
|
// /**
|
|
|
|
// * \brief Thread handling server communication.
|
|
|
|
// */
|
|
|
|
// void f_server(void *arg);
|
|
|
|
//
|
|
|
|
// /**
|
|
|
|
// * \brief Thread handling communication to monitor.
|
|
|
|
// */
|
|
|
|
// void f_sendToMon(void *arg);
|
|
|
|
//
|
|
|
|
// /**
|
|
|
|
// * \brief Thread handling communication from monitor.
|
|
|
|
// */
|
|
|
|
// void f_receiveFromMon(void *arg);
|
|
|
|
//
|
|
|
|
// /**
|
|
|
|
// * \brief Thread handling opening of robot communication.
|
|
|
|
// */
|
|
|
|
// void f_openComRobot(void * arg);
|
|
|
|
//
|
|
|
|
// /**
|
|
|
|
// * \brief Thread handling robot mouvements.
|
|
|
|
// */
|
|
|
|
// void f_move(void *arg);
|
|
|
|
//
|
|
|
|
// /**
|
|
|
|
// * \brief Thread handling robot activation.
|
|
|
|
// */
|
|
|
|
// void f_startRobot(void *arg);
|
2018-12-21 16:36:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // __TASKS_H__
|
2018-08-27 16:39:49 +02:00
|
|
|
|