From c330c9515aff1fccf5ab08910c0f783fe03f8a90 Mon Sep 17 00:00:00 2001 From: Gautier Hattenberger Date: Thu, 25 Dec 2014 23:40:07 +0100 Subject: [PATCH] [papgets] start working on multi AC papgets --- sw/ground_segment/cockpit/live.ml | 1 + sw/ground_segment/cockpit/papgets.ml | 15 ++++++++++++--- sw/lib/ocaml/papget.ml | 6 +++--- sw/lib/ocaml/papget.mli | 1 + 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/sw/ground_segment/cockpit/live.ml b/sw/ground_segment/cockpit/live.ml index 244db7a4d5f..69fb005bf84 100644 --- a/sw/ground_segment/cockpit/live.ml +++ b/sw/ground_segment/cockpit/live.ml @@ -545,6 +545,7 @@ let create_ac = fun alert (geomap:G.widget) (acs_notebook:GPack.notebook) (ac_id (* Drag for Drop *) let papget = Papget_common.xml "goto_block" "button" [ "block_name", block_name; + "sender", ac_id; "icon", icon] in Papget_common.dnd_source b#coerce papget; diff --git a/sw/ground_segment/cockpit/papgets.ml b/sw/ground_segment/cockpit/papgets.ml index 120fdc2b52d..62797dd84d5 100644 --- a/sw/ground_segment/cockpit/papgets.ml +++ b/sw/ground_segment/cockpit/papgets.ml @@ -42,9 +42,11 @@ let papget_listener = fun papget -> try let field = Papget_common.get_property "field" papget in + let sender = Papget_common.get_property "sender" papget in + prerr_endline field; flush stderr; match Str.split sep field with [msg_name; field_name] -> - (new Papget.message_field msg_name field_name) + (new Papget.message_field ~sender msg_name field_name) | _ -> failwith (sprintf "Unexpected field spec: %s" field) with _ -> failwith (sprintf "field attr expected in '%s" (Xml.to_string papget)) @@ -72,7 +74,8 @@ let extra_functions = let expression_listener = fun papget -> let expr = Papget_common.get_property "expr" papget in let expr = Expr_lexer.parse expr in - new Papget.expression ~extra_functions expr + let sender = Papget_common.get_property "sender" papget in + new Papget.expression ~extra_functions ~sender expr @@ -125,12 +128,17 @@ let create = fun canvas_group papget -> let block_name = Papget_common.get_property "block_name" papget in let clicked = fun () -> prerr_endline "Warning: goto_block papget sends to all A/C"; + let sender = Papget_common.get_property "sender" papget in + printf "%s\n" sender; flush stdout; Hashtbl.iter (fun ac_id ac -> + printf "%s %s\n" sender ac_id; flush stdout; + if ac_id = sender then begin let blocks = ExtXml.child ac.Live.fp "blocks" in let block = ExtXml.child ~select:(fun x -> ExtXml.attrib x "name" = block_name) blocks "block" in let block_id = ExtXml.int_attrib block "no" in Live.jump_to_block ac_id block_id + end ) Live.aircrafts in @@ -198,13 +206,14 @@ let parse_message_dnd = | _ -> raise (Parse_message_dnd (Printf.sprintf "parse_dnd: %s" s)) let dnd_data_received = fun canvas_group _context ~x ~y data ~info ~time -> try (* With the format sent by Messages *) - let (_sender, _class_name, msg_name, field_name,scale) = parse_message_dnd data#data in + let (sender, _class_name, msg_name, field_name,scale) = parse_message_dnd data#data in let attrs = [ "type", "message_field"; "display", "text"; "x", sprintf "%d" x; "y", sprintf "%d" y ] and props = [ Papget_common.property "field" (sprintf "%s:%s" msg_name field_name); + Papget_common.property "sender" sender; Papget_common.property "scale" scale ] in let papget_xml = Xml.Element ("papget", attrs, props) in create canvas_group papget_xml diff --git a/sw/lib/ocaml/papget.ml b/sw/lib/ocaml/papget.ml index 8968fcb2bf2..7a497cc922b 100644 --- a/sw/lib/ocaml/papget.ml +++ b/sw/lib/ocaml/papget.ml @@ -83,7 +83,7 @@ object end -let hash_vars = fun expr -> +let hash_vars = fun ?sender expr -> let htable = Hashtbl.create 3 in let rec loop = function E.Ident i -> prerr_endline i @@ -131,8 +131,8 @@ let eval_expr = fun (extra_functions:(string * (string list -> string)) list) h -class expression = fun ?(extra_functions=[]) expr -> - let h = hash_vars expr in +class expression = fun ?(extra_functions=[]) ?sender expr -> + let h = hash_vars ~sender expr in object val mutable callbacks = [] val mutable last_value = "0." diff --git a/sw/lib/ocaml/papget.mli b/sw/lib/ocaml/papget.mli index 21b1115566f..1ea06e8c1a3 100644 --- a/sw/lib/ocaml/papget.mli +++ b/sw/lib/ocaml/papget.mli @@ -45,6 +45,7 @@ class message_field : class expression : ?extra_functions:(string * (string list -> string)) list -> + ?sender:string -> Expr_syntax.expression -> value