Add sendBatteryLevel task

This commit is contained in:
Yohan Simard 2021-03-12 13:25:52 +01:00
parent a39a47bb97
commit 7f993019bc
2 changed files with 109 additions and 92 deletions

View file

@ -124,6 +124,12 @@ void Tasks::Init() {
cerr << "Error task create th_move: " << strerror(-err) << endl; cerr << "Error task create th_move: " << strerror(-err) << endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if ((err = rt_task_create(&th_sendBatteryLevel, "th_sendBatteryLevel", 0, PRIORITY_TBATTERY, 0))) {
cerr << "Error task create th_sendBatteryLevel: " << strerror(-err) << endl;
exit(EXIT_FAILURE);
}
cout << "Tasks created successfully" << endl; cout << "Tasks created successfully" << endl;
/* ************************************************************************************* /* *************************************************************************************
@ -168,6 +174,10 @@ void Tasks::Run() {
cerr << "Error task start MoveTask: " << strerror(-err) << endl; cerr << "Error task start MoveTask: " << strerror(-err) << endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (err = rt_task_start(&th_sendBatteryLevel, (void (*)(void *)) &Tasks::SendBatteryLevel, this)) {
cerr << "Error task start SendBatteryLevel: " << strerror(-err) << endl;
exit(EXIT_FAILURE);
}
cout << "Tasks launched" << endl; cout << "Tasks launched" << endl;
} }
@ -330,7 +340,7 @@ void Tasks::ReceiveFromMonTask(void *arg) {
rt_sem_p(&sem_startRobot, TM_INFINITE); rt_sem_p(&sem_startRobot, TM_INFINITE);
cout << "Start robot without watchdog ("; cout << "Start robot without watchdog (";
rt_mutex_acquire(&mutex_robot, TM_INFINITE); rt_mutex_acquire(&mutex_robot, TM_INFINITE);
msgSend = robot.Write(robot.StartWithoutWD()); msgSend = robot.Write(ComRobot::StartWithoutWD());
rt_mutex_release(&mutex_robot); rt_mutex_release(&mutex_robot);
cout << msgSend->GetID(); cout << msgSend->GetID();
cout << ")" << endl; cout << ")" << endl;

View file

@ -133,6 +133,13 @@ private:
*/ */
[[noreturn]] void MoveTask(void *arg); [[noreturn]] void MoveTask(void *arg);
/**
* @brief Thread handling battery level sending.
*/
[[noreturn]] void SendBatteryLevel(void *arg);
/* ********************************************************************* /* *********************************************************************
* Queue services * Queue services
* ********************************************************************/ * ********************************************************************/