Shared trip: one itinerary per server (data/trip.json, GET/PUT /api/trip, routed server-side), the route panel edits it when logged in and polls other screens' changes in without moving the camera; the GNSS simulation skips trips under 1 km and starts elsewhere when it can't get on from a road island; the car's server updates itself from a topbar button (SELF_UPDATE=1: newer main with CI passed → bin/update-maptool.sh via maptool-update.path); Android Auto and the trip's next steps in TODO
This commit is contained in:
1 parent
5f4c7c6ee8
commit
17891c53b5
16 files changed
+513
-5
No files matched your search
@@ -13,6 +13,8 @@ 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/trip"
|
||||
require_relative "lib/maptool/updater"
|
||||
require_relative "lib/maptool/sync"
|
||||
require "ipaddr"
|
||||
require_relative "lib/maptool/live_store"
|
||||
@@ -492,6 +494,33 @@ module Maptool
|
||||
redirect "/", 303
|
||||
end
|
||||
|
||||
# Self-update (lib/maptool/updater.rb), on the car's server only
|
||||
# (SELF_UPDATE=1): GET says whether main has a newer commit that passed
|
||||
# CI, POST asks the host to install it (bin/update-maptool.sh).
|
||||
SELF_UPDATE = ENV["SELF_UPDATE"] == "1"
|
||||
UPDATE_REPO = ENV.fetch("UPDATE_REPO", "randy/maptool")
|
||||
|
||||
get "/api/update" do
|
||||
require_login!
|
||||
halt json(enabled: false) unless SELF_UPDATE
|
||||
|
||||
latest = Updater.latest(GITEA_URL, UPDATE_REPO)
|
||||
available = !!latest && latest[:ci] == "success" && latest[:sha] && !latest[:sha].start_with?(REVISION)
|
||||
json enabled: true, current: REVISION, latest: latest&.dig(:sha)&.slice(0, 7), ci: latest&.dig(:ci),
|
||||
available: available, status: Updater.status(DATA_DIR)
|
||||
end
|
||||
|
||||
post "/api/update" do
|
||||
require_login!
|
||||
halt 404, json(error: "self-update is off on this server") unless SELF_UPDATE
|
||||
|
||||
latest = Updater.latest(GITEA_URL, UPDATE_REPO)
|
||||
halt 409, json(error: "no newer version that passed CI") unless latest && latest[:ci] == "success" && !latest[:sha].start_with?(REVISION)
|
||||
|
||||
Updater.request(DATA_DIR, latest[:sha])
|
||||
json requested: latest[:sha][0, 7]
|
||||
end
|
||||
|
||||
get "/api/health" do
|
||||
json status: "ok", revision: REVISION
|
||||
end
|
||||
@@ -680,6 +709,34 @@ module Maptool
|
||||
halt 503, json(error: e.message)
|
||||
end
|
||||
|
||||
# The shared trip (lib/maptool/trip.rb): every screen polls it
|
||||
# (?version=N: 204 while it's still N) and edits it with PUT
|
||||
# {points: [{lngLat, name, nav}], vehicle, avoid, editing}, routed here.
|
||||
# Logged in only — it's this server's own itinerary.
|
||||
TRIP_STORE = TripStore.new(File.join(DATA_DIR, "trip.json"))
|
||||
|
||||
get "/api/trip" do
|
||||
require_login!
|
||||
trip = TRIP_STORE.get
|
||||
halt 204 if params[:version] && params[:version].to_i == trip[:version]
|
||||
|
||||
json trip
|
||||
end
|
||||
|
||||
put "/api/trip" do
|
||||
require_login!
|
||||
body = JSON.parse(request.body.read, symbolize_names: true)
|
||||
halt 400, json(error: "points must be a list of {lngLat: [lon, lat]}") unless body[:points].is_a?(Array) && body[:points].all? { |p| p.is_a?(Hash) && p[:lngLat].is_a?(Array) }
|
||||
|
||||
json(TRIP_STORE.update(points: body[:points], vehicle: body[:vehicle], avoid: body[:avoid], editing: body[:editing]) do |locations, vehicle, avoid|
|
||||
Routing.route(VALHALLA_URL, locations, Routing.vehicle(DATA_DIR, vehicle), avoid.transform_keys(&:to_s))
|
||||
end)
|
||||
rescue JSON::ParserError
|
||||
halt 400, json(error: "invalid JSON")
|
||||
rescue ArgumentError, TypeError, KeyError
|
||||
halt 400, json(error: "invalid points")
|
||||
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
|
||||
|
||||
Reference in new issue
Block a user