eive-obsw/bsp_hosted/InitMission.cpp

196 lines
7.6 KiB
C++
Raw Normal View History

2020-12-29 14:37:39 +01:00
#include "InitMission.h"
#include <OBSWConfig.h>
2022-06-17 08:31:36 +02:00
#include <bsp_hosted/fsfwconfig/pollingsequence/DummyPst.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>
2020-09-30 17:17:01 +02:00
#include <fsfw/serviceinterface/ServiceInterfaceStream.h>
#include <fsfw/tasks/FixedTimeslotTaskIF.h>
#include <fsfw/tasks/PeriodicTaskIF.h>
#include <fsfw/tasks/TaskFactory.h>
2021-03-04 18:29:28 +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 "ObjectFactory.h"
2020-09-30 21:07:30 +02:00
#ifdef LINUX
ServiceInterfaceStream sif::debug("DEBUG");
ServiceInterfaceStream sif::info("INFO");
ServiceInterfaceStream sif::warning("WARNING");
2020-09-30 17:17:01 +02:00
ServiceInterfaceStream sif::error("ERROR", false, false, true);
2020-09-30 21:07:30 +02:00
#else
ServiceInterfaceStream sif::debug("DEBUG", true);
ServiceInterfaceStream sif::info("INFO", true);
ServiceInterfaceStream sif::warning("WARNING", true);
ServiceInterfaceStream sif::error("ERROR", true, false, true);
#endif
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();
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);
ReturnValue_t 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 */
PeriodicTaskIF* tmtcBridgeTask = factory->createPeriodicTask(
"TMTC_UNIX_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-01-17 15:58:27 +01:00
sif::error << "Add component UDP Unix Bridge failed" << std::endl;
}
PeriodicTaskIF* tmtcPollingTask = factory->createPeriodicTask(
"UDP_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-01-17 15:58:27 +01:00
sif::error << "Add component UDP Polling failed" << std::endl;
}
/* PUS Services */
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;
}
PeriodicTaskIF* eventHandling = factory->createPeriodicTask(
"EVENTS", 60, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.200, missedDeadlineFunc);
result = eventHandling->addComponent(objects::EVENT_MANAGER);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
initmission::printAddObjectError("EVENT_MNGR", objects::EVENT_MANAGER);
}
result = eventHandling->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("PUS5", objects::PUS_SERVICE_5_EVENT_REPORTING);
}
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);
}
result = pusHighPrio->addComponent(objects::PUS_SERVICE_3_HOUSEKEEPING);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
initmission::printAddObjectError("PUS3", objects::PUS_SERVICE_3_HOUSEKEEPING);
}
2022-01-17 15:58:27 +01:00
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);
}
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);
}
2022-06-13 08:58:06 +02:00
PeriodicTaskIF* thermalTask = factory->createPeriodicTask(
"THERMAL_CTL_TASK", 40, PeriodicTaskIF::MINIMUM_STACK_SIZE, 1.0, missedDeadlineFunc);
2022-06-13 08:58:06 +02:00
result = thermalTask->addComponent(objects::RTD_0_IC3_PLOC_HEATSPREADER);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
initmission::printAddObjectError("RTD_0_dummy", objects::RTD_0_IC3_PLOC_HEATSPREADER);
}
2022-06-13 08:58:06 +02:00
result = thermalTask->addComponent(objects::SUS_0_N_LOC_XFYFZM_PT_XF);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
initmission::printAddObjectError("SUS_0_dummy", objects::SUS_0_N_LOC_XFYFZM_PT_XF);
}
2022-06-13 08:58:06 +02:00
result = thermalTask->addComponent(objects::CORE_CONTROLLER);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-06-17 08:31:36 +02:00
initmission::printAddObjectError("Core controller dummy", objects::CORE_CONTROLLER);
}
2022-06-13 08:58:06 +02:00
result = thermalTask->addComponent(objects::THERMAL_CONTROLLER);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
initmission::printAddObjectError("THERMAL_CONTROLLER", objects::THERMAL_CONTROLLER);
}
FixedTimeslotTaskIF* pstTask = factory->createFixedTimeslotTask(
"DUMMY_PST", 75, PeriodicTaskIF::MINIMUM_STACK_SIZE * 4, 0.5, missedDeadlineFunc);
result = dummy_pst::pst(pstTask);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
sif::error << "Failed to add dummy pst to fixed timeslot task" << std::endl;
}
2020-11-20 18:10:39 +01:00
#if OBSW_ADD_TEST_CODE == 1
2022-01-17 15:58:27 +01:00
result = testTask->addComponent(objects::TEST_TASK);
2022-08-24 17:27:47 +02:00
if (result != returnvalue::OK) {
2022-01-17 15:58:27 +01:00
initmission::printAddObjectError("TEST_TASK", objects::TEST_TASK);
}
2021-03-04 18:29:28 +01:00
#endif /* OBSW_ADD_TEST_CODE == 1 */
2022-01-17 15:58:27 +01:00
sif::info << "Starting tasks.." << std::endl;
tmTcDistributor->startTask();
tmtcBridgeTask->startTask();
tmtcPollingTask->startTask();
2021-03-04 18:29:28 +01:00
2022-01-17 15:58:27 +01:00
pusVerification->startTask();
eventHandling->startTask();
2022-01-17 15:58:27 +01:00
pusHighPrio->startTask();
pusMedPrio->startTask();
pusLowPrio->startTask();
2020-09-30 17:17:01 +02:00
pstTask->startTask();
2022-06-13 08:58:06 +02:00
thermalTask->startTask();
2020-11-20 18:10:39 +01:00
#if OBSW_ADD_TEST_CODE == 1
2022-01-17 15:58:27 +01:00
testTask->startTask();
2021-03-04 18:29:28 +01:00
#endif /* OBSW_ADD_TEST_CODE == 1 */
2022-01-17 15:58:27 +01:00
sif::info << "Tasks started.." << std::endl;
2020-09-30 17:17:01 +02:00
}