From 36206a789f1283ef9c5a1f1e98c5b16f80df3911 Mon Sep 17 00:00:00 2001 From: Gautier Hattenberger Date: Fri, 7 Nov 2014 22:47:51 +0100 Subject: [PATCH] [ocaml][messages] use quotes for char arrays - char[] are now treated as 'real' strings - no more delimiters for other arrays (where space characters should not appear) - INFO_MSG are printed in the GCS console --- conf/messages.xml | 12 +++++++---- .../subsystems/datalink/ivy_transport.c | 21 ++++++++++++------- sw/ground_segment/cockpit/live.ml | 8 +++++++ sw/ground_segment/tmtc/server.ml | 4 ++-- sw/lib/ocaml/pprz.ml | 20 ++++++++++++------ 5 files changed, 46 insertions(+), 19 deletions(-) diff --git a/conf/messages.xml b/conf/messages.xml index 52dd6a17803..de0cf7ac82d 100644 --- a/conf/messages.xml +++ b/conf/messages.xml @@ -1923,10 +1923,14 @@ - - - - + + + + + + + + diff --git a/sw/airborne/subsystems/datalink/ivy_transport.c b/sw/airborne/subsystems/datalink/ivy_transport.c index d8188d5eedb..2e76554f7d3 100644 --- a/sw/airborne/subsystems/datalink/ivy_transport.c +++ b/sw/airborne/subsystems/datalink/ivy_transport.c @@ -41,9 +41,9 @@ static void put_bytes(struct ivy_transport *trans, struct link_device *dev __att { const uint8_t *b = (const uint8_t *) bytes; - // Start delimiter for arrays - if (format == DL_FORMAT_ARRAY) { - trans->ivy_p += sprintf(trans->ivy_p, "|"); + // Start delimiter "quote" for char arrays (strings) + if (format == DL_FORMAT_ARRAY && type == DL_TYPE_CHAR) { + trans->ivy_p += sprintf(trans->ivy_p, "\""); } int i = 0; @@ -109,17 +109,24 @@ static void put_bytes(struct ivy_transport *trans, struct link_device *dev __att i++; break; } - // Coma delimiter for array, space otherwise + // Coma delimiter for array, no delimiter for char array (string), space otherwise if (format == DL_FORMAT_ARRAY) { - trans->ivy_p += sprintf(trans->ivy_p, ","); + if (type != DL_TYPE_CHAR) { + trans->ivy_p += sprintf(trans->ivy_p, ","); + } } else { trans->ivy_p += sprintf(trans->ivy_p, " "); } } - // End delimiter for arrays + // space end delimiter for arrays, additionally un-quote char arrays (strings) if (format == DL_FORMAT_ARRAY) { - trans->ivy_p += sprintf(trans->ivy_p, "| "); + if (type == DL_TYPE_CHAR) { + trans->ivy_p += sprintf(trans->ivy_p, "\" "); + } + else { + trans->ivy_p += sprintf(trans->ivy_p, " "); + } } } diff --git a/sw/ground_segment/cockpit/live.ml b/sw/ground_segment/cockpit/live.ml index 814027b7ef5..df3390a42cf 100644 --- a/sw/ground_segment/cockpit/live.ml +++ b/sw/ground_segment/cockpit/live.ml @@ -1382,6 +1382,13 @@ let listen_error = fun a -> log_and_say a "gcs" msg in safe_bind "TELEMETRY_ERROR" get_error +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 + tele_bind "INFO_MSG" (get_msg a) + let listen_tcas = fun a -> let get_alarm_tcas = fun a txt _sender vs -> let ac = find_ac _sender in @@ -1419,6 +1426,7 @@ let listen_acs_and_msgs = fun geomap ac_notebook my_alert auto_center_new_ac alt listen_telemetry_status (); listen_alert my_alert; listen_error my_alert; + listen_info_msg my_alert; listen_tcas my_alert; listen_dcshot geomap; diff --git a/sw/ground_segment/tmtc/server.ml b/sw/ground_segment/tmtc/server.ml index b457da243c5..1ecee825fca 100644 --- a/sw/ground_segment/tmtc/server.ml +++ b/sw/ground_segment/tmtc/server.ml @@ -201,7 +201,7 @@ let send_dl_values = fun a -> for i = 0 to a.nb_dl_setting_values - 1 do csv := sprintf "%s%f," !csv a.dl_setting_values.(i) done; - let vs = ["ac_id", Pprz.String a.id; "values", Pprz.String ("|"^ !csv ^"|")] in + let vs = ["ac_id", Pprz.String a.id; "values", Pprz.String !csv] in Ground_Pprz.message_send my_id "DL_VALUES" vs let send_svsinfo = fun a -> @@ -223,7 +223,7 @@ let send_svsinfo = fun a -> concat azim a.svinfo.(i).azim; concat age a.svinfo.(i).age done; - let f = fun s r -> (s, Pprz.String ("|"^ !r ^"|")) in + let f = fun s r -> (s, Pprz.String !r) in let vs = ["ac_id", Pprz.String a.id; "pacc", Pprz.Int a.gps_Pacc; f "svid" svid; f "flags" flags; f "qi" qi; f "msg_age" age; diff --git a/sw/lib/ocaml/pprz.ml b/sw/lib/ocaml/pprz.ml index 8191b9889e2..de41089b773 100644 --- a/sw/lib/ocaml/pprz.ml +++ b/sw/lib/ocaml/pprz.ml @@ -146,7 +146,7 @@ let rec value = fun t v -> | Scalar "uint32" -> Int64 (Int64.of_string v) | Scalar ("uint64" | "int64") -> Int64 (Int64.of_string v) | Scalar ("float" | "double") -> Float (float_of_string v) - | Scalar "string" -> String v + | ArrayType "char" | FixedArrayType ("char", _) | Scalar "string" -> String v | Scalar "char" -> Char v.[0] | ArrayType t' -> Array (Array.map (value (Scalar t')) (Array.of_list (split_array v))) @@ -162,7 +162,11 @@ let rec string_of_value = function | Int64 x -> Int64.to_string x | Char c -> String.make 1 c | String s -> s - | Array a -> "|"^(String.concat separator (Array.to_list (Array.map string_of_value a)))^"|" + | Array a -> + let l = (Array.to_list (Array.map string_of_value a)) in + match a.(0) with + | Char _ -> "\""^(String.concat "" l)^"\"" + | _ -> String.concat separator l let magic = fun x -> (Obj.magic x:('a,'b,'c) Pervasives.format) @@ -182,7 +186,11 @@ let rec formatted_string_of_value = fun format v -> | 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)))^"|" + | Array a -> + let l = (Array.to_list (Array.map (formatted_string_of_value format) a)) in + match a.(0) with + | Char _ -> "\""^(String.concat "" l)^"\"" + | _ -> String.concat separator l let sizeof = fun f -> @@ -681,15 +689,15 @@ module MessagesOfXml(Class:CLASS_Xml) = struct let space = Str.regexp "[ \t]+" - let array_sep = Str.regexp "|" + let array_sep = Str.regexp "\"" let values_of_string = fun s -> (* split arguments and arrays *) let array_split = Str.full_split array_sep s in let rec loop = fun fields -> match fields with | [] -> [] - | (Str.Delim "|")::((Str.Text l)::[Str.Delim "|"]) -> [l] - | (Str.Delim "|")::((Str.Text l)::((Str.Delim "|")::xs)) -> [l] @ (loop xs) + | (Str.Delim "\"")::((Str.Text l)::[Str.Delim "\""]) -> [l] + | (Str.Delim "\"")::((Str.Text l)::((Str.Delim "\"")::xs)) -> [l] @ (loop xs) | [Str.Text x] -> Str.split space x | (Str.Text x)::xs -> (Str.split space x) @ (loop xs) | (Str.Delim _)::_ -> failwith "Pprz.values_of_string: incorrect array delimiter"