Skip to content

Commit 7f3513a

Browse files
committed
Add get_can_ids and clarify reboot_remote
Add get_can_ids() to return CAN node IDs from the latest scan (useful for OTA flashing). Expand and clarify reboot_remote() docstring to document can_address semantics (0 = master, 1..127 = remote slave via SDO write), note qid is unused but kept for API compatibility, and show example response formats. Small cleanup: add an inline comment for the /can_act task and change the scan call to expect 1 response (nResponses=1).
1 parent 5eb39db commit 7f3513a

1 file changed

Lines changed: 20 additions & 6 deletions

File tree

uc2rest/can.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,29 @@ def register_callback(self, key, callbackfct):
5757
"""Register a callback function for a specific key."""
5858
self._callbackPerKey[key] = callbackfct
5959

60+
def get_can_ids(self):
61+
"""Return CAN node IDs from the latest scan (e.g. for OTA flashing)."""
62+
return [entry.get("canId") for entry in self.scanResults
63+
if entry.get("canId") is not None]
64+
6065
def reboot_remote(self, qid=1, can_address=0, isBlocking=False, timeout=2):
6166
"""
62-
Send a reboot signal to the remote CAN device.
67+
Reboot a CAN device.
6368
64-
:param qid: Query ID for the CAN command (default: 1)
69+
- ``can_address == 0`` reboots the master (this ESP32) itself.
70+
- ``can_address in 1..127`` reboots a remote slave by SDO-writing 1
71+
to OD index 0x2507 sub 0 on the target node. The slave's
72+
CO_tmr_task observes the write and calls ESP.restart() ~200 ms
73+
later.
74+
75+
:param qid: Query ID for the CAN command (unused by firmware, kept
76+
for API compatibility)
77+
:param can_address: 0 = master, 1..127 = remote slave nodeId
6578
:param isBlocking: If True, wait for response
6679
:param timeout: Timeout for the command in seconds
67-
:param can_address: Address of the CAN device to reboot (0 is master)
68-
:return: Response from the device
80+
:return: Response from the device, e.g.
81+
``{"status":"ok","nodeId":11}`` or
82+
``{"status":"error","error":"SDO write failed","nodeId":11}``.
6983
"""
7084
path = "/can_act"
7185
payload = {
@@ -98,7 +112,7 @@ def scan(self, qid=1, timeout=5):
98112
"count": 2
99113
}
100114
"""
101-
path = "/can_act"
115+
path = "/can_act" # {"task":"/can_act", "scan": true}
102116
payload = {
103117
"task": path,
104118
"scan": True,
@@ -109,7 +123,7 @@ def scan(self, qid=1, timeout=5):
109123
payload,
110124
getReturn=True,
111125
timeout=timeout,
112-
nResponses=2
126+
nResponses=1
113127
)
114128

115129
def get_available_devices(self, timeout=2):

0 commit comments

Comments
 (0)