2022-03-17 14:28:32 +01:00
|
|
|
#include "InitMission.h"
|
|
|
|
|
|
|
|
#include <fsfw/objectmanager/ObjectManager.h>
|
|
|
|
#include <fsfw/objectmanager/ObjectManagerIF.h>
|
2022-08-24 17:27:47 +02:00
|
|
|
#include <fsfw/returnvalues/returnvalue.h>
|
2022-03-17 14:28:32 +01:00
|
|
|
#include <fsfw/serviceinterface/ServiceInterface.h>
|
|
|
|
#include <fsfw/tasks/FixedTimeslotTaskIF.h>
|
|
|
|
#include <fsfw/tasks/PeriodicTaskIF.h>
|
|
|
|
#include <fsfw/tasks/TaskFactory.h>
|
|
|
|
#include <mission/utility/InitMission.h>
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include "OBSWConfig.h"
|
|
|
|
#include "ObjectFactory.h"
|
|
|
|
#include "objects/systemObjectList.h"
|
|
|
|
#include "pollingsequence/pollingSequenceFactory.h"
|
|
|
|
|
|
|
|
ServiceInterfaceStream sif::debug("DEBUG");
|
|
|
|
ServiceInterfaceStream sif::info("INFO");
|
|
|
|
ServiceInterfaceStream sif::warning("WARNING");
|
|
|
|
ServiceInterfaceStream sif::error("ERROR");
|
|
|
|
|
|
|
|
ObjectManagerIF* objectManager = nullptr;
|
|
|
|
|
|
|
|
void initmission::initMission() {
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
void initmission::initTasks() {
|
|
|
|
TaskFactory* factory = TaskFactory::instance();
|
2022-08-24 17:27:47 +02:00
|
|
|
ReturnValue_t result = returnvalue::OK;
|
2022-03-17 14:28:32 +01:00
|
|
|
if (factory == nullptr) {
|
|
|
|
/* Should never happen ! */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#if OBSW_PRINT_MISSED_DEADLINES == 1
|
|
|
|
void (*missedDeadlineFunc)(void) = TaskFactory::printMissedDeadline;
|
|
|
|
#else
|
|
|
|
void (*missedDeadlineFunc)(void) = nullptr;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* 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-03-17 14:28:32 +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-03-17 14:28:32 +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-03-17 14:28:32 +01:00
|
|
|
sif::error << "Object add component failed" << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
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-03-17 14:28:32 +01:00
|
|
|
sif::error << "Add component TMTC Bridge failed" << std::endl;
|
|
|
|
}
|
|
|
|
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-03-17 14:28:32 +01:00
|
|
|
sif::error << "Add component TMTC Polling failed" << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* PUS Services */
|
|
|
|
std::vector<PeriodicTaskIF*> pusTasks;
|
|
|
|
createPusTasks(*factory, missedDeadlineFunc, pusTasks);
|
|
|
|
|
|
|
|
std::vector<PeriodicTaskIF*> pstTasks;
|
|
|
|
FixedTimeslotTaskIF* pst = factory->createFixedTimeslotTask(
|
2022-04-20 21:33:39 +02:00
|
|
|
"UART_PST", 70, PeriodicTaskIF::MINIMUM_STACK_SIZE * 4, 1.0, missedDeadlineFunc);
|
2022-03-17 14:28:32 +01:00
|
|
|
result = pst::pstUart(pst);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-03-17 14:28:32 +01:00
|
|
|
sif::error << "InitMission::initTasks: Creating PST failed!" << std::endl;
|
|
|
|
}
|
|
|
|
pstTasks.push_back(pst);
|
|
|
|
|
2022-04-10 18:46:39 +02:00
|
|
|
#if OBSW_ADD_PLOC_MPSOC == 1
|
2022-03-17 14:28:32 +01:00
|
|
|
PeriodicTaskIF* mpsocHelperTask = factory->createPeriodicTask(
|
|
|
|
"PLOC_MPSOC_HELPER", 20, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.2, missedDeadlineFunc);
|
2022-03-17 19:51:00 +01:00
|
|
|
result = mpsocHelperTask->addComponent(objects::PLOC_MPSOC_HELPER);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-03-17 14:28:32 +01:00
|
|
|
initmission::printAddObjectError("PLOC_MPSOC_HELPER", objects::PLOC_MPSOC_HELPER);
|
|
|
|
}
|
2022-04-10 18:46:39 +02:00
|
|
|
#endif /* OBSW_ADD_PLOC_MPSOC == 1*/
|
|
|
|
|
2022-05-04 12:49:43 +02:00
|
|
|
#if OBSW_ADD_PLOC_SUPERVISOR == 1
|
2022-04-10 18:46:39 +02:00
|
|
|
PeriodicTaskIF* supvHelperTask = factory->createPeriodicTask(
|
|
|
|
"PLOC_SUPV_HELPER", 20, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.2, missedDeadlineFunc);
|
|
|
|
result = supvHelperTask->addComponent(objects::PLOC_SUPERVISOR_HELPER);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-04-10 18:46:39 +02:00
|
|
|
initmission::printAddObjectError("PLOC_SUPV_HELPER", objects::PLOC_SUPERVISOR_HELPER);
|
|
|
|
}
|
2022-05-04 12:49:43 +02:00
|
|
|
#endif /* OBSW_ADD_PLOC_SUPERVISOR == 1 */
|
2022-03-17 14:28:32 +01:00
|
|
|
|
2022-10-27 09:06:34 +02:00
|
|
|
#if OBSW_ADD_CCSDS_IP_CORES == 1
|
2022-06-08 07:16:12 +02:00
|
|
|
PeriodicTaskIF* ccsdsHandlerTask = factory->createPeriodicTask(
|
|
|
|
"CCSDS_HANDLER", 50, PeriodicTaskIF::MINIMUM_STACK_SIZE, 2.0, missedDeadlineFunc);
|
|
|
|
result = ccsdsHandlerTask->addComponent(objects::CCSDS_HANDLER);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-06-08 07:16:12 +02:00
|
|
|
initmission::printAddObjectError("CCSDS Handler", objects::CCSDS_HANDLER);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Minimal distance between two received TCs amounts to 0.6 seconds
|
|
|
|
// If a command has not been read before the next one arrives, the old command will be
|
|
|
|
// overwritten by the PDEC.
|
|
|
|
PeriodicTaskIF* pdecHandlerTask = factory->createPeriodicTask(
|
|
|
|
"PDEC_HANDLER", 50, PeriodicTaskIF::MINIMUM_STACK_SIZE, 1.0, missedDeadlineFunc);
|
|
|
|
result = pdecHandlerTask->addComponent(objects::PDEC_HANDLER);
|
2022-08-24 17:27:47 +02:00
|
|
|
if (result != returnvalue::OK) {
|
2022-06-08 07:16:12 +02:00
|
|
|
initmission::printAddObjectError("PDEC Handler", objects::PDEC_HANDLER);
|
|
|
|
}
|
2022-10-27 09:06:34 +02:00
|
|
|
#endif /* OBSW_ADD_CCSDS_IP_CORES == 1 */
|
2022-06-08 07:16:12 +02:00
|
|
|
|
2022-03-17 14:28:32 +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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
sif::info << "Starting tasks.." << std::endl;
|
|
|
|
tmtcDistributor->startTask();
|
|
|
|
tmtcBridgeTask->startTask();
|
|
|
|
tmtcPollingTask->startTask();
|
2022-10-26 16:11:34 +02:00
|
|
|
#if OBSW_ADD_CCSDS_IP_CORE == 1
|
2022-06-08 07:16:12 +02:00
|
|
|
pdecHandlerTask->startTask();
|
|
|
|
ccsdsHandlerTask->startTask();
|
2022-10-26 16:11:34 +02:00
|
|
|
#endif /* #if OBSW_ADD_CCSDS_IP_CORE == 1 */
|
2022-05-04 12:49:43 +02:00
|
|
|
#if OBSW_ADD_PLOC_SUPERVISOR == 1
|
2022-04-10 18:46:39 +02:00
|
|
|
supvHelperTask->startTask();
|
2022-05-04 12:49:43 +02:00
|
|
|
#endif /* OBSW_ADD_PLOC_SUPERVISOR == 1 */
|
2022-04-10 18:46:39 +02:00
|
|
|
#if OBSW_ADD_PLOC_MPSOC == 1
|
|
|
|
mpsocHelperTask->startTask();
|
|
|
|
#endif /* OBSW_ADD_PLOC_MPSOC == 1 */
|
2022-03-17 14:28:32 +01:00
|
|
|
|
|
|
|
taskStarter(pstTasks, "PST Tasks");
|
|
|
|
taskStarter(pusTasks, "PUS Tasks");
|
|
|
|
|
|
|
|
sif::info << "Tasks started.." << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
void initmission::createPusTasks(TaskFactory& factory,
|
|
|
|
TaskDeadlineMissedFunction missedDeadlineFunc,
|
|
|
|
std::vector<PeriodicTaskIF*>& taskVec) {
|
2022-08-24 17:27:47 +02:00
|
|
|
ReturnValue_t result = returnvalue::OK;
|
2022-03-17 14:28:32 +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-03-17 14:28:32 +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-03-17 14:28:32 +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-03-17 14:28:32 +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-03-17 14:28:32 +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-03-17 14:28:32 +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-03-17 14:28:32 +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-03-17 14:28:32 +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-03-17 14:28:32 +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-03-17 14:28:32 +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-03-17 14:28:32 +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-03-17 14:28:32 +01:00
|
|
|
initmission::printAddObjectError("INT_ERR_RPRT", objects::INTERNAL_ERROR_REPORTER);
|
|
|
|
}
|
|
|
|
taskVec.push_back(pusLowPrio);
|
|
|
|
}
|