eive-obsw/bsp_linux_board/InitMission.cpp

187 lines
7.8 KiB
C++
Raw Normal View History

2020-12-29 13:59:31 +01:00
#include "InitMission.h"
#include "ObjectFactory.h"
2020-09-30 17:17:01 +02:00
2021-05-23 20:44:54 +02:00
#include "objects/systemObjectList.h"
#include "OBSWConfig.h"
#include "pollingsequence/pollingSequenceFactory.h"
2021-03-04 18:29:28 +01:00
#include <mission/utility/InitMission.h>
2020-09-30 17:17:01 +02:00
#include <fsfw/objectmanager/ObjectManagerIF.h>
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
2021-03-04 18:29:28 +01:00
#include <fsfw/serviceinterface/ServiceInterface.h>
2020-09-30 17:17:01 +02:00
#include <fsfw/objectmanager/ObjectManager.h>
#include <fsfw/tasks/FixedTimeslotTaskIF.h>
#include <fsfw/tasks/PeriodicTaskIF.h>
#include <fsfw/tasks/TaskFactory.h>
#include <iostream>
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
ObjectManagerIF *objectManager = nullptr;
2021-03-04 18:29:28 +01:00
void initmission::initMission() {
sif::info << "Building global objects.." << std::endl;
/* Instantiate global object manager and also create all objects */
2021-06-08 16:45:25 +02:00
ObjectManager::instance()->setObjectFactoryFunction(ObjectFactory::produce, nullptr);
2020-09-30 17:17:01 +02:00
sif::info << "Initializing all objects.." << std::endl;
2021-06-08 16:45:25 +02:00
ObjectManager::instance()->initialize();
2020-09-30 17:17:01 +02:00
/* This function creates and starts all tasks */
initTasks();
}
2021-03-04 18:29:28 +01:00
void initmission::initTasks() {
TaskFactory* factory = TaskFactory::instance();
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);
ReturnValue_t result = tmTcDistributor->addComponent(
objects::CCSDS_PACKET_DISTRIBUTOR);
if(result != HasReturnvaluesIF::RETURN_OK){
sif::error << "Object add component failed" << std::endl;
}
result = tmTcDistributor->addComponent(objects::PUS_PACKET_DISTRIBUTOR);
if(result != HasReturnvaluesIF::RETURN_OK){
sif::error << "Object add component failed" << std::endl;
}
result = tmTcDistributor->addComponent(objects::TM_FUNNEL);
2020-09-30 17:17:01 +02:00
if(result != HasReturnvaluesIF::RETURN_OK) {
2021-03-04 18:29:28 +01:00
sif::error << "Object add component failed" << std::endl;
2020-09-30 17:17:01 +02:00
}
/* UDP bridge */
2021-03-04 18:29:28 +01:00
PeriodicTaskIF* udpBridgeTask = factory->createPeriodicTask(
"UDP_UNIX_BRIDGE", 50, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.2, missedDeadlineFunc);
result = udpBridgeTask->addComponent(objects::UDP_BRIDGE);
2020-09-30 17:17:01 +02:00
if(result != HasReturnvaluesIF::RETURN_OK) {
2021-03-04 18:29:28 +01:00
sif::error << "Add component UDP Unix Bridge failed" << std::endl;
2020-09-30 17:17:01 +02:00
}
2021-03-04 18:29:28 +01:00
PeriodicTaskIF* udpPollingTask = factory->createPeriodicTask(
"UDP_POLLING", 80, PeriodicTaskIF::MINIMUM_STACK_SIZE, 2.0, missedDeadlineFunc);
result = udpPollingTask->addComponent(objects::UDP_POLLING_TASK);
2020-09-30 17:17:01 +02:00
if(result != HasReturnvaluesIF::RETURN_OK) {
2021-03-04 18:29:28 +01:00
sif::error << "Add component UDP Polling failed" << std::endl;
}
2020-09-30 17:17:01 +02:00
2021-03-04 18:29:28 +01:00
/* PUS Services */
PeriodicTaskIF* pusVerification = factory->createPeriodicTask(
"PUS_VERIF", 40, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.200, missedDeadlineFunc);
result = pusVerification->addComponent(objects::PUS_SERVICE_1_VERIFICATION);
if(result != HasReturnvaluesIF::RETURN_OK){
sif::error << "Object add component failed" << std::endl;
}
2020-12-29 13:59:31 +01:00
2021-03-04 18:29:28 +01:00
PeriodicTaskIF* pusEvents = factory->createPeriodicTask(
"PUS_EVENTS", 60, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.200, missedDeadlineFunc);
result = pusVerification->addComponent(objects::PUS_SERVICE_5_EVENT_REPORTING);
if(result != HasReturnvaluesIF::RETURN_OK){
initmission::printAddObjectError("PUS5", objects::PUS_SERVICE_5_EVENT_REPORTING);
}
2020-11-19 18:24:03 +01:00
2021-03-04 18:29:28 +01:00
PeriodicTaskIF* pusHighPrio = factory->createPeriodicTask(
"PUS_HIGH_PRIO", 50, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.200, missedDeadlineFunc);
result = pusHighPrio->addComponent(objects::PUS_SERVICE_2_DEVICE_ACCESS);
if(result != HasReturnvaluesIF::RETURN_OK) {
initmission::printAddObjectError("PUS2", objects::PUS_SERVICE_2_DEVICE_ACCESS);
}
result = pusHighPrio->addComponent(objects::PUS_SERVICE_9_TIME_MGMT);
if(result != HasReturnvaluesIF::RETURN_OK) {
initmission::printAddObjectError("PUS9", objects::PUS_SERVICE_9_TIME_MGMT);
}
2020-09-30 17:17:01 +02:00
2021-03-04 18:29:28 +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);
if(result != HasReturnvaluesIF::RETURN_OK) {
initmission::printAddObjectError("PUS8", objects::PUS_SERVICE_8_FUNCTION_MGMT);
}
result = pusMedPrio->addComponent(objects::PUS_SERVICE_200_MODE_MGMT);
if(result != HasReturnvaluesIF::RETURN_OK) {
initmission::printAddObjectError("PUS200", objects::PUS_SERVICE_200_MODE_MGMT);
}
result = pusMedPrio->addComponent(objects::PUS_SERVICE_20_PARAMETERS);
if(result != HasReturnvaluesIF::RETURN_OK) {
initmission::printAddObjectError("PUS20", objects::PUS_SERVICE_20_PARAMETERS);
2021-02-23 22:07:39 +01:00
}
2021-05-27 16:20:40 +02:00
result = pusMedPrio->addComponent(objects::PUS_SERVICE_3_HOUSEKEEPING);
if(result != HasReturnvaluesIF::RETURN_OK) {
initmission::printAddObjectError("PUS3", objects::PUS_SERVICE_3_HOUSEKEEPING);
}
2021-02-23 22:07:39 +01:00
2021-03-22 12:47:45 +01:00
PeriodicTaskIF* pusLowPrio = factory->createPeriodicTask(
"PUS_LOW_PRIO", 30, PeriodicTaskIF::MINIMUM_STACK_SIZE, 1.6, missedDeadlineFunc);
result = pusLowPrio->addComponent(objects::PUS_SERVICE_17_TEST);
if(result != HasReturnvaluesIF::RETURN_OK) {
initmission::printAddObjectError("PUS17", objects::PUS_SERVICE_17_TEST);
}
2021-05-27 16:20:40 +02:00
result = pusLowPrio->addComponent(objects::INTERNAL_ERROR_REPORTER);
if(result != HasReturnvaluesIF::RETURN_OK) {
initmission::printAddObjectError("INT_ERR_RPRT",
objects::INTERNAL_ERROR_REPORTER);
}
2021-03-22 12:47:45 +01:00
2021-05-24 01:20:44 +02:00
#if OBSW_ADD_TEST_PST == 1
FixedTimeslotTaskIF* pstTestTask = factory->createFixedTimeslotTask(
2021-03-04 18:29:28 +01:00
"ACS_PST", 50, PeriodicTaskIF::MINIMUM_STACK_SIZE * 2, 2.0, missedDeadlineFunc);
2021-05-24 01:20:44 +02:00
result = pst::pollingSequenceTest(pstTestTask);
2021-03-04 18:29:28 +01:00
if(result != HasReturnvaluesIF::RETURN_OK) {
sif::warning << "initmission::initTasks: ACS PST initialization failed!" << std::endl;
}
#endif /* RPI_TEST_ACS_BOARD == 1 */
2020-12-04 14:14:08 +01:00
2021-03-04 18:29:28 +01:00
PeriodicTaskIF* testTask = factory->createPeriodicTask(
"TEST_TASK", 40, PeriodicTaskIF::MINIMUM_STACK_SIZE, 2.0, missedDeadlineFunc);
#if OBSW_ADD_TEST_CODE == 1
result = testTask->addComponent(objects::TEST_TASK);
if(result != HasReturnvaluesIF::RETURN_OK) {
initmission::printAddObjectError("TEST_TASK", objects::TEST_TASK);
}
#endif /* OBSW_ADD_TEST_CODE == 1 */
#if RPI_ADD_SPI_TEST == 1
result = testTask->addComponent(objects::SPI_TEST);
if(result != HasReturnvaluesIF::RETURN_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);
if(result != HasReturnvaluesIF::RETURN_OK) {
initmission::printAddObjectError("GPIOD_TEST", objects::LIBGPIOD_TEST);
}
#endif /* RPI_ADD_GPIO_TEST == 1 */
sif::info << "Starting tasks.." << std::endl;
tmTcDistributor->startTask();
udpBridgeTask->startTask();
udpPollingTask->startTask();
pusVerification->startTask();
pusEvents->startTask();
pusHighPrio->startTask();
pusMedPrio->startTask();
pusLowPrio->startTask();
2021-01-14 00:40:30 +01:00
2020-12-29 13:59:31 +01:00
#if OBSW_ADD_TEST_CODE == 1
2021-03-04 18:29:28 +01:00
testTask->startTask();
#endif /* OBSW_ADD_TEST_CODE == 1 */
2021-05-24 01:20:44 +02:00
#if OBSW_ADD_TEST_PST == 1
pstTestTask->startTask();
2021-03-04 18:29:28 +01:00
#endif /* RPI_TEST_ACS_BOARD == 1 */
sif::info << "Tasks started.." << std::endl;
2020-09-30 17:17:01 +02:00
}