More reformatting
This commit is contained in:
parent
2673651834
commit
7d3372a443
2 changed files with 23 additions and 24 deletions
|
@ -18,6 +18,8 @@
|
|||
#include "tasks.h"
|
||||
#include <stdexcept>
|
||||
|
||||
using namespace std;
|
||||
|
||||
// Déclaration des priorités des taches
|
||||
#define PRIORITY_TSERVER 30
|
||||
#define PRIORITY_TOPENCOMROBOT 20
|
||||
|
@ -42,7 +44,7 @@
|
|||
*
|
||||
* 5- Same behavior existe for ComMonitor::Write !
|
||||
*
|
||||
* 6- When you want to write something in terminal, use cout and terminate with endl and flush
|
||||
* 6- When you want to write something in terminal, use cout and terminate with endl
|
||||
*
|
||||
* 7- Good luck !
|
||||
*/
|
||||
|
@ -151,31 +153,31 @@ void Tasks::Run() {
|
|||
rt_task_set_priority(nullptr, T_LOPRIO);
|
||||
int err;
|
||||
|
||||
if (err = rt_task_start(&th_server, (void (*)(void *)) &Tasks::ServerTask, this)) {
|
||||
if (err = rt_task_start(&th_server, reinterpret_cast<void (*)(void *)>(&Tasks::ServerTask), this)) {
|
||||
cerr << "Error task start ServerTask: " << strerror(-err) << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (err = rt_task_start(&th_sendToMon, (void (*)(void *)) &Tasks::SendToMonTask, this)) {
|
||||
if (err = rt_task_start(&th_sendToMon, reinterpret_cast<void (*)(void *)>(&Tasks::SendToMonTask), this)) {
|
||||
cerr << "Error task start SendToMonTask: " << strerror(-err) << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (err = rt_task_start(&th_receiveFromMon, (void (*)(void *)) &Tasks::ReceiveFromMonTask, this)) {
|
||||
if (err = rt_task_start(&th_receiveFromMon, reinterpret_cast<void (*)(void *)>(&Tasks::ReceiveFromMonTask), this)) {
|
||||
cerr << "Error task start ReceiveFromMonTask: " << strerror(-err) << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (err = rt_task_start(&th_openComRobot, (void (*)(void *)) &Tasks::OpenComRobot, this)) {
|
||||
if (err = rt_task_start(&th_openComRobot, reinterpret_cast<void (*)(void *)>(&Tasks::OpenComRobot), this)) {
|
||||
cerr << "Error task start OpenComRobot: " << strerror(-err) << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (err = rt_task_start(&th_startRobot, (void (*)(void *)) &Tasks::StartRobotTask, this)) {
|
||||
if (err = rt_task_start(&th_startRobot, reinterpret_cast<void (*)(void *)>(&Tasks::StartRobotTask), this)) {
|
||||
cerr << "Error task start StartRobotTask: " << strerror(-err) << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (err = rt_task_start(&th_move, (void (*)(void *)) &Tasks::MoveTask, this)) {
|
||||
if (err = rt_task_start(&th_move, reinterpret_cast<void (*)(void *)>(&Tasks::MoveTask), this)) {
|
||||
cerr << "Error task start MoveTask: " << strerror(-err) << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (err = rt_task_start(&th_sendBatteryLevel, (void (*)(void *)) &Tasks::SendBatteryLevel, this)) {
|
||||
if (err = rt_task_start(&th_sendBatteryLevel, reinterpret_cast<void (*)(void *)>(&Tasks::SendBatteryLevel), this)) {
|
||||
cerr << "Error task start SendBatteryLevel: " << strerror(-err) << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
@ -219,8 +221,8 @@ void Tasks::ServerTask(void *arg) {
|
|||
cout << "Open server on port " << (SERVER_PORT) << " (" << status << ")" << endl;
|
||||
|
||||
if (status < 0)
|
||||
throw std::runtime_error{
|
||||
"Unable to start server on port " + std::to_string(SERVER_PORT)
|
||||
throw runtime_error{
|
||||
"Unable to start server on port " + to_string(SERVER_PORT)
|
||||
};
|
||||
monitor.AcceptClient(); // Wait the monitor client
|
||||
cout << "Rock'n'Roll baby, client accepted!" << endl;
|
||||
|
@ -314,7 +316,7 @@ void Tasks::ReceiveFromMonTask(void *arg) {
|
|||
status = robot.Open();
|
||||
rt_mutex_release(&mutex_robot);
|
||||
cout << status;
|
||||
cout << ")" << endl << flush;
|
||||
cout << ")" << endl;
|
||||
|
||||
Message *msgSend;
|
||||
if (status < 0) {
|
||||
|
@ -361,7 +363,7 @@ void Tasks::ReceiveFromMonTask(void *arg) {
|
|||
|
||||
[[noreturn]] void Tasks::SendBatteryLevel(void *arg) {
|
||||
int rs;
|
||||
cout << "Start " << __PRETTY_FUNCTION__ << endl << flush;
|
||||
cout << "Start " << __PRETTY_FUNCTION__ << endl;
|
||||
// Synchronization barrier (waiting that all tasks are starting)
|
||||
rt_sem_p(&sem_barrier, TM_INFINITE);
|
||||
|
||||
|
@ -369,7 +371,7 @@ void Tasks::ReceiveFromMonTask(void *arg) {
|
|||
/* The task sendBatteryLevel starts here */
|
||||
/* *************************************************************************************/
|
||||
|
||||
rt_task_set_periodic(nullptr, TM_NOW, 500000000); // 500 ms //TODO
|
||||
rt_task_set_periodic(nullptr, TM_NOW, 500000000); // 500 ms
|
||||
|
||||
while (true) {
|
||||
rt_task_wait_period(nullptr);
|
||||
|
@ -380,8 +382,7 @@ void Tasks::ReceiveFromMonTask(void *arg) {
|
|||
rt_mutex_release(&mutex_robotStarted);
|
||||
if (rs == 1) {
|
||||
rt_mutex_acquire(&mutex_robot, TM_INFINITE);
|
||||
auto battRequest = new Message(MESSAGE_ROBOT_BATTERY_GET);
|
||||
auto msg = dynamic_cast<MessageBattery *>(robot.Write(battRequest));
|
||||
auto msg = dynamic_cast<MessageBattery *>(robot.Write(ComRobot::GetBattery()));
|
||||
if (msg == nullptr) {
|
||||
cout << "NULLPTR" << endl;
|
||||
} else {
|
||||
|
@ -407,7 +408,7 @@ void Tasks::ReceiveFromMonTask(void *arg) {
|
|||
/* **************************************************************************************
|
||||
* The task starts here
|
||||
* *************************************************************************************/
|
||||
rt_task_set_periodic(nullptr, TM_NOW, 100000000);
|
||||
rt_task_set_periodic(nullptr, TM_NOW, 100000000); // 100 ms
|
||||
|
||||
while (true) {
|
||||
rt_task_wait_period(nullptr);
|
||||
|
@ -426,7 +427,7 @@ void Tasks::ReceiveFromMonTask(void *arg) {
|
|||
robot.Write(new Message((MessageID) cpMove));
|
||||
rt_mutex_release(&mutex_robot);
|
||||
}
|
||||
cout << endl << flush;
|
||||
cout << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -439,7 +440,7 @@ void Tasks::WriteInQueue(RT_QUEUE *queue, Message *msg) {
|
|||
int err;
|
||||
if ((err = rt_queue_write(queue, (const void *) &msg, sizeof((const void *) &msg), Q_NORMAL)) < 0) {
|
||||
cerr << "Write in queue failed: " << strerror(-err) << endl;
|
||||
throw std::runtime_error{"Error in write in queue"};
|
||||
throw runtime_error{"Error in write in queue"};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -454,9 +455,9 @@ Message *Tasks::ReadInQueue(RT_QUEUE *queue) {
|
|||
|
||||
if ((err = rt_queue_read(queue, &msg, sizeof((void *) &msg), TM_INFINITE)) < 0) {
|
||||
cout << "Read in queue failed: " << strerror(-err) << endl;
|
||||
throw std::runtime_error{"Error in read in queue"};
|
||||
throw runtime_error{"Error in read in queue"};
|
||||
}/** else {
|
||||
cout << "@msg :" << msg << endl << flush;
|
||||
cout << "@msg :" << msg << endl;
|
||||
} **/
|
||||
|
||||
return msg;
|
||||
|
|
|
@ -34,8 +34,6 @@
|
|||
#include "camera.h"
|
||||
#include "img.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Tasks {
|
||||
public:
|
||||
/**
|
||||
|
@ -149,14 +147,14 @@ private:
|
|||
* @param queue Queue identifier
|
||||
* @param msg Message to be stored
|
||||
*/
|
||||
void WriteInQueue(RT_QUEUE *queue, Message *msg);
|
||||
static void WriteInQueue(RT_QUEUE *queue, Message *msg);
|
||||
|
||||
/**
|
||||
* Read a message from a given queue, block if empty
|
||||
* @param queue Queue identifier
|
||||
* @return Message read
|
||||
*/
|
||||
Message *ReadInQueue(RT_QUEUE *queue);
|
||||
static Message *ReadInQueue(RT_QUEUE *queue);
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue