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

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

Merged
merged 14 commits into from
Sep 4, 2023

Conversation

aentinger
Copy link
Contributor

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

…Ds following a <linux/can.h> inspired approach.
@aentinger aentinger self-assigned this Aug 2, 2023
@codecov-commenter
Copy link

codecov-commenter commented Aug 2, 2023

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
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 {

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;

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

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).

api/CanMsg.h Show resolved Hide resolved
api/CanMsg.h Show resolved Hide resolved
@facchinm
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
4 checks passed
@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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants