#include "InitMission.h" #include "ObjectFactory.h" #include "OBSWConfig.h" #include "pollingsequence/pollingSequenceFactory.h" #include #include #include #include #include #include #include #include #include /* This is configured for linux without CR */ #ifdef LINUX ServiceInterfaceStream sif::debug("DEBUG"); ServiceInterfaceStream sif::info("INFO"); ServiceInterfaceStream sif::warning("WARNING"); ServiceInterfaceStream sif::error("ERROR", false, false, true); #else ServiceInterfaceStream sif::debug("DEBUG", true); ServiceInterfaceStream sif::info("INFO", true); ServiceInterfaceStream sif::warning("WARNING", true); ServiceInterfaceStream sif::error("ERROR", true, false, true); #endif 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(); ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; if(factory == nullptr) { /* Should never happen ! */ return; } #if OBSW_PRINT_MISSED_DEADLINES == 1 void (*missedDeadlineFunc) (void) = TaskFactory::printMissedDeadline; #else void (*missedDeadlineFunc) (void) = nullptr; #endif PeriodicTaskIF* coreController = factory->createPeriodicTask( "CORE_CTRL", 60, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.4, missedDeadlineFunc); result = coreController->addComponent(objects::CORE_CONTROLLER); if(result != HasReturnvaluesIF::RETURN_OK) { initmission::printAddObjectError("CORE_CTRL", objects::CORE_CONTROLLER); } /* TMTC Distribution */ PeriodicTaskIF* tmTcDistributor = factory->createPeriodicTask( "DIST", 40, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.2, missedDeadlineFunc); result = tmTcDistributor->addComponent(objects::CCSDS_PACKET_DISTRIBUTOR); if(result != HasReturnvaluesIF::RETURN_OK) { initmission::printAddObjectError("CCSDS_DISTRIB", objects::CCSDS_PACKET_DISTRIBUTOR); } result = tmTcDistributor->addComponent(objects::PUS_PACKET_DISTRIBUTOR); if(result != HasReturnvaluesIF::RETURN_OK) { initmission::printAddObjectError("PUS_PACKET_DISTRIB", objects::PUS_PACKET_DISTRIBUTOR); } result = tmTcDistributor->addComponent(objects::TM_FUNNEL); if(result != HasReturnvaluesIF::RETURN_OK) { initmission::printAddObjectError("TM_FUNNEL", objects::TM_FUNNEL); } /* UDP bridge */ PeriodicTaskIF* udpBridgeTask = factory->createPeriodicTask( "UDP_UNIX_BRIDGE", 50, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.2, missedDeadlineFunc); result = udpBridgeTask->addComponent(objects::UDP_BRIDGE); if(result != HasReturnvaluesIF::RETURN_OK) { initmission::printAddObjectError("UDP_BRIDGE", objects::UDP_BRIDGE); } PeriodicTaskIF* udpPollingTask = factory->createPeriodicTask( "UDP_POLLING", 80, PeriodicTaskIF::MINIMUM_STACK_SIZE, 2.0, missedDeadlineFunc); result = udpPollingTask->addComponent(objects::UDP_POLLING_TASK); if(result != HasReturnvaluesIF::RETURN_OK) { initmission::printAddObjectError("UDP_POLLING", objects::UDP_POLLING_TASK); } #if TEST_CCSDS_BRIDGE == 1 PeriodicTaskIF* ptmeTestTask = factory->createPeriodicTask( "PTME_TEST", 80, PeriodicTaskIF::MINIMUM_STACK_SIZE, 2.0, missedDeadlineFunc); result = ptmeTestTask->addComponent(objects::CCSDS_IP_CORE_BRIDGE); if(result != HasReturnvaluesIF::RETURN_OK) { initmission::printAddObjectError("PTME_TEST", objects::CCSDS_IP_CORE_BRIDGE); } #endif /* 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) { initmission::printAddObjectError("PUS_VERIF", objects::PUS_SERVICE_1_VERIFICATION); } PeriodicTaskIF* pusEvents = factory->createPeriodicTask( "PUS_EVENTS", 60, PeriodicTaskIF::MINIMUM_STACK_SIZE, 0.200, missedDeadlineFunc); result = pusEvents->addComponent(objects::PUS_SERVICE_5_EVENT_REPORTING); if(result != HasReturnvaluesIF::RETURN_OK) { initmission::printAddObjectError("PUS_EVENTS", objects::PUS_SERVICE_5_EVENT_REPORTING); } result = pusEvents->addComponent(objects::EVENT_MANAGER); if(result != HasReturnvaluesIF::RETURN_OK) { initmission::printAddObjectError("PUS_MGMT", objects::EVENT_MANAGER); } 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("PUS_2", objects::PUS_SERVICE_2_DEVICE_ACCESS); } result = pusHighPrio->addComponent(objects::PUS_SERVICE_9_TIME_MGMT); if(result != HasReturnvaluesIF::RETURN_OK) { initmission::printAddObjectError("PUS_9", objects::PUS_SERVICE_9_TIME_MGMT); } 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("PUS_8", objects::PUS_SERVICE_8_FUNCTION_MGMT); } result = pusMedPrio->addComponent(objects::PUS_SERVICE_3_HOUSEKEEPING); 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) { initmission::printAddObjectError("PUS_200", objects::PUS_SERVICE_200_MODE_MGMT); } result = pusMedPrio->addComponent(objects::PUS_SERVICE_20_PARAMETERS); if(result != HasReturnvaluesIF::RETURN_OK) { initmission::printAddObjectError("PUS_20", 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); if(result != HasReturnvaluesIF::RETURN_OK) { initmission::printAddObjectError("PUS_17", objects::PUS_SERVICE_17_TEST); } result = pusLowPrio->addComponent(objects::INTERNAL_ERROR_REPORTER); if(result != HasReturnvaluesIF::RETURN_OK) { initmission::printAddObjectError("ERROR_REPORTER", objects::INTERNAL_ERROR_REPORTER); } #if BOARD_TE0720 == 0 //TODO: Add handling of missed deadlines /* Polling Sequence Table Default */ #if Q7S_ADD_SPI_TEST == 0 FixedTimeslotTaskIF* spiPst = factory->createFixedTimeslotTask( "PST_TASK_DEFAULT", 70, PeriodicTaskIF::MINIMUM_STACK_SIZE * 4, 3.0, missedDeadlineFunc); result = pst::pstSpi(spiPst); if (result != HasReturnvaluesIF::RETURN_OK) { sif::error << "InitMission::initTasks: Creating PST failed!" << std::endl; } #endif FixedTimeslotTaskIF* uartPst = factory->createFixedTimeslotTask( "UART_PST", 70, PeriodicTaskIF::MINIMUM_STACK_SIZE * 4, 3.0, missedDeadlineFunc); result = pst::pstUart(uartPst); if (result != HasReturnvaluesIF::RETURN_OK) { sif::error << "InitMission::initTasks: Creating PST failed!" << std::endl; } FixedTimeslotTaskIF* gpioPst = factory->createFixedTimeslotTask( "GPIO_PST", 70, PeriodicTaskIF::MINIMUM_STACK_SIZE * 4, 3.0, missedDeadlineFunc); result = pst::pstGpio(gpioPst); if (result != HasReturnvaluesIF::RETURN_OK) { sif::error << "InitMission::initTasks: Creating PST failed!" << std::endl; } FixedTimeslotTaskIF* i2cPst = factory->createFixedTimeslotTask( "I2C_PST", 70, PeriodicTaskIF::MINIMUM_STACK_SIZE * 4, 3.0, missedDeadlineFunc); result = pst::pstI2c(i2cPst); if (result != HasReturnvaluesIF::RETURN_OK) { sif::error << "InitMission::initTasks: Creating PST failed!" << std::endl; } FixedTimeslotTaskIF* gomSpacePstTask = factory->createFixedTimeslotTask( "GS_PST_TASK", 70, PeriodicTaskIF::MINIMUM_STACK_SIZE * 4, 1.0, missedDeadlineFunc); result = pst::pstGompaceCan(gomSpacePstTask); if(result != HasReturnvaluesIF::RETURN_OK) { sif::error << "InitMission::initTasks: GomSpace PST initialization failed!" << std::endl; } #else /* BOARD_TE7020 == 0 */ FixedTimeslotTaskIF * pollingSequenceTaskTE0720 = factory->createFixedTimeslotTask( "PST_TASK_TE0720", 30, PeriodicTaskIF::MINIMUM_STACK_SIZE * 8, 3.0, missedDeadlineFunc); result = pst::pollingSequenceTE0720(pollingSequenceTaskTE0720); if (result != HasReturnvaluesIF::RETURN_OK) { sif::error << "InitMission::initTasks: Creating TE0720 PST failed!" << std::endl; } #endif /* BOARD_TE7020 == 1 */ #if OBSW_ADD_TEST_CODE == 1 PeriodicTaskIF* testTask = factory->createPeriodicTask( "TEST_TASK", 60, PeriodicTaskIF::MINIMUM_STACK_SIZE, 1, missedDeadlineFunc); result = testTask->addComponent(objects::TEST_TASK); if(result != HasReturnvaluesIF::RETURN_OK) { initmission::printAddObjectError("TEST_TASK", objects::TEST_TASK); } #if Q7S_ADD_SPI_TEST == 1 result = testTask->addComponent(objects::SPI_TEST); if(result != HasReturnvaluesIF::RETURN_OK) { initmission::printAddObjectError("SPI_TEST", objects::SPI_TEST); } #endif #endif /* OBSW_ADD_TEST_CODE == 1 */ #if BOARD_TE0720 == 1 && TEST_LIBGPIOD == 1 result = testTask->addComponent(objects::LIBGPIOD_TEST); if(result != HasReturnvaluesIF::RETURN_OK) { initmission::printAddObjectError("GPIOD_TEST", objects::LIBGPIOD_TEST); } #endif /* TE0720 == 1 && TEST_LIBGPIOD == 1 */ sif::info << "Starting tasks.." << std::endl; tmTcDistributor->startTask(); udpBridgeTask->startTask(); udpPollingTask->startTask(); coreController->startTask(); #if BOARD_TE0720 == 0 uartPst->startTask(); gpioPst->startTask(); i2cPst->startTask(); #if Q7S_ADD_SPI_TEST == 0 gomSpacePstTask->startTask(); spiPst->startTask(); #endif /* Q7S_ADD_SPI_TEST == 0 */ #elif BOARD_TE0720 == 1 && Q7S_ADD_SPI_TEST == 0 pollingSequenceTaskTE0720->startTask(); #endif pusVerification->startTask(); pusEvents->startTask(); pusHighPrio->startTask(); pusMedPrio->startTask(); pusLowPrio->startTask(); #if OBSW_ADD_TEST_CODE == 1 testTask->startTask(); #endif #if TEST_CCSDS_BRIDGE == 1 ptmeTestTask->startTask(); #endif sif::info << "Tasks started.." << std::endl; }