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) ⇒ 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/cosmos/system/target.rb', line 82

def initialize(target_name, substitute_name = nil, path = nil, target_filename = nil)
  path = File.join(USERPATH,'config','targets') unless path
  @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
  @requires = []
  @ignored_parameters = []
  @ignored_items = []
  @auto_screen_substitute = false

  @dir = File.join(path, @original_name)
  lib_dir = File.join(@dir, 'lib')
  Cosmos.add_to_search_path(lib_dir, false) if File.exist?(lib_dir)

  @cmd_tlm_files = []
  @filename = File.join(@dir, target_filename || 'target.txt')
  if File.exist?(@filename)
    process_file(@filename)
  else
    raise "Target file #{target_filename} for target #{@name} does not exist" if target_filename
  end

  if @cmd_tlm_files.empty?
    if Dir.exist?(File.join(@dir, 'cmd_tlm'))
      Dir.foreach(File.join(@dir, 'cmd_tlm')) do |dir_filename|
        if dir_filename[0] != '.'
          @cmd_tlm_files << File.join(@dir, 'cmd_tlm', dir_filename)
        end
      end
    end
    @cmd_tlm_files.sort!
  end

  @interface = nil
  @routers = []
  @cmd_cnt = 0
  @tlm_cnt = 0
end

Instance Attribute Details

#auto_screen_substituteBoolean (readonly)



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

def auto_screen_substitute
  @auto_screen_substitute
end

#cmd_cntInteger



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

def cmd_cnt
  @cmd_cnt
end

#cmd_tlm_filesArray<String> (readonly)



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

def cmd_tlm_files
  @cmd_tlm_files
end

#dirString (readonly)



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

def dir
  @dir
end

#filenameString (readonly)



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

def filename
  @filename
end

#ignored_itemsArray<String> (readonly)



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

def ignored_items
  @ignored_items
end

#ignored_parametersArray<String> (readonly)



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

def ignored_parameters
  @ignored_parameters
end

#interfaceInterface



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

def interface
  @interface
end

#nameString (readonly)



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

def name
  @name
end

#original_nameString (readonly)



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

def original_name
  @original_name
end

#requiresArray<String> (readonly)



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

def requires
  @requires
end

#substituteBoolean (readonly)



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

def substitute
  @substitute
end

#tlm_cntInteger



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



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

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'
      usage = "#{keyword} <PARAMETER NAME>"
      parser.verify_num_parameters(1, 1, usage)
      @ignored_parameters << parameters[0].upcase

    when 'IGNORE_ITEM'
      usage = "#{keyword} <ITEM NAME>"
      parser.verify_num_parameters(1, 1, usage)
      @ignored_items << parameters[0].upcase

    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