Skip to content

Commit 4d1794f

Browse files
IOhannes m zmölnig (Debian/GNU)umlaeute
authored andcommitted
BigEndian test fixes
PCAN_BITRATES are stored in BIGendian, no use to byteswap on littleendian. Also the TPCANChannelInformation expects data in the native byte order Closes: #1624
1 parent dc0ae68 commit 4d1794f

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

test/test_bit_timing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def test_from_btr():
175175
def test_btr_persistence():
176176
f_clock = 8_000_000
177177
for btr0btr1 in PCAN_BITRATES.values():
178-
btr1, btr0 = struct.unpack("BB", btr0btr1)
178+
btr0, btr1 = struct.pack(">H", btr0btr1.value)
179179

180180
t = can.BitTiming.from_registers(f_clock, btr0, btr1)
181181
assert t.btr0 == btr0

test/test_pcan.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44

55
import ctypes
6+
import struct
67
import unittest
78
from unittest import mock
89
from unittest.mock import Mock, patch
@@ -379,9 +380,7 @@ def test_detect_available_configs(self) -> None:
379380
self.assertEqual(len(configs), 50)
380381
else:
381382
value = (TPCANChannelInformation * 1).from_buffer_copy(
382-
b"Q\x00\x05\x00\x01\x00\x00\x00PCAN-USB FD\x00\x00\x00\x00"
383-
b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
384-
b'\x00\x00\x00\x00\x00\x00\x003"\x11\x00\x01\x00\x00\x00'
383+
struct.pack("HBBI33sII", 81, 5, 0, 1, b"PCAN-USB FD", 1122867, 1)
385384
)
386385
self.mock_pcan.GetValue = Mock(return_value=(PCAN_ERROR_OK, value))
387386
configs = PcanBus._detect_available_configs()

0 commit comments

Comments
 (0)