mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-06-05 06:54:49 +08:00
[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)
This commit is contained in:
committed by
Felix Ruess
parent
0bcb25ecf7
commit
408b2c8bd1
@@ -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;
|
const uint8_t *b = (const uint8_t *) bytes;
|
||||||
|
|
||||||
// Start delimiter for arrays
|
// Start delimiter "quote" for char arrays (strings)
|
||||||
if (format == DL_FORMAT_ARRAY) {
|
if (format == DL_FORMAT_ARRAY && type == DL_TYPE_CHAR) {
|
||||||
trans->ivy_p += sprintf(trans->ivy_p, "|");
|
trans->ivy_p += sprintf(trans->ivy_p, "\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@@ -109,17 +109,24 @@ static void put_bytes(struct ivy_transport *trans, struct link_device *dev __att
|
|||||||
i++;
|
i++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Coma delimiter for array, space otherwise
|
// Coma delimiter for array, no delimiter for char array (string), space otherwise
|
||||||
if (format == DL_FORMAT_ARRAY) {
|
if (format == DL_FORMAT_ARRAY) {
|
||||||
|
if (type != DL_TYPE_CHAR) {
|
||||||
trans->ivy_p += sprintf(trans->ivy_p, ",");
|
trans->ivy_p += sprintf(trans->ivy_p, ",");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
trans->ivy_p += sprintf(trans->ivy_p, " ");
|
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) {
|
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, " ");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1386,7 +1386,7 @@ let listen_info_msg = fun a ->
|
|||||||
let get_msg = fun a _sender vs ->
|
let get_msg = fun a _sender vs ->
|
||||||
let ac = find_ac _sender in
|
let ac = find_ac _sender in
|
||||||
let msg_array = Pprz.assoc "msg" vs in
|
let msg_array = Pprz.assoc "msg" vs in
|
||||||
log_and_say a ac.ac_name (Pprz.string_of_chars msg_array) in
|
log_and_say a ac.ac_name (Pprz.string_of_value msg_array) in
|
||||||
tele_bind "INFO_MSG" (get_msg a)
|
tele_bind "INFO_MSG" (get_msg a)
|
||||||
|
|
||||||
let listen_tcas = fun a ->
|
let listen_tcas = fun a ->
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ let one_page = fun sender class_name (notebook:GPack.notebook) bind m ->
|
|||||||
with _ ->
|
with _ ->
|
||||||
match format_ with
|
match format_ with
|
||||||
| Some f -> alt_value (Pprz.formatted_string_of_value f x)
|
| Some f -> alt_value (Pprz.formatted_string_of_value f x)
|
||||||
| _ -> alt_value (Pprz.string_of_chars x)
|
| _ -> alt_value (Pprz.string_of_value x)
|
||||||
and display_value = fun () ->
|
and display_value = fun () ->
|
||||||
if notebook#page_num v#coerce = notebook#current_page then
|
if notebook#page_num v#coerce = notebook#current_page then
|
||||||
if l#label <> !value then l#set_text !value in
|
if l#label <> !value then l#set_text !value in
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ let send_dl_values = fun a ->
|
|||||||
for i = 0 to a.nb_dl_setting_values - 1 do
|
for i = 0 to a.nb_dl_setting_values - 1 do
|
||||||
csv := sprintf "%s%f," !csv a.dl_setting_values.(i)
|
csv := sprintf "%s%f," !csv a.dl_setting_values.(i)
|
||||||
done;
|
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
|
Ground_Pprz.message_send my_id "DL_VALUES" vs
|
||||||
|
|
||||||
let send_svsinfo = fun a ->
|
let send_svsinfo = fun a ->
|
||||||
@@ -223,7 +223,7 @@ let send_svsinfo = fun a ->
|
|||||||
concat azim a.svinfo.(i).azim;
|
concat azim a.svinfo.(i).azim;
|
||||||
concat age a.svinfo.(i).age
|
concat age a.svinfo.(i).age
|
||||||
done;
|
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;
|
let vs = ["ac_id", Pprz.String a.id;
|
||||||
"pacc", Pprz.Int a.gps_Pacc;
|
"pacc", Pprz.Int a.gps_Pacc;
|
||||||
f "svid" svid; f "flags" flags; f "qi" qi; f "msg_age" age;
|
f "svid" svid; f "flags" flags; f "qi" qi; f "msg_age" age;
|
||||||
|
|||||||
+13
-17
@@ -146,7 +146,7 @@ let rec value = fun t v ->
|
|||||||
| Scalar "uint32" -> Int64 (Int64.of_string v)
|
| Scalar "uint32" -> Int64 (Int64.of_string v)
|
||||||
| Scalar ("uint64" | "int64") -> Int64 (Int64.of_string v)
|
| Scalar ("uint64" | "int64") -> Int64 (Int64.of_string v)
|
||||||
| Scalar ("float" | "double") -> Float (float_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]
|
| Scalar "char" -> Char v.[0]
|
||||||
| ArrayType t' ->
|
| ArrayType t' ->
|
||||||
Array (Array.map (value (Scalar t')) (Array.of_list (split_array v)))
|
Array (Array.map (value (Scalar t')) (Array.of_list (split_array v)))
|
||||||
@@ -162,19 +162,11 @@ let rec string_of_value = function
|
|||||||
| Int64 x -> Int64.to_string x
|
| Int64 x -> Int64.to_string x
|
||||||
| Char c -> String.make 1 c
|
| Char c -> String.make 1 c
|
||||||
| String s -> s
|
| 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
|
||||||
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
|
match a.(0) with
|
||||||
Char x -> String.concat "" vl
|
| Char _ -> "\""^(String.concat "" l)^"\""
|
||||||
| _ -> "|"^(String.concat separator vl)^"|"
|
| _ -> String.concat separator l
|
||||||
|
|
||||||
|
|
||||||
let magic = fun x -> (Obj.magic x:('a,'b,'c) Pervasives.format)
|
let magic = fun x -> (Obj.magic x:('a,'b,'c) Pervasives.format)
|
||||||
@@ -194,7 +186,11 @@ let rec formatted_string_of_value = fun format v ->
|
|||||||
| Int64 x -> sprintf (magic format) x
|
| Int64 x -> sprintf (magic format) x
|
||||||
| Char x -> sprintf (magic format) x
|
| Char x -> sprintf (magic format) x
|
||||||
| String 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 ->
|
let sizeof = fun f ->
|
||||||
@@ -693,15 +689,15 @@ module MessagesOfXml(Class:CLASS_Xml) = struct
|
|||||||
|
|
||||||
|
|
||||||
let space = Str.regexp "[ \t]+"
|
let space = Str.regexp "[ \t]+"
|
||||||
let array_sep = Str.regexp "|"
|
let array_sep = Str.regexp "\""
|
||||||
let values_of_string = fun s ->
|
let values_of_string = fun s ->
|
||||||
(* split arguments and arrays *)
|
(* split arguments and arrays *)
|
||||||
let array_split = Str.full_split array_sep s in
|
let array_split = Str.full_split array_sep s in
|
||||||
let rec loop = fun fields ->
|
let rec loop = fun fields ->
|
||||||
match fields with
|
match fields with
|
||||||
| [] -> []
|
| [] -> []
|
||||||
| (Str.Delim "|")::((Str.Text l)::[Str.Delim "|"]) -> [l]
|
| (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 "\"")::xs)) -> [l] @ (loop xs)
|
||||||
| [Str.Text x] -> Str.split space x
|
| [Str.Text x] -> Str.split space x
|
||||||
| (Str.Text x)::xs -> (Str.split space x) @ (loop xs)
|
| (Str.Text x)::xs -> (Str.split space x) @ (loop xs)
|
||||||
| (Str.Delim _)::_ -> failwith "Pprz.values_of_string: incorrect array delimiter"
|
| (Str.Delim _)::_ -> failwith "Pprz.values_of_string: incorrect array delimiter"
|
||||||
|
|||||||
@@ -63,7 +63,6 @@ val is_fixed_array_type : string -> bool
|
|||||||
|
|
||||||
val size_of_field : field -> int
|
val size_of_field : field -> int
|
||||||
val string_of_value : value -> string
|
val string_of_value : value -> string
|
||||||
val string_of_chars : value -> string
|
|
||||||
val formatted_string_of_value : 'a -> value -> string
|
val formatted_string_of_value : 'a -> value -> string
|
||||||
val int_of_value : value -> int (* May raise Invalid_argument *)
|
val int_of_value : value -> int (* May raise Invalid_argument *)
|
||||||
type type_descr = {
|
type type_descr = {
|
||||||
|
|||||||
Reference in New Issue
Block a user