Skip to content
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

Updated instances of **config to **kwargs, closes #492 #536

Merged
merged 1 commit into from
Mar 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions can/bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class BusABC(object):
RECV_LOGGING_LEVEL = 9

@abstractmethod
def __init__(self, channel, can_filters=None, **config):
def __init__(self, channel, can_filters=None, **kwargs):
"""Construct and open a CAN bus instance of the specified type.

Subclasses should call though this method with all given parameters
Expand All @@ -45,7 +45,7 @@ def __init__(self, channel, can_filters=None, **config):
:param list can_filters:
See :meth:`~can.BusABC.set_filters` for details.

:param dict config:
:param dict kwargs:
Any backend dependent configurations are passed in this dictionary
"""
self._periodic_tasks = []
Expand Down
28 changes: 14 additions & 14 deletions can/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class Bus(BusABC):
"""

@staticmethod
def __new__(cls, channel=None, *args, **config):
def __new__(cls, channel=None, *args, **kwargs):
"""
Takes the same arguments as :class:`can.BusABC.__init__`.
Some might have a special meaning, see below.
Expand All @@ -86,7 +86,7 @@ def __new__(cls, channel=None, *args, **config):

Expected type is backend dependent.

:param dict config:
:param dict kwargs:
Should contain an ``interface`` key with a valid interface name. If not,
it is completed using :meth:`can.util.load_config`.

Expand All @@ -99,32 +99,32 @@ def __new__(cls, channel=None, *args, **config):

# figure out the rest of the configuration; this might raise an error
if channel is not None:
config['channel'] = channel
if 'context' in config:
context = config['context']
del config['context']
kwargs['channel'] = channel
if 'context' in kwargs:
context = kwargs['context']
del kwargs['context']
else:
context = None
config = load_config(config=config, context=context)
kwargs = load_config(config=kwargs, context=context)

# resolve the bus class to use for that interface
cls = _get_class_for_interface(config['interface'])
cls = _get_class_for_interface(kwargs['interface'])

# remove the 'interface' key so it doesn't get passed to the backend
del config['interface']
del kwargs['interface']

# make sure the bus can handle this config format
if 'channel' not in config:
if 'channel' not in kwargs:
raise ValueError("'channel' argument missing")
else:
channel = config['channel']
del config['channel']
channel = kwargs['channel']
del kwargs['channel']

if channel is None:
# Use the default channel for the backend
return cls(*args, **config)
return cls(*args, **kwargs)
else:
return cls(channel, *args, **config)
return cls(channel, *args, **kwargs)


def detect_available_configs(interfaces=None):
Expand Down
28 changes: 14 additions & 14 deletions can/interfaces/ics_neovi/neovi_bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class NeoViBus(BusABC):
https://github.com/intrepidcs/python_ics
"""

def __init__(self, channel, can_filters=None, **config):
def __init__(self, channel, can_filters=None, **kwargs):
"""
:param channel:
The channel ids to create this bus with.
Expand Down Expand Up @@ -98,13 +98,13 @@ def __init__(self, channel, can_filters=None, **config):
raise ImportError('Please install python-ics')

super(NeoViBus, self).__init__(
channel=channel, can_filters=can_filters, **config)
channel=channel, can_filters=can_filters, **kwargs)

logger.info("CAN Filters: {}".format(can_filters))
logger.info("Got configuration of: {}".format(config))
logger.info("Got configuration of: {}".format(kwargs))

if 'override_library_name' in config:
ics.override_library_name(config.get('override_library_name'))
if 'override_library_name' in kwargs:
ics.override_library_name(kwargs.get('override_library_name'))

if isinstance(channel, (list, tuple)):
self.channels = channel
Expand All @@ -115,26 +115,26 @@ def __init__(self, channel, can_filters=None, **config):
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')
type_filter = kwargs.get('type_filter')
serial = kwargs.get('serial')
self.dev = self._find_device(type_filter, serial)
ics.open_device(self.dev)

if 'bitrate' in config:
if 'bitrate' in kwargs:
for channel in self.channels:
ics.set_bit_rate(self.dev, config.get('bitrate'), channel)
ics.set_bit_rate(self.dev, kwargs.get('bitrate'), channel)

fd = config.get('fd', False)
fd = kwargs.get('fd', False)
if fd:
if 'data_bitrate' in config:
if 'data_bitrate' in kwargs:
for channel in self.channels:
ics.set_fd_bit_rate(
self.dev, config.get('data_bitrate'), channel)
self.dev, kwargs.get('data_bitrate'), channel)

self._use_system_timestamp = bool(
config.get('use_system_timestamp', False)
kwargs.get('use_system_timestamp', False)
)
self._receive_own_messages = config.get('receive_own_messages', True)
self._receive_own_messages = kwargs.get('receive_own_messages', True)

self.channel_info = '%s %s CH:%s' % (
self.dev.Name,
Expand Down
16 changes: 8 additions & 8 deletions can/interfaces/ixxat/canlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ class IXXATBus(BusABC):
}
}

def __init__(self, channel, can_filters=None, **config):
def __init__(self, channel, can_filters=None, **kwargs):
"""
:param int channel:
The Channel id to create this bus with.
Expand All @@ -292,13 +292,13 @@ def __init__(self, channel, can_filters=None, **config):
if _canlib is None:
raise ImportError("The IXXAT VCI library has not been initialized. Check the logs for more details.")
log.info("CAN Filters: %s", can_filters)
log.info("Got configuration of: %s", config)
log.info("Got configuration of: %s", kwargs)
# Configuration options
bitrate = config.get('bitrate', 500000)
UniqueHardwareId = config.get('UniqueHardwareId', None)
rxFifoSize = config.get('rxFifoSize', 16)
txFifoSize = config.get('txFifoSize', 16)
self._receive_own_messages = config.get('receive_own_messages', False)
bitrate = kwargs.get('bitrate', 500000)
UniqueHardwareId = kwargs.get('UniqueHardwareId', None)
rxFifoSize = kwargs.get('rxFifoSize', 16)
txFifoSize = kwargs.get('txFifoSize', 16)
self._receive_own_messages = kwargs.get('receive_own_messages', False)
# Usually comes as a string from the config file
channel = int(channel)

Expand Down Expand Up @@ -395,7 +395,7 @@ def __init__(self, channel, can_filters=None, **config):
except (VCITimeout, VCIRxQueueEmptyError):
break

super(IXXATBus, self).__init__(channel=channel, can_filters=None, **config)
super(IXXATBus, self).__init__(channel=channel, can_filters=None, **kwargs)

def _inWaiting(self):
try:
Expand Down
32 changes: 16 additions & 16 deletions can/interfaces/kvaser/canlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ class KvaserBus(BusABC):
The CAN Bus implemented for the Kvaser interface.
"""

def __init__(self, channel, can_filters=None, **config):
def __init__(self, channel, can_filters=None, **kwargs):
"""
:param int channel:
The Channel id to create this bus with.
Expand Down Expand Up @@ -353,18 +353,18 @@ def __init__(self, channel, can_filters=None, **config):
"""

log.info("CAN Filters: {}".format(can_filters))
log.info("Got configuration of: {}".format(config))
bitrate = config.get('bitrate', 500000)
tseg1 = config.get('tseg1', 0)
tseg2 = config.get('tseg2', 0)
sjw = config.get('sjw', 0)
no_samp = config.get('no_samp', 0)
driver_mode = config.get('driver_mode', DRIVER_MODE_NORMAL)
single_handle = config.get('single_handle', False)
receive_own_messages = config.get('receive_own_messages', False)
accept_virtual = config.get('accept_virtual', True)
fd = config.get('fd', False)
data_bitrate = config.get('data_bitrate', None)
log.info("Got configuration of: {}".format(kwargs))
bitrate = kwargs.get('bitrate', 500000)
tseg1 = kwargs.get('tseg1', 0)
tseg2 = kwargs.get('tseg2', 0)
sjw = kwargs.get('sjw', 0)
no_samp = kwargs.get('no_samp', 0)
driver_mode = kwargs.get('driver_mode', DRIVER_MODE_NORMAL)
single_handle = kwargs.get('single_handle', False)
receive_own_messages = kwargs.get('receive_own_messages', False)
accept_virtual = kwargs.get('accept_virtual', True)
fd = kwargs.get('fd', False)
data_bitrate = kwargs.get('data_bitrate', None)

try:
channel = int(channel)
Expand Down Expand Up @@ -400,7 +400,7 @@ def __init__(self, channel, can_filters=None, **config):
4)

if fd:
if 'tseg1' not in config and bitrate in BITRATE_FD:
if 'tseg1' not in kwargs and bitrate in BITRATE_FD:
# Use predefined bitrate for arbitration
bitrate = BITRATE_FD[bitrate]
if data_bitrate in BITRATE_FD:
Expand All @@ -411,7 +411,7 @@ def __init__(self, channel, can_filters=None, **config):
data_bitrate = bitrate
canSetBusParamsFd(self._read_handle, data_bitrate, tseg1, tseg2, sjw)
else:
if 'tseg1' not in config and bitrate in BITRATE_OBJS:
if 'tseg1' not in kwargs and bitrate in BITRATE_OBJS:
bitrate = BITRATE_OBJS[bitrate]
canSetBusParams(self._read_handle, bitrate, tseg1, tseg2, sjw, no_samp, 0)

Expand Down Expand Up @@ -446,7 +446,7 @@ def __init__(self, channel, can_filters=None, **config):
self._timestamp_offset = time.time() - (timer.value * TIMESTAMP_FACTOR)

self._is_filtered = False
super(KvaserBus, self).__init__(channel=channel, can_filters=can_filters, **config)
super(KvaserBus, self).__init__(channel=channel, can_filters=can_filters, **kwargs)

def _apply_filters(self, filters):
if filters and len(filters) == 1:
Expand Down
20 changes: 10 additions & 10 deletions can/interfaces/systec/ucanbus.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class UcanBus(BusABC):
1000000: Baudrate.BAUD_1MBit
}

def __init__(self, channel, can_filters=None, **config):
def __init__(self, channel, can_filters=None, **kwargs):
"""
:param int channel:
The Channel id to create this bus with.
Expand Down Expand Up @@ -96,14 +96,14 @@ def __init__(self, channel, can_filters=None, **config):
raise ImportError("The SYSTEC ucan library has not been initialized.")

self.channel = int(channel)
device_number = int(config.get('device_number', ANY_MODULE))
device_number = int(kwargs.get('device_number', ANY_MODULE))

# configuration options
bitrate = config.get('bitrate', 500000)
bitrate = kwargs.get('bitrate', 500000)
if bitrate not in self.BITRATES:
raise ValueError("Invalid bitrate {}".format(bitrate))

state = config.get('state', BusState.ACTIVE)
state = kwargs.get('state', BusState.ACTIVE)
if state is BusState.ACTIVE or BusState.PASSIVE:
self._state = state
else:
Expand All @@ -112,15 +112,15 @@ def __init__(self, channel, can_filters=None, **config):
# get parameters
self._params = {
"mode": Mode.MODE_NORMAL |
(Mode.MODE_TX_ECHO if config.get('receive_own_messages') else 0) |
(Mode.MODE_TX_ECHO if kwargs.get('receive_own_messages') else 0) |
(Mode.MODE_LISTEN_ONLY if state is BusState.PASSIVE else 0),
"BTR": self.BITRATES[bitrate]
}
# get extra parameters
if config.get("rx_buffer_entries"):
self._params["rx_buffer_entries"] = int(config.get("rx_buffer_entries"))
if config.get("tx_buffer_entries"):
self._params["tx_buffer_entries"] = int(config.get("tx_buffer_entries"))
if kwargs.get("rx_buffer_entries"):
self._params["rx_buffer_entries"] = int(kwargs.get("rx_buffer_entries"))
if kwargs.get("tx_buffer_entries"):
self._params["tx_buffer_entries"] = int(kwargs.get("tx_buffer_entries"))

self._ucan.init_hardware(device_number=device_number)
self._ucan.init_can(self.channel, **self._params)
Expand All @@ -131,7 +131,7 @@ def __init__(self, channel, can_filters=None, **config):
self.channel,
self._ucan.get_baudrate_message(self.BITRATES[bitrate])
)
super(UcanBus, self).__init__(channel=channel, can_filters=can_filters, **config)
super(UcanBus, self).__init__(channel=channel, can_filters=can_filters, **kwargs)

def _recv_internal(self, timeout):
message, _ = self._ucan.read_can_msg(self.channel, 1, timeout)
Expand Down
7 changes: 4 additions & 3 deletions can/interfaces/vector/canlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ class VectorBus(BusABC):

def __init__(self, channel, can_filters=None, poll_interval=0.01,
receive_own_messages=False,
bitrate=None, rx_queue_size=2**14, app_name="CANalyzer", serial=None, fd=False, data_bitrate=None, sjwAbr=2, tseg1Abr=6, tseg2Abr=3, sjwDbr=2, tseg1Dbr=6, tseg2Dbr=3, **config):
bitrate=None, rx_queue_size=2**14, app_name="CANalyzer",
serial=None, fd=False, data_bitrate=None, sjwAbr=2, tseg1Abr=6,
tseg2Abr=3, sjwDbr=2, tseg1Dbr=6, tseg2Dbr=3, **kwargs):
"""
:param list channel:
The channel indexes to create this bus with.
Expand Down Expand Up @@ -208,8 +210,7 @@ def __init__(self, channel, can_filters=None, poll_interval=0.01,
self._time_offset = time.time() - offset.value * 1e-9

self._is_filtered = False
super(VectorBus, self).__init__(channel=channel, can_filters=can_filters,
**config)
super(VectorBus, self).__init__(channel=channel, can_filters=can_filters, **kwargs)

def _apply_filters(self, filters):
if filters:
Expand Down
6 changes: 2 additions & 4 deletions can/interfaces/virtual.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,8 @@ class VirtualBus(BusABC):
if a message is sent to 5 receivers with the timeout set to 1.0.
"""

def __init__(self, channel=None, receive_own_messages=False,
rx_queue_size=0, **config):
super(VirtualBus, self).__init__(channel=channel,
receive_own_messages=receive_own_messages, **config)
def __init__(self, channel=None, receive_own_messages=False, rx_queue_size=0, **kwargs):
super(VirtualBus, self).__init__(channel=channel, receive_own_messages=receive_own_messages, **kwargs)

# the channel identifier may be an arbitrary object
self.channel_id = channel
Expand Down