diff --git a/software/raspberry/superviseur-robot/nbproject/private/private.xml b/software/raspberry/superviseur-robot/nbproject/private/private.xml
index 40175b4..c5e3f05 100644
--- a/software/raspberry/superviseur-robot/nbproject/private/private.xml
+++ b/software/raspberry/superviseur-robot/nbproject/private/private.xml
@@ -7,12 +7,9 @@
- file:/home_pers/pehladik/dumber/software/raspberry/superviseur-robot/lib/camera.h
- file:/home_pers/pehladik/dumber/software/raspberry/superviseur-robot/lib/messages.cpp
- file:/home_pers/pehladik/dumber/software/raspberry/superviseur-robot/tasks.h
- file:/home_pers/pehladik/dumber/software/raspberry/superviseur-robot/lib/camera.cpp
- file:/home_pers/pehladik/dumber/software/raspberry/superviseur-robot/tasks.cpp
- file:/home_pers/pehladik/dumber/software/raspberry/superviseur-robot/lib/messages.h
+ file:/home/gallois/Documents/insa4/S2/robot/Temps_Reel_Robot/software/raspberry/superviseur-robot/tasks.cpp
+ file:/home/gallois/Documents/insa4/S2/robot/Temps_Reel_Robot/software/raspberry/superviseur-robot/lib/comrobot.cpp
+ file:/home/gallois/Documents/insa4/S2/robot/Temps_Reel_Robot/software/raspberry/superviseur-robot/tasks.h
diff --git a/software/raspberry/superviseur-robot/tasks.cpp b/software/raspberry/superviseur-robot/tasks.cpp
index 126e0b9..4d469f1 100644
--- a/software/raspberry/superviseur-robot/tasks.cpp
+++ b/software/raspberry/superviseur-robot/tasks.cpp
@@ -97,6 +97,11 @@ void Tasks::Init() {
cerr << "Error semaphore create: " << strerror(-err) << endl << flush;
exit(EXIT_FAILURE);
}
+ if (err = rt_sem_create(&sem_restartServer, NULL, 0, S_FIFO)) {
+ cerr << "Error semaphore create: " << strerror(-err) << endl << flush;
+ exit(EXIT_FAILURE);
+ }
+
cout << "Semaphores created successfully" << endl << flush;
/**************************************************************************************/
@@ -224,18 +229,22 @@ void Tasks::ServerTask(void *arg) {
/**************************************************************************************/
/* The task server starts here */
/**************************************************************************************/
- rt_mutex_acquire(&mutex_monitor, TM_INFINITE);
- status = monitor.Open(SERVER_PORT);
- rt_mutex_release(&mutex_monitor);
+ while(1){
+ rt_mutex_acquire(&mutex_monitor, TM_INFINITE);
+ status = monitor.Open(SERVER_PORT);
+ rt_mutex_release(&mutex_monitor);
- cout << "Open server on port " << (SERVER_PORT) << " (" << status << ")" << endl;
+ 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)
+ };
+ monitor.AcceptClient(); // Wait the monitor client
+ cout << "Rock'n'Roll baby, client accepted!" << endl << flush;
+ rt_sem_broadcast(&sem_serverOk);
+ rt_sem_p(&sem_restartServer);
+ }
- if (status < 0) throw std::runtime_error {
- "Unable to start server on port " + std::to_string(SERVER_PORT)
- };
- monitor.AcceptClient(); // Wait the monitor client
- cout << "Rock'n'Roll baby, client accepted!" << endl << flush;
- rt_sem_broadcast(&sem_serverOk);
}
/**
@@ -287,7 +296,8 @@ void Tasks::ReceiveFromMonTask(void *arg) {
delete(msgRcv);
exit(-1);
} else if (msgRcv->CompareID(MESSAGE_ROBOT_COM_OPEN)) {
- rt_sem_v(&sem_openComRobot);
+ //rt_sem_v(&sem_openComRobot);
+ WriteInQueue(&q_messageComRobot, msgRcv);
} else if (msgRcv->CompareID(MESSAGE_ROBOT_START_WITHOUT_WD)) {
rt_sem_v(&sem_startRobot);
} else if (msgRcv->CompareID(MESSAGE_ROBOT_GO_FORWARD) ||
@@ -319,21 +329,42 @@ void Tasks::OpenComRobot(void *arg) {
/* The task openComRobot starts here */
/**************************************************************************************/
while (1) {
- rt_sem_p(&sem_openComRobot, TM_INFINITE);
- cout << "Open serial com (";
- rt_mutex_acquire(&mutex_robot, TM_INFINITE);
- status = robot.Open();
- rt_mutex_release(&mutex_robot);
- cout << status;
- cout << ")" << endl << flush;
+ Message * msg;
+ msg=ReadInQueue(&q_messageComRobot);
+ if(msg->CompareID(MESSAGE_ROBOT_COM_OPEN)){
+ cout << "Open serial com (";
+ rt_mutex_acquire(&mutex_robot, TM_INFINITE);
+ status = robot.Open();
+ rt_mutex_release(&mutex_robot);
+ cout << status;
+ cout << ")" << endl << flush;
- Message * msgSend;
- if (status < 0) {
- msgSend = new Message(MESSAGE_ANSWER_NACK);
- } else {
- msgSend = new Message(MESSAGE_ANSWER_ACK);
+ Message * msgSend;
+ if (status < 0) {
+ msgSend = new Message(MESSAGE_ANSWER_NACK);
+ } else {
+ msgSend = new Message(MESSAGE_ANSWER_ACK);
+ }
+ WriteInQueue(&q_messageToMon, msgSend); // msgSend will be deleted by sendToMon
+ }else if(msg->CompareID(MESSAGE_ROBOT_COM_CLOSE)){
+ cout << "Close serial com (";
+ rt_mutex_acquire(&mutex_robot, TM_INFINITE);
+ status = robot.Close();
+ rt_mutex_release(&mutex_robot);
+ cout << status;
+ cout << ")" << endl << flush;
+
+ Message * msgSend;
+ if (status < 0) {
+ msgSend = new Message(MESSAGE_ANSWER_NACK);
+ } else {
+ msgSend = new Message(MESSAGE_ANSWER_ACK);
+ }
+ WriteInQueue(&q_messageToMon, msgSend); // msgSend will be deleted by sendToMon
}
- WriteInQueue(&q_messageToMon, msgSend); // msgSend will be deleted by sendToMon
+ delete(msg);
+ //rt_sem_p(&sem_openComRobot, TM_INFINITE);
+
}
}