Skip to content

Commit da89d35

Browse files
committed
Reimplement UdpMulticastBus.is_fd attribute as read-only property
The property is superseded by BusABC.protocol and scheduled for removal in version 5.0.
1 parent c6da1c4 commit da89d35

File tree

1 file changed

+15
-4
lines changed
  • can/interfaces/udp_multicast

1 file changed

+15
-4
lines changed

can/interfaces/udp_multicast/bus.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import select
44
import socket
55
import struct
6+
import warnings
67
from typing import List, Optional, Tuple, Union
78

89
import can
@@ -103,12 +104,22 @@ def __init__(
103104
)
104105

105106
super().__init__(
106-
channel, **kwargs, protocol=CanProtocol.CAN_FD if fd else CanProtocol.CAN_20
107+
channel,
108+
**kwargs,
109+
protocol=CanProtocol.CAN_FD if fd else CanProtocol.CAN_20,
107110
)
108111

109-
self.is_fd = fd
110112
self._multicast = GeneralPurposeUdpMulticastBus(channel, port, hop_limit)
111113

114+
@property
115+
def is_fd(self) -> bool:
116+
warnings.warn(
117+
"The UdpMulticastBus.is_fd property is deprecated and superseded by "
118+
"BusABC.protocol. It is scheduled for removal in version 5.0.",
119+
DeprecationWarning,
120+
)
121+
return self.protocol == CanProtocol.CAN_FD
122+
112123
def _recv_internal(self, timeout: Optional[float]):
113124
result = self._multicast.recv(timeout)
114125
if not result:
@@ -124,13 +135,13 @@ def _recv_internal(self, timeout: Optional[float]):
124135
"could not unpack received message"
125136
) from exception
126137

127-
if not self.is_fd and can_message.is_fd:
138+
if self.protocol != CanProtocol.CAN_FD and can_message.is_fd:
128139
return None, False
129140

130141
return can_message, False
131142

132143
def send(self, msg: can.Message, timeout: Optional[float] = None) -> None:
133-
if not self.is_fd and msg.is_fd:
144+
if self.protocol != CanProtocol.CAN_FD and msg.is_fd:
134145
raise can.CanOperationError(
135146
"cannot send FD message over bus with CAN FD disabled"
136147
)

0 commit comments

Comments
 (0)