Skip to content

Commit

Permalink
[gen_fligtplan] 'call' statement can be configured to loop and/or break
Browse files Browse the repository at this point in the history
default behavior:
- the function is called until returning FALSE (same as before)
- at the end of the call, go to next stage immediately (new)

this is related to #830
  • Loading branch information
gautierhattenberger committed Nov 6, 2014
1 parent 43dc0c8 commit 2957147
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
4 changes: 3 additions & 1 deletion conf/flight_plans/flight_plan.dtd
Expand Up @@ -162,7 +162,9 @@ value CDATA #REQUIRED>

<!ATTLIST call
fun CDATA #REQUIRED
until CDATA #IMPLIED>
until CDATA #IMPLIED
loop CDATA #IMPLIED
break CDATA #IMPLIED>

<!ATTLIST follow
ac_id CDATA #REQUIRED
Expand Down
42 changes: 32 additions & 10 deletions sw/tools/generators/gen_flight_plan.ml
Expand Up @@ -494,16 +494,38 @@ let rec print_stage = fun index_of_waypoints x ->
| "call" ->
stage ();
let statement = ExtXml.attrib x "fun" in
lprintf "if (! (%s))\n" statement;
lprintf " NextStageAndBreak();\n";
begin
try
let c = parsed_attrib x "until" in
lprintf "if (%s) NextStageAndBreak();\n" c
with
ExtXml.Error _ -> ()
end;
lprintf "break;\n"
(* by default, function is called while returning TRUE *)
(* otherwise, function is called once and returned value is ignored *)
let loop = String.uppercase (ExtXml.attrib_or_default x "loop" "TRUE") in
(* be default, go to next stage immediately *)
let break = String.uppercase (ExtXml.attrib_or_default x "break" "FALSE") in
begin match loop with
| "TRUE" ->
lprintf "if (! (%s)) {\n" statement;
begin match break with
| "TRUE" -> lprintf " NextStageAndBreak();\n";
| "FALSE" -> lprintf " NextStage();\n";
| _ -> failwith "FP: 'call' break attribute must be TRUE or FALSE";
end;
lprintf "} else {\n";
begin
try
let c = parsed_attrib x "until" in
lprintf " if (%s) NextStageAndBreak();\n" c
with
ExtXml.Error _ -> ()
end;
lprintf " break;\n";
lprintf "}\n"
| "FALSE" ->
lprintf "%s\n" statement;
begin match break with
| "TRUE" -> lprintf "NextStageAndBreak();\n";
| "FALSE" -> lprintf "NextStage();\n";
| _ -> failwith "FP: 'call' break attribute must be TRUE or FALSE";
end;
| _ -> failwith "FP: 'call' loop attribute must be TRUE or FALSE"
end
| "survey_rectangle" ->
let grid = parsed_attrib x "grid"
and wp1 = get_index_waypoint (ExtXml.attrib x "wp1") index_of_waypoints
Expand Down

0 comments on commit 2957147

Please sign in to comment.