generate tuning files in var/include and var/<AC>,

it defines dl_settings id for include in external program
This commit is contained in:
Gautier Hattenberger
2008-02-12 13:52:02 +00:00
parent 96671fdd6f
commit 6dcf9e7e83
3 changed files with 83 additions and 2 deletions
+10 -1
View File
@@ -39,6 +39,9 @@ SETTINGS_H=$(ACINCLUDE)/settings.h
SETTINGS_XMLS=$(patsubst %,$(CONF)/%,$(SETTINGS))
SETTINGS_XML=$(ACINCLUDE)/settings.xml
MAKEFILE_AC=$(ACINCLUDE)/Makefile.ac
SETTINGS_FILE=$(SETTINGS:settings%=%)
TUNING_H=$(ACINCLUDE)/tuning.h
TUNING_INC_H=$(PAPARAZZI_HOME)/var/include/$(SETTINGS:settings/%.xml=%.h)
SUPERVISION=./paparazzi
MAKE=make PAPARAZZI_SRC=$(PAPARAZZI_SRC) PAPARAZZI_HOME=$(PAPARAZZI_HOME)
@@ -52,7 +55,7 @@ init:
demo:
$(SUPERVISION)
all_ac_h: $(AIRFRAME_H) $(RADIO_H) $(FLIGHT_PLAN_H) $(FLIGHT_PLAN_XML) $(SETTINGS_H) $(MAKEFILE_AC) $(PERIODIC_H)
all_ac_h: $(AIRFRAME_H) $(RADIO_H) $(FLIGHT_PLAN_H) $(FLIGHT_PLAN_XML) $(SETTINGS_H) $(TUNING_H) $(MAKEFILE_AC) $(PERIODIC_H)
$(AIRFRAME_H) : $(CONF)/$(AIRFRAME_XML) $(CONF_XML)
@echo BUILD $@
@@ -84,6 +87,12 @@ $(SETTINGS_H) : $(SETTINGS_XMLS) $(CONF_XML) $(TOOLS)/gen_settings.out
$(Q)$(TOOLS)/gen_settings.out $(SETTINGS_XML) $(SETTINGS_XMLS) > $@
$(Q)chmod a+r $@
$(TUNING_H) : $(SETTINGS_XMLS) $(CONF_XML) $(TOOLS)/gen_tuning.out
@echo BUILD $@
$(Q)$(TOOLS)/gen_tuning.out $(SETTINGS_XMLS) > $@
$(Q)cp $@ $(TUNING_INC_H)
$(Q)chmod a+r $@ $(TUNING_INC_H)
$(MAKEFILE_AC) : $(CONF)/$(AIRFRAME_XML)
@echo BUILD $@
$(Q)$(TOOLS)/extract_makefile.out $< > $@
+1 -1
View File
@@ -28,7 +28,7 @@ INCLUDES=-I ../lib/ocaml -I +xml-light
OCAMLLEX=ocamllex
OCAMLYACC=ocamlyacc
all: gen_aircraft.out gen_airframe.out gen_messages.out gen_ubx.out gen_flight_plan.out gen_radio.out extract_makefile.out gen_periodic.out gen_settings.out
all: gen_aircraft.out gen_airframe.out gen_messages.out gen_ubx.out gen_flight_plan.out gen_radio.out extract_makefile.out gen_periodic.out gen_settings.out gen_tuning.out
FP_CMO = fp_syntax.cmo fp_parser.cmo fp_lexer.cmo fp_proc.cmo gen_flight_plan.cmo
ABS_FP = $(FP_CMO:%=$$PAPARAZZI_SRC/sw/tools/%)
+72
View File
@@ -0,0 +1,72 @@
(*
* $Id$
*
* XML preprocessing for dynamic tuning
*
* Copyright (C) 2006 Pascal Brisset, Antoine Drouin
*
* This file is part of paparazzi.
*
* paparazzi is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* paparazzi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with paparazzi; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*)
(** Generates code to define dl_setting in external program *)
open Printf
open Xml2h
let rec flatten = fun xml r ->
if ExtXml.tag_is xml "dl_setting" then
xml::r
else
match Xml.children xml with
[] -> r
| x::xs ->
List.iter (fun y -> assert(ExtXml.tag_is y (Xml.tag x))) xs;
List.fold_right flatten (x::xs) r
let _ =
if Array.length Sys.argv <> 2 then
failwith (Printf.sprintf "Usage: %s input_xml_file(s)" Sys.argv.(0));
let h_name = "TUNING_H" in
let xml_file = Sys.argv.(1) in
try
printf "/* This file has been generated from %s */\n" xml_file;
printf "/* Please DO NOT EDIT */\n\n";
printf "#ifndef %s\n" h_name;
printf "#define %s\n\n" h_name;
let xml = Xml.parse_file xml_file in
let settings = flatten xml [] in
(** Macro to define variables id *)
let idx = ref 0 in
List.iter (fun s ->
let v = ExtXml.attrib s "var" in
let up = String.uppercase v in
begin printf "#define PPRZ_%s %d \n" up !idx end;
incr idx)
settings;
finish h_name
with
Xml.Error e -> prerr_endline (Xml.error e); exit 1
| Dtd.Prove_error e -> prerr_endline (Dtd.prove_error e); exit 1
| Dtd.Parse_error e -> prerr_endline (Dtd.parse_error e); exit 1