From c5002218942c8498690982e9708cb13533f81340 Mon Sep 17 00:00:00 2001 From: Matthias Grob Date: Thu, 14 Dec 2017 08:40:16 +0100 Subject: [PATCH] FlightTasks: move methods of the class header into the cpp --- src/lib/FlightTasks/FlightTasks.cpp | 66 +++++++++++++++++++++++++++++ src/lib/FlightTasks/FlightTasks.hpp | 66 +---------------------------- 2 files changed, 68 insertions(+), 64 deletions(-) diff --git a/src/lib/FlightTasks/FlightTasks.cpp b/src/lib/FlightTasks/FlightTasks.cpp index 75f42c14a6..746b46ed6e 100644 --- a/src/lib/FlightTasks/FlightTasks.cpp +++ b/src/lib/FlightTasks/FlightTasks.cpp @@ -3,6 +3,72 @@ #include #include +bool FlightTasks::update() +{ + _updateCommand(); + + if (isAnyTaskActive()) { + _subscription_array.update(); + return _current_task->updateInitialize() && _current_task->update(); + } + + return false; +} + +int FlightTasks::switchTask(int task_number) +{ + /* switch to the running task, nothing to do */ + if (task_number == _current_task_index) { + return 0; + } + + /* disable the old task if there is any */ + if (_current_task) { + _current_task->~FlightTask(); + _current_task = nullptr; + _current_task_index = -1; + } + + switch (task_number) { + case 0: + _current_task = new (&_task_union.manual) FlightTaskManual(this, "MAN"); + break; + + case 1: + _current_task = new (&_task_union.orbit) FlightTaskOrbit(this, "ORB"); + break; + + case -1: + /* disable tasks is a success */ + return 0; + + default: + /* invalid task */ + return -1; + } + + /* subscription failed */ + if (!_current_task->initializeSubscriptions(_subscription_array)) { + _current_task->~FlightTask(); + _current_task = nullptr; + _current_task_index = -1; + return -2; + } + + _subscription_array.forcedUpdate(); // make sure data is available for all new subscriptions + + /* activation failed */ + if (!_current_task->updateInitialize() || !_current_task->activate()) { + _current_task->~FlightTask(); + _current_task = nullptr; + _current_task_index = -1; + return -3; + } + + _current_task_index = task_number; + return 0; +} + bool FlightTasks::_updateCommand() { /* lazy subscription to command topic */ diff --git a/src/lib/FlightTasks/FlightTasks.hpp b/src/lib/FlightTasks/FlightTasks.hpp index a8e5d33dd3..0cdf7f4e61 100644 --- a/src/lib/FlightTasks/FlightTasks.hpp +++ b/src/lib/FlightTasks/FlightTasks.hpp @@ -67,17 +67,7 @@ public: * Call regularly in the control loop cycle to execute the task * @return true on success, false on error */ - bool update() - { - _updateCommand(); - - if (isAnyTaskActive()) { - _subscription_array.update(); - return _current_task->updateInitialize() && _current_task->update(); - } - - return false; - } + bool update(); /** * Get the output data from the current task @@ -105,59 +95,7 @@ public: * @param task number to switch to * @return 0 on success, <0 on error */ - int switchTask(int task_number) - { - /* switch to the running task, nothing to do */ - if (task_number == _current_task_index) { - return 0; - } - - /* disable the old task if there is any */ - if (_current_task) { - _current_task->~FlightTask(); - _current_task = nullptr; - _current_task_index = -1; - } - - switch (task_number) { - case 0: - _current_task = new (&_task_union.manual) FlightTaskManual(this, "MAN"); - break; - - case 1: - _current_task = new (&_task_union.orbit) FlightTaskOrbit(this, "ORB"); - break; - - case -1: - /* disable tasks is a success */ - return 0; - - default: - /* invalid task */ - return -1; - } - - /* subscription failed */ - if (!_current_task->initializeSubscriptions(_subscription_array)) { - _current_task->~FlightTask(); - _current_task = nullptr; - _current_task_index = -1; - return -2; - } - - _subscription_array.forcedUpdate(); // make sure data is available for all new subscriptions - - /* activation failed */ - if (!_current_task->updateInitialize() || !_current_task->activate()) { - _current_task->~FlightTask(); - _current_task = nullptr; - _current_task_index = -1; - return -3; - } - - _current_task_index = task_number; - return 0; - } + int switchTask(int task_number); /** * Get the number of the active task