[ocaml] fix formatting of values in pprz ocaml lib (#1135)

This commit is contained in:
Gautier Hattenberger
2015-03-18 13:35:33 +01:00
parent f21932a529
commit 72deb3577c
5 changed files with 18 additions and 32 deletions
+1 -1
View File
@@ -11,7 +11,7 @@
<message name="ALIVE" id="2">
<description>alive/heartbeat message containing the MD5sum of the aircraft configuration</description>
<field name="md5sum" type="uint8[]"/>
<field name="md5sum" type="uint8[]" format="%x"/>
</message>
<message name="PONG" id="3">
+1 -1
View File
@@ -83,7 +83,7 @@ let one_page = fun sender class_name (notebook:GPack.notebook) (topnote:GPack.no
sprintf "%s (%d)" literal_values.(i) i
with _ ->
match format_ with
| Some f -> alt_value (Pprz.string_of_value_format f x)
| Some f -> alt_value (Pprz.formatted_string_of_value f x)
| _ -> alt_value (Pprz.string_of_value x)
and display_value = fun () ->
if notebook#page_num v#coerce = notebook#current_page then
+7 -7
View File
@@ -311,11 +311,11 @@ let send_telemetry_status = fun a ->
[ "ac_id", Pprz.String id;
"link_id", Pprz.String link_id;
"time_since_last_msg", Pprz.Float (U.gettimeofday () -. a.last_msg_date); (* don't use rx_lost_time from LINK_REPORT so it also works in simulation *)
"rx_bytes", Pprz.Int link_status.rx_bytes;
"rx_msgs", Pprz.Int link_status.rx_msgs;
"rx_bytes", Pprz.Int32 (Int32.of_int link_status.rx_bytes);
"rx_msgs", Pprz.Int32 (Int32.of_int link_status.rx_msgs);
"rx_bytes_rate", Pprz.Float link_status.rx_bytes_rate;
"tx_msgs", Pprz.Int link_status.tx_msgs;
"uplink_lost_time", Pprz.Int datalink_status.uplink_lost_time;
"tx_msgs", Pprz.Int32 (Int32.of_int link_status.tx_msgs);
"uplink_lost_time", Pprz.Int32 (Int32.of_int datalink_status.uplink_lost_time);
"uplink_msgs", Pprz.Int datalink_status.uplink_msgs;
"downlink_msgs", Pprz.Int datalink_status.downlink_msgs;
"downlink_rate", Pprz.Int datalink_status.downlink_rate;
@@ -401,8 +401,8 @@ let send_aircraft_msg = fun ac ->
let values = ["ac_id", Pprz.String ac;
"cur_block", Pprz.Int a.cur_block;
"cur_stage", Pprz.Int a.cur_stage;
"stage_time", Pprz.Int a.stage_time;
"block_time", Pprz.Int a.block_time;
"stage_time", Pprz.Int32 (Int32.of_int a.stage_time);
"block_time", Pprz.Int32 (Int32.of_int a.block_time);
"target_lat", f ((Rad>>Deg)a.desired_pos.posn_lat);
"target_long", f ((Rad>>Deg)a.desired_pos.posn_long);
"target_alt", Pprz.Float a.desired_altitude;
@@ -432,7 +432,7 @@ let send_aircraft_msg = fun ac ->
let state_filter_mode = get_indexed_value state_filter_modes a.state_filter_mode
and kill_mode = if a.kill_mode then "ON" else "OFF" in
let values = ["ac_id", Pprz.String ac;
"flight_time", Pprz.Int a.flight_time;
"flight_time", Pprz.Int32 (Int32.of_int a.flight_time);
"ap_mode", Pprz.String ap_mode;
"gaz_mode", Pprz.String gaz_mode;
"lat_mode", Pprz.String lat_mode;
+8 -21
View File
@@ -169,26 +169,15 @@ let rec string_of_value = function
| _ -> String.concat separator l
let magic = fun x -> (Obj.magic x:('a,'b,'c) Pervasives.format)
(* FIXME temporary solution, the complete formatted_string_of_value function
causes a segfault in server and GCS
magic format also cases segfaults with OCaml 4.02, so complety disable this for now
*)
let string_of_value_format = fun format v ->
match v with
(*Float x -> sprintf (magic format) x*)
| v -> string_of_value v
(* FIXME: causes a segfault in server and GCS. *)
let rec formatted_string_of_value = fun format v ->
let f = fun x -> Scanf.format_from_string format x in
match v with
| Int x -> sprintf (magic format) x
| Float x -> sprintf (magic format) x
| Int32 x -> sprintf (magic format) x
| Int64 x -> sprintf (magic format) x
| Char x -> sprintf (magic format) x
| String x -> sprintf (magic format) x
| Int x -> sprintf (f "%d") x
| Float x -> sprintf (f "%f") x
| Int32 x -> sprintf (f "%ld") x
| Int64 x -> sprintf (f "%Ld") x
| Char x -> sprintf (f "%c") x
| String x ->sprintf "%s" x
| Array a ->
let l = (Array.to_list (Array.map (formatted_string_of_value format) a)) in
match a.(0) with
@@ -736,9 +725,7 @@ module MessagesOfXml(Class:CLASS_Xml) = struct
try List.assoc field_name values with
Not_found ->
default_value field._type in
(* should actually use this here, but it segfaults, so disable format strings for now
formatted_string_of_value field.fformat v)*)
string_of_value_format field.fformat v)
formatted_string_of_value field.fformat v)
msg.fields)
let message_send = fun ?timestamp ?link_id sender msg_name values ->
+1 -2
View File
@@ -63,8 +63,7 @@ val is_fixed_array_type : string -> bool
val size_of_field : field -> int
val string_of_value : value -> string
val formatted_string_of_value : 'a -> value -> string
val string_of_value_format : 'a -> value -> string
val formatted_string_of_value : format -> value -> string
val int_of_value : value -> int (* May raise Invalid_argument *)
type type_descr = {
format : string ;