From 9bf4c0d8108cdbb5e9b1e3fd91126363f237452b Mon Sep 17 00:00:00 2001 From: Colin Rafferty Date: Mon, 29 Jul 2019 10:19:19 -0400 Subject: [PATCH 01/23] Do not incorrectly reset CANMsg.MSGTYPE on remote frame. In `PcanBus.send()`, we initially set `msgType` based on all the flags of `msg`, including RTR. In the if/else for `self.fd`, we are incorrectly resetting it if rtr. We should not, and so we are no longer doing it. --- can/interfaces/pcan/pcan.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/can/interfaces/pcan/pcan.py b/can/interfaces/pcan/pcan.py index 864308bab..f062d62aa 100644 --- a/can/interfaces/pcan/pcan.py +++ b/can/interfaces/pcan/pcan.py @@ -385,9 +385,7 @@ def send(self, msg, timeout=None): CANMsg.MSGTYPE = msgType # if a remote frame will be sent, data bytes are not important. - if msg.is_remote_frame: - CANMsg.MSGTYPE = msgType.value | PCAN_MESSAGE_RTR.value - else: + if not msg.is_remote_frame: # copy data for i in range(CANMsg.LEN): CANMsg.DATA[i] = msg.data[i] From 4405bc5d3c815f6f5535ba9360acb90936a04a76 Mon Sep 17 00:00:00 2001 From: Brian Thorne Date: Thu, 15 Aug 2019 21:00:39 +1000 Subject: [PATCH 02/23] Bump version to 3.3.2 --- CHANGELOG.txt | 5 +++++ can/__init__.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 5c492d19f..933318a66 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,3 +1,8 @@ +Version 3.3.2 +==== + +Minor bug fix release addressing issue in PCAN RTR. + Version 3.3.1 ==== diff --git a/can/__init__.py b/can/__init__.py index e00e7dd53..44aa90e4a 100644 --- a/can/__init__.py +++ b/can/__init__.py @@ -8,7 +8,7 @@ import logging -__version__ = "3.3.1" +__version__ = "3.3.2" log = logging.getLogger('can') From fbe11048f5c0a5801ed330a880d7709bb75d814f Mon Sep 17 00:00:00 2001 From: Brian Thorne Date: Thu, 24 Oct 2019 21:23:00 +1100 Subject: [PATCH 03/23] Backport #713 - RTR bug fix in canutils.py --- can/io/canutils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/can/io/canutils.py b/can/io/canutils.py index 69c0227a4..b5cec0cb5 100644 --- a/can/io/canutils.py +++ b/can/io/canutils.py @@ -62,7 +62,7 @@ def __iter__(self): else: isExtended = False canId = int(canId, 16) - + dataBin = None if data and data[0].lower() == 'r': isRemoteFrame = True if len(data) > 1: From 7505d21aa032735a25e2b12e9ac95500c21e6968 Mon Sep 17 00:00:00 2001 From: Brian Thorne Date: Thu, 24 Oct 2019 21:42:07 +1100 Subject: [PATCH 04/23] Bump version to 3.3.3 --- can/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/can/__init__.py b/can/__init__.py index 44aa90e4a..481dc29e3 100644 --- a/can/__init__.py +++ b/can/__init__.py @@ -8,7 +8,7 @@ import logging -__version__ = "3.3.2" +__version__ = "3.3.3" log = logging.getLogger('can') From f69b162766e014ee9a56671092075a0d73e1542d Mon Sep 17 00:00:00 2001 From: Alexander Bessman Date: Sun, 29 Dec 2019 09:19:17 +1300 Subject: [PATCH 05/23] Backport fix to ASCReader #701 Skip J1939TP messages --- can/io/asc.py | 8 ++++++-- test/data/logfile.asc | 46 ++++++++++++++++++++++++++----------------- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/can/io/asc.py b/can/io/asc.py index 3ed50f04a..4f1115e98 100644 --- a/can/io/asc.py +++ b/can/io/asc.py @@ -28,7 +28,8 @@ class ASCReader(BaseIOHandler): """ - Iterator of CAN messages from a ASC logging file. + Iterator of CAN messages from a ASC logging file. Meta data (comments, + bus statistics, J1939 Transport Protocol messages) is ignored. TODO: turn relative timestamps back to absolute form """ @@ -77,7 +78,10 @@ def __iter__(self): channel=channel) yield msg - elif not isinstance(channel, int) or dummy.strip()[0:10].lower() == 'statistic:': + elif (not isinstance(channel, int) + or dummy.strip()[0:10].lower() == 'statistic:' + or dummy.split(None, 1)[0] == "J1939TP" + ): pass elif dummy[-1:].lower() == 'r': diff --git a/test/data/logfile.asc b/test/data/logfile.asc index 4b7c64363..b855811a2 100644 --- a/test/data/logfile.asc +++ b/test/data/logfile.asc @@ -1,18 +1,28 @@ -date Sam Sep 30 15:06:13.191 2017 -base hex timestamps absolute -internal events logged -// version 9.0.0 -Begin Triggerblock Sam Sep 30 15:06:13.191 2017 - 0.000000 Start of measurement - 0.015991 CAN 1 Status:chip status error passive - TxErr: 132 RxErr: 0 - 0.015991 CAN 2 Status:chip status error active - 1.015991 1 Statistic: D 0 R 0 XD 0 XR 0 E 0 O 0 B 0.00% - 1.015991 2 Statistic: D 0 R 0 XD 0 XR 0 E 0 O 0 B 0.00% - 2.015992 1 Statistic: D 0 R 0 XD 0 XR 0 E 0 O 0 B 0.00% - 17.876707 CAN 1 Status:chip status error passive - TxErr: 131 RxErr: 0 - 17.876708 1 6F9 Rx d 8 05 0C 00 00 00 00 00 00 Length = 240015 BitCount = 124 ID = 1785 - 17.876976 1 6F8 Rx d 8 FF 00 0C FE 00 00 00 00 Length = 239910 BitCount = 124 ID = 1784 - 18.015997 1 Statistic: D 2 R 0 XD 0 XR 0 E 0 O 0 B 0.04% - 113.016026 1 Statistic: D 0 R 0 XD 0 XR 0 E 0 O 0 B 0.00% - 113.016026 2 Statistic: D 0 R 0 XD 0 XR 0 E 0 O 0 B 0.00% -End TriggerBlock +date Sam Sep 30 15:06:13.191 2017 +base hex timestamps absolute +internal events logged +// version 9.0.0 +Begin Triggerblock Sam Sep 30 15:06:13.191 2017 + 0.000000 Start of measurement + 0.015991 CAN 1 Status:chip status error passive - TxErr: 132 RxErr: 0 + 0.015991 CAN 2 Status:chip status error active + 1.015991 1 Statistic: D 0 R 0 XD 0 XR 0 E 0 O 0 B 0.00% + 1.015991 2 Statistic: D 0 R 0 XD 0 XR 0 E 0 O 0 B 0.00% + 2.015992 1 Statistic: D 0 R 0 XD 0 XR 0 E 0 O 0 B 0.00% + 3.098426 1 18EBFF00x Rx d 8 01 A0 0F A6 60 3B D1 40 Length = 273910 BitCount = 141 ID = 418119424x + 3.148421 1 18EBFF00x Rx d 8 02 1F DE 80 25 DF C0 2B Length = 271910 BitCount = 140 ID = 418119424x + 3.197693 1 18EBFF00x Rx d 8 03 E1 00 4B FF FF 3C 0F Length = 283910 BitCount = 146 ID = 418119424x + 3.248765 1 18EBFF00x Rx d 8 04 00 4B FF FF FF FF FF Length = 283910 BitCount = 146 ID = 418119424x + 3.297743 1 J1939TP FEE3p 6 0 0 - Rx d 23 A0 0F A6 60 3B D1 40 1F DE 80 25 DF C0 2B E1 00 4B FF FF 3C 0F 00 4B FF FF FF FF FF FF FF FF FF FF FF FF + 17.876707 CAN 1 Status:chip status error passive - TxErr: 131 RxErr: 0 + 17.876708 1 6F9 Rx d 8 05 0C 00 00 00 00 00 00 Length = 240015 BitCount = 124 ID = 1785 + 17.876976 1 6F8 Rx d 8 FF 00 0C FE 00 00 00 00 Length = 239910 BitCount = 124 ID = 1784 + 18.015997 1 Statistic: D 2 R 0 XD 0 XR 0 E 0 O 0 B 0.04% + 20.105214 2 18EBFF00x Rx d 8 01 A0 0F A6 60 3B D1 40 Length = 273925 BitCount = 141 ID = 418119424x + 20.155119 2 18EBFF00x Rx d 8 02 1F DE 80 25 DF C0 2B Length = 272152 BitCount = 140 ID = 418119424x + 20.204671 2 18EBFF00x Rx d 8 03 E1 00 4B FF FF 3C 0F Length = 283910 BitCount = 146 ID = 418119424x + 20.248887 2 18EBFF00x Rx d 8 04 00 4B FF FF FF FF FF Length = 283925 BitCount = 146 ID = 418119424x + 20.305233 2 J1939TP FEE3p 6 0 0 - Rx d 23 A0 0F A6 60 3B D1 40 1F DE 80 25 DF C0 2B E1 00 4B FF FF 3C 0F 00 4B FF FF FF FF FF FF FF FF FF FF FF FF + 113.016026 1 Statistic: D 0 R 0 XD 0 XR 0 E 0 O 0 B 0.00% + 113.016026 2 Statistic: D 0 R 0 XD 0 XR 0 E 0 O 0 B 0.00% +End TriggerBlock From 250d290792d865dd06e422ed1a97b6b391062a20 Mon Sep 17 00:00:00 2001 From: Christian Sandberg Date: Sun, 29 Dec 2019 09:24:50 +1300 Subject: [PATCH 06/23] Backport fix to can.player #690 Expose options to send or skip error frame messages --- can/player.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/can/player.py b/can/player.py index c712f1714..2b1864a36 100644 --- a/can/player.py +++ b/can/player.py @@ -47,6 +47,12 @@ def main(): help='''Ignore timestamps (send all frames immediately with minimum gap between frames)''', action='store_false') + parser.add_argument( + "--error-frames", + help="Also send error frames to the interface.", + action="store_true", + ) + parser.add_argument('-g', '--gap', type=float, help=''' minimum time between replayed frames''', default=0.0001) parser.add_argument('-s', '--skip', type=float, default=60*60*24, @@ -68,6 +74,8 @@ def main(): logging_level_name = ['critical', 'error', 'warning', 'info', 'debug', 'subdebug'][min(5, verbosity)] can.set_logging_level(logging_level_name) + error_frames = results.error_frames + config = {"single_handle": True} if results.interface: config["interface"] = results.interface @@ -84,6 +92,8 @@ def main(): try: for m in in_sync: + if m.is_error_frame and not error_frames: + continue if verbosity >= 3: print(m) bus.send(m) From 0e3812d218f03947d5fc7db59c61981b53e5b6e1 Mon Sep 17 00:00:00 2001 From: Karl Date: Fri, 12 Jul 2019 05:00:11 +1200 Subject: [PATCH 07/23] Backport socketcan fix: Read the BCM status before creating a Task Currently bus.send_periodic blindly wraps the BCM socket API, and sends a BCM operation with the TX_SETUP opcode. However, the semantics that the kernel driver provides are an "upsert". As such, when one attempts to create two Tasks with the same CAN Arbitration ID, it ends up silently modifying the periodic messages, which is contrary to what our API implies. This fixes the problem by first sending a TX_READ opcode with the CAN Arbitration ID that we wish to create. The kernel driver will return -EINVAL if a periodic transmission with the given Arbitration ID does not exist. If this is the case, then we can continue creating the Task, otherwise we error and notify the user. #605 --- can/interfaces/socketcan/constants.py | 5 ++-- can/interfaces/socketcan/socketcan.py | 35 +++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/can/interfaces/socketcan/constants.py b/can/interfaces/socketcan/constants.py index b56eaae64..1fa6fdf72 100644 --- a/can/interfaces/socketcan/constants.py +++ b/can/interfaces/socketcan/constants.py @@ -9,8 +9,9 @@ CAN_EFF_FLAG = 0x80000000 # BCM opcodes -CAN_BCM_TX_SETUP = 1 -CAN_BCM_TX_DELETE = 2 +CAN_BCM_TX_SETUP = 1 +CAN_BCM_TX_DELETE = 2 +CAN_BCM_TX_READ = 3 # BCM flags SETTIMER = 0x0001 diff --git a/can/interfaces/socketcan/socketcan.py b/can/interfaces/socketcan/socketcan.py index 633c87b22..b69b2636f 100644 --- a/can/interfaces/socketcan/socketcan.py +++ b/can/interfaces/socketcan/socketcan.py @@ -346,8 +346,39 @@ def _tx_setup(self, message): count = 0 ival1 = 0 ival2 = self.period - header = build_bcm_transmit_header(self.can_id_with_flags, count, ival1, - ival2, self.flags) + + # First do a TX_READ before creating a new task, and check if we get + # EINVAL. If so, then we are referring to a CAN message with the same + # ID + check_header = build_bcm_header( + opcode=CAN_BCM_TX_READ, + flags=0, + count=0, + ival1_seconds=0, + ival1_usec=0, + ival2_seconds=0, + ival2_usec=0, + can_id=self.can_id_with_flags, + nframes=0, + ) + try: + self.bcm_socket.send(check_header) + except OSError as e: + assert e.errno == errno.EINVAL + else: + raise ValueError( + "A periodic Task for Arbitration ID {} has already been created".format( + message.arbitration_id + ) + ) + + header = build_bcm_transmit_header( + self.can_id_with_flags, + count, + ival1, + ival2, + self.flags + ) frame = build_can_frame(message) log.debug("Sending BCM command") send_bcm(self.bcm_socket, header + frame) From cee9d642cc57b64ad62914391cab40cd14de87e6 Mon Sep 17 00:00:00 2001 From: Karl Date: Sat, 13 Jul 2019 14:38:59 -0700 Subject: [PATCH 08/23] Raise Exception instead of using assert on EINVAL --- can/interfaces/socketcan/socketcan.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/can/interfaces/socketcan/socketcan.py b/can/interfaces/socketcan/socketcan.py index b69b2636f..b671f926a 100644 --- a/can/interfaces/socketcan/socketcan.py +++ b/can/interfaces/socketcan/socketcan.py @@ -364,7 +364,8 @@ def _tx_setup(self, message): try: self.bcm_socket.send(check_header) except OSError as e: - assert e.errno == errno.EINVAL + if e.errno != errno.EINVAL: + raise e else: raise ValueError( "A periodic Task for Arbitration ID {} has already been created".format( From a479d7f2fb609f21d2e15439ce595af38a1103ab Mon Sep 17 00:00:00 2001 From: nick black Date: Sun, 9 Jun 2019 03:32:42 +1200 Subject: [PATCH 09/23] Backport canalystii fix to init #617 Pass kwargs through to BusABC's initializer. Doesn't backport changing baud to bitrate to avoid changing the API --- can/interfaces/canalystii.py | 6 ++++-- doc/configuration.rst | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/can/interfaces/canalystii.py b/can/interfaces/canalystii.py index 35f240a66..6a2fd51a9 100644 --- a/can/interfaces/canalystii.py +++ b/can/interfaces/canalystii.py @@ -66,7 +66,9 @@ class VCI_CAN_OBJ(Structure): class CANalystIIBus(BusABC): - def __init__(self, channel, device=0, baud=None, Timing0=None, Timing1=None, can_filters=None): + def __init__( + self, channel, device=0, baud=None, Timing0=None, Timing1=None, can_filters=None, **kwargs + ): """ :param channel: channel number @@ -76,7 +78,7 @@ def __init__(self, channel, device=0, baud=None, Timing0=None, Timing1=None, can :param Timing1: :param can_filters: filters for packet """ - super(CANalystIIBus, self).__init__(channel, can_filters) + super(CANalystIIBus, self).__init__(channel, can_filters, **kwargs) if isinstance(channel, (list, tuple)): self.channels = channel diff --git a/doc/configuration.rst b/doc/configuration.rst index dda2ace2a..142e816da 100644 --- a/doc/configuration.rst +++ b/doc/configuration.rst @@ -126,3 +126,7 @@ Lookup table of interface names: +---------------------+-------------------------------------+ | ``"virtual"`` | :doc:`interfaces/virtual` | +---------------------+-------------------------------------+ +| ``"canalystii"`` | :doc:`interfaces/canalystii` | ++---------------------+-------------------------------------+ +| ``"systec"`` | :doc:`interfaces/systec` | ++---------------------+-------------------------------------+ From 1587c3639bbb5c1227ebd7b35139934f24e5c13a Mon Sep 17 00:00:00 2001 From: Brian Thorne Date: Mon, 23 Dec 2019 22:18:19 +1300 Subject: [PATCH 10/23] Backport updating test deps (#745) * pin versions of testing dependencies including coverage --- setup.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 27121b61a..29c7478f7 100644 --- a/setup.py +++ b/setup.py @@ -33,11 +33,14 @@ 'mock~=2.0', 'pytest~=4.3', 'pytest-timeout~=1.3', - 'pytest-cov~=2.6', + 'pytest-cov~=2.8', + # coveragepy==5.0 fails with `Safety level may not be changed inside a transaction` + # on python 3.6 on MACOS + 'coverage<5', 'codecov~=2.0', 'future', 'six', - 'hypothesis' + 'hypothesis~=4.56' ] + extras_require['serial'] extras_require['test'] = tests_require From f9198f3f30c2a9c57d44d6e1f4b61a50ac5b3042 Mon Sep 17 00:00:00 2001 From: chrisoro <4160557+chrisoro@users.noreply.github.com> Date: Tue, 24 Dec 2019 07:16:31 +0100 Subject: [PATCH 11/23] Exclude all test packages, not just toplevel (#740) --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 29c7478f7..e5b05e8dc 100644 --- a/setup.py +++ b/setup.py @@ -90,7 +90,7 @@ # Code version=version, - packages=find_packages(exclude=["test", "doc", "scripts", "examples"]), + packages=find_packages(exclude=["test*", "doc", "scripts", "examples"]), scripts=list(filter(isfile, (join("scripts/", f) for f in listdir("scripts/")))), # Author From 6d44fd0ecac17cee7085ad7019ea7f123bf78bd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Sch=C3=A4rlund?= Date: Sat, 22 Jun 2019 10:14:05 +0200 Subject: [PATCH 12/23] Avoid padding CAN_FD_MESSAGE_64 objects to 4 bytes --- can/io/blf.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/can/io/blf.py b/can/io/blf.py index d162fdebc..a17a6b6a7 100644 --- a/can/io/blf.py +++ b/can/io/blf.py @@ -195,8 +195,13 @@ def __iter__(self): raise BLFParseError() obj_size = header[3] + obj_type = header[4] # Calculate position of next object - next_pos = pos + obj_size + (obj_size % 4) + if obj_size % 4 and obj_type != CAN_FD_MESSAGE_64: + next_pos = pos + obj_size + (obj_size % 4) + else: + # CAN_FD_MESSAGE_64 objects are not padded to 4 bytes. + next_pos = pos + obj_size if next_pos > len(data): # Object continues in next log container break @@ -222,7 +227,6 @@ def __iter__(self): factor = 1e-9 timestamp = timestamp * factor + self.start_timestamp - obj_type = header[4] # Both CAN message types have the same starting content if obj_type in (CAN_MESSAGE, CAN_MESSAGE2): (channel, flags, dlc, can_id, From ba4c6761286150c5ea3de39a74c73e076b293ba2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Sch=C3=A4rlund?= Date: Sun, 23 Jun 2019 13:55:21 +0200 Subject: [PATCH 13/23] Refactor to save calculations --- can/io/blf.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/can/io/blf.py b/can/io/blf.py index a17a6b6a7..91f2945c9 100644 --- a/can/io/blf.py +++ b/can/io/blf.py @@ -197,11 +197,9 @@ def __iter__(self): obj_size = header[3] obj_type = header[4] # Calculate position of next object - if obj_size % 4 and obj_type != CAN_FD_MESSAGE_64: - next_pos = pos + obj_size + (obj_size % 4) - else: - # CAN_FD_MESSAGE_64 objects are not padded to 4 bytes. - next_pos = pos + obj_size + next_pos = pos + obj_size + if obj_type != CAN_FD_MESSAGE_64: + next_pos += obj_size % 4 if next_pos > len(data): # Object continues in next log container break From 9fb3c23f3b167630ae3ae2ab2137c496c7ec2def Mon Sep 17 00:00:00 2001 From: Brian Thorne Date: Mon, 17 Feb 2020 22:12:50 +1300 Subject: [PATCH 14/23] Backport accepting bitrate instead of baud in CANalystIIBus Backported from #617 --- can/interfaces/canalystii.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/can/interfaces/canalystii.py b/can/interfaces/canalystii.py index 6a2fd51a9..859fdca9a 100644 --- a/can/interfaces/canalystii.py +++ b/can/interfaces/canalystii.py @@ -1,3 +1,4 @@ +import warnings from ctypes import * import logging import platform @@ -67,13 +68,13 @@ class VCI_CAN_OBJ(Structure): class CANalystIIBus(BusABC): def __init__( - self, channel, device=0, baud=None, Timing0=None, Timing1=None, can_filters=None, **kwargs + self, channel, device=0, bitrate=None, baud=None, Timing0=None, Timing1=None, can_filters=None, **kwargs ): """ :param channel: channel number :param device: device number - :param baud: baud rate + :param baud: baud rate. Renamed to bitrate in next release. :param Timing0: customize the timing register if baudrate is not specified :param Timing1: :param can_filters: filters for packet @@ -93,10 +94,15 @@ def __init__( self.channel_info = "CANalyst-II: device {}, channels {}".format(self.device, self.channels) if baud is not None: + warnings.warn('Argument baud will be deprecated in version 4, use bitrate instead', + PendingDeprecationWarning) + bitrate = baud + + if bitrate is not None: try: - Timing0, Timing1 = TIMING_DICT[baud] + Timing0, Timing1 = TIMING_DICT[bitrate] except KeyError: - raise ValueError("Baudrate is not supported") + raise ValueError("Bitrate is not supported") if Timing0 is None or Timing1 is None: raise ValueError("Timing registers are not set") From 6041bbcf37a588d0e7e6d96578ebee1d56db2f3d Mon Sep 17 00:00:00 2001 From: Brian Thorne Date: Sun, 19 Apr 2020 12:17:35 +1200 Subject: [PATCH 15/23] Add changelog for release 3.3.3 and append alpha 0 tag for testing. --- CHANGELOG.txt | 16 ++++++++++++++++ can/__init__.py | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 933318a66..c22c5bad6 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,3 +1,19 @@ +Version 3.3.3 +==== + +Backported fixes from Python 3 only 4.x development. + +* Exclude test packages from distribution. #740 +* RTR crash fix in canutils log reader parsing RTR frames. #713 +* Skip J1939 messages in ASC Reader. #701 +* Exposes a configuration option to allow the CAN message player to send error frames + (and sets the default to not send error frames). #690 +* Fixes the semantics provided by periodic tasks in SocketCAN interface. #638 +* Avoid padding CAN_FD_MESSAGE_64 objects to 4 bytes. #628 +* Fixes the broken CANalyst-II interface. #617 +* Socketcan BCM status fix. #605 + + Version 3.3.2 ==== diff --git a/can/__init__.py b/can/__init__.py index 481dc29e3..c467396c8 100644 --- a/can/__init__.py +++ b/can/__init__.py @@ -8,7 +8,7 @@ import logging -__version__ = "3.3.3" +__version__ = "3.3.3-alpha.0" log = logging.getLogger('can') From e45c8cc93202ad19d4024daf066867b94adcbb83 Mon Sep 17 00:00:00 2001 From: Karl Date: Sun, 19 Apr 2020 19:30:15 +1200 Subject: [PATCH 16/23] Fix Vector CANlib treatment of empty app name In Python 2, the str type was used for text and bytes, whereas in Python 3, these are separate and incompatible types. This broke instantiation of a VectorBus when the app_name parameter in __init__ was set to None. This correctly sets it to a bytes object. Fixes #796 --- can/interfaces/vector/canlib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/can/interfaces/vector/canlib.py b/can/interfaces/vector/canlib.py index 251b9fa56..65af0147b 100644 --- a/can/interfaces/vector/canlib.py +++ b/can/interfaces/vector/canlib.py @@ -87,7 +87,7 @@ def __init__(self, channel, can_filters=None, poll_interval=0.01, else: # Assume comma separated string of channels self.channels = [int(ch.strip()) for ch in channel.split(',')] - self._app_name = app_name.encode() if app_name is not None else '' + self._app_name = app_name.encode() if app_name is not None else b'' self.channel_info = 'Application %s: %s' % ( app_name, ', '.join('CAN %d' % (ch + 1) for ch in self.channels)) From e36e37612131001dcd8398a55f55b4a5714646c5 Mon Sep 17 00:00:00 2001 From: Brian Thorne Date: Mon, 20 Apr 2020 09:49:49 +1200 Subject: [PATCH 17/23] 3.3.3-a.1 --- can/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/can/__init__.py b/can/__init__.py index c467396c8..8aa111be7 100644 --- a/can/__init__.py +++ b/can/__init__.py @@ -8,7 +8,7 @@ import logging -__version__ = "3.3.3-alpha.0" +__version__ = "3.3.3-alpha.1" log = logging.getLogger('can') From 2ae3de5efa7254bb4132ec3af332a63c81726de9 Mon Sep 17 00:00:00 2001 From: Brian Thorne Date: Tue, 21 Apr 2020 08:52:15 +1200 Subject: [PATCH 18/23] Backport fix for handling empty csv file #771 Bump pre-release version to 3.3.3-a.2 --- can/__init__.py | 2 +- can/io/csv.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/can/__init__.py b/can/__init__.py index 8aa111be7..43996ff4f 100644 --- a/can/__init__.py +++ b/can/__init__.py @@ -8,7 +8,7 @@ import logging -__version__ = "3.3.3-alpha.1" +__version__ = "3.3.3-alpha.2" log = logging.getLogger('can') diff --git a/can/io/csv.py b/can/io/csv.py index 92f841f8f..32e34d0fb 100644 --- a/can/io/csv.py +++ b/can/io/csv.py @@ -91,7 +91,11 @@ def __init__(self, file): def __iter__(self): # skip the header line - next(self.file) + try: + next(self.file) + except StopIteration: + # don't crash on a file with only a header + return for line in self.file: From 5180591a2721c8a26b8adc1fb1e43f1adcdcfd49 Mon Sep 17 00:00:00 2001 From: pierreluctg Date: Mon, 23 Mar 2020 16:11:25 -0400 Subject: [PATCH 19/23] Backport caching msg.data value in neovi interface (#798) --- can/interfaces/ics_neovi/neovi_bus.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/can/interfaces/ics_neovi/neovi_bus.py b/can/interfaces/ics_neovi/neovi_bus.py index 4baee6177..530d7c524 100644 --- a/can/interfaces/ics_neovi/neovi_bus.py +++ b/can/interfaces/ics_neovi/neovi_bus.py @@ -334,11 +334,12 @@ def send(self, msg, timeout=None): flag3 |= ics.SPY_STATUS3_CANFD_ESI message.ArbIDOrHeader = msg.arbitration_id - message.NumberBytesData = len(msg.data) - message.Data = tuple(msg.data[:8]) - if msg.is_fd and len(msg.data) > 8: + msg_data = msg.data + message.NumberBytesData = len(msg_data) + message.Data = tuple(msg_data[:8]) + if msg.is_fd and len(msg_data) > 8: message.ExtraDataPtrEnabled = 1 - message.ExtraDataPtr = tuple(msg.data) + message.ExtraDataPtr = tuple(msg_data) message.StatusBitField = flag0 message.StatusBitField2 = 0 message.StatusBitField3 = flag3 From 390ff1cd8cf2b766a38215711d5bba5f2ebdb07f Mon Sep 17 00:00:00 2001 From: Brian Thorne Date: Tue, 21 Apr 2020 08:58:51 +1200 Subject: [PATCH 20/23] Update changelog with more backported fixes for 3.3.3 release --- CHANGELOG.txt | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index c22c5bad6..3399feb65 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -3,15 +3,18 @@ Version 3.3.3 Backported fixes from Python 3 only 4.x development. -* Exclude test packages from distribution. #740 -* RTR crash fix in canutils log reader parsing RTR frames. #713 -* Skip J1939 messages in ASC Reader. #701 -* Exposes a configuration option to allow the CAN message player to send error frames - (and sets the default to not send error frames). #690 -* Fixes the semantics provided by periodic tasks in SocketCAN interface. #638 -* Avoid padding CAN_FD_MESSAGE_64 objects to 4 bytes. #628 -* Fixes the broken CANalyst-II interface. #617 -* Socketcan BCM status fix. #605 +* #798 Backport caching msg.data value in neovi interface +* #796 Fix Vector CANlib treatment of empty app name +* #771 Handle empty CSV file +* #740 Exclude test packages from distribution. +* #713 RTR crash fix in canutils log reader parsing RTR frames. +* #701 Skip J1939 messages in ASC Reader. +* #690 Exposes a configuration option to allow the CAN message player to send error frames + (and sets the default to not send error frames). +* #638 Fixes the semantics provided by periodic tasks in SocketCAN interface. +* #628 Avoid padding CAN_FD_MESSAGE_64 objects to 4 bytes. +* #617 Fixes the broken CANalyst-II interface. +* #605 Socketcan BCM status fix. Version 3.3.2 From 16d89bc8fc210fd423d34c4dfbb9952b92418722 Mon Sep 17 00:00:00 2001 From: Syed Date: Fri, 31 Jan 2020 04:53:11 +1300 Subject: [PATCH 21/23] Backport #741 - Fixing ASCII reader unable to read FD frames --- can/io/asc.py | 35 +++++++++++++++++++++++++++++------ test/logformats_test.py | 2 +- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/can/io/asc.py b/can/io/asc.py index 4f1115e98..60f845bd0 100644 --- a/can/io/asc.py +++ b/can/io/asc.py @@ -59,9 +59,13 @@ def __iter__(self): temp = line.strip() if not temp or not temp[0].isdigit(): continue - + is_fd = False try: timestamp, channel, dummy = temp.split(None, 2) # , frameType, dlc, frameData + if channel == "CANFD": + timestamp, _, channel, _, dummy = temp.split(None, 4) + is_fd = True + except ValueError: # we parsed an empty comment continue @@ -95,16 +99,32 @@ def __iter__(self): yield msg else: + brs = None + esi = None + data_length = 0 try: - # this only works if dlc > 0 and thus data is availabe - can_id_str, _, _, dlc, data = dummy.split(None, 4) + # this only works if dlc > 0 and thus data is available + if not is_fd: + can_id_str, _, _, dlc, data = dummy.split(None, 4) + else: + can_id_str, frame_name, brs, esi, dlc, data_length, data = dummy.split( + None, 6 + ) + if frame_name.isdigit(): + # Empty frame_name + can_id_str, brs, esi, dlc, data_length, data = dummy.split( + None, 5 + ) except ValueError: # but if not, we only want to get the stuff up to the dlc can_id_str, _, _, dlc = dummy.split(None, 3) # and we set data to an empty sequence manually data = '' - - dlc = int(dlc) + dlc = int(dlc, 16) + if is_fd: + # For fd frames, dlc and data length might not be equal and + # data_length is the actual size of the data + dlc = int(data_length) frame = bytearray() data = data.split() for byte in data[0:dlc]: @@ -119,7 +139,10 @@ def __iter__(self): is_remote_frame=False, dlc=dlc, data=frame, - channel=channel + is_fd=is_fd, + channel=channel, + bitrate_switch=is_fd and brs == "1", + error_state_indicator=is_fd and esi == "1", ) self.stop() diff --git a/test/logformats_test.py b/test/logformats_test.py index d9551e5d6..41bf2e9c4 100644 --- a/test/logformats_test.py +++ b/test/logformats_test.py @@ -315,7 +315,7 @@ class TestAscFileFormat(ReaderWriterTest): def _setup_instance(self): super(TestAscFileFormat, self)._setup_instance_helper( can.ASCWriter, can.ASCReader, - check_fd=False, + check_fd=True, check_comments=True, preserves_channel=False, adds_default_channel=0 ) From d2d701269dcbba6d945ad1e4b33ba1ab448fb161 Mon Sep 17 00:00:00 2001 From: Brian Thorne Date: Thu, 7 May 2020 09:08:55 +1200 Subject: [PATCH 22/23] 3.3.3-a.3 --- CHANGELOG.txt | 9 +++++---- can/__init__.py | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 3399feb65..c2a6ea38a 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,11 +1,12 @@ Version 3.3.3 ==== -Backported fixes from Python 3 only 4.x development. +Backported fixes from 4.x development branch which targets Python 3. -* #798 Backport caching msg.data value in neovi interface -* #796 Fix Vector CANlib treatment of empty app name -* #771 Handle empty CSV file +* #798 Backport caching msg.data value in neovi interface. +* #796 Fix Vector CANlib treatment of empty app name. +* #771 Handle empty CSV file. +* #741 ASCII reader can now handle FD frames. * #740 Exclude test packages from distribution. * #713 RTR crash fix in canutils log reader parsing RTR frames. * #701 Skip J1939 messages in ASC Reader. diff --git a/can/__init__.py b/can/__init__.py index 43996ff4f..0e30f1c18 100644 --- a/can/__init__.py +++ b/can/__init__.py @@ -8,7 +8,7 @@ import logging -__version__ = "3.3.3-alpha.2" +__version__ = "3.3.3-alpha.3" log = logging.getLogger('can') From 8b76232e283c9fab05515d96cb6bc5b32d7d0684 Mon Sep 17 00:00:00 2001 From: Brian Thorne Date: Mon, 18 May 2020 10:16:58 +1200 Subject: [PATCH 23/23] Set version to 3.3.3 --- can/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/can/__init__.py b/can/__init__.py index 0e30f1c18..481dc29e3 100644 --- a/can/__init__.py +++ b/can/__init__.py @@ -8,7 +8,7 @@ import logging -__version__ = "3.3.3-alpha.3" +__version__ = "3.3.3" log = logging.getLogger('can')