Terrain closes by itself again: the road's surface only off the route (back on it the last road's stayed, so the view never closed); while it's open the top row's Limit shows the surface. Navigated, the planned route behind the car thin and dashed under the trip log's track (the line and its casing clear there). The scale back over the map, bottom left. CAN recordings older than CAN_REC_KEEP_HOURS (24 by default, 0 keeps all) deleted when listed and every segment while recording. TODO tidied
This commit is contained in:
1 parent
21ad6c0c21
commit
f981b80599
9 files changed
+80
-34
No files matched your search
@@ -6,15 +6,19 @@ module Maptool
|
||||
# writes every interface's frames into ASAM MDF4 files, one per segment
|
||||
# (`<dir>/<UTC start>.mf4`, asammdf with a DBC, CSS Electronics' tools);
|
||||
# this starts it, stops it (SIGTERM: the segment being recorded is
|
||||
# written) and lists what it wrote.
|
||||
# written) and lists what it wrote. Segments older than `keep` seconds
|
||||
# go (it's diagnostics, ~85 MB an hour at 1000 frames/s): when listed and
|
||||
# every segment while recording; `keep` nil keeps them all.
|
||||
class Recorder
|
||||
NAME = /\A\d{8}-\d{6}\.mf4\z/
|
||||
STOP_WAIT = 10 # s for the last segment to be written
|
||||
|
||||
attr_reader :dir, :error, :started_at
|
||||
|
||||
def initialize(dir, interfaces, binary: ENV.fetch("CAN_RECORDER", "can-recorder"), segment: 300)
|
||||
def initialize(dir, interfaces, binary: ENV.fetch("CAN_RECORDER", "can-recorder"), segment: 300,
|
||||
keep: (ENV.fetch("CAN_REC_KEEP_HOURS", "24").to_f * 3600).then { |s| s.positive? ? s : nil })
|
||||
@dir = dir
|
||||
@keep = keep
|
||||
@interfaces = interfaces
|
||||
@binary = binary
|
||||
@segment = segment
|
||||
@@ -35,6 +39,8 @@ module Maptool
|
||||
@pid = pid
|
||||
@started_at = Time.now.to_f
|
||||
@error = nil
|
||||
waiter = @waiter
|
||||
Thread.new { loop { prune; break if waiter.join(@segment) } }
|
||||
rescue SystemCallError => e
|
||||
@error = "#{@binary}: #{e.message}"
|
||||
raise
|
||||
@@ -57,12 +63,25 @@ module Maptool
|
||||
def files
|
||||
return [] unless Dir.exist?(@dir)
|
||||
|
||||
prune
|
||||
Dir.children(@dir).grep(NAME).sort.reverse.map do |name|
|
||||
stat = File.stat(File.join(@dir, name))
|
||||
{ name: name, size: stat.size, at: stat.mtime.to_f }
|
||||
end
|
||||
end
|
||||
|
||||
def prune
|
||||
return unless @keep && Dir.exist?(@dir)
|
||||
|
||||
old = Time.now - @keep
|
||||
Dir.children(@dir).grep(NAME).each do |name|
|
||||
path = File.join(@dir, name)
|
||||
File.delete(path) if File.mtime(path) < old
|
||||
rescue SystemCallError
|
||||
nil # gone meanwhile
|
||||
end
|
||||
end
|
||||
|
||||
def path(name)
|
||||
path = File.join(@dir, name)
|
||||
path if NAME.match?(name) && File.file?(path)
|
||||
|
||||
Reference in new issue
Block a user