Class: OpenC3::XtceConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/openc3/packets/parsers/xtce_converter.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#current_target_nameObject

Returns the value of attribute current_target_name.



34
35
36
# File 'lib/openc3/packets/parsers/xtce_converter.rb', line 34

def current_target_name
  @current_target_name
end

Class Method Details

.combine_output_xtce(output_dir, root_target_name = nil) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/openc3/packets/parsers/xtce_converter.rb', line 49

def self.combine_output_xtce(output_dir, root_target_name = nil)
  combined_file_directory = File.join(output_dir, 'TARGETS_COMBINED', 'cmd_tlm')
  begin
    FileUtils.rm_rf(combined_file_directory)
  rescue
    # doesn't exist
  end
  file_pattern = File.join(output_dir, "**", "*.xtce")
  xml_files = Dir.glob(file_pattern)
  if xml_files.empty?
      puts "No *.xtce files found to combine."
  elsif xml_files.length == 1
      puts "Only one *.xtce file found. No need to unify."
  else
    puts "Multiple targets found. Creating Unified XTCE representation."
    FileUtils.mkdir_p(combined_file_directory)
    file_basename = "combined"
    xml_files.each do |file_path|
      file_basename += "_#{File.basename(file_path, ".*")}"
    end
    full_file_name = File.join(combined_file_directory, file_basename.downcase + '.xtce')
    begin
      File.delete(full_file_name)
    rescue
      # Doesn't exist
    end
    xml_files.each do |file_path|
      file_basename += File.basename(file_path, ".*")
    end
    root_builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
      xml['xtce'].SpaceSystem("xmlns:xtce" => "http://www.omg.org/spec/XTCE/20180204",
                              "xmlns:xsi" => "http://www.w3.org/2001/XMLSchema-instance",
                              "name" => root_target_name ? root_target_name : "root",
                              "xsi:schemaLocation" => "http://www.omg.org/spec/XTCE/20180204 https://www.omg.org/spec/XTCE/20180204/SpaceSystem.xsd")
    end
    new_doc = root_builder.doc
    new_root = new_doc.root
    xml_files.each do |file_path|
      source_doc = Nokogiri::XML(File.open(file_path))
      target_root = source_doc.root
      target_root.attributes.each do |name, attr|
        unless name == "name"
          attr.remove
        end
      end
      if root_target_name == target_root["name"]
        nodes_to_add_reversed = target_root.children.to_a.reverse
        nodes_to_add_reversed.each do |child_node|
          new_root.prepend_child(child_node)
        end
      else
        new_root.add_child(target_root)
      end
    end
    File.open(full_file_name, 'w') do |file|
      file.puts new_doc.to_xml
    end
    full_file_name
  end
end

.convert(commands, telemetry, output_dir, time_association_name) ⇒ Object

Output a previously parsed definition file into the XTCE format

Parameters:

  • commands (Hash<String=>Packet>)

    Hash of all the command packets keyed by the packet name.

  • telemetry (Hash<String=>Packet>)

    Hash of all the telemetry packets keyed by the packet name. that were created while parsing the configuration

  • output_dir (String)

    The name of the output directory to generate the XTCE files. A file is generated for each target.



45
46
47
# File 'lib/openc3/packets/parsers/xtce_converter.rb', line 45

def self.convert(commands, telemetry, output_dir, time_association_name)
  XtceConverter.new(commands, telemetry, output_dir, time_association_name)
end