From 295714793dcbf2b5bd677f3491ee901c678a0320 Mon Sep 17 00:00:00 2001 From: Gautier Hattenberger Date: Fri, 31 Oct 2014 00:18:18 +0100 Subject: [PATCH] [gen_fligtplan] 'call' statement can be configured to loop and/or break 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 --- conf/flight_plans/flight_plan.dtd | 4 ++- sw/tools/generators/gen_flight_plan.ml | 42 ++++++++++++++++++++------ 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/conf/flight_plans/flight_plan.dtd b/conf/flight_plans/flight_plan.dtd index 33599ac043e..68be3712bbc 100644 --- a/conf/flight_plans/flight_plan.dtd +++ b/conf/flight_plans/flight_plan.dtd @@ -162,7 +162,9 @@ value CDATA #REQUIRED> +until CDATA #IMPLIED +loop CDATA #IMPLIED +break CDATA #IMPLIED> | "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