Skip to content

Commit

Permalink
Added group attribute to dtd file. Initialize as empty subgroup count…
Browse files Browse the repository at this point in the history
… of commands. Avoid unnecessary array to list conversion.
  • Loading branch information
tmldeponti committed Apr 15, 2024
1 parent 51cacb3 commit 4b9c04e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
3 changes: 2 additions & 1 deletion conf/airframes/airframe.dtd
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ collective CDATA #REQUIRED>

<!ATTLIST axis
name CDATA #REQUIRED
failsafe_value CDATA #REQUIRED>
failsafe_value CDATA #REQUIRED
group CDATA #IMPLIED>

<!ATTLIST set
value CDATA #REQUIRED
Expand Down
14 changes: 7 additions & 7 deletions sw/tools/generators/gen_airframe.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ open Printf
open Xml2h

type channel = { min : float; max : float; neutral : float }
type control = { failsafe_value : int; foo : int; actuator_type : string}
type control = { failsafe_value : int; foo : int; group : string}

let fos = float_of_string
let sof = fun x -> if mod_float x 1. = 0. then Printf.sprintf "%.0f" x else string_of_float x
Expand Down Expand Up @@ -338,16 +338,16 @@ let parse_ap_only_commands = fun out ap_only ->
let parse_command = fun out command no ->
let command_name = "COMMAND_"^ExtXml.attrib command "name" in
let failsafe_value = int_of_string (ExtXml.attrib command "failsafe_value") in
let actuator_type = ExtXml.attrib_or_default command "actuator_type" "REAL" in
let group = ExtXml.attrib_or_default command "group" "REAL" in
define_out out command_name (string_of_int no);
{ failsafe_value = failsafe_value; foo = 0 ; actuator_type = actuator_type }
{ failsafe_value = failsafe_value; foo = 0 ; group = group }

let count_commands_by_type commands_params =
List.fold_left (fun acc cmd ->
let subtype = cmd.actuator_type in
Array.fold_left (fun acc cmd ->
let subtype = cmd.group in
let count = try List.assoc subtype acc with Not_found -> 0 in
(subtype, count + 1) :: (List.remove_assoc subtype acc)
) [("REAL", 0); ("VIRTUAL", 0); ("PASSIVE", 0); ("OTHER", 0)] commands_params
) [] commands_params

let parse_heli_curves = fun out heli_curves ->
let a = fun s -> ExtXml.attrib heli_curves s in
Expand Down Expand Up @@ -395,7 +395,7 @@ let rec parse_section = fun out ac_id s ->
| "commands" ->
let commands = Array.of_list (Xml.children s) in
let commands_params = Array.mapi (fun i c -> parse_command out c i) commands in
let commands_counts = count_commands_by_type (Array.to_list commands_params) in
let commands_counts = count_commands_by_type (commands_params) in
List.iter (fun (subtype, count) ->
define_out out (sprintf "COMMANDS_NB_%s" subtype) (string_of_int count)
) commands_counts;
Expand Down

0 comments on commit 4b9c04e

Please sign in to comment.