From 712c6bf7ade74bce3000a165b67618c1919085cd Mon Sep 17 00:00:00 2001
From: Roman Priesol
Date: Wed, 2 Dec 2026 19:05:07 +0100
Subject: [PATCH] =?UTF-8?q?CAN=20trace=20on=20its=20own=20debug=20tab=20(/?=
=?UTF-8?q?trace.html),=20off=20the=20CAN=20analyzer:=20records=20between?=
=?UTF-8?q?=20Start=20and=20Stop=20only=20(polled=20every=200.5=20s,=20the?=
=?UTF-8?q?=20server=20keeps=20the=20last=205000=20frames,=20lost=20ones?=
=?UTF-8?q?=20counted,=20stops=20at=2020000),=20the=20newest=20on=20top;?=
=?UTF-8?q?=20sorted=20by=20any=20column,=20filtered=20by=20text=20(a,=20b?=
=?UTF-8?q?=20=3D=20either),=20frame=20type,=20interface,=20node=20and=20o?=
=?UTF-8?q?nly=20changes;=20=CE=94=20per=20ID;=201000=20rows=20drawn,=20th?=
=?UTF-8?q?e=20filter=20and=20sort=20over=20all;=20export=20as=20candump?=
=?UTF-8?q?=20.log=20(can-utils,=20SavvyCAN,=20python-can)=20or=20the=20sh?=
=?UTF-8?q?own=20rows=20decoded=20as=20CSV;=20SDO=20objects=20named=20by?=
=?UTF-8?q?=20esphome-canopen's=20EDS=20(public/can/esphome.eds,=20from=20?=
=?UTF-8?q?can2mqtt)=20and=20its=20entity=20objects?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
TODO.adoc | 3 +
app.rb | 5 +
docs/third-party-notices.adoc | 7 +
lib/maptool/can.rb | 6 +-
public/can/esphome.eds | 169 +++++++++++++++++++
test/test_can.rb | 1 +
views/_debug_nav.erb | 4 +-
views/can.erb | 122 +-------------
views/trace.erb | 306 ++++++++++++++++++++++++++++++++++
9 files changed, 498 insertions(+), 125 deletions(-)
create mode 100644 public/can/esphome.eds
create mode 100644 views/trace.erb
diff --git a/TODO.adoc b/TODO.adoc
index 32538ab..ea4bddb 100644
--- a/TODO.adoc
+++ b/TODO.adoc
@@ -230,6 +230,9 @@ already reaches the home MQTT broker (`mqtt_ext`) from ESPHome nodes in `~/espho
*** [ ] EDS (CiA 306) read from a node (`0x1021`) or a file, the same decoder from it — once the
ESPHome side generates EDS (proposal for mrk in home-gitops `docs/canopen-nodes.adoc`); the
car bridge's frames described the same way
+**** [x] Meanwhile one EDS for all of them: esphome-canopen's generic one (from can2mqtt) in
+ `public/can/esphome.eds`, names the SDO objects in `/trace.html` (plus the entity objects);
+ a node's own EDS (`0x1021`) to take its place per node
*** [ ] 0x1008/0x1018 identity for any CANopen device in `/can.html`
** [x] A node that stops its heartbeat (3 missed) is flagged: one journal line when it goes
silent and when it's back (`can: node 2 silent, last heartbeat …`), red in `/can.html`
diff --git a/app.rb b/app.rb
index ec22935..c752f0f 100644
--- a/app.rb
+++ b/app.rb
@@ -540,6 +540,11 @@ module Maptool
erb :can, layout: false
end
+ # Every CAN frame as it came, decoded (polls GET /api/can?since=).
+ get "/trace.html" do
+ erb :trace, layout: false
+ end
+
# A share to the installed app normally never reaches the server: the
# service worker (public/sw.js) takes the POST, parks the files and
# opens the app. Only lands here if no worker is running yet — back to
diff --git a/docs/third-party-notices.adoc b/docs/third-party-notices.adoc
index 618b080..30990dd 100644
--- a/docs/third-party-notices.adoc
+++ b/docs/third-party-notices.adoc
@@ -165,6 +165,13 @@ Offline routing runs https://github.com/valhalla/valhalla[Valhalla]
(`ghcr.io/valhalla/valhalla`, version pinned in `docker-compose.yaml`),
over the same Geofabrik extracts (ODbL). See `docs/routing-design.adoc`.
+`public/can/esphome.eds`, the CANopen object dictionary of
+https://github.com/mrk-its/esphome-canopen[esphome-canopen] nodes (the
+CAN trace names SDO objects by it), is copied from
+https://github.com/mrk-its/can2mqtt[can2mqtt]
+(`src/can2mqtt/eds/esphome.eds`, commit `815ad0f`, MIT or Apache-2.0,
+© mrk-its). Updated by hand.
+
Not a frontend asset like the above, but also baked into this app's own
Docker image (not a separate container the way kiwix-serve is —
see `docs/deployment.adoc`/`docs/development.adoc`): three CLI tools
diff --git a/lib/maptool/can.rb b/lib/maptool/can.rb
index 696bc2f..08278bb 100644
--- a/lib/maptool/can.rb
+++ b/lib/maptool/can.rb
@@ -137,7 +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
+ LOG_SIZE = 5000 # the last frames as they came, for /trace.html (a few seconds of a busy 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).
@@ -213,11 +213,11 @@ module Maptool
end
end
- # log: the frames after seq `since` (none without it).
+ # log: the frames after seq `since` (none without it); log_seq: the last one's.
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
+ since ? snap.merge(log: @log.select { |f| f[:seq] > since }, log_seq: @seq) : snap
end
end
end
diff --git a/public/can/esphome.eds b/public/can/esphome.eds
new file mode 100644
index 0000000..a6c2317
--- /dev/null
+++ b/public/can/esphome.eds
@@ -0,0 +1,169 @@
+[DeviceInfo]
+VendorName=ESPHome
+VendorNumber=1
+BaudRate_10=0
+BaudRate_20=0
+BaudRate_50=0
+BaudRate_125=1
+BaudRate_250=1
+BaudRate_500=1
+BaudRate_800=0
+BaudRate_1000=1
+SimpleBootUpMaster=0
+SimpleBootUpSlave=1
+Granularity=8
+DynamicChannelsSupported=0
+CompactPDO=0
+GroupMessaging=0
+
+NrOfRXPDO=0
+NrOfTXPDO=4
+LSS_Supported=0
+
+[1008]
+ParameterName=DeviceName
+ObjectType=7
+DataType=9
+AccessType=R
+
+[1009]
+ParameterName=HardwareVersion
+ObjectType=7
+DataType=9
+AccessType=R
+
+[100a]
+ParameterName=SoftwareVersion
+ObjectType=7
+DataType=9
+AccessType=R
+
+[1010]
+ParameterName=ParamStore
+ObjectType=9
+
+[1010sub0]
+ParameterName=Number of ParamStore Entries
+ObjectType=7
+DataType=5
+AccessType=R
+
+[1010sub1]
+ParameterName=Store All
+ObjectType=7
+DataType=7
+AccessType=RW
+
+[1010sub2]
+ParameterName=Store Comm
+ObjectType=7
+DataType=7
+AccessType=RW
+
+[1011]
+ParameterName=ParamReset
+ObjectType=9
+
+[1011sub0]
+ParameterName=Number of ParamStore Entries
+ObjectType=7
+DataType=5
+AccessType=R
+
+[1011sub1]
+ParameterName=Reset All Params
+ObjectType=7
+DataType=7
+AccessType=RW
+
+[1011sub2]
+ParameterName=Reset Comm Params
+ObjectType=7
+DataType=7
+AccessType=RW
+
+
+
+[1017]
+ParameterName=ProducerHeartbeatTime
+ObjectType=7
+DataType=6
+AccessType=RW
+
+[1018]
+ParameterName=Identity
+ObjectType=9
+
+[1018sub0]
+ParameterName=Number of Entries
+ObjectType=7
+DataType=5
+AccessType=R
+
+[1018sub1]
+ParameterName=VendorId
+ObjectType=7
+DataType=7
+AccessType=R
+
+[1018sub2]
+ParameterName=ProductCode
+ObjectType=7
+DataType=7
+AccessType=R
+
+[1018sub3]
+ParameterName=RevisionNumber
+ObjectType=7
+DataType=7
+AccessType=R
+
+[1018sub4]
+ParameterName=SerialNumber
+ObjectType=7
+DataType=7
+AccessType=R
+
+[3000]
+ParameterName=Firmware
+ObjectType=9
+
+[3000sub0]
+ParameterName=Firmware Max Index
+ObjectType=7
+DataType=5
+AccessType=R
+DefaultValue=0
+
+[3000sub1]
+ParameterName=Firmware Command
+ObjectType=7
+DataType=7
+AccessType=RW
+DefaultValue=0
+
+[3000sub2]
+ParameterName=Firmware Size
+ObjectType=7
+DataType=7
+AccessType=RW
+DefaultValue=0
+
+[3000sub3]
+ParameterName=Firmware MD5
+ObjectType=7
+DataType=0xf
+AccessType=W
+
+[3000sub4]
+ParameterName=Firmware Data
+ObjectType=7
+DataType=0xf
+AccessType=W
+
+[3000sub5]
+ParameterName=Firmware Flags
+ObjectType=7
+DataType=7
+AccessType=R
+
diff --git a/test/test_can.rb b/test/test_can.rb
index 0da0658..558041b 100644
--- a/test/test_can.rb
+++ b/test/test_can.rb
@@ -67,6 +67,7 @@ class CanTest < Minitest::Test
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 [[], 4], store.snapshot(since: 99).values_at(:log, :log_seq)
assert_equal "3081" "11", store.snapshot(since: 3)[:log].first[:data]
end
diff --git a/views/_debug_nav.erb b/views/_debug_nav.erb
index e75e2fa..96b9ca4 100644
--- a/views/_debug_nav.erb
+++ b/views/_debug_nav.erb
@@ -1,4 +1,4 @@
-<%# The debug pages' switcher, on top of each (status, CAN, GNSS simulation). %>
+<%# The debug pages' switcher, on top of each (status, CAN, CAN trace, GNSS simulation). %>
+ <%= erb :_debug_nav, layout: false %>
+
+
+
+
+
+
+
+
+
+
+
+ commandOD indexsubindexpayloadunused
+ · byte 0:
ccs/scs t n e s · SDO objects named by
esphome.eds · click a column to sort
+
+ | # | Time | Δ ms | Δ ID ms |
+ Interface | ID | Data | From | Byte 0 | Meaning |
+
+
+
+
diff --git a/views/trace.erb b/views/trace.erb
new file mode 100644
index 0000000..c55b2be
--- /dev/null
+++ b/views/trace.erb
@@ -0,0 +1,306 @@
+
+
+