Skip to content

Commit ecbf5c8

Browse files
authored
Merge pull request #38 from pylessard/Handle-CANFD-Bitrate-switch
Handle bitrate_switch flag
2 parents c9ed47a + 85840ea commit ecbf5c8

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

doc/source/isotp/implementation.rst

+12
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,18 @@ The transport layer ``params`` parameter must be a dictionary with the following
147147
Setting this parameter to ``True`` does not change the behaviour of the :class:`TransportLayer<isotp.TransportLayer>` except that outputted message will have their ``is_fd`` property set to ``True``. This parameter is just a convenience to integrate more easily with python-can
148148

149149

150+
.. _param_bitrate_switch:
151+
152+
.. attribute:: bitrate_switch
153+
:annotation: (bool)
154+
155+
**default: False**
156+
157+
When set to ``True``, tx message will have a flag ``bitrate_switch`` marked as ``True``, meaning that the underlying layer shall performe a CAN FD bitrate switch after arbitration phase.
158+
159+
Setting this parameter to ``True`` does not change the behaviour of the :class:`TransportLayer<isotp.TransportLayer>` except that outputted message will have their ``bitrate_switch`` property set to ``True``. This parameter is just a convenience to integrate more easily with python-can
160+
161+
150162
-----
151163

152164
Usage

isotp/protocol.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@ class CanMessage:
2626
:param is_fd: When True, message has to be transmitted or has been received in a CAN FD frame. CAN frame when set to False
2727
:type extended_id: bool
2828
"""
29-
__slots__ = 'arbitration_id', 'dlc', 'data', 'is_extended_id', 'is_fd'
29+
__slots__ = 'arbitration_id', 'dlc', 'data', 'is_extended_id', 'is_fd', 'bitrate_switch'
3030

31-
def __init__(self, arbitration_id=None, dlc=None, data=None, extended_id=False, is_fd=False):
31+
def __init__(self, arbitration_id=None, dlc=None, data=None, extended_id=False, is_fd=False, bitrate_switch=False):
3232
self.arbitration_id = arbitration_id
3333
self.dlc = dlc
3434
self.data = data
3535
self.is_extended_id = extended_id
3636
self.is_fd = is_fd
37+
self.bitrate_switch = bitrate_switch
3738

3839
class PDU:
3940
"""
@@ -194,7 +195,7 @@ class TransportLayer:
194195
class Params:
195196
__slots__ = ( 'stmin', 'blocksize', 'squash_stmin_requirement', 'rx_flowcontrol_timeout',
196197
'rx_consecutive_frame_timeout', 'tx_padding', 'wftmax', 'tx_data_length', 'tx_data_min_length',
197-
'max_frame_size', 'can_fd'
198+
'max_frame_size', 'can_fd', 'bitrate_switch'
198199
)
199200

200201
def __init__(self):
@@ -209,6 +210,7 @@ def __init__(self):
209210
self.tx_data_min_length = None
210211
self.max_frame_size = 4095
211212
self.can_fd = False
213+
self.bitrate_switch = False
212214

213215
def set(self, key, val, validate=True):
214216
param_alias = {
@@ -286,6 +288,9 @@ def validate(self):
286288

287289
if not isinstance(self.can_fd, bool):
288290
raise ValueError('can_fd must be a boolean value')
291+
292+
if not isinstance(self.bitrate_switch, bool):
293+
raise ValueError('bitrate_switch must be a boolean value')
289294

290295

291296
class Timer:
@@ -730,7 +735,7 @@ def stop_sending_flow_control(self):
730735

731736
def make_tx_msg(self, arbitration_id, data):
732737
self.pad_message_data(data)
733-
return CanMessage(arbitration_id = arbitration_id, dlc=self.get_dlc(data, validate_tx=True), data=data, extended_id=self.address.is_29bits, is_fd=self.params.can_fd)
738+
return CanMessage(arbitration_id = arbitration_id, dlc=self.get_dlc(data, validate_tx=True), data=data, extended_id=self.address.is_29bits, is_fd=self.params.can_fd, bitrate_switch=self.params.bitrate_switch)
734739

735740
def get_dlc(self, data, validate_tx=False):
736741
fdlen = self.get_nearest_can_fd_size(len(data))
@@ -877,15 +882,15 @@ class CanStack(TransportLayer):
877882
"""
878883

879884
def _tx_canbus_3plus(self, msg):
880-
self.bus.send(can.Message(arbitration_id=msg.arbitration_id, data = msg.data, is_extended_id=msg.is_extended_id, is_fd=msg.is_fd))
885+
self.bus.send(can.Message(arbitration_id=msg.arbitration_id, data = msg.data, is_extended_id=msg.is_extended_id, is_fd=msg.is_fd, bitrate_switch=msg.bitrate_switch))
881886

882887
def _tx_canbus_3minus(self, msg):
883-
self.bus.send(can.Message(arbitration_id=msg.arbitration_id, data = msg.data, extended_id=msg.is_extended_id, is_fd=msg.is_fd))
888+
self.bus.send(can.Message(arbitration_id=msg.arbitration_id, data = msg.data, extended_id=msg.is_extended_id, is_fd=msg.is_fd, bitrate_switch=msg.bitrate_switch))
884889

885890
def rx_canbus(self):
886891
msg = self.bus.recv(0)
887892
if msg is not None:
888-
return CanMessage(arbitration_id=msg.arbitration_id, data=msg.data, extended_id=msg.is_extended_id, is_fd=msg.is_fd)
893+
return CanMessage(arbitration_id=msg.arbitration_id, data=msg.data, extended_id=msg.is_extended_id, is_fd=msg.is_fd, bitrate_switch=msg.bitrate_switch)
889894

890895
def __init__(self, bus, *args, **kwargs):
891896
global can

0 commit comments

Comments
 (0)