cosmos 3.3.3 → 3.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitattributes +2 -0
- data/.travis.yml +2 -1
- data/Gemfile +4 -3
- data/Manifest.txt +22 -0
- data/autohotkey/tools/handbook_creator.ahk +9 -0
- data/autohotkey/tools/packet_viewer.ahk +4 -0
- data/bin/exchndl20-x64.dll +0 -0
- data/bin/exchndl20.dll +0 -0
- data/bin/exchndl21-x64.dll +0 -0
- data/bin/exchndl21.dll +0 -0
- data/bin/exchndl22-x64.dll +0 -0
- data/bin/exchndl22.dll +0 -0
- data/bin/mgwhelp-x64.dll +0 -0
- data/bin/mgwhelp.dll +0 -0
- data/cosmos.gemspec +1 -0
- data/data/crc.txt +30 -24
- data/demo/config/data/crc.txt +3 -3
- data/demo/config/tools/handbook_creator/templates/command_packets.html.erb +3 -1
- data/demo/config/tools/handbook_creator/templates/telemetry_packets.html.erb +3 -1
- data/demo/procedures/cosmos_api_test.rb +1 -1
- data/ext/cosmos/ext/low_fragmentation_array/low_fragmentation_array.c +4 -0
- data/ext/cosmos/ext/platform/platform.c +22 -2
- data/ext/cosmos/ext/structure/structure.c +631 -104
- data/ext/cosmos/ext/telemetry/telemetry.c +3 -2
- data/lib/cosmos/gui/line_graph/line_graph_drawing.rb +71 -92
- data/lib/cosmos/gui/line_graph/overview_graph.rb +1 -1
- data/lib/cosmos/gui/qt.rb +38 -24
- data/lib/cosmos/gui/text/ruby_editor.rb +1 -1
- data/lib/cosmos/packets/binary_accessor.rb +1 -288
- data/lib/cosmos/packets/telemetry.rb +2 -1
- data/lib/cosmos/script/cmd_tlm_server.rb +110 -0
- data/lib/cosmos/script/commands.rb +166 -0
- data/lib/cosmos/script/extract.rb +2 -2
- data/lib/cosmos/script/limits.rb +108 -0
- data/lib/cosmos/script/script.rb +28 -1487
- data/lib/cosmos/script/scripting.rb +889 -0
- data/lib/cosmos/script/telemetry.rb +174 -0
- data/lib/cosmos/script/tools.rb +138 -0
- data/lib/cosmos/streams/stream_protocol.rb +9 -6
- data/lib/cosmos/system/target.rb +55 -38
- data/lib/cosmos/tools/cmd_tlm_server/api.rb +6 -3
- data/lib/cosmos/tools/cmd_tlm_server/connections.rb +0 -1
- data/lib/cosmos/tools/cmd_tlm_server/gui/interfaces_tab.rb +17 -7
- data/lib/cosmos/tools/cmd_tlm_server/interface_thread.rb +15 -4
- data/lib/cosmos/tools/handbook_creator/handbook_creator.rb +15 -8
- data/lib/cosmos/tools/handbook_creator/handbook_creator_config.rb +41 -13
- data/lib/cosmos/tools/packet_viewer/packet_viewer.rb +18 -1
- data/lib/cosmos/tools/tlm_viewer/widgets/canvasline_widget.rb +1 -1
- data/lib/cosmos/tools/tlm_viewer/widgets/canvaslinevalue_widget.rb +1 -1
- data/lib/cosmos/tools/tlm_viewer/widgets/limitsbar_widget.rb +1 -1
- data/lib/cosmos/tools/tlm_viewer/widgets/rangebar_widget.rb +1 -1
- data/lib/cosmos/top_level.rb +1 -1
- data/lib/cosmos/utilities/ruby_lex_utils.rb +1 -1
- data/lib/cosmos/version.rb +5 -5
- data/spec/gui/line_graph/line_clip_spec.rb +6 -6
- data/spec/gui/qt_spec.rb +102 -0
- data/spec/interfaces/interface_spec.rb +9 -9
- data/spec/interfaces/linc_interface_spec.rb +72 -15
- data/spec/interfaces/serial_interface_spec.rb +9 -9
- data/spec/interfaces/simulated_target_interface_spec.rb +7 -7
- data/spec/interfaces/stream_interface_spec.rb +4 -4
- data/spec/interfaces/tcpip_client_interface_spec.rb +8 -8
- data/spec/interfaces/tcpip_server_interface_spec.rb +9 -9
- data/spec/interfaces/udp_interface_spec.rb +20 -20
- data/spec/io/json_drb_spec.rb +4 -4
- data/spec/io/raw_logger_pair_spec.rb +20 -20
- data/spec/io/raw_logger_spec.rb +3 -3
- data/spec/io/tcpip_server_spec.rb +9 -9
- data/spec/io/udp_sockets_spec.rb +2 -2
- data/spec/io/win32_serial_driver_spec.rb +2 -2
- data/spec/packets/binary_accessor_spec.rb +143 -6
- data/spec/packets/commands_spec.rb +5 -5
- data/spec/packets/limits_spec.rb +15 -15
- data/spec/packets/packet_config_spec.rb +19 -19
- data/spec/packets/packet_item_limits_spec.rb +3 -3
- data/spec/packets/packet_item_spec.rb +4 -4
- data/spec/packets/packet_spec.rb +33 -33
- data/spec/packets/structure_item_spec.rb +19 -19
- data/spec/packets/telemetry_spec.rb +6 -6
- data/spec/script/cmd_tlm_server_spec.rb +110 -0
- data/spec/script/commands_disconnect_spec.rb +270 -0
- data/spec/script/commands_spec.rb +288 -0
- data/spec/script/limits_spec.rb +153 -0
- data/spec/script/script_spec.rb +32 -696
- data/spec/script/scripting_spec.rb +436 -0
- data/spec/script/telemetry_spec.rb +130 -0
- data/spec/script/tools_spec.rb +117 -0
- data/spec/spec_helper.rb +10 -5
- data/spec/streams/preidentified_stream_protocol_spec.rb +4 -4
- data/spec/streams/serial_stream_spec.rb +8 -8
- data/spec/streams/stream_protocol_spec.rb +4 -4
- data/spec/streams/tcpip_client_stream_spec.rb +3 -3
- data/spec/streams/tcpip_socket_stream_spec.rb +7 -7
- data/spec/streams/template_stream_protocol_spec.rb +1 -1
- data/spec/system/system_spec.rb +6 -6
- data/spec/system/target_spec.rb +2 -0
- data/spec/tools/cmd_tlm_server/api_spec.rb +17 -17
- data/spec/tools/cmd_tlm_server/cmd_tlm_server_config_spec.rb +5 -5
- data/spec/tools/cmd_tlm_server/interface_thread_spec.rb +3 -3
- data/spec/top_level/top_level_spec.rb +8 -8
- data/spec/utilities/csv_spec.rb +3 -3
- data/spec/utilities/message_log_spec.rb +3 -3
- data/spec/utilities/ruby_lex_utils_spec.rb +7 -7
- data/test/performance/config/tools/launcher/launcher_threads.txt +8 -1
- data/test/performance/tools/CmdTlmServerMemProf +1 -1
- data/test/performance/tools/TlmGrapherMemProf +19 -0
- data/test/performance/tools/TlmGrapherMemProf.bat +59 -0
- metadata +38 -2
@@ -0,0 +1,174 @@
|
|
1
|
+
# encoding: ascii-8bit
|
2
|
+
|
3
|
+
# Copyright 2014 Ball Aerospace & Technologies Corp.
|
4
|
+
# All Rights Reserved.
|
5
|
+
#
|
6
|
+
# This program is free software; you can modify and/or redistribute it
|
7
|
+
# under the terms of the GNU General Public License
|
8
|
+
# as published by the Free Software Foundation; version 3 with
|
9
|
+
# attribution addendums as found in the LICENSE.txt
|
10
|
+
|
11
|
+
module Cosmos
|
12
|
+
|
13
|
+
module Script
|
14
|
+
private
|
15
|
+
|
16
|
+
# Poll for the converted value of a telemetry item
|
17
|
+
# Usage:
|
18
|
+
# tlm(target_name, packet_name, item_name)
|
19
|
+
# or
|
20
|
+
# tlm('target_name packet_name item_name')
|
21
|
+
def tlm(*args)
|
22
|
+
return $cmd_tlm_server.tlm(*args)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Poll for the raw value of a telemetry item
|
26
|
+
# Usage:
|
27
|
+
# tlm_raw(target_name, packet_name, item_name)
|
28
|
+
# or
|
29
|
+
# tlm_raw('target_name packet_name item_name')
|
30
|
+
def tlm_raw(*args)
|
31
|
+
return $cmd_tlm_server.tlm_raw(*args)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Poll for the formatted value of a telemetry item
|
35
|
+
# Usage:
|
36
|
+
# tlm_formatted(target_name, packet_name, item_name)
|
37
|
+
# or
|
38
|
+
# tlm_formatted('target_name packet_name item_name')
|
39
|
+
def tlm_formatted(*args)
|
40
|
+
return $cmd_tlm_server.tlm_formatted(*args)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Poll for the formatted with units value of a telemetry item
|
44
|
+
# Usage:
|
45
|
+
# tlm_with_units(target_name, packet_name, item_name)
|
46
|
+
# or
|
47
|
+
# tlm_with_units('target_name packet_name item_name')
|
48
|
+
def tlm_with_units(*args)
|
49
|
+
return $cmd_tlm_server.tlm_with_units(*args)
|
50
|
+
end
|
51
|
+
|
52
|
+
def tlm_variable(*args)
|
53
|
+
return $cmd_tlm_server.tlm_variable(*args)
|
54
|
+
end
|
55
|
+
|
56
|
+
# Set a telemetry point to a given value. Note this will be over written in
|
57
|
+
# a live system by incoming new telemetry.
|
58
|
+
# Usage:
|
59
|
+
# set_tlm(target_name, packet_name, item_name, value)
|
60
|
+
# or
|
61
|
+
# set_tlm("target_name packet_name item_name = value")
|
62
|
+
def set_tlm(*args)
|
63
|
+
return $cmd_tlm_server.set_tlm(*args)
|
64
|
+
end
|
65
|
+
|
66
|
+
# Set the raw value of a telemetry point to a given value. Note this will
|
67
|
+
# be over written in a live system by incoming new telemetry.
|
68
|
+
# Usage:
|
69
|
+
# set_tlm(target_name, packet_name, item_name, value)
|
70
|
+
# or
|
71
|
+
# set_tlm("target_name packet_name item_name = value")
|
72
|
+
def set_tlm_raw(*args)
|
73
|
+
return $cmd_tlm_server.set_tlm_raw(*args)
|
74
|
+
end
|
75
|
+
|
76
|
+
# Gets all the values from the given packet returned in a two dimensional
|
77
|
+
# array containing the item_name, value, and limits state.
|
78
|
+
# Usage:
|
79
|
+
# values = get_tlm_packet(target_name, packet_name, <:RAW, :CONVERTED, :FORMATTED, :WITH_UNITS>)
|
80
|
+
def get_tlm_packet(target_name, packet_name, value_types = :CONVERTED)
|
81
|
+
result = $cmd_tlm_server.get_tlm_packet(target_name, packet_name, value_types)
|
82
|
+
result.each do |entry|
|
83
|
+
entry[2] = entry[2].to_s.intern if entry[2]
|
84
|
+
end
|
85
|
+
result
|
86
|
+
end
|
87
|
+
|
88
|
+
# Gets all the values from the given packet returned in an
|
89
|
+
# array consisting of an Array of item values, an array of item limits state
|
90
|
+
# given as symbols such as :RED, :YELLOW, :STALE, an array of arrays including
|
91
|
+
# the limits setting such as red low, yellow low, yellow high, red high and
|
92
|
+
# optionally green low and high, and the overall limits state of the system.
|
93
|
+
# Usage:
|
94
|
+
# values = get_tlm_values([[target_name, packet_name, item_name], ...], <:RAW, :CONVERTED, :FORMATTED, :WITH_UNITS>)
|
95
|
+
def get_tlm_values(items, value_types = :CONVERTED)
|
96
|
+
result = $cmd_tlm_server.get_tlm_values(items, value_types)
|
97
|
+
result[1].length.times do |index|
|
98
|
+
result[1][index] = result[1][index].to_s.intern if result[1][index]
|
99
|
+
end
|
100
|
+
result[3] = result[3].to_s.intern
|
101
|
+
result
|
102
|
+
end
|
103
|
+
|
104
|
+
# Gets the packets for a given target name. Returns an array of arrays
|
105
|
+
# consisting of packet names and packet descriptions.
|
106
|
+
def get_tlm_list(target_name)
|
107
|
+
return $cmd_tlm_server.get_tlm_list(target_name)
|
108
|
+
end
|
109
|
+
|
110
|
+
# Gets all the telemetry mnemonics for a given target and packet. Returns an
|
111
|
+
# array of arrays consisting of item names, item states, and item descriptions.
|
112
|
+
def get_tlm_item_list(target_name, packet_name)
|
113
|
+
return $cmd_tlm_server.get_tlm_item_list(target_name, packet_name)
|
114
|
+
end
|
115
|
+
|
116
|
+
# Gets the list of all defined targets.
|
117
|
+
def get_target_list
|
118
|
+
return $cmd_tlm_server.get_target_list
|
119
|
+
end
|
120
|
+
|
121
|
+
def get_tlm_details(items)
|
122
|
+
$cmd_tlm_server.get_tlm_details(items)
|
123
|
+
end
|
124
|
+
|
125
|
+
# Subscribe to one or more telemetry packets. The queue ID is returned for
|
126
|
+
# use in get_packet_data and unsubscribe_packet_data.
|
127
|
+
# Usage:
|
128
|
+
# id = subscribe_packet_data([[target_name,packet_name], ...], <queue_size>)
|
129
|
+
def subscribe_packet_data(packets, queue_size = CmdTlmServer::DEFAULT_PACKET_DATA_QUEUE_SIZE)
|
130
|
+
result = $cmd_tlm_server.subscribe_packet_data(packets, queue_size)
|
131
|
+
result
|
132
|
+
end
|
133
|
+
|
134
|
+
# Unsubscribe to telemetry packets. Pass the queue ID which was returned by
|
135
|
+
# the subscribe_packet_data method.
|
136
|
+
# Usage:
|
137
|
+
# unsubscribe_packet_data(id)
|
138
|
+
def unsubscribe_packet_data(id)
|
139
|
+
result = $cmd_tlm_server.unsubscribe_packet_data(id)
|
140
|
+
result
|
141
|
+
end
|
142
|
+
|
143
|
+
# DEPRECATED
|
144
|
+
def get_packet_data(id, non_block = false)
|
145
|
+
results = $cmd_tlm_server.get_packet_data(id, non_block)
|
146
|
+
if Array === results and results[3] and results[4]
|
147
|
+
results[3] = Time.at(results[3], results[4])
|
148
|
+
results.delete_at(4)
|
149
|
+
end
|
150
|
+
results
|
151
|
+
end
|
152
|
+
|
153
|
+
# Get a packet which was previously subscribed to by
|
154
|
+
# subscribe_packet_data. This method can block waiting for new packets or
|
155
|
+
# not based on the second parameter. It returns a single Cosmos::Packet instance
|
156
|
+
# and will return nil when no more packets are buffered (assuming non_block
|
157
|
+
# is false).
|
158
|
+
# Usage:
|
159
|
+
# get_packet(id, <true or false to block>)
|
160
|
+
def get_packet(id, non_block = false)
|
161
|
+
packet = nil
|
162
|
+
buffer, target_name, packet_name, received_time, received_count = get_packet_data(id, non_block)
|
163
|
+
if buffer
|
164
|
+
packet = System.telemetry.packet(target_name, packet_name).clone
|
165
|
+
packet.buffer = buffer
|
166
|
+
packet.received_time = received_time
|
167
|
+
packet.received_count = received_count
|
168
|
+
end
|
169
|
+
packet
|
170
|
+
end
|
171
|
+
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
@@ -0,0 +1,138 @@
|
|
1
|
+
# encoding: ascii-8bit
|
2
|
+
|
3
|
+
# Copyright 2014 Ball Aerospace & Technologies Corp.
|
4
|
+
# All Rights Reserved.
|
5
|
+
#
|
6
|
+
# This program is free software; you can modify and/or redistribute it
|
7
|
+
# under the terms of the GNU General Public License
|
8
|
+
# as published by the Free Software Foundation; version 3 with
|
9
|
+
# attribution addendums as found in the LICENSE.txt
|
10
|
+
|
11
|
+
module Cosmos
|
12
|
+
|
13
|
+
module Script
|
14
|
+
private
|
15
|
+
|
16
|
+
#######################################
|
17
|
+
# Methods accessing tlm_viewer
|
18
|
+
#######################################
|
19
|
+
|
20
|
+
def display(display_name, x_pos = nil, y_pos = nil)
|
21
|
+
run_tlm_viewer(display_name, "displayed") do |tlm_viewer|
|
22
|
+
tlm_viewer.display(display_name, x_pos, y_pos)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def clear(display_name)
|
27
|
+
run_tlm_viewer(display_name, "cleared") do |tlm_viewer|
|
28
|
+
tlm_viewer.clear(display_name)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def run_tlm_viewer(display_name, action)
|
33
|
+
tlm_viewer = JsonDRbObject.new "localhost", System.ports['TLMVIEWER_API']
|
34
|
+
begin
|
35
|
+
yield tlm_viewer
|
36
|
+
tlm_viewer.disconnect
|
37
|
+
rescue DRb::DRbConnError
|
38
|
+
# No Listening Tlm Viewer - So Start One
|
39
|
+
start_tlm_viewer
|
40
|
+
begin
|
41
|
+
yield tlm_viewer
|
42
|
+
tlm_viewer.disconnect
|
43
|
+
rescue DRb::DRbConnError
|
44
|
+
raise "Unable to Successfully Start Listening Telemetry Viewer: #{display_name} could not be #{action}"
|
45
|
+
rescue Errno::ENOENT
|
46
|
+
raise "Display Screen File: #{display_name}.txt does not exist"
|
47
|
+
end
|
48
|
+
rescue Errno::ENOENT
|
49
|
+
raise "Display Screen File: #{display_name}.txt does not exist"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def start_tlm_viewer
|
54
|
+
system_file = File.basename(System.initial_filename)
|
55
|
+
mac_app = File.join(Cosmos::USERPATH, 'tools', 'mac', 'TlmViewer.app')
|
56
|
+
|
57
|
+
if Kernel.is_mac? && File.exist?(mac_app)
|
58
|
+
Cosmos.run_process("open '#{mac_app}' --args --system #{system_file}")
|
59
|
+
else
|
60
|
+
cmd = 'ruby'
|
61
|
+
cmd << 'w' if Kernel.is_windows? # Windows uses rubyw to avoid creating a DOS shell
|
62
|
+
Cosmos.run_process("#{cmd} '#{File.join(Cosmos::USERPATH, 'tools', 'TlmViewer')}' --system #{system_file}")
|
63
|
+
end
|
64
|
+
sleep(5)
|
65
|
+
end
|
66
|
+
|
67
|
+
#######################################
|
68
|
+
# Methods accessing script runner
|
69
|
+
#######################################
|
70
|
+
|
71
|
+
def _ensure_script_runner_frame
|
72
|
+
yield if defined? ScriptRunnerFrame && ScriptRunnerFrame.instance
|
73
|
+
end
|
74
|
+
|
75
|
+
def set_line_delay(delay)
|
76
|
+
_ensure_script_runner_frame { ScriptRunnerFrame.line_delay = delay if delay >= 0.0 }
|
77
|
+
end
|
78
|
+
|
79
|
+
def get_line_delay
|
80
|
+
_ensure_script_runner_frame { ScriptRunnerFrame.line_delay }
|
81
|
+
end
|
82
|
+
|
83
|
+
def get_scriptrunner_message_log_filename
|
84
|
+
filename = nil
|
85
|
+
_ensure_script_runner_frame do
|
86
|
+
filename = ScriptRunnerFrame.instance.message_log.filename if ScriptRunnerFrame.instance.message_log
|
87
|
+
end
|
88
|
+
return filename
|
89
|
+
end
|
90
|
+
|
91
|
+
def start_new_scriptrunner_message_log
|
92
|
+
# A new log will be created at the next message
|
93
|
+
_ensure_script_runner_frame { ScriptRunnerFrame.instance.stop_message_log }
|
94
|
+
end
|
95
|
+
|
96
|
+
def disable_instrumentation
|
97
|
+
if defined? ScriptRunnerFrame && ScriptRunnerFrame.instance
|
98
|
+
ScriptRunnerFrame.instance.use_instrumentation = false
|
99
|
+
begin
|
100
|
+
yield
|
101
|
+
ensure
|
102
|
+
ScriptRunnerFrame.instance.use_instrumentation = true
|
103
|
+
end
|
104
|
+
else
|
105
|
+
yield
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def set_stdout_max_lines(max_lines)
|
110
|
+
_ensure_script_runner_frame { ScriptRunnerFrame.instance.stdout_max_lines = max_lines }
|
111
|
+
end
|
112
|
+
|
113
|
+
#######################################
|
114
|
+
# Methods for debugging
|
115
|
+
#######################################
|
116
|
+
|
117
|
+
def insert_return(*params)
|
118
|
+
_ensure_script_runner_frame do
|
119
|
+
ScriptRunnerFrame.instance.inline_return = true
|
120
|
+
ScriptRunnerFrame.instance.inline_return_params = params
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def step_mode
|
125
|
+
_ensure_script_runner_frame { ScriptRunnerFrame.step_mode = true }
|
126
|
+
end
|
127
|
+
|
128
|
+
def run_mode
|
129
|
+
_ensure_script_runner_frame { ScriptRunnerFrame.step_mode = false }
|
130
|
+
end
|
131
|
+
|
132
|
+
def show_backtrace(value = true)
|
133
|
+
_ensure_script_runner_frame { ScriptRunnerFrame.show_backtrace = value }
|
134
|
+
end
|
135
|
+
|
136
|
+
end # module Script
|
137
|
+
|
138
|
+
end # module Cosmos
|
@@ -109,7 +109,11 @@ module Cosmos
|
|
109
109
|
# @return [Boolean] Whether the stream attribute has been set and is
|
110
110
|
# connected
|
111
111
|
def connected?
|
112
|
-
|
112
|
+
if @stream
|
113
|
+
@stream.connected?
|
114
|
+
else
|
115
|
+
false
|
116
|
+
end
|
113
117
|
end
|
114
118
|
|
115
119
|
# Disconnects from the underlying {Stream} by calling {Stream#disconnect}.
|
@@ -133,7 +137,6 @@ module Cosmos
|
|
133
137
|
def read
|
134
138
|
# Loop until we have a packet to give
|
135
139
|
loop do
|
136
|
-
# Handle a sync pattern if present
|
137
140
|
result = handle_sync_pattern()
|
138
141
|
return nil unless result
|
139
142
|
|
@@ -267,20 +270,20 @@ module Cosmos
|
|
267
270
|
|
268
271
|
protected
|
269
272
|
|
273
|
+
# @return [Boolean] Whether we successfully found a sync pattern
|
270
274
|
def handle_sync_pattern
|
271
|
-
# Handle a sync pattern
|
272
275
|
if @sync_pattern
|
273
276
|
loop do
|
274
277
|
# Make sure we have some data to look for a sync word in
|
275
278
|
read_minimum_size(@sync_pattern.length)
|
276
|
-
return
|
279
|
+
return false if @data.length <= 0
|
277
280
|
|
278
|
-
# Find the sync pattern
|
281
|
+
# Find the beginning of the sync pattern
|
279
282
|
sync_index = @data.index(@sync_pattern.getbyte(0).chr)
|
280
283
|
if sync_index
|
281
284
|
# Make sure we have enough data for the whole sync pattern past this index
|
282
285
|
read_minimum_size(sync_index + @sync_pattern.length)
|
283
|
-
return
|
286
|
+
return false if @data.length <= 0
|
284
287
|
|
285
288
|
# Check for the rest of the sync pattern
|
286
289
|
found = true
|
data/lib/cosmos/system/target.rb
CHANGED
@@ -80,7 +80,17 @@ module Cosmos
|
|
80
80
|
# @param target_filename [String] Configuration file for the target. Normally
|
81
81
|
# target.txt
|
82
82
|
def initialize(target_name, substitute_name = nil, path = nil, target_filename = nil)
|
83
|
-
|
83
|
+
@requires = []
|
84
|
+
@ignored_parameters = []
|
85
|
+
@ignored_items = []
|
86
|
+
@cmd_tlm_files = []
|
87
|
+
@auto_screen_substitute = false
|
88
|
+
@interface = nil
|
89
|
+
@routers = []
|
90
|
+
@cmd_cnt = 0
|
91
|
+
@tlm_cnt = 0
|
92
|
+
|
93
|
+
# Determine the target name using substitution if given
|
84
94
|
@original_name = target_name.clone.upcase.freeze
|
85
95
|
if substitute_name
|
86
96
|
@substitute = true
|
@@ -89,38 +99,14 @@ module Cosmos
|
|
89
99
|
@substitute = false
|
90
100
|
@name = @original_name
|
91
101
|
end
|
92
|
-
@requires = []
|
93
|
-
@ignored_parameters = []
|
94
|
-
@ignored_items = []
|
95
|
-
@auto_screen_substitute = false
|
96
|
-
|
97
|
-
@dir = File.join(path, @original_name)
|
98
|
-
lib_dir = File.join(@dir, 'lib')
|
99
|
-
Cosmos.add_to_search_path(lib_dir, false) if File.exist?(lib_dir)
|
100
|
-
|
101
|
-
@cmd_tlm_files = []
|
102
|
-
@filename = File.join(@dir, target_filename || 'target.txt')
|
103
|
-
if File.exist?(@filename)
|
104
|
-
process_file(@filename)
|
105
|
-
else
|
106
|
-
raise "Target file #{target_filename} for target #{@name} does not exist" if target_filename
|
107
|
-
end
|
108
102
|
|
103
|
+
@dir = get_target_dir(path, @original_name)
|
104
|
+
# Parse the target.txt file if it exists
|
105
|
+
@filename = process_target_config_file(@dir, @name, target_filename)
|
106
|
+
# If target.txt didn't specify specific cmd/tlm files then add everything
|
109
107
|
if @cmd_tlm_files.empty?
|
110
|
-
|
111
|
-
Dir.foreach(File.join(@dir, 'cmd_tlm')) do |dir_filename|
|
112
|
-
if dir_filename[0] != '.'
|
113
|
-
@cmd_tlm_files << File.join(@dir, 'cmd_tlm', dir_filename)
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
@cmd_tlm_files.sort!
|
108
|
+
@cmd_tlm_files = add_all_cmd_tlm(@dir)
|
118
109
|
end
|
119
|
-
|
120
|
-
@interface = nil
|
121
|
-
@routers = []
|
122
|
-
@cmd_cnt = 0
|
123
|
-
@tlm_cnt = 0
|
124
110
|
end
|
125
111
|
|
126
112
|
# Parses the target configuration file
|
@@ -141,15 +127,11 @@ module Cosmos
|
|
141
127
|
end
|
142
128
|
@requires << parameters[0]
|
143
129
|
|
144
|
-
when 'IGNORE_PARAMETER'
|
145
|
-
usage = "#{keyword}
|
130
|
+
when 'IGNORE_PARAMETER', 'IGNORE_ITEM'
|
131
|
+
usage = "#{keyword} <#{keyword.split('_')[1]} NAME>"
|
146
132
|
parser.verify_num_parameters(1, 1, usage)
|
147
|
-
@ignored_parameters << parameters[0].upcase
|
148
|
-
|
149
|
-
when 'IGNORE_ITEM'
|
150
|
-
usage = "#{keyword} <ITEM NAME>"
|
151
|
-
parser.verify_num_parameters(1, 1, usage)
|
152
|
-
@ignored_items << parameters[0].upcase
|
133
|
+
@ignored_parameters << parameters[0].upcase if keyword.include?("PARAMETER")
|
134
|
+
@ignored_items << parameters[0].upcase if keyword.include?("ITEM")
|
153
135
|
|
154
136
|
when 'COMMANDS', 'TELEMETRY'
|
155
137
|
usage = "#{keyword} <FILENAME>"
|
@@ -170,6 +152,41 @@ module Cosmos
|
|
170
152
|
end
|
171
153
|
end
|
172
154
|
|
155
|
+
protected
|
156
|
+
|
157
|
+
# Get the target directory and add the target's lib folder to the
|
158
|
+
# search path if it exists
|
159
|
+
def get_target_dir(path, name)
|
160
|
+
path = File.join(USERPATH,'config','targets') unless path
|
161
|
+
dir = File.join(path, name)
|
162
|
+
lib_dir = File.join(dir, 'lib')
|
163
|
+
Cosmos.add_to_search_path(lib_dir, false) if File.exist?(lib_dir)
|
164
|
+
dir
|
165
|
+
end
|
166
|
+
|
167
|
+
# Process the target's configuration file if it exists
|
168
|
+
def process_target_config_file(dir, name, target_filename)
|
169
|
+
filename = File.join(dir, target_filename || 'target.txt')
|
170
|
+
if File.exist?(filename)
|
171
|
+
process_file(filename)
|
172
|
+
else
|
173
|
+
raise "Target file #{target_filename} for target #{name} does not exist" if target_filename
|
174
|
+
end
|
175
|
+
filename
|
176
|
+
end
|
177
|
+
|
178
|
+
# Automatically add all command and telemetry definitions to the list
|
179
|
+
def add_all_cmd_tlm(dir)
|
180
|
+
cmd_tlm_files = []
|
181
|
+
if Dir.exist?(File.join(dir, 'cmd_tlm'))
|
182
|
+
# Only grab *.txt files in the root of the cmd_tlm folder
|
183
|
+
Dir[File.join(dir, 'cmd_tlm', '*.txt')].each do |filename|
|
184
|
+
cmd_tlm_files << filename
|
185
|
+
end
|
186
|
+
end
|
187
|
+
cmd_tlm_files.sort!
|
188
|
+
end
|
189
|
+
|
173
190
|
end # class Target
|
174
191
|
|
175
192
|
end # module Cosmos
|