fsfw-example-hosted/bsp_hosted/core/InitMission.cpp

286 lines
9.8 KiB
C++
Raw Normal View History

2021-06-08 13:36:08 +02:00
#include <OBSWConfig.h>
#include <bsp_hosted/core/InitMission.h>
#include <bsp_hosted/fsfwconfig/objects/systemObjectList.h>
#include <bsp_hosted/fsfwconfig/pollingsequence/pollingSequenceFactory.h>
2021-10-17 23:28:24 +02:00
#include <fsfw/modes/HasModesIF.h>
2022-09-07 17:40:41 +02:00
#include <fsfw/retval.h>
2021-06-08 13:36:08 +02:00
#include <fsfw/serviceinterface/ServiceInterface.h>
#include <fsfw/tasks/FixedTimeslotTaskIF.h>
#include <fsfw/tasks/PeriodicTaskIF.h>
#include <fsfw/tasks/TaskFactory.h>
2021-10-17 23:28:24 +02:00
2022-05-05 20:55:48 +02:00
#include "example/utility/TaskCreation.h"
#include "fsfw_tests/integration/assemblies/TestAssembly.h"
2021-06-08 13:36:08 +02:00
#ifdef _WIN32
#include <fsfw/osal/windows/winTaskHelpers.h>
#endif
void InitMission::createTasks() {
2022-05-05 20:55:48 +02:00
TaskFactory* taskFactory = TaskFactory::instance();
if (taskFactory == nullptr) {
return;
}
2021-06-08 13:36:08 +02:00
2022-05-05 20:55:48 +02:00
TaskPriority currPrio;
2021-06-08 13:36:08 +02:00
#ifdef _WIN32
2022-05-05 20:55:48 +02:00
currPrio = tasks::makeWinPriority();
2021-06-08 13:36:08 +02:00
#endif
2022-05-05 20:55:48 +02:00
TaskDeadlineMissedFunction deadlineMissedFunc = nullptr;
2021-06-08 13:36:08 +02:00
#if OBSW_PRINT_MISSED_DEADLINES == 1
2022-05-05 20:55:48 +02:00
deadlineMissedFunc = TaskFactory::printMissedDeadline;
2021-06-08 13:36:08 +02:00
#endif
#if OBSW_ADD_CORE_COMPONENTS == 1
#ifdef __unix__
2022-05-05 20:55:48 +02:00
currPrio = 40;
2021-06-08 13:36:08 +02:00
#endif
2022-05-05 20:55:48 +02:00
/* TMTC Distribution */
PeriodicTaskIF* distributerTask = taskFactory->createPeriodicTask(
"DIST", currPrio, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.1, deadlineMissedFunc);
ReturnValue_t result = distributerTask->addComponent(objects::CCSDS_DISTRIBUTOR);
2022-09-07 17:40:41 +02:00
if (result != returnvalue::OK) {
2022-05-05 20:55:48 +02:00
task::printInitError("CCSDS distributor", objects::CCSDS_DISTRIBUTOR);
}
result = distributerTask->addComponent(objects::PUS_DISTRIBUTOR);
2022-09-07 17:40:41 +02:00
if (result != returnvalue::OK) {
2022-05-05 20:55:48 +02:00
task::printInitError("PUS distributor", objects::PUS_DISTRIBUTOR);
}
result = distributerTask->addComponent(objects::TM_FUNNEL);
2022-09-07 17:40:41 +02:00
if (result != returnvalue::OK) {
2022-05-05 20:55:48 +02:00
task::printInitError("TM funnel", objects::TM_FUNNEL);
}
2021-06-08 13:36:08 +02:00
#ifdef __unix__
2022-05-05 20:55:48 +02:00
currPrio = 50;
2021-06-08 13:36:08 +02:00
#endif
2022-05-05 20:55:48 +02:00
/* UDP bridge */
PeriodicTaskIF* udpBridgeTask = taskFactory->createPeriodicTask(
"TCPIP_TMTC_BRIDGE", currPrio, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.2, deadlineMissedFunc);
result = udpBridgeTask->addComponent(objects::TCPIP_TMTC_BRIDGE);
2022-09-07 17:40:41 +02:00
if (result != returnvalue::OK) {
2022-05-05 20:55:48 +02:00
task::printInitError("TMTC bridge", objects::TCPIP_TMTC_BRIDGE);
}
2021-06-08 13:36:08 +02:00
#ifdef __unix__
2022-05-05 20:55:48 +02:00
currPrio = 80;
2021-06-08 13:36:08 +02:00
#endif
2022-05-05 20:55:48 +02:00
PeriodicTaskIF* udpPollingTask = taskFactory->createPeriodicTask(
"TMTC_POLLING", currPrio, PeriodicTaskIF::MINIMUM_STACK_SIZE, 2.0, deadlineMissedFunc);
result = udpPollingTask->addComponent(objects::TCPIP_TMTC_POLLING_TASK);
2022-09-07 17:40:41 +02:00
if (result != returnvalue::OK) {
2022-05-05 20:55:48 +02:00
task::printInitError("TMTC polling", objects::TCPIP_TMTC_POLLING_TASK);
}
2021-06-08 13:36:08 +02:00
#ifdef __unix__
2022-05-05 20:55:48 +02:00
currPrio = 20;
2021-06-08 13:36:08 +02:00
#endif
2022-05-05 20:55:48 +02:00
PeriodicTaskIF* eventTask = taskFactory->createPeriodicTask(
"EVENT", currPrio, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.100, deadlineMissedFunc);
result = eventTask->addComponent(objects::EVENT_MANAGER);
2022-09-07 17:40:41 +02:00
if (result != returnvalue::OK) {
2022-05-05 20:55:48 +02:00
task::printInitError("Event Manager", objects::EVENT_MANAGER);
}
2021-06-08 13:36:08 +02:00
#endif /* OBSW_ADD_CORE_COMPONENTS == 1 */
#if OBSW_ADD_TASK_EXAMPLE == 1
#ifdef __unix__
2022-05-05 20:55:48 +02:00
currPrio = 50;
2021-06-08 13:36:08 +02:00
#endif
2022-05-05 20:55:48 +02:00
FixedTimeslotTaskIF* timeslotDemoTask = taskFactory->createFixedTimeslotTask(
"PST_TASK", currPrio, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.5, deadlineMissedFunc);
result = pst::pollingSequenceExamples(timeslotDemoTask);
2022-09-07 17:40:41 +02:00
if (result != returnvalue::OK) {
2021-06-08 13:36:08 +02:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
2022-05-05 20:55:48 +02:00
sif::error << "InitMission::createTasks: Timeslot demo task initialization failed!"
<< std::endl;
2021-06-08 13:36:08 +02:00
#else
2022-05-05 20:55:48 +02:00
sif::printError("InitMission::createTasks: Timeslot demo task initialization failed!\n");
2021-06-08 13:36:08 +02:00
#endif
2022-05-05 20:55:48 +02:00
}
2021-06-08 13:36:08 +02:00
#ifdef __unix__
2022-05-05 20:55:48 +02:00
currPrio = 40;
2021-06-08 13:36:08 +02:00
#endif
2022-05-05 20:55:48 +02:00
PeriodicTaskIF* readerTask = taskFactory->createPeriodicTask(
"READER_TASK", currPrio, PeriodicTaskIF::MINIMUM_STACK_SIZE, 1.0, deadlineMissedFunc);
result = readerTask->addComponent(objects::TEST_DUMMY_4);
2022-09-07 17:40:41 +02:00
if (result != returnvalue::OK) {
2022-05-05 20:55:48 +02:00
task::printInitError("Dummy 4", objects::TEST_DUMMY_4);
}
2021-06-08 13:36:08 +02:00
#endif /* OBSW_ADD_TASK_EXAMPLE == 1 */
#if OBSW_ADD_PUS_STACK == 1
2022-05-05 20:55:48 +02:00
/* PUS Services */
2021-06-08 13:36:08 +02:00
#ifdef __unix__
2022-05-05 20:55:48 +02:00
currPrio = 45;
2021-06-08 13:36:08 +02:00
#endif
2022-05-05 20:55:48 +02:00
PeriodicTaskIF* pusVerification = taskFactory->createPeriodicTask(
"PUS_VERIF_1", currPrio, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.200, deadlineMissedFunc);
result = pusVerification->addComponent(objects::PUS_SERVICE_1_VERIFICATION);
2022-09-07 17:40:41 +02:00
if (result != returnvalue::OK) {
2022-05-05 20:55:48 +02:00
task::printInitError("PUS 1", objects::PUS_SERVICE_1_VERIFICATION);
}
2021-06-08 13:36:08 +02:00
#ifdef __unix__
2022-05-05 20:55:48 +02:00
currPrio = 50;
2021-06-08 13:36:08 +02:00
#endif
2022-05-05 20:55:48 +02:00
PeriodicTaskIF* pusHighPrio = taskFactory->createPeriodicTask(
"PUS_HIGH_PRIO", currPrio, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.2, deadlineMissedFunc);
result = pusHighPrio->addComponent(objects::PUS_SERVICE_2_DEVICE_ACCESS);
2022-09-07 17:40:41 +02:00
if (result != returnvalue::OK) {
2022-05-05 20:55:48 +02:00
task::printInitError("PUS 2", objects::PUS_SERVICE_2_DEVICE_ACCESS);
}
result = pusHighPrio->addComponent(objects::PUS_SERVICE_5_EVENT_REPORTING);
2022-09-07 17:40:41 +02:00
if (result != returnvalue::OK) {
2022-05-05 20:55:48 +02:00
task::printInitError("PUS 5", objects::PUS_SERVICE_5_EVENT_REPORTING);
}
result = pusHighPrio->addComponent(objects::PUS_SERVICE_9_TIME_MGMT);
2022-09-07 17:40:41 +02:00
if (result != returnvalue::OK) {
2022-05-05 20:55:48 +02:00
task::printInitError("PUS 9", objects::PUS_SERVICE_9_TIME_MGMT);
}
2021-06-08 13:36:08 +02:00
#ifdef __unix__
2022-05-05 20:55:48 +02:00
currPrio = 40;
2021-06-08 13:36:08 +02:00
#endif
2022-05-05 20:55:48 +02:00
PeriodicTaskIF* pusMedPrio = taskFactory->createPeriodicTask(
"PUS_MED_PRIO", currPrio, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.6, deadlineMissedFunc);
result = pusMedPrio->addComponent(objects::PUS_SERVICE_3_HOUSEKEEPING);
2022-09-07 17:40:41 +02:00
if (result != returnvalue::OK) {
2022-05-05 20:55:48 +02:00
task::printInitError("PUS 3", objects::PUS_SERVICE_3_HOUSEKEEPING);
}
result = pusMedPrio->addComponent(objects::PUS_SERVICE_8_FUNCTION_MGMT);
2022-09-07 17:40:41 +02:00
if (result != returnvalue::OK) {
2022-05-05 20:55:48 +02:00
task::printInitError("PUS 8", objects::PUS_SERVICE_8_FUNCTION_MGMT);
}
result = pusMedPrio->addComponent(objects::PUS_SERVICE_20_PARAMETERS);
2022-09-07 17:40:41 +02:00
if (result != returnvalue::OK) {
2022-05-05 20:55:48 +02:00
task::printInitError("PUS 20", objects::PUS_SERVICE_20_PARAMETERS);
}
result = pusMedPrio->addComponent(objects::PUS_SERVICE_200_MODE_MGMT);
2022-09-07 17:40:41 +02:00
if (result != returnvalue::OK) {
2022-05-05 20:55:48 +02:00
task::printInitError("PUS 200", objects::PUS_SERVICE_200_MODE_MGMT);
}
2022-05-20 08:59:25 +02:00
result = pusMedPrio->addComponent(objects::PUS_SERVICE_11_TC_SCHEDULER);
2022-09-07 17:40:41 +02:00
if (result != returnvalue::OK) {
2022-05-20 08:59:25 +02:00
task::printInitError("PUS 11", objects::PUS_SERVICE_11_TC_SCHEDULER);
}
2021-06-08 13:36:08 +02:00
#ifdef __unix__
2022-05-05 20:55:48 +02:00
currPrio = 30;
2021-06-08 13:36:08 +02:00
#endif
2022-05-05 20:55:48 +02:00
PeriodicTaskIF* pusLowPrio = taskFactory->createPeriodicTask(
"PUS_LOW_PRIO", currPrio, PeriodicTaskIF::MINIMUM_STACK_SIZE, 1.2, deadlineMissedFunc);
result = pusLowPrio->addComponent(objects::PUS_SERVICE_17_TEST);
2022-09-07 17:40:41 +02:00
if (result != returnvalue::OK) {
2022-05-05 20:55:48 +02:00
task::printInitError("PUS 17", objects::PUS_SERVICE_17_TEST);
}
2021-06-08 13:36:08 +02:00
#endif /* OBSW_ADD_PUS_STACK == 1 */
#if OBSW_ADD_DEVICE_HANDLER_DEMO == 1
#ifdef __unix__
2022-05-05 20:55:48 +02:00
currPrio = 60;
2021-06-08 13:36:08 +02:00
#elif _WIN32
2022-05-05 20:55:48 +02:00
currPrio =
tasks::makeWinPriority(tasks::PriorityClass::CLASS_HIGH, tasks::PriorityNumber::HIGHEST);
2021-06-08 13:36:08 +02:00
#endif
2022-05-05 20:55:48 +02:00
FixedTimeslotTaskIF* testDevicesTimeslotTask = taskFactory->createFixedTimeslotTask(
"PST_TEST_TASK", currPrio, PeriodicTaskIF::MINIMUM_STACK_SIZE, 2.0, deadlineMissedFunc);
result = pst::pollingSequenceDevices(testDevicesTimeslotTask);
2022-09-07 17:40:41 +02:00
if (result != returnvalue::OK) {
2021-06-08 13:36:08 +02:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
2022-05-05 20:55:48 +02:00
sif::error << "InitMission::createTasks: Test PST initialization failed!" << std::endl;
2021-06-08 13:36:08 +02:00
#else
2022-05-05 20:55:48 +02:00
sif::printError("InitMission::createTasks: Test PST initialization failed!\n");
2021-06-08 13:36:08 +02:00
#endif
2022-05-05 20:55:48 +02:00
}
2021-06-08 13:36:08 +02:00
#if _WIN32
2022-05-05 20:55:48 +02:00
currPrio = tasks::makeWinPriority();
2021-06-08 13:36:08 +02:00
#endif
2022-05-05 20:55:48 +02:00
PeriodicTaskIF* assemblyTask = taskFactory->createPeriodicTask(
"ASS_TASK", currPrio, PeriodicTaskIF::MINIMUM_STACK_SIZE, 2.0, nullptr);
if (assemblyTask == nullptr) {
task::printInitError("ASS_TASK", objects::TEST_ASSEMBLY);
}
result = assemblyTask->addComponent(objects::TEST_ASSEMBLY);
2022-09-07 17:40:41 +02:00
if (result != returnvalue::OK) {
2022-05-05 20:55:48 +02:00
task::printInitError("ASS_TASK", objects::TEST_ASSEMBLY);
}
2021-06-08 13:36:08 +02:00
#endif /* OBSW_ADD_DEVICE_HANDLER_DEMO == 1 */
#if OBSW_ADD_CONTROLLER_DEMO == 1
#ifdef __unix__
2022-05-05 20:55:48 +02:00
currPrio = 45;
2021-06-08 13:36:08 +02:00
#endif
2022-05-05 20:55:48 +02:00
PeriodicTaskIF* controllerTask = taskFactory->createPeriodicTask(
"TEST_CTRL", currPrio, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.8, deadlineMissedFunc);
result = controllerTask->addComponent(objects::TEST_CONTROLLER);
2022-09-07 17:40:41 +02:00
if (result != returnvalue::OK) {
2022-05-05 20:55:48 +02:00
task::printInitError("Controller Task", objects::TEST_CONTROLLER);
}
2021-06-08 13:36:08 +02:00
#endif /* OBSW_ADD_CONTROLLER_DEMO == 1 */
#ifdef __unix__
2022-05-05 20:55:48 +02:00
currPrio = 15;
2021-06-08 13:36:08 +02:00
#endif
2022-05-05 20:55:48 +02:00
PeriodicTaskIF* testTask = TaskFactory::instance()->createPeriodicTask(
"TEST_TASK", currPrio, PeriodicTaskIF::MINIMUM_STACK_SIZE, 1.0, deadlineMissedFunc);
result = testTask->addComponent(objects::TEST_TASK);
2022-09-07 17:40:41 +02:00
if (result != returnvalue::OK) {
2022-05-05 20:55:48 +02:00
task::printInitError("Test Task", objects::TEST_TASK);
}
2021-06-08 13:36:08 +02:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
2022-05-05 20:55:48 +02:00
sif::info << "Starting tasks.." << std::endl;
2021-06-08 13:36:08 +02:00
#else
2022-05-05 20:55:48 +02:00
sif::printInfo("Starting tasks..\n");
2021-06-08 13:36:08 +02:00
#endif
#if OBSW_ADD_CORE_COMPONENTS == 1
2022-05-05 20:55:48 +02:00
distributerTask->startTask();
udpBridgeTask->startTask();
udpPollingTask->startTask();
eventTask->startTask();
2021-06-08 13:36:08 +02:00
#endif /* OBSW_ADD_CORE_COMPONENTS == 1 */
#if OBSW_ADD_PUS_STACK == 1
2022-05-05 20:55:48 +02:00
pusVerification->startTask();
pusHighPrio->startTask();
pusMedPrio->startTask();
pusLowPrio->startTask();
2021-06-08 13:36:08 +02:00
#endif /* OBSW_ADD_PUS_STACK == 1 */
#if OBSW_ADD_TASK_EXAMPLE == 1
2022-05-05 20:55:48 +02:00
timeslotDemoTask->startTask();
readerTask->startTask();
2021-06-08 13:36:08 +02:00
#endif /* OBSW_ADD_TASK_EXAMPLE == 1 */
#if OBSW_ADD_DEVICE_HANDLER_DEMO == 1
2022-05-05 20:55:48 +02:00
testDevicesTimeslotTask->startTask();
assemblyTask->startTask();
2021-06-08 13:36:08 +02:00
#endif /* OBSW_ADD_DEVICE_HANDLER_DEMO == 1 */
#if OBSW_ADD_CONTROLLER_DEMO == 1
2022-05-05 20:55:48 +02:00
controllerTask->startTask();
2021-06-08 13:36:08 +02:00
#endif /* OBSW_ADD_CONTROLLER_DEMO == 1 */
2022-05-05 20:55:48 +02:00
testTask->startTask();
2021-06-08 13:36:08 +02:00
#if FSFW_CPP_OSTREAM_ENABLED == 1
2022-05-05 20:55:48 +02:00
sif::info << "Tasks started.." << std::endl;
2021-06-08 13:36:08 +02:00
#else
2022-05-05 20:55:48 +02:00
sif::printInfo("Tasks started..\n");
2021-06-08 13:36:08 +02:00
#endif
#if OBSW_ADD_DEVICE_HANDLER_DEMO
2022-05-05 20:55:48 +02:00
auto* assembly = ObjectManager::instance()->get<HasModesIF>(objects::TEST_ASSEMBLY);
if (assembly == nullptr) {
return;
}
2021-06-08 13:36:08 +02:00
#endif /* OBSW_ADD_DEVICE_HANDLER_DEMO */
}