Compare commits

..

No commits in common. "4ac28d8427b4540290c7dc8a5a8fd698af557b01" and "a100a35c08e7bd6715c853f99fe072c94014279a" have entirely different histories.

2 changed files with 29 additions and 56 deletions

View file

@ -7,9 +7,12 @@
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/> <editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2"> <open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group> <group>
<file>file:/home/gallois/Documents/insa4/S2/robot/Temps_Reel_Robot/software/raspberry/superviseur-robot/tasks.cpp</file> <file>file:/home_pers/pehladik/dumber/software/raspberry/superviseur-robot/lib/camera.h</file>
<file>file:/home/gallois/Documents/insa4/S2/robot/Temps_Reel_Robot/software/raspberry/superviseur-robot/lib/comrobot.cpp</file> <file>file:/home_pers/pehladik/dumber/software/raspberry/superviseur-robot/lib/messages.cpp</file>
<file>file:/home/gallois/Documents/insa4/S2/robot/Temps_Reel_Robot/software/raspberry/superviseur-robot/tasks.h</file> <file>file:/home_pers/pehladik/dumber/software/raspberry/superviseur-robot/tasks.h</file>
<file>file:/home_pers/pehladik/dumber/software/raspberry/superviseur-robot/lib/camera.cpp</file>
<file>file:/home_pers/pehladik/dumber/software/raspberry/superviseur-robot/tasks.cpp</file>
<file>file:/home_pers/pehladik/dumber/software/raspberry/superviseur-robot/lib/messages.h</file>
</group> </group>
</open-files> </open-files>
</project-private> </project-private>

View file

@ -97,11 +97,6 @@ void Tasks::Init() {
cerr << "Error semaphore create: " << strerror(-err) << endl << flush; cerr << "Error semaphore create: " << strerror(-err) << endl << flush;
exit(EXIT_FAILURE); 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; cout << "Semaphores created successfully" << endl << flush;
/**************************************************************************************/ /**************************************************************************************/
@ -229,22 +224,18 @@ void Tasks::ServerTask(void *arg) {
/**************************************************************************************/ /**************************************************************************************/
/* The task server starts here */ /* The task server starts here */
/**************************************************************************************/ /**************************************************************************************/
while(1){ rt_mutex_acquire(&mutex_monitor, TM_INFINITE);
rt_mutex_acquire(&mutex_monitor, TM_INFINITE); status = monitor.Open(SERVER_PORT);
status = monitor.Open(SERVER_PORT); rt_mutex_release(&mutex_monitor);
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);
} }
/** /**
@ -350,42 +341,21 @@ void Tasks::OpenComRobot(void *arg) {
/* The task openComRobot starts here */ /* The task openComRobot starts here */
/**************************************************************************************/ /**************************************************************************************/
while (1) { while (1) {
Message * msg; rt_sem_p(&sem_openComRobot, TM_INFINITE);
msg=ReadInQueue(&q_messageComRobot); cout << "Open serial com (";
if(msg->CompareID(MESSAGE_ROBOT_COM_OPEN)){ rt_mutex_acquire(&mutex_robot, TM_INFINITE);
cout << "Open serial com ("; status = robot.Open();
rt_mutex_acquire(&mutex_robot, TM_INFINITE); rt_mutex_release(&mutex_robot);
status = robot.Open(); cout << status;
rt_mutex_release(&mutex_robot); cout << ")" << endl << flush;
cout << status;
cout << ")" << endl << flush;
Message * msgSend; Message * msgSend;
if (status < 0) { if (status < 0) {
msgSend = new Message(MESSAGE_ANSWER_NACK); msgSend = new Message(MESSAGE_ANSWER_NACK);
} else { } else {
msgSend = new Message(MESSAGE_ANSWER_ACK); 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
} }
delete(msg); WriteInQueue(&q_messageToMon, msgSend); // msgSend will be deleted by sendToMon
//rt_sem_p(&sem_openComRobot, TM_INFINITE);
} }
} }