cosmos 3.8.2 → 3.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Manifest.txt +5 -5
- data/Rakefile +8 -2
- data/autohotkey/tools/autohotkey.rb +3 -3
- data/data/crc.txt +27 -27
- data/demo/Launcher.bat +3 -3
- data/demo/config/data/crc.txt +27 -27
- data/demo/{procedures → config/targets/INST/procedures}/checks.rb +0 -0
- data/demo/{procedures → config/targets/INST/procedures}/collect.rb +2 -2
- data/demo/{procedures → config/targets/INST/procedures}/disconnect.rb +0 -0
- data/demo/{procedures/clear_util.rb → config/targets/INST/procedures/utilities/clear.rb} +0 -0
- data/demo/{procedures/collect_util.rb → config/targets/INST/procedures/utilities/collect.rb} +2 -2
- data/demo/config/targets/INST/screens/commanding.txt +3 -3
- data/demo/config/tools/table_manager/ExampleTableDefinition.txt +7 -7
- data/demo/procedures/plot_test.rb +1 -1
- data/demo/tools/CmdExtractor.bat +3 -3
- data/demo/tools/CmdSender.bat +3 -3
- data/demo/tools/CmdTlmServer.bat +3 -3
- data/demo/tools/DataViewer.bat +3 -3
- data/demo/tools/ExampleTarget.bat +3 -3
- data/demo/tools/HandbookCreator.bat +3 -3
- data/demo/tools/Launcher.bat +3 -3
- data/demo/tools/LimitsMonitor.bat +3 -3
- data/demo/tools/OpenGLBuilder.bat +3 -3
- data/demo/tools/PacketViewer.bat +3 -3
- data/demo/tools/Replay.bat +3 -3
- data/demo/tools/ScpiTarget.bat +3 -3
- data/demo/tools/ScriptRunner.bat +3 -3
- data/demo/tools/TableManager.bat +3 -3
- data/demo/tools/TestRunner.bat +3 -3
- data/demo/tools/TlmExtractor.bat +3 -3
- data/demo/tools/TlmGrapher.bat +3 -3
- data/demo/tools/TlmViewer.bat +3 -3
- data/demo/tools/ToolLaunch.bat +3 -6
- data/ext/cosmos/ext/packet/packet.c +10 -0
- data/install/config/data/crc.txt +17 -17
- data/install/tools/CmdExtractor.bat +3 -3
- data/install/tools/CmdSender.bat +3 -3
- data/install/tools/CmdTlmServer.bat +3 -3
- data/install/tools/DataViewer.bat +3 -3
- data/install/tools/HandbookCreator.bat +3 -3
- data/install/tools/Launcher.bat +3 -3
- data/install/tools/LimitsMonitor.bat +3 -3
- data/install/tools/OpenGLBuilder.bat +3 -3
- data/install/tools/PacketViewer.bat +3 -3
- data/install/tools/Replay.bat +3 -3
- data/install/tools/ScriptRunner.bat +3 -3
- data/install/tools/TableManager.bat +3 -3
- data/install/tools/TestRunner.bat +3 -3
- data/install/tools/TlmExtractor.bat +3 -3
- data/install/tools/TlmGrapher.bat +3 -3
- data/install/tools/TlmViewer.bat +3 -3
- data/install/tools/ToolLaunch.bat +3 -6
- data/lib/cosmos/config/config_parser.rb +10 -2
- data/lib/cosmos/gui/qt_tool.rb +6 -0
- data/lib/cosmos/gui/utilities/screenshot.rb +8 -0
- data/lib/cosmos/gui/utilities/script_module_gui.rb +37 -11
- data/lib/cosmos/interfaces/cmd_tlm_server_interface.rb +3 -3
- data/lib/cosmos/interfaces/udp_interface.rb +9 -2
- data/lib/cosmos/packet_logs/packet_log_reader.rb +1 -0
- data/lib/cosmos/packets/commands.rb +70 -74
- data/lib/cosmos/packets/packet.rb +14 -7
- data/lib/cosmos/script/scripting.rb +9 -7
- data/lib/cosmos/system/system.rb +4 -0
- data/lib/cosmos/system/target.rb +2 -0
- data/lib/cosmos/tools/cmd_tlm_server/api.rb +10 -10
- data/lib/cosmos/tools/cmd_tlm_server/gui/interfaces_tab.rb +2 -2
- data/lib/cosmos/tools/cmd_tlm_server/interface_thread.rb +1 -1
- data/lib/cosmos/tools/packet_viewer/packet_viewer.rb +5 -15
- data/lib/cosmos/tools/script_runner/script_runner.rb +40 -21
- data/lib/cosmos/tools/table_manager/table.rb +2 -2
- data/lib/cosmos/tools/table_manager/table_config.rb +18 -10
- data/lib/cosmos/tools/table_manager/table_manager.rb +61 -59
- data/lib/cosmos/tools/table_manager/table_manager_core.rb +24 -56
- data/lib/cosmos/tools/test_runner/test_runner.rb +15 -10
- data/lib/cosmos/tools/tlm_viewer/widgets/checkbutton_widget.rb +9 -2
- data/lib/cosmos/tools/tlm_viewer/widgets/combobox_widget.rb +1 -1
- data/lib/cosmos/tools/tlm_viewer/widgets/radiobutton_widget.rb +9 -1
- data/lib/cosmos/top_level.rb +5 -5
- data/lib/cosmos/version.rb +4 -4
- data/spec/config/config_parser_spec.rb +40 -2
- data/spec/packet_logs/packet_log_reader_spec.rb +66 -2
- data/spec/packets/packet_spec.rb +27 -0
- data/spec/script/scripting_spec.rb +7 -2
- data/spec/spec_helper.rb +4 -5
- data/spec/system/system_spec.rb +18 -0
- metadata +7 -7
@@ -1,9 +1,9 @@
|
|
1
1
|
@ECHO OFF
|
2
2
|
|
3
|
-
IF NOT EXIST %~dp0ToolLaunch.bat (
|
4
|
-
echo %~dp0ToolLaunch.bat does not exist
|
3
|
+
IF NOT EXIST "%~dp0ToolLaunch.bat" (
|
4
|
+
echo "%~dp0ToolLaunch.bat" does not exist
|
5
5
|
pause
|
6
6
|
exit /b
|
7
7
|
)
|
8
8
|
|
9
|
-
call %~dp0ToolLaunch.bat rubyw.exe %~n0 %*
|
9
|
+
call "%~dp0ToolLaunch.bat" rubyw.exe %~n0 %*
|
@@ -1,9 +1,9 @@
|
|
1
1
|
@ECHO OFF
|
2
2
|
|
3
|
-
IF NOT EXIST %~dp0ToolLaunch.bat (
|
4
|
-
echo %~dp0ToolLaunch.bat does not exist
|
3
|
+
IF NOT EXIST "%~dp0ToolLaunch.bat" (
|
4
|
+
echo "%~dp0ToolLaunch.bat" does not exist
|
5
5
|
pause
|
6
6
|
exit /b
|
7
7
|
)
|
8
8
|
|
9
|
-
call %~dp0ToolLaunch.bat rubyw.exe %~n0 %*
|
9
|
+
call "%~dp0ToolLaunch.bat" rubyw.exe %~n0 %*
|
data/install/tools/Replay.bat
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
@ECHO OFF
|
2
2
|
|
3
|
-
IF NOT EXIST %~dp0ToolLaunch.bat (
|
4
|
-
echo %~dp0ToolLaunch.bat does not exist
|
3
|
+
IF NOT EXIST "%~dp0ToolLaunch.bat" (
|
4
|
+
echo "%~dp0ToolLaunch.bat" does not exist
|
5
5
|
pause
|
6
6
|
exit /b
|
7
7
|
)
|
8
8
|
|
9
|
-
call %~dp0ToolLaunch.bat rubyw.exe %~n0 %*
|
9
|
+
call "%~dp0ToolLaunch.bat" rubyw.exe %~n0 %*
|
@@ -1,9 +1,9 @@
|
|
1
1
|
@ECHO OFF
|
2
2
|
|
3
|
-
IF NOT EXIST %~dp0ToolLaunch.bat (
|
4
|
-
echo %~dp0ToolLaunch.bat does not exist
|
3
|
+
IF NOT EXIST "%~dp0ToolLaunch.bat" (
|
4
|
+
echo "%~dp0ToolLaunch.bat" does not exist
|
5
5
|
pause
|
6
6
|
exit /b
|
7
7
|
)
|
8
8
|
|
9
|
-
call %~dp0ToolLaunch.bat rubyw.exe %~n0 %*
|
9
|
+
call "%~dp0ToolLaunch.bat" rubyw.exe %~n0 %*
|
@@ -1,9 +1,9 @@
|
|
1
1
|
@ECHO OFF
|
2
2
|
|
3
|
-
IF NOT EXIST %~dp0ToolLaunch.bat (
|
4
|
-
echo %~dp0ToolLaunch.bat does not exist
|
3
|
+
IF NOT EXIST "%~dp0ToolLaunch.bat" (
|
4
|
+
echo "%~dp0ToolLaunch.bat" does not exist
|
5
5
|
pause
|
6
6
|
exit /b
|
7
7
|
)
|
8
8
|
|
9
|
-
call %~dp0ToolLaunch.bat rubyw.exe %~n0 %*
|
9
|
+
call "%~dp0ToolLaunch.bat" rubyw.exe %~n0 %*
|
@@ -1,9 +1,9 @@
|
|
1
1
|
@ECHO OFF
|
2
2
|
|
3
|
-
IF NOT EXIST %~dp0ToolLaunch.bat (
|
4
|
-
echo %~dp0ToolLaunch.bat does not exist
|
3
|
+
IF NOT EXIST "%~dp0ToolLaunch.bat" (
|
4
|
+
echo "%~dp0ToolLaunch.bat" does not exist
|
5
5
|
pause
|
6
6
|
exit /b
|
7
7
|
)
|
8
8
|
|
9
|
-
call %~dp0ToolLaunch.bat rubyw.exe %~n0 %*
|
9
|
+
call "%~dp0ToolLaunch.bat" rubyw.exe %~n0 %*
|
@@ -1,9 +1,9 @@
|
|
1
1
|
@ECHO OFF
|
2
2
|
|
3
|
-
IF NOT EXIST %~dp0ToolLaunch.bat (
|
4
|
-
echo %~dp0ToolLaunch.bat does not exist
|
3
|
+
IF NOT EXIST "%~dp0ToolLaunch.bat" (
|
4
|
+
echo "%~dp0ToolLaunch.bat" does not exist
|
5
5
|
pause
|
6
6
|
exit /b
|
7
7
|
)
|
8
8
|
|
9
|
-
call %~dp0ToolLaunch.bat rubyw.exe %~n0 %*
|
9
|
+
call "%~dp0ToolLaunch.bat" rubyw.exe %~n0 %*
|
@@ -1,9 +1,9 @@
|
|
1
1
|
@ECHO OFF
|
2
2
|
|
3
|
-
IF NOT EXIST %~dp0ToolLaunch.bat (
|
4
|
-
echo %~dp0ToolLaunch.bat does not exist
|
3
|
+
IF NOT EXIST "%~dp0ToolLaunch.bat" (
|
4
|
+
echo "%~dp0ToolLaunch.bat" does not exist
|
5
5
|
pause
|
6
6
|
exit /b
|
7
7
|
)
|
8
8
|
|
9
|
-
call %~dp0ToolLaunch.bat rubyw.exe %~n0 %*
|
9
|
+
call "%~dp0ToolLaunch.bat" rubyw.exe %~n0 %*
|
data/install/tools/TlmViewer.bat
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
@ECHO OFF
|
2
2
|
|
3
|
-
IF NOT EXIST %~dp0ToolLaunch.bat (
|
4
|
-
echo %~dp0ToolLaunch.bat does not exist
|
3
|
+
IF NOT EXIST "%~dp0ToolLaunch.bat" (
|
4
|
+
echo "%~dp0ToolLaunch.bat" does not exist
|
5
5
|
pause
|
6
6
|
exit /b
|
7
7
|
)
|
8
8
|
|
9
|
-
call %~dp0ToolLaunch.bat rubyw.exe %~n0 %*
|
9
|
+
call "%~dp0ToolLaunch.bat" rubyw.exe %~n0 %*
|
@@ -10,8 +10,8 @@ IF NOT EXIST !TOOL! (
|
|
10
10
|
exit /b
|
11
11
|
)
|
12
12
|
|
13
|
-
IF NOT EXIST %~dp0tool_launch.rb (
|
14
|
-
echo %~dp0tool_launch.rb does not exist
|
13
|
+
IF NOT EXIST "%~dp0tool_launch.rb" (
|
14
|
+
echo "%~dp0tool_launch.rb" does not exist
|
15
15
|
pause
|
16
16
|
exit /b
|
17
17
|
)
|
@@ -42,11 +42,9 @@ goto loop
|
|
42
42
|
|
43
43
|
IF EXIST "!DESTINATION_DIR!Vendor\Ruby" (
|
44
44
|
:: Convert DESTINATION_DIR to absolute path
|
45
|
-
echo !DESTINATION_DIR!
|
46
45
|
pushd !DESTINATION_DIR!
|
47
46
|
SET "DESTINATION_DIR=!CD!\"
|
48
47
|
popd
|
49
|
-
echo !DESTINATION_DIR!
|
50
48
|
|
51
49
|
:: Set environmental variables
|
52
50
|
for /f "delims=" %%a in ('dir "!DESTINATION_DIR!Vendor\Ruby\lib\ruby\gems\2*" /on /ad /b') do set RUBY_ABI=%%a
|
@@ -63,8 +61,7 @@ IF EXIST "!DESTINATION_DIR!Vendor\Ruby" (
|
|
63
61
|
SET RUBYLIB=
|
64
62
|
|
65
63
|
:: Run tool using Installer Ruby
|
66
|
-
ECHO !
|
67
|
-
ECHO Starting tool using installer ruby in !DESTINATION_DIR!
|
64
|
+
ECHO Starting tool using installer ruby in "!DESTINATION_DIR!"
|
68
65
|
START "COSMOS" "!DESTINATION_DIR!Vendor\Ruby\bin\!RUBYEXE!" "!TOOL!" !PARAMS!
|
69
66
|
) else (
|
70
67
|
:: Use System Ruby and Environment
|
@@ -149,8 +149,16 @@ module Cosmos
|
|
149
149
|
def render(template_name, options = {})
|
150
150
|
b = binding
|
151
151
|
if options[:locals]
|
152
|
-
|
153
|
-
|
152
|
+
if RUBY_VERSION.split('.')[0..1].join.to_i >= 21
|
153
|
+
options[:locals].each {|key, value| b.local_variable_set(key, value) }
|
154
|
+
else
|
155
|
+
options[:locals].each do |key, value|
|
156
|
+
if value.is_a? String
|
157
|
+
b.eval("#{key} = '#{value}'")
|
158
|
+
else
|
159
|
+
b.eval("#{key} = #{value}")
|
160
|
+
end
|
161
|
+
end
|
154
162
|
end
|
155
163
|
end
|
156
164
|
# Assume the file is there. If not we raise a pretty obvious error
|
data/lib/cosmos/gui/qt_tool.rb
CHANGED
@@ -62,6 +62,11 @@ module Cosmos
|
|
62
62
|
@about_action = Qt::Action.new(Cosmos.get_icon('help.png'), tr('&About'), self)
|
63
63
|
@about_action.statusTip = tr('About the application')
|
64
64
|
connect(@about_action, SIGNAL('triggered()'), self, SLOT('about()'))
|
65
|
+
@documentation_action = Qt::Action.new(tr('&Documentation'), self)
|
66
|
+
@documentation_action.statusTip = tr('COSMOS Online Documentation')
|
67
|
+
self.connect(@documentation_action, SIGNAL('triggered()')) do
|
68
|
+
Qt::DesktopServices.openUrl(Qt::Url.new("http://cosmosrb.com"))
|
69
|
+
end
|
65
70
|
end
|
66
71
|
|
67
72
|
# Creates the Help menu and adds the @about_action to it. Thus this MUST be
|
@@ -69,6 +74,7 @@ module Cosmos
|
|
69
74
|
def initialize_help_menu
|
70
75
|
@help_menu = menuBar().addMenu(tr('&Help'))
|
71
76
|
@help_menu.addAction(@about_action)
|
77
|
+
@help_menu.addAction(@documentation_action)
|
72
78
|
end
|
73
79
|
|
74
80
|
# This should be called after the tool has been completely laid out and all
|
@@ -15,6 +15,14 @@ module Cosmos
|
|
15
15
|
|
16
16
|
# Take a screenshot of the given window
|
17
17
|
def self.screenshot_window (window, filename)
|
18
|
+
if !Kernel.is_windows?()
|
19
|
+
# Delay for one second to allow any dialogs to fully clear first
|
20
|
+
start_time = Time.now
|
21
|
+
while ((Time.now - start_time) < 1.0)
|
22
|
+
Qt::CoreApplication.processEvents(Qt::EventLoop::AllEvents, 1000)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
18
26
|
# Create a Pixmap to save the screenshot into
|
19
27
|
pixmap = Qt::Pixmap::grabWindow(window.winId())
|
20
28
|
pixmap.save(filename)
|
@@ -194,8 +194,14 @@ module Cosmos
|
|
194
194
|
msg = Qt::MessageBox.new(window)
|
195
195
|
msg.setText(string)
|
196
196
|
msg.setWindowTitle("Message Box")
|
197
|
-
|
198
|
-
|
197
|
+
# Check if the last parameter is false which means they don't want
|
198
|
+
# the Cancel button to be displayed
|
199
|
+
if buttons[-1] == false
|
200
|
+
buttons[0..-2].each {|text| msg.addButton(text, Qt::MessageBox::AcceptRole)}
|
201
|
+
else
|
202
|
+
buttons.each {|text| msg.addButton(text, Qt::MessageBox::AcceptRole)}
|
203
|
+
msg.addButton("Cancel", Qt::MessageBox::RejectRole)
|
204
|
+
end
|
199
205
|
msg.exec()
|
200
206
|
if msg.clickedButton.text == "Cancel"
|
201
207
|
Logger.warn "User pressed 'Cancel' for '#{string}'"
|
@@ -219,9 +225,18 @@ module Cosmos
|
|
219
225
|
Qt.execute_in_main_thread(true, 0.05) do
|
220
226
|
dialog = _build_dialog(string)
|
221
227
|
|
228
|
+
# Check if the last parameter is false which means they don't want
|
229
|
+
# the Cancel button to be displayed
|
230
|
+
if buttons[-1] == false
|
231
|
+
cancel = false
|
232
|
+
display_buttons = buttons[0..-2]
|
233
|
+
else
|
234
|
+
cancel = true
|
235
|
+
display_buttons = buttons
|
236
|
+
end
|
222
237
|
button_layout = Qt::VBoxLayout.new
|
223
238
|
button_layout.setContentsMargins(11,11,11,11)
|
224
|
-
|
239
|
+
display_buttons.each do |button_text|
|
225
240
|
button = Qt::PushButton.new(button_text)
|
226
241
|
button.connect(SIGNAL('clicked()')) do
|
227
242
|
result = button_text
|
@@ -230,7 +245,7 @@ module Cosmos
|
|
230
245
|
button_layout.addWidget(button)
|
231
246
|
end
|
232
247
|
dialog.layout.addLayout(button_layout)
|
233
|
-
dialog.layout.addWidget(_build_dialog_buttons(dialog, false))
|
248
|
+
dialog.layout.addWidget(_build_dialog_buttons(dialog, false, cancel))
|
234
249
|
result = "Cancel" unless _exec_dialog(dialog, string, result)
|
235
250
|
end
|
236
251
|
if result == "Cancel"
|
@@ -246,11 +261,20 @@ module Cosmos
|
|
246
261
|
result = options[0]
|
247
262
|
Qt.execute_in_main_thread(true, 0.05) do
|
248
263
|
dialog = _build_dialog(string)
|
249
|
-
|
264
|
+
# Check if the last parameter is false which means they don't want
|
265
|
+
# the Cancel button to be displayed
|
266
|
+
if options[-1] == false
|
267
|
+
cancel = false
|
268
|
+
display_options = options[0..-2]
|
269
|
+
else
|
270
|
+
cancel = true
|
271
|
+
display_options = options
|
272
|
+
end
|
273
|
+
chooser = ComboboxChooser.new(dialog, "Select:", display_options)
|
250
274
|
chooser.setContentsMargins(11,11,11,11)
|
251
275
|
chooser.sel_command_callback = lambda { |value| result = value }
|
252
276
|
dialog.layout.addWidget(chooser)
|
253
|
-
dialog.layout.addWidget(_build_dialog_buttons(dialog))
|
277
|
+
dialog.layout.addWidget(_build_dialog_buttons(dialog, true, cancel))
|
254
278
|
result = "Cancel" unless _exec_dialog(dialog, string, result)
|
255
279
|
end
|
256
280
|
if result == "Cancel"
|
@@ -287,7 +311,7 @@ module Cosmos
|
|
287
311
|
result
|
288
312
|
end
|
289
313
|
|
290
|
-
def _build_dialog_buttons(dialog, ok_button = true)
|
314
|
+
def _build_dialog_buttons(dialog, ok_button = true, cancel_button = true)
|
291
315
|
button_layout = Qt::HBoxLayout.new
|
292
316
|
if ok_button
|
293
317
|
ok = Qt::PushButton.new("Ok")
|
@@ -296,11 +320,13 @@ module Cosmos
|
|
296
320
|
end
|
297
321
|
button_layout.addWidget(ok)
|
298
322
|
end
|
299
|
-
|
300
|
-
|
301
|
-
|
323
|
+
if cancel_button
|
324
|
+
cancel = Qt::PushButton.new("Cancel")
|
325
|
+
cancel.connect(SIGNAL('clicked()')) do
|
326
|
+
dialog.reject()
|
327
|
+
end
|
328
|
+
button_layout.addWidget(cancel)
|
302
329
|
end
|
303
|
-
button_layout.addWidget(cancel)
|
304
330
|
|
305
331
|
widget = Qt::Widget.new
|
306
332
|
widget.setLayout(button_layout)
|
@@ -59,7 +59,7 @@ module Cosmos
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
-
while
|
62
|
+
while connected?
|
63
63
|
begin
|
64
64
|
event = CmdTlmServer.instance.get_limits_event(@limit_id)
|
65
65
|
if event
|
@@ -89,8 +89,8 @@ module Cosmos
|
|
89
89
|
break
|
90
90
|
end
|
91
91
|
end
|
92
|
-
|
93
|
-
|
92
|
+
|
93
|
+
return nil
|
94
94
|
end
|
95
95
|
|
96
96
|
# Write a packet to the CmdTlmServer to change various settings.
|
@@ -79,6 +79,7 @@ module Cosmos
|
|
79
79
|
@ttl,
|
80
80
|
@bind_address) if @write_dest_port
|
81
81
|
@read_socket = UdpReadSocket.new(@read_port, @hostname, @interface_address, @bind_address) if @read_port
|
82
|
+
@thread_sleeper = nil
|
82
83
|
end
|
83
84
|
|
84
85
|
# @return [Boolean] Whether the active ports (read and/or write) have
|
@@ -100,6 +101,8 @@ module Cosmos
|
|
100
101
|
@write_socket = nil
|
101
102
|
Cosmos.close_socket(@read_socket)
|
102
103
|
@read_socket = nil
|
104
|
+
@thread_sleeper.cancel if @thread_sleeper
|
105
|
+
@thread_sleeper = nil
|
103
106
|
end
|
104
107
|
|
105
108
|
# If the read port was given, the read_socket is read and the data returned
|
@@ -113,7 +116,7 @@ module Cosmos
|
|
113
116
|
@raw_logger_pair.read_logger.write(data) if @raw_logger_pair
|
114
117
|
rescue IOError
|
115
118
|
# Disconnected
|
116
|
-
|
119
|
+
return nil
|
117
120
|
end
|
118
121
|
|
119
122
|
@bytes_read += data.length
|
@@ -122,7 +125,11 @@ module Cosmos
|
|
122
125
|
return Packet.new(nil, nil, :BIG_ENDIAN, nil, data)
|
123
126
|
else
|
124
127
|
# Write only interface so stop the thread which calls read
|
125
|
-
|
128
|
+
@thread_sleeper = Sleeper.new
|
129
|
+
while connected?()
|
130
|
+
@thread_sleeper.sleep(1000000)
|
131
|
+
end
|
132
|
+
return nil
|
126
133
|
end
|
127
134
|
end
|
128
135
|
|
@@ -125,7 +125,9 @@ module Cosmos
|
|
125
125
|
# @param range_checking [Boolean] Whether to perform range checking on the
|
126
126
|
# passed in parameters.
|
127
127
|
# @param raw [Boolean] Indicates whether or not to run conversions on command parameters
|
128
|
-
|
128
|
+
# @param check_required_params [Boolean] Indicates whether or not to check
|
129
|
+
# that the required command parameters are present
|
130
|
+
def build_cmd(target_name, packet_name, params = {}, range_checking = true, raw = false, check_required_params = true)
|
129
131
|
target_upcase = target_name.to_s.upcase
|
130
132
|
packet_upcase = packet_name.to_s.upcase
|
131
133
|
|
@@ -135,50 +137,11 @@ module Cosmos
|
|
135
137
|
# Set time, parameters, and restore defaults
|
136
138
|
command.received_time = Time.now
|
137
139
|
command.given_values = params
|
138
|
-
command.restore_defaults
|
140
|
+
command.restore_defaults(command.buffer(false), params.keys)
|
139
141
|
command.raw = raw
|
140
142
|
|
141
|
-
|
142
|
-
given_item_names
|
143
|
-
params.each do |item_name, value|
|
144
|
-
item_upcase = item_name.to_s.upcase
|
145
|
-
item = command.get_item(item_upcase)
|
146
|
-
range_check_value = value
|
147
|
-
|
148
|
-
# Convert from state to value if possible
|
149
|
-
if item.states and item.states[value.to_s.upcase]
|
150
|
-
range_check_value = item.states[value.to_s.upcase]
|
151
|
-
end
|
152
|
-
|
153
|
-
if range_checking
|
154
|
-
range = item.range
|
155
|
-
if range
|
156
|
-
# Perform Range Check on command parameter
|
157
|
-
if not range.include?(range_check_value)
|
158
|
-
range_check_value = "'#{range_check_value}'" if String === range_check_value
|
159
|
-
raise "Command parameter '#{target_upcase} #{packet_upcase} #{item_upcase}' = #{range_check_value} not in valid range of #{range.first} to #{range.last}"
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
# Update parameter in command
|
165
|
-
if raw
|
166
|
-
command.write(item_upcase, value, :RAW)
|
167
|
-
else
|
168
|
-
command.write(item_upcase, value, :CONVERTED)
|
169
|
-
end
|
170
|
-
|
171
|
-
given_item_names << item_upcase
|
172
|
-
end # cmd_params.each
|
173
|
-
|
174
|
-
# Script Runner could call this command with only some parameters
|
175
|
-
# so make sure any required parameters were actually passed in.
|
176
|
-
item_defs = command.items
|
177
|
-
item_defs.each do |item_name, item_def|
|
178
|
-
if item_def.required and not given_item_names.include? item_name
|
179
|
-
raise "Required command parameter '#{target_upcase} #{packet_upcase} #{item_name}' not given"
|
180
|
-
end
|
181
|
-
end
|
143
|
+
given_item_names = set_parameters(command, params, range_checking)
|
144
|
+
check_required_params(command, given_item_names) if check_required_params
|
182
145
|
|
183
146
|
return command
|
184
147
|
end
|
@@ -227,39 +190,10 @@ module Cosmos
|
|
227
190
|
# are set. Thus any given parameter values are first applied to the command
|
228
191
|
# and then checked for hazardous states.
|
229
192
|
#
|
230
|
-
# @param
|
231
|
-
|
232
|
-
# @param params (see #build_cmd)
|
233
|
-
def cmd_hazardous?(target_name, packet_name, params = {})
|
234
|
-
target_upcase = target_name.to_s.upcase
|
235
|
-
packet_upcase = packet_name.to_s.upcase
|
236
|
-
|
237
|
-
# Lookup the command
|
238
|
-
command = packet(target_upcase, packet_upcase)
|
239
|
-
|
240
|
-
# Overall command hazardous check
|
193
|
+
# @param command [Packet] The command to check for hazardous
|
194
|
+
def cmd_pkt_hazardous?(command)
|
241
195
|
return [true, command.hazardous_description] if command.hazardous
|
242
196
|
|
243
|
-
# Create a light weight copy of command
|
244
|
-
command = command.clone()
|
245
|
-
# Set given command parameters and restore defaults
|
246
|
-
command.given_values = params
|
247
|
-
command.restore_defaults()
|
248
|
-
|
249
|
-
# Set any parameters
|
250
|
-
params.each do |item_name, value|
|
251
|
-
item_upcase = item_name.to_s.upcase
|
252
|
-
item = command.get_item(item_upcase)
|
253
|
-
|
254
|
-
if item.states
|
255
|
-
state_value = item.states[value.to_s.upcase]
|
256
|
-
value = state_value if state_value
|
257
|
-
end
|
258
|
-
|
259
|
-
# Update parameter in command
|
260
|
-
command.write(item_upcase, value)
|
261
|
-
end
|
262
|
-
|
263
197
|
# Check each item for hazardous states
|
264
198
|
item_defs = command.items
|
265
199
|
item_defs.each do |item_name, item_def|
|
@@ -276,6 +210,20 @@ module Cosmos
|
|
276
210
|
return [false, nil]
|
277
211
|
end
|
278
212
|
|
213
|
+
# Returns whether the given command is hazardous. Commands are hazardous
|
214
|
+
# if they are marked hazardous overall or if any of their hardardous states
|
215
|
+
# are set. Thus any given parameter values are first applied to the command
|
216
|
+
# and then checked for hazardous states.
|
217
|
+
#
|
218
|
+
# @param target_name (see #packet)
|
219
|
+
# @param packet_name (see #packet)
|
220
|
+
# @param params (see #build_cmd)
|
221
|
+
def cmd_hazardous?(target_name, packet_name, params = {})
|
222
|
+
# Build a command without range checking, perform conversions, and don't
|
223
|
+
# check required parameters since we're not actually using the command.
|
224
|
+
cmd_pkt_hazardous?(build_cmd(target_name, packet_name, params, false, false, false))
|
225
|
+
end
|
226
|
+
|
279
227
|
def clear_counters
|
280
228
|
@config.commands.each do |target_name, target_packets|
|
281
229
|
target_packets.each do |packet_name, packet|
|
@@ -288,6 +236,54 @@ module Cosmos
|
|
288
236
|
@config.commands
|
289
237
|
end
|
290
238
|
|
239
|
+
protected
|
240
|
+
|
241
|
+
def set_parameters(command, params, range_checking)
|
242
|
+
given_item_names = []
|
243
|
+
params.each do |item_name, value|
|
244
|
+
item_upcase = item_name.to_s.upcase
|
245
|
+
item = command.get_item(item_upcase)
|
246
|
+
range_check_value = value
|
247
|
+
|
248
|
+
# Convert from state to value if possible
|
249
|
+
if item.states and item.states[value.to_s.upcase]
|
250
|
+
range_check_value = item.states[value.to_s.upcase]
|
251
|
+
end
|
252
|
+
|
253
|
+
if range_checking
|
254
|
+
range = item.range
|
255
|
+
if range
|
256
|
+
# Perform Range Check on command parameter
|
257
|
+
if not range.include?(range_check_value)
|
258
|
+
range_check_value = "'#{range_check_value}'" if String === range_check_value
|
259
|
+
raise "Command parameter '#{command.target_name} #{command.packet_name} #{item_upcase}' = #{range_check_value} not in valid range of #{range.first} to #{range.last}"
|
260
|
+
end
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
# Update parameter in command
|
265
|
+
if command.raw
|
266
|
+
command.write(item_upcase, value, :RAW)
|
267
|
+
else
|
268
|
+
command.write(item_upcase, value, :CONVERTED)
|
269
|
+
end
|
270
|
+
|
271
|
+
given_item_names << item_upcase
|
272
|
+
end
|
273
|
+
given_item_names
|
274
|
+
end
|
275
|
+
|
276
|
+
def check_required_params(command, given_item_names)
|
277
|
+
# Script Runner could call this command with only some parameters
|
278
|
+
# so make sure any required parameters were actually passed in.
|
279
|
+
item_defs = command.items
|
280
|
+
item_defs.each do |item_name, item_def|
|
281
|
+
if item_def.required and not given_item_names.include? item_name
|
282
|
+
raise "Required command parameter '#{command.target_name} #{command.packet_name} #{item_name}' not given"
|
283
|
+
end
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
291
287
|
end # class Commands
|
292
288
|
|
293
289
|
end # module Cosmos
|