Skip to content

Improved channel handling #332

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

Merged
merged 3 commits into from
Jun 25, 2018

Conversation

christiansandberg
Copy link
Collaborator

Make Notifier support multiple buses
Add support for channels in more formats, interfaces, and loggers

Make Notifier support multiple buses
Add support for channels in more formats, interfaces, and loggers
@@ -197,8 +198,12 @@ def on_message_received(self, msg):
if msg.is_extended_id:
arb_id += 'x'

# Many interfaces start channel numbering at 0 which is invalid
channel = msg.channel + 1 if isinstance(msg.channel, int) else self.channel
channel = channel2int(msg.channel)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this always be turned into an int? Because SocketCAN's vcan0/can2 are hard to transform into a int. Same applies for BLF as well. Or is that required by the file format? Because then, it should be noted in the code and/or the class docs, because users might expect that Message 1 -> Writer -> Reader -> Message 2 results in Message 1 == Message 2. That should be added somewhere as a warning/note or whatever.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Unfortunately the ASC format requires integers (same as BLF). So the channel read back may be different than the one put in. 😞 I still think it's better than not being able to tell the channels apart at all.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yep, you are right. Who designs such short-sighted protocols ... ? Well anyways, we should note that somewhere in the docs at least.

can/notifier.py Outdated
self._running = False
timeout = self.timeout + 0.1 if self.timeout is not None else 5
for reader in self._readers:
reader.join(timeout)
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe add a timeout parameter to the method. Additionally, it might be surprising that the timeout counts for each bus. So for five channels and a timeout of one seconds, this method could block 5 seconds although many would expect it to block 1 second.

can/util.py Outdated
def channel2int(channel):
"""Try to convert the channel to an integer.

:param str channel:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we should support arbitrary Python objects here, because the virtual and other future interfaces might use anything as an channel identifier. We could just check for type character string, None, and integral number, and simply use channel = str(channel) or channel = repr(channel) for the rest.

can/notifier.py Outdated
:param bus: The :ref:`bus` to listen too.
:param listeners: An iterable of :class:`~can.Listener`s
:param timeout: An optional maximum number of seconds to wait for any message.
:param bus: The :ref:`bus` or list of buses to listen to.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would say any iterable should do.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It seems to be difficult to determine if a variable is iterable or not in an easy way. I'm not sure when one would need an iterable instead of a list.

@@ -13,57 +13,62 @@

class Notifier(object):
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should probably add a test for this class that includes multiple buses & listeners.

@felixdivo felixdivo added the api label Jun 20, 2018
@christiansandberg christiansandberg merged commit c4752b2 into hardbyte:develop Jun 25, 2018
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.

2 participants