Dashboard overlay (Overlays → Live → Dashboard): one inclinometer (compass ring, roll and pitch), speed, the speed limit with an over-limit warning and, on the route, the next limit change, traffic signal, maneuver and its lanes; /api/route gains speed_limits, signals and lanes, POST /api/road gives the driven road's limit; GNSS simulation (random trips over Valhalla) for trying it without the car; the HMC5883L heading in can.json
This commit is contained in:
1 parent
5958ffd153
commit
190a8ad334
13 files changed
+713
-27
No files matched your search
@@ -12,6 +12,7 @@ require_relative "lib/maptool/google_saved"
|
||||
require_relative "lib/maptool/routing"
|
||||
require_relative "lib/maptool/mqtt_client"
|
||||
require_relative "lib/maptool/can"
|
||||
require_relative "lib/maptool/gnss_sim"
|
||||
require_relative "lib/maptool/sync"
|
||||
require "ipaddr"
|
||||
require_relative "lib/maptool/live_store"
|
||||
@@ -398,13 +399,16 @@ module Maptool
|
||||
warn "can: #{CAN_CONFIG_PATH}: #{e.message} — CAN off"
|
||||
[nil, nil]
|
||||
end
|
||||
# Simulated driving (lib/maptool/gnss_sim.rb) in place of the GNSS node.
|
||||
GNSS_SIM = GnssSim.new(VALHALLA_URL)
|
||||
|
||||
if CAN_CONFIG && !test?
|
||||
decoder = CAN_DECODER
|
||||
CAN_CONFIG.fetch("interfaces", []).each do |interface|
|
||||
Thread.new do
|
||||
Can.listen(interface, decoder: decoder, store: CAN_STORE, start_nodes: CAN_CONFIG["nmt_start"]) do |values|
|
||||
gnss = values.filter_map { |name, value| [name.delete_prefix("gnss.").to_sym, value] if name.start_with?("gnss.") }.to_h
|
||||
next if gnss.empty?
|
||||
next if gnss.empty? || GNSS_SIM.running?
|
||||
|
||||
GNSS_LATEST_MUTEX.synchronize do
|
||||
GNSS_LATEST.merge!(gnss)
|
||||
@@ -654,6 +658,21 @@ module Maptool
|
||||
halt 503, json(error: e.message)
|
||||
end
|
||||
|
||||
# The road being driven ({"points": [[lon, lat], ...]}, the last few
|
||||
# fixes): name and speed limit, for the dashboard. Open like /api/route.
|
||||
post "/api/road" do
|
||||
points = JSON.parse(request.body.read)["points"]
|
||||
halt 400, json(error: "points must be a list of [lon, lat]") unless points.is_a?(Array) && points.all?(Array)
|
||||
|
||||
json Routing.road(VALHALLA_URL, points.last(10))
|
||||
rescue JSON::ParserError
|
||||
halt 400, json(error: "invalid JSON")
|
||||
rescue Routing::RouteError => e
|
||||
halt 422, json(error: e.message)
|
||||
rescue Routing::Unavailable => e
|
||||
halt 503, json(error: e.message)
|
||||
end
|
||||
|
||||
# Where the vehicle profile gets in each of `minutes` from `center`
|
||||
# ({"center": [lon, lat], "minutes": [30, 60]}). Open like /api/route.
|
||||
post "/api/isochrone" do
|
||||
@@ -1217,6 +1236,35 @@ module Maptool
|
||||
json snapshot.merge(available: !CAN_CONFIG.nil?)
|
||||
end
|
||||
|
||||
# The GNSS simulation: POST {"start": [lon, lat]} drives randomly from
|
||||
# there, DELETE 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
|
||||
end
|
||||
|
||||
post "/api/sim/gnss" do
|
||||
require_login!
|
||||
lon, lat = JSON.parse(request.body.read)["start"]
|
||||
halt 400, json(error: "start must be [lon, lat]") unless lon.is_a?(Numeric) && lat.is_a?(Numeric)
|
||||
|
||||
CAN_STORE.override_prefix = "gnss."
|
||||
GNSS_SIM.start(lon, lat) do |fix|
|
||||
CAN_STORE.put(fix.transform_keys { |key| "gnss.#{key}" })
|
||||
GNSS_LATEST_MUTEX.synchronize { GNSS_LATEST.merge!(fix, received_at: Time.now.to_f) }
|
||||
end
|
||||
json running: true
|
||||
rescue JSON::ParserError
|
||||
halt 400, json(error: "invalid JSON")
|
||||
end
|
||||
|
||||
delete "/api/sim/gnss" do
|
||||
require_login!
|
||||
GNSS_SIM.stop
|
||||
CAN_STORE.override_prefix = nil
|
||||
json running: false
|
||||
end
|
||||
|
||||
get "/api/live" do
|
||||
require_login!
|
||||
json LIVE_STORE.snapshot.merge(available: !MQTT_URL.empty?)
|
||||
|
||||
Reference in new issue
Block a user