Skip to content

Add NI-XNET CANFD interface #968

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

Merged
merged 8 commits into from
Feb 1, 2021
Merged

Add NI-XNET CANFD interface #968

merged 8 commits into from
Feb 1, 2021

Conversation

jaesc
Copy link
Contributor

@jaesc jaesc commented Jan 13, 2021

Add support to NI-XNET interfaces from National Instruments

@mergify mergify bot requested a review from hardbyte January 13, 2021 13:03
@codecov
Copy link

codecov bot commented Jan 13, 2021

Codecov Report

Merging #968 (49691d8) into develop (7ddea9e) will increase coverage by 0.17%.
The diff coverage is 13.59%.

@@             Coverage Diff             @@
##           develop     #968      +/-   ##
===========================================
+ Coverage    70.78%   70.96%   +0.17%     
===========================================
  Files           75       76       +1     
  Lines         7267     7708     +441     
===========================================
+ Hits          5144     5470     +326     
- Misses        2123     2238     +115     

Copy link
Collaborator

@christiansandberg christiansandberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! You could also add the dependency as an extra in setup.py.


def _recv_internal(self, timeout):
try:
fr = self.__session_receive.frames.read(4, timeout=0.0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you want to use the timeout argument here? Otherwise there is no place for the CPU to do other things. If you want to read multiple frames at once for optimization you can skip the read operation if the queue is not empty.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only a trick to make it working without modifying the nixnet library from National. With a positive timeout of any value it doesn't works. And regarding the queue and the 4 frames reading is because they have hardcoded a fixed length for reading of 24 bytes, so this is needed to be able to read 64 bytes CANFD frames, or at least, is the easy way I have found without patching the underlaying library. Also, it's a good idea to skip the reading if the queue is not empty, I'll do it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The library definitely seems a bit unfinished but that's not your fault.

is_extended_id=can_frame.identifier.extended,
# Get identifier from CanIdentifier structure
arbitration_id=can_frame.identifier.identifier,
dlc=len(can_frame.payload),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remote frames don't contain any data, isn't there a DLC attribute?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, there isn't...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, no big deal. RTR is not used that much nowadays anyway.

# if msg.bitrate_switch:
# type_message = constants.FrameType.CANFDBRS_DATA
# else:
# type_message = constants.FrameType.CANFD_DATA
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, I forgot to change it back.
Yes, this works in this layer. I think we have the problem with can-isotp or udsoncan.

@@ -0,0 +1,22 @@
NI-XNET
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, and you also need to add this to interfaces.rst.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

is_extended_id=can_frame.identifier.extended,
# Get identifier from CanIdentifier structure
arbitration_id=can_frame.identifier.identifier,
dlc=len(can_frame.payload),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, no big deal. RTR is not used that much nowadays anyway.


def _recv_internal(self, timeout):
try:
fr = self.__session_receive.frames.read(4, timeout=0.0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The library definitely seems a bit unfinished but that's not your fault.

Copy link
Collaborator

@christiansandberg christiansandberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may need to run your files through black to make CI happy.

Copy link
Owner

@hardbyte hardbyte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎆 Thanks for the contribution!

@jaesc jaesc closed this Jan 20, 2021
@jaesc jaesc reopened this Jan 20, 2021
@jaesc
Copy link
Contributor Author

jaesc commented Jan 25, 2021

Hi, I'm not sure if I need to do anything else in order to close the pull request or if it's pending for someone.
Thanks!

@jaesc jaesc closed this Jan 25, 2021
@jaesc jaesc reopened this Jan 25, 2021
@hardbyte hardbyte added this to the 4.0 Release milestone Feb 1, 2021
@hardbyte hardbyte added the backend:nixnet National Instruments - XNET label Feb 1, 2021
@hardbyte hardbyte merged commit 0a0c7bd into hardbyte:develop Feb 1, 2021
felixdivo added a commit that referenced this pull request Oct 27, 2021
Part of #1046.

Since the NI-XNET interface was not released in a stable release yet (see #968), we can freely change the exception handling without deprecation notices.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:nixnet National Instruments - XNET
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants