- Notifications
You must be signed in to change notification settings - Fork 665
Software filtering for all Buses#277
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
felixdivo commented Mar 6, 2018 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
christiansandberg left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try not to change unrelated lines in a pull request. Makes it more difficult to review.
can/bus.py Outdated
| * :meth:`~can.BusABC.shutdown` to override how the bus should | ||
| shut down, in which case the class has to either call through | ||
| `super().shutdown()` or call :meth:`~can.BusABC.flush_tx_buffer` | ||
| on its own |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flushing buffer is usually unnecessary.
felixdivoMar 8, 2018 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See below on the discussion of def shutdown(): ....
can/bus.py Outdated
| # try next one only if there still is time, and with reduced timeout | ||
| else: | ||
| timeout = timeout - (time() - start) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this even correct? Maybe something like time_left = timeout - (time() - start) and use time_left in the _recv_internal call. Then you also need to set time_left = timeout in the beginning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are right of course.
can/bus.py Outdated
| :return: A started task instance | ||
| :rtype: can.CyclicSendTaskABC | ||
| :rtype: :class:`can.CyclicSendTaskABC` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't think you need to change this. See Sphinx docs.
can/bus.py Outdated
| """ | ||
| raise NotImplementedError("Trying to set_filters on unsupported bus") | ||
| # TODO: add unit testing for this method |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also if filters is empty then this should always return True.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right!
can/bus.py Outdated
| # then check for the mask and id | ||
| can_id = can_filter['can_id'] | ||
| can_mask = can_filter['can_mask'] | ||
| if msg.arbitration_id & can_mask == can_id & can_mask: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be faster to use (can_id ^ msg.arbitration_id) & can_mask == 0 but is harder to read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will replace it and leave a comment explaining it.
can/bus.py Outdated
| """ | ||
| Called to carry out any interface specific cleanup required | ||
| in shutting down a bus. | ||
| in shutting down a bus. Calls :meth:`~can.BusABC.flush_tx_buffer`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know the reason for this. Maybe remove it. Is there any interface using it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, ixxat, kavaser, nican and vector all implement flush_tx_buffer(). But none of the interfaces calls the method, at least none of the internal ones. I propose we remove the call to flush_tx_buffer() from shutdown() and remove the comment I added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See 6a4aa5b.
can/bus.py Outdated
| """ | ||
| Read a message from the bus and tell whether it was filtered. | ||
| :raise: :class:`can.CanError` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use :raises can.Error: instead. See Sphinx.
can/bus.py Outdated
| else: | ||
| return None | ||
| @abstractmethod |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't make this abstract or it will brake older external implementations. If an interface implements recv() directly then this will also work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, I changed it.
felixdivo commented Apr 4, 2018
Shall I change all internal interfaces to work with this new ABC, or shall I change the ABC first? |
felixdivo commented May 1, 2018
@hardbyte What do you think? |
felixdivo commented May 1, 2018 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
TODO: General:
Switch interfaces to new abstract base class methods:
DONE |
felixdivo commented May 16, 2018 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
@christiansandberg@hardbyte I finished this PR as far as I know. The changing of all 13 backend interfaces as well as the core API has lead to many changes that ware required all over the place, along with a lot of cleanup effort that went into this. The goal of this PR is to unify the API more than it was previously the case, which was quite messy. But all unittests now run together with the new one I added. |
hardbyte left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic work @felixdivo - a couple of documentation related things I think can be improved before merging.
can/bus.py Outdated
| """Construct and open a CAN bus instance of the specified type. | ||
| Subclasses should call though this one with all parameters as | ||
| it applies filters (for now). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep in mind that a lot of the code comments have lasted many many years so when people read "for now" they won't easily have any idea if that is talking of change to come soon... or was an idea the developer had 5 years earlier...
can/bus.py Outdated
| """ | ||
| Contains the ABC bus implementation. | ||
| Contains the ABC bus implementation and it's documentation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: it's "its"
can/bus.py Outdated
| """Block waiting for a message from the Bus. | ||
| :param float timeout: Seconds to wait for a message. | ||
| If the concrete bus does not override it, this method makes sure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is reading like library developer documentation - not user documentation.
This class along with the Message data class is essentially the primary interface to python-can. The front page of the docs links directly to API Docs -> Bus. I think this needs to be moved into an interface developers section of the docs.
| class ICSApiError(CanError): | ||
| """ | ||
| TODO add docs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes please - or remove the docstring
| makes Sphinx complain about more subtle problems. | ||
| Creating a new interface/backend |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for writing this! 🥇
This basically implements #157 (with some small changes).
The
BusABCclass is now finished, and I want to ask whether that is looking good. If it is, I will adjust the other interfaces one by one to make it work with this new frontend. It shouldn't be too much work though. It would be nice if someone could comment on the docstrings / the semantics of the methods.Well, and the tests will obviously fail for now.
I also did some refactoring in interface.py so it will be quite easy to add support for #51 later.
Closes#157. Closes#104.