Class: Cosmos::Target
Overview
Target encapsulates the information about a COSMOS target. Targets are accessed through interfaces and have command and telemetry definition files which define their access.
Instance Attribute Summary collapse
-
#cmd_cnt ⇒ Integer
The number of command packets send to this target.
-
#cmd_tlm_files ⇒ Array<String>
readonly
List of configuration files which define the commands and telemetry for this target.
-
#cmd_unique_id_mode ⇒ Boolean
Indicates if all command packets identify using different fields.
-
#dir ⇒ String
readonly
The directory which contains this target.
-
#filename ⇒ String
readonly
Target filename for this target.
-
#id ⇒ String
Id of the target configuration.
-
#ignored_items ⇒ Array<String>
readonly
List of items that should be ignored.
-
#ignored_parameters ⇒ Array<String>
readonly
List of parameters that should be ignored.
-
#interface ⇒ Interface
The interface used to access the target.
-
#name ⇒ String
readonly
Name of the target.
-
#requires ⇒ Array<String>
readonly
List of filenames that must be required by Ruby before parsing the command and telemetry definitions for this target.
-
#tlm_cnt ⇒ Integer
The number of telemetry packets received from this target.
-
#tlm_unique_id_mode ⇒ Boolean
Indicates if telemetry packets identify using different fields.
Instance Method Summary collapse
- #as_json ⇒ Object
-
#initialize(target_name, path, gem_path = nil) ⇒ Target
constructor
Creates a new target by processing the target.txt file in the directory given by the path joined with the target_name.
-
#process_file(filename) ⇒ Object
Parses the target configuration file.
Constructor Details
#initialize(target_name, path, gem_path = nil) ⇒ Target
Creates a new target by processing the target.txt file in the directory given by the path joined with the target_name. Records all the command and telemetry definition files found in the targets cmd_tlm directory. System uses this list and processes them using PacketConfig.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/cosmos/system/target.rb', line 82 def initialize(target_name, path, gem_path = nil) @requires = [] @ignored_parameters = [] @ignored_items = [] @cmd_tlm_files = [] # @auto_screen_substitute = false @interface = nil @routers = [] @cmd_cnt = 0 @tlm_cnt = 0 @cmd_unique_id_mode = false @tlm_unique_id_mode = false @name = target_name.clone.upcase.freeze get_target_dir(path, gem_path) process_target_config_file() # If target.txt didn't specify specific cmd/tlm files then add everything if @cmd_tlm_files.empty? @cmd_tlm_files = add_all_cmd_tlm() else add_cmd_tlm_partials() end end |
Instance Attribute Details
#cmd_cnt ⇒ Integer
Returns The number of command packets send to this target.
60 61 62 |
# File 'lib/cosmos/system/target.rb', line 60 def cmd_cnt @cmd_cnt end |
#cmd_tlm_files ⇒ Array<String> (readonly)
Returns List of configuration files which define the commands and telemetry for this target.
48 49 50 |
# File 'lib/cosmos/system/target.rb', line 48 def cmd_tlm_files @cmd_tlm_files end |
#cmd_unique_id_mode ⇒ Boolean
Returns Indicates if all command packets identify using different fields.
66 67 68 |
# File 'lib/cosmos/system/target.rb', line 66 def cmd_unique_id_mode @cmd_unique_id_mode end |
#dir ⇒ String (readonly)
Returns The directory which contains this target.
54 55 56 |
# File 'lib/cosmos/system/target.rb', line 54 def dir @dir end |
#filename ⇒ String (readonly)
Returns Target filename for this target.
51 52 53 |
# File 'lib/cosmos/system/target.rb', line 51 def filename @filename end |
#id ⇒ String
Returns Id of the target configuration.
72 73 74 |
# File 'lib/cosmos/system/target.rb', line 72 def id @id end |
#ignored_items ⇒ Array<String> (readonly)
Returns List of items that should be ignored. Tools which access this target should not display or manipulate these items.
44 45 46 |
# File 'lib/cosmos/system/target.rb', line 44 def ignored_items @ignored_items end |
#ignored_parameters ⇒ Array<String> (readonly)
Returns List of parameters that should be ignored. Tools which access this target should not display or manipulate these parameters.
39 40 41 |
# File 'lib/cosmos/system/target.rb', line 39 def ignored_parameters @ignored_parameters end |
#interface ⇒ Interface
Returns The interface used to access the target.
57 58 59 |
# File 'lib/cosmos/system/target.rb', line 57 def interface @interface end |
#name ⇒ String (readonly)
Returns Name of the target. This can be overridden when the system processes the target.
30 31 32 |
# File 'lib/cosmos/system/target.rb', line 30 def name @name end |
#requires ⇒ Array<String> (readonly)
Returns List of filenames that must be required by Ruby before parsing the command and telemetry definitions for this target.
34 35 36 |
# File 'lib/cosmos/system/target.rb', line 34 def requires @requires end |
#tlm_cnt ⇒ Integer
Returns The number of telemetry packets received from this target.
63 64 65 |
# File 'lib/cosmos/system/target.rb', line 63 def tlm_cnt @tlm_cnt end |
#tlm_unique_id_mode ⇒ Boolean
Returns Indicates if telemetry packets identify using different fields.
69 70 71 |
# File 'lib/cosmos/system/target.rb', line 69 def tlm_unique_id_mode @tlm_unique_id_mode end |
Instance Method Details
#as_json ⇒ Object
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/cosmos/system/target.rb', line 187 def as_json config = {} config['name'] = @name config['requires'] = @requires config['ignored_parameters'] = @ignored_parameters config['ignored_items'] = @ignored_items # config['auto_screen_substitute'] = true if @auto_screen_substitute config['cmd_tlm_files'] = @cmd_tlm_files # config['filename'] = @filename # config['interface'] = @interface.name if @interface # config['dir'] = @dir # config['cmd_cnt'] = @cmd_cnt # config['tlm_cnt'] = @tlm_cnt config['cmd_unique_id_mode'] = true if @cmd_unique_id_mode config['tlm_unique_id_mode'] = true if @tlm_unique_id_mode config['id'] = @id config end |
#process_file(filename) ⇒ Object
Parses the target configuration file
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/cosmos/system/target.rb', line 109 def process_file(filename) Logger.instance.info "Processing target definition in file '#{filename}'" parser = ConfigParser.new("https://cosmosc2.com/docs/v5/target") parser.parse_file(filename) do |keyword, parameters| case keyword when 'REQUIRE' usage = "#{keyword} <FILENAME>" parser.verify_num_parameters(1, 1, usage) filename = File.join(@dir, 'lib', parameters[0]) begin # Require absolute path to file in target lib folder. Prevents name # conflicts at the require step Cosmos.disable_warnings do Cosmos.require_file(filename, false) end rescue LoadError begin # If we couldn't load at the target/lib level check everywhere Cosmos.disable_warnings do filename = parameters[0] Cosmos.require_file(parameters[0]) end rescue Exception => err raise parser.error(err.) end rescue Exception => err raise parser.error(err.) end # This code resolves any relative paths to absolute before putting into the @requires array unless Pathname.new(filename).absolute? $:.each do |search_path| test_filename = File.join(search_path, filename).gsub("\\", "/") if File.exist?(test_filename) filename = test_filename break end end end @requires << filename when 'IGNORE_PARAMETER', 'IGNORE_ITEM' usage = "#{keyword} <#{keyword.split('_')[1]} NAME>" parser.verify_num_parameters(1, 1, usage) @ignored_parameters << parameters[0].upcase if keyword.include?("PARAMETER") @ignored_items << parameters[0].upcase if keyword.include?("ITEM") when 'COMMANDS', 'TELEMETRY' usage = "#{keyword} <FILENAME>" parser.verify_num_parameters(1, 1, usage) filename = File.join(@dir, 'cmd_tlm', parameters[0]) raise parser.error("#{filename} not found") unless File.exist?(filename) @cmd_tlm_files << filename # when 'AUTO_SCREEN_SUBSTITUTE' # usage = "#{keyword}" # parser.verify_num_parameters(0, 0, usage) # @auto_screen_substitute = true when 'CMD_UNIQUE_ID_MODE' usage = "#{keyword}" parser.verify_num_parameters(0, 0, usage) @cmd_unique_id_mode = true when 'TLM_UNIQUE_ID_MODE' usage = "#{keyword}" parser.verify_num_parameters(0, 0, usage) @tlm_unique_id_mode = true else # blank lines will have a nil keyword and should not raise an exception raise parser.error("Unknown keyword '#{keyword}'") if keyword end # case keyword end end |