Skip to content

Commit

Permalink
BigEndian test fixes (#1625)
Browse files Browse the repository at this point in the history
PCAN_BITRATES are stored in BIGendian, no use to byteswap on littleendian.
Also the TPCANChannelInformation expects data in the native byte order

Closes: #1624

Co-authored-by: IOhannes m zmölnig (Debian/GNU) <umlaeute@debian.org>
  • Loading branch information
umlaeute and IOhannes m zmölnig (Debian/GNU) committed Jun 30, 2023
1 parent dc0ae68 commit c5d7a7c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion test/test_bit_timing.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def test_from_btr():
def test_btr_persistence():
f_clock = 8_000_000
for btr0btr1 in PCAN_BITRATES.values():
btr1, btr0 = struct.unpack("BB", btr0btr1)
btr0, btr1 = struct.pack(">H", btr0btr1.value)

t = can.BitTiming.from_registers(f_clock, btr0, btr1)
assert t.btr0 == btr0
Expand Down
5 changes: 2 additions & 3 deletions test/test_pcan.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import ctypes
import struct
import unittest
from unittest import mock
from unittest.mock import Mock, patch
Expand Down Expand Up @@ -379,9 +380,7 @@ def test_detect_available_configs(self) -> None:
self.assertEqual(len(configs), 50)
else:
value = (TPCANChannelInformation * 1).from_buffer_copy(
b"Q\x00\x05\x00\x01\x00\x00\x00PCAN-USB FD\x00\x00\x00\x00"
b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
b'\x00\x00\x00\x00\x00\x00\x003"\x11\x00\x01\x00\x00\x00'
struct.pack("HBBI33sII", 81, 5, 0, 1, b"PCAN-USB FD", 1122867, 1)
)
self.mock_pcan.GetValue = Mock(return_value=(PCAN_ERROR_OK, value))
configs = PcanBus._detect_available_configs()
Expand Down

0 comments on commit c5d7a7c

Please sign in to comment.