Conversation
christiansandberg
left a comment
There was a problem hiding this comment.
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.
Flushing buffer is usually unnecessary.
There was a problem hiding this comment.
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.
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.
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.
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.
Also if filters is empty then this should always return True.
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.
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.
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.
I don't know the reason for this. Maybe remove it. Is there any interface using it?
There was a problem hiding this comment.
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.
can/bus.py
Outdated
| """ | ||
| Read a message from the bus and tell whether it was filtered. | ||
|
|
||
| :raise: :class:`can.CanError` |
can/bus.py
Outdated
| else: | ||
| return None | ||
|
|
||
| @abstractmethod |
There was a problem hiding this comment.
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.
You are right, I changed it.
|
Shall I change all internal interfaces to work with this new ABC, or shall I change the ABC first? |
|
@hardbyte What do you think? |
|
TODO: General:
Switch interfaces to new abstract base class methods:
DONE |
|
@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.
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.
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. |
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.
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.
Yes please - or remove the docstring
| makes Sphinx complain about more subtle problems. | ||
|
|
||
|
|
||
| Creating a new interface/backend |
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.