GNSS simulation on its own diagnostics page (/sim.html: drive the trip's route or randomly, stop, simulated time, the position and the trip); along the route with a detour now and then (300–800 m off every 3–8 km, routed by Valhalla); simulated time 1–20× with the fixes carrying the simulation's clock, so a recorded trip keeps real speeds (PUT /api/sim/gnss); /api/can says simulated
CI / check (push) Successful in 21s
CI / deploy (push) Successful in 17s

This commit is contained in:
randy committed 2026-12-01 02:31:31 +01:00
1 parent 7d72e9eb63
commit 0c809b3e2b
9 files changed
+265 -46

No files matched your search

+20 -4
View File
@@ -415,7 +415,8 @@ module Maptool
end
return unless fix && fix[:lat] && fix[:lon]
TRIP_LOG.record(fix[:lon], fix[:lat], fix[:alt], at) if TRIP_LOG.active?
# a fix's own time when it has one (the simulation's clock, sped up)
TRIP_LOG.record(fix[:lon], fix[:lat], fix[:alt], gnss[:time].is_a?(Numeric) ? gnss[:time] : at) if TRIP_LOG.active?
# off the shared trip's route: routed again from here (TripStore#follow)
TRIP_STORE.follow([fix[:lon], fix[:lat]], speed: fix[:speed], hdop: fix[:hdop]) do |locations, vehicle, avoid|
@@ -498,6 +499,11 @@ module Maptool
erb :symbols, layout: false
end
# The GNSS simulation's controls (its API below, login).
get "/sim.html" do
erb :sim, layout: false
end
# Every status endpoint on one full-screen page (they need the login).
get "/status.html" do
erb :status, layout: false
@@ -1361,7 +1367,8 @@ module Maptool
snapshot = CAN_STORE.snapshot
units = CAN_DECODER ? CAN_DECODER.units : {}
snapshot[:signals] = snapshot[:signals].to_h { |name, signal| [name, units[name] ? signal.merge(unit: units[name]) : signal] }
json snapshot.merge(available: !CAN_CONFIG.nil?)
# simulated: the GNSS simulation (/sim.html) stands in for gnss.*
json snapshot.merge(available: !CAN_CONFIG.nil?, simulated: GNSS_SIM.running?)
end
# The GNSS simulation: POST {"start": [lon, lat]} drives randomly from
@@ -1369,7 +1376,16 @@ module Maptool
# stops it, GET says whether it's on (and why it stopped).
get "/api/sim/gnss" do
require_login!
json running: GNSS_SIM.running?, error: GNSS_SIM.error
json running: GNSS_SIM.running?, error: GNSS_SIM.error, speedup: GNSS_SIM.speedup, speedups: GnssSim::SPEEDUPS
end
# {"speedup": 1|2|5|10|20}: the simulation's time, faster (also while it runs).
put "/api/sim/gnss" do
require_login!
GNSS_SIM.speedup = JSON.parse(request.body.read)["speedup"]
json running: GNSS_SIM.running?, error: GNSS_SIM.error, speedup: GNSS_SIM.speedup, speedups: GnssSim::SPEEDUPS
rescue JSON::ParserError
halt 400, json(error: "invalid JSON")
end
post "/api/sim/gnss" do
@@ -1390,7 +1406,7 @@ module Maptool
CAN_STORE.override_prefix = "gnss."
GNSS_SIM.start(lon, lat, bboxes: bboxes, route: route) do |fix|
CAN_STORE.put(fix.transform_keys { |key| "gnss.#{key}" })
CAN_STORE.put(fix.except(:time).transform_keys { |key| "gnss.#{key}" })
App.gnss_update(fix)
end
json running: true