FlightTaks: prevent running a new task with default parameters because they got rejected

This commit is contained in:
Matthias Grob
2018-04-05 07:30:12 +02:00
committed by Beat Küng
parent d9c7e6321f
commit fd93e55527
2 changed files with 13 additions and 9 deletions
+12 -8
View File
@@ -76,7 +76,7 @@ int FlightTasks::switchTask(int task_number)
}
_current_task_index = task_number;
return 0;
return 1;
}
bool FlightTasks::_updateCommand()
@@ -103,17 +103,21 @@ bool FlightTasks::_updateCommand()
}
/* evaluate command */
uint8_t switch_result = switchTask(int(command.param1));
int switch_result = switchTask(int(command.param1));
uint8_t cmd_result = vehicle_command_ack_s::VEHICLE_RESULT_FAILED;
/* switch succeeded */
if (!switch_result) {
/* if we are in the desired task */
if (switch_result >= 0) {
cmd_result = vehicle_command_ack_s::VEHICLE_RESULT_ACCEPTED;
/* if the correct task is running apply parameters to it and see if it rejects */
if (isAnyTaskActive()) {
if (!_current_task->applyCommandParameters(command)) {
cmd_result = vehicle_command_ack_s::VEHICLE_RESULT_DENIED;
/* if the task is running apply parameters to it and see if it rejects */
if (isAnyTaskActive() && !_current_task->applyCommandParameters(command)) {
cmd_result = vehicle_command_ack_s::VEHICLE_RESULT_DENIED;
/* if we just switched and parameters are not accepted, go to failsafe */
if (switch_result == 1) {
switchTask(-1);
cmd_result = vehicle_command_ack_s::VEHICLE_RESULT_FAILED;
}
}
}
+1 -1
View File
@@ -93,7 +93,7 @@ public:
/**
* Switch to a specific task (for normal usage)
* @param task number to switch to
* @return 0 on success, <0 on error
* @return 1 on success, 0 on no change, <0 on error
*/
int switchTask(int task_number);