Skip to content

Commit

Permalink
[ocaml][messages] use quotes for char arrays
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
gautierhattenberger authored and flixr committed Nov 10, 2014
1 parent 31b6600 commit 36206a7
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 19 deletions.
12 changes: 8 additions & 4 deletions conf/messages.xml
Expand Up @@ -1923,10 +1923,14 @@
<field name="wn" type="float"/>
</message>

<!--215 is free -->
<!--216 is free -->
<!--217 is free -->
<!--218 is free -->
<message name="INFO_MSG" id="215">
<field name="msg" type="char[]"/>
</message>

<!--216 is free -->
<!--217 is free -->
<!--218 is free -->

<message name="WEATHER" id="219">
<field name="p_amb" type="float" unit="Pa" alt_unit="mBar" alt_unit_coef="0.01"/>
<field name="t_amb" type="float" unit="deg C"/>
Expand Down
21 changes: 14 additions & 7 deletions sw/airborne/subsystems/datalink/ivy_transport.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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, " ");
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions sw/ground_segment/cockpit/live.ml
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions sw/ground_segment/tmtc/server.ml
Expand Up @@ -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 ->
Expand All @@ -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;
Expand Down
20 changes: 14 additions & 6 deletions sw/lib/ocaml/pprz.ml
Expand Up @@ -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)))
Expand All @@ -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)
Expand All @@ -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 ->
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 36206a7

Please sign in to comment.