[ground_segment] use None/Some instead of abusing infinity

This commit is contained in:
Gautier Hattenberger
2014-12-08 23:14:11 +01:00
parent 2f8e003357
commit f32ba8ea9a
7 changed files with 22 additions and 15 deletions
+10 -5
View File
@@ -102,7 +102,7 @@ type aircraft = {
mutable ground_prox : bool;
mutable got_track_status_timer : int;
mutable last_dist_to_wp : float;
mutable dl_values : float array;
mutable dl_values : string option array;
mutable last_unix_time : float;
mutable airspeed : float
}
@@ -739,8 +739,8 @@ let create_ac = fun alert (geomap:G.widget) (acs_notebook:GPack.notebook) (ac_id
let id = settings_tab#assoc "snav_desired_tow" in
let set_appointment = fun _ ->
begin try
let v = ac.dl_values.(id) in
let t = Unix.gmtime (Latlong.unix_time_of_tow (truncate v)) in
let v = match ac.dl_values.(id) with None -> raise Not_found | Some x -> int_of_string x in
let t = Unix.gmtime (Latlong.unix_time_of_tow v) in
ac.strip#set_label "apt" (sprintf "%d:%02d:%02d" t.Unix.tm_hour t.Unix.tm_min t.Unix.tm_sec)
with _ -> () end;
true
@@ -910,10 +910,15 @@ let listen_dl_value = fun () ->
match ac.dl_settings_page with
Some settings ->
let csv = Pprz.string_assoc "values" vs in
let values = Array.map float_of_string (Array.of_list (Str.split list_separator csv)) in
let float_of_string_value = fun v -> match v with "?" -> None | _ -> Some v in
let values = Array.map float_of_string_value (Array.of_list (Str.split list_separator csv)) in
ac.dl_values <- values;
let float_of_value = fun v -> match v with None -> raise Not_found | Some x -> x in
for i = 0 to min (Array.length values) settings#length - 1 do
settings#set i (try values.(i) with _ -> failwith (sprintf "values.(%d)" i))
try
let v = float_of_value values.(i) in
settings#set i (try float_of_string v with _ -> failwith (sprintf "values.(%d)" i))
with _ -> ()
done
| None -> () in
safe_bind "DL_VALUES" get_dl_value
+1 -1
View File
@@ -59,7 +59,7 @@ type aircraft = private {
mutable ground_prox : bool;
mutable got_track_status_timer : int;
mutable last_dist_to_wp : float;
mutable dl_values : float array;
mutable dl_values : string option array;
mutable last_unix_time : float;
mutable airspeed : float
}
+2 -2
View File
@@ -36,8 +36,8 @@ object
let (alt_a, alt_b) = Ocaml_tools.affine_transform auc in
(float_of_string current_value#text -. alt_b) /. alt_a
method update = fun s ->
(* value of infinity (string "inf") means it is not yet confirmed, so display "?" *)
if s = "inf" then
(* if not yet confirmed, display "?" *)
if s = "?" then
current_value#set_text "?"
else
if current_value#text <> s then begin
+2 -2
View File
@@ -184,7 +184,7 @@ type aircraft = {
mutable stage_time : int;
mutable block_time : int;
mutable horiz_mode : horiz_mode;
dl_setting_values : float array;
dl_setting_values : float option array;
mutable nb_dl_setting_values : int;
mutable survey : (Latlong.geographic * Latlong.geographic) option;
datalink_status : datalink_status;
@@ -217,7 +217,7 @@ let new_aircraft = fun id name fp airframe ->
cam = { phi = 0.; theta = 0. ; target=(0.,0.)};
fbw = { rc_status = "???"; rc_mode = "???"; rc_rate=0; pprz_mode_msgs_since_last_fbw_status_msg=0 };
svinfo = svsinfo_init;
dl_setting_values = Array.create max_nb_dl_setting_values infinity;
dl_setting_values = Array.create max_nb_dl_setting_values None;
nb_dl_setting_values = 0;
horiz_mode = UnknownHorizMode;
horizontal_mode = 0;
+1 -1
View File
@@ -136,7 +136,7 @@ type aircraft = {
mutable stage_time : int;
mutable block_time : int;
mutable horiz_mode : horiz_mode;
dl_setting_values : float array;
dl_setting_values : float option array;
mutable nb_dl_setting_values : int;
mutable survey : (Latlong.geographic * Latlong.geographic) option;
datalink_status : datalink_status;
+1 -1
View File
@@ -298,7 +298,7 @@ let log_and_parse = fun ac_name (a:Aircraft.aircraft) msg values ->
| "DL_VALUE" ->
let i = ivalue "index" in
if i < max_nb_dl_setting_values then begin
a.dl_setting_values.(i) <- fvalue "value";
a.dl_setting_values.(i) <- Some (fvalue "value");
a.nb_dl_setting_values <- max a.nb_dl_setting_values (i+1)
end else
failwith "Too much dl_setting values !!!"
+5 -3
View File
@@ -199,7 +199,9 @@ let send_dl_values = fun a ->
if a.nb_dl_setting_values > 0 then
let csv = ref "" in
for i = 0 to a.nb_dl_setting_values - 1 do
csv := sprintf "%s%f," !csv a.dl_setting_values.(i)
match a.dl_setting_values.(i) with
| None -> csv := sprintf "%s?," !csv
| Some s -> csv := sprintf "%s%f," !csv s
done;
let vs = ["ac_id", Pprz.String a.id; "values", Pprz.String !csv] in
Ground_Pprz.message_send my_id "DL_VALUES" vs
@@ -681,7 +683,7 @@ let setting = fun logging _sender vs ->
(* mark the setting as not yet confirmed *)
let ac = Hashtbl.find aircrafts ac_id in
let idx = Pprz.int_of_value (List.assoc "index" vs) in
ac.dl_setting_values.(idx) <- infinity
ac.dl_setting_values.(idx) <- None
(** Got a GET_DL_SETTING, and send an GET_SETTING *)
@@ -694,7 +696,7 @@ let get_setting = fun logging _sender vs ->
(* mark the setting as not yet confirmed *)
let ac = Hashtbl.find aircrafts ac_id in
let idx = Pprz.int_of_value (List.assoc "index" vs) in
ac.dl_setting_values.(idx) <- infinity
ac.dl_setting_values.(idx) <- None
(** Got a JUMP_TO_BLOCK, and send an BLOCK *)