added code_unit attribute to section defines in airframe file parsing

always convert degrees to radians, unless explicitly stated otherwise
* if unit and code_unit are specified the value is converted to code_unit and then written to the generated airframe.h file
* this works for default units like deg<->rad, m<->mm, etc.
* only works if the contents of the value attribute can be converted to float, otherwise string is simply copied
* special treatment for unit="deg": if code_unit is not specified, will be converted to rad nevertheless, if this is not wanted explicitly specify code_unit="deg"
This commit is contained in:
Felix Ruess
2011-12-01 01:12:25 +01:00
parent 9d71e49f85
commit fd058ee7d4
2 changed files with 30 additions and 8 deletions
+1
View File
@@ -97,6 +97,7 @@ value CDATA #REQUIRED>
name CDATA #REQUIRED name CDATA #REQUIRED
value CDATA #IMPLIED value CDATA #IMPLIED
unit CDATA #IMPLIED unit CDATA #IMPLIED
code_unit CDATA #IMPLIED
integer CDATA #IMPLIED> integer CDATA #IMPLIED>
<!ATTLIST configure <!ATTLIST configure
+29 -8
View File
@@ -26,6 +26,8 @@
let max_pprz = 9600. (* !!!! MAX_PPRZ From paparazzi.h !!!! *) let max_pprz = 9600. (* !!!! MAX_PPRZ From paparazzi.h !!!! *)
exception Undefined_scale
open Printf open Printf
open Xml2h open Xml2h
@@ -80,19 +82,38 @@ let define_integer name v n =
in in
continious_frac (truncate v) v (1, (truncate v)) (0, 1) continious_frac (truncate v) v (1, (truncate v)) (0, 1)
let code_unit_scale_of_tag = function t ->
let u = try ExtXml.attrib t "unit" with _ -> "" in
let cu = try ExtXml.attrib t "code_unit" with _ -> "" in
match (u, cu) with
("deg", "rad") | ("deg/s", "rad/s") -> Latlong.pi /. 180.
| ("deg", "") | ("deg/s", "") -> Latlong.pi /. 180.
| ("rad", "deg") | ("rad/s", "deg/s") -> 180. /. Latlong.pi
| ("m", "cm") | ("m/s", "cm/s") -> 100.
| ("cm", "m") | ("cm/s", "m/s") -> 0.01
| ("m", "mm") | ("m/s", "mm/s") -> 1000.
| ("mm", "m") | ("mm/s", "m/s") -> 0.001
| ("decideg", "deg") -> 0.1
| ("deg", "decideg") -> 10.
| (_, _) -> raise Undefined_scale
let parse_element = fun prefix s -> let parse_element = fun prefix s ->
match Xml.tag s with match Xml.tag s with
"define" -> begin "define" -> begin
try try
define (prefix^ExtXml.attrib s "name") (ExtXml.display_entities (ExtXml.attrib s "value")); try
define_integer (prefix^(ExtXml.attrib s "name")) (ExtXml.float_attrib s "value") (ExtXml.int_attrib s "integer"); let value = (ExtXml.float_attrib s "value") *. (code_unit_scale_of_tag s) in
with _ -> (); define (prefix^ExtXml.attrib s "name") (string_of_float value);
end with
| "linear" -> _ -> define (prefix^ExtXml.attrib s "name") (ExtXml.display_entities (ExtXml.attrib s "value"));
define_integer (prefix^(ExtXml.attrib s "name")) (ExtXml.float_attrib s "value") (ExtXml.int_attrib s "integer");
with _ -> ();
end
| "linear" ->
let name = ExtXml.attrib s "name" let name = ExtXml.attrib s "name"
and n = int_of_string (ExtXml.attrib s "arity") in and n = int_of_string (ExtXml.attrib s "arity") in
define_macro (prefix^name) n s define_macro (prefix^name) n s
| _ -> xml_error "define|linear" | _ -> xml_error "define|linear"