[flash_mode] parse boards' name as regexp

This commit is contained in:
Gautier Hattenberger
2013-12-18 19:11:54 +01:00
parent e010ee04a0
commit 4eeddf5c53
3 changed files with 75 additions and 11 deletions

View File

@@ -1,31 +1,88 @@
<?xml version="1.0"?>
<flash_modes>
<mode name="SERIAL (ISP)" boards="booz_1.0|classix|hb_1.1|logom_2.2|navgo_1.0|sdlog_1.0|tiny_0.99|tiny_1.1|tiny_2.1|tiny_2.11|twog_1.0|umarim_1.0|umarim_lite_2.0|yapa_2.0">
<mode name="SERIAL (ISP)">
<variable name="FLASH_MODE" value="ISP"/>
<boards>
<board name="booz_*"/>
<board name="classix"/>
<board name="hb_*"/>
<board name="logom_*"/>
<board name="navgo_*"/>
<board name="sdlog_*"/>
<board name="tiny_*"/>
<board name="twog_*"/>
<board name="umarim_*"/>
<board name="yapa_*"/>
</boards>
</mode>
<mode name="SERIAL (stm32)" boards="krooz_sd|lia_1.1|lisa_m_1.0|lisa_m_2.0|lisa_s_0.1">
<mode name="SERIAL (stm32)">
<variable name="FLASH_MODE" value="SERIAL"/>
<boards>
<board name="krooz_sd"/>
<board name="lia_*"/>
<board name="lisa_[ms]_*"/>
</boards>
</mode>
<mode name="USB (IAP)" boards="booz_1.0|classix|hb_1.1|logom_2.2|navgo_1.0|sdlog_1.0|tiny_0.99|tiny_1.1|tiny_2.1|tiny_2.11|twog_1.0|umarim_1.0|umarim_lite_2.0|yapa_2.0">
<mode name="USB (IAP)">
<variable name="FLASH_MODE" value="IAP"/>
<boards>
<board name="booz_*"/>
<board name="classix"/>
<board name="hb_*"/>
<board name="logom_*"/>
<board name="navgo_*"/>
<board name="sdlog_*"/>
<board name="tiny_*"/>
<board name="twog_*"/>
<board name="umarim_*"/>
<board name="yapa_*"/>
</boards>
</mode>
<mode name="USB DFU (stm32_mem)" boards="krooz_sd|lia_1.1|lisa_m_1.1|lisa_m_2.0|px4fmu_1.7">
<variable name="FLASH_MODE" value="DFU"/>
<boards>
<board name="krooz_sd"/>
<board name="li[s]?a_[m]?_*"/>
<board name="px4fmu_*"/>
</boards>
</mode>
<mode name="USB DFU-UTIL" boards="apogee_1.0|apogee_0.99|stm32f4_discovery">
<variable name="FLASH_MODE" value="DFU-UTIL"/>
<boards>
<board name="apogee_*"/>
<board name="stm32f4_discovery"/>
</boards>
</mode>
<mode name="STLink (SWD)" boards="apogee_1.0|apogee_0.99">
<variable name="FLASH_MODE" value="STLINK"/>
<boards>
<board name="apogee_*"/>
</boards>
</mode>
<mode name="BlackMagic Probe (SWD)" boards="apogee_1.0|apogee_0.99|stm32f4_discovery|lisa_m_1.0|lia_1.1|lisa_m_2.0|lisa_s_0.1|px4fmu_1.7">
<mode name="BlackMagic Probe (SWD)">
<variable name="FLASH_MODE" value="SWD"/>
<boards>
<board name="apogee_*"/>
<board name="stm32f4_discovery"/>
<board name="li[s]?a_[ms]?_*"/>
<board name="px4fmu_*"/>
</boards>
</mode>
<mode name="BlackMagic Probe (JTAG)" boards="apogee_1.0|apogee_0.99|stm32f4_discovery|lisa_m_1.0|lia_1.1|lisa_m_2.0|lisa_s_0.1|px4fmu_1.7">
<mode name="BlackMagic Probe (JTAG)">
<variable name="FLASH_MODE" value="JTAG_BMP"/>
<boards>
<board name="apogee_*"/>
<board name="stm32f4_discovery"/>
<board name="li[s]?a_[ms]?_*"/>
<board name="px4fmu_*"/>
</boards>
</mode>
<mode name="JTAG (OpenOCD)" boards="krooz_sd|lia_1.1|lisa_l_1.0|lisa_l_1.1|lisa_m_1.0|lisa_m_2.0">
<mode name="JTAG (OpenOCD)">
<variable name="FLASH_MODE" value="JTAG"/>
<boards>
<board name="krooz_sd"/>
<board name="li[s]?a_[lm]?_*"/>
</boards>
</mode>
</flash_modes>

View File

@@ -207,10 +207,15 @@ let parse_ac_flash = fun target flash_combo ac_file ->
let af_xml = Xml.parse_file (Env.paparazzi_home // "conf" // ac_file) in
let targets = get_targets_list af_xml in
let board = Xml.attrib (List.find (fun t -> Xml.attrib t "name" = target) targets) "board" in
let flash_modes = try Hashtbl.find (snd CP.flash_modes) board with _ -> [] in (* not a valid board *)
List.iter (fun m -> Gtk_tools.add_to_combo flash_combo m) flash_modes;
(* board names as regexp *)
let flash_modes = ref [] in
Hashtbl.iter (fun b m ->
if Str.string_match (Str.regexp b) board 0 then
flash_modes := !flash_modes @ m;
) (snd CP.flash_modes);
List.iter (fun m -> Gtk_tools.add_to_combo flash_combo m) !flash_modes;
Gtk_tools.select_in_combo flash_combo "Default";
(Gtk_tools.combo_widget flash_combo)#misc#set_sensitive (List.length flash_modes > 0)
(Gtk_tools.combo_widget flash_combo)#misc#set_sensitive (List.length !flash_modes > 0)
with _ ->
(* not a valid airframe file *)
(Gtk_tools.combo_widget flash_combo)#misc#set_sensitive false

View File

@@ -67,11 +67,12 @@ let flash_modes =
List.iter (fun m ->
let mode = Xml.attrib m "name" in
(* list of boards *)
let board_list = Str.split (Str.regexp "|") (Xml.attrib m "boards") in
let board_list = try Xml.children (ExtXml.child m "boards") with _ -> [] in
let board_list = List.map (fun x -> Xml.attrib x "name") board_list in
(* build options for this mode *)
let options = List.map (fun o ->
sprintf "%s=%s" (Xml.attrib o "name") (Xml.attrib o "value")
) (Xml.children m) in
) (List.filter (fun t -> Xml.tag t = "variable") (Xml.children m)) in
let options = String.concat " " options in
(* add to hash tables *)
Hashtbl.add modes mode options;
@@ -82,6 +83,7 @@ let flash_modes =
Hashtbl.replace boards b ([mode] @ _modes)
) board_list;
) (fm_common @ fm_custom);
(* convert string to regexp *)
modes, boards