Skip to content

Commit 8aa7166

Browse files
authored
Truncating message data if over max frame length (#1181)
Fixes #1177
1 parent d603ff9 commit 8aa7166

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

can/interfaces/ics_neovi/neovi_bus.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,18 @@ def send(self, msg, timeout=0):
417417
"""
418418
if not ics.validate_hobject(self.dev):
419419
raise CanOperationError("bus not open")
420+
421+
# Check for valid DLC to avoid passing extra long data to the driver
422+
if msg.is_fd:
423+
if msg.dlc > 64:
424+
raise ValueError(
425+
f"DLC was {msg.dlc} but it should be <= 64 for CAN FD frames"
426+
)
427+
elif msg.dlc > 8:
428+
raise ValueError(
429+
f"DLC was {msg.dlc} but it should be <= 8 for normal CAN frames"
430+
)
431+
420432
message = ics.SpyMessage()
421433

422434
flag0 = 0
@@ -434,8 +446,8 @@ def send(self, msg, timeout=0):
434446
flag3 |= ics.SPY_STATUS3_CANFD_ESI
435447

436448
message.ArbIDOrHeader = msg.arbitration_id
437-
msg_data = msg.data
438-
message.NumberBytesData = len(msg_data)
449+
msg_data = msg.data[: msg.dlc]
450+
message.NumberBytesData = msg.dlc
439451
message.Data = tuple(msg_data[:8])
440452
if msg.is_fd and len(msg_data) > 8:
441453
message.ExtraDataPtrEnabled = 1

0 commit comments

Comments
 (0)