Skip to content
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

NTCAN hardware layer #198

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

NTCAN hardware layer #198

wants to merge 3 commits into from

Conversation

Y-Less
Copy link

@Y-Less Y-Less commented Mar 3, 2023

I wanted to add support for this virtual CAN bus:

https://esd.eu/en/products/can-sdk

I know there's a basic virtual CAN already in the library, but it doesn't work between processes.

This is only a very basic first pass at the code (and clearly copied almost wholesale from the PCAN implementation), just here for any early comments (I've not even tested it yet). They do claim that their library is cross-platform, so there may be a way to support Linux in here as well. You may notice that the bundled .lib files are in sub-directories instead of using the existing _x86 and _x64 naming convention on other libraries. This is because the include itself, copied from their SDK, looks for a file named exactly ntcan.lib via #pragma.

@Y-Less Y-Less temporarily deployed to Integrate Pull Request March 3, 2023 02:11 — with GitHub Actions Inactive
Copy link
Member

@ad3154 ad3154 left a comment

Choose a reason for hiding this comment

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

I know it's still in a draft state but here's some initial thoughts. Nothing major but I worry about them using an All Rights Reserved in their header file. We will have to do our due diligence to see if this can be added to the repo in the first place.

hardware_integration/src/ntcan_fifo_plugin.cpp Outdated Show resolved Hide resolved
hardware_integration/src/ntcan_fifo_plugin.cpp Outdated Show resolved Hide resolved
* *
* ntcan.h -- NTCAN-API procedure declarations and constant definitions *
* *
* Copyright (c) 1997 - 2022, esd electronics gmbh. All rights reserved. *
Copy link
Member

Choose a reason for hiding this comment

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

All rights reserved is more restrictive than MIT license - we may not be able to include this file in our project. I will have to check their EULA...

if (NTCAN_SUCCESS == openResult)
{
ids = 0x20000000;
openResult = canIdRegionAdd(handle, 0 | NTCAN_20B_BASE, &ids);
Copy link
Member

Choose a reason for hiding this comment

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

0 | something is always something. Do you need the 0?

hardware_integration/src/ntcan_fifo_plugin.cpp Outdated Show resolved Hide resolved
hardware_integration/src/ntcan_fifo_plugin.cpp Outdated Show resolved Hide resolved
@ad3154 ad3154 added the enhancement New feature or request label Mar 3, 2023
@ad3154 ad3154 self-assigned this Mar 3, 2023
@Y-Less
Copy link
Author

Y-Less commented Mar 3, 2023

Thanks for the comments. Fortunately most of those seem fairly trivial. As for the main point - basic testing has at least confirmed it works.

@Y-Less
Copy link
Author

Y-Less commented Mar 4, 2023

So I'm not sure what the best way to deal with removing the explicit width types in, since I used those to match what the NTCAN API expects. If a function expects uint64_t I don't want to pass long long just in case... But maybe I should and just accept errors when they don't match. On the other hand the explicit width types are not exposed outside the plugin at all, and since the API itself has them this code isn't introducing any new incompatibilities that aren't introduced by the API itself. I've prefixed them with std:: anyway though.

0 | NTCAN_20B_BASE was me trying to be explicit. It is address 0 with the extended IDs flag, rather than just the flag alone. Yes it is pointless from a maths point of view, but I thought it was more helpful from an understanding point of view. I added a comment to this effect.

As for the inclusion of the library directly, I did that because the PCAN one did and I was just trying to emulate the existing style. However, since you need the driver installed to use this hardware backend anyway, and that includes the SDK with the latest version of the includes and libs, I don't think much is lost by removing it entirely and not worrying about the licenses at all. I can even rebase and purge the copies from git history.

Alex Cole added 3 commits March 9, 2023 08:49
- Prefix types with `std::`.
- Comment `| 0`.
- Still using explicit width types, because they're what the API takes (and none are exposed outside the plugin).
- Not a suggestion, but I switched to using `<< 11` and `<< 29` instead of more magic numbers to make it slightly clearer that those numbers are to do with CAN 11- and 29-bit identifiers.
- Reduced some scopes.
@Y-Less Y-Less temporarily deployed to Integrate Pull Request March 9, 2023 08:50 — with GitHub Actions Inactive
@Y-Less
Copy link
Author

Y-Less commented Mar 9, 2023

I've rebased and removed the copies of the ntcan library. Now you just have to link it correctly.

@sonarcloud
Copy link

sonarcloud bot commented Mar 9, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants