@@ -69,9 +69,10 @@ class NeoViBus(BusABC):
6969
7070 def __init__ (self , channel , can_filters = None , ** config ):
7171 """
72-
73- :param int channel:
74- The Channel id or name to create this bus with.
72+ :param list channel:
73+ The channel ids to create this bus with.
74+ Can also be a single integer, netid name or a comma separated
75+ string.
7576 :param list can_filters:
7677 See :meth:`can.BusABC.set_filters` for details.
7778 :param use_system_timestamp:
@@ -98,18 +99,14 @@ def __init__(self, channel, can_filters=None, **config):
9899 logger .info ("CAN Filters: {}" .format (can_filters ))
99100 logger .info ("Got configuration of: {}" .format (config ))
100101
101- self ._use_system_timestamp = bool (
102- config .get ('use_system_timestamp' , False )
103- )
104- try :
105- channel = int (channel )
106- except ValueError :
107- channel = getattr (ics , "NETID_{}" .format (channel .upper ()), - 1 )
108- if channel == - 1 :
109- raise ValueError (
110- 'channel must be an integer or '
111- 'a valid ICS channel name'
112- )
102+ if isinstance (channel , (list , tuple )):
103+ self .channels = channel
104+ elif isinstance (channel , int ):
105+ self .channels = [channel ]
106+ else :
107+ # Assume comma separated string of channels
108+ self .channels = [ch .strip () for ch in channel .split (',' )]
109+ self .channels = [NeoViBus .channel_to_netid (ch ) for ch in self .channels ]
113110
114111 type_filter = config .get ('type_filter' )
115112 serial = config .get ('serial' )
@@ -125,15 +122,33 @@ def __init__(self, channel, can_filters=None, **config):
125122 ics .set_fd_bit_rate (
126123 self .dev , config .get ('data_bitrate' ), channel )
127124
125+ self ._use_system_timestamp = bool (
126+ config .get ('use_system_timestamp' , False )
127+ )
128+
128129 self .channel_info = '%s %s CH:%s' % (
129130 self .dev .Name ,
130131 self .get_serial_number (self .dev ),
131- channel
132+ self . channels
132133 )
133134 logger .info ("Using device: {}" .format (self .channel_info ))
134135
135136 self .rx_buffer = deque ()
136- self .network = channel if channel is not None else None
137+
138+ @staticmethod
139+ def channel_to_netid (channel_name_or_id ):
140+ try :
141+ channel = int (channel_name_or_id )
142+ except ValueError :
143+ netid = "NETID_{}" .format (channel_name_or_id .upper ())
144+ if hasattr (ics , netid ):
145+ channel = getattr (ics , netid )
146+ else :
147+ raise ValueError (
148+ 'channel must be an integer or '
149+ 'a valid ICS channel name'
150+ )
151+ return channel
137152
138153 @staticmethod
139154 def get_serial_number (device ):
@@ -203,7 +218,7 @@ def _process_msg_queue(self, timeout=0.1):
203218 except ics .RuntimeError :
204219 return
205220 for ics_msg in messages :
206- if ics_msg .NetworkID != self .network :
221+ if ics_msg .NetworkID not in self .channels :
207222 continue
208223 self .rx_buffer .append (ics_msg )
209224 if errors :
@@ -258,7 +273,7 @@ def _ics_msg_to_message(self, ics_msg):
258273 bitrate_switch = bool (
259274 ics_msg .StatusBitField3 & ics .SPY_STATUS3_CANFD_BRS
260275 ),
261- channel = ics_msg .NetworkID
276+ channel = int ( ics_msg .NetworkID )
262277 )
263278 else :
264279 return Message (
@@ -273,7 +288,7 @@ def _ics_msg_to_message(self, ics_msg):
273288 is_remote_frame = bool (
274289 ics_msg .StatusBitField & ics .SPY_STATUS_REMOTE_FRAME
275290 ),
276- channel = ics_msg .NetworkID
291+ channel = int ( ics_msg .NetworkID )
277292 )
278293
279294 def _recv_internal (self , timeout = 0.1 ):
@@ -314,7 +329,11 @@ def send(self, msg, timeout=None):
314329 message .StatusBitField = flag0
315330 message .StatusBitField2 = 0
316331 message .StatusBitField3 = flag3
317- message .NetworkID = self .network
332+ if msg .channel is not None :
333+ message .NetworkID = msg .channel
334+ else :
335+ # defaults to the first channel in channels
336+ message .NetworkID = self .channels [0 ]
318337
319338 try :
320339 ics .transmit_messages (self .dev , message )
0 commit comments