From e95647c572aa4f2769f99840263145c61c657108 Mon Sep 17 00:00:00 2001 From: Ulrich Mohr Date: Mon, 14 Feb 2022 13:49:12 +0100 Subject: [PATCH] working on thermal controller unit test. --- mission/controller/ThermalController.cpp | 36 ++++++++++++++-- mission/controller/ThermalController.h | 9 ++-- .../ThermalControllerDefinitions.h | 43 +++++++++++++++++++ unittest/controller/testThermalController.cpp | 36 +++++++++++++--- unittest/main.cpp | 4 -- 5 files changed, 111 insertions(+), 17 deletions(-) create mode 100644 mission/controller/controllerdefinitions/ThermalControllerDefinitions.h diff --git a/mission/controller/ThermalController.cpp b/mission/controller/ThermalController.cpp index 04ab8682..8ca86b7e 100644 --- a/mission/controller/ThermalController.cpp +++ b/mission/controller/ThermalController.cpp @@ -1,20 +1,50 @@ #include "ThermalController.h" -ThermalController::ThermalController(object_id_t objectId, object_id_t parentId) :ExtendedControllerBase(objectId, parentId) {} +ThermalController::ThermalController(object_id_t objectId, object_id_t parentId) + : ExtendedControllerBase(objectId, parentId), + sensorTemperatures(this), + componentTemperatures(this) {} ReturnValue_t ThermalController::perform() { return HasReturnvaluesIF::RETURN_FAILED; } ReturnValue_t ThermalController::handleCommandMessage(CommandMessage* message) { return RETURN_FAILED; } -void ThermalController::performControlOperation() {} +void ThermalController::performControlOperation() { + sif::info << "tc performOperation()" << std::endl; + + ReturnValue_t result = sensorTemperatures.read(); + if (result != RETURN_OK) { + return; + } + result = componentTemperatures.read(); + if (result != RETURN_OK) { + return; + } + + componentTemperatures.rw = (sensorTemperatures.rw.value + sensorTemperatures.gps.value) / 2; + + sensorTemperatures.commit(); + componentTemperatures.commit(); +} + ReturnValue_t ThermalController::initializeLocalDataPool(localpool::DataPool& localDataPoolMap, LocalDataPoolManager& poolManager) { + localDataPoolMap.emplace(thermalControllerDefinitions::SENSOR_RW, new PoolEntry({0.0})); + localDataPoolMap.emplace(thermalControllerDefinitions::SENSOR_GPS, new PoolEntry({0.0})); + localDataPoolMap.emplace(thermalControllerDefinitions::COMPONENT_RW, new PoolEntry({0.0})); + return RETURN_OK; } LocalPoolDataSetBase* ThermalController::getDataSetHandle(sid_t sid) { return nullptr; } ReturnValue_t ThermalController::checkModeCommand(Mode_t mode, Submode_t submode, uint32_t* msToReachTheMode) { - return RETURN_FAILED; + if (submode != SUBMODE_NONE) { + return INVALID_SUBMODE; + } + if ((mode != MODE_OFF) && (mode != MODE_ON) && (mode != MODE_NORMAL)) { + return INVALID_MODE; + } + return RETURN_OK; } \ No newline at end of file diff --git a/mission/controller/ThermalController.h b/mission/controller/ThermalController.h index 1faba29f..58e147e3 100644 --- a/mission/controller/ThermalController.h +++ b/mission/controller/ThermalController.h @@ -2,8 +2,7 @@ #define MISSION_CONTROLLER_THERMALCONTROLLER_H_ #include - - +#include class ThermalController : public ExtendedControllerBase { public: @@ -11,7 +10,7 @@ class ThermalController : public ExtendedControllerBase { ReturnValue_t perform(); -protected: + protected: virtual ReturnValue_t handleCommandMessage(CommandMessage* message) override; virtual void performControlOperation() override; virtual ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap, @@ -21,6 +20,10 @@ protected: // Mode abstract functions virtual ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode, uint32_t* msToReachTheMode) override; + + private: + thermalControllerDefinitions::SensorTemperatures sensorTemperatures; + thermalControllerDefinitions::ComponentTemperatures componentTemperatures; }; #endif /* MISSION_CONTROLLER_THERMALCONTROLLER_H_ */ diff --git a/mission/controller/controllerdefinitions/ThermalControllerDefinitions.h b/mission/controller/controllerdefinitions/ThermalControllerDefinitions.h new file mode 100644 index 00000000..48853778 --- /dev/null +++ b/mission/controller/controllerdefinitions/ThermalControllerDefinitions.h @@ -0,0 +1,43 @@ +#ifndef MISSION_CONTROLLER_CONTROLLERDEFINITIONS_THERMALCONTROLLERDEFINITIONS_H_ +#define MISSION_CONTROLLER_CONTROLLERDEFINITIONS_THERMALCONTROLLERDEFINITIONS_H_ + +#include +#include + +namespace thermalControllerDefinitions { + +enum SetIds : uint32_t { SENSOR_TEMPERATURES, COMPONENT_TEMPERATURES }; + +enum PoolIds : lp_id_t { SENSOR_RW, SENSOR_GPS, COMPONENT_RW }; + +/** + * @brief This dataset can be used to store the collected temperatures of all temperature sensors + */ +class SensorTemperatures : public StaticLocalDataSet<2> { + public: + SensorTemperatures(HasLocalDataPoolIF* owner) : StaticLocalDataSet(owner, SENSOR_TEMPERATURES) {} + + SensorTemperatures(object_id_t objectId) + : StaticLocalDataSet(sid_t(objectId, SENSOR_TEMPERATURES)) {} + + lp_var_t rw = lp_var_t(sid.objectId, PoolIds::SENSOR_RW, this); + lp_var_t gps = lp_var_t(sid.objectId, PoolIds::SENSOR_GPS, this); +}; + +/** + * @brief This dataset can be used to store the collected temperatures of all components + */ +class ComponentTemperatures : public StaticLocalDataSet<2> { + public: + ComponentTemperatures(HasLocalDataPoolIF* owner) + : StaticLocalDataSet(owner, SENSOR_TEMPERATURES) {} + + ComponentTemperatures(object_id_t objectId) + : StaticLocalDataSet(sid_t(objectId, SENSOR_TEMPERATURES)) {} + + lp_var_t rw = lp_var_t(sid.objectId, PoolIds::COMPONENT_RW, this); +}; + +} // namespace thermalControllerDefinitions + +#endif /* MISSION_CONTROLLER_CONTROLLERDEFINITIONS_THERMALCONTROLLERDEFINITIONS_H_ */ \ No newline at end of file diff --git a/unittest/controller/testThermalController.cpp b/unittest/controller/testThermalController.cpp index 357cadd2..9c2b227a 100644 --- a/unittest/controller/testThermalController.cpp +++ b/unittest/controller/testThermalController.cpp @@ -1,13 +1,11 @@ +#include #include #include #include +#include #include #include #include -#include - - - #include #include @@ -34,14 +32,38 @@ void factory(void* args) { } TEST_CASE("Thermal Controller", "[ThermalController]") { - bool test = true; - REQUIRE(test == true); + + const object_id_t THERMAL_CONTROLLER_ID = 0x123; - ThermalController controller(0x123, objects::NO_OBJECT); + + ThermalController controller(THERMAL_CONTROLLER_ID, objects::NO_OBJECT); ObjectManager::instance()->setObjectFactoryFunction(factory, nullptr); ObjectManager::instance()->initialize(); ObjectManager::instance()->printList(); + controller.initializeAfterTaskCreation(); + + MessageQueueId_t controllerQueue = controller.getCommandQueue(); + + CommandMessage modeMessage; + + ModeMessage::setModeMessage(&modeMessage, ModeMessage::CMD_MODE_COMMAND, + ControllerBase::MODE_NORMAL, HasModesIF::SUBMODE_NONE); + + MessageQueueIF* commandQueue = QueueFactory::instance()->createMessageQueue( + 5, MessageQueueMessage::MAX_MESSAGE_SIZE); + + commandQueue->sendMessage(controllerQueue,&modeMessage); + REQUIRE(controller.performOperation(0) == HasReturnvaluesIF::RETURN_OK); + + thermalControllerDefinitions::ComponentTemperatures componentTemperatures(THERMAL_CONTROLLER_ID); + + componentTemperatures.read(); + REQUIRE(componentTemperatures.rw == 0); + + componentTemperatures.commit(); + + QueueFactory::instance()->deleteMessageQueue(commandQueue); } \ No newline at end of file diff --git a/unittest/main.cpp b/unittest/main.cpp index fecfaf75..2d65ccb4 100644 --- a/unittest/main.cpp +++ b/unittest/main.cpp @@ -1,10 +1,6 @@ -#include - #include int main(int argc, char* argv[]) { - puts("unittests"); - // Catch internal function call int result = Catch::Session().run(argc, argv);