From 7fdc0114e6f450cdfe1bbc606015503f4cde6cc9 Mon Sep 17 00:00:00 2001 From: Roman Priesol Date: Wed, 2 Dec 2026 18:22:16 +0100 Subject: [PATCH] =?UTF-8?q?Debug=20pages=20switch=20between=20each=20other?= =?UTF-8?q?:=20one=20tab=20bar=20on=20top=20of=20/status.html,=20/can.html?= =?UTF-8?q?=20and=20/sim.html=20(views/=5Fdebug=5Fnav.erb).=20CAN=20analyz?= =?UTF-8?q?er:=20a=20trace=20of=20every=20frame=20as=20it=20came=20(the=20?= =?UTF-8?q?server=20keeps=20the=20last=201000,=20GET=20/api/can=3Fsince=3D?= =?UTF-8?q?=20gives=20the=20new=20ones),=20each=20byte=20colored=20by?= =?UTF-8?q?=20what=20it=20is=20and=20decoded=20by=20its=20CANopen=20role?= =?UTF-8?q?=20=E2=80=94=20SDO=20command,=20index:subindex,=20expedited=20p?= =?UTF-8?q?ayload,=20segments,=20abort=20codes,=20byte=200=20in=20bits;=20?= =?UTF-8?q?NMT,=20heartbeat,=20EMCY,=20SYNC,=20PDOs;=20who=20sent=20it,=20?= =?UTF-8?q?=CE=94=20ms,=20pause,=20clear,=20the=20frame=20filter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.rb | 2 +- lib/maptool/can.rb | 13 ++++- test/test_can.rb | 2 + views/_debug_nav.erb | 14 +++++ views/can.erb | 127 +++++++++++++++++++++++++++++++++++++++++-- views/sim.erb | 2 +- views/status.erb | 2 +- 7 files changed, 153 insertions(+), 9 deletions(-) create mode 100644 views/_debug_nav.erb diff --git a/app.rb b/app.rb index 65d0a54..91ef4f3 100644 --- a/app.rb +++ b/app.rb @@ -1364,7 +1364,7 @@ module Maptool # CANopen node (heartbeat state, last seen) and each configured signal. get "/api/can" do require_login! - snapshot = CAN_STORE.snapshot + snapshot = CAN_STORE.snapshot(since: params[:since]&.to_i) 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.* diff --git a/lib/maptool/can.rb b/lib/maptool/can.rb index 4a0954a..696bc2f 100644 --- a/lib/maptool/can.rb +++ b/lib/maptool/can.rb @@ -137,6 +137,7 @@ module Maptool # every frame id seen (count, rate, last data) and the decoded signals. class Store MAX_FRAME_IDS = 2048 # ponytail: stops counting new ids past this, enough for a bus + LOG_SIZE = 1000 # the last frames as they came, for /can.html's trace # Signals starting with this aren't taken from the bus (the GNSS # simulation's, put by #put, stand in for the node's meanwhile). @@ -148,6 +149,8 @@ module Maptool @nodes = {} @interfaces = {} @frames = {} + @log = [] + @seq = 0 end def interface(name, **state) @@ -174,6 +177,8 @@ module Maptool # EMCY: error code (0 = errors reset), error register, 5 bytes vendor-specific n[:emcy] = { code: frame.data.unpack1("S<"), register: frame.data.getbyte(2), at: at } if role == :emcy && frame.data.bytesize >= 3 end + @log << { seq: @seq += 1, at: at, interface: interface, id: frame.id, extended: frame.extended, data: frame.data.unpack1("H*") } + @log.shift if @log.size > LOG_SIZE key = "#{interface}:#{frame.extended ? format('%08X', frame.id) : format('%03X', frame.id)}" f = @frames[key] if f.nil? && @frames.size < MAX_FRAME_IDS @@ -208,8 +213,12 @@ module Maptool end end - def snapshot - @mutex.synchronize { { interfaces: @interfaces.dup, nodes: @nodes.dup, signals: @signals.dup, frames: @frames.values.map(&:dup) } } + # log: the frames after seq `since` (none without it). + def snapshot(since: nil) + @mutex.synchronize do + snap = { interfaces: @interfaces.dup, nodes: @nodes.dup, signals: @signals.dup, frames: @frames.values.map(&:dup) } + since ? snap.merge(log: @log.select { |f| f[:seq] > since }) : snap + end end end diff --git a/test/test_can.rb b/test/test_can.rb index 89176f1..0da0658 100644 --- a/test/test_can.rb +++ b/test/test_can.rb @@ -66,6 +66,8 @@ class CanTest < Minitest::Test tpdo = snapshot[:frames].find { |f| f[:id] == 0x181 } assert_equal [:tpdo1, 1, 2, 0.5], tpdo.values_at(:role, :node, :count, :interval) assert_equal({ code: 0x8130, register: 0x11, at: 3.0 }, snapshot[:nodes][5][:emcy]) + assert_equal [3, 4], store.snapshot(since: 2)[:log].map { |f| f[:seq] } + assert_equal "3081" "11", store.snapshot(since: 3)[:log].first[:data] end def test_a_node_missing_3_heartbeats_is_silent_until_heard_again diff --git a/views/_debug_nav.erb b/views/_debug_nav.erb new file mode 100644 index 0000000..e75e2fa --- /dev/null +++ b/views/_debug_nav.erb @@ -0,0 +1,14 @@ +<%# The debug pages' switcher, on top of each (status, CAN, GNSS simulation). %> + + diff --git a/views/can.erb b/views/can.erb index 4159d10..b53c068 100644 --- a/views/can.erb +++ b/views/can.erb @@ -4,7 +4,7 @@ - CANopen diagnostics + CAN analyzer + <%= erb :_debug_nav, layout: false %>
-

CANopen diagnostics

+

CAN analyzer

loading…
@@ -56,6 +66,11 @@
InterfaceCOB-IDRoleNodeCountRateDataLast
+

Trace + commandOD indexsubindexpayloadunused + · byte 0: ccs/scs t n e s · the frame filter applies

+
#TimeΔ msInterfaceIDDataFromByte 0Meaning
+ diff --git a/views/sim.erb b/views/sim.erb index 6f0a771..8b87ff2 100644 --- a/views/sim.erb +++ b/views/sim.erb @@ -23,10 +23,10 @@ + <%= erb :_debug_nav, layout: false %>

GNSS simulation

loading… - Server status CANopen diagnostics The map
diff --git a/views/status.erb b/views/status.erb index cde9025..5a755a9 100644 --- a/views/status.erb +++ b/views/status.erb @@ -27,12 +27,12 @@ + <%= erb :_debug_nav, layout: false %>

Server status

loading… - CANopen diagnostics GNSS simulation