Skip to content

Conversation

@felixdivo
Copy link
Collaborator

@felixdivofelixdivo commented Mar 6, 2018

This basically implements #157 (with some small changes).

The BusABC class 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.

Copy link
Collaborator

@christiansandbergchristiansandberg left a 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
Copy link
Collaborator

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.

Copy link
CollaboratorAuthor

@felixdivofelixdivoMar 8, 2018

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)
Copy link
Collaborator

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.

Copy link
CollaboratorAuthor

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`
Copy link
Collaborator

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
Copy link
Collaborator

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.

Copy link
CollaboratorAuthor

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:
Copy link
Collaborator

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.

Copy link
CollaboratorAuthor

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`.
Copy link
Collaborator

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?

Copy link
CollaboratorAuthor

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.

Copy link
CollaboratorAuthor

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`
Copy link
Collaborator

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
Copy link
Collaborator

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.

Copy link
CollaboratorAuthor

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
Copy link
CollaboratorAuthor

Shall I change all internal interfaces to work with this new ABC, or shall I change the ABC first?

@felixdivo
Copy link
CollaboratorAuthor

@hardbyte What do you think?

@felixdivo
Copy link
CollaboratorAuthor

felixdivo commented May 1, 2018

TODO:

General:

  • We also need tests to check that everything works as intended. (see test/test_message_filtering.py)

Switch interfaces to new abstract base class methods:

  • kvaser
  • socketcan_ctypes
  • socketcan_native
  • serial
  • pcan
  • usb2can
  • ixxat
  • nican
  • iscan
  • virtual
  • neovi
  • vector
  • slcan

DONE

@felixdivo
Copy link
CollaboratorAuthor

felixdivo commented May 16, 2018

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

Copy link
Owner

@hardbytehardbyte left a 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).
Copy link
Owner

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.
Copy link
Owner

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
Copy link
Owner

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
Copy link
Owner

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

@hardbytehardbyte added this to the 2.2 Release milestone May 27, 2018
makes Sphinx complain about more subtle problems.


Creating a new interface/backend
Copy link
Owner

Choose a reason for hiding this comment

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

Thanks for writing this! 🥇

@felixdivofelixdivo merged commit 4ba482f into developMay 28, 2018
@felixdivofelixdivo deleted the software-filtering branch May 28, 2018 05:45
Sign up for freeto 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

@felixdivo@hardbyte@christiansandberg@AntonioCohimbra