Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Extend CanMsg to allow to distinguish between standard and extended ids ... #194

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
aentinger merged 14 commits into master from fix-11-bit-can-id
Sep 4, 2023

Conversation

Copy link
Contributor

@aentinger aentinger commented Aug 2, 2023

... following a <linux/can.h> inspired approach.

designer2k2 reacted with thumbs up emoji
@aentinger aentinger self-assigned this Aug 2, 2023
Copy link

codecov-commenter commented Aug 2, 2023
edited
Loading

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.16% 🎉

Comparison is base (84b98c7) 95.77% compared to head (e091080) 95.93%.

Additional details and impacted files
@@ Coverage Diff @@
## master #194 +/- ##
==========================================
+ Coverage 95.77% 95.93% +0.16% 
==========================================
 Files 13 14 +1 
 Lines 970 1009 +39 
==========================================
+ Hits 929 968 +39 
 Misses 41 41 
Files Changed Coverage Δ
api/CanMsg.h 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

aentinger added 11 commits August 2, 2023 08:35
...n order to eliminate the 3 MSBits encoded status flags.
... files, inline functions to prevent linker errors, and define static constants so that the compiler can place them in memory. All of those changes broaden adoption.
Copy link
Contributor Author

Hi @facchinm ☕ 👋

This PR is required by

which support both standard (11-Bit) and extended (29-Bit) CAN IDs by the respective platform libraries.

I'm not a 💯 on the proposed design, especially id still being a publicly exposed member variable. Personally I'd like to turn id private, something that would also work with both aforementioned pull requests, but may cause problems for users which have already adopted the new CAN API. I'd love to hear your thoughts on this.

Copy link

@thirtytwobits thirtytwobits left a comment

Choose a reason for hiding this comment

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

Really exciting to see CAN move forward in Arduino and looking forward to CAN-FD support in this header.

@@ -82,11 +92,45 @@ class CanMsg : public Printable
return n;
}


uint32_t getStandardId() const {
Copy link

@thirtytwobits thirtytwobits Aug 10, 2023

Choose a reason for hiding this comment

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

Would it make sense to make the ID an ADT? That way you could have something like:

class CanId : public Printable
{
 virtual uint32_t toInt() const = 0;
};
class ExtendedCanId : public CanId
...
class StandardCanId: public CanId
...

This would allow libraries to be written that extend this to things like:

class DroneCANId : public ExtendedCanId
...
class CyphalId : public ExtendedCandId
...
class ARINC825 : public ExtendedCanId
...
// etc.

@@ -31,14 +33,19 @@ namespace arduino
class CanMsg : public Printable
{
public:
static size_t constexpr MAX_DATA_LENGTH = 8;
static uint8_t constexpr MAX_DATA_LENGTH = 8;
Copy link

@thirtytwobits thirtytwobits Aug 10, 2023

Choose a reason for hiding this comment

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

Of course, the thing that is most irksome when you finally add CAN-FD support is the quantization of the DLC. If you are trying to get ahead of adoption and avoid future churn you might want to start moving away from an integer data_length type to an enumerated one now.

Copy link
Contributor Author

@aentinger aentinger Aug 10, 2023

Choose a reason for hiding this comment

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

I had been thinking of making a CanFdMsg whose MAX_DATA_LENGTH would be 64 then. Overall I'm a fan of const/constexpr over enum because they provide a strong type guarantee (vs. enum that easily and without warning converts to int, etc.).

Note: enum classes in public Arduino APIs are discouraged (they'd provide strong type support).

Copy link
Member

especially id still being a publicly exposed member variable.

I'm ok for leaving it public to keep the APIs space simpler and allow some optimizations for libraries adopting this.

@aentinger aentinger marked this pull request as ready for review September 4, 2023 09:46
@aentinger aentinger merged commit fbc0646 into master Sep 4, 2023
@aentinger aentinger deleted the fix-11-bit-can-id branch September 4, 2023 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@facchinm facchinm facchinm approved these changes

+1 more reviewer

@thirtytwobits thirtytwobits thirtytwobits left review comments

Reviewers whose approvals may not affect merge requirements
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /