diff --git a/bsp_hosted/CMakeLists.txt b/bsp_hosted/CMakeLists.txt index 2804977d..2e979ff4 100644 --- a/bsp_hosted/CMakeLists.txt +++ b/bsp_hosted/CMakeLists.txt @@ -2,3 +2,4 @@ target_sources(${OBSW_NAME} PUBLIC InitMission.cpp main.cpp ObjectFactory.cpp) add_subdirectory(fsfwconfig) add_subdirectory(boardconfig) +add_subdirectory(dummies) diff --git a/bsp_hosted/InitMission.cpp b/bsp_hosted/InitMission.cpp index e14b3d94..971a0533 100644 --- a/bsp_hosted/InitMission.cpp +++ b/bsp_hosted/InitMission.cpp @@ -143,6 +143,14 @@ void initmission::initTasks() { if (result != HasReturnvaluesIF::RETURN_OK) { initmission::printAddObjectError("THERMAL_CONTROLLER", objects::THERMAL_CONTROLLER); } + + // needs high priority to be able to run before the controller tasks + PeriodicTaskIF* dummyTask = factory->createPeriodicTask( + "THERMAL_CTL_TASK", 50, PeriodicTaskIF::MINIMUM_STACK_SIZE, 1.0, missedDeadlineFunc); + result = dummyTask->addComponent(objects::RTD_0_IC3_PLOC_HEATSPREADER); + if (result != HasReturnvaluesIF::RETURN_OK) { + initmission::printAddObjectError("RTD_0", objects::RTD_0_IC3_PLOC_HEATSPREADER); + } #if OBSW_ADD_TEST_CODE == 1 result = testTask->addComponent(objects::TEST_TASK); if (result != HasReturnvaluesIF::RETURN_OK) { @@ -163,6 +171,8 @@ void initmission::initTasks() { thermalControllerTask->startTask(); + dummyTask->startTask(); + #if OBSW_ADD_TEST_CODE == 1 testTask->startTask(); #endif /* OBSW_ADD_TEST_CODE == 1 */ diff --git a/bsp_hosted/ObjectFactory.cpp b/bsp_hosted/ObjectFactory.cpp index 51b6b659..871858aa 100644 --- a/bsp_hosted/ObjectFactory.cpp +++ b/bsp_hosted/ObjectFactory.cpp @@ -26,6 +26,8 @@ #include #endif +#include "dummies/TemperatureSensorsDummy.h" + void Factory::setStaticFrameworkObjectIds() { PusServiceBase::packetSource = objects::PUS_PACKET_DISTRIBUTOR; PusServiceBase::packetDestination = objects::TM_FUNNEL; @@ -45,6 +47,8 @@ void ObjectFactory::produce(void* args) { Factory::setStaticFrameworkObjectIds(); ObjectFactory::produceGenericObjects(); + + new TemperatureSensorsDummy(); new ThermalController(objects::THERMAL_CONTROLLER, objects::NO_OBJECT); //new TestTask(objects::TEST_TASK); diff --git a/bsp_hosted/comIF/CMakeLists.txt b/bsp_hosted/comIF/CMakeLists.txt index 9301d6b0..568cf560 100644 --- a/bsp_hosted/comIF/CMakeLists.txt +++ b/bsp_hosted/comIF/CMakeLists.txt @@ -1 +1 @@ -target_sources(${TARGET_NAME} PUBLIC ArduinoComIF.cpp ArduinoCookie.cpp) +target_sources(${OBSW_NAME} PUBLIC ArduinoComIF.cpp ArduinoCookie.cpp) diff --git a/bsp_hosted/dummies/CMakeLists.txt b/bsp_hosted/dummies/CMakeLists.txt new file mode 100644 index 00000000..14fd41d4 --- /dev/null +++ b/bsp_hosted/dummies/CMakeLists.txt @@ -0,0 +1 @@ +target_sources(${OBSW_NAME} PUBLIC TemperatureSensorsDummy.cpp) diff --git a/bsp_hosted/dummies/TemperatureSensorsDummy.cpp b/bsp_hosted/dummies/TemperatureSensorsDummy.cpp new file mode 100644 index 00000000..5a9c562b --- /dev/null +++ b/bsp_hosted/dummies/TemperatureSensorsDummy.cpp @@ -0,0 +1,83 @@ +#include "TemperatureSensorsDummy.h" + +#include + +#include +#include + +TemperatureSensorsDummy::TemperatureSensorsDummy() + : ExtendedControllerBase(objects::RTD_0_IC3_PLOC_HEATSPREADER, objects::NO_OBJECT), + max31865Set(this) { + ObjectManager::instance()->insert(objects::RTD_1_IC4_PLOC_MISSIONBOARD, this); + ObjectManager::instance()->insert(objects::RTD_2_IC5_4K_CAMERA, this); + ObjectManager::instance()->insert(objects::RTD_3_IC6_DAC_HEATSPREADER, this); + ObjectManager::instance()->insert(objects::RTD_4_IC7_STARTRACKER, this); + ObjectManager::instance()->insert(objects::RTD_5_IC8_RW1_MX_MY, this); + ObjectManager::instance()->insert(objects::RTD_6_IC9_DRO, this); + ObjectManager::instance()->insert(objects::RTD_7_IC10_SCEX, this); + ObjectManager::instance()->insert(objects::RTD_8_IC11_X8, this); + ObjectManager::instance()->insert(objects::RTD_9_IC12_HPA, this); + ObjectManager::instance()->insert(objects::RTD_10_IC13_PL_TX, this); + ObjectManager::instance()->insert(objects::RTD_11_IC14_MPA, this); + ObjectManager::instance()->insert(objects::RTD_12_IC15_ACU, this); + ObjectManager::instance()->insert(objects::RTD_13_IC16_PLPCDU_HEATSPREADER, this); + ObjectManager::instance()->insert(objects::RTD_14_IC17_TCS_BOARD, this); + ObjectManager::instance()->insert(objects::RTD_15_IC18_IMTQ, this); +} + +ReturnValue_t TemperatureSensorsDummy::initialize() { + static bool done = false; + if (not done) { + done = true; + ReturnValue_t result = ExtendedControllerBase::initialize(); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + } + + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t TemperatureSensorsDummy::handleCommandMessage(CommandMessage* message) { + return RETURN_FAILED; +} + +void TemperatureSensorsDummy::performControlOperation() { + iteration++; + value = sin(iteration / 80. * M_PI) * 10; + + max31865Set.read(); + max31865Set.temperatureCelcius = value; + max31865Set.commit(); +} + +ReturnValue_t TemperatureSensorsDummy::initializeLocalDataPool( + localpool::DataPool& localDataPoolMap, LocalDataPoolManager& poolManager) { + localDataPoolMap.emplace(Max31865Definitions::PoolIds::RTD_VALUE, new PoolEntry({0})); + localDataPoolMap.emplace(Max31865Definitions::PoolIds::TEMPERATURE_C, + new PoolEntry({0}, 1, true)); + localDataPoolMap.emplace(Max31865Definitions::PoolIds::FAULT_BYTE, new PoolEntry({0})); + + return RETURN_OK; +} + +LocalPoolDataSetBase* TemperatureSensorsDummy::getDataSetHandle(sid_t sid) { + sif::debug << "getHandle" << std::endl; + switch (sid.ownerSetId) { + case Max31865Definitions::MAX31865_SET_ID: + return &max31865Set; + default: + return nullptr; + } +} + +ReturnValue_t TemperatureSensorsDummy::checkModeCommand(Mode_t mode, Submode_t submode, + uint32_t* msToReachTheMode) { + if (submode != SUBMODE_NONE) { + return INVALID_SUBMODE; + } + if ((mode != MODE_OFF) && (mode != MODE_ON) && (mode != MODE_NORMAL)) { + return INVALID_MODE; + } + return RETURN_OK; +} diff --git a/bsp_hosted/dummies/TemperatureSensorsDummy.h b/bsp_hosted/dummies/TemperatureSensorsDummy.h new file mode 100644 index 00000000..8aeb50df --- /dev/null +++ b/bsp_hosted/dummies/TemperatureSensorsDummy.h @@ -0,0 +1,29 @@ +#pragma once + +#include +#include + +class TemperatureSensorsDummy : public ExtendedControllerBase { + public: + TemperatureSensorsDummy(); + + ReturnValue_t initialize() override; + + protected: + virtual ReturnValue_t handleCommandMessage(CommandMessage* message) override; + virtual void performControlOperation() override; + virtual ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap, + LocalDataPoolManager& poolManager) override; + virtual LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override; + + // Mode abstract functions + virtual ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode, + uint32_t* msToReachTheMode) override; + + private: + int iteration = 0; + float value = 0; + Max31865Definitions::Max31865Set max31865Set; + + void noise(); +}; \ No newline at end of file