eive-obsw/bsp_q7s/InitMission.cpp

192 lines
7.0 KiB
C++
Raw Normal View History

2020-12-29 13:59:31 +01:00
#include "InitMission.h"
#include "ObjectFactory.h"
#include <OBSWConfig.h>
2020-09-30 17:17:01 +02:00
#include <fsfw/objectmanager/ObjectManagerIF.h>
#include <fsfw/returnvalues/HasReturnvaluesIF.h>
#include <fsfw/serviceinterface/ServiceInterfaceStream.h>
#include <fsfw/objectmanager/ObjectManager.h>
#include <fsfw/tasks/FixedTimeslotTaskIF.h>
#include <fsfw/tasks/PeriodicTaskIF.h>
#include <fsfw/tasks/TaskFactory.h>
#include <fsfwconfig/pollingsequence/PollingSequenceFactory.h>
2020-09-30 17:17:01 +02:00
#include <iostream>
// This is configured for linux without \cr
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
ObjectManagerIF *objectManager = nullptr;
void InitMission::initMission() {
sif::info << "Building global objects.." << std::endl;
/* Instantiate global object manager and also create all objects */
objectManager = new ObjectManager(ObjectFactory::produce);
sif::info << "Initializing all objects.." << std::endl;
objectManager->initialize();
/* This function creates and starts all tasks */
initTasks();
}
void InitMission::initTasks(){
/* TMTC Distribution */
PeriodicTaskIF* TmTcDistributor = TaskFactory::instance()->
createPeriodicTask("DIST", 40, PeriodicTaskIF::MINIMUM_STACK_SIZE,
2020-12-30 14:34:25 +01:00
0.2, nullptr);
2020-09-30 17:17:01 +02:00
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);
if(result != HasReturnvaluesIF::RETURN_OK) {
sif::error << "Object add component failed" << std::endl;
}
/* UDP bridge */
PeriodicTaskIF* UdpBridgeTask = TaskFactory::instance()->createPeriodicTask(
"UDP_UNIX_BRIDGE", 50, PeriodicTaskIF::MINIMUM_STACK_SIZE,
0.2, nullptr);
result = UdpBridgeTask->addComponent(objects::UDP_BRIDGE);
if(result != HasReturnvaluesIF::RETURN_OK) {
sif::error << "Add component UDP Unix Bridge failed" << std::endl;
}
PeriodicTaskIF* UdpPollingTask = TaskFactory::instance()->
createPeriodicTask("UDP_POLLING", 80,
PeriodicTaskIF::MINIMUM_STACK_SIZE, 2.0, nullptr);
result = UdpPollingTask->addComponent(objects::UDP_POLLING_TASK);
if(result != HasReturnvaluesIF::RETURN_OK) {
sif::error << "Add component UDP Polling failed" << std::endl;
}
/* PUS Services */
PeriodicTaskIF* PusVerification = TaskFactory::instance()->
createPeriodicTask("PUS_VERIF_1", 40,
PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.200, nullptr);
result = PusVerification->addComponent(objects::PUS_SERVICE_1_VERIFICATION);
if(result != HasReturnvaluesIF::RETURN_OK){
sif::error << "Object add component failed" << std::endl;
}
PeriodicTaskIF* PusEvents = TaskFactory::instance()->
createPeriodicTask("PUS_VERIF_1", 60,
PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.200, nullptr);
result = PusVerification->addComponent(objects::PUS_SERVICE_5_EVENT_REPORTING);
if(result != HasReturnvaluesIF::RETURN_OK){
sif::error << "Object add component failed" << std::endl;
}
PeriodicTaskIF* PusHighPrio = TaskFactory::instance()->
createPeriodicTask("PUS_HIGH_PRIO", 50,
PeriodicTaskIF::MINIMUM_STACK_SIZE,
0.200, nullptr);
result = PusHighPrio->addComponent(objects::PUS_SERVICE_2_DEVICE_ACCESS);
if(result!=HasReturnvaluesIF::RETURN_OK){
sif::error << "Object add component failed" << std::endl;
}
result = PusHighPrio->addComponent(objects::PUS_SERVICE_9_TIME_MGMT);
if(result!=HasReturnvaluesIF::RETURN_OK){
sif::error << "Object add component failed" << std::endl;
}
PeriodicTaskIF* PusMedPrio = TaskFactory::instance()->
createPeriodicTask("PUS_HIGH_PRIO", 40,
PeriodicTaskIF::MINIMUM_STACK_SIZE,
0.8, nullptr);
result = PusMedPrio->addComponent(objects::PUS_SERVICE_8_FUNCTION_MGMT);
if(result!=HasReturnvaluesIF::RETURN_OK){
sif::error << "Object add component failed" << std::endl;
}
result = PusMedPrio->addComponent(objects::PUS_SERVICE_200_MODE_MGMT);
if(result!=HasReturnvaluesIF::RETURN_OK){
sif::error << "Object add component failed" << std::endl;
}
PeriodicTaskIF* PusLowPrio = TaskFactory::instance()->
createPeriodicTask("PUSB", 30, PeriodicTaskIF::MINIMUM_STACK_SIZE,
1.6, nullptr);
result = PusLowPrio->addComponent(objects::PUS_SERVICE_17_TEST);
if(result!=HasReturnvaluesIF::RETURN_OK){
sif::error << "Object add component failed" << std::endl;
}
2021-01-08 09:34:43 +01:00
//TODO: Add handling of missed deadlines
/* Polling Sequence Table Default */
FixedTimeslotTaskIF * PollingSequenceTableTaskDefault =
TaskFactory::instance()->createFixedTimeslotTask("PST_TASK_DEFAULT",
50, PeriodicTaskIF::MINIMUM_STACK_SIZE*4, 3.0,
nullptr);
result = pst::pollingSequenceInitDefault(PollingSequenceTableTaskDefault);
if (result != HasReturnvaluesIF::RETURN_OK) {
sif::error << "InitMission::initTasks: Creating PST failed!"
<< std::endl;
}
2020-12-10 10:01:45 +01:00
FixedTimeslotTaskIF* GomSpacePstTask = TaskFactory::instance()->
2020-12-10 10:01:45 +01:00
createFixedTimeslotTask("GS_PST_TASK", 50,
2021-02-06 11:57:45 +01:00
PeriodicTaskIF::MINIMUM_STACK_SIZE*8, 3.0, nullptr);
result = pst::gomspacePstInit(GomSpacePstTask);
if(result != HasReturnvaluesIF::RETURN_OK) {
sif::error << "InitMission::initTasks: GomSpace PST initialization "
<< "failed!" << std::endl;
}
2020-09-30 17:17:01 +02:00
2020-12-29 13:59:31 +01:00
#if OBSW_ADD_TEST_CODE == 1
2020-11-19 18:24:03 +01:00
// FixedTimeslotTaskIF* TestTimeslotTask = TaskFactory::instance()->
// createFixedTimeslotTask("PST_TEST_TASK", 10,
// PeriodicTaskIF::MINIMUM_STACK_SIZE, 1.0, nullptr);
// result = pst::pollingSequenceTestFunction(TestTimeslotTask);
// if(result != HasReturnvaluesIF::RETURN_OK) {
// sif::error << "InitMission::createTasks: Test PST initialization "
// << "failed!" << std::endl;
// }
2021-02-14 09:25:40 +01:00
#endif
#if TE0720 == 1 && TEST_LIBGPIOD == 1
PeriodicTaskIF* TestTask = TaskFactory::instance()->
createPeriodicTask("Libgpiod Test Task", 60,
PeriodicTaskIF::MINIMUM_STACK_SIZE, 1, nullptr);
result = TestTask->addComponent(objects::LIBGPIOD_TEST);
if(result != HasReturnvaluesIF::RETURN_OK){
sif::error << "Object add component libgpiod test task object" << std::endl;
}
2020-09-30 17:17:01 +02:00
#endif
//Main thread sleep
sif::info << "Starting tasks.." << std::endl;
TmTcDistributor->startTask();
UdpBridgeTask->startTask();
UdpPollingTask->startTask();
2021-02-03 08:09:54 +01:00
GomSpacePstTask->startTask();
2021-01-08 09:34:43 +01:00
PollingSequenceTableTaskDefault->startTask();
2020-09-30 17:17:01 +02:00
PusVerification->startTask();
PusEvents->startTask();
PusHighPrio->startTask();
PusMedPrio->startTask();
PusLowPrio->startTask();
2020-12-04 14:14:08 +01:00
2021-02-14 09:25:40 +01:00
#if TE0720 == 1 && TEST_LIBGPIOD == 1
TestTask->startTask();
2020-09-30 17:17:01 +02:00
#endif
sif::info << "Tasks started.." << std::endl;
}