CAN bus recorded on the server into ASAM MDF4: can-recorder (Rust, can-recorder/) reads every interface's SocketCAN frames with the kernel's timestamp and writes a finished .mf4 every 5 min (data/can_rec/<UTC start>.mf4, .part then renamed: a power cut loses at most the last segment), its own minimal MDF 4.10 writer in the CANedge CAN_DataFrame layout (mdf4-rs's lacks the bus-event flags and components: asammdf couldn't DBC-decode it) — checked in asammdf 8.8.35 against candump, every frame, < 0.002 ms, DBC decoding works; lib/maptool/can_recorder.rb starts and stops it, GET/POST/DELETE /api/can/recording, the files by GET /api/can/recordings/<name>; /trace.html's 'Recording on the server (MF4)'; built in its own Dockerfile stage (rust:1.100-slim-trixie)
CI / check (push) Successful in 23s
CI / deploy (push) Successful in 1m37s

This commit is contained in:
randy committed 2026-12-02 19:35:54 +01:00
1 parent 712c6bf7ad
commit 60d7c825fc
13 files changed
+980

No files matched your search

+36
View File
@@ -13,6 +13,7 @@ require_relative "lib/maptool/routing"
require_relative "lib/maptool/mqtt_client"
require_relative "lib/maptool/can"
require_relative "lib/maptool/can_discovery"
require_relative "lib/maptool/can_recorder"
require_relative "lib/maptool/gnss_sim"
require_relative "lib/maptool/trip"
require_relative "lib/maptool/trip_log"
@@ -463,6 +464,9 @@ module Maptool
warn "can: #{CAN_CONFIG_PATH}: #{e.message} — CAN off"
[nil, nil]
end
# The bus recorded on the server into MF4 files (/trace.html, can-recorder/).
CAN_RECORDER = Can::Recorder.new(File.join(DATA_DIR, "can_rec"), CAN_CONFIG ? CAN_CONFIG.fetch("interfaces", []) : [])
at_exit { CAN_RECORDER.stop }
# Simulated driving (lib/maptool/gnss_sim.rb) in place of the GNSS node.
GNSS_SIM = GnssSim.new(VALHALLA_URL)
@@ -1402,6 +1406,38 @@ module Maptool
json snapshot.merge(available: !CAN_CONFIG.nil?, simulated: GNSS_SIM.running?)
end
# Recording the bus into MF4 files on the server: GET whether it runs and
# the files (newest first), POST starts it, DELETE stops it (the segment
# being recorded is written); a file by GET /api/can/recordings/<name>.
get "/api/can/recording" do
require_login!
json available: !CAN_CONFIG.nil?, running: CAN_RECORDER.running?, started_at: CAN_RECORDER.started_at,
error: CAN_RECORDER.error, files: CAN_RECORDER.files
end
post "/api/can/recording" do
require_login!
halt 409, json(error: "CAN is off: no data/can.json on this server") unless CAN_CONFIG
begin
CAN_RECORDER.start
rescue SystemCallError => e
halt 500, json(error: CAN_RECORDER.error || e.message)
end
json running: CAN_RECORDER.running?
end
delete "/api/can/recording" do
require_login!
CAN_RECORDER.stop
json running: CAN_RECORDER.running?, error: CAN_RECORDER.error
end
get "/api/can/recordings/:name" do
require_login!
path = CAN_RECORDER.path(params[:name]) or halt 404
send_file path, disposition: "attachment", type: "application/octet-stream"
end
# The GNSS simulation: POST {"start": [lon, lat]} drives randomly from
# there, POST {} from a random place in the offline countries, DELETE
# stops it, GET says whether it's on (and why it stopped).