-
Notifications
You must be signed in to change notification settings - Fork 673
Adding multiple channels support to neoVI #415
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
Changes from 1 commit
3f8e239
4ffa9b9
822a7ff
4ab7f99
f9ddd86
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,9 +69,10 @@ class NeoViBus(BusABC): | |
|
|
||
| def __init__(self, channel, can_filters=None, **config): | ||
| """ | ||
|
|
||
| :param int channel: | ||
| The Channel id or name to create this bus with. | ||
| :param list channel: | ||
| The channel ids to create this bus with. | ||
| Can also be a single integer, netid name or a comma separated | ||
| string. | ||
| :param list can_filters: | ||
| See :meth:`can.BusABC.set_filters` for details. | ||
| :param use_system_timestamp: | ||
|
|
@@ -98,18 +99,14 @@ def __init__(self, channel, can_filters=None, **config): | |
| logger.info("CAN Filters: {}".format(can_filters)) | ||
| logger.info("Got configuration of: {}".format(config)) | ||
|
|
||
| self._use_system_timestamp = bool( | ||
| config.get('use_system_timestamp', False) | ||
| ) | ||
| try: | ||
| channel = int(channel) | ||
| except ValueError: | ||
| channel = getattr(ics, "NETID_{}".format(channel.upper()), -1) | ||
| if channel == -1: | ||
| raise ValueError( | ||
| 'channel must be an integer or ' | ||
| 'a valid ICS channel name' | ||
| ) | ||
| if isinstance(channel, (list, tuple)): | ||
|
felixdivo marked this conversation as resolved.
|
||
| self.channels = channel | ||
| elif isinstance(channel, int): | ||
| self.channels = [channel] | ||
| else: | ||
| # Assume comma separated string of channels | ||
| self.channels = [ch.strip() for ch in channel.split(',')] | ||
| self.channels = [NeoViBus.channel_to_netid(ch) for ch in self.channels] | ||
|
|
||
| type_filter = config.get('type_filter') | ||
| serial = config.get('serial') | ||
|
|
@@ -125,15 +122,33 @@ def __init__(self, channel, can_filters=None, **config): | |
| ics.set_fd_bit_rate( | ||
| self.dev, config.get('data_bitrate'), channel) | ||
|
|
||
| self._use_system_timestamp = bool( | ||
| config.get('use_system_timestamp', False) | ||
| ) | ||
|
|
||
| self.channel_info = '%s %s CH:%s' % ( | ||
| self.dev.Name, | ||
| self.get_serial_number(self.dev), | ||
| channel | ||
| self.channels | ||
| ) | ||
| logger.info("Using device: {}".format(self.channel_info)) | ||
|
|
||
| self.rx_buffer = deque() | ||
| self.network = channel if channel is not None else None | ||
|
|
||
| @staticmethod | ||
| def channel_to_netid(channel_name_or_id): | ||
| try: | ||
| channel = int(channel_name_or_id) | ||
| except ValueError: | ||
| netid = "NETID_{}".format(channel_name_or_id.upper()) | ||
| if hasattr(ics, netid): | ||
| channel = getattr(ics, netid) | ||
| else: | ||
| raise ValueError( | ||
| 'channel must be an integer or ' | ||
| 'a valid ICS channel name' | ||
| ) | ||
| return channel | ||
|
|
||
| @staticmethod | ||
| def get_serial_number(device): | ||
|
|
@@ -203,7 +218,7 @@ def _process_msg_queue(self, timeout=0.1): | |
| except ics.RuntimeError: | ||
| return | ||
| for ics_msg in messages: | ||
| if ics_msg.NetworkID != self.network: | ||
| if ics_msg.NetworkID not in self.channels: | ||
| continue | ||
| self.rx_buffer.append(ics_msg) | ||
| if errors: | ||
|
|
@@ -258,7 +273,7 @@ def _ics_msg_to_message(self, ics_msg): | |
| bitrate_switch=bool( | ||
| ics_msg.StatusBitField3 & ics.SPY_STATUS3_CANFD_BRS | ||
| ), | ||
| channel=ics_msg.NetworkID | ||
| channel=int(ics_msg.NetworkID) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this already an int? If not, wouldn't line 221 fail? |
||
| ) | ||
| else: | ||
| return Message( | ||
|
|
@@ -273,7 +288,7 @@ def _ics_msg_to_message(self, ics_msg): | |
| is_remote_frame=bool( | ||
| ics_msg.StatusBitField & ics.SPY_STATUS_REMOTE_FRAME | ||
| ), | ||
| channel=ics_msg.NetworkID | ||
| channel=int(ics_msg.NetworkID) | ||
| ) | ||
|
|
||
| def _recv_internal(self, timeout=0.1): | ||
|
|
@@ -314,7 +329,11 @@ def send(self, msg, timeout=None): | |
| message.StatusBitField = flag0 | ||
| message.StatusBitField2 = 0 | ||
| message.StatusBitField3 = flag3 | ||
| message.NetworkID = self.network | ||
| if msg.channel is not None: | ||
| message.NetworkID = msg.channel | ||
| else: | ||
| # defaults to the first channel in channels | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be surprising! We should at least document this clearly, or maybe even raise an Exception? Another option would be to send it to all, but I guess that is unexpected as well? |
||
| message.NetworkID = self.channels[0] | ||
|
|
||
| try: | ||
| ics.transmit_messages(self.dev, message) | ||
|
|
||
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, we should annotate this with the correct type. See "Container types such as lists and dictionaries can be linked automatically using the following syntax: ...".