Class: OpenC3::Target
Overview
Target encapsulates the information about a OpenC3 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.
-
#language ⇒ String
readonly
Programming language.
-
#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(*_a) ⇒ 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.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/openc3/system/target.rb', line 88 def initialize(target_name, path, gem_path = nil) @language = 'ruby' @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.
66 67 68 |
# File 'lib/openc3/system/target.rb', line 66 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.
54 55 56 |
# File 'lib/openc3/system/target.rb', line 54 def cmd_tlm_files @cmd_tlm_files end |
#cmd_unique_id_mode ⇒ Boolean
Returns Indicates if all command packets identify using different fields.
72 73 74 |
# File 'lib/openc3/system/target.rb', line 72 def cmd_unique_id_mode @cmd_unique_id_mode end |
#dir ⇒ String (readonly)
Returns The directory which contains this target.
60 61 62 |
# File 'lib/openc3/system/target.rb', line 60 def dir @dir end |
#filename ⇒ String (readonly)
Returns Target filename for this target.
57 58 59 |
# File 'lib/openc3/system/target.rb', line 57 def filename @filename end |
#id ⇒ String
Returns Id of the target configuration.
78 79 80 |
# File 'lib/openc3/system/target.rb', line 78 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.
50 51 52 |
# File 'lib/openc3/system/target.rb', line 50 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.
45 46 47 |
# File 'lib/openc3/system/target.rb', line 45 def ignored_parameters @ignored_parameters end |
#interface ⇒ Interface
Returns The interface used to access the target.
63 64 65 |
# File 'lib/openc3/system/target.rb', line 63 def interface @interface end |
#language ⇒ String (readonly)
Returns Programming language. Must be ‘ruby’ or ‘python’.
36 37 38 |
# File 'lib/openc3/system/target.rb', line 36 def language @language end |
#name ⇒ String (readonly)
Returns Name of the target. This can be overridden when the system processes the target.
33 34 35 |
# File 'lib/openc3/system/target.rb', line 33 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.
40 41 42 |
# File 'lib/openc3/system/target.rb', line 40 def requires @requires end |
#tlm_cnt ⇒ Integer
Returns The number of telemetry packets received from this target.
69 70 71 |
# File 'lib/openc3/system/target.rb', line 69 def tlm_cnt @tlm_cnt end |
#tlm_unique_id_mode ⇒ Boolean
Returns Indicates if telemetry packets identify using different fields.
75 76 77 |
# File 'lib/openc3/system/target.rb', line 75 def tlm_unique_id_mode @tlm_unique_id_mode end |
Instance Method Details
#as_json(*_a) ⇒ Object
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/openc3/system/target.rb', line 199 def as_json(*_a) 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
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 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/openc3/system/target.rb', line 116 def process_file(filename) Logger.instance.info "Processing target definition in file '#{filename}'" parser = ConfigParser.new("https://docs.openc3.com/docs/configuration/target") parser.parse_file(filename) do |keyword, parameters| case keyword when 'LANGUAGE' usage = "#{keyword} <ruby | python>" parser.verify_num_parameters(1, 1, usage) @language = parameters[0].downcase 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 OpenC3.disable_warnings do OpenC3.require_file(filename, false) end rescue LoadError begin # If we couldn't load at the target/lib level check everywhere OpenC3.disable_warnings do filename = parameters[0] OpenC3.require_file(parameters[0]) end rescue Exception => e raise parser.error(e.formatted) end rescue Exception => e raise parser.error(e.formatted) 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 |