From e848f7c0a74b5835c9b738de399f0b5269a9a350 Mon Sep 17 00:00:00 2001 From: Felix Ruess Date: Thu, 6 Nov 2014 16:59:24 +0100 Subject: [PATCH] [ocaml] separate string_of_chars function for printing strings in console --- sw/ground_segment/cockpit/live.ml | 2 +- sw/lib/ocaml/pprz.ml | 11 ++++++++++- sw/lib/ocaml/pprz.mli | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/sw/ground_segment/cockpit/live.ml b/sw/ground_segment/cockpit/live.ml index df3390a42cf..ad54e389d5d 100644 --- a/sw/ground_segment/cockpit/live.ml +++ b/sw/ground_segment/cockpit/live.ml @@ -1386,7 +1386,7 @@ let listen_info_msg = fun a -> let get_msg = fun a _sender vs -> let ac = find_ac _sender in let msg_array = Pprz.assoc "msg" vs in - log_and_say a ac.ac_name (Pprz.string_of_value msg_array) in + log_and_say a ac.ac_name (Pprz.string_of_chars msg_array) in tele_bind "INFO_MSG" (get_msg a) let listen_tcas = fun a -> diff --git a/sw/lib/ocaml/pprz.ml b/sw/lib/ocaml/pprz.ml index 54b46e19ef5..5bd2e25e4aa 100644 --- a/sw/lib/ocaml/pprz.ml +++ b/sw/lib/ocaml/pprz.ml @@ -162,7 +162,16 @@ let rec string_of_value = function | Int64 x -> Int64.to_string x | Char c -> String.make 1 c | String s -> s - | Array a -> let vl = Array.to_list (Array.map string_of_value a) in + | Array a -> "|"^(String.concat separator (Array.to_list (Array.map string_of_value a)))^"|" + +let rec string_of_chars = function + Int x -> string_of_int x + | Float x -> string_of_float x + | Int32 x -> Int32.to_string x + | Int64 x -> Int64.to_string x + | Char c -> String.make 1 c + | String s -> s + | Array a -> let vl = Array.to_list (Array.map string_of_chars a) in match a.(0) with Char x -> String.concat "" vl | _ -> "|"^(String.concat separator vl)^"|" diff --git a/sw/lib/ocaml/pprz.mli b/sw/lib/ocaml/pprz.mli index 6eb4657db9b..c57b75a374d 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 string_of_chars : value -> string val formatted_string_of_value : 'a -> value -> string val int_of_value : value -> int (* May raise Invalid_argument *) type type_descr = {