cosmos 3.3.3 → 3.4.0

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.
Files changed (109) hide show
  1. checksums.yaml +4 -4
  2. data/.gitattributes +2 -0
  3. data/.travis.yml +2 -1
  4. data/Gemfile +4 -3
  5. data/Manifest.txt +22 -0
  6. data/autohotkey/tools/handbook_creator.ahk +9 -0
  7. data/autohotkey/tools/packet_viewer.ahk +4 -0
  8. data/bin/exchndl20-x64.dll +0 -0
  9. data/bin/exchndl20.dll +0 -0
  10. data/bin/exchndl21-x64.dll +0 -0
  11. data/bin/exchndl21.dll +0 -0
  12. data/bin/exchndl22-x64.dll +0 -0
  13. data/bin/exchndl22.dll +0 -0
  14. data/bin/mgwhelp-x64.dll +0 -0
  15. data/bin/mgwhelp.dll +0 -0
  16. data/cosmos.gemspec +1 -0
  17. data/data/crc.txt +30 -24
  18. data/demo/config/data/crc.txt +3 -3
  19. data/demo/config/tools/handbook_creator/templates/command_packets.html.erb +3 -1
  20. data/demo/config/tools/handbook_creator/templates/telemetry_packets.html.erb +3 -1
  21. data/demo/procedures/cosmos_api_test.rb +1 -1
  22. data/ext/cosmos/ext/low_fragmentation_array/low_fragmentation_array.c +4 -0
  23. data/ext/cosmos/ext/platform/platform.c +22 -2
  24. data/ext/cosmos/ext/structure/structure.c +631 -104
  25. data/ext/cosmos/ext/telemetry/telemetry.c +3 -2
  26. data/lib/cosmos/gui/line_graph/line_graph_drawing.rb +71 -92
  27. data/lib/cosmos/gui/line_graph/overview_graph.rb +1 -1
  28. data/lib/cosmos/gui/qt.rb +38 -24
  29. data/lib/cosmos/gui/text/ruby_editor.rb +1 -1
  30. data/lib/cosmos/packets/binary_accessor.rb +1 -288
  31. data/lib/cosmos/packets/telemetry.rb +2 -1
  32. data/lib/cosmos/script/cmd_tlm_server.rb +110 -0
  33. data/lib/cosmos/script/commands.rb +166 -0
  34. data/lib/cosmos/script/extract.rb +2 -2
  35. data/lib/cosmos/script/limits.rb +108 -0
  36. data/lib/cosmos/script/script.rb +28 -1487
  37. data/lib/cosmos/script/scripting.rb +889 -0
  38. data/lib/cosmos/script/telemetry.rb +174 -0
  39. data/lib/cosmos/script/tools.rb +138 -0
  40. data/lib/cosmos/streams/stream_protocol.rb +9 -6
  41. data/lib/cosmos/system/target.rb +55 -38
  42. data/lib/cosmos/tools/cmd_tlm_server/api.rb +6 -3
  43. data/lib/cosmos/tools/cmd_tlm_server/connections.rb +0 -1
  44. data/lib/cosmos/tools/cmd_tlm_server/gui/interfaces_tab.rb +17 -7
  45. data/lib/cosmos/tools/cmd_tlm_server/interface_thread.rb +15 -4
  46. data/lib/cosmos/tools/handbook_creator/handbook_creator.rb +15 -8
  47. data/lib/cosmos/tools/handbook_creator/handbook_creator_config.rb +41 -13
  48. data/lib/cosmos/tools/packet_viewer/packet_viewer.rb +18 -1
  49. data/lib/cosmos/tools/tlm_viewer/widgets/canvasline_widget.rb +1 -1
  50. data/lib/cosmos/tools/tlm_viewer/widgets/canvaslinevalue_widget.rb +1 -1
  51. data/lib/cosmos/tools/tlm_viewer/widgets/limitsbar_widget.rb +1 -1
  52. data/lib/cosmos/tools/tlm_viewer/widgets/rangebar_widget.rb +1 -1
  53. data/lib/cosmos/top_level.rb +1 -1
  54. data/lib/cosmos/utilities/ruby_lex_utils.rb +1 -1
  55. data/lib/cosmos/version.rb +5 -5
  56. data/spec/gui/line_graph/line_clip_spec.rb +6 -6
  57. data/spec/gui/qt_spec.rb +102 -0
  58. data/spec/interfaces/interface_spec.rb +9 -9
  59. data/spec/interfaces/linc_interface_spec.rb +72 -15
  60. data/spec/interfaces/serial_interface_spec.rb +9 -9
  61. data/spec/interfaces/simulated_target_interface_spec.rb +7 -7
  62. data/spec/interfaces/stream_interface_spec.rb +4 -4
  63. data/spec/interfaces/tcpip_client_interface_spec.rb +8 -8
  64. data/spec/interfaces/tcpip_server_interface_spec.rb +9 -9
  65. data/spec/interfaces/udp_interface_spec.rb +20 -20
  66. data/spec/io/json_drb_spec.rb +4 -4
  67. data/spec/io/raw_logger_pair_spec.rb +20 -20
  68. data/spec/io/raw_logger_spec.rb +3 -3
  69. data/spec/io/tcpip_server_spec.rb +9 -9
  70. data/spec/io/udp_sockets_spec.rb +2 -2
  71. data/spec/io/win32_serial_driver_spec.rb +2 -2
  72. data/spec/packets/binary_accessor_spec.rb +143 -6
  73. data/spec/packets/commands_spec.rb +5 -5
  74. data/spec/packets/limits_spec.rb +15 -15
  75. data/spec/packets/packet_config_spec.rb +19 -19
  76. data/spec/packets/packet_item_limits_spec.rb +3 -3
  77. data/spec/packets/packet_item_spec.rb +4 -4
  78. data/spec/packets/packet_spec.rb +33 -33
  79. data/spec/packets/structure_item_spec.rb +19 -19
  80. data/spec/packets/telemetry_spec.rb +6 -6
  81. data/spec/script/cmd_tlm_server_spec.rb +110 -0
  82. data/spec/script/commands_disconnect_spec.rb +270 -0
  83. data/spec/script/commands_spec.rb +288 -0
  84. data/spec/script/limits_spec.rb +153 -0
  85. data/spec/script/script_spec.rb +32 -696
  86. data/spec/script/scripting_spec.rb +436 -0
  87. data/spec/script/telemetry_spec.rb +130 -0
  88. data/spec/script/tools_spec.rb +117 -0
  89. data/spec/spec_helper.rb +10 -5
  90. data/spec/streams/preidentified_stream_protocol_spec.rb +4 -4
  91. data/spec/streams/serial_stream_spec.rb +8 -8
  92. data/spec/streams/stream_protocol_spec.rb +4 -4
  93. data/spec/streams/tcpip_client_stream_spec.rb +3 -3
  94. data/spec/streams/tcpip_socket_stream_spec.rb +7 -7
  95. data/spec/streams/template_stream_protocol_spec.rb +1 -1
  96. data/spec/system/system_spec.rb +6 -6
  97. data/spec/system/target_spec.rb +2 -0
  98. data/spec/tools/cmd_tlm_server/api_spec.rb +17 -17
  99. data/spec/tools/cmd_tlm_server/cmd_tlm_server_config_spec.rb +5 -5
  100. data/spec/tools/cmd_tlm_server/interface_thread_spec.rb +3 -3
  101. data/spec/top_level/top_level_spec.rb +8 -8
  102. data/spec/utilities/csv_spec.rb +3 -3
  103. data/spec/utilities/message_log_spec.rb +3 -3
  104. data/spec/utilities/ruby_lex_utils_spec.rb +7 -7
  105. data/test/performance/config/tools/launcher/launcher_threads.txt +8 -1
  106. data/test/performance/tools/CmdTlmServerMemProf +1 -1
  107. data/test/performance/tools/TlmGrapherMemProf +19 -0
  108. data/test/performance/tools/TlmGrapherMemProf.bat +59 -0
  109. metadata +38 -2
@@ -366,17 +366,17 @@ module Cosmos
366
366
  describe "check_stale" do
367
367
  it "checks each packet for staleness" do
368
368
  @tlm.check_stale
369
- expect(@tlm.packet("TGT1","PKT1").stale).to be_truthy
370
- expect(@tlm.packet("TGT1","PKT2").stale).to be_truthy
371
- expect(@tlm.packet("TGT2","PKT1").stale).to be_truthy
369
+ expect(@tlm.packet("TGT1","PKT1").stale).to be true
370
+ expect(@tlm.packet("TGT1","PKT2").stale).to be true
371
+ expect(@tlm.packet("TGT2","PKT1").stale).to be true
372
372
 
373
373
  @tlm.packet("TGT1","PKT1").check_limits
374
374
  @tlm.packet("TGT1","PKT2").check_limits
375
375
  @tlm.packet("TGT2","PKT1").check_limits
376
376
  @tlm.check_stale
377
- expect(@tlm.packet("TGT1","PKT1").stale).to be_falsey
378
- expect(@tlm.packet("TGT1","PKT2").stale).to be_falsey
379
- expect(@tlm.packet("TGT2","PKT1").stale).to be_falsey
377
+ expect(@tlm.packet("TGT1","PKT1").stale).to be false
378
+ expect(@tlm.packet("TGT1","PKT2").stale).to be false
379
+ expect(@tlm.packet("TGT2","PKT1").stale).to be false
380
380
  end
381
381
  end
382
382
 
@@ -0,0 +1,110 @@
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
+ require 'spec_helper'
12
+ require 'cosmos'
13
+ require 'cosmos/script/script'
14
+ require 'tempfile'
15
+
16
+ module Cosmos
17
+
18
+ describe Script do
19
+
20
+ before(:all) do
21
+ cts = File.join(Cosmos::USERPATH,'config','tools','cmd_tlm_server','cmd_tlm_server.txt')
22
+ FileUtils.mkdir_p(File.dirname(cts))
23
+ File.open(cts,'w') do |file|
24
+ file.puts 'INTERFACE INST_INT interface.rb'
25
+ file.puts 'TARGET INST'
26
+ end
27
+ System.class_eval('@@instance = nil')
28
+
29
+ require 'cosmos/script'
30
+ end
31
+
32
+ after(:all) do
33
+ clean_config()
34
+ FileUtils.rm_rf File.join(Cosmos::USERPATH,'config','tools')
35
+ end
36
+
37
+ before(:each) do
38
+ allow_any_instance_of(Interface).to receive(:connected?).and_return(true)
39
+ allow_any_instance_of(Interface).to receive(:disconnect)
40
+
41
+ @server = CmdTlmServer.new
42
+ shutdown_cmd_tlm()
43
+ initialize_script_module()
44
+ sleep 0.1
45
+ end
46
+
47
+ after(:each) do
48
+ @server.stop
49
+ shutdown_cmd_tlm()
50
+ sleep(0.1)
51
+ end
52
+
53
+ describe "get_interface_names" do
54
+ it "returns all interfaces" do
55
+ expect(get_interface_names).to include("INST_INT")
56
+ end
57
+ end
58
+
59
+ describe "connect_interface, disconnect_interface, interface_state" do
60
+ it "connects, disconnect and return the state of the interface CTS-3" do
61
+ connect_interface("INST_INT")
62
+ expect(interface_state("INST_INT")).to eql "CONNECTED"
63
+ disconnect_interface("INST_INT")
64
+ end
65
+ end
66
+
67
+ describe "map_target_to_interface" do
68
+ it "maps a target name to an interface" do
69
+ map_target_to_interface("INST","INST_INT")
70
+ end
71
+ end
72
+
73
+ describe "connect_router, disconnect_router, get_router_names, router_state" do
74
+ it "returns connect, disconnect, and list the routers CTS-11" do
75
+ expect(get_router_names).to include("PREIDENTIFIED_ROUTER")
76
+ connect_router("PREIDENTIFIED_ROUTER")
77
+ expect(router_state("PREIDENTIFIED_ROUTER")).to eql "CONNECTED"
78
+ disconnect_router("PREIDENTIFIED_ROUTER")
79
+ end
80
+ end
81
+
82
+ describe "logging methods" do
83
+ it "starts and stop logging and get filenames CTS-14" do
84
+ start_logging
85
+ stop_logging
86
+ get_cmd_log_filename
87
+ get_tlm_log_filename
88
+ start_cmd_log
89
+ start_tlm_log
90
+ get_cmd_log_filename
91
+ get_tlm_log_filename
92
+ stop_cmd_log
93
+ stop_tlm_log
94
+ get_cmd_log_filename
95
+ get_tlm_log_filename
96
+ start_raw_logging_interface
97
+ start_raw_logging_router
98
+ stop_raw_logging_interface
99
+ stop_raw_logging_router
100
+
101
+ start_new_server_message_log
102
+ sleep 0.1
103
+ filename = get_server_message_log_filename
104
+ expect(filename).to match /server_messages.txt/
105
+ end
106
+ end
107
+
108
+ end
109
+ end
110
+
@@ -0,0 +1,270 @@
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
+ require 'spec_helper'
12
+ require 'cosmos'
13
+ require 'cosmos/script/script'
14
+ require 'tempfile'
15
+
16
+ module Cosmos
17
+
18
+ describe Script do
19
+
20
+ before(:all) do
21
+ cts = File.join(Cosmos::USERPATH,'config','tools','cmd_tlm_server','cmd_tlm_server.txt')
22
+ FileUtils.mkdir_p(File.dirname(cts))
23
+ File.open(cts,'w') do |file|
24
+ file.puts 'INTERFACE INST_INT interface.rb'
25
+ file.puts 'TARGET INST'
26
+ end
27
+ System.class_eval('@@instance = nil')
28
+ require 'cosmos/script'
29
+ set_cmd_tlm_disconnect(true)
30
+ end
31
+
32
+ after(:all) do
33
+ clean_config()
34
+ FileUtils.rm_rf File.join(Cosmos::USERPATH,'config','tools')
35
+ end
36
+
37
+ describe "require cosmos/script.rb" do
38
+ it "should raise when inside CmdTlmServer" do
39
+ save = $0
40
+ $0 = "CmdTlmServer"
41
+ expect { load 'cosmos/script.rb' }.to raise_error(/must not be required/)
42
+ $0 = save
43
+ end
44
+
45
+ it "should raise when inside Replay" do
46
+ save = $0
47
+ $0 = "Replay"
48
+ expect { load 'cosmos/script.rb' }.to raise_error(/must not be required/)
49
+ $0 = save
50
+ end
51
+ end
52
+
53
+ describe "cmd" do
54
+ it "sends a command" do
55
+ capture_io do |stdout|
56
+ cmd("INST ABORT")
57
+ expect(stdout.string).to match /cmd\(\"INST ABORT\"\)/ #"
58
+ stdout.rewind
59
+ cmd("INST", "ABORT")
60
+ expect(stdout.string).to match /cmd\(\"INST ABORT\"\)/ #"
61
+ end
62
+ end
63
+
64
+ it "checks parameter ranges" do
65
+ expect { cmd("INST COLLECT with TYPE NORMAL, DURATION 20") }.to raise_error(/Command parameter 'INST COLLECT DURATION' = 20 not in valid range/)
66
+ end
67
+
68
+ it "prompts for a hazardous command" do
69
+ capture_io do |stdout|
70
+ expect(self).to receive(:gets) { 'y' } # Send hazardous command
71
+ cmd("INST COLLECT with TYPE SPECIAL")
72
+
73
+ expect(stdout.string).to match /cmd\(\"INST COLLECT/ # "
74
+ expect(stdout.string).to match "Warning: Command INST COLLECT is Hazardous"
75
+ expect(stdout.string).to_not match "Command INST COLLECT being sent ignoring range checks"
76
+ expect(stdout.string).to_not match "Command INST COLLECT being sent ignoring hazardous warnings"
77
+ stdout.rewind
78
+
79
+ expect(self).to receive(:gets) { 'n' } # Don't send hazardous
80
+ expect(self).to receive(:gets) { 'y' } # Stop running script
81
+ cmd("INST COLLECT with TYPE SPECIAL")
82
+ expect(stdout.string).to match "Warning: Command INST COLLECT is Hazardous"
83
+ end
84
+ end
85
+ end
86
+
87
+ describe "cmd_no_range_check" do
88
+ it "sends an out of range command" do
89
+ expect { cmd_no_range_check("INST COLLECT with TYPE NORMAL, DURATION 20") }.to_not raise_error
90
+ end
91
+
92
+ it "prompts for a hazardous command" do
93
+ capture_io do |stdout|
94
+ expect(self).to receive(:gets) { 'y' } # Send hazardous command
95
+ cmd_no_range_check("INST COLLECT with TYPE SPECIAL")
96
+
97
+ expect(stdout.string).to match /cmd\(\"INST COLLECT/ # "
98
+ expect(stdout.string).to match "Warning: Command INST COLLECT is Hazardous"
99
+ expect(stdout.string).to match "Command INST COLLECT being sent ignoring range checks"
100
+ expect(stdout.string).to_not match "Command INST COLLECT being sent ignoring hazardous warnings"
101
+ stdout.rewind
102
+
103
+ expect(self).to receive(:gets) { 'n' } # Don't send hazardous
104
+ expect(self).to receive(:gets) { 'y' } # Stop running script
105
+ cmd_no_range_check("INST COLLECT with TYPE SPECIAL")
106
+ expect(stdout.string).to match "Warning: Command INST COLLECT is Hazardous"
107
+ end
108
+ end
109
+ end
110
+
111
+ describe "cmd_no_hazardous_check" do
112
+ it "checks parameter ranges" do
113
+ expect { cmd_no_hazardous_check("INST COLLECT with TYPE SPECIAL, DURATION 20") }.to raise_error(/Command parameter 'INST COLLECT DURATION' = 20 not in valid range/)
114
+ end
115
+
116
+ it "sends a hazardous command without prompting" do
117
+ capture_io do |stdout|
118
+ cmd_no_hazardous_check("INST COLLECT with TYPE SPECIAL")
119
+
120
+ expect(stdout.string).to match /cmd\(\"INST COLLECT/ # "
121
+ expect(stdout.string).to_not match "Warning: Command INST COLLECT is Hazardous"
122
+ expect(stdout.string).to_not match "Command INST COLLECT being sent ignoring range checks"
123
+ expect(stdout.string).to match "Command INST COLLECT being sent ignoring hazardous warnings"
124
+ end
125
+ end
126
+ end
127
+
128
+ describe "cmd_no_checks" do
129
+ it "sends an out of range hazardous command without prompting" do
130
+ capture_io do |stdout|
131
+ cmd_no_checks("INST COLLECT with TYPE SPECIAL, DURATION 20")
132
+
133
+ expect(stdout.string).to match /cmd\(\"INST COLLECT/ # "
134
+ expect(stdout.string).to_not match "Warning: Command INST COLLECT is Hazardous"
135
+ expect(stdout.string).to match "Command INST COLLECT being sent ignoring range checks"
136
+ expect(stdout.string).to match "Command INST COLLECT being sent ignoring hazardous warnings"
137
+ end
138
+ end
139
+ end
140
+
141
+ describe "cmd_raw" do
142
+ it "sends a command" do
143
+ capture_io do |stdout|
144
+ cmd_raw("INST ABORT")
145
+ expect(stdout.string).to match /cmd_raw\(\"INST ABORT\"\)/ # "
146
+ end
147
+ end
148
+
149
+ it "checks parameter ranges" do
150
+ expect { cmd_raw("INST COLLECT with TYPE 0, DURATION 20") }.to raise_error(/Command parameter 'INST COLLECT DURATION' = 20 not in valid range/) # '
151
+ end
152
+
153
+ it "prompts for a hazardous command" do
154
+ capture_io do |stdout|
155
+ expect(self).to receive(:gets) { 'y' } # Send hazardous command
156
+ cmd_raw("INST COLLECT with TYPE 1")
157
+
158
+ expect(stdout.string).to match /cmd_raw\(\"INST COLLECT/ # "
159
+ expect(stdout.string).to match "Warning: Command INST COLLECT is Hazardous"
160
+ expect(stdout.string).to_not match "Command INST COLLECT being sent ignoring range checks"
161
+ expect(stdout.string).to_not match "Command INST COLLECT being sent ignoring hazardous warnings"
162
+ stdout.rewind
163
+
164
+ expect(self).to receive(:gets) { 'n' } # Don't send hazardous
165
+ expect(self).to receive(:gets) { 'y' } # Stop running script
166
+ cmd_raw("INST COLLECT with TYPE 1")
167
+ expect(stdout.string).to match "Warning: Command INST COLLECT is Hazardous"
168
+ end
169
+ end
170
+ end
171
+
172
+ describe "cmd_raw_no_range_check" do
173
+ it "sends an out of range command" do
174
+ expect { cmd_raw_no_range_check("INST COLLECT with TYPE 0, DURATION 20") }.to_not raise_error
175
+ end
176
+
177
+ it "prompts for a hazardous command" do
178
+ capture_io do |stdout|
179
+ expect(self).to receive(:gets) { 'y' } # Send hazardous command
180
+ cmd_raw_no_range_check("INST COLLECT with TYPE 1")
181
+
182
+ expect(stdout.string).to match /cmd_raw\(\"INST COLLECT/ # "
183
+ expect(stdout.string).to match "Warning: Command INST COLLECT is Hazardous"
184
+ expect(stdout.string).to match "Command INST COLLECT being sent ignoring range checks"
185
+ expect(stdout.string).to_not match "Command INST COLLECT being sent ignoring hazardous warnings"
186
+ stdout.rewind
187
+
188
+ expect(self).to receive(:gets) { 'n' } # Don't send hazardous
189
+ expect(self).to receive(:gets) { 'y' } # Stop running script
190
+ cmd_raw_no_range_check("INST COLLECT with TYPE 1")
191
+ expect(stdout.string).to match "Warning: Command INST COLLECT is Hazardous"
192
+ end
193
+ end
194
+ end
195
+
196
+ describe "cmd_raw_no_hazardous_check" do
197
+ it "checks parameter ranges" do
198
+ expect { cmd_raw_no_hazardous_check("INST COLLECT with TYPE 1, DURATION 20") }.to raise_error(/Command parameter 'INST COLLECT DURATION' = 20 not in valid range/)
199
+ end
200
+
201
+ it "sends a hazardous command without prompting" do
202
+ capture_io do |stdout|
203
+ cmd_raw_no_hazardous_check("INST COLLECT with TYPE 1")
204
+ expect(stdout.string).to match /cmd_raw\(\"INST COLLECT/ #"
205
+ expect(stdout.string).to_not match "Warning: Command INST COLLECT is Hazardous"
206
+ expect(stdout.string).to_not match "Command INST COLLECT being sent ignoring range checks"
207
+ expect(stdout.string).to match "Command INST COLLECT being sent ignoring hazardous warnings"
208
+ end
209
+ end
210
+ end
211
+
212
+ describe "cmd_raw_no_checks" do
213
+ it "sends an out of range hazardous command without prompting" do
214
+ capture_io do |stdout|
215
+ cmd_raw_no_checks("INST COLLECT with TYPE 1, DURATION 20")
216
+ expect(stdout.string).to match /cmd_raw\(\"INST COLLECT/ #"
217
+ expect(stdout.string).to_not match "Warning: Command INST COLLECT is Hazardous"
218
+ expect(stdout.string).to match "Command INST COLLECT being sent ignoring range checks"
219
+ expect(stdout.string).to match "Command INST COLLECT being sent ignoring hazardous warnings"
220
+ end
221
+ end
222
+ end
223
+
224
+ describe "send_raw" do
225
+ it "sends data to the write_raw interface method" do
226
+ expect_any_instance_of(Interface).to receive(:write_raw).with('\x00')
227
+ send_raw('INST_INT', '\x00')
228
+ end
229
+ end
230
+
231
+ describe "send_raw_file" do
232
+ it "sends file data to the write_raw interface method" do
233
+ file = File.open('raw_test_file.bin','wb')
234
+ file.write '\x00\x01\x02\x03'
235
+ file.close
236
+
237
+ expect_any_instance_of(Interface).to receive(:write_raw).with('\x00\x01\x02\x03')
238
+
239
+ send_raw_file('INST_INT', 'raw_test_file.bin')
240
+
241
+ File.delete('raw_test_file.bin')
242
+ end
243
+ end
244
+
245
+ describe "get_cmd_list" do
246
+ it "returns all the target commands" do
247
+ list = get_cmd_list("INST")
248
+ # Only check for the collect command to make this test list dependent
249
+ # on the demo INST command definition file
250
+ expect(list).to include(["COLLECT", "Starts a collect on the instrument"])
251
+ end
252
+ end
253
+
254
+ describe "get_cmd_param_list" do
255
+ it "returns all the parameters for a command" do
256
+ list = get_cmd_param_list("INST", "COLLECT")
257
+ expect(list).to include(["TYPE", 0, {"NORMAL"=>0, "SPECIAL"=>1}, "Collect type", nil, nil, true])
258
+ end
259
+ end
260
+
261
+ describe "get_cmd_hazardous" do
262
+ it "returns whether a command is hazardous" do
263
+ expect(get_cmd_hazardous("INST", "COLLECT", {"TYPE"=>"NORMAL"})).to be false
264
+ expect(get_cmd_hazardous("INST", "COLLECT", {"TYPE"=>"SPECIAL"})).to be true
265
+ end
266
+ end
267
+
268
+ end
269
+ end
270
+
@@ -0,0 +1,288 @@
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
+ require 'spec_helper'
12
+ require 'cosmos'
13
+ require 'cosmos/script/script'
14
+ require 'tempfile'
15
+
16
+ module Cosmos
17
+
18
+ describe Script do
19
+
20
+ before(:all) do
21
+ cts = File.join(Cosmos::USERPATH,'config','tools','cmd_tlm_server','cmd_tlm_server.txt')
22
+ FileUtils.mkdir_p(File.dirname(cts))
23
+ File.open(cts,'w') do |file|
24
+ file.puts 'INTERFACE INST_INT interface.rb'
25
+ file.puts 'TARGET INST'
26
+ end
27
+ System.class_eval('@@instance = nil')
28
+
29
+ require 'cosmos/script'
30
+ end
31
+
32
+ after(:all) do
33
+ clean_config()
34
+ FileUtils.rm_rf File.join(Cosmos::USERPATH,'config','tools')
35
+ end
36
+
37
+ before(:each) do
38
+ allow_any_instance_of(Interface).to receive(:connected?).and_return(true)
39
+ allow_any_instance_of(Interface).to receive(:disconnect)
40
+ allow_any_instance_of(Interface).to receive(:write)
41
+ allow_any_instance_of(Interface).to receive(:read)
42
+
43
+ @server = CmdTlmServer.new
44
+ shutdown_cmd_tlm()
45
+ initialize_script_module()
46
+ sleep 0.1
47
+ end
48
+
49
+ after(:each) do
50
+ @server.stop
51
+ shutdown_cmd_tlm()
52
+ sleep(0.1)
53
+ end
54
+
55
+ describe "require cosmos/script.rb" do
56
+ it "should raise when inside CmdTlmServer" do
57
+ save = $0
58
+ $0 = "CmdTlmServer"
59
+ expect { load 'cosmos/script.rb' }.to raise_error(/must not be required/)
60
+ $0 = save
61
+ end
62
+
63
+ it "should raise when inside Replay" do
64
+ save = $0
65
+ $0 = "Replay"
66
+ expect { load 'cosmos/script.rb' }.to raise_error(/must not be required/)
67
+ $0 = save
68
+ end
69
+ end
70
+
71
+ describe "cmd" do
72
+ it "sends a command" do
73
+ capture_io do |stdout|
74
+ cmd("INST ABORT")
75
+ expect(stdout.string).to match /cmd\(\"INST ABORT\"\)/ #"
76
+ stdout.rewind
77
+ cmd("INST", "ABORT")
78
+ expect(stdout.string).to match /cmd\(\"INST ABORT\"\)/ #"
79
+ end
80
+ end
81
+
82
+ it "checks parameter ranges" do
83
+ expect { cmd("INST COLLECT with TYPE NORMAL, DURATION 20") }.to raise_error(/Command parameter 'INST COLLECT DURATION' = 20 not in valid range/)
84
+ end
85
+
86
+ it "prompts for a hazardous command" do
87
+ capture_io do |stdout|
88
+ expect(self).to receive(:gets) { 'y' } # Send hazardous command
89
+ cmd("INST COLLECT with TYPE SPECIAL")
90
+
91
+ expect(stdout.string).to match /cmd\(\"INST COLLECT/ #"
92
+ expect(stdout.string).to match "Warning: Command INST COLLECT is Hazardous"
93
+ expect(stdout.string).to_not match "Command INST COLLECT being sent ignoring range checks"
94
+ expect(stdout.string).to_not match "Command INST COLLECT being sent ignoring hazardous warnings"
95
+ stdout.rewind
96
+
97
+ expect(self).to receive(:gets) { 'n' } # Don't send hazardous
98
+ expect(self).to receive(:gets) { 'y' } # Stop running script
99
+ cmd("INST COLLECT with TYPE SPECIAL")
100
+ expect(stdout.string).to match "Warning: Command INST COLLECT is Hazardous"
101
+ end
102
+ end
103
+ end
104
+
105
+ describe "cmd_no_range_check" do
106
+ it "sends an out of range command" do
107
+ expect { cmd_no_range_check("INST COLLECT with TYPE NORMAL, DURATION 20") }.to_not raise_error
108
+ end
109
+
110
+ it "prompts for a hazardous command" do
111
+ capture_io do |stdout|
112
+ expect(self).to receive(:gets) { 'y' } # Send hazardous command
113
+ cmd_no_range_check("INST COLLECT with TYPE SPECIAL")
114
+
115
+ expect(stdout.string).to match /cmd\(\"INST COLLECT/ #"
116
+ expect(stdout.string).to match "Warning: Command INST COLLECT is Hazardous"
117
+ expect(stdout.string).to match "Command INST COLLECT being sent ignoring range checks"
118
+ expect(stdout.string).to_not match "Command INST COLLECT being sent ignoring hazardous warnings"
119
+ stdout.rewind
120
+
121
+ expect(self).to receive(:gets) { 'n' } # Don't send hazardous
122
+ expect(self).to receive(:gets) { 'y' } # Stop running script
123
+ cmd_no_range_check("INST COLLECT with TYPE SPECIAL")
124
+ expect(stdout.string).to match "Warning: Command INST COLLECT is Hazardous"
125
+ end
126
+ end
127
+ end
128
+
129
+ describe "cmd_no_hazardous_check" do
130
+ it "checks parameter ranges" do
131
+ expect { cmd_no_hazardous_check("INST COLLECT with TYPE SPECIAL, DURATION 20") }.to raise_error(/Command parameter 'INST COLLECT DURATION' = 20 not in valid range/)
132
+ end
133
+
134
+ it "sends a hazardous command without prompting" do
135
+ capture_io do |stdout|
136
+ cmd_no_hazardous_check("INST COLLECT with TYPE SPECIAL")
137
+
138
+ expect(stdout.string).to match /cmd\(\"INST COLLECT/ #"
139
+ expect(stdout.string).to_not match "Warning: Command INST COLLECT is Hazardous"
140
+ expect(stdout.string).to_not match "Command INST COLLECT being sent ignoring range checks"
141
+ expect(stdout.string).to match "Command INST COLLECT being sent ignoring hazardous warnings"
142
+ end
143
+ end
144
+ end
145
+
146
+ describe "cmd_no_checks" do
147
+ it "sends an out of range hazardous command without prompting" do
148
+ capture_io do |stdout|
149
+ cmd_no_checks("INST COLLECT with TYPE SPECIAL, DURATION 20")
150
+
151
+ expect(stdout.string).to match /cmd\(\"INST COLLECT/ #"
152
+ expect(stdout.string).to_not match "Warning: Command INST COLLECT is Hazardous"
153
+ expect(stdout.string).to match "Command INST COLLECT being sent ignoring range checks"
154
+ expect(stdout.string).to match "Command INST COLLECT being sent ignoring hazardous warnings"
155
+ end
156
+ end
157
+ end
158
+
159
+ describe "cmd_raw" do
160
+ it "sends a command" do
161
+ capture_io do |stdout|
162
+ cmd_raw("INST ABORT")
163
+ expect(stdout.string).to match /cmd_raw\(\"INST ABORT\"\)/ #"
164
+ end
165
+ end
166
+
167
+ it "checks parameter ranges" do
168
+ expect { cmd_raw("INST COLLECT with TYPE 0, DURATION 20") }.to raise_error(/Command parameter 'INST COLLECT DURATION' = 20 not in valid range/)
169
+ end
170
+
171
+ it "prompts for a hazardous command" do
172
+ capture_io do |stdout|
173
+ expect(self).to receive(:gets) { 'y' } # Send hazardous command
174
+ cmd_raw("INST COLLECT with TYPE 1")
175
+
176
+ expect(stdout.string).to match /cmd_raw\(\"INST COLLECT/ #"
177
+ expect(stdout.string).to match "Warning: Command INST COLLECT is Hazardous"
178
+ expect(stdout.string).to_not match "Command INST COLLECT being sent ignoring range checks"
179
+ expect(stdout.string).to_not match "Command INST COLLECT being sent ignoring hazardous warnings"
180
+ stdout.rewind
181
+
182
+ expect(self).to receive(:gets) { 'n' } # Don't send hazardous
183
+ expect(self).to receive(:gets) { 'y' } # Stop running script
184
+ cmd_raw("INST COLLECT with TYPE 1")
185
+ expect(stdout.string).to match "Warning: Command INST COLLECT is Hazardous"
186
+ end
187
+ end
188
+ end
189
+
190
+ describe "cmd_raw_no_range_check" do
191
+ it "sends an out of range command" do
192
+ expect { cmd_raw_no_range_check("INST COLLECT with TYPE 0, DURATION 20") }.to_not raise_error
193
+ end
194
+
195
+ it "prompts for a hazardous command" do
196
+ capture_io do |stdout|
197
+ expect(self).to receive(:gets) { 'y' } # Send hazardous command
198
+ cmd_raw_no_range_check("INST COLLECT with TYPE 1")
199
+
200
+ expect(stdout.string).to match /cmd_raw\(\"INST COLLECT/ #"
201
+ expect(stdout.string).to match "Warning: Command INST COLLECT is Hazardous"
202
+ expect(stdout.string).to match "Command INST COLLECT being sent ignoring range checks"
203
+ expect(stdout.string).to_not match "Command INST COLLECT being sent ignoring hazardous warnings"
204
+ stdout.rewind
205
+
206
+ expect(self).to receive(:gets) { 'n' } # Don't send hazardous
207
+ expect(self).to receive(:gets) { 'y' } # Stop running script
208
+ cmd_raw_no_range_check("INST COLLECT with TYPE 1")
209
+ expect(stdout.string).to match "Warning: Command INST COLLECT is Hazardous"
210
+ end
211
+ end
212
+ end
213
+
214
+ describe "cmd_raw_no_hazardous_check" do
215
+ it "checks parameter ranges" do
216
+ expect { cmd_raw_no_hazardous_check("INST COLLECT with TYPE 1, DURATION 20") }.to raise_error(/Command parameter 'INST COLLECT DURATION' = 20 not in valid range/)
217
+ end
218
+
219
+ it "sends a hazardous command without prompting" do
220
+ capture_io do |stdout|
221
+ cmd_raw_no_hazardous_check("INST COLLECT with TYPE 1")
222
+ expect(stdout.string).to match /cmd_raw\(\"INST COLLECT/ #"
223
+ expect(stdout.string).to_not match "Warning: Command INST COLLECT is Hazardous"
224
+ expect(stdout.string).to_not match "Command INST COLLECT being sent ignoring range checks"
225
+ expect(stdout.string).to match "Command INST COLLECT being sent ignoring hazardous warnings"
226
+ end
227
+ end
228
+ end
229
+
230
+ describe "cmd_raw_no_checks" do
231
+ it "sends an out of range hazardous command without prompting" do
232
+ capture_io do |stdout|
233
+ cmd_raw_no_checks("INST COLLECT with TYPE 1, DURATION 20")
234
+ expect(stdout.string).to match /cmd_raw\(\"INST COLLECT/ #"
235
+ expect(stdout.string).to_not match "Warning: Command INST COLLECT is Hazardous"
236
+ expect(stdout.string).to match "Command INST COLLECT being sent ignoring range checks"
237
+ expect(stdout.string).to match "Command INST COLLECT being sent ignoring hazardous warnings"
238
+ end
239
+ end
240
+ end
241
+
242
+ describe "send_raw" do
243
+ it "sends data to the write_raw interface method" do
244
+ expect_any_instance_of(Interface).to receive(:write_raw).with('\x00')
245
+ send_raw('INST_INT', '\x00')
246
+ end
247
+ end
248
+
249
+ describe "send_raw_file" do
250
+ it "sends file data to the write_raw interface method" do
251
+ file = File.open('raw_test_file.bin','wb')
252
+ file.write '\x00\x01\x02\x03'
253
+ file.close
254
+
255
+ expect_any_instance_of(Interface).to receive(:write_raw).with('\x00\x01\x02\x03')
256
+
257
+ send_raw_file('INST_INT', 'raw_test_file.bin')
258
+
259
+ File.delete('raw_test_file.bin')
260
+ end
261
+ end
262
+
263
+ describe "get_cmd_list" do
264
+ it "returns all the target commands" do
265
+ list = get_cmd_list("INST")
266
+ # Only check for the collect command to make this test list dependent
267
+ # on the demo INST command definition file
268
+ expect(list).to include(["COLLECT", "Starts a collect on the instrument"])
269
+ end
270
+ end
271
+
272
+ describe "get_cmd_param_list" do
273
+ it "returns all the parameters for a command" do
274
+ list = get_cmd_param_list("INST", "COLLECT")
275
+ expect(list).to include(["TYPE", 0, {"NORMAL"=>0, "SPECIAL"=>1}, "Collect type", nil, nil, true])
276
+ end
277
+ end
278
+
279
+ describe "get_cmd_hazardous" do
280
+ it "returns whether a command is hazardous" do
281
+ expect(get_cmd_hazardous("INST", "COLLECT", {"TYPE"=>"NORMAL"})).to be false
282
+ expect(get_cmd_hazardous("INST", "COLLECT", {"TYPE"=>"SPECIAL"})).to be true
283
+ end
284
+ end
285
+
286
+ end
287
+ end
288
+