-
Notifications
You must be signed in to change notification settings - Fork 197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add custom eds storage format & block transfer mechanism #343
Open
samsamfire
wants to merge
8
commits into
christiansandberg:master
Choose a base branch
from
samsamfire:add-custom-eds-compression
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
074be34
Adding propagation of dictionary changes to PDO and vice versa.
samsamfire 5e673bb
- Added possibility to use an external format handler in case EDS is …
samsamfire af804df
- Fixed formating on doc, should be good now
samsamfire 368ce59
Revert "Adding propagation of dictionary changes to PDO and vice versa."
samsamfire 9480440
typo
samsamfire 67db91b
reove empty lines
samsamfire 6ca7105
- Fixed typo and added storage_format in network.rst
samsamfire 3847c92
- Forgot to add 0x1022 part
samsamfire File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't spot anything wrong with the code, just some small formatting problems, can you please arrange this. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
except ImportError: | ||
from ConfigParser import RawConfigParser, NoOptionError, NoSectionError | ||
from canopen import objectdictionary | ||
from canopen.sdo import SdoClient | ||
from canopen.sdo import SdoClient, SdoAbortedError | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
@@ -167,21 +167,39 @@ def import_eds(source, node_id): | |
return od | ||
|
||
|
||
def import_from_node(node_id, network): | ||
def import_from_node(node_id, network,block_transfer =False,eds_format_handler = None): | ||
""" Download the configuration from the remote node | ||
:param int node_id: Identifier of the node | ||
:param network: network object | ||
:param block_transfer: use block transfer | ||
:param eds_format_handler: Callable with custom logic that should return the EDS | ||
""" | ||
# Create temporary SDO client | ||
sdo_client = SdoClient(0x600 + node_id, 0x580 + node_id, objectdictionary.ObjectDictionary()) | ||
sdo_client.network = network | ||
# Subscribe to SDO responses | ||
network.subscribe(0x580 + node_id, sdo_client.on_response) | ||
# Get Storage format (0x1022) | ||
try: | ||
storage_format = int.from_bytes(sdo_client.upload(0x1022,0),byteorder="little") | ||
except SdoAbortedError as e: | ||
# Default to 0 if not present | ||
storage_format = 0 | ||
logger.debug("Failed to read object 0x1022, for EDS storage format, default to ASCII (0)") | ||
# Create file like object for Store EDS variable | ||
try: | ||
eds_fp = sdo_client.open(0x1021, 0, "rt") | ||
od = import_eds(eds_fp, node_id) | ||
if eds_format_handler is not None: | ||
eds_raw_fp = sdo_client.open(0x1021, 0, "rb",block_transfer=block_transfer) | ||
# Custom format handler must return a fp or string to extracted EDS file | ||
eds_fp = eds_format_handler(eds_raw_fp,storage_format) | ||
else: | ||
if storage_format != 0: | ||
logger.warning("Trying to read EDS with ASCII format (0) even though storage format is not 0") | ||
eds_fp = sdo_client.open(0x1021, 0, "rt", block_transfer=block_transfer) | ||
od = import_eds(eds_fp,node_id) | ||
|
||
except Exception as e: | ||
print(e) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove the print |
||
logger.error("No object dictionary could be loaded for node %d: %s", | ||
node_id, e) | ||
od = None | ||
|
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't spot anything wrong with the code,
It is just a small request, please pay some attention to the format of the code, like spaces between parameters when calling functions line 170:
object_dictionary = import_from_node(node, self, block_transfer, eds_format_handler)
remove unnecessary spaces:
eds_format_handler: Callable = None
It's just this small things.