Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
258d35a7a1 | ||
|
|
f161243c61 | ||
|
|
97d1bda09c |
No files matched your search
@@ -334,6 +334,11 @@ already reaches the home MQTT broker (`mqtt_ext`) from ESPHome nodes in `~/espho
|
||||
the car server's trip and position (`/api/trip`, `/api/gnss/position`); only the map and
|
||||
the next maneuver, planning stays on the web. Testable without the car: the tablet runs the
|
||||
Android Auto head unit emulation (DHU)
|
||||
*** [ ] Views by who's driving off which screen: no Android Auto connected → the 16" display
|
||||
shows the 3D follow view (heading-up, pitched) for the driver; Android Auto connected → it
|
||||
streams the 3D navigation to the driver, and the co-driver's display stays 2D (north-up
|
||||
overview, planning). Needs the app to report connected/disconnected to the server (e.g.
|
||||
next to `/api/gnss/position`) and the driving view to switch on it
|
||||
** [ ] A native Android app on Ferrostar (rerouting, Valhalla speed limits, TTS built in) over
|
||||
our Valhalla (`format: osrm`) — only if navigation is wanted on a phone outside the car; the
|
||||
car's 16" display is the Pi's browser either way. Ferrostar's web components are beta: no
|
||||
|
||||
@@ -464,6 +464,13 @@ module Maptool
|
||||
warn "can: #{CAN_CONFIG_PATH}: #{e.message} — CAN off"
|
||||
[nil, nil]
|
||||
end
|
||||
# can.json's "actions": SDO writes /can.html offers beside their node (Can::Sdo::Action).
|
||||
CAN_ACTIONS = (CAN_CONFIG ? CAN_CONFIG.fetch("actions", []) : []).filter_map do |action|
|
||||
Can::Sdo::Action.parse(action)
|
||||
rescue StandardError => e
|
||||
warn "can: #{CAN_CONFIG_PATH}: action #{action.inspect}: #{e.message} — skipped"
|
||||
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 }
|
||||
@@ -1403,7 +1410,24 @@ module Maptool
|
||||
units = CAN_DECODER ? CAN_DECODER.units : {}
|
||||
snapshot[:signals] = snapshot[:signals].to_h { |name, signal| [name, units[name] ? signal.merge(unit: units[name]) : signal] }
|
||||
# simulated: the GNSS simulation (/sim.html) stands in for gnss.*
|
||||
json snapshot.merge(available: !CAN_CONFIG.nil?, simulated: GNSS_SIM.running?)
|
||||
actions = CAN_ACTIONS.map { |a| { name: a.name, node: a.node } }
|
||||
json snapshot.merge(available: !CAN_CONFIG.nil?, simulated: GNSS_SIM.running?, actions: actions)
|
||||
end
|
||||
|
||||
# Runs can.json's action number :n (its place in GET /api/can's actions).
|
||||
post "/api/can/actions/:n" do
|
||||
require_login!
|
||||
halt 409, json(error: "CAN is off: no data/can.json on this server") unless CAN_CONFIG
|
||||
action = CAN_ACTIONS[Integer(params[:n], exception: false) || -1] or halt 404
|
||||
transport = Can::Sdo::SocketTransport.new(CAN_CONFIG.fetch("interfaces").first)
|
||||
begin
|
||||
action.run(Can::Sdo.new(transport))
|
||||
rescue Can::Sdo::Error => e
|
||||
halt 502, json(error: e.message)
|
||||
ensure
|
||||
transport.close
|
||||
end
|
||||
json ok: true
|
||||
end
|
||||
|
||||
# Recording the bus into MF4 files on the server: GET whether it runs and
|
||||
|
||||
+114
-1
@@ -267,7 +267,8 @@ comes from, is one too) of *16 × 10 cells of 80 px* on the navigator's
|
||||
* top row: the manoeuvre (4 cells), then fields (2 cells each);
|
||||
* the map 13 × 8 cells, nothing over it;
|
||||
* right column 3 cells wide: the next stop, km and ETA, the rest to the
|
||||
end, the inclinometer (3 cells), a small compass (1 cell);
|
||||
end, the elevation ahead (3 cells; the inclinometer moved to the
|
||||
Terrain profile, below), a small compass (1 cell);
|
||||
* bottom row: the menu's tabs (Trip, Points, Layers, Search, Menu), the
|
||||
map keys (−, +, 3D, Follow), day/dusk/night — all 80 px, the
|
||||
Android Auto 76 px at least;
|
||||
@@ -284,6 +285,118 @@ Sources: OpenCPN manuals — Dashboard
|
||||
(opencpn-manuals.github.io/main/dashboard), inland ECDIS getting started;
|
||||
the photos of the bridge and the plotter.
|
||||
|
||||
=== Screen profiles (2026-12-02)
|
||||
|
||||
The grid's cells belong to a *profile*: planning (standing, a big map and
|
||||
the trip), road (the Grid above), terrain, later others. A profile is
|
||||
its cells — `{area, widget, options}`, the widget a value field (any
|
||||
signal from the bus or GNSS, label, unit, decimals, amber/red limits), a
|
||||
dial (inclinometer, compass), a chart (elevation), a list (stops), the
|
||||
map, a menu panel or a row of keys — plus the condition that switches it
|
||||
on. Every cell is configurable; the grid differs per screen (16″
|
||||
1280×800 is 16 × 10), so profiles are per screen type. Edited in the app,
|
||||
standing only: tap a cell → widget and signal, drag a corner → its size.
|
||||
|
||||
*Terrain* (artboard GridTerrain): the inclinometer only off-road — on
|
||||
the road its cells show the elevation ahead. A 7 × 8 panel like a menu,
|
||||
the map 9 × 8: roll (a rear view) and pitch (a side view), each with
|
||||
amber past 20° / 25° and red past 1.5× (as `dashboard.js`), the maximum
|
||||
held until reset; heading, the climb and the side slope ahead (DEM), the
|
||||
elevation of the next 2 km; the surface in the top row in place of the
|
||||
limit; "Level here" (the node levels itself, SDO, `/can.html`'s action
|
||||
already), "Reset max", "Road view". It switches itself on when the car
|
||||
leaves paved road (OSM `surface`, `tracktype` ≥ 2, or off any road) or
|
||||
roll/pitch stay past 10° for 10 s, back after 2 km of paved road or by
|
||||
hand; the menu has "Terrain view: automatic / by hand" (automatic by
|
||||
default).
|
||||
|
||||
=== Switches and the keypad: how others do it (research, 2026-12-02)
|
||||
|
||||
Relay modules and lights on the CANopen bus, keys and rotary encoders on
|
||||
a CANopen keypad (RGB LED per key), all driven by maptool.
|
||||
|
||||
[cols="1,3"]
|
||||
|===
|
||||
|Who |How
|
||||
|
||||
|Garmin PowerSwitch (app, custom layouts)
|
||||
|A button: label, icon, colour. Actions per switch: *Toggle*, *Turn On*,
|
||||
*Turn Off*. Button modes: *Normal* (one touch), *Momentary* (on only
|
||||
while touched), *Strobe* (on and off at a chosen interval). A brightness
|
||||
slider for lights.
|
||||
|
||||
|Garmin OnDeck (ActiveCaptain / chartplotter)
|
||||
|*Latching* (on until turned off) or *Momentary* for a selected
|
||||
*duration*; a name, an icon, a switch can be hidden.
|
||||
|
||||
|MaxxECU PDM, CAN keypads (Blink Marine, Grayhill/MoTeC)
|
||||
|Button steps: *Momentary* or *2 to 6 positions* (each press moves to the
|
||||
next state). *Keep state* at power loss: keep the last state or reset to
|
||||
off. LED: a colour per state, a *fault indication* (blinks red on any or
|
||||
a given fault), *user colours* on a condition; only green, orange and red
|
||||
on the Grayhill/MoTeC keypads. Encoders: steps 0–255, LED pattern single
|
||||
LED / bar graph / one + first/last. Backlight always on or with the
|
||||
ignition (with an off delay), dimmed with the lights.
|
||||
|
||||
|ECUMaster PMU (5x3MT, RacePad)
|
||||
|RGB, 7 colours. Encoder modes: *encoder* (a channel's value, first /
|
||||
last / default state, autosaved), *changer* (pages, wrap from last to
|
||||
first), *parameter controller* with buttons as *parameter selectors*
|
||||
(radio buttons choosing what the knob changes; pressing the selected one
|
||||
again releases the knob). 16 LEDs around each encoder show its value
|
||||
(start offset, inverted, bi-directional from the centre).
|
||||
|
||||
|PDM and marine practice (not in the pages above)
|
||||
|Timers (auto-off), exclusive *interlock* groups (winch in ⟂ out),
|
||||
conditions (ignition, engine running, speed), a defined state when
|
||||
communication is lost, a confirmation for dangerous circuits.
|
||||
|===
|
||||
|
||||
What it means for us:
|
||||
|
||||
* *maptool is the whole controller*: keypads, relay modules and lights
|
||||
are I/O; the modes, timers, strobe, interlocks, conditions and LED
|
||||
colours run in maptool — unless a device has its own firmware for that
|
||||
function, which is outside our scope.
|
||||
* *A binding* = an input (keypad node, key or encoder) + a mode + a
|
||||
target: an output (a relay or light channel, SDO/RPDO) or a screen
|
||||
function (zoom, the next profile, the next stop). Bindings live in the
|
||||
screen profile, so a key can do something else off-road.
|
||||
* *Modes*: Toggle, On, Off, Hold (momentary), Pulse (on for a duration),
|
||||
Positions 1..N, Strobe (interval), Dimmer (a level, an encoder turns
|
||||
it); per binding an interlock group, "only when", a long press, a
|
||||
confirmation, the state at power-on and when maptool or the keypad is
|
||||
lost.
|
||||
* *The LED colour on the screen*: a thin line in the key's LED colour
|
||||
under the tile or screen key it drives — dim off, full on, blinking red
|
||||
on a fault — so it's clear which key controls what.
|
||||
* *Fail-safe*: a Hold output goes off when the keypad or maptool goes
|
||||
silent; a relay node needs a heartbeat consumer on maptool and its own
|
||||
safe state.
|
||||
* *Encoders*: a value (dimmer, volume), a changer (profiles, wrap) or a
|
||||
parameter controller. The interim (Blink Marine style) keypad has 8
|
||||
keys and 8 encoders: two move the map, one zooms, the rest are bound
|
||||
per profile. *Moving with a knob* instead of dragging: press to grab
|
||||
the selected row (a stop, a point, a layer), turn to move it up or
|
||||
down the list or into a folder, press again to drop it — no dragging
|
||||
on a bumpy road. Ours have one LED each, no ring: the value could
|
||||
show for a moment on the keypad's other LEDs while the knob turns (a
|
||||
bar across the keys, then back to their own colours) — to be worked
|
||||
out.
|
||||
|
||||
Mockups: the Design canvas, artboards GridSwitches (tiles: icon, name,
|
||||
state, mode, the key, the LED line) and GridBinding (the keypad, a key's
|
||||
target, mode, options, LED colours).
|
||||
|
||||
Sources: Garmin PowerSwitch manual, "Adding a Button to a Custom Layout"
|
||||
(www8.garmin.com/manuals/webhelp, Tread Overland Edition); Garmin OnDeck
|
||||
manual, "Configuring the Switches with a Mobile Device" and "…with a
|
||||
Chartplotter"; MaxxECU help, CAN keypad settings
|
||||
(maxxecu.com/webhelp/settings-can_keypad-keypad_settings.html);
|
||||
ECUMaster, "How-to Set Up Keyboards with Encoders in PMU" (v1.0,
|
||||
2026-01-09); ECUMaster USA, CAN keypads with the PMU16; HP Academy, PDM
|
||||
control pad setup.
|
||||
|
||||
== Typography
|
||||
|
||||
* Planning UI: the system sans; *National Park* (the router-carved
|
||||
|
||||
@@ -12,6 +12,8 @@ module Maptool
|
||||
# Config (data/can.json; CAN is off without it):
|
||||
# { "interfaces": ["can0"],
|
||||
# "nmt_start": true, // NMT "start all nodes" on connect
|
||||
# "actions": [ // SDO writes, buttons beside the node in /can.html
|
||||
# { "name": "Level IMU", "node": 33, "index": "0x2022", "subindex": 1, "data": "01" } ],
|
||||
# "signals": [
|
||||
# { "name": "gnss.lat", "id": "0x181", "byte": 0, "type": "i32", "scale": 1e-7 },
|
||||
# { "name": "keypad.key1", "id": "0x195", "byte": 0, "bit": 0, "type": "bit" },
|
||||
|
||||
@@ -80,6 +80,24 @@ module Maptool
|
||||
raise Error, format("unexpected SDO reply 0x%02X", response.getbyte(0)) unless response.getbyte(0) == 0x60
|
||||
end
|
||||
|
||||
# A command from can.json's "actions", written by an expedited download
|
||||
# — /can.html's buttons beside a node, e.g. levelling its IMU:
|
||||
# { "name": "Level IMU", "node": 33, "index": "0x2022", "subindex": 1, "data": "01" }
|
||||
# `data`: the bytes in hex, little-endian like the OD (1 to 4 bytes).
|
||||
Action = Struct.new(:name, :node, :index, :sub, :bytes) do
|
||||
def self.parse(config)
|
||||
int = ->(v) { Integer(v) } # "0x2022" or 8226
|
||||
bytes = [config.fetch("data")].pack("H*")
|
||||
raise ArgumentError, "#{config["name"]}: data must be 1 to 4 bytes in hex" unless (1..4).cover?(bytes.bytesize)
|
||||
|
||||
new(config.fetch("name"), int.(config.fetch("node")), int.(config.fetch("index")), int.(config.fetch("subindex", 0)), bytes)
|
||||
end
|
||||
|
||||
def run(sdo)
|
||||
sdo.download(node, index, sub, bytes)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Sends to 0x600+node, waits for 0x580+node. index/sub: an initiate's
|
||||
|
||||
+3
-3
@@ -74,7 +74,7 @@ export function resumeFollow(map) {
|
||||
// The first step of a follow (or a jump after a gap): zoom in to see the
|
||||
// road ahead. easeTo, not flyTo — flyTo's swoop zooms out over the distance
|
||||
// first, the wrong way when starting to drive.
|
||||
export const FOLLOW_ZOOM = 16;
|
||||
export const FOLLOW_ZOOM = 17;
|
||||
export function startFollow(map, lngLat) {
|
||||
map.easeTo({ center: lngLat, zoom: Math.max(map.getZoom(), FOLLOW_ZOOM), duration: 1000 });
|
||||
}
|
||||
@@ -102,11 +102,11 @@ export function followPosition(map, lngLat, heading, speed, duration) {
|
||||
}
|
||||
|
||||
// Auto-zoom like a car navigation: close in town, farther out the faster
|
||||
// (0 km/h z17, 50 z16.2, 90 z15.6, 130+ z15). Eased toward that by at most
|
||||
// (up to 20 km/h z18, 50 z17.3, 90 z16.3, 120+ z15.6). Eased toward that by at most
|
||||
// 0.15 a fix and ignored within 0.25, so speed jitter doesn't pump the map.
|
||||
// A hand zoom pauses the follow; on resuming it eases back.
|
||||
export function autoZoom(current, speed) {
|
||||
const target = Math.min(17, Math.max(15, 17 - speed * 3.6 * 0.0154));
|
||||
const target = Math.max(15.5, 18 - Math.max(0, speed * 3.6 - 20) * 0.024);
|
||||
const diff = target - current;
|
||||
if (Math.abs(diff) < 0.25) return null;
|
||||
return current + Math.sign(diff) * Math.min(Math.abs(diff), 0.15);
|
||||
|
||||
+2
-1
@@ -190,7 +190,8 @@ class AppTest < Minitest::Test
|
||||
|
||||
def test_can_requires_login_and_is_off_without_a_config
|
||||
assert_equal 401, request.get("/api/can").status
|
||||
assert_equal({ "interfaces" => {}, "nodes" => {}, "signals" => {}, "frames" => [], "available" => false, "simulated" => false }, json_body(request.get("/api/can", **logged_in_env)))
|
||||
assert_equal 409, request.post("/api/can/actions/0", **logged_in_env).status
|
||||
assert_equal({ "interfaces" => {}, "nodes" => {}, "signals" => {}, "frames" => [], "available" => false, "simulated" => false, "actions" => [] }, json_body(request.get("/api/can", **logged_in_env)))
|
||||
end
|
||||
|
||||
# MQTT messages land in the tracker / ITS-G5 parts of /api/live.
|
||||
|
||||
@@ -85,6 +85,14 @@ class CanDiscoveryTest < Minitest::Test
|
||||
assert_equal "\x01", node.od[[0x20E2, 1]]
|
||||
end
|
||||
|
||||
def test_an_action_writes_its_bytes_and_rejects_bad_data
|
||||
node = FakeNode.new(0x21, {})
|
||||
action = Maptool::Can::Sdo::Action.parse("name" => "Level IMU", "node" => 33, "index" => "0x2022", "subindex" => 1, "data" => "01")
|
||||
action.run(Maptool::Can::Sdo.new(node))
|
||||
assert_equal "\x01".b, node.od[[0x2022, 1]]
|
||||
assert_raises(ArgumentError) { Maptool::Can::Sdo::Action.parse("name" => "x", "node" => 1, "index" => 1, "data" => "0102030405") }
|
||||
end
|
||||
|
||||
def test_a_node_described_decodes_its_own_tpdos
|
||||
sdo = Maptool::Can::Sdo.new(FakeNode.new(0x21, GNSS_OD.dup))
|
||||
description = Maptool::Can::Discovery.describe(sdo, 0x21, aliases: { "XIAO STM32C5 2.Latitude" => "gnss.lat" })
|
||||
|
||||
+22
-5
@@ -47,7 +47,7 @@
|
||||
<div class="scroll"><table id="interfaces"><thead><tr><th>Interface</th><th>State</th><th class="num">Frames</th><th>Last frame</th><th>Error</th></tr></thead><tbody></tbody></table></div>
|
||||
|
||||
<h2>Nodes</h2>
|
||||
<div class="scroll"><table id="nodes"><thead><tr><th>Node</th><th>State</th><th>Last seen</th><th>Last EMCY</th><th>Sends</th></tr></thead><tbody></tbody></table></div>
|
||||
<div class="scroll"><table id="nodes"><thead><tr><th>Node</th><th>State</th><th>Last seen</th><th>Last EMCY</th><th>Sends</th><th>Actions</th></tr></thead><tbody></tbody></table></div>
|
||||
|
||||
<h2>Signals</h2>
|
||||
<div class="scroll"><table id="signals"><thead><tr><th>Signal</th><th class="num">Value</th><th>Unit</th><th>Updated</th></tr></thead><tbody></tbody></table></div>
|
||||
@@ -97,6 +97,22 @@
|
||||
document.querySelector(`#${id} tbody`).innerHTML = rows.length ? rows.join("") : `<tr><td class="empty" colspan="${cols}">${empty}</td></tr>`;
|
||||
}
|
||||
|
||||
// can.json's "actions" beside their node: one SDO write each (POST /api/can/actions/<n>).
|
||||
let notice = null; // an action's outcome, shown in the status for 10 s
|
||||
const actionsHtml = (actions, node) => (actions || []).map((a, n) => a.node === node ? `<button type="button" data-action="${n}">${esc(a.name)}</button>` : "").join(" ");
|
||||
document.getElementById("nodes").addEventListener("click", async (e) => {
|
||||
const button = e.target.closest("button[data-action]");
|
||||
if (!button || !confirm(`${button.textContent} on node ${last.actions[button.dataset.action].node}?`)) return;
|
||||
button.disabled = true;
|
||||
try {
|
||||
const response = await fetch(`/api/can/actions/${button.dataset.action}`, { method: "POST" });
|
||||
const body = await response.json().catch(() => ({}));
|
||||
notice = { text: `${button.textContent}: ${response.ok ? "done" : body.error || `HTTP ${response.status}`}`, bad: !response.ok, until: Date.now() + 10000 };
|
||||
} finally {
|
||||
button.disabled = false;
|
||||
}
|
||||
});
|
||||
|
||||
const STATE_CLASS = { operational: "ok", "pre-operational": "warn", stopped: "bad", "boot-up": "warn" };
|
||||
|
||||
function render(data) {
|
||||
@@ -108,8 +124,8 @@
|
||||
for (const f of data.frames) if (f.node != null) (roles[f.node] ||= new Set()).add(f.role);
|
||||
fill("nodes", Object.entries(data.nodes).sort((a, b) => a[0] - b[0]).map(([id, n]) => {
|
||||
const emcy = n.emcy ? `<code>${hex(n.emcy.code, 4)}</code> reg <code>${hex(n.emcy.register, 2)}</code> ${n.emcy.code === 0 ? "(reset)" : ""} · ${age(n.emcy.at)}` : "—";
|
||||
return `<tr class="${stale(n.seen_at) && !n.silent ? "stale" : ""}"><td>${nodeName(id)}</td><td class="${n.silent ? "bad" : STATE_CLASS[n.state] || ""}"${n.silent ? ' title="3 heartbeats missed"' : ""}>${n.silent ? "silent" : esc(n.state || "no heartbeat")}</td><td>${age(n.seen_at)}</td><td class="${n.emcy?.code ? "bad" : ""}">${emcy}</td><td>${[...(roles[id] || [])].sort().map(esc).join(", ")}</td></tr>`;
|
||||
}), "No CANopen node heard yet.", 5);
|
||||
return `<tr class="${stale(n.seen_at) && !n.silent ? "stale" : ""}"><td>${nodeName(id)}</td><td class="${n.silent ? "bad" : STATE_CLASS[n.state] || ""}"${n.silent ? ' title="3 heartbeats missed"' : ""}>${n.silent ? "silent" : esc(n.state || "no heartbeat")}</td><td>${age(n.seen_at)}</td><td class="${n.emcy?.code ? "bad" : ""}">${emcy}</td><td>${[...(roles[id] || [])].sort().map(esc).join(", ")}</td><td>${actionsHtml(data.actions, Number(id))}</td></tr>`;
|
||||
}), "No CANopen node heard yet.", 6);
|
||||
|
||||
fill("signals", Object.entries(data.signals).sort().map(([name, s]) =>
|
||||
`<tr class="${stale(s.at) ? "stale" : ""}"><td>${esc(name)}</td><td class="num">${typeof s.value === "number" ? +s.value.toFixed(6) : esc(s.value)}</td><td>${esc(s.unit)}</td><td>${age(s.at)}</td></tr>`),
|
||||
@@ -136,8 +152,9 @@
|
||||
if (date) clockOffset = Math.abs(date / 1000 - Date.now() / 1000) > 2 ? date / 1000 - Date.now() / 1000 : 0;
|
||||
render(last = await response.json());
|
||||
const silent = Object.keys(last.nodes).filter((id) => last.nodes[id].silent);
|
||||
status.className = silent.length ? "bad" : "";
|
||||
status.textContent = (silent.length ? `⚠ node ${silent.join(", ")} silent · ` : "") + `updated ${new Date().toLocaleTimeString()}`;
|
||||
const shown = notice && notice.until > Date.now() ? notice : null;
|
||||
status.className = silent.length || shown?.bad ? "bad" : "";
|
||||
status.textContent = (shown ? `${shown.text} · ` : "") + (silent.length ? `⚠ node ${silent.join(", ")} silent · ` : "") + `updated ${new Date().toLocaleTimeString()}`;
|
||||
} catch (e) {
|
||||
status.textContent = `can't reach the server: ${e.message}`;
|
||||
} finally {
|
||||
|
||||
Reference in new issue
Block a user