eive-obsw/bsp_linux_board/InitMission.cpp

268 lines
10 KiB
C++
Raw Normal View History

2020-12-29 13:59:31 +01:00
#include "InitMission.h"
2021-03-04 18:29:28 +01:00
2022-05-29 17:52:13 +02:00
#include <fsfw/devicehandlers/DeviceHandlerIF.h>
2022-01-17 15:58:27 +01:00
#include <fsfw/objectmanager/ObjectManager.h>
2020-09-30 17:17:01 +02:00
#include <fsfw/objectmanager/ObjectManagerIF.h>
2022-08-24 17:27:47 +02:00
#include <fsfw/returnvalues/returnvalue.h>
2021-03-04 18:29:28 +01:00
#include <fsfw/serviceinterface/ServiceInterface.h>
2020-09-30 17:17:01 +02:00
#include <fsfw/tasks/FixedTimeslotTaskIF.h>
#include <fsfw/tasks/PeriodicTaskIF.h>
#include <fsfw/tasks/TaskFactory.h>
#include <linux/InitMission.h>
2022-01-17 15:58:27 +01:00
#include <mission/utility/InitMission.h>
2020-09-30 17:17:01 +02:00
#include <iostream>
2022-01-17 15:58:27 +01:00
#include "OBSWConfig.h"
#include "ObjectFactory.h"
#include "objects/systemObjectList.h"
#include "pollingsequence/pollingSequenceFactory.h"
2020-09-30 21:07:30 +02:00
ServiceInterfaceStream sif::debug("DEBUG");
ServiceInterfaceStream sif::info("INFO");
ServiceInterfaceStream sif::warning("WARNING");
2021-01-14 00:40:30 +01:00
ServiceInterfaceStream sif::error("ERROR");
2020-09-30 17:17:01 +02:00
2022-01-17 15:58:27 +01:00
ObjectManagerIF* objectManager = nullptr;
2020-09-30 17:17:01 +02:00
2021-03-04 18:29:28 +01:00
void initmission::initMission() {
2022-01-17 15:58:27 +01:00
sif::info << "Building global objects.." << std::endl;
/* Instantiate global object manager and also create all objects */
ObjectManager::instance()->setObjectFactoryFunction(ObjectFactory::produce, nullptr);
sif::info << "Initializing all objects.." << std::endl;
ObjectManager::instance()->initialize();
/* This function creates and starts all tasks */
initTasks();
2020-09-30 17:17:01 +02:00
}
2021-03-04 18:29:28 +01:00
void initmission::initTasks() {
2022-01-17 15:58:27 +01:00
TaskFactory* factory = TaskFactory::instance();
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
2022-01-17 15:58:27 +01:00
if (factory == nullptr) {
/* Should never happen ! */
return;
}
2021-03-04 18:29:28 +01:00
#if OBSW_PRINT_MISSED_DEADLINES == 1
2022-01-17 15:58:27 +01:00
void (*missedDeadlineFunc)(void) = TaskFactory::printMissedDeadline;
2021-03-04 18:29:28 +01:00
#else
2022-01-17 15:58:27 +01:00
void (*missedDeadlineFunc)(void) = nullptr;
2021-03-04 18:29:28 +01:00
#endif
2022-01-17 15:58:27 +01:00
/* TMTC Distribution */
PeriodicTaskIF* tmTcDistributor = factory->createPeriodicTask(
"DIST", 40, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.2, missedDeadlineFunc);
result = tmTcDistributor->addComponent(objects::CCSDS_PACKET_DISTRIBUTOR);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-01-17 15:58:27 +01:00
sif::error << "Object add component failed" << std::endl;
}
result = tmTcDistributor->addComponent(objects::PUS_PACKET_DISTRIBUTOR);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-01-17 15:58:27 +01:00
sif::error << "Object add component failed" << std::endl;
}
result = tmTcDistributor->addComponent(objects::TM_FUNNEL);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-01-17 15:58:27 +01:00
sif::error << "Object add component failed" << std::endl;
}
/* UDP bridge */
2022-02-05 13:19:20 +01:00
PeriodicTaskIF* tmtcBridgeTask = factory->createPeriodicTask(
"TMTC_BRIDGE", 50, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.2, missedDeadlineFunc);
result = tmtcBridgeTask->addComponent(objects::TMTC_BRIDGE);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-02-05 13:19:20 +01:00
sif::error << "Add component TMTC Bridge failed" << std::endl;
2022-01-17 15:58:27 +01:00
}
2022-02-05 13:19:20 +01:00
PeriodicTaskIF* tmtcPollingTask = factory->createPeriodicTask(
"TMTC_POLLING", 80, PeriodicTaskIF::MINIMUM_STACK_SIZE, 2.0, missedDeadlineFunc);
result = tmtcPollingTask->addComponent(objects::TMTC_POLLING_TASK);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-02-05 13:19:20 +01:00
sif::error << "Add component TMTC Polling failed" << std::endl;
2022-01-17 15:58:27 +01:00
}
#if OBSW_ADD_SCEX_DEVICE == 1
PeriodicTaskIF* scexDevHandler;
PeriodicTaskIF* scexReaderTask;
scheduling::schedulingScex(*factory, scexDevHandler, scexReaderTask);
2022-05-30 20:52:45 +02:00
#endif
2022-01-17 15:58:27 +01:00
/* PUS Services */
std::vector<PeriodicTaskIF*> pusTasks;
createPusTasks(*factory, missedDeadlineFunc, pusTasks);
std::vector<PeriodicTaskIF*> pstTasks;
createPstTasks(*factory, missedDeadlineFunc, pstTasks);
#if OBSW_ADD_TEST_CODE == 1
std::vector<PeriodicTaskIF*> testTasks;
createTestTasks(*factory, missedDeadlineFunc, pstTasks);
#endif /* OBSW_ADD_TEST_CODE == 1 */
2021-09-22 14:04:39 +02:00
2022-01-17 15:58:27 +01:00
auto taskStarter = [](std::vector<PeriodicTaskIF*>& taskVector, std::string name) {
for (const auto& task : taskVector) {
if (task != nullptr) {
task->startTask();
} else {
sif::error << "Task in vector " << name << " is invalid!" << std::endl;
}
2020-09-30 17:17:01 +02:00
}
2022-01-17 15:58:27 +01:00
};
2021-09-22 14:27:01 +02:00
2022-01-17 15:58:27 +01:00
sif::info << "Starting tasks.." << std::endl;
tmTcDistributor->startTask();
2022-02-05 13:19:20 +01:00
tmtcBridgeTask->startTask();
tmtcPollingTask->startTask();
taskStarter(pusTasks, "PUS Tasks");
#if OBSW_ADD_TEST_CODE == 1
taskStarter(testTasks, "Test Tasks");
#endif /* OBSW_ADD_TEST_CODE == 1 */
2022-01-17 15:58:27 +01:00
taskStarter(pstTasks, "PST Tasks");
2021-09-22 14:27:01 +02:00
#if OBSW_ADD_SCEX_DEVICE == 1
2022-05-26 12:04:27 +02:00
scexDevHandler->startTask();
2022-06-21 16:44:14 +02:00
scexReaderTask->startTask();
2022-05-26 12:04:27 +02:00
#endif
#if OBSW_ADD_TEST_PST == 1
if (startTestPst) {
pstTestTask->startTask();
}
#endif /* RPI_TEST_ACS_BOARD == 1 */
2022-01-17 15:58:27 +01:00
sif::info << "Tasks started.." << std::endl;
2021-09-22 14:27:01 +02:00
}
void initmission::createPusTasks(TaskFactory& factory,
2022-01-17 15:58:27 +01:00
TaskDeadlineMissedFunction missedDeadlineFunc,
std::vector<PeriodicTaskIF*>& taskVec) {
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
2022-01-17 15:58:27 +01:00
PeriodicTaskIF* pusVerification = factory.createPeriodicTask(
"PUS_VERIF", 40, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.200, missedDeadlineFunc);
result = pusVerification->addComponent(objects::PUS_SERVICE_1_VERIFICATION);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-01-17 15:58:27 +01:00
sif::error << "Object add component failed" << std::endl;
}
taskVec.push_back(pusVerification);
PeriodicTaskIF* pusEvents = factory.createPeriodicTask(
"PUS_EVENTS", 60, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.200, missedDeadlineFunc);
result = pusEvents->addComponent(objects::PUS_SERVICE_5_EVENT_REPORTING);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-01-17 15:58:27 +01:00
initmission::printAddObjectError("PUS_EVENTS", objects::PUS_SERVICE_5_EVENT_REPORTING);
}
result = pusEvents->addComponent(objects::EVENT_MANAGER);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-01-17 15:58:27 +01:00
initmission::printAddObjectError("PUS_MGMT", objects::EVENT_MANAGER);
}
taskVec.push_back(pusEvents);
PeriodicTaskIF* pusHighPrio = factory.createPeriodicTask(
"PUS_HIGH_PRIO", 50, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.200, missedDeadlineFunc);
result = pusHighPrio->addComponent(objects::PUS_SERVICE_2_DEVICE_ACCESS);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-01-17 15:58:27 +01:00
initmission::printAddObjectError("PUS2", objects::PUS_SERVICE_2_DEVICE_ACCESS);
}
result = pusHighPrio->addComponent(objects::PUS_SERVICE_9_TIME_MGMT);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-01-17 15:58:27 +01:00
initmission::printAddObjectError("PUS9", objects::PUS_SERVICE_9_TIME_MGMT);
}
taskVec.push_back(pusHighPrio);
PeriodicTaskIF* pusMedPrio = factory.createPeriodicTask(
"PUS_MED_PRIO", 40, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.8, missedDeadlineFunc);
result = pusMedPrio->addComponent(objects::PUS_SERVICE_8_FUNCTION_MGMT);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-01-17 15:58:27 +01:00
initmission::printAddObjectError("PUS8", objects::PUS_SERVICE_8_FUNCTION_MGMT);
}
result = pusMedPrio->addComponent(objects::PUS_SERVICE_200_MODE_MGMT);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-01-17 15:58:27 +01:00
initmission::printAddObjectError("PUS200", objects::PUS_SERVICE_200_MODE_MGMT);
}
result = pusMedPrio->addComponent(objects::PUS_SERVICE_20_PARAMETERS);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-01-17 15:58:27 +01:00
initmission::printAddObjectError("PUS20", objects::PUS_SERVICE_20_PARAMETERS);
}
result = pusMedPrio->addComponent(objects::PUS_SERVICE_3_HOUSEKEEPING);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-01-17 15:58:27 +01:00
initmission::printAddObjectError("PUS3", objects::PUS_SERVICE_3_HOUSEKEEPING);
}
taskVec.push_back(pusMedPrio);
PeriodicTaskIF* pusLowPrio = factory.createPeriodicTask(
"PUS_LOW_PRIO", 30, PeriodicTaskIF::MINIMUM_STACK_SIZE, 1.6, missedDeadlineFunc);
result = pusLowPrio->addComponent(objects::PUS_SERVICE_17_TEST);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-01-17 15:58:27 +01:00
initmission::printAddObjectError("PUS17", objects::PUS_SERVICE_17_TEST);
}
result = pusLowPrio->addComponent(objects::INTERNAL_ERROR_REPORTER);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-01-17 15:58:27 +01:00
initmission::printAddObjectError("INT_ERR_RPRT", objects::INTERNAL_ERROR_REPORTER);
}
taskVec.push_back(pusLowPrio);
2021-09-22 14:04:39 +02:00
}
void initmission::createPstTasks(TaskFactory& factory,
TaskDeadlineMissedFunction missedDeadlineFunc,
std::vector<PeriodicTaskIF*>& taskVec) {
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
#if OBSW_ADD_SPI_TEST_CODE == 0
FixedTimeslotTaskIF* spiPst = factory.createFixedTimeslotTask(
2022-03-31 17:58:16 +02:00
"SPI_PST", 70, PeriodicTaskIF::MINIMUM_STACK_SIZE * 4, 1.0, missedDeadlineFunc);
result = pst::pstSpi(spiPst);
2022-08-30 18:36:00 +02:00
if (result != returnvalue::OK) {
2022-06-21 16:44:14 +02:00
if (result != FixedTimeslotTaskIF::SLOT_LIST_EMPTY) {
2022-08-30 16:51:30 +02:00
sif::error << "InitMission::createPstTasks: Creating PST failed!" << std::endl;
2022-06-21 16:44:14 +02:00
}
} else {
taskVec.push_back(spiPst);
}
#endif
}
void initmission::createTestTasks(TaskFactory& factory,
TaskDeadlineMissedFunction missedDeadlineFunc,
std::vector<PeriodicTaskIF*>& taskVec) {
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
PeriodicTaskIF* testTask = factory.createPeriodicTask(
"TEST_TASK", 40, PeriodicTaskIF::MINIMUM_STACK_SIZE, 2.0, missedDeadlineFunc);
result = testTask->addComponent(objects::TEST_TASK);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
initmission::printAddObjectError("TEST_TASK", objects::TEST_TASK);
}
2022-02-22 13:50:46 +01:00
#if OBSW_ADD_SPI_TEST_CODE == 1
result = testTask->addComponent(objects::SPI_TEST);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
initmission::printAddObjectError("SPI_TEST", objects::SPI_TEST);
}
#endif /* RPI_ADD_SPI_TEST == 1 */
#if RPI_ADD_GPIO_TEST == 1
result = testTask->addComponent(objects::LIBGPIOD_TEST);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
initmission::printAddObjectError("GPIOD_TEST", objects::LIBGPIOD_TEST);
}
#endif /* RPI_ADD_GPIO_TEST == 1 */
2022-02-22 13:50:46 +01:00
#if OBSW_ADD_UART_TEST_CODE == 1
result = testTask->addComponent(objects::UART_TEST);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
initmission::printAddObjectError("UART_TEST", objects::UART_TEST);
}
2022-03-25 17:48:38 +01:00
PeriodicTaskIF* scexReaderTask = factory.createPeriodicTask(
2022-04-08 19:12:21 +02:00
"SCEX_UART_READER", 20, PeriodicTaskIF::MINIMUM_STACK_SIZE, 2.0, missedDeadlineFunc);
result = scexReaderTask->addComponent(objects::SCEX_UART_READER);
2022-08-30 18:36:00 +02:00
if (result != returnvalue::OK) {
2022-04-08 19:12:21 +02:00
initmission::printAddObjectError("SCEX_UART_READER", objects::SCEX_UART_READER);
}
2022-03-25 17:48:38 +01:00
taskVec.push_back(scexReaderTask);
2022-04-08 19:12:21 +02:00
#endif /* RPI_ADD_GPIO_TEST == 1 */
2022-02-22 13:50:46 +01:00
taskVec.push_back(testTask);
bool startTestPst = true;
static_cast<void>(startTestPst);
#if OBSW_ADD_TEST_PST == 1
FixedTimeslotTaskIF* pstTestTask = factory->createFixedTimeslotTask(
"TEST_PST", 50, PeriodicTaskIF::MINIMUM_STACK_SIZE * 2, 2.0, missedDeadlineFunc);
result = pst::pstTest(pstTestTask);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
sif::info << "initmission::initTasks: ACS PST empty or invalid" << std::endl;
startTestPst = false;
}
#endif /* RPI_TEST_ACS_BOARD == 1 */
}