Added acknowledge, created SendToRobot()

This commit is contained in:
Robin Marin-Muller 2024-04-04 17:55:02 +02:00
parent b7fae99df4
commit c67814a39b
3 changed files with 19 additions and 13 deletions

View file

@ -1,4 +1,4 @@
#Thu Apr 04 17:21:41 CEST 2024 #Thu Apr 04 17:49:31 CEST 2024
/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/main.cpp=c1712238648769 /home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/main.cpp=c1712238648769
/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/nbproject/Makefile-Debug__PC_.mk=c1712238648773 /home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/nbproject/Makefile-Debug__PC_.mk=c1712238648773
/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/nbproject/private/Makefile-variables.mk=c1712238648790 /home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/nbproject/private/Makefile-variables.mk=c1712238648790
@ -8,13 +8,13 @@
/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/nbproject/Makefile-Debug__RPI_.mk=c1712238648775 /home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/nbproject/Makefile-Debug__RPI_.mk=c1712238648775
/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/lib/.gitignore=c1712238648721 /home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/lib/.gitignore=c1712238648721
/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/nbproject/Package-Debug__PC_.bash=c1712238648782 /home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/nbproject/Package-Debug__PC_.bash=c1712238648782
/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/tasks.h=c1712243914675 /home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/tasks.h=c1712244813410
/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/README.md=c1712238648637 /home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/README.md=c1712238648637
/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/nbproject/project.xml=c1712238648826 /home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/nbproject/project.xml=c1712238648826
/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/nbproject/Makefile-impl.mk=c1712238648778 /home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/nbproject/Makefile-impl.mk=c1712238648778
/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/superviseur.doxygen=c1712238648829 /home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/superviseur.doxygen=c1712238648829
/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/lib/base64/README.md=c1712238648730 /home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/lib/base64/README.md=c1712238648730
/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/tasks.cpp=c1712244064711 /home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/tasks.cpp=c1712245729354
/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/lib/comrobot.cpp=c1712238648753 /home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/lib/comrobot.cpp=c1712238648753
/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/.dep.inc=c1712238648629 /home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/.dep.inc=c1712238648629
/home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/lib/img.h=c1712238648760 /home/marin-muller/Documents/4A/Robot/dumber/software/raspberry/superviseur-robot/lib/img.h=c1712238648760

View file

@ -487,6 +487,13 @@ Message *Tasks::ReadInQueue(RT_QUEUE *queue) {
/* OUR CODE */ /* OUR CODE */
void Tasks::SendToRobot(MessageID message)
{
rt_mutex_acquire(&mutex_monitor, TM_INFINITE);
WriteInQueue(&q_messageToMon, new Message(message));
rt_mutex_release(&mutex_monitor);
}
void Tasks::BatteryStatusTask(void * arg) { void Tasks::BatteryStatusTask(void * arg) {
// Variables // Variables
int rs(0); int rs(0);
@ -512,16 +519,9 @@ void Tasks::BatteryStatusTask(void * arg) {
getbatterytask = robotBatteryGet; getbatterytask = robotBatteryGet;
if ((rs != 0) && getbatterytask) { if ((rs != 0) && getbatterytask) {
rt_mutex_acquire(&mutex_robot, TM_INFINITE); SendToRobot(MESSAGE_ROBOT_BATTERY_GET);
Message* msg = robot.Write(new Message(MESSAGE_ROBOT_BATTERY_GET));
rt_mutex_release(&mutex_robot);
rt_mutex_acquire(&mutex_monitor, TM_INFINITE);
monitor.Write(msg);
rt_mutex_release(&mutex_monitor);
robotBatteryGet = false; robotBatteryGet = false;
getbatterytask = false; getbatterytask = false;
} }
rt_mutex_release(&mutex_batteryGet); rt_mutex_release(&mutex_batteryGet);
} }
@ -563,7 +563,10 @@ void Tasks::OpenCamera(void * arg)
if(is_opened) if(is_opened)
{ {
cameraStatus = CameraStatusEnum::OPENED; cameraStatus = CameraStatusEnum::OPENED;
std::cout << "Camera Opened" << std::endl; SendToRobot(MESSAGE_ANSWER_ACK);
}
else {
SendToRobot(MESSAGE_ANSWER_NACK);
} }
rt_mutex_release(&mutex_cameraStatus); rt_mutex_release(&mutex_cameraStatus);
} }
@ -626,8 +629,8 @@ void Tasks::CloseCamera(void * arg)
rt_mutex_release(&mutex_camera); rt_mutex_release(&mutex_camera);
rt_mutex_acquire(&mutex_cameraStatus, TM_INFINITE); rt_mutex_acquire(&mutex_cameraStatus, TM_INFINITE);
cameraStatus = CameraStatusEnum::CLOSED; cameraStatus = CameraStatusEnum::CLOSED;
std::cout << "Camera Closed" << std::endl;
rt_mutex_release(&mutex_cameraStatus); rt_mutex_release(&mutex_cameraStatus);
SendToRobot(MESSAGE_ANSWER_ACK);
} }
} }
} }

View file

@ -157,6 +157,9 @@ private:
void ImageCamera(void * arg); void ImageCamera(void * arg);
void CloseCamera(void * arg); void CloseCamera(void * arg);
// Utility functions
void SendToRobot(MessageID message);
/**********************************************************************/ /**********************************************************************/
/* Queue services */ /* Queue services */