CAN: a node that misses 3 heartbeats is flagged silent (one journal line when it stops and when it's back, red in /can.html); /can.html tables as wide as their content, numeric headers aligned with their values

This commit is contained in:
randy committed 2026-11-30 18:30:21 +01:00
1 parent 5c023619ec
commit 500acf9fd5
3 files changed
+51 -7

No files matched your search

+14 -1
View File
@@ -57,7 +57,7 @@ class CanTest < Minitest::Test
store.record("vcan0", Frame.new(0x181, "".b, false), { "gnss.lat" => 49.1 }, at: 2.0)
snapshot = store.snapshot
assert_equal({ frames: 2, last_frame_at: 2.0 }, snapshot[:interfaces]["vcan0"])
assert_equal({ seen_at: 1.0, state: "operational" }, snapshot[:nodes][5])
assert_equal [1.0, "operational"], snapshot[:nodes][5].values_at(:seen_at, :state)
assert_equal({ value: 49.1, at: 2.0 }, snapshot[:signals]["gnss.lat"])
store.record("vcan0", Frame.new(0x181, "".b, false), {}, at: 2.5)
@@ -68,6 +68,19 @@ class CanTest < Minitest::Test
assert_equal({ code: 0x8130, register: 0x11, at: 3.0 }, snapshot[:nodes][5][:emcy])
end
def test_a_node_missing_3_heartbeats_is_silent_until_heard_again
store = Maptool::Can::Store.new
[0, 5, 10].each { |t| store.record("vcan0", Frame.new(0x702, "\x05".b, false), {}, at: t.to_f) }
_, err = capture_io { store.record("vcan0", Frame.new(0x701, "\x05".b, false), {}, at: 24.0) }
refute store.snapshot[:nodes][2][:silent]
_, err = capture_io { store.record("vcan0", Frame.new(0x701, "\x05".b, false), {}, at: 26.0) }
assert store.snapshot[:nodes][2][:silent]
assert_match(/node 2 silent/, err)
_, err = capture_io { store.record("vcan0", Frame.new(0x702, "\x05".b, false), {}, at: 30.0) }
refute store.snapshot[:nodes][2][:silent]
assert_match(/node 2 back after 20s/, err)
end
# Over a real SocketCAN interface when there is one:
# sudo ip link add dev vcan0 type vcan && sudo ip link set up vcan0
def test_frames_go_over_vcan0