Class: Cosmos::Target

Inherits:
Object show all
Defined in:
lib/cosmos/system/target.rb

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

Instance Method Summary collapse

Constructor Details

#initialize(target_name, substitute_name = nil, path = nil, target_filename = nil, 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.

Parameters:

  • target_name (String)

    The name of the target. This must match the directory name which contains the target.

  • substitute_name (String) (defaults to: nil)

    The name COSMOS should use when refering to the target. All accesses will ignore the original target_name.

  • path (String) (defaults to: nil)

    Path to the target directory. Passing nil sets the path to the default of <USERPATH>/config/targets.

  • target_filename (String) (defaults to: nil)

    Configuration file for the target. Normally target.txt

  • gem_path (String) (defaults to: nil)

    Path to the gem file or nil if there is no gem



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
109
110
111
112
113
# File 'lib/cosmos/system/target.rb', line 83

def initialize(target_name, substitute_name = nil, path = nil, target_filename = nil, gem_path = nil)
  @requires = []
  @ignored_parameters = []
  @ignored_items = []
  @cmd_tlm_files = []
  @auto_screen_substitute = false
  @interface = nil
  @routers = []
  @cmd_cnt = 0
  @tlm_cnt = 0

  # Determine the target name using substitution if given
  @original_name = target_name.clone.upcase.freeze
  if substitute_name
    @substitute = true
    @name = substitute_name.clone.upcase.freeze
  else
    @substitute = false
    @name = @original_name
  end

  @dir = get_target_dir(path, @original_name, gem_path)
  # Parse the target.txt file if it exists
  @filename = process_target_config_file(@dir, @name, target_filename)
  # 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(@dir)
  else
    add_cmd_tlm_partials(@dir)
  end
end

Instance Attribute Details

#auto_screen_substituteBoolean (readonly)

Returns Whether auto screen substitution is enabled.

Returns:

  • (Boolean)

    Whether auto screen substitution is enabled



45
46
47
# File 'lib/cosmos/system/target.rb', line 45

def auto_screen_substitute
  @auto_screen_substitute
end

#cmd_cntInteger

Returns The number of command packets send to this target.

Returns:

  • (Integer)

    The number of command packets send to this target



64
65
66
# File 'lib/cosmos/system/target.rb', line 64

def cmd_cnt
  @cmd_cnt
end

#cmd_tlm_filesArray<String> (readonly)

Returns List of configuration files which define the commands and telemetry for this target.

Returns:

  • (Array<String>)

    List of configuration files which define the commands and telemetry for this target



49
50
51
# File 'lib/cosmos/system/target.rb', line 49

def cmd_tlm_files
  @cmd_tlm_files
end

#dirString (readonly)

Returns The directory which contains this target. The directory is by default <USERPATH>/config/targets/<original_name>. Once a target has been processed it is copied to a saved configuration location and the dir will be updated to return this location.

Returns:

  • (String)

    The directory which contains this target. The directory is by default <USERPATH>/config/targets/<original_name>. Once a target has been processed it is copied to a saved configuration location and the dir will be updated to return this location.



58
59
60
# File 'lib/cosmos/system/target.rb', line 58

def dir
  @dir
end

#filenameString (readonly)

Returns Target filename for this target.

Returns:

  • (String)

    Target filename for this target



52
53
54
# File 'lib/cosmos/system/target.rb', line 52

def filename
  @filename
end

#ignored_itemsArray<String> (readonly)

Returns List of items that should be ignored. Tools which access this target should not display or manipulate these items.

Returns:

  • (Array<String>)

    List of items that should be ignored. Tools which access this target should not display or manipulate these items.



42
43
44
# File 'lib/cosmos/system/target.rb', line 42

def ignored_items
  @ignored_items
end

#ignored_parametersArray<String> (readonly)

Returns List of parameters that should be ignored. Tools which access this target should not display or manipulate these parameters.

Returns:

  • (Array<String>)

    List of parameters that should be ignored. Tools which access this target should not display or manipulate these parameters.



37
38
39
# File 'lib/cosmos/system/target.rb', line 37

def ignored_parameters
  @ignored_parameters
end

#interfaceInterface

Returns The interface used to access the target.

Returns:

  • (Interface)

    The interface used to access the target



61
62
63
# File 'lib/cosmos/system/target.rb', line 61

def interface
  @interface
end

#nameString (readonly)

Returns Name of the target. This can be overridden when the system processes the target.

Returns:

  • (String)

    Name of the target. This can be overridden when the system processes the target.



21
22
23
# File 'lib/cosmos/system/target.rb', line 21

def name
  @name
end

#original_nameString (readonly)

Returns Name of the target as defined by the target directory name. This name does not change.

Returns:

  • (String)

    Name of the target as defined by the target directory name. This name does not change.



25
26
27
# File 'lib/cosmos/system/target.rb', line 25

def original_name
  @original_name
end

#requiresArray<String> (readonly)

Returns List of filenames that must be required by Ruby before parsing the command and telemetry definitions for this target.

Returns:

  • (Array<String>)

    List of filenames that must be required by Ruby before parsing the command and telemetry definitions for this target



32
33
34
# File 'lib/cosmos/system/target.rb', line 32

def requires
  @requires
end

#substituteBoolean (readonly)

Returns Indicates if substitution should take place or not.

Returns:

  • (Boolean)

    Indicates if substitution should take place or not



28
29
30
# File 'lib/cosmos/system/target.rb', line 28

def substitute
  @substitute
end

#tlm_cntInteger

Returns The number of telemetry packets received from this target.

Returns:

  • (Integer)

    The number of telemetry packets received from this target



67
68
69
# File 'lib/cosmos/system/target.rb', line 67

def tlm_cnt
  @tlm_cnt
end

Instance Method Details

#process_file(filename) ⇒ Object

Parses the target configuration file

Parameters:

  • filename (String)

    The target configuration file to parse



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
# File 'lib/cosmos/system/target.rb', line 118

def process_file(filename)
  Logger.instance.info "Processing target definition in file '#{filename}'"
  parser = ConfigParser.new
  parser.parse_file(filename) do |keyword, parameters|
    case keyword
    when 'REQUIRE'
      usage = "#{keyword} <FILENAME>"
      parser.verify_num_parameters(1, 1, usage)
      begin
        Cosmos.require_file(parameters[0])
      rescue Exception => err
        raise parser.error(err.message)
      end
      @requires << parameters[0]

    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

    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