@@ -41,7 +41,13 @@ class SocketCANMedia(Media):
4141 SocketCAN documentation: https://www.kernel.org/doc/Documentation/networking/can.txt
4242 """
4343
44- def __init__ (self , iface_name : str , mtu : int , loop : typing .Optional [asyncio .AbstractEventLoop ] = None ) -> None :
44+ def __init__ (
45+ self ,
46+ iface_name : str ,
47+ mtu : int ,
48+ disable_brs : bool = False ,
49+ loop : typing .Optional [asyncio .AbstractEventLoop ] = None ,
50+ ) -> None :
4551 """
4652 CAN Classic/FD is selected automatically based on the MTU. It is not possible to use CAN FD with MTU of 8 bytes.
4753
@@ -50,6 +56,9 @@ def __init__(self, iface_name: str, mtu: int, loop: typing.Optional[asyncio.Abst
5056 :param mtu: The maximum data field size in bytes. CAN FD is used if this value > 8, Classic CAN otherwise.
5157 This value must belong to Media.VALID_MTU_SET.
5258
59+ :param disable_brs: When true, will disabele bitrate switching for CAN FD frames. Meaning that the data bitrate
60+ will be the same as the nominal bitrate.
61+
5362 :param loop: Deprecated.
5463 """
5564 # This can't be made a class attribute because these errnos are only available on GNU/Linux.
@@ -68,6 +77,8 @@ def __init__(self, iface_name: str, mtu: int, loop: typing.Optional[asyncio.Abst
6877 self ._mtu = int (mtu )
6978 if self ._mtu not in self .VALID_MTU_SET :
7079 raise ValueError (f"Invalid MTU: { self ._mtu } not in { self .VALID_MTU_SET } " )
80+ self ._disable_brs : bool = disable_brs
81+
7182 if loop :
7283 warnings .warn ("The loop argument is deprecated" , DeprecationWarning )
7384
@@ -260,7 +271,7 @@ def _read_frame(self, ts_mono_ns: int) -> typing.Tuple[Timestamp, Envelope]:
260271 return timestamp , Envelope (out , loopback = loopback )
261272
262273 def _compile_native_frame (self , source : DataFrame ) -> bytes :
263- flags = _CANFD_BRS if self ._is_fd else 0
274+ flags = _CANFD_BRS if ( self ._is_fd and not self . _disable_brs ) else 0
264275 ident = source .identifier | (_CAN_EFF_FLAG if source .format == FrameFormat .EXTENDED else 0 )
265276 header = _FRAME_HEADER_STRUCT .pack (ident , len (source .data ), flags )
266277 out = header + source .data .ljust (self ._native_frame_data_capacity , b"\x00 " )
0 commit comments