diff --git a/sw/ground_segment/tmtc/messages.ml b/sw/ground_segment/tmtc/messages.ml index 0661e986aa..209c785423 100644 --- a/sw/ground_segment/tmtc/messages.ml +++ b/sw/ground_segment/tmtc/messages.ml @@ -67,7 +67,7 @@ let one_page = fun sender class_name (notebook:GPack.notebook) bind m -> let literal_values = values_of_field f in let alt_value = try - let coeff = float_of_string (Pprz.alt_unit_coef_of_xml f) + let coeff = float_of_string (Pprz.alt_unit_coef_of_xml ~auto:"display" f) and unit = Xml.attrib f "alt_unit" in fun value -> sprintf "%s (%f%s)" value (coeff*.float_of_string value) unit with @@ -86,7 +86,7 @@ let one_page = fun sender class_name (notebook:GPack.notebook) bind m -> (* box dragger *) field_label#drag#source_set dnd_targets ~modi:[`BUTTON1] ~actions:[`COPY]; let data_get = fun _ (sel:GObj.selection_context) ~info ~time -> - let scale = Pprz.alt_unit_coef_of_xml f in + let scale = Pprz.alt_unit_coef_of_xml ~auto:"display" f in let field_descr = if Pprz.is_array_type type_ then match GToolbox.input_string ~title:"Index of value to drag" ~text:"0" "Index in the array ?" with diff --git a/sw/lib/ocaml/pprz.ml b/sw/lib/ocaml/pprz.ml index 1302dc4167..00892d003e 100644 --- a/sw/lib/ocaml/pprz.ml +++ b/sw/lib/ocaml/pprz.ml @@ -162,7 +162,7 @@ exception Unit_conversion_error of string exception Unknown_conversion of string * string exception No_automatic_conversion of string * string -let scale_of_units = fun from_unit to_unit -> +let scale_of_units = fun ?auto from_unit to_unit -> if (from_unit = to_unit) then 1.0 else @@ -173,7 +173,9 @@ let scale_of_units = fun from_unit to_unit -> (* will raise Xml.No_attribute if not a valid attribute *) let f = Xml.attrib u "from" and t = Xml.attrib u "to" - and a = String.lowercase (ExtXml.attrib_or_default u "auto" "") in + and a = match auto with + | Some a -> a + | None -> String.lowercase (ExtXml.attrib_or_default u "auto" "") in if (f = from_unit || a = "display") && (t = to_unit || a = "code") then true else false ) (Xml.children units_xml) in (* return coef, raise Failure if coef is not a numerical value *) @@ -187,13 +189,16 @@ let scale_of_units = fun from_unit to_unit -> | _ -> raise (Unknown_conversion (from_unit, to_unit)) -let alt_unit_coef_of_xml = function xml -> +let alt_unit_coef_of_xml = fun ?auto xml -> try Xml.attrib xml "alt_unit_coef" with _ -> let u = try Xml.attrib xml "unit" with _ -> "" in let au = try Xml.attrib xml "alt_unit" with _ -> "" in - let coef = try string_of_float (scale_of_units u au) with - Unit_conversion_error s -> prerr_endline (sprintf "Unit conversion error: %s" s); flush stderr; "1." (* Use coef 1. *) + let coef = try string_of_float (match auto with + | None -> scale_of_units u au + | Some a -> scale_of_units u au ~auto:a) + with + | Unit_conversion_error s -> prerr_endline (sprintf "Unit conversion error: %s" s); flush stderr; "1." (* Use coef 1. *) | Unknown_conversion _ -> "1." (* Use coef 1. *) | _ -> "1." in diff --git a/sw/lib/ocaml/pprz.mli b/sw/lib/ocaml/pprz.mli index b7ec04c53f..5338be84fa 100644 --- a/sw/lib/ocaml/pprz.mli +++ b/sw/lib/ocaml/pprz.mli @@ -95,7 +95,7 @@ exception No_automatic_conversion of string * string * and from_unit or to_unit are empty string *) -val scale_of_units : string -> string -> float +val scale_of_units : ?auto:string -> string -> string -> float (** scale_of_units from to * Returns conversion factor between two units * The possible conversions are described in conf/units.xml @@ -103,7 +103,7 @@ val scale_of_units : string -> string -> float * or if units.xml is not valid *) -val alt_unit_coef_of_xml : Xml.xml -> string +val alt_unit_coef_of_xml : ?auto:string -> Xml.xml -> string (** Return coef for alternate unit *)