From b2af9c3f58d295579380811064e27f8829364d3c Mon Sep 17 00:00:00 2001 From: Dennis Mannhart Date: Wed, 23 May 2018 10:09:32 +0200 Subject: [PATCH] FlightTasks: error to char string message --- src/lib/FlightTasks/FlightTasks.cpp | 11 +++++++++++ src/lib/FlightTasks/FlightTasks.hpp | 20 ++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/lib/FlightTasks/FlightTasks.cpp b/src/lib/FlightTasks/FlightTasks.cpp index 99bb1526d9..92277e3053 100644 --- a/src/lib/FlightTasks/FlightTasks.cpp +++ b/src/lib/FlightTasks/FlightTasks.cpp @@ -140,6 +140,17 @@ void FlightTasks::handleParameterUpdate() } } +const char *FlightTasks::errorToString(const int error) +{ + for (auto e : _taskError) { + if (e.error == error) { + return e.msg; + } + } + + return "This error is not mapped to a string or is unknown."; +} + void FlightTasks::_updateCommand() { // TODO: port flight task mavlink command to have support for this functionality diff --git a/src/lib/FlightTasks/FlightTasks.hpp b/src/lib/FlightTasks/FlightTasks.hpp index 92765815f5..88422239a7 100644 --- a/src/lib/FlightTasks/FlightTasks.hpp +++ b/src/lib/FlightTasks/FlightTasks.hpp @@ -134,6 +134,11 @@ public: */ void handleParameterUpdate(); + /** + * Call this method to get the description of a task error. + */ + const char *errorToString(const int error); + private: /** @@ -161,6 +166,21 @@ private: SubscriptionArray _subscription_array; + struct task_error_t { + int error; + const char *msg; + }; + + static const int _numError = 4; + /** + * Map from Error int to user friendly string. + */ + task_error_t _taskError[_numError] = { + {0, "No Error"}, + {-1, "Invalid Task "}, + {-2, "Subscription Failed"}, + {-3, "Activation Failed"} + }; /** * Check for vehicle commands (received via MAVLink), evaluate and acknowledge them */