diff --git a/sw/ground_segment/tmtc/messages.ml b/sw/ground_segment/tmtc/messages.ml index 11d07a1087..e9cedcda20 100644 --- a/sw/ground_segment/tmtc/messages.ml +++ b/sw/ground_segment/tmtc/messages.ml @@ -57,6 +57,7 @@ let one_page = fun sender class_name (notebook:GPack.notebook) bind m -> let field_name = Xml.attrib f "name" in let type_ = ExtXml.attrib f "type" in let name = Printf.sprintf "%s %s %s: " type_ field_name unit in + let format_ = try Some (Xml.attrib f "format") with _ -> None in let h = GPack.hbox ~packing:v#pack () in let field_label = GButton.button ~label:name ~packing:h#pack () in @@ -76,7 +77,9 @@ let one_page = fun sender class_name (notebook:GPack.notebook) bind m -> let i = Pprz.int_of_value x in sprintf "%s (%d)" literal_values.(i) i with _ -> - alt_value (Pprz.string_of_value x) + match format_ with + | Some f -> alt_value (Pprz.formatted_string_of_value f x) + | _ -> alt_value (Pprz.string_of_value x) and display_value = fun () -> if notebook#page_num v#coerce = notebook#current_page then if l#label <> !value then l#set_text !value in diff --git a/sw/lib/ocaml/pprz.ml b/sw/lib/ocaml/pprz.ml index 7a86919d23..1f0f7af96a 100644 --- a/sw/lib/ocaml/pprz.ml +++ b/sw/lib/ocaml/pprz.ml @@ -168,10 +168,15 @@ let rec string_of_value = function let magic = fun x -> (Obj.magic x:('a,'b,'c) Pervasives.format) -let formatted_string_of_value = fun format v -> +let rec formatted_string_of_value = fun format v -> match v with - Float x -> sprintf (magic format) x - | v -> string_of_value v + | Int x -> sprintf (magic format) x + | Float x -> sprintf (magic format) x + | Int32 x -> sprintf (magic format) x + | Int64 x -> sprintf (magic format) x + | Char x -> sprintf (magic format) x + | String x -> sprintf (magic format) x + | Array a -> "|"^(String.concat separator (Array.to_list (Array.map (formatted_string_of_value format) a)))^"|" let sizeof = fun f -> diff --git a/sw/lib/ocaml/pprz.mli b/sw/lib/ocaml/pprz.mli index a0c10daf0e..6eb4657db9 100644 --- a/sw/lib/ocaml/pprz.mli +++ b/sw/lib/ocaml/pprz.mli @@ -63,6 +63,7 @@ val is_fixed_array_type : string -> bool val size_of_field : field -> int val string_of_value : value -> string +val formatted_string_of_value : 'a -> value -> string val int_of_value : value -> int (* May raise Invalid_argument *) type type_descr = { format : string ;