From f32ba8ea9a7bc04847d8f1fcd228b4bf8124f137 Mon Sep 17 00:00:00 2001 From: Gautier Hattenberger Date: Mon, 8 Dec 2014 23:14:11 +0100 Subject: [PATCH] [ground_segment] use None/Some instead of abusing infinity --- sw/ground_segment/cockpit/live.ml | 15 ++++++++++----- sw/ground_segment/cockpit/live.mli | 2 +- sw/ground_segment/cockpit/page_settings.ml | 4 ++-- sw/ground_segment/tmtc/aircraft.ml | 4 ++-- sw/ground_segment/tmtc/aircraft.mli | 2 +- sw/ground_segment/tmtc/fw_server.ml | 2 +- sw/ground_segment/tmtc/server.ml | 8 +++++--- 7 files changed, 22 insertions(+), 15 deletions(-) diff --git a/sw/ground_segment/cockpit/live.ml b/sw/ground_segment/cockpit/live.ml index 7787fa11aa..bcbc9b61de 100644 --- a/sw/ground_segment/cockpit/live.ml +++ b/sw/ground_segment/cockpit/live.ml @@ -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 diff --git a/sw/ground_segment/cockpit/live.mli b/sw/ground_segment/cockpit/live.mli index 53ed41711e..4222af0202 100644 --- a/sw/ground_segment/cockpit/live.mli +++ b/sw/ground_segment/cockpit/live.mli @@ -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 } diff --git a/sw/ground_segment/cockpit/page_settings.ml b/sw/ground_segment/cockpit/page_settings.ml index 53fff8b53e..8e99856003 100644 --- a/sw/ground_segment/cockpit/page_settings.ml +++ b/sw/ground_segment/cockpit/page_settings.ml @@ -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 diff --git a/sw/ground_segment/tmtc/aircraft.ml b/sw/ground_segment/tmtc/aircraft.ml index e433593e02..383478880d 100644 --- a/sw/ground_segment/tmtc/aircraft.ml +++ b/sw/ground_segment/tmtc/aircraft.ml @@ -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; diff --git a/sw/ground_segment/tmtc/aircraft.mli b/sw/ground_segment/tmtc/aircraft.mli index bda45823c1..67a0a0890d 100644 --- a/sw/ground_segment/tmtc/aircraft.mli +++ b/sw/ground_segment/tmtc/aircraft.mli @@ -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; diff --git a/sw/ground_segment/tmtc/fw_server.ml b/sw/ground_segment/tmtc/fw_server.ml index ac639a5b7e..756acea4bb 100644 --- a/sw/ground_segment/tmtc/fw_server.ml +++ b/sw/ground_segment/tmtc/fw_server.ml @@ -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 !!!" diff --git a/sw/ground_segment/tmtc/server.ml b/sw/ground_segment/tmtc/server.ml index 3276cc91e5..5cdd15f4cd 100644 --- a/sw/ground_segment/tmtc/server.ml +++ b/sw/ground_segment/tmtc/server.ml @@ -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 *)