cosmos 3.8.3 → 3.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -3
  3. data/Manifest.txt +14 -0
  4. data/Rakefile +35 -2
  5. data/autohotkey/config/targets/INST/screens/_footer.txt +4 -0
  6. data/autohotkey/config/targets/INST/screens/hs.txt +1 -4
  7. data/autohotkey/config/tools/table_manager/OldOneDimensionalTable_def.txt +19 -0
  8. data/autohotkey/config/tools/table_manager/OldTwoDimensionalTable_def.txt +248 -0
  9. data/autohotkey/config/tools/table_manager/OneDimensionalTable_def.txt +27 -15
  10. data/autohotkey/config/tools/table_manager/TwoDimensionalTable_def.txt +12 -232
  11. data/autohotkey/procedures/example_test.rb +4 -0
  12. data/autohotkey/tools/TableManagerAHK +4 -9
  13. data/autohotkey/tools/TableManagerAHK2 +18 -0
  14. data/autohotkey/tools/TableManagerAHK3 +18 -0
  15. data/autohotkey/tools/TableManagerAHK4 +24 -0
  16. data/autohotkey/tools/TlmViewerAHK +1 -1
  17. data/autohotkey/tools/autohotkey.rb +2 -1
  18. data/autohotkey/tools/open_gl_builder.ahk +1 -1
  19. data/autohotkey/tools/table_manager.ahk +141 -70
  20. data/cosmos.gemspec +3 -3
  21. data/data/crc.txt +70 -68
  22. data/data/legal.txt +4 -5
  23. data/demo/config/data/crc.txt +10 -9
  24. data/demo/config/targets/INST/screens/_footer.txt +4 -0
  25. data/demo/config/targets/INST/screens/hs.txt +1 -6
  26. data/demo/config/targets/INST/screens/limits.txt +3 -11
  27. data/demo/config/tools/cmd_tlm_server/cmd_tlm_server.txt +1 -0
  28. data/demo/config/tools/table_manager/MCConfigurationTable_fsw1_def.txt +33 -22
  29. data/demo/config/tools/table_manager/MCConfigurationTable_fsw2_def.txt +30 -22
  30. data/demo/config/tools/table_manager/PPSSelectionTable_def.txt +8 -7
  31. data/demo/config/tools/table_manager/TLMMonitoringTable_def.txt +13 -13
  32. data/demo/lib/example_background_task.rb +6 -12
  33. data/demo/procedures/example_test.rb +5 -0
  34. data/lib/cosmos/conversions/conversion.rb +3 -7
  35. data/lib/cosmos/core_ext/class.rb +3 -1
  36. data/lib/cosmos/core_ext/file.rb +1 -0
  37. data/lib/cosmos/core_ext/io.rb +18 -0
  38. data/lib/cosmos/core_ext/range.rb +1 -5
  39. data/lib/cosmos/core_ext/time.rb +3 -3
  40. data/lib/cosmos/gui/dialogs/about_dialog.rb +60 -36
  41. data/lib/cosmos/gui/dialogs/calendar_dialog.rb +10 -14
  42. data/lib/cosmos/gui/dialogs/cmd_details_dialog.rb +4 -5
  43. data/lib/cosmos/gui/dialogs/cmd_tlm_raw_dialog.rb +31 -17
  44. data/lib/cosmos/gui/dialogs/details_dialog.rb +63 -47
  45. data/lib/cosmos/gui/dialogs/exception_dialog.rb +77 -68
  46. data/lib/cosmos/gui/dialogs/exception_list_dialog.rb +6 -5
  47. data/lib/cosmos/gui/dialogs/legal_dialog.rb +34 -21
  48. data/lib/cosmos/gui/dialogs/packet_log_dialog.rb +19 -43
  49. data/lib/cosmos/gui/dialogs/progress_dialog.rb +79 -42
  50. data/lib/cosmos/gui/dialogs/pry_dialog.rb +9 -5
  51. data/lib/cosmos/gui/dialogs/scroll_text_dialog.rb +6 -4
  52. data/lib/cosmos/gui/dialogs/select_dialog.rb +23 -18
  53. data/lib/cosmos/gui/dialogs/set_tlm_dialog.rb +34 -10
  54. data/lib/cosmos/gui/dialogs/splash.rb +18 -8
  55. data/lib/cosmos/gui/dialogs/tlm_details_dialog.rb +38 -43
  56. data/lib/cosmos/gui/dialogs/tlm_edit_dialog.rb +51 -53
  57. data/lib/cosmos/gui/line_graph/line_graph_scaling.rb +1 -1
  58. data/lib/cosmos/gui/line_graph/lines.rb +1 -1
  59. data/lib/cosmos/gui/qt.rb +9 -2
  60. data/lib/cosmos/gui/qt_tool.rb +50 -8
  61. data/lib/cosmos/gui/widgets/packet_log_frame.rb +53 -27
  62. data/lib/cosmos/interfaces/linc_interface.rb +103 -62
  63. data/lib/cosmos/io/json_drb_object.rb +3 -3
  64. data/lib/cosmos/io/raw_logger.rb +4 -8
  65. data/lib/cosmos/io/tcpip_server.rb +2 -2
  66. data/lib/cosmos/packets/binary_accessor.rb +1 -1
  67. data/lib/cosmos/packets/limits.rb +2 -5
  68. data/lib/cosmos/packets/packet.rb +1 -1
  69. data/lib/cosmos/packets/packet_config.rb +54 -19
  70. data/lib/cosmos/packets/parsers/packet_item_parser.rb +7 -1
  71. data/lib/cosmos/script/scripting.rb +4 -5
  72. data/lib/cosmos/system/system.rb +2 -1
  73. data/lib/cosmos/system/target.rb +4 -0
  74. data/lib/cosmos/tools/cmd_tlm_server/background_task.rb +13 -5
  75. data/lib/cosmos/tools/cmd_tlm_server/background_tasks.rb +37 -27
  76. data/lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server.rb +6 -2
  77. data/lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_config.rb +7 -5
  78. data/lib/cosmos/tools/cmd_tlm_server/gui/status_tab.rb +21 -10
  79. data/lib/cosmos/tools/limits_monitor/limits_monitor.rb +11 -11
  80. data/lib/cosmos/tools/script_runner/script_runner.rb +2 -18
  81. data/lib/cosmos/tools/script_runner/script_runner_frame.rb +6 -6
  82. data/lib/cosmos/tools/table_manager/table.rb +32 -41
  83. data/lib/cosmos/tools/table_manager/table_config.rb +140 -729
  84. data/lib/cosmos/tools/table_manager/table_item.rb +20 -36
  85. data/lib/cosmos/tools/table_manager/table_item_parser.rb +46 -0
  86. data/lib/cosmos/tools/table_manager/table_manager.rb +754 -691
  87. data/lib/cosmos/tools/table_manager/table_manager_core.rb +172 -358
  88. data/lib/cosmos/tools/table_manager/table_parser.rb +75 -0
  89. data/lib/cosmos/tools/test_runner/results_writer.rb +1 -1
  90. data/lib/cosmos/tools/test_runner/test_runner.rb +11 -0
  91. data/lib/cosmos/tools/tlm_grapher/data_object_adders/housekeeping_data_object_adder.rb +2 -2
  92. data/lib/cosmos/tools/tlm_grapher/data_object_adders/singlexy_data_object_adder.rb +2 -2
  93. data/lib/cosmos/tools/tlm_grapher/data_object_adders/xy_data_object_adder.rb +2 -2
  94. data/lib/cosmos/tools/tlm_grapher/data_objects/data_object.rb +4 -4
  95. data/lib/cosmos/tools/tlm_grapher/data_objects/housekeeping_data_object.rb +13 -13
  96. data/lib/cosmos/tools/tlm_grapher/data_objects/linegraph_data_object.rb +9 -9
  97. data/lib/cosmos/tools/tlm_grapher/data_objects/xy_data_object.rb +9 -9
  98. data/lib/cosmos/tools/tlm_grapher/tabbed_plots_tool/tabbed_plots_config.rb +4 -4
  99. data/lib/cosmos/tools/tlm_grapher/tabbed_plots_tool/tabbed_plots_tool.rb +1 -1
  100. data/lib/cosmos/tools/tlm_viewer/tlm_viewer.rb +8 -18
  101. data/lib/cosmos/tools/tlm_viewer/tlm_viewer_config.rb +7 -4
  102. data/lib/cosmos/top_level.rb +12 -0
  103. data/lib/cosmos/version.rb +5 -5
  104. data/run_gui_tests.bat +6 -0
  105. data/spec/core_ext/array_spec.rb +1 -1
  106. data/spec/interfaces/linc_interface_spec.rb +4 -4
  107. data/spec/io/json_drb_spec.rb +2 -2
  108. data/spec/io/json_rpc_spec.rb +1 -1
  109. data/spec/io/raw_logger_spec.rb +5 -1
  110. data/spec/packet_logs/packet_log_writer_spec.rb +1 -1
  111. data/spec/packets/packet_config_spec.rb +144 -0
  112. data/spec/packets/parsers/packet_item_parser_spec.rb +60 -0
  113. data/spec/spec_helper.rb +11 -0
  114. data/spec/system/target_spec.rb +5 -1
  115. data/spec/tools/cmd_tlm_server/background_task_spec.rb +15 -3
  116. data/spec/tools/cmd_tlm_server/background_tasks_spec.rb +117 -31
  117. data/spec/tools/cmd_tlm_server/cmd_tlm_server_spec.rb +4 -0
  118. data/spec/tools/launcher/launcher_config_spec.rb +1 -1
  119. data/spec/tools/table_manager/table_config_spec.rb +226 -0
  120. data/spec/tools/table_manager/table_item_spec.rb +57 -0
  121. data/spec/tools/table_manager/table_parser_spec.rb +96 -0
  122. data/spec/tools/table_manager/table_spec.rb +90 -0
  123. data/spec/tools/table_manager/tablemanager_core_spec.rb +557 -0
  124. data/spec/top_level/top_level_spec.rb +9 -0
  125. data/spec/utilities/csv_spec.rb +3 -3
  126. metadata +30 -11
@@ -0,0 +1,557 @@
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/tools/table_manager/table_manager_core'
14
+
15
+ module Cosmos
16
+
17
+ describe TableManagerCore do
18
+ let(:core) { TableManagerCore.new }
19
+
20
+ describe "process_definition" do
21
+ it "complains if the definition filename does not exist" do
22
+ expect { core.process_definition('path') }.to raise_error(/No such file/)
23
+ end
24
+
25
+ it "processes the table definition" do
26
+ tf = Tempfile.new('unittest')
27
+ tf.puts("TABLE table1 BIG_ENDIAN ONE_DIMENSIONAL")
28
+ tf.close
29
+ core.process_definition(tf.path)
30
+ tf.unlink
31
+ expect(core.config).to_not be_nil
32
+ end
33
+ end
34
+
35
+ describe "reset" do
36
+ it "clears the definition filename and configuration" do
37
+ tf = Tempfile.new('unittest')
38
+ tf.puts("TABLE table1 BIG_ENDIAN ONE_DIMENSIONAL")
39
+ tf.close
40
+ core.process_definition(tf.path)
41
+ tf.unlink
42
+ expect(core.config).to_not be_nil
43
+ core.reset
44
+ expect(core.config).to be_nil
45
+ end
46
+ end
47
+
48
+ describe "file_new" do
49
+ it "complains if the definition filename does not exist" do
50
+ expect { core.file_new('path', Dir.pwd) }.to raise_error(/No such file/)
51
+ end
52
+
53
+ it "creates a new file in the given output dir" do
54
+ def_filename = File.join(Dir.pwd, 'table_def.txt')
55
+ File.open(def_filename,'w') do |file|
56
+ file.puts 'TABLE table1 BIG_ENDIAN ONE_DIMENSIONAL'
57
+ file.puts ' APPEND_PARAMETER item1 32 UINT MIN MAX 0xDEADBEEF "Item"'
58
+ file.puts ' APPEND_PARAMETER item2 16 UINT 0 1 0 "Item"'
59
+ file.puts ' STATE DISABLE 0'
60
+ file.puts ' STATE ENABLE 1'
61
+ end
62
+ bin_filename = core.file_new(def_filename, Dir.pwd)
63
+ expect(bin_filename).to eq File.join(Dir.pwd, "table.dat")
64
+ expect(File.read(bin_filename).formatted).to match /DE AD BE EF 00 00/
65
+ FileUtils.rm def_filename
66
+ FileUtils.rm bin_filename
67
+ FileUtils.rm 'table.csv'
68
+ end
69
+ end
70
+
71
+ describe "file_open" do
72
+ it "complains if the definition filename does not exist" do
73
+ def_filename = File.join(Dir.pwd, 'def.txt')
74
+ FileUtils.rm def_filename if File.exist? def_filename
75
+ bin_filename = File.join(Dir.pwd, 'dat.bin')
76
+ File.open(bin_filename,'w') {|file| file.puts "\x00\x01" }
77
+ expect { core.file_open(bin_filename, def_filename) }.to raise_error(/No such file/)
78
+ FileUtils.rm bin_filename
79
+ end
80
+
81
+ it "complains if the binary filename does not exist" do
82
+ bin_filename = File.join(Dir.pwd, 'bin.dat')
83
+ FileUtils.rm bin_filename if File.exist? bin_filename
84
+ def_filename = File.join(Dir.pwd, 'def.txt')
85
+ File.open(def_filename,'w') {|file| file.puts "TABLE table1 BIG_ENDIAN ONE_DIMENSIONAL" }
86
+ expect { core.file_open(bin_filename, def_filename) }.to raise_error(/No such file/)
87
+ FileUtils.rm def_filename
88
+ end
89
+
90
+ it "complains if the binary filename isn't big enough for the definition and zero fills data" do
91
+ bin_filename = File.join(Dir.pwd, 'bin.dat')
92
+ File.open(bin_filename,'w') {|file| file.write "\xAB\xCD" }
93
+ def_filename = File.join(Dir.pwd, 'def.txt')
94
+ File.open(def_filename,'w') do |file|
95
+ file.puts 'TABLE table1 BIG_ENDIAN ONE_DIMENSIONAL'
96
+ file.puts ' APPEND_PARAMETER item1 32 UINT 0 0 0 "Item"'
97
+ end
98
+ expect { core.file_open(bin_filename, def_filename) }.to raise_error(/Binary size of 2 not large enough/)
99
+ expect(core.config.tables['TABLE1'].buffer.formatted).to match /AB CD 00 00/
100
+ FileUtils.rm bin_filename
101
+ FileUtils.rm def_filename
102
+ end
103
+
104
+ it "complains if the binary filename is too enough for the definition and truncates the data" do
105
+ bin_filename = File.join(Dir.pwd, 'bin.dat')
106
+ File.open(bin_filename,'w') {|file| file.write "\xAB\xCD\xEF" }
107
+ def_filename = File.join(Dir.pwd, 'def.txt')
108
+ File.open(def_filename,'w') do |file|
109
+ file.puts 'TABLE table1 BIG_ENDIAN ONE_DIMENSIONAL'
110
+ file.puts ' APPEND_PARAMETER item1 16 UINT 0 0 0 "Item"'
111
+ end
112
+ expect { core.file_open(bin_filename, def_filename) }.to raise_error(/Binary size of 3 larger/)
113
+ expect(core.config.tables['TABLE1'].buffer.formatted).to match /AB CD/
114
+ FileUtils.rm bin_filename
115
+ FileUtils.rm def_filename
116
+ end
117
+ end
118
+
119
+ describe "file_save" do
120
+ it "complains if there is no configuration" do
121
+ expect { core.file_save('save') }.to raise_error(TableManagerCore::NoConfigError)
122
+ end
123
+
124
+ it "complains if there is an error in the configuration data" do
125
+ bin_filename = File.join(Dir.pwd, 'bin.dat')
126
+ File.open(bin_filename,'w') {|file| file.write "\x00\x01" }
127
+ def_filename = File.join(Dir.pwd, 'def.txt')
128
+ File.open(def_filename,'w') do |file|
129
+ file.puts 'TABLE table1 BIG_ENDIAN ONE_DIMENSIONAL'
130
+ file.puts ' APPEND_PARAMETER item1 16 UINT 0 0 0 "Item"'
131
+ end
132
+ core.file_open(bin_filename, def_filename)
133
+ expect { core.file_save('save.bin') }.to raise_error(TableManagerCore::CoreError)
134
+ FileUtils.rm bin_filename
135
+ FileUtils.rm def_filename
136
+ end
137
+
138
+ it "writes the configuration to file" do
139
+ bin_filename = File.join(Dir.pwd, 'bin.dat')
140
+ File.open(bin_filename,'w') {|file| file.write "\x00\x01" }
141
+ def_filename = File.join(Dir.pwd, 'def.txt')
142
+ File.open(def_filename,'w') do |file|
143
+ file.puts 'TABLE table1 BIG_ENDIAN ONE_DIMENSIONAL'
144
+ file.puts ' APPEND_PARAMETER item1 16 UINT MIN MAX 0 "Item"'
145
+ end
146
+ core.file_open(bin_filename, def_filename)
147
+ core.config.tables['TABLE1'].buffer = "\xAB\xCD"
148
+ core.file_save('save.bin')
149
+ expect(File.read('save.bin').formatted).to match /AB CD/
150
+ FileUtils.rm bin_filename
151
+ FileUtils.rm def_filename
152
+ FileUtils.rm 'save.bin'
153
+ FileUtils.rm 'save.bin.csv'
154
+ end
155
+ end
156
+
157
+ describe "file_check" do
158
+ it "complains if there is no configuration" do
159
+ expect { core.file_check() }.to raise_error(TableManagerCore::NoConfigError)
160
+ end
161
+
162
+ it "complains if there is an error in the configuration data" do
163
+ bin_filename = File.join(Dir.pwd, 'bin.dat')
164
+ File.open(bin_filename,'w') {|file| file.write "\x00\x01" }
165
+ def_filename = File.join(Dir.pwd, 'def.txt')
166
+ File.open(def_filename,'w') do |file|
167
+ file.puts 'TABLE table1 BIG_ENDIAN ONE_DIMENSIONAL'
168
+ file.puts ' APPEND_PARAMETER item1 16 UINT 0 0 0 "Item"'
169
+ end
170
+ core.file_open(bin_filename, def_filename)
171
+ expect { core.file_check() }.to raise_error(/Errors in TABLE1/)
172
+ FileUtils.rm bin_filename
173
+ FileUtils.rm def_filename
174
+ end
175
+
176
+ it "returns a success string if there are no errors" do
177
+ bin_filename = File.join(Dir.pwd, 'bin.dat')
178
+ File.open(bin_filename,'w') {|file| file.write "\x00\x01" }
179
+ def_filename = File.join(Dir.pwd, 'def.txt')
180
+ File.open(def_filename,'w') do |file|
181
+ file.puts 'TABLE table1 BIG_ENDIAN ONE_DIMENSIONAL'
182
+ file.puts ' APPEND_PARAMETER item1 16 UINT MIN MAX 0 "Item"'
183
+ end
184
+ core.file_open(bin_filename, def_filename)
185
+ expect(core.file_check()).to eql "All parameters are within their constraints."
186
+ FileUtils.rm bin_filename
187
+ FileUtils.rm def_filename
188
+ end
189
+ end
190
+
191
+ describe "file_report" do
192
+ it "complains if there is no configuration" do
193
+ expect { core.file_report('file.dat', 'file_def.txt') }.to raise_error(TableManagerCore::NoConfigError)
194
+ end
195
+
196
+ it "creates a CSV file with the configuration for ONE_DIMENSIONAL" do
197
+ bin_filename = File.join(Dir.pwd, 'testfile.dat')
198
+ File.open(bin_filename,'w') {|file| file.write "\x00\x01" }
199
+ def_filename = File.join(Dir.pwd, 'testfile_def.txt')
200
+ File.open(def_filename,'w') do |file|
201
+ file.puts 'TABLE table1 BIG_ENDIAN ONE_DIMENSIONAL'
202
+ file.puts ' APPEND_PARAMETER item1 16 UINT MIN MAX 0 "Item"'
203
+ end
204
+ core.file_open(bin_filename, def_filename)
205
+ report_filename = core.file_report(bin_filename, def_filename)
206
+ expect(File.basename(report_filename)).to eql "testfile.csv"
207
+ report = File.read(report_filename)
208
+ expect(report).to match /#{bin_filename}/
209
+ expect(report).to match /#{def_filename}/
210
+ FileUtils.rm report_filename
211
+ FileUtils.rm bin_filename
212
+ FileUtils.rm def_filename
213
+ end
214
+
215
+ it "creates a CSV file with the configuration for TWO_DIMENSIONAL" do
216
+ bin_filename = File.join(Dir.pwd, 'testfile.dat')
217
+ File.open(bin_filename,'w') {|file| file.write "\x00\x01\x02\x03\x00\x01\x02\x03" }
218
+ def_filename = File.join(Dir.pwd, 'testfile_def.txt')
219
+ File.open(def_filename,'w') do |file|
220
+ file.puts 'TABLE table1 BIG_ENDIAN TWO_DIMENSIONAL 2'
221
+ file.puts ' APPEND_PARAMETER item1 16 UINT MIN MAX 0 "Item"'
222
+ file.puts ' APPEND_PARAMETER item2 16 UINT MIN MAX 0 "Item"'
223
+ end
224
+ core.file_open(bin_filename, def_filename)
225
+ report_filename = core.file_report(bin_filename, def_filename)
226
+ expect(File.basename(report_filename)).to eql "testfile.csv"
227
+ report = File.read(report_filename)
228
+ expect(report).to match /#{bin_filename}/
229
+ expect(report).to match /#{def_filename}/
230
+ FileUtils.rm report_filename
231
+ FileUtils.rm bin_filename
232
+ FileUtils.rm def_filename
233
+ end
234
+ end
235
+
236
+ describe "file_hex" do
237
+ it "complains if there is no configuration" do
238
+ expect { core.file_hex }.to raise_error(TableManagerCore::NoConfigError)
239
+ end
240
+
241
+ it "creates a hex representation of the binary data" do
242
+ bin_filename = File.join(Dir.pwd, 'testfile.dat')
243
+ File.open(bin_filename,'w') {|file| file.write "\xDE\xAD\xBE\xEF" }
244
+ def_filename = File.join(Dir.pwd, 'testfile_def.txt')
245
+ File.open(def_filename,'w') do |file|
246
+ file.puts 'TABLE table1 BIG_ENDIAN ONE_DIMENSIONAL'
247
+ file.puts ' APPEND_PARAMETER item1 16 UINT MIN MAX 0 "Item"'
248
+ file.puts ' APPEND_PARAMETER item2 16 UINT MIN MAX 0 "Item"'
249
+ end
250
+ core.file_open(bin_filename, def_filename)
251
+ expect(core.file_hex).to match /Total Bytes Read: 4/
252
+ expect(core.file_hex).to match /DE AD BE EF/
253
+ FileUtils.rm bin_filename
254
+ FileUtils.rm def_filename
255
+ end
256
+ end
257
+
258
+ describe "table_check" do
259
+ it "complains if there is no configuration" do
260
+ expect { core.table_check('table') }.to raise_error(TableManagerCore::NoConfigError)
261
+ end
262
+
263
+ it "complains if the table does not exist" do
264
+ bin_filename = File.join(Dir.pwd, 'testfile.dat')
265
+ File.open(bin_filename,'w') {|file| file.write "\x00\x00" }
266
+ def_filename = File.join(Dir.pwd, 'testfile_def.txt')
267
+ File.open(def_filename,'w') do |file|
268
+ file.puts 'TABLE table1 BIG_ENDIAN ONE_DIMENSIONAL'
269
+ file.puts ' APPEND_PARAMETER item1 16 UINT MIN MAX 0 "Item"'
270
+ end
271
+ core.file_open(bin_filename, def_filename)
272
+ expect { core.table_check('TABLE') }.to raise_error(TableManagerCore::NoTableError)
273
+ FileUtils.rm bin_filename
274
+ FileUtils.rm def_filename
275
+ end
276
+
277
+ it "returns a string with out of range values" do
278
+ bin_filename = File.join(Dir.pwd, 'testfile.dat')
279
+ File.open(bin_filename,'w') {|file| file.write "\x00\x03\xFF\xFD\x48\x46\x4C\x4C\x4F\x00\x00" }
280
+ def_filename = File.join(Dir.pwd, 'testfile_def.txt')
281
+ File.open(def_filename,'w') do |file|
282
+ file.puts 'TABLE table1 BIG_ENDIAN ONE_DIMENSIONAL'
283
+ file.puts ' APPEND_PARAMETER item1 16 UINT 0 2 0 "Item"'
284
+ file.puts ' STATE DISABLE 0'
285
+ file.puts ' STATE ENABLE 1'
286
+ file.puts ' STATE UNKNOWN 2'
287
+ file.puts ' APPEND_PARAMETER item2 16 INT -2 2 0 "Item"'
288
+ file.puts ' APPEND_PARAMETER item3 40 STRING "HELLO" "Item"'
289
+ file.puts ' APPEND_PARAMETER item4 16 UINT 0 4 0 "Item"'
290
+ file.puts ' FORMAT_STRING "0x%0X"'
291
+ file.puts ' GENERIC_READ_CONVERSION_START'
292
+ file.puts ' myself.read("item1") * 2'
293
+ file.puts ' GENERIC_READ_CONVERSION_END'
294
+ end
295
+ core.file_open(bin_filename, def_filename)
296
+ result = core.table_check('table1')
297
+ expect(result).to match "ITEM1: 3 outside valid range of 0..2"
298
+ expect(result).to match "ITEM2: -3 outside valid range of -2..2"
299
+ expect(result).to match "ITEM4: 0x6 outside valid range of 0x0..0x4"
300
+ FileUtils.rm bin_filename
301
+ FileUtils.rm def_filename
302
+ end
303
+ end
304
+
305
+ describe "table_default" do
306
+ it "complains if there is no configuration" do
307
+ expect { core.table_default('table') }.to raise_error(TableManagerCore::NoConfigError)
308
+ end
309
+
310
+ it "complains if the table does not exist" do
311
+ bin_filename = File.join(Dir.pwd, 'testfile.dat')
312
+ File.open(bin_filename,'w') {|file| file.write "\x00\x00" }
313
+ def_filename = File.join(Dir.pwd, 'testfile_def.txt')
314
+ File.open(def_filename,'w') do |file|
315
+ file.puts 'TABLE table1 BIG_ENDIAN ONE_DIMENSIONAL'
316
+ file.puts ' APPEND_PARAMETER item1 16 UINT MIN MAX 0 "Item"'
317
+ end
318
+ core.file_open(bin_filename, def_filename)
319
+ expect { core.table_default('TABLE') }.to raise_error(TableManagerCore::NoTableError)
320
+ FileUtils.rm bin_filename
321
+ FileUtils.rm def_filename
322
+ end
323
+
324
+ it "sets all table items to their default" do
325
+ bin_filename = File.join(Dir.pwd, 'testfile.dat')
326
+ File.open(bin_filename,'w') {|file| file.write "\x00"*11 }
327
+ def_filename = File.join(Dir.pwd, 'testfile_def.txt')
328
+ File.open(def_filename,'w') do |file|
329
+ file.puts 'TABLE table1 BIG_ENDIAN ONE_DIMENSIONAL'
330
+ file.puts ' APPEND_PARAMETER item1 16 INT MIN MAX -100 "Item"'
331
+ file.puts ' APPEND_PARAMETER item2 32 UINT MIN MAX 0xDEADBEEF "Item"'
332
+ file.puts ' APPEND_PARAMETER item3 40 STRING "HELLO" "Item"'
333
+ end
334
+ core.file_open(bin_filename, def_filename)
335
+ expect(core.config.tables['TABLE1'].read('item1')).to eq 0
336
+ expect(core.config.tables['TABLE1'].read('item2')).to eq 0
337
+ expect(core.config.tables['TABLE1'].read('item3')).to eq ""
338
+ core.table_default('table1')
339
+ expect(core.config.tables['TABLE1'].read('item1')).to eq -100
340
+ expect(core.config.tables['TABLE1'].read('item2')).to eq 0xDEADBEEF
341
+ expect(core.config.tables['TABLE1'].read('item3')).to eq "HELLO"
342
+ FileUtils.rm bin_filename
343
+ FileUtils.rm def_filename
344
+ end
345
+ end
346
+
347
+ describe "table_hex" do
348
+ it "complains if there is no configuration" do
349
+ expect { core.table_hex('table') }.to raise_error(TableManagerCore::NoConfigError)
350
+ end
351
+
352
+ it "complains if the table does not exist" do
353
+ bin_filename = File.join(Dir.pwd, 'testfile.dat')
354
+ File.open(bin_filename,'w') {|file| file.write "\xDE\xAD\xBE\xEF" }
355
+ def_filename = File.join(Dir.pwd, 'testfile_def.txt')
356
+ File.open(def_filename,'w') do |file|
357
+ file.puts 'TABLE table1 BIG_ENDIAN ONE_DIMENSIONAL'
358
+ file.puts ' APPEND_PARAMETER item1 16 UINT MIN MAX 0 "Item"'
359
+ file.puts ' APPEND_PARAMETER item2 16 UINT MIN MAX 0 "Item"'
360
+ end
361
+ core.file_open(bin_filename, def_filename)
362
+ expect { core.table_hex('table') }.to raise_error(TableManagerCore::NoTableError)
363
+ FileUtils.rm bin_filename
364
+ FileUtils.rm def_filename
365
+ end
366
+
367
+ it "creates a hex representation of the binary data" do
368
+ bin_filename = File.join(Dir.pwd, 'testfile.dat')
369
+ File.open(bin_filename,'w') {|file| file.write "\xDE\xAD\xBE\xEF\xCA\xFE\xBA\xBE" }
370
+ def_filename = File.join(Dir.pwd, 'testfile_def.txt')
371
+ File.open(def_filename,'w') do |file|
372
+ file.puts 'TABLE table1 BIG_ENDIAN ONE_DIMENSIONAL'
373
+ file.puts ' APPEND_PARAMETER item1 16 UINT MIN MAX 0 "Item"'
374
+ file.puts ' APPEND_PARAMETER item2 16 UINT MIN MAX 0 "Item"'
375
+ file.puts 'TABLE table2 BIG_ENDIAN ONE_DIMENSIONAL'
376
+ file.puts ' APPEND_PARAMETER item1 16 UINT MIN MAX 0 "Item"'
377
+ file.puts ' APPEND_PARAMETER item2 16 UINT MIN MAX 0 "Item"'
378
+ end
379
+ core.file_open(bin_filename, def_filename)
380
+ expect(core.table_hex('table1')).to match /Total Bytes Read: 4/
381
+ expect(core.table_hex('table1')).to match /DE AD BE EF/
382
+ expect(core.table_hex('table2')).to match /Total Bytes Read: 4/
383
+ expect(core.table_hex('table2')).to match /CA FE BA BE/
384
+ FileUtils.rm bin_filename
385
+ FileUtils.rm def_filename
386
+ end
387
+ end
388
+
389
+ describe "table_save" do
390
+ it "complains if there is no configuration" do
391
+ expect { core.table_save('table', 'table.dat') }.to raise_error(TableManagerCore::NoConfigError)
392
+ end
393
+
394
+ it "complains if the table does not exist" do
395
+ bin_filename = File.join(Dir.pwd, 'testfile.dat')
396
+ File.open(bin_filename,'w') {|file| file.write "\xDE\xAD\xBE\xEF" }
397
+ def_filename = File.join(Dir.pwd, 'testfile_def.txt')
398
+ File.open(def_filename,'w') do |file|
399
+ file.puts 'TABLE table1 BIG_ENDIAN ONE_DIMENSIONAL'
400
+ file.puts ' APPEND_PARAMETER item1 16 UINT MIN MAX 0 "Item"'
401
+ file.puts ' APPEND_PARAMETER item2 16 UINT MIN MAX 0 "Item"'
402
+ end
403
+ core.file_open(bin_filename, def_filename)
404
+ expect { core.table_save('table', 'table.dat') }.to raise_error(TableManagerCore::NoTableError)
405
+ FileUtils.rm bin_filename
406
+ FileUtils.rm def_filename
407
+ end
408
+
409
+ it "complains if the table has errors" do
410
+ bin_filename = File.join(Dir.pwd, 'testfile.dat')
411
+ File.open(bin_filename,'w') {|file| file.write "\xDE\xAD\xBE\xEF" }
412
+ def_filename = File.join(Dir.pwd, 'testfile_def.txt')
413
+ File.open(def_filename,'w') do |file|
414
+ file.puts 'TABLE table1 BIG_ENDIAN ONE_DIMENSIONAL'
415
+ file.puts ' APPEND_PARAMETER item1 16 UINT 0 0 0 "Item"'
416
+ file.puts ' APPEND_PARAMETER item2 16 UINT MIN MAX 0 "Item"'
417
+ end
418
+ core.file_open(bin_filename, def_filename)
419
+ expect { core.table_save('table1', 'table.dat') }.to raise_error(TableManagerCore::CoreError)
420
+ FileUtils.rm bin_filename
421
+ FileUtils.rm def_filename
422
+ end
423
+
424
+ it "creates a new file with the table binary data" do
425
+ bin_filename = File.join(Dir.pwd, 'testfile.dat')
426
+ File.open(bin_filename,'w') {|file| file.write "\xDE\xAD\xBE\xEF\xCA\xFE\xBA\xBE" }
427
+ def_filename = File.join(Dir.pwd, 'testfile_def.txt')
428
+ File.open(def_filename,'w') do |file|
429
+ file.puts 'TABLE table1 BIG_ENDIAN ONE_DIMENSIONAL'
430
+ file.puts ' APPEND_PARAMETER item1 16 UINT MIN MAX 0 "Item"'
431
+ file.puts ' APPEND_PARAMETER item2 16 UINT MIN MAX 0 "Item"'
432
+ file.puts 'TABLE table2 BIG_ENDIAN ONE_DIMENSIONAL'
433
+ file.puts ' APPEND_PARAMETER item1 16 UINT MIN MAX 0 "Item"'
434
+ file.puts ' APPEND_PARAMETER item2 16 UINT MIN MAX 0 "Item"'
435
+ end
436
+ core.file_open(bin_filename, def_filename)
437
+ core.table_save('table1', 'table1.dat')
438
+ expect(File.read('table1.dat').formatted).to match /DE AD BE EF/
439
+ core.table_save('table2', 'table2.dat')
440
+ expect(File.read('table2.dat').formatted).to match /CA FE BA BE/
441
+ FileUtils.rm bin_filename
442
+ FileUtils.rm def_filename
443
+ FileUtils.rm 'table1.dat'
444
+ FileUtils.rm 'table2.dat'
445
+ end
446
+ end
447
+
448
+ describe "table_commit" do
449
+ it "complains if there is no configuration" do
450
+ expect { core.table_commit('table', 'table.dat', 'table_def.txt') }.to raise_error(TableManagerCore::NoConfigError)
451
+ end
452
+
453
+ it "complains if the table does not exist" do
454
+ bin_filename = File.join(Dir.pwd, 'testfile.dat')
455
+ File.open(bin_filename,'w') {|file| file.write "\xDE\xAD\xBE\xEF" }
456
+ def_filename = File.join(Dir.pwd, 'testfile_def.txt')
457
+ File.open(def_filename,'w') do |file|
458
+ file.puts 'TABLE table1 BIG_ENDIAN ONE_DIMENSIONAL'
459
+ file.puts ' APPEND_PARAMETER item1 16 UINT MIN MAX 0 "Item"'
460
+ file.puts ' APPEND_PARAMETER item2 16 UINT MIN MAX 0 "Item"'
461
+ end
462
+ core.file_open(bin_filename, def_filename)
463
+ expect { core.table_commit('table', 'testfile.dat', 'testfile_def.txt') }.to raise_error(TableManagerCore::NoTableError)
464
+ FileUtils.rm bin_filename
465
+ FileUtils.rm def_filename
466
+ end
467
+
468
+ it "complains if the table has errors" do
469
+ bin_filename = File.join(Dir.pwd, 'testfile.dat')
470
+ File.open(bin_filename,'w') {|file| file.write "\xDE\xAD\xBE\xEF" }
471
+ def_filename = File.join(Dir.pwd, 'testfile_def.txt')
472
+ File.open(def_filename,'w') do |file|
473
+ file.puts 'TABLE table1 BIG_ENDIAN ONE_DIMENSIONAL'
474
+ file.puts ' APPEND_PARAMETER item1 16 UINT 0 0 0 "Item"'
475
+ file.puts ' APPEND_PARAMETER item2 16 UINT MIN MAX 0 "Item"'
476
+ end
477
+ core.file_open(bin_filename, def_filename)
478
+ expect { core.table_commit('table1', 'testfile.dat', 'testfile_def.txt') }.to raise_error(TableManagerCore::CoreError)
479
+ FileUtils.rm bin_filename
480
+ FileUtils.rm def_filename
481
+ end
482
+
483
+ it "complains if the new definition has errors" do
484
+ bin_filename = File.join(Dir.pwd, 'testfile.dat')
485
+ File.open(bin_filename,'w') {|file| file.write "\xDE\xAD\xBE\xEF" }
486
+ def_filename = File.join(Dir.pwd, 'testfile_def.txt')
487
+ File.open(def_filename,'w') do |file|
488
+ file.puts 'TABLE table1 BIG_ENDIAN ONE_DIMENSIONAL'
489
+ file.puts ' APPEND_PARAMETER item1 16 UINT MIN MAX 0 "Item"'
490
+ file.puts ' APPEND_PARAMETER item2 16 UINT MIN MAX 0 "Item"'
491
+ end
492
+ new_def_filename = File.join(Dir.pwd, 'newtestfile_def.txt')
493
+ File.open(new_def_filename,'w') do |file|
494
+ file.puts 'TABLE table1'
495
+ file.puts ' APPEND_PARAMETER item1 16 UINT MIN MAX 0 "Item"'
496
+ file.puts ' APPEND_PARAMETER item2 16 UINT MIN MAX 0 "Item"'
497
+ end
498
+ core.file_open(bin_filename, def_filename)
499
+ expect { core.table_commit('table1', 'testfile.dat', 'newtestfile_def.txt') }.to raise_error(TableManagerCore::CoreError)
500
+ FileUtils.rm bin_filename
501
+ FileUtils.rm def_filename
502
+ FileUtils.rm new_def_filename
503
+ end
504
+
505
+ it "complains if the new file doesn't define the table" do
506
+ bin_filename = File.join(Dir.pwd, 'testfile.dat')
507
+ File.open(bin_filename,'w') {|file| file.write "\xDE\xAD\xBE\xEF" }
508
+ def_filename = File.join(Dir.pwd, 'testfile_def.txt')
509
+ File.open(def_filename,'w') do |file|
510
+ file.puts 'TABLE table1 BIG_ENDIAN ONE_DIMENSIONAL'
511
+ file.puts ' APPEND_PARAMETER item1 16 UINT MIN MAX 0 "Item"'
512
+ file.puts ' APPEND_PARAMETER item2 16 UINT MIN MAX 0 "Item"'
513
+ end
514
+ new_def_filename = File.join(Dir.pwd, 'newtestfile_def.txt')
515
+ File.open(new_def_filename,'w') do |file|
516
+ file.puts 'TABLE table2 BIG_ENDIAN ONE_DIMENSIONAL'
517
+ file.puts ' APPEND_PARAMETER item1 16 UINT MIN MAX 0 "Item"'
518
+ file.puts ' APPEND_PARAMETER item2 16 UINT MIN MAX 0 "Item"'
519
+ end
520
+ core.file_open(bin_filename, def_filename)
521
+ expect { core.table_commit('table1', 'testfile.dat', 'newtestfile_def.txt') }.to raise_error(TableManagerCore::NoTableError)
522
+ FileUtils.rm bin_filename
523
+ FileUtils.rm def_filename
524
+ FileUtils.rm new_def_filename
525
+ end
526
+
527
+ it "saves the table binary data into a new file" do
528
+ bin_filename = File.join(Dir.pwd, 'testfile.dat')
529
+ File.open(bin_filename,'w') {|file| file.write "\xDE\xAD\xBE\xEF\xCA\xFE\xBA\xBE" }
530
+ def_filename = File.join(Dir.pwd, 'testfile_def.txt')
531
+ File.open(def_filename,'w') do |file|
532
+ file.puts 'TABLE table1 BIG_ENDIAN ONE_DIMENSIONAL'
533
+ file.puts ' APPEND_PARAMETER item1 16 UINT MIN MAX 0 "Item"'
534
+ file.puts ' APPEND_PARAMETER item2 16 UINT MIN MAX 0 "Item"'
535
+ file.puts 'TABLE table2 BIG_ENDIAN ONE_DIMENSIONAL'
536
+ file.puts ' APPEND_PARAMETER item1 16 UINT MIN MAX 0 "Item"'
537
+ file.puts ' APPEND_PARAMETER item2 16 UINT MIN MAX 0 "Item"'
538
+ end
539
+ new_bin_filename = File.join(Dir.pwd, 'newtestfile.dat')
540
+ File.open(new_bin_filename,'w') {|file| file.write "\x00"*8 }
541
+
542
+ core.file_open(bin_filename, def_filename)
543
+ expect(File.read('newtestfile.dat').formatted).to match /00 00 00 00 00 00 00 00/
544
+ core.table_commit('table1', 'newtestfile.dat', 'testfile_def.txt')
545
+ expect(File.read('newtestfile.dat').formatted).to match /DE AD BE EF 00 00 00 00/
546
+ core.table_commit('table2', 'newtestfile.dat', 'testfile_def.txt')
547
+ expect(File.read('newtestfile.dat').formatted).to match /DE AD BE EF CA FE BA BE/
548
+ FileUtils.rm bin_filename
549
+ FileUtils.rm def_filename
550
+ FileUtils.rm new_bin_filename
551
+ FileUtils.rm 'newtestfile.csv'
552
+ end
553
+ end
554
+
555
+ end # describe TableManagerCore
556
+ end
557
+