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

+3 -34
View File
@@ -1,5 +1,5 @@
import { isLoggedIn } from "/js/auth.js";
import { onRouteChanged, requestReroute, requestGnssFollow, notifyRouteProgress } from "/js/panels.js";
import { onRouteChanged, requestReroute, notifyRouteProgress } from "/js/panels.js";
import { elevationAt } from "/js/dem.js";
// The car's dashboard over the map, off the CAN signals (GET /api/can,
@@ -176,7 +176,6 @@ export class DashboardControl {
this._lastAt = 0;
this._offFixes = 0;
this._sentKm = undefined; // the new route drawn by the next fix
this._simLabel();
}));
this._trace = []; // [lon, lat] fixes TRACE_STEP_M apart, for /api/road
this._road = null; // its last answer
@@ -299,8 +298,7 @@ export class DashboardControl {
<label class="live-tracker__row"><input type="checkbox" data-widget="navigation"> Speed limit &amp; ahead (route)</label>
<label class="live-tracker__row"><input type="checkbox" data-widget="banner"> Navigation banner (next turn)</label>
<label class="live-tracker__row">Background <input type="range" class="dash-opacity" min="0" max="1" step="0.05"></label>
<button type="button" class="dash-sim">Simulate driving from a random place</button>
<p class="live-panel__status dash-sim-status" hidden></p>
<a class="dash-sim" href="/sim.html" target="_blank">GNSS simulation ↗</a>
</div>`;
this._toggle = li.querySelector(".overlays-panel__toggle");
this._status = li.querySelector(".live-panel__status");
@@ -331,36 +329,6 @@ export class DashboardControl {
this._save();
this._card?.style.setProperty("--dash-alpha", opacity.value);
});
this._simButton = li.querySelector(".dash-sim");
this._simStatus = li.querySelector(".dash-sim-status");
this._simButton.addEventListener("click", () => this._simulate(!this._simRunning));
this._simulate(null);
}
// GNSS simulation on the server (POST/DELETE /api/sim/gnss): random
// driving from a random place in the offline countries, the GNSS control
// turned on to follow it; on = true / false, null = just read the state.
async _simulate(on) {
// along the route when there is one (the shared trip's), else from a random place
const options = on === true ? { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(this._route ? { trip: true } : {}) }
: on === false ? { method: "DELETE" } : {};
try {
const response = await fetch("/api/sim/gnss", options);
const state = await response.json();
if (!response.ok) throw new Error(state.error || `HTTP ${response.status}`);
this._simRunning = state.running;
if (on === true && state.running) requestGnssFollow(); // the map follows the simulated position
this._simStatus.hidden = !state.error;
this._simStatus.textContent = state.error ? `Simulation stopped: ${state.error}` : "";
} catch (e) {
this._simStatus.hidden = false;
this._simStatus.textContent = `Simulation: ${e.message}`;
}
this._simLabel();
}
_simLabel() {
if (this._simButton) this._simButton.textContent = this._simRunning ? "Stop the simulation" : this._route ? "Simulate driving the route" : "Simulate driving from a random place";
}
_save() {
@@ -406,6 +374,7 @@ export class DashboardControl {
return [key, s && now - s.at < STALE_S + 1 ? s.value : null];
}));
this._updateCourse(this._values);
this._simRunning = !!data.simulated; // /sim.html runs it
if (this._simRunning) await this._simulateTerrain();
this._navigate();
this._status.textContent = this._simRunning ? "Simulated GNSS" : data.available ? "" : "CAN is off on this server";