Add CAN discovery, probing and node ID APIs#143
Merged
Conversation
Extend CAN.scan to support SDO probing of an ID range (probe_range, id_from, id_to) and include SDO-reported build/fwVersion/mac for reachable nodes. Add payload support for probeRange/from/to. Introduce discover() as a convenience wrapper around scan(..., probe_range=True). Add helpers: get_device_build_info() to extract per-node build info from the latest scanResults, set_remote_node_id() to reassign a node's CAN id (by current id or by MAC) with optional safety checks and blocking behavior, and assign_node_id_by_mac() as a convenience call for MAC-keyed provisioning. Docstrings updated to describe return shapes and behavior (persisted ID, CANopen reset, etc.).
Contributor
There was a problem hiding this comment.
Pull request overview
Extends the uc2rest Python CAN client API to support discovery/probing of node-ID ranges via SDO and adds convenience helpers for extracting probed build info and remotely reassigning node IDs (including MAC-keyed provisioning).
Changes:
- Extend
CAN.scan()with optional SDO probing (probe_range,id_from,id_to) and send corresponding payload fields (probeRange,from,to). - Add
CAN.discover()as a convenience wrapper aroundscan(..., probe_range=True, ...). - Add helper APIs:
get_device_build_info(),set_remote_node_id(), andassign_node_id_by_mac().
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+138
to
+141
| if probe_range: | ||
| payload["probeRange"] = True | ||
| payload["from"] = int(id_from) | ||
| payload["to"] = int(id_to) |
Comment on lines
+243
to
+256
| if by_mac is None and target is None: | ||
| raise ValueError("set_remote_node_id requires either target or by_mac") | ||
| path = "/can_act" | ||
| payload = { | ||
| "task": path, | ||
| "setRemoteNodeId": int(new_id), | ||
| "qid": qid, | ||
| } | ||
| if by_mac is not None: | ||
| payload["byMac"] = str(by_mac) | ||
| else: | ||
| payload["target"] = int(target) | ||
| if expect_mac is not None: | ||
| payload["expectMac"] = str(expect_mac) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Extend CAN.scan to support SDO probing of an ID range (probe_range, id_from, id_to) and include SDO-reported build/fwVersion/mac for reachable nodes. Add payload support for probeRange/from/to. Introduce discover() as a convenience wrapper around scan(..., probe_range=True). Add helpers: get_device_build_info() to extract per-node build info from the latest scanResults, set_remote_node_id() to reassign a node's CAN id (by current id or by MAC) with optional safety checks and blocking behavior, and assign_node_id_by_mac() as a convenience call for MAC-keyed provisioning. Docstrings updated to describe return shapes and behavior (persisted ID, CANopen reset, etc.).