Skip to content

Commit

Permalink
[units] yet another units fix
Browse files Browse the repository at this point in the history
Units that can be automatically converted should come last so other
possibilities are tested first. (ok, that is a lazy and fragile
solution...)
A the type of auto conversion ("display" or "code" can be changed only
for conversions that were already using auto mode (eg. deg <-> decideg
will not be auto converted)
  • Loading branch information
gautierhattenberger committed Jul 25, 2012
1 parent 8212e54 commit f4cbb7b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 4 additions & 4 deletions conf/units.xml
@@ -1,10 +1,6 @@
<!-- Table of default units convertion -->
<!-- used to convert from unit to alt_unit (messages) or code_unit (airframe) -->
<units>
<unit from="deg" to="rad" coef="0.0174532925" auto="code"/>
<unit from="rad" to="deg" coef="57.2957795131" auto="display"/>
<unit from="deg/s" to="rad/s" coef="0.0174532925" auto="code"/>
<unit from="rad/s" to="deg/s" coef="57.2957795131" auto="display"/>
<unit from="m" to="cm" coef="100."/>
<unit from="cm" to="m" coef="0.01"/>
<unit from="m/s" to="cm/s" coef="100."/>
Expand All @@ -15,4 +11,8 @@
<unit from="mm/s" to="m/s" coef="0.001"/>
<unit from="decideg" to="deg" coef="0.1"/>
<unit from="deg" to="decideg" coef="10."/>
<unit from="deg" to="rad" coef="0.0174532925" auto="code"/>
<unit from="rad" to="deg" coef="57.2957795131" auto="display"/>
<unit from="deg/s" to="rad/s" coef="0.0174532925" auto="code"/>
<unit from="rad/s" to="deg/s" coef="57.2957795131" auto="display"/>
</units>
8 changes: 5 additions & 3 deletions sw/lib/ocaml/pprz.ml
Expand Up @@ -173,9 +173,11 @@ let scale_of_units = fun ?auto 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 = match auto with
| Some a -> a
| None -> String.lowercase (ExtXml.attrib_or_default u "auto" "") in
and a = try Some (Xml.attrib u "auto") with _ -> None in
let a = match auto, a with
| Some _, None | None, None -> "" (* No auto conversion *)
| Some t, Some _ | None, Some t -> String.lowercase t (* param auto is used before attribute *)
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 *)
Expand Down

0 comments on commit f4cbb7b

Please sign in to comment.