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

+30 -1
View File
@@ -117,6 +117,10 @@ module Maptool
class Store
MAX_FRAME_IDS = 2048 # ponytail: stops counting new ids past this, enough for a bus
# Signals starting with this aren't taken from the bus (the GNSS
# simulation's, put by #put, stand in for the node's meanwhile).
attr_accessor :override_prefix
def initialize
@mutex = Mutex.new
@signals = {}
@@ -137,6 +141,13 @@ module Maptool
role, node = Can.canopen_role(frame.id, extended: frame.extended)
if node
n = (@nodes[node] ||= {})
if n.delete(:silent)
warn "can: node #{node} back after #{(at - n[:seen_at]).round}s"
end
if role == :heartbeat
n[:heartbeat_interval] = at - n[:heartbeat_at] if n[:heartbeat_at]
n[:heartbeat_at] = at
end
n[:seen_at] = at
n[:state] = HEARTBEAT_STATES.fetch(frame.data.getbyte(0) & 0x7F, "unknown") if role == :heartbeat && frame.data.bytesize >= 1
# EMCY: error code (0 = errors reset), error register, 5 bytes vendor-specific
@@ -154,7 +165,25 @@ module Maptool
end
f.merge!(count: f[:count] + 1, data: frame.data.unpack1("H*"), at: at)
end
values.each { |name, value| @signals[name] = { value: value, at: at } }
values.each { |name, value| @signals[name] = { value: value, at: at } unless @override_prefix && name.start_with?(@override_prefix) }
mark_silent(at)
end
end
def put(values, at: Time.now.to_f)
@mutex.synchronize { values.each { |name, value| @signals[name] = { value: value, at: at } } }
end
# A node with a heartbeat that missed 3 of them: silent, warned once
# (in the journal, so the time it stopped is kept). Checked as other
# frames come in — with the whole bus quiet the interface says so.
def mark_silent(at)
return if @checked_at && at - @checked_at < 1
@checked_at = at
@nodes.each do |node, n|
next if n[:silent] || !n[:heartbeat_interval] || at - n[:heartbeat_at] < 3 * n[:heartbeat_interval]
n[:silent] = true
warn "can: node #{node} silent, last heartbeat #{Time.at(n[:heartbeat_at]).strftime('%F %T')}"
end
end