mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-05-31 03:57:45 +08:00
[messages] add support for spaces in messages array
- add special delimiters ([]) for arrays (which are now forbidden characters) - backward compatible with old format if no spaces in array
This commit is contained in:
@@ -18,6 +18,8 @@ extern int ivy_dl_enabled;
|
||||
|
||||
#define Space() ivy_p += sprintf(ivy_p, " ");
|
||||
#define Comma() ivy_p += sprintf(ivy_p, ",");
|
||||
#define DelimStart() ivy_p += sprintf(ivy_p, "[");
|
||||
#define DelimEnd() ivy_p += sprintf(ivy_p, "]");
|
||||
|
||||
#define IvyTransportPutcByAddr(_dev,x) ivy_p += sprintf(ivy_p, "%c", *x);
|
||||
#define IvyTransportPutCharByAddr(_dev,x) IvyTransportPutcByAddr(_dev,x) Space()
|
||||
@@ -39,10 +41,11 @@ extern int ivy_dl_enabled;
|
||||
|
||||
#define IvyTransportPutArray(_dev,_put, _n, _x) { \
|
||||
int __i; \
|
||||
DelimStart(); \
|
||||
for(__i = 0; __i < _n; __i++) { \
|
||||
_put(_dev,&_x[__i]); \
|
||||
Comma(); \
|
||||
} Space() \
|
||||
} DelimEnd(); Space(); \
|
||||
}
|
||||
|
||||
#define IvyTransportPutInt8Array(_dev,_n, _x) IvyTransportPutArray(_dev,IvyTransportPutIntByAddr, _n, _x)
|
||||
|
||||
@@ -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;
|
||||
|
||||
+15
-2
@@ -160,7 +160,7 @@ 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 -> "["^(String.concat separator (Array.to_list (Array.map string_of_value a)))^"]"
|
||||
|
||||
|
||||
let magic = fun x -> (Obj.magic x:('a,'b,'c) Pervasives.format)
|
||||
@@ -661,8 +661,21 @@ module MessagesOfXml(Class:CLASS_Xml) = struct
|
||||
|
||||
|
||||
let space = Str.regexp "[ \t]+"
|
||||
let array_sep = Str.regexp "\\[\\|\\]"
|
||||
let values_of_string = fun s ->
|
||||
match Str.split space s with
|
||||
(* 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.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"
|
||||
in
|
||||
let msg_split = loop array_split in
|
||||
match msg_split with
|
||||
msg_name::args ->
|
||||
begin
|
||||
try
|
||||
|
||||
Reference in New Issue
Block a user