cosmos 4.2.3-java → 4.2.4-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/Manifest.txt +14 -1
- data/bin/dart_util +4 -0
- data/cosmos.gemspec +3 -2
- data/data/config/interface_modifiers.yaml +2 -1
- data/data/config/item_modifiers.yaml +1 -1
- data/data/config/parameter_modifiers.yaml +1 -1
- data/data/crc.txt +52 -45
- data/demo/config/data/crc.txt +6 -1
- data/demo/config/system/system.txt +1 -0
- data/demo/config/targets/DART/cmd_tlm/dart_cmds.txt +2 -0
- data/demo/config/targets/DART/cmd_tlm/dart_tlm.txt +40 -0
- data/demo/config/targets/DART/cmd_tlm_server.txt +6 -0
- data/demo/config/targets/DART/screens/status.txt +54 -0
- data/demo/config/targets/DART/target.txt +7 -0
- data/ext/cosmos/ext/structure/structure.c +16 -4
- data/lib/cosmos/dart/app/models/status.rb +2 -0
- data/lib/cosmos/dart/db/migrate/20180423205644_create_statuses.rb +22 -0
- data/lib/cosmos/dart/db/migrate/20180425211340_add_decom_state_index.rb +5 -0
- data/lib/cosmos/dart/db/migrate/20180509204705_remove_indexes.rb +29 -0
- data/lib/cosmos/dart/db/migrate/20180510160002_remove_timestamps_from_ples.rb +6 -0
- data/lib/cosmos/dart/db/migrate/20180511194944_add_packet_log_id_to_tables.rb +18 -0
- data/lib/cosmos/dart/db/schema.rb +15 -9
- data/lib/cosmos/dart/db/seeds.rb +8 -0
- data/lib/cosmos/dart/lib/dart_common.rb +5 -6
- data/lib/cosmos/dart/lib/dart_database_cleaner.rb +56 -5
- data/lib/cosmos/dart/lib/dart_decom_query.rb +108 -6
- data/lib/cosmos/dart/lib/dart_decommutator.rb +81 -22
- data/lib/cosmos/dart/lib/dart_importer.rb +44 -14
- data/lib/cosmos/dart/lib/dart_packet_log_writer.rb +73 -55
- data/lib/cosmos/dart/lib/dart_reducer_manager.rb +34 -3
- data/lib/cosmos/dart/lib/dart_reducer_worker_thread.rb +18 -7
- data/lib/cosmos/dart/processes/dart.rb +2 -1
- data/lib/cosmos/dart/processes/dart_decom_server.rb +2 -1
- data/lib/cosmos/dart/processes/dart_import.rb +1 -0
- data/lib/cosmos/dart/processes/dart_ingester.rb +1 -0
- data/lib/cosmos/dart/processes/dart_reducer.rb +1 -0
- data/lib/cosmos/dart/processes/dart_stream_server.rb +1 -0
- data/lib/cosmos/dart/processes/dart_util.rb +147 -0
- data/lib/cosmos/dart/processes/dart_worker.rb +1 -0
- data/lib/cosmos/dart/spec/dart/dart_database_cleaner_spec.rb +1 -1
- data/lib/cosmos/dart/spec/dart/dart_decom_query_spec.rb +1 -0
- data/lib/cosmos/dart/spec/dart/dart_decommutator_spec.rb +1 -0
- data/lib/cosmos/dart/spec/dart/dart_importer_spec.rb +1 -0
- data/lib/cosmos/dart/spec/dart/dart_packet_log_writer_spec.rb +39 -36
- data/lib/cosmos/dart/spec/dart/dart_reducer_manager_spec.rb +2 -1
- data/lib/cosmos/dart/spec/dart/dart_tcpip_server_interface_spec.rb +1 -2
- data/lib/cosmos/gui/widgets/dart_meta_frame.rb +13 -6
- data/lib/cosmos/interfaces.rb +1 -0
- data/lib/cosmos/interfaces/dart_status_interface.rb +91 -0
- data/lib/cosmos/interfaces/serial_interface.rb +5 -1
- data/lib/cosmos/io/json_drb.rb +7 -2
- data/lib/cosmos/io/json_drb_object.rb +11 -6
- data/lib/cosmos/io/json_rpc.rb +1 -0
- data/lib/cosmos/io/posix_serial_driver.rb +4 -2
- data/lib/cosmos/io/serial_driver.rb +8 -4
- data/lib/cosmos/io/win32_serial_driver.rb +4 -3
- data/lib/cosmos/packets/packet_config.rb +12 -2
- data/lib/cosmos/packets/structure_item.rb +1 -0
- data/lib/cosmos/script/extract.rb +4 -2
- data/lib/cosmos/streams/serial_stream.rb +10 -5
- data/lib/cosmos/tools/cmd_tlm_server/cmd_tlm_server_config.rb +15 -15
- data/lib/cosmos/tools/cmd_tlm_server/gui/status_tab.rb +1 -1
- data/lib/cosmos/tools/table_manager/table_manager.rb +6 -4
- data/lib/cosmos/tools/tlm_grapher/tabbed_plots_tool/tabbed_plots_dart_thread.rb +5 -4
- data/lib/cosmos/tools/tlm_grapher/tabbed_plots_tool/tabbed_plots_logfile_thread.rb +1 -1
- data/lib/cosmos/top_level.rb +1 -1
- data/lib/cosmos/version.rb +4 -4
- data/spec/interfaces/serial_interface_spec.rb +13 -0
- data/spec/io/json_rpc_spec.rb +7 -0
- data/spec/io/win32_serial_driver_spec.rb +8 -0
- data/spec/packets/structure_item_spec.rb +6 -0
- data/spec/script/extract_spec.rb +5 -0
- data/spec/tools/cmd_tlm_server/cmd_tlm_server_config_spec.rb +10 -0
- metadata +17 -3
- data/lib/cosmos/dart/app/helpers/application_helper.rb +0 -2
@@ -12,6 +12,24 @@ require 'dart_common'
|
|
12
12
|
require 'dart_logging'
|
13
13
|
require 'packet_log_entry'
|
14
14
|
|
15
|
+
class DartDecommutatorStatus
|
16
|
+
attr_accessor :count
|
17
|
+
attr_accessor :error_count
|
18
|
+
attr_accessor :message
|
19
|
+
attr_accessor :message_time
|
20
|
+
|
21
|
+
def initialize
|
22
|
+
@count = 0
|
23
|
+
@error_count = 0
|
24
|
+
@message = ''
|
25
|
+
@message_time = Time.now
|
26
|
+
@cached_meta_ple = nil
|
27
|
+
@cached_system_meta = nil
|
28
|
+
@cached_system_meta_id = nil
|
29
|
+
@cached_system_config = nil
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
15
33
|
class DartDecommutator
|
16
34
|
include DartCommon
|
17
35
|
|
@@ -22,10 +40,12 @@ class DartDecommutator
|
|
22
40
|
sync_targets_and_packets()
|
23
41
|
@worker_id = worker_id
|
24
42
|
@num_workers = num_workers
|
43
|
+
@status = DartDecommutatorStatus.new
|
25
44
|
end
|
26
45
|
|
27
46
|
# Run forever looking for data to decommutate
|
28
47
|
def run
|
48
|
+
status_time = Time.now + 60.seconds
|
29
49
|
while true
|
30
50
|
time_start = Time.now # Remember start time so we can throttle
|
31
51
|
# Get all entries that are ready and decommutation hasn't started
|
@@ -34,7 +54,6 @@ class DartDecommutator
|
|
34
54
|
where("id % #{@num_workers} = #{@worker_id}").in_batches do |group|
|
35
55
|
group.each do |ple|
|
36
56
|
begin
|
37
|
-
# TODO - Optimize and cache meta and system config and packet config lookup
|
38
57
|
meta_ple = get_meta_ple(ple)
|
39
58
|
next unless meta_ple
|
40
59
|
system_meta = get_system_meta(ple, meta_ple)
|
@@ -48,12 +67,28 @@ class DartDecommutator
|
|
48
67
|
# If we timeout this code will simply exit the application
|
49
68
|
wait_for_ready_packet_config(packet_config)
|
50
69
|
decom_packet(ple, packet, packet_config)
|
70
|
+
|
71
|
+
# Update status
|
72
|
+
if Time.now > status_time
|
73
|
+
status_time = Time.now + 60.seconds
|
74
|
+
status = Status.first
|
75
|
+
if (Time.now - @status.message_time) <= 60.0
|
76
|
+
status.decom_message = @status.message
|
77
|
+
status.decom_message_time = @status.message_time
|
78
|
+
status.save!
|
79
|
+
end
|
80
|
+
if @status.count > 0 or @status.error_count > 0
|
81
|
+
Status.update_counters(status.id, :decom_count => @status.count, :decom_error_count => @status.error_count)
|
82
|
+
@status.count = 0
|
83
|
+
@status.error_count = 0
|
84
|
+
end
|
85
|
+
end
|
51
86
|
rescue => err
|
52
|
-
|
53
|
-
Cosmos::Logger.error(err.formatted)
|
87
|
+
handle_error("PLE:#{ple.id}:ERROR\n#{err.formatted}")
|
54
88
|
end
|
55
89
|
end # each ple
|
56
90
|
end # batches
|
91
|
+
|
57
92
|
# Throttle to no faster than 1 Hz
|
58
93
|
delta = Time.now - time_start
|
59
94
|
sleep(1 - delta) if delta < 1 && delta > 0
|
@@ -65,46 +100,61 @@ class DartDecommutator
|
|
65
100
|
protected
|
66
101
|
|
67
102
|
def get_meta_ple(ple)
|
103
|
+
return @cached_meta_ple if @cached_meta_ple and @cached_meta_ple.id == ple.meta_id
|
104
|
+
|
68
105
|
if ple.meta_id != ple.id
|
69
|
-
PacketLogEntry.find(ple.meta_id)
|
106
|
+
meta_ple = PacketLogEntry.find(ple.meta_id)
|
70
107
|
else
|
71
|
-
ple
|
108
|
+
meta_ple = ple
|
72
109
|
end
|
110
|
+
@cached_meta_ple = meta_ple
|
111
|
+
return meta_ple
|
73
112
|
rescue => err
|
74
113
|
ple.decom_state = PacketLogEntry::NO_META_PLE
|
75
114
|
ple.save!
|
76
|
-
|
115
|
+
handle_error("PLE:#{ple.id}:#{ple.decom_state_string}")
|
77
116
|
nil
|
78
117
|
end
|
79
118
|
|
80
119
|
def get_system_meta(ple, meta_ple)
|
120
|
+
return @cached_system_meta if @cached_system_meta and @cached_system_meta_id == meta_ple.id
|
121
|
+
|
81
122
|
system_meta = read_packet_from_ple(meta_ple)
|
82
|
-
|
123
|
+
if system_meta
|
124
|
+
@cached_system_meta_id = meta_ple.id
|
125
|
+
@cached_system_meta = system_meta
|
126
|
+
return system_meta
|
127
|
+
end
|
83
128
|
|
84
129
|
ple.decom_state = PacketLogEntry::NO_META_PACKET
|
85
130
|
ple.save!
|
86
|
-
|
131
|
+
handle_error("PLE:#{ple.id}:#{ple.decom_state_string}")
|
87
132
|
nil
|
88
133
|
end
|
89
134
|
|
90
135
|
def get_system_config(ple, system_meta)
|
91
136
|
system_config_name = system_meta.read("CONFIG")
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
137
|
+
if @cached_system_config and @cached_system_config.name == system_config_name
|
138
|
+
system_config = @cached_system_config
|
139
|
+
else
|
140
|
+
system_config = SystemConfig.where("name = ?", system_config_name).first
|
141
|
+
unless system_config
|
142
|
+
begin
|
143
|
+
# Try to create a new SystemConfig since it didn't exist
|
144
|
+
system_config = SystemConfig.create(:name => system_config_name)
|
145
|
+
rescue
|
146
|
+
# Another thread probably already created it - Try to get it one more time
|
147
|
+
system_config = SystemConfig.where("name = ?", system_config_name).first
|
148
|
+
end
|
100
149
|
end
|
101
150
|
end
|
102
151
|
unless system_config
|
103
152
|
ple.decom_state = PacketLogEntry::NO_SYSTEM_CONFIG
|
104
153
|
ple.save!
|
105
|
-
|
154
|
+
handle_error("PLE:#{ple.id}:#{ple.decom_state_string}")
|
106
155
|
return nil
|
107
156
|
end
|
157
|
+
@cached_system_config = system_config
|
108
158
|
|
109
159
|
# Switch to this system_config
|
110
160
|
begin
|
@@ -113,7 +163,7 @@ class DartDecommutator
|
|
113
163
|
Cosmos::Logger.error("Could not load system_config: #{system_config_name}")
|
114
164
|
ple.decom_state = PacketLogEntry::NO_CONFIG
|
115
165
|
ple.save!
|
116
|
-
|
166
|
+
handle_error("PLE:#{ple.id}:#{ple.decom_state_string}")
|
117
167
|
return nil
|
118
168
|
end
|
119
169
|
system_config
|
@@ -125,7 +175,7 @@ class DartDecommutator
|
|
125
175
|
|
126
176
|
ple.decom_state = PacketLogEntry::NO_PACKET
|
127
177
|
ple.save!
|
128
|
-
|
178
|
+
handle_error("PLE:#{ple.id}:#{ple.decom_state_string}")
|
129
179
|
nil
|
130
180
|
end
|
131
181
|
|
@@ -141,14 +191,14 @@ class DartDecommutator
|
|
141
191
|
setup_packet_config(packet, packet_id, packet_config)
|
142
192
|
Cosmos::Logger.info("Successfully Created PacketConfig: #{packet.config_name}")
|
143
193
|
rescue => err
|
144
|
-
|
194
|
+
handle_error(err.formatted)
|
145
195
|
# Another thread probably already created it - Try to get it one more time
|
146
196
|
packet_config = PacketConfig.where("packet_id = ? and name = ?", packet_id, packet.config_name).first
|
147
197
|
end
|
148
198
|
unless packet_config
|
149
199
|
ple.decom_state = PacketLogEntry::NO_PACKET_CONFIG
|
150
200
|
ple.save!
|
151
|
-
|
201
|
+
handle_error("PLE:#{ple.id}:#{ple.decom_state_string}")
|
152
202
|
return nil
|
153
203
|
end
|
154
204
|
packet_config
|
@@ -167,7 +217,7 @@ class DartDecommutator
|
|
167
217
|
packet_config.reload
|
168
218
|
|
169
219
|
if (Time.now - ready_wait_start) > PACKET_CONFIG_READY_TIMEOUT
|
170
|
-
|
220
|
+
handle_error("Timeout waiting for ready on PacketConfig:#{packet_config.id}")
|
171
221
|
exit(1)
|
172
222
|
end
|
173
223
|
end
|
@@ -211,6 +261,7 @@ class DartDecommutator
|
|
211
261
|
row = model.new
|
212
262
|
row.time = ple.time
|
213
263
|
row.ple_id = ple.id
|
264
|
+
row.packet_log_id = ple.packet_log_id
|
214
265
|
row.meta_id = ple.meta_id
|
215
266
|
row.reduced_state = INITIALIZING
|
216
267
|
table_values.each_with_index do |value, index|
|
@@ -230,6 +281,14 @@ class DartDecommutator
|
|
230
281
|
# The log entry has been decommutated, mark COMPLETE
|
231
282
|
ple.decom_state = PacketLogEntry::COMPLETE
|
232
283
|
ple.save!
|
284
|
+
@status.count += 1
|
233
285
|
Cosmos::Logger.debug("PLE:#{ple.id}:#{ple.decom_state_string}")
|
234
286
|
end
|
287
|
+
|
288
|
+
def handle_error(message)
|
289
|
+
Cosmos::Logger.error(message)
|
290
|
+
@status.error_count += 1
|
291
|
+
@status.message = message
|
292
|
+
@status.message_time = Time.now
|
293
|
+
end
|
235
294
|
end
|
@@ -80,10 +80,12 @@ class DartImporter
|
|
80
80
|
Cosmos::Logger.info("First and Last Packet in File not in database")
|
81
81
|
|
82
82
|
# Check if time range of packets is not present in database
|
83
|
-
ple = PacketLogEntry.where("time >= ?
|
83
|
+
ple = PacketLogEntry.where("time >= ? and time <= ?", first_packet.received_time, last_packet.received_time).first
|
84
84
|
if !ple # Can go fast if not present at all
|
85
85
|
Cosmos::Logger.info(" Fast Import Enabled...")
|
86
86
|
fast = true
|
87
|
+
else
|
88
|
+
Cosmos::Logger.warn("Time range already in database. Will verify each packet before adding")
|
87
89
|
end
|
88
90
|
else
|
89
91
|
Cosmos::Logger.warn("File partially in database. Will verify each packet before adding")
|
@@ -97,6 +99,8 @@ class DartImporter
|
|
97
99
|
# Read File and Create PacketLogEntries
|
98
100
|
count = 0
|
99
101
|
meta_id = nil
|
102
|
+
ple_data = ""
|
103
|
+
ple_data_count = 0
|
100
104
|
plr.open(filename)
|
101
105
|
data_offset = plr.bytes_read
|
102
106
|
plr.each(filename) do |packet|
|
@@ -117,27 +121,39 @@ class DartImporter
|
|
117
121
|
|
118
122
|
# No PacketLogEntry was found so create one from scratch
|
119
123
|
unless ple
|
120
|
-
ple = PacketLogEntry.new
|
121
|
-
ple.target_id = target_id
|
122
|
-
ple.packet_id = packet_id
|
123
|
-
ple.time = packet.received_time
|
124
|
-
ple.packet_log_id = packet_log.id
|
125
|
-
ple.data_offset = data_offset
|
126
|
-
ple.meta_id = meta_id
|
127
|
-
ple.is_tlm = is_tlm
|
128
|
-
ple.ready = true
|
129
|
-
ple.save!
|
130
|
-
count += 1
|
131
|
-
|
132
124
|
# SYSTEM META packets are special in that their meta_id is their own
|
133
125
|
# PacketLogEntry ID from the database. All other packets have meta_id
|
134
126
|
# values which point back to the last SYSTEM META PacketLogEntry ID.
|
135
127
|
if target_name == 'SYSTEM'.freeze and packet_name == 'META'.freeze
|
128
|
+
if ple_data.length > 0
|
129
|
+
ActiveRecord::Base.connection.execute("INSERT INTO packet_log_entries (target_id, packet_id, time, packet_log_id, data_offset, meta_id, is_tlm, ready) VALUES #{ple_data}")
|
130
|
+
ple_data.clear
|
131
|
+
ple_data_count = 0
|
132
|
+
end
|
133
|
+
|
134
|
+
ple = PacketLogEntry.new
|
135
|
+
ple.target_id = target_id
|
136
|
+
ple.packet_id = packet_id
|
137
|
+
ple.time = packet.received_time
|
138
|
+
ple.packet_log_id = packet_log.id
|
139
|
+
ple.data_offset = data_offset
|
140
|
+
ple.meta_id = meta_id
|
141
|
+
ple.is_tlm = is_tlm
|
142
|
+
ple.ready = false
|
143
|
+
ple.save!(validate: false)
|
144
|
+
|
136
145
|
# Need to update meta_id for this and all subsequent packets
|
137
146
|
meta_id = ple.id
|
138
147
|
ple.meta_id = meta_id
|
139
|
-
ple.
|
148
|
+
ple.ready = true
|
149
|
+
ple.save!(validate: false)
|
150
|
+
else
|
151
|
+
ple_data << "," if ple_data.length > 0
|
152
|
+
ple_data << "(#{target_id},#{packet_id},'#{packet.received_time.dup.utc.iso8601(6)}',#{packet_log.id},#{data_offset},#{meta_id},#{is_tlm},true)"
|
153
|
+
ple_data_count += 1
|
140
154
|
end
|
155
|
+
|
156
|
+
count += 1
|
141
157
|
else # A PacketLogEntry was found so this packet is skipped
|
142
158
|
# If the packet is a SYSTEM META packet we keep track of the meta_id
|
143
159
|
# for use in subsequent packets that aren't already in the database.
|
@@ -146,8 +162,22 @@ class DartImporter
|
|
146
162
|
meta_id = ple.id
|
147
163
|
end
|
148
164
|
end
|
165
|
+
|
166
|
+
if ple_data_count >= 1000
|
167
|
+
ActiveRecord::Base.connection.execute("INSERT INTO packet_log_entries (target_id, packet_id, time, packet_log_id, data_offset, meta_id, is_tlm, ready) VALUES #{ple_data}")
|
168
|
+
ple_data.clear
|
169
|
+
ple_data_count = 0
|
170
|
+
end
|
171
|
+
|
149
172
|
data_offset = plr.bytes_read
|
150
173
|
end
|
174
|
+
|
175
|
+
if ple_data.length > 0
|
176
|
+
ActiveRecord::Base.connection.execute("INSERT INTO packet_log_entries (target_id, packet_id, time, packet_log_id, data_offset, meta_id, is_tlm, ready) VALUES #{ple_data}")
|
177
|
+
ple_data.clear
|
178
|
+
ple_data_count = 0
|
179
|
+
end
|
180
|
+
|
151
181
|
Cosmos::Logger.info("Added #{count} packet log entries to database")
|
152
182
|
return 0 # Success code
|
153
183
|
end
|
@@ -29,7 +29,13 @@ class DartPacketLogWriter < Cosmos::PacketLogWriter
|
|
29
29
|
@db_queue = Queue.new
|
30
30
|
@sync_count = 0
|
31
31
|
@sync_count_limit = DEFAULT_SYNC_COUNT_LIMIT
|
32
|
-
@
|
32
|
+
@ple_data = ""
|
33
|
+
@sync_ple = nil
|
34
|
+
if @log_type == :TLM
|
35
|
+
@is_tlm = true
|
36
|
+
else
|
37
|
+
@is_tlm = false
|
38
|
+
end
|
33
39
|
|
34
40
|
sync_targets_and_packets()
|
35
41
|
|
@@ -42,6 +48,13 @@ class DartPacketLogWriter < Cosmos::PacketLogWriter
|
|
42
48
|
def shutdown
|
43
49
|
super()
|
44
50
|
Cosmos.kill_thread(self, @db_thread)
|
51
|
+
handle_sync_ple()
|
52
|
+
queue_ple_data()
|
53
|
+
while @db_queue.length > 0
|
54
|
+
ple_data = @db_queue.pop
|
55
|
+
break if ple_data.nil?
|
56
|
+
ActiveRecord::Base.connection.execute("INSERT INTO packet_log_entries (target_id, packet_id, time, packet_log_id, data_offset, meta_id, is_tlm, ready) VALUES #{ple_data}")
|
57
|
+
end
|
45
58
|
end
|
46
59
|
|
47
60
|
# Kick the database update thread to allow it to quit
|
@@ -54,33 +67,75 @@ class DartPacketLogWriter < Cosmos::PacketLogWriter
|
|
54
67
|
|
55
68
|
# Override the default new file hook to create a PacketLog entry in the database
|
56
69
|
def start_new_file_hook(packet)
|
57
|
-
# When we create a new file we
|
58
|
-
|
59
|
-
|
60
|
-
|
70
|
+
# When we create a new file we write out any queued ple_data
|
71
|
+
if @ple_data.length > 0
|
72
|
+
@db_queue << @ple_data.clone
|
73
|
+
@ple_data.clear
|
74
|
+
@sync_count = 0
|
75
|
+
end
|
61
76
|
|
62
77
|
packet_log = PacketLog.new
|
63
78
|
packet_log.filename = @filename.clone
|
64
|
-
|
65
|
-
packet_log.is_tlm = true
|
66
|
-
else
|
67
|
-
packet_log.is_tlm = false
|
68
|
-
end
|
79
|
+
packet_log.is_tlm = @is_tlm
|
69
80
|
packet_log.save!
|
70
81
|
@packet_log_id = packet_log.id
|
71
82
|
super(packet)
|
72
83
|
end
|
73
84
|
|
85
|
+
def queue_ple_data
|
86
|
+
if @ple_data.length > 0
|
87
|
+
@db_queue << @ple_data.clone
|
88
|
+
@ple_data.clear
|
89
|
+
@sync_count = 0
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def handle_sync_ple
|
94
|
+
if @sync_ple
|
95
|
+
@file.fsync if @file
|
96
|
+
@sync_ple.ready = true
|
97
|
+
@sync_ple.save!
|
98
|
+
@sync_ple = nil
|
99
|
+
queue_ple_data()
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
74
103
|
# Override the default pre write hook to pop a message on the queue which
|
75
104
|
# will be processed by the database thread. This also writes out the log
|
76
105
|
# files to disk periodically for use by other DART processes.
|
77
106
|
def pre_write_entry_hook(packet)
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
107
|
+
handle_sync_ple()
|
108
|
+
|
109
|
+
# SYSTEM META packets are special in that their meta_id is their own
|
110
|
+
# PacketLogEntry ID from the database. All other packets have meta_id
|
111
|
+
# values which point back to the last SYSTEM META PacketLogEntry ID.
|
112
|
+
target_id, packet_id = lookup_target_and_packet_id(packet.target_name, packet.packet_name, @is_tlm)
|
113
|
+
if packet.target_name == 'SYSTEM'.freeze and packet.packet_name == 'META'.freeze
|
114
|
+
ple = PacketLogEntry.new
|
115
|
+
ple.target_id = target_id
|
116
|
+
ple.packet_id = packet_id
|
117
|
+
ple.time = packet.received_time
|
118
|
+
ple.packet_log_id = @packet_log_id
|
119
|
+
ple.data_offset = @file_size
|
120
|
+
ple.meta_id = @meta_id
|
121
|
+
ple.is_tlm = @is_tlm
|
122
|
+
ple.ready = false
|
123
|
+
ple.save!
|
124
|
+
@meta_id = ple.id
|
125
|
+
ple.meta_id = @meta_id
|
126
|
+
ple.save!
|
127
|
+
@sync_ple = ple
|
128
|
+
else
|
129
|
+
@sync_count += 1
|
130
|
+
if @sync_count > @sync_count_limit
|
131
|
+
@file.fsync
|
132
|
+
@db_queue << @ple_data.clone
|
133
|
+
@ple_data.clear
|
134
|
+
@sync_count = 0
|
135
|
+
end
|
136
|
+
@ple_data << "," if @ple_data.length > 0
|
137
|
+
@ple_data << "(#{target_id},#{packet_id},'#{packet.received_time.dup.utc.iso8601(6)}',#{@packet_log_id},#{@file_size},#{@meta_id},#{@is_tlm},true)"
|
82
138
|
end
|
83
|
-
@db_queue << [packet.target_name, packet.packet_name, packet.received_time, @file_size, @packet_log_id, @sync_count]
|
84
139
|
end
|
85
140
|
|
86
141
|
# Build the target / packet table lookup table and then wait on the queue
|
@@ -88,52 +143,15 @@ class DartPacketLogWriter < Cosmos::PacketLogWriter
|
|
88
143
|
# PacketLogEntry table. Each entry identifies a packet in the log file by
|
89
144
|
# its target, packet, time, and data offset (among other things).
|
90
145
|
def db_thread_body
|
91
|
-
if @log_type == :TLM
|
92
|
-
is_tlm = true
|
93
|
-
else
|
94
|
-
is_tlm = false
|
95
|
-
end
|
96
|
-
|
97
146
|
while true
|
98
147
|
begin
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
# since we know the packets have been written to disk.
|
103
|
-
if sync_count == 0 or sync_count.nil?
|
104
|
-
PacketLogEntry.where("id" => @not_ready_ple_ids).update_all(ready: true)
|
105
|
-
@not_ready_ple_ids.clear
|
106
|
-
end
|
107
|
-
return if @cancel_threads or sync_count.nil?
|
148
|
+
ple_data = @db_queue.pop
|
149
|
+
return if @cancel_threads or ple_data.nil?
|
150
|
+
ActiveRecord::Base.connection.execute("INSERT INTO packet_log_entries (target_id, packet_id, time, packet_log_id, data_offset, meta_id, is_tlm, ready) VALUES #{ple_data}")
|
108
151
|
rescue ThreadError
|
109
152
|
# This can happen when the thread is killed
|
110
153
|
return
|
111
154
|
end
|
112
|
-
|
113
|
-
target_id, packet_id = lookup_target_and_packet_id(target_name, packet_name, is_tlm)
|
114
|
-
|
115
|
-
ple = PacketLogEntry.new
|
116
|
-
ple.target_id = target_id
|
117
|
-
ple.packet_id = packet_id
|
118
|
-
ple.time = time
|
119
|
-
ple.packet_log_id = packet_log_id
|
120
|
-
ple.data_offset = data_offset
|
121
|
-
ple.meta_id = @meta_id
|
122
|
-
ple.is_tlm = is_tlm
|
123
|
-
ple.ready = false
|
124
|
-
ple.save!
|
125
|
-
|
126
|
-
# SYSTEM META packets are special in that their meta_id is their own
|
127
|
-
# PacketLogEntry ID from the database. All other packets have meta_id
|
128
|
-
# values which point back to the last SYSTEM META PacketLogEntry ID.
|
129
|
-
if target_name == 'SYSTEM'.freeze and packet_name == 'META'.freeze
|
130
|
-
# Need to update meta_id for this and all subsequent packets
|
131
|
-
@meta_id = ple.id
|
132
|
-
ple.meta_id = @meta_id
|
133
|
-
ple.save!
|
134
|
-
end
|
135
|
-
# Remember this new PacketLogEntry so we can mark it ready later
|
136
|
-
@not_ready_ple_ids << ple.id
|
137
155
|
end
|
138
156
|
end
|
139
157
|
end
|