CAN actions: can.json's "actions" ({name, node, index, subindex, data: 1–4 bytes hex}) are SDO expedited downloads, a button beside their node on /can.html (confirm first, the result in the status line) — POST /api/can/actions/:n (login, 409 with no config, 404 unknown, 502 on an SDO error), GET /api/can lists them; first one: Level IMU on node 0x21 (0x2022:1 ← 01)
This commit is contained in:
1 parent
0a5548cd8f
commit
97d1bda09c
6 files changed
+77
-7
No files matched your search
@@ -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
|
||||
|
||||
Reference in new issue
Block a user