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
@@ -12,6 +12,8 @@ module Maptool
|
||||
# Config (data/can.json; CAN is off without it):
|
||||
# { "interfaces": ["can0"],
|
||||
# "nmt_start": true, // NMT "start all nodes" on connect
|
||||
# "actions": [ // SDO writes, buttons beside the node in /can.html
|
||||
# { "name": "Level IMU", "node": 33, "index": "0x2022", "subindex": 1, "data": "01" } ],
|
||||
# "signals": [
|
||||
# { "name": "gnss.lat", "id": "0x181", "byte": 0, "type": "i32", "scale": 1e-7 },
|
||||
# { "name": "keypad.key1", "id": "0x195", "byte": 0, "bit": 0, "type": "bit" },
|
||||
|
||||
@@ -80,6 +80,24 @@ module Maptool
|
||||
raise Error, format("unexpected SDO reply 0x%02X", response.getbyte(0)) unless response.getbyte(0) == 0x60
|
||||
end
|
||||
|
||||
# A command from can.json's "actions", written by an expedited download
|
||||
# — /can.html's buttons beside a node, e.g. levelling its IMU:
|
||||
# { "name": "Level IMU", "node": 33, "index": "0x2022", "subindex": 1, "data": "01" }
|
||||
# `data`: the bytes in hex, little-endian like the OD (1 to 4 bytes).
|
||||
Action = Struct.new(:name, :node, :index, :sub, :bytes) do
|
||||
def self.parse(config)
|
||||
int = ->(v) { Integer(v) } # "0x2022" or 8226
|
||||
bytes = [config.fetch("data")].pack("H*")
|
||||
raise ArgumentError, "#{config["name"]}: data must be 1 to 4 bytes in hex" unless (1..4).cover?(bytes.bytesize)
|
||||
|
||||
new(config.fetch("name"), int.(config.fetch("node")), int.(config.fetch("index")), int.(config.fetch("subindex", 0)), bytes)
|
||||
end
|
||||
|
||||
def run(sdo)
|
||||
sdo.download(node, index, sub, bytes)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Sends to 0x600+node, waits for 0x580+node. index/sub: an initiate's
|
||||
|
||||
Reference in new issue
Block a user