Skip to content
Open
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
7 changes: 7 additions & 0 deletions can/interfaces/socketcand/socketcand.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,13 @@ def convert_ascii_message_to_can_message(ascii_msg: str) -> can.Message:
def convert_can_message_to_ascii_message(can_message: can.Message) -> str:
# Note: socketcan bus adds extended flag, remote_frame_flag & error_flag to id
# not sure if that is necessary here
if can_message.is_remote_frame:
# The send command is "< send id dlc [data]* >", there is no field for
# the remote request flag, so the frame would go out as a normal one
raise can.CanOperationError(
"socketcand cannot send remote frames, its send command has no "
"remote request flag"
)
can_id = can_message.arbitration_id
if can_message.is_extended_id:
can_id_string = f"{(can_id&0x1FFFFFFF):08X}"
Expand Down
1 change: 1 addition & 0 deletions doc/changelog.d/2091.fixed.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Refuse to send remote frames on the ``socketcand`` interface instead of sending them as normal frames. The socketcand protocol has no remote request flag. (:issue:`2091`)
27 changes: 27 additions & 0 deletions test/test_socketcand.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,32 @@ def test_missing_ending_character(self):
self.assertIsNone(msg)


class TestConvertCanMessageToAsciiMessage(unittest.TestCase):
def test_standard_frame(self):
msg = can.Message(
arbitration_id=0x123, data=[0x01, 0x02, 0x03, 0x04], is_extended_id=False
)
self.assertEqual(
socketcand.convert_can_message_to_ascii_message(msg),
"< send 123 4 1 2 3 4 >",
)

def test_extended_frame(self):
msg = can.Message(
arbitration_id=0x1AAAAAAA, data=[0x01, 0xF1], is_extended_id=True
)
self.assertEqual(
socketcand.convert_can_message_to_ascii_message(msg),
"< send 1AAAAAAA 2 1 f1 >",
)

def test_remote_frame_is_refused(self):
msg = can.Message(
arbitration_id=0x403, is_remote_frame=True, is_extended_id=False
)
with self.assertRaises(can.CanOperationError):
socketcand.convert_can_message_to_ascii_message(msg)


if __name__ == "__main__":
unittest.main()