#!/usr/bin/env ruby # encoding: ascii-8bit # Copyright 2022 Ball Aerospace & Technologies Corp. # All Rights Reserved. # # This program is free software; you can modify and/or redistribute it # under the terms of the GNU Affero General Public License # as published by the Free Software Foundation; version 3 with # attribution addendums as found in the LICENSE.txt # # This program 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 Affero General Public License for more details. # # This program may also be used under the terms of a commercial or # enterprise edition license of COSMOS if purchased from the # copyright holder # This file converts to and from the .xtce file format require 'ostruct' require 'optparse' require 'cosmos' input_filename = nil option_parser = OptionParser.new do |option_parser| option_parser.banner = "Usage: xtce_converter [options] --import input_xtce_filename output_dir\n xtce_converter [options] --export output_dir" option_parser.separator("") # Create the help option option_parser.on("-h", "--help", "Show this message") do puts option_parser exit end # Create the version option option_parser.on("-v", "--version", "Show version") do puts "COSMOS Version: #{COSMOS_VERSION}" puts "User Version: #{USER_VERSION}" if defined? USER_VERSION exit end # Create the system option option_parser.on("--system VALUE", "Use an alternative system.txt file") do |arg| Cosmos::System.instance(File.join(USERPATH, 'config', 'system', arg)) end # Handle --import mode option_parser.on("-i VALUE", "--import VALUE", "Import the specified .xtce file") do |arg| input_filename = arg end # Handle --export mode option_parser.on("-e", "--export", "Create .xtce file(s) from the COSMOS Configuration") do |arg| # This is optional and the default end end begin option_parser.parse!(ARGV) rescue => err puts err puts option_parser exit end if ARGV[0] output_dir = ARGV[0] else puts option_parser exit end if input_filename packet_config = Cosmos::PacketConfig.new puts "Processing #{input_filename}..." packet_config.process_file(input_filename, nil) puts "Converting to COSMOS config files in #{output_dir}" packet_config.to_config(output_dir) puts "Success" exit 0 else puts "Loading COSMOS Configuration..." Cosmos::System.commands puts "Converting configuration to .xtce files in #{output_dir}" Cosmos::System.instance.instance_variable_get(:@config).to_xtce(output_dir) puts "Success" exit 0 end