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

add acceptance filter configuration helper #171

Merged
merged 3 commits into from
Dec 4, 2021

Conversation

coderkalyan
Copy link
Contributor

@coderkalyan coderkalyan commented Jul 19, 2021

Briefly tested all 3 functions on a test project with yakut. Appears to work, and it's super simple.

@pavel-kirienko Does it make more sense from an API perspective to use the CanardInstance itself as an argument for the service generator and pull the local node id from that?

Closes #169

Copy link
Member

@pavel-kirienko pavel-kirienko left a comment

Choose a reason for hiding this comment

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

Wow this is nice. Few things to look into:

  • Please run make format to fix non-conformant formatting. You will need clang-format v11.

  • Bump minor version & update the changelog.

  • The current test coverage of 0% is ∞ times below the required level.

  • I see that canardMakeAcceptanceFilterConfigForService() accepts the service-ID as well, while in my proposal it was intentionally omitted. The assumption was that service transfers are addressed transfers rather than opt-in like messages. If you have a match on the destination node-ID, then there is a good chance you need to handle that transfer. Combined with the fact that in UAVCAN networks service traffic takes only a small percentage of the total network load, it makes sense to simplify the API by accepting all service transfers where the destination node-ID matches the local node-ID. The way you did it certainly also works but remember that the number of hardware acceptance filters is usually limited which will force most users to use canardConsolidateAcceptanceFilterConfigs(). Both approaches are valid and usable, but if you prefer to keep yours, then I suggest updating the usage demo with a simple loop that consolidates all service filters into one config to show the most common usage scenario. Remember that you need not only service-IDs you serve but also those you invoke (otherwise responses will get lost). Overall this may somewhat increase the perceived complexity of the API.

Does it make more sense from an API perspective to use the CanardInstance itself as an argument for the service generator and pull the local node id from that?

Probably not, I think, because passing only the node-ID allows us to segregate the filter API from the rest of the library, potentially making this API more reusable (e.g., what if you need to configure filters for a different node). OTOH, if one were to turn this principle up to eleven, the entire CanardInstance would have to be refactored into a collection of smaller, more granular interfaces, which I would have probably done if this library was written in an OOP-friendly language instead of C. I think implementing it the way you did it is the most reasonable approach.

I just noticed that our CI is borked, asked Clyde to look into that.

libcanard/canard.h Outdated Show resolved Hide resolved
@coderkalyan
Copy link
Contributor Author

coderkalyan commented Jul 23, 2021

Everything other than tests have been fixed (haven't pushed the updates yet). Still trying to figure out how/what tests to write 😄 The new Github Actions CI is also almost ready.

@pavel-kirienko
Copy link
Member

Add a new file like test_acceptance_filter.cpp under /tests. Write a test function that invokes canardMakeAcceptanceFilterConfigForSubject() with a few different values and ensures that the output matches the expected value. Likewise for canardMakeAcceptanceFilterConfigForService() and canardConsolidateAcceptanceFilterConfigs(). These are simple functions so I don't expect the test to be longer than a couple dozen of lines.

@pavel-kirienko
Copy link
Member

@coderkalyan please rebase this to my v2 branch.

@coderkalyan coderkalyan changed the base branch from master to v2 October 10, 2021 04:43
@pavel-kirienko pavel-kirienko mentioned this pull request Oct 13, 2021
@coderkalyan coderkalyan force-pushed the acceptance-filters branch 3 times, most recently from 0b2eba7 to 5bf56cb Compare November 3, 2021 04:24
@coderkalyan
Copy link
Contributor Author

@pavel-kirienko This has been rebased onto your v2 branch, and I wrote a few lines of tests, but I'm not fully sure if they meet the requirements. Could you take a look and send feedback?

Copy link
Member

@pavel-kirienko pavel-kirienko left a comment

Choose a reason for hiding this comment

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

It generally looks okay with a few notes:

  • The unit test won't compile, I take it it's still incomplete.
  • Clang-Tidy complains about dangerous implicit casts, this one is an easy fix (just explicitly upcast your small fields like the node-ID).
  • I neglected to notice it earlier but our newly added identifiers are longer than 31 character, which is non-conformant with AUTOSAR/MISRA. Can we please just replace AcceptanceFilterConfig -> Filter everywhere (both functions and the type)?

libcanard/canard.h Outdated Show resolved Hide resolved
libcanard/canard.h Outdated Show resolved Hide resolved
libcanard/canard.h Outdated Show resolved Hide resolved
libcanard/canard.h Outdated Show resolved Hide resolved
@coderkalyan coderkalyan force-pushed the acceptance-filters branch 6 times, most recently from 0ea9197 to 79ad956 Compare November 11, 2021 21:37
@coderkalyan coderkalyan force-pushed the acceptance-filters branch 6 times, most recently from d3a7546 to b6c1915 Compare December 4, 2021 05:27
Adds helper API functions for configuring CAN controller hardware
acceptance filters.
@coderkalyan
Copy link
Contributor Author

Ready for review again. I believe all the comments have been addressed and the CI is passing now. Other than the sonarcloud, that is, which is addressed in #186

@pavel-kirienko pavel-kirienko merged commit 13cb7b1 into OpenCyphal:v2 Dec 4, 2021
pavel-kirienko added a commit that referenced this pull request Dec 4, 2021
* Drop canard_dsdl, use Nunavut instead

* Upgrade CI to LLVM 13

* Actualize license headers

* Support redundant transmission queues and use more consistent public field naming

* Ditch the deprecated canardRxAccept(), rename canardRxAccept2()

* Refactor the API to eliminate the need to cast away const qualifiers; fixes #175

* Tighten up memory checking in the test suite -- add canaries

* Fix race condition in the roundtrip test

* Do not use Catch2 macros from non-main thread because it is not thread-safe

* Support CANARD_CONFIG_HEADER

* CI: add style_check job

* Use AVL tree in the transmission queue

* Remove all linked lists

* Reduce indirection, pointer casts, and memory footprint by exposing the AVL tree in the public API

* Disable C++-specific warnings as they make no sense for a C library

* Add table-based CRC option (#186)

* CI: disable SonarCloud on forks

* Add docker utilities (#187)

* Add acceptance filter configuration helpers (#171)

Co-authored-by: Kalyan Sriram <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Acceptance filter configuration helpers
2 participants