mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-06-05 15:30:08 +08:00
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:
@@ -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
|
||||||
|
|||||||
@@ -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,11 +82,30 @@ 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
|
||||||
|
let value = (ExtXml.float_attrib s "value") *. (code_unit_scale_of_tag s) in
|
||||||
|
define (prefix^ExtXml.attrib s "name") (string_of_float value);
|
||||||
|
with
|
||||||
|
_ -> 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");
|
define_integer (prefix^(ExtXml.attrib s "name")) (ExtXml.float_attrib s "value") (ExtXml.int_attrib s "integer");
|
||||||
with _ -> ();
|
with _ -> ();
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user