diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..bf5e415 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,5 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Never modify line endings of bash scripts +*.sh text eol=lf diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 82094e6..0000000 --- a/.travis.yml +++ /dev/null @@ -1,4 +0,0 @@ -language: c++ -os: osx -compiler: clang -osx_image: xcode12.5 diff --git a/Deployment.md b/Deployment.md index 54ece1a..18e1be1 100644 --- a/Deployment.md +++ b/Deployment.md @@ -1,6 +1,6 @@ ### macOS® User-Space Driver for TouCAN USB Interfaces from Rusoku -_Copyright © 2020-2023 Uwe Vogt, UV Software, Berlin (info@mac-can.com)_ \ +_Copyright © 2020-2024 Uwe Vogt, UV Software, Berlin (info@mac-can.com)_ \ _All rights reserved._ # Deployment Rules @@ -26,16 +26,12 @@ _All rights reserved._ - `Update CAN API V3 testing sources to rev. `_nnn_ \ `- `_list of major changes (optional)_ 4. Check and update the version and date information in the following files: - - `$(PROJROOT)/Sources/TouCAN.h` - - `$(PROJROOT)/Sources/TouCAN.cpp` - - `$(PROJROOT)/Sources/Wrapper/can_api.c` + - `$(PROJROOT)/Sources/Version.h` - `$(PROJROOT)/Sources/Swift/CANAPI.swift` - `$(PROJROOT)/Libraries/CANAPI/Makefile`* - `$(PROJROOT)/Libraries/TouCAN/Makefile`* - - `$(PROJROOT)/Utilities/can_moni/Driver.h` - `$(PROJROOT)/Utilities/can_moni/Makefile` - `$(PROJROOT)/Utilities/can_moni/README.md` - - `$(PROJROOT)/Utilities/can_test/Driver.h` - `$(PROJROOT)/Utilities/can_test/Makefile` - `$(PROJROOT)/Utilities/can_test/README.md` @@ -85,12 +81,12 @@ _All rights reserved._ 3. Run the `Makefile` in the project root folder: - `uv-pc013mac:~ eris$ cd $(PROJROOT)` - `uv-pc013mac:RusokuCAN eris$ make pristine` - - `uv-pc013mac:RusokuCAN eris$ make BINARY=UNIVERSAL` + - `uv-pc013mac:RusokuCAN eris$ make all BINARY=UNIVERSAL` - `uv-pc013mac:RusokuCAN eris$ make test` - `uv-pc013mac:RusokuCAN eris$ sudo make install` 4. Build the CAN API V3 GoogleTest program: - `uv-pc013mac:~ eris$ cd $(PROJROOT)/Tests/CANAPI` - - `uv-pc013mac:CANAPI eris$ make pristine` + - `uv-pc013mac:CANAPI eris$ make clean` - `uv-pc013mac:CANAPI eris$ make all` 5. Run the CAN API V3 GoogleTest program with two TouCAN USB device: - `uv-pc013mac:CANAPI eris$./tou_testing --can_dut1=TouCAN-USB1 --can_dut2=TouCAN-USB2 --gtest_output=xml:TestReport_TouCAN-USB.xml --run_all=YES --smoketest_frames=100000` [...] @@ -100,16 +96,16 @@ _All rights reserved._ - `$(PROJROOT)/Binaries/*.*` - `$(PROJROOT)/Includes/*.*` - `$(PROJROOT)/README.md` - - `$(PROJROOT)/LICENSE` + - `$(PROJROOT)/LICENSE.*` 8. Double check and update the [`README.md`](https://github.com/mac-can/RusokuCAN/blob/main/README.md) on GitHub (or insert just a blank). ### Procedure 1. Click on `Draft a new release` in the [GitHub](https://github.com/mac-can/RusokuCAN) repo. 2. Fill out all required fields: - - Tag version: e.g `v0.2.6` (cf. semantic versioning) + - Tag version: e.g `v0.3` (cf. semantic versioning) - Target: `main` (default branch) - - Release title: e.g. `Release of November 12, 2023` + - Release title: e.g. `Release of January 19, 2038` - Change-log: list all major changes, e.g. from commit comments - Assets: drag and drop the artifacts archive (see above) 3. Click on `Publish release`. diff --git a/Examples/C++/Makefile b/Examples/C++/Makefile index 620f283..dd93b52 100644 --- a/Examples/C++/Makefile +++ b/Examples/C++/Makefile @@ -1,5 +1,5 @@ BINARIES = ../../Binaries -INCLUDES = -I../../INCLUDES +INCLUDES = -I../../Includes TARGET1 = can_recv SOURCE1 = $(TARGET1).cpp $(BINARIES)/libTouCAN.a diff --git a/Examples/Python/CANAPI.py b/Examples/Python/CANAPI.py index 63f88fd..9c33750 100644 --- a/Examples/Python/CANAPI.py +++ b/Examples/Python/CANAPI.py @@ -2,7 +2,7 @@ # # CAN Interface API, Version 3 (Python Wrapper) # -# Copyright (c) 2005-2023 Uwe Vogt, UV Software, Berlin (info@uv-software.com) +# Copyright (c) 2005-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) # All rights reserved. # # This file is part of CAN API V3. @@ -43,7 +43,7 @@ # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with CAN API V3. If not, see . +# along with CAN API V3. If not, see . # """ CAN API V3 Python Wrapper for generic CAN Interfaces. @@ -52,9 +52,9 @@ Interface API for various CAN interfaces from different vendors running under multiple operating systems. - $Author: makemake $ + $Author: quaoar $ - $Rev: 1198 $ + $Rev: 1278 $ """ from ctypes import * import platform @@ -69,7 +69,7 @@ # CAN API V3 - Python Wrapper # -CAN_API_V3_PYTHON = {'major': 0, 'minor': 2, 'patch': 0} +CAN_API_V3_PYTHON = {'major': 0, 'minor': 3, 'patch': 1} # CAN Identifier Ranges # @@ -122,6 +122,13 @@ (49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64): c_uint8(0xF) } +# CAN Acceptance Filter: (code ^ id) & mask == 0 +# +CANACC_CODE_11BIT = 0x000 # mask for 11-bit acceptance code +CANACC_MASK_11BIT = 0x000 # mask for 11-bit acceptance mask +CANACC_CODE_29BIT = 0x00000000 # mask for 29-bit acceptance code +CANACC_MASK_29BIT = 0x00000000 # mask for 29-bit acceptance mask + # CAN 2.0 Predefined Bit-rates (as index acc. CiA) # CANBTR_INDEX_1M = c_int32(0) # bit-rate: 1000 kbit/s @@ -210,8 +217,9 @@ # Control of blocking read # -CANREAD_INFINITE = c_uint16(65535) # infinite time-out (blocking read) - +CANWAIT_INFINITE = 65535 # infinite time-out (blocking operation) +CANREAD_INFINITE = CANWAIT_INFINITE +CANWRITE_INFINITE = CANWAIT_INFINITE # CAN Status-register # @@ -637,6 +645,133 @@ def bitrate(self): print('+++ exception: {}'.format(e)) raise + def filter11bit(self, code, mask): + """ + sets a 11-bit filter for the CAN controller. + + :param code: 11-bit code for the filter (or None) + :param mask: 11-bit mask for the filter (or None) + :return: result, code, mask + result: 0 if successful, or a negative value on error + code: 11-bit code for the filter + mask: 11-bit mask for the filter + """ + try: + # set the 11-bit filter (if code or mask are not None) + if code is not None or mask is not None: + __filter = c_uint64(0) + if code is not None: + __filter.value = code << 32 + if mask is not None: + __filter.value |= mask & 0xFFFFFFFF + result = self.__m_library.can_property(self.__m_handle, 42, byref(__filter), 8) + if result < 0: + return int(result), None, None + # get the 11-bit filter + __value = c_uint64(0) + result = self.__m_library.can_property(self.__m_handle, 40, byref(__value), 8) + if result < 0: + return int(result), None, None + return int(result), int(__filter.value >> 32), int(__filter.value & 0xFFFFFFFF) + except Exception as e: + print('+++ exception: {}'.format(e)) + raise + + def filter29bit(self, code, mask): + """ + sets a 29-bit filter for the CAN controller. + + :param code: 29-bit code for the filter (or None) + :param mask: 29-bit mask for the filter (or None) + :return: result, code, mask + result: 0 if successful, or a negative value on error + code: 29-bit code for the filter + mask: 29-bit mask for the filter + """ + try: + # set the 29-bit filter (if code or mask are not None) + if code is not None or mask is not None: + __filter = c_uint64(0) + if code is not None: + __filter.value = code << 32 + if mask is not None: + __filter.value |= mask & 0xFFFFFFFF + result = self.__m_library.can_property(self.__m_handle, 43, byref(__filter), 8) + if result < 0: + return int(result), None, None + # get the 29-bit filter + __value = c_uint64(0) + result = self.__m_library.can_property(self.__m_handle, 41, byref(__value), 8) + if result < 0: + return int(result), None, None + return int(result), int(__filter.value >> 32), int(__filter.value & 0xFFFFFFFF) + except Exception as e: + print('+++ exception: {}'.format(e)) + raise + + def hardware(self): + """ + retrieves the hardware version of the CAN controller + board as a zero-terminated string. + + note: API function 'can_hardware' is marked as deprecated. + + :return: version + version: version information as string + """ + try: + self.__m_library.can_hardware.restype = c_char_p + version_c = self.__m_library.can_hardware(self.__m_handle) + if version_c is not None: + return version_c.decode('utf-8') + else: + raise Exception('+++ error: can_hardware returned None') + except Exception as e: + print('+++ exception: {}'.format(e)) + raise + + def firmware(self): + """ + retrieves the firmware version of the CAN controller + board as a zero-terminated string. + + note: API function 'can_firmware' is marked as deprecated. + + :return: version + version: version information as string + """ + try: + self.__m_library.can_firmware.restype = c_char_p + version_c = self.__m_library.can_firmware(self.__m_handle) + if version_c is not None: + return version_c.decode('utf-8') + else: + raise Exception('+++ error: can_firmware returned None') + except Exception as e: + print('+++ exception: {}'.format(e)) + raise + + def software(self): + """ + retrieves version information of the CAN API V3 DLL + as a zero-terminated string. + + note: API function 'can_version' is marked as deprecated. + + :return: version + version: version information as string + """ + try: + self.__m_library.can_version.restype = c_char_p + version_c = self.__m_library.can_version() + if version_c is not None: + return version_c.decode('utf-8') + else: + raise Exception('+++ error: can_version returned None') + except Exception as e: + print('+++ exception: {}'.format(e)) + raise + @staticmethod def version(): """ @@ -703,6 +838,7 @@ def len2dlc(length): print(CANAPI.version()) print('>>> can = CANAPI(' + lib + ')') can = CANAPI(lib) + print(can.software()) # initialize the CAN interface print('>>> can.init({}, 0x{:02X})'.format(chn, opMode.byte)) @@ -715,6 +851,20 @@ def len2dlc(length): else: print('>>> can.status() >>> 0x{:02X}'.format(status.byte)) + # set acceptance filter + code = CANACC_CODE_11BIT + mask = CANACC_MASK_11BIT + print('>>> can.filter11bit(0x{:03X}, 0x{:03X})'.format(code, mask)) + res, code, mask = can.filter11bit(code=code, mask=mask) + if res < CANERR_NOERROR: + print('+++ error: can.filter11bit returned {}'.format(res)) + code = CANACC_CODE_29BIT + mask = CANACC_MASK_29BIT + print('>>> can.filter29bit(0x{:08X}, 0x{:08X})'.format(code, mask)) + res, code, mask = can.filter29bit(code=code, mask=mask) + if res < CANERR_NOERROR: + print('+++ error: can.filter29bit returned {}'.format(res)) + # start the CAN controller if bitRate.index > 0: # FIXME: Expected type 'int', got 'c_int32[int]' instead print('>>> can.start([{},[{},{},{},{},{}],[{},{},{},{},])'.format(bitRate.btr.frequency, @@ -753,6 +903,10 @@ def len2dlc(length): else: print('>>> can.status() >>> 0x{:02X}'.format(status.byte)) + # print some version information + print('>>> can.hardware() >>> ' + can.hardware()) + print('>>> can.firmware() >>> ' + can.firmware()) + # shutdown the CAN interface print('>>> can.exit()') res = can.exit() @@ -762,5 +916,5 @@ def len2dlc(length): # have a great time print('Bye, bye!') -# * $Id: CANAPI.py 1198 2023-09-13 08:43:19Z makemake $ *** (c) UV Software, Berlin *** +# * $Id: CANAPI.py 1278 2024-04-23 08:34:36Z quaoar $ *** (c) UV Software, Berlin *** # diff --git a/Examples/Python/can_recv.py b/Examples/Python/can_recv.py index 1229b34..fa9259c 100644 --- a/Examples/Python/can_recv.py +++ b/Examples/Python/can_recv.py @@ -55,6 +55,7 @@ def sigterm(signo, frame): print(CANAPI.version()) print('>>> can = CANAPI(' + lib + ')') can = CANAPI(lib) +print(can.software()) # initialize the CAN interface print('>>> can.init({}, 0x{:02X})'.format(chn, opMode.byte)) @@ -67,6 +68,20 @@ def sigterm(signo, frame): else: print('>>> can.status() >>> 0x{:02X}'.format(status.byte)) +# set acceptance filter +code = 0x70F #CANACC_CODE_11BIT +mask = 0x0F0 #CANACC_MASK_11BIT +print('>>> can.filter11bit(0x{:03X}, 0x{:03X})'.format(code, mask)) +res, code, mask = can.filter11bit(code=code, mask=mask) +if res < CANERR_NOERROR: + print('+++ error: can.filter11bit returned {}'.format(res)) +code = CANACC_CODE_29BIT +mask = CANACC_MASK_29BIT +print('>>> can.filter29bit(0x{:08X}, 0x{:08X})'.format(code, mask)) +res, code, mask = can.filter29bit(code=code, mask=mask) +if res < CANERR_NOERROR: + print('+++ error: can.filter29bit returned {}'.format(res)) + # start the CAN controller if int(bitRate.index) > 0: # FIXME: Expected type 'int', got 'c_int32[int]' instead print('>>> can.start([{},[{},{},{},{},{}],[{},{},{},{},])'.format(bitRate.btr.frequency, @@ -147,6 +162,10 @@ def sigterm(signo, frame): else: print('>>> can.status() >>> 0x{:02X}'.format(status.byte)) +# print some version information +print('>>> can.hardware() >>> ' + can.hardware()) +print('>>> can.firmware() >>> ' + can.firmware()) + # shutdown the CAN interface print('>>> can.exit()') res = can.exit() diff --git a/Examples/Python/can_send.py b/Examples/Python/can_send.py index 9e7e05e..8d17e67 100644 --- a/Examples/Python/can_send.py +++ b/Examples/Python/can_send.py @@ -68,6 +68,7 @@ def sigterm(signo, frame): print(CANAPI.version()) print('>>> can = CANAPI(' + lib + ')') can = CANAPI(lib) +print(can.software()) # initialize the CAN interface print('>>> can.init({}, 0x{:02X})'.format(chn, opMode.byte)) @@ -137,6 +138,10 @@ def sigterm(signo, frame): else: print('>>> can.status() >>> 0x{:02X}'.format(status.byte)) +# print some version information +print('>>> can.hardware() >>> ' + can.hardware()) +print('>>> can.firmware() >>> ' + can.firmware()) + # shutdown the CAN interface print('>>> can.exit()') res = can.exit() diff --git a/Examples/Swift/can_recv.xcodeproj/project.pbxproj b/Examples/Swift/can_recv.xcodeproj/project.pbxproj index 09d797e..3594570 100644 --- a/Examples/Swift/can_recv.xcodeproj/project.pbxproj +++ b/Examples/Swift/can_recv.xcodeproj/project.pbxproj @@ -12,16 +12,6 @@ 0F7BCB4D267BC40400C7BCD8 /* libUVCANTOU.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 0F7BCB4C267BC40400C7BCD8 /* libUVCANTOU.a */; }; /* End PBXBuildFile section */ -/* Begin PBXContainerItemProxy section */ - 0F82853E27731C0D00FE2C2E /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 0F82853A27731C0D00FE2C2E /* can_send.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 0F7BCB32267BC1D200C7BCD8; - remoteInfo = can_send; - }; -/* End PBXContainerItemProxy section */ - /* Begin PBXCopyFilesBuildPhase section */ 0F7BCB1D267BC15700C7BCD8 /* CopyFiles */ = { isa = PBXCopyFilesBuildPhase; @@ -39,7 +29,6 @@ 0F7BCB46267BC3AB00C7BCD8 /* main.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = main.swift; path = can_recv/main.swift; sourceTree = ""; }; 0F7BCB49267BC3E000C7BCD8 /* CANAPI.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = CANAPI.swift; path = ../../Sources/Swift/CANAPI.swift; sourceTree = ""; }; 0F7BCB4C267BC40400C7BCD8 /* libUVCANTOU.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libUVCANTOU.a; path = ../../Binaries/libUVCANTOU.a; sourceTree = ""; }; - 0F82853A27731C0D00FE2C2E /* can_send.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; path = can_send.xcodeproj; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -57,7 +46,6 @@ 0F7BCB16267BC15700C7BCD8 = { isa = PBXGroup; children = ( - 0F82853A27731C0D00FE2C2E /* can_send.xcodeproj */, 0F7BCB4C267BC40400C7BCD8 /* libUVCANTOU.a */, 0F7BCB45267BC39100C7BCD8 /* Sources */, 0F7BCB20267BC15700C7BCD8 /* Products */, @@ -81,14 +69,6 @@ name = Sources; sourceTree = ""; }; - 0F82853B27731C0D00FE2C2E /* Products */ = { - isa = PBXGroup; - children = ( - 0F82853F27731C0D00FE2C2E /* can_send */, - ); - name = Products; - sourceTree = ""; - }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -135,12 +115,6 @@ mainGroup = 0F7BCB16267BC15700C7BCD8; productRefGroup = 0F7BCB20267BC15700C7BCD8 /* Products */; projectDirPath = ""; - projectReferences = ( - { - ProductGroup = 0F82853B27731C0D00FE2C2E /* Products */; - ProjectRef = 0F82853A27731C0D00FE2C2E /* can_send.xcodeproj */; - }, - ); projectRoot = ""; targets = ( 0F7BCB1E267BC15700C7BCD8 /* can_recv */, @@ -148,16 +122,6 @@ }; /* End PBXProject section */ -/* Begin PBXReferenceProxy section */ - 0F82853F27731C0D00FE2C2E /* can_send */ = { - isa = PBXReferenceProxy; - fileType = "compiled.mach-o.executable"; - path = can_send; - remoteRef = 0F82853E27731C0D00FE2C2E /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; -/* End PBXReferenceProxy section */ - /* Begin PBXSourcesBuildPhase section */ 0F7BCB1B267BC15700C7BCD8 /* Sources */ = { isa = PBXSourcesBuildPhase; diff --git a/Examples/Swift/can_recv/main.swift b/Examples/Swift/can_recv/main.swift index 372a031..8dcd952 100644 --- a/Examples/Swift/can_recv/main.swift +++ b/Examples/Swift/can_recv/main.swift @@ -28,6 +28,11 @@ do { step = "InitializeChannel" print(">>> \(step)(channel: \(channel), mode: \(mode))") try can.InitializeChannel(channel: channel, mode: mode) + step = "AcceptanceFilter" + can.filter = (0x000, 0x000) + if let filter = can.filter { + print(">>> \(step): \(filter)") + } step = "StartController" print(">>> \(step)(index: \(baud))") try can.StartController(index: baud) diff --git a/Examples/Swift/can_send.xcodeproj/xcshareddata/xcschemes/can_send.xcscheme b/Examples/Swift/can_send.xcodeproj/xcshareddata/xcschemes/can_send.xcscheme new file mode 100644 index 0000000..3e56bfc --- /dev/null +++ b/Examples/Swift/can_send.xcodeproj/xcshareddata/xcschemes/can_send.xcscheme @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LICENSE.BSD-2-Clause b/LICENSE.BSD-2-Clause new file mode 100644 index 0000000..77d754e --- /dev/null +++ b/LICENSE.BSD-2-Clause @@ -0,0 +1,25 @@ +BSD 2-Clause License + +Copyright (c) 2020-2024, Uwe Vogt, UV Software +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/LICENSE b/LICENSE.GPL-3.0-or-later similarity index 99% rename from LICENSE rename to LICENSE.GPL-3.0-or-later index e72bfdd..f288702 100644 --- a/LICENSE +++ b/LICENSE.GPL-3.0-or-later @@ -671,4 +671,4 @@ into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read -. \ No newline at end of file +. diff --git a/Libraries/CANAPI/Makefile b/Libraries/CANAPI/Makefile index bf7ad85..6566b2b 100644 --- a/Libraries/CANAPI/Makefile +++ b/Libraries/CANAPI/Makefile @@ -1,10 +1,36 @@ # -# CAN Interface API, Version 3 (for Rusoku TouCAN USB Interfaces) +# TouCAN - macOS User-Space Driver for Rusoku TouCAN USB Adapters # -# Copyright (C) 2020-2023 Uwe Vogt, UV Software, Berlin (info@mac-can.com) +# Copyright (c) 2020-2024 Uwe Vogt, UV Software, Berlin (info@mac-can.com) +# All rights reserved. # # This file is part of MacCAN-TouCAN. # +# MacCAN-TouCAN is dual-licensed under the BSD 2-Clause "Simplified" License +# and under the GNU General Public License v3.0 (or any later version). You can +# choose between one of them if you use MacCAN-TouCAN in whole or in part. +# +# BSD 2-Clause "Simplified" License: +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# MacCAN-TouCAN IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF MacCAN-TouCAN, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# GNU General Public License v3.0 or later: # MacCAN-TouCAN is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or @@ -16,14 +42,25 @@ # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with MacCAN-TouCAN. If not, see . +# along with MacCAN-TouCAN. If not, see . # current_OS := $(shell sh -c 'uname 2>/dev/null || echo Unknown OS') current_OS := $(patsubst CYGWIN%,Cygwin,$(current_OS)) current_OS := $(patsubst MINGW%,MinGW,$(current_OS)) current_OS := $(patsubst MSYS%,MinGW,$(current_OS)) +MAJOR = 0 +MINOR = 3 +PATCH = 0 + +ifeq ($(PATCH),0) +VERSION = $(MAJOR).$(MINOR) +else +VERSION = $(MAJOR).$(MINOR).$(PATCH) +endif + HOME_DIR = ../.. +MAIN_DIR = . SOURCE_DIR = $(HOME_DIR)/Sources CANAPI_DIR = $(HOME_DIR)/Sources/CANAPI @@ -31,35 +68,13 @@ MACCAN_DIR = $(HOME_DIR)/Sources/MacCAN DRIVER_DIR = $(HOME_DIR)/Sources/Driver WRAPPER_DIR = $(HOME_DIR)/Sources/Wrapper -OBJECTS = $(OUTDIR)/TouCAN_Driver.o $(OUTDIR)/TouCAN_USB_Driver.o \ - $(OUTDIR)/TouCAN_USB_Device.o $(OUTDIR)/TouCAN_USB.o \ +OBJECTS = $(OUTDIR)/can_api.o $(OUTDIR)/can_btr.o \ + $(OUTDIR)/TouCAN_Driver.o $(OUTDIR)/TouCAN_USB_Driver.o \ + $(OUTDIR)/TouCAN_USB_Device.o $(OUTDIR)/TouCAN_USB_CmdMsg.o \ $(OUTDIR)/MacCAN_Devices.o $(OUTDIR)/MacCAN_Debug.o \ - $(OUTDIR)/MacCAN_IOUsbKit.o $(OUTDIR)/MacCAN_MsgQueue.o \ - $(OUTDIR)/can_api.o $(OUTDIR)/can_btr.o - + $(OUTDIR)/MacCAN_IOUsbKit.o $(OUTDIR)/MacCAN_MsgQueue.o -ifeq ($(current_OS),Darwin) # macOS - libUVCANTOU.dylib - -PROJECT = UVCANTOU -LIBRARY = lib$(PROJECT) - -MAJOR = 0 -MINOR = 2 -PATCH = 6 - -VERSION = $(MAJOR).$(MINOR).$(PATCH) -TARGET = $(LIBRARY).$(VERSION).dylib -STATIC = $(LIBRARY).a - -INSTALL_NAME = @rpath/$(TARGET) -CURRENT_VERSION = $(MAJOR).$(MINOR).$(PATCH) -COMPATIBILITY_VERSION = $(MAJOR).$(MINOR).0 - -INSTALL = /usr/local/lib - -INCLUDE = /usr/local/include - -DEFINES = -DOPTION_CANAPI_TOUCAN_DYLIB=1 \ +DEFINES = -DOPTION_CAN_2_0_ONLY=0 \ -DOPTION_CANAPI_DRIVER=1 \ -DOPTION_CANAPI_RETVALS=1 \ -DOPTION_CANAPI_COMPANIONS=1 \ @@ -70,8 +85,7 @@ DEFINES = -DOPTION_CANAPI_TOUCAN_DYLIB=1 \ -DOPTION_MACCAN_DEBUG_LEVEL=0 \ -DOPTION_MACCAN_INSTRUMENTATION=0 \ -DOPTION_CANAPI_DEBUG_LEVEL=0 \ - -DOPTION_CANAPI_INSTRUMENTATION=0 \ - -DOPTION_CAN_2_0_ONLY=0 + -DOPTION_CANAPI_INSTRUMENTATION=0 HEADERS = -I$(SOURCE_DIR) \ -I$(CANAPI_DIR) \ @@ -79,8 +93,25 @@ HEADERS = -I$(SOURCE_DIR) \ -I$(DRIVER_DIR) \ -I$(WRAPPER_DIR) + +ifeq ($(current_OS),Darwin) # macOS - libUVCANTOU.dylib + +PROJECT = UVCANTOU +LIBRARY = lib$(PROJECT) + +TARGET = $(LIBRARY).$(VERSION).dylib +STATIC = $(LIBRARY).a + +INSTALL_NAME = $(TARGET) +CURRENT_VERSION = $(MAJOR).$(MINOR).$(PATCH) +COMPATIBILITY_VERSION = $(MAJOR).$(MINOR).0 + +INSTALL = /usr/local/lib + +DEFINES += -DOPTION_CANAPI_TOUCAN_DYLIB=1 + CFLAGS += -O2 -Wall -Wextra -Wno-parentheses \ - -fmessage-length=0 -fno-strict-aliasing \ + -fno-strict-aliasing \ $(DEFINES) \ $(HEADERS) @@ -88,14 +119,11 @@ CXXFLAGS += -O2 -g -Wall -Wextra -pthread \ $(DEFINES) \ $(HEADERS) -LIBRARIES = - -LDFLAGS += -lpthread \ - -nostartfiles -dynamiclib -fvisibility=hidden \ - -Wl,-framework -Wl,IOKit -Wl,-framework -Wl,CoreFoundation \ - -Wl,-install_name,$(INSTALL_NAME) \ +LDFLAGS += -nostartfiles -dynamiclib -fvisibility=hidden \ + -Wl,-install_name,@rpath/$(INSTALL_NAME) \ -Wl,-current_version,$(CURRENT_VERSION) \ - -Wl,-compatibility_version,$(COMPATIBILITY_VERSION) + -Wl,-compatibility_version,$(COMPATIBILITY_VERSION) \ + -Wl,-framework -Wl,IOKit -Wl,-framework -Wl,CoreFoundation LTFLAGS += -static @@ -105,6 +133,8 @@ CXXFLAGS += -arch arm64 -arch x86_64 LDFLAGS += -arch arm64 -arch x86_64 endif +LIBRARIES = -lpthread + CXX = clang++ CC = clang LD = clang @@ -140,6 +170,7 @@ incdir: @cp $(SOURCE_DIR)/TouCAN_Defines.h $(INCDIR) @cp $(SOURCE_DIR)/TouCAN_Defaults.h $(INCDIR) @cp $(CANAPI_DIR)/can_api.h $(INCDIR) + @cp $(CANAPI_DIR)/can_btr.h $(INCDIR) @cp $(CANAPI_DIR)/CANAPI_Types.h $(INCDIR) @cp $(CANAPI_DIR)/CANAPI_Defines.h $(INCDIR) @cp $(CANAPI_DIR)/CANBTR_Defaults.h $(INCDIR) @@ -160,6 +191,12 @@ ifeq ($(current_OS),Darwin) endif +$(OUTDIR)/can_api.o: $(WRAPPER_DIR)/can_api.c + $(CC) $(CFLAGS) -MMD -MF $*.d -o $@ -c $< + +$(OUTDIR)/can_btr.o: $(CANAPI_DIR)/can_btr.c + $(CC) $(CFLAGS) -MMD -MF $*.d -o $@ -c $< + $(OUTDIR)/TouCAN_Driver.o: $(DRIVER_DIR)/TouCAN_Driver.c $(CC) $(CFLAGS) -MMD -MF $*.d -o $@ -c $< @@ -169,7 +206,7 @@ $(OUTDIR)/TouCAN_USB_Driver.o: $(DRIVER_DIR)/TouCAN_USB_Driver.c $(OUTDIR)/TouCAN_USB_Device.o: $(DRIVER_DIR)/TouCAN_USB_Device.c $(CC) $(CFLAGS) -MMD -MF $*.d -o $@ -c $< -$(OUTDIR)/TouCAN_USB.o: $(DRIVER_DIR)/TouCAN_USB.c +$(OUTDIR)/TouCAN_USB_CmdMsg.o: $(DRIVER_DIR)/TouCAN_USB_CmdMsg.c $(CC) $(CFLAGS) -MMD -MF $*.d -o $@ -c $< $(OUTDIR)/MacCAN_Debug.o: $(MACCAN_DIR)/MacCAN_Debug.c @@ -184,15 +221,9 @@ $(OUTDIR)/MacCAN_IOUsbKit.o: $(MACCAN_DIR)/MacCAN_IOUsbKit.c $(OUTDIR)/MacCAN_MsgQueue.o: $(MACCAN_DIR)/MacCAN_MsgQueue.c $(CC) $(CFLAGS) -MMD -MF $*.d -o $@ -c $< -$(OUTDIR)/can_api.o: $(WRAPPER_DIR)/can_api.c - $(CC) $(CFLAGS) -MMD -MF $*.d -o $@ -c $< - -$(OUTDIR)/can_btr.o: $(CANAPI_DIR)/can_btr.c - $(CC) $(CFLAGS) -MMD -MF $*.d -o $@ -c $< - $(STATIC): $(OBJECTS) - $(LT) $(LTFLAGS) -o $@ $(OBJECTS) $(LIBRARIES) + $(LT) $(LTFLAGS) -o $@ $(OBJECTS) $(CP) $@ $(BINDIR) @lipo -archs $@ @echo "\033[1mTarget '"$@"' successfully build\033[0m" diff --git a/Libraries/TouCAN/Makefile b/Libraries/TouCAN/Makefile index c4f6faf..0e23d4b 100644 --- a/Libraries/TouCAN/Makefile +++ b/Libraries/TouCAN/Makefile @@ -1,10 +1,36 @@ # -# TouCAN - macOS User-Space Driver for Rusoku TouCAN USB Interfaces +# TouCAN - macOS User-Space Driver for Rusoku TouCAN USB Adapters # -# Copyright (C) 2020-2023 Uwe Vogt, UV Software, Berlin (info@mac-can.com) +# Copyright (c) 2020-2024 Uwe Vogt, UV Software, Berlin (info@mac-can.com) +# All rights reserved. # # This file is part of MacCAN-TouCAN. # +# MacCAN-TouCAN is dual-licensed under the BSD 2-Clause "Simplified" License +# and under the GNU General Public License v3.0 (or any later version). You can +# choose between one of them if you use MacCAN-TouCAN in whole or in part. +# +# BSD 2-Clause "Simplified" License: +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# MacCAN-TouCAN IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF MacCAN-TouCAN, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# GNU General Public License v3.0 or later: # MacCAN-TouCAN is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or @@ -16,14 +42,25 @@ # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with MacCAN-TouCAN. If not, see . +# along with MacCAN-TouCAN. If not, see . # current_OS := $(shell sh -c 'uname 2>/dev/null || echo Unknown OS') current_OS := $(patsubst CYGWIN%,Cygwin,$(current_OS)) current_OS := $(patsubst MINGW%,MinGW,$(current_OS)) current_OS := $(patsubst MSYS%,MinGW,$(current_OS)) +MAJOR = 0 +MINOR = 3 +PATCH = 0 + +ifeq ($(PATCH),0) +VERSION = $(MAJOR).$(MINOR) +else +VERSION = $(MAJOR).$(MINOR).$(PATCH) +endif + HOME_DIR = ../.. +MAIN_DIR = . SOURCE_DIR = $(HOME_DIR)/Sources CANAPI_DIR = $(HOME_DIR)/Sources/CANAPI @@ -31,37 +68,14 @@ MACCAN_DIR = $(HOME_DIR)/Sources/MacCAN DRIVER_DIR = $(HOME_DIR)/Sources/Driver WRAPPER_DIR = $(HOME_DIR)/Sources/Wrapper -OBJECTS = $(OUTDIR)/TouCAN.o \ +OBJECTS = $(OUTDIR)/can_api.o $(OUTDIR)/can_btr.o \ $(OUTDIR)/TouCAN_Driver.o $(OUTDIR)/TouCAN_USB_Driver.o \ - $(OUTDIR)/TouCAN_USB_Device.o $(OUTDIR)/TouCAN_USB.o \ + $(OUTDIR)/TouCAN_USB_Device.o $(OUTDIR)/TouCAN_USB_CmdMsg.o \ $(OUTDIR)/MacCAN_Devices.o $(OUTDIR)/MacCAN_Debug.o \ $(OUTDIR)/MacCAN_IOUsbKit.o $(OUTDIR)/MacCAN_MsgQueue.o \ - $(OUTDIR)/can_api.o $(OUTDIR)/can_btr.o - + $(OUTDIR)/TouCAN.o -ifeq ($(current_OS),Darwin) # macOS - libTouCAN.dylib - -PROJECT = TouCAN -LIBRARY = lib$(PROJECT) - -MAJOR = 0 -MINOR = 2 -PATCH = 6 - -VERSION = $(MAJOR).$(MINOR).$(PATCH) -TARGET = $(LIBRARY).$(VERSION).dylib -STATIC = $(LIBRARY).a - -INSTALL_NAME = @rpath/$(TARGET) -CURRENT_VERSION = $(MAJOR).$(MINOR).$(PATCH) -COMPATIBILITY_VERSION = $(MAJOR).$(MINOR).0 - -INSTALL = /usr/local/lib - -INCLUDE = /usr/local/include - -DEFINES = -DOPTION_TOUCAN_DYLIB=1 \ - -DOPTION_CANAPI_TOUCAN_DYLIB=0 \ +DEFINES = -DOPTION_CAN_2_0_ONLY=0 \ -DOPTION_CANAPI_DRIVER=1 \ -DOPTION_CANAPI_RETVALS=0 \ -DOPTION_CANAPI_COMPANIONS=1 \ @@ -72,8 +86,7 @@ DEFINES = -DOPTION_TOUCAN_DYLIB=1 \ -DOPTION_MACCAN_DEBUG_LEVEL=0 \ -DOPTION_MACCAN_INSTRUMENTATION=0 \ -DOPTION_CANAPI_DEBUG_LEVEL=0 \ - -DOPTION_CANAPI_INSTRUMENTATION=0 \ - -DOPTION_CAN_2_0_ONLY=0 + -DOPTION_CANAPI_INSTRUMENTATION=0 HEADERS = -I$(SOURCE_DIR) \ -I$(CANAPI_DIR) \ @@ -81,8 +94,26 @@ HEADERS = -I$(SOURCE_DIR) \ -I$(DRIVER_DIR) \ -I$(WRAPPER_DIR) + +ifeq ($(current_OS),Darwin) # macOS - libTouCAN.dylib + +PROJECT = TouCAN +LIBRARY = lib$(PROJECT) + +TARGET = $(LIBRARY).$(VERSION).dylib +STATIC = $(LIBRARY).a + +INSTALL_NAME = $(TARGET) +CURRENT_VERSION = $(MAJOR).$(MINOR).$(PATCH) +COMPATIBILITY_VERSION = $(MAJOR).$(MINOR).0 + +INSTALL = /usr/local/lib + +DEFINES += -DOPTION_TOUCAN_DYLIB=1 \ + -DOPTION_CANAPI_TOUCAN_DYLIB=0 + CFLAGS += -O2 -Wall -Wextra -Wno-parentheses \ - -fmessage-length=0 -fno-strict-aliasing \ + -fno-strict-aliasing \ $(DEFINES) \ $(HEADERS) @@ -90,14 +121,11 @@ CXXFLAGS += -O2 -g -Wall -Wextra -pthread \ $(DEFINES) \ $(HEADERS) -LIBRARIES = - -LDFLAGS += -lpthread \ - -nostartfiles -dynamiclib -fvisibility=hidden \ - -Wl,-framework -Wl,IOKit -Wl,-framework -Wl,CoreFoundation \ - -Wl,-install_name,$(INSTALL_NAME) \ +LDFLAGS += -nostartfiles -dynamiclib -fvisibility=hidden \ + -Wl,-install_name,@rpath/$(INSTALL_NAME) \ -Wl,-current_version,$(CURRENT_VERSION) \ - -Wl,-compatibility_version,$(COMPATIBILITY_VERSION) + -Wl,-compatibility_version,$(COMPATIBILITY_VERSION) \ + -Wl,-framework -Wl,IOKit -Wl,-framework -Wl,CoreFoundation LTFLAGS += -static @@ -107,6 +135,8 @@ CXXFLAGS += -arch arm64 -arch x86_64 LDFLAGS += -arch arm64 -arch x86_64 endif +LIBRARIES = -lpthread + CXX = clang++ CC = clang LD = clang++ @@ -166,6 +196,12 @@ endif $(OUTDIR)/TouCAN.o: $(SOURCE_DIR)/TouCAN.cpp $(CXX) $(CXXFLAGS) -MMD -MF $*.d -o $@ -c $< +$(OUTDIR)/can_api.o: $(WRAPPER_DIR)/can_api.c + $(CC) $(CFLAGS) -MMD -MF $*.d -o $@ -c $< + +$(OUTDIR)/can_btr.o: $(CANAPI_DIR)/can_btr.c + $(CC) $(CFLAGS) -MMD -MF $*.d -o $@ -c $< + $(OUTDIR)/TouCAN_Driver.o: $(DRIVER_DIR)/TouCAN_Driver.c $(CC) $(CFLAGS) -MMD -MF $*.d -o $@ -c $< @@ -175,7 +211,7 @@ $(OUTDIR)/TouCAN_USB_Driver.o: $(DRIVER_DIR)/TouCAN_USB_Driver.c $(OUTDIR)/TouCAN_USB_Device.o: $(DRIVER_DIR)/TouCAN_USB_Device.c $(CC) $(CFLAGS) -MMD -MF $*.d -o $@ -c $< -$(OUTDIR)/TouCAN_USB.o: $(DRIVER_DIR)/TouCAN_USB.c +$(OUTDIR)/TouCAN_USB_CmdMsg.o: $(DRIVER_DIR)/TouCAN_USB_CmdMsg.c $(CC) $(CFLAGS) -MMD -MF $*.d -o $@ -c $< $(OUTDIR)/MacCAN_Debug.o: $(MACCAN_DIR)/MacCAN_Debug.c @@ -190,15 +226,9 @@ $(OUTDIR)/MacCAN_IOUsbKit.o: $(MACCAN_DIR)/MacCAN_IOUsbKit.c $(OUTDIR)/MacCAN_MsgQueue.o: $(MACCAN_DIR)/MacCAN_MsgQueue.c $(CC) $(CFLAGS) -MMD -MF $*.d -o $@ -c $< -$(OUTDIR)/can_api.o: $(WRAPPER_DIR)/can_api.c - $(CC) $(CFLAGS) -MMD -MF $*.d -o $@ -c $< - -$(OUTDIR)/can_btr.o: $(CANAPI_DIR)/can_btr.c - $(CC) $(CFLAGS) -MMD -MF $*.d -o $@ -c $< - $(STATIC): $(OBJECTS) - $(LT) $(LTFLAGS) -o $@ $(OBJECTS) $(LIBRARIES) + $(LT) $(LTFLAGS) -o $@ $(OBJECTS) $(CP) $@ $(BINDIR) @lipo -archs $@ @echo "\033[1mTarget '"$@"' successfully build\033[0m" diff --git a/Makefile b/Makefile index b06460f..2eb2748 100755 --- a/Makefile +++ b/Makefile @@ -1,10 +1,36 @@ # -# TouCAN - macOS User-Space Driver for Rusoku TouCAN USB Interfaces +# TouCAN - macOS User-Space Driver for Rusoku TouCAN USB Adapters # -# Copyright (C) 2020-2022 Uwe Vogt, UV Software, Berlin (info@mac-can.com) +# Copyright (c) 2020-2024 Uwe Vogt, UV Software, Berlin (info@mac-can.com) +# All rights reserved. # # This file is part of MacCAN-TouCAN. # +# MacCAN-TouCAN is dual-licensed under the BSD 2-Clause "Simplified" License +# and under the GNU General Public License v3.0 (or any later version). You can +# choose between one of them if you use MacCAN-TouCAN in whole or in part. +# +# BSD 2-Clause "Simplified" License: +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# MacCAN-TouCAN IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF MacCAN-TouCAN, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# GNU General Public License v3.0 or later: # MacCAN-TouCAN is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or @@ -16,9 +42,8 @@ # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with MacCAN-TouCAN. If not, see . +# along with MacCAN-TouCAN. If not, see . # - all: @./build_no.sh @echo "\033[1mBuilding MacCAN-TouCAN...\033[0m" @@ -27,7 +52,7 @@ all: $(MAKE) -C Libraries/TouCAN $@ $(MAKE) -C Utilities/can_test $@ $(MAKE) -C Utilities/can_moni $@ -# $(MAKE) -C Tests/CANAPI $@ + $(MAKE) -C Tests/CANAPI $@ clean: $(MAKE) -C Trial $@ @@ -35,7 +60,7 @@ clean: $(MAKE) -C Libraries/TouCAN $@ $(MAKE) -C Utilities/can_test $@ $(MAKE) -C Utilities/can_moni $@ -# $(MAKE) -C Tests/CANAPI $@ + $(MAKE) -C Tests/CANAPI $@ pristine: $(MAKE) -C Trial $@ @@ -43,7 +68,7 @@ pristine: $(MAKE) -C Libraries/TouCAN $@ $(MAKE) -C Utilities/can_test $@ $(MAKE) -C Utilities/can_moni $@ -# $(MAKE) -C Tests/CANAPI $@ + $(MAKE) -C Tests/CANAPI $@ install: # $(MAKE) -C Trial $@ diff --git a/Package.swift b/Package.swift index 927ac1e..ea1e510 100644 --- a/Package.swift +++ b/Package.swift @@ -47,7 +47,7 @@ let package = Package( "Driver/TouCAN_Driver.c", "Driver/TouCAN_USB_Driver.c", "Driver/TouCAN_USB_Device.c", - "Driver/TouCAN_USB.c", + "Driver/TouCAN_USB_CmdMsg.c", "MacCAN/MacCAN_MsgQueue.c", "MacCAN/MacCAN_IOUsbKit.c", "MacCAN/MacCAN_Devices.c", diff --git a/README.md b/README.md index ca400a1..870dc04 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ ### macOS® User-Space Driver for TouCAN USB Interfaces from Rusoku -_Copyright © 2020-2023 Uwe Vogt, UV Software, Berlin (info@mac-can.com)_ +_Copyright © 2020-2024 Uwe Vogt, UV Software, Berlin (info@mac-can.com)_ + +![macOS Build](https://github.com/mac-can/RusokuCAN.dylib/actions/workflows/macos-build.yml/badge.svg) # Running CAN on Mac® @@ -12,13 +14,14 @@ The macOS driver for TouCAN USB interfaces from [Rusoku](https://www.rusoku.com) This repo contains the source code for the _MacCAN-TouCAN_ driver and several alternatives to build dynamic libraries for macOS, either as a C++ class library ([_libTouCAN_](#libTouCAN)), or as a _CAN API V3_ driver library ([_libUVCANTOU_](#libUVCANTOU)), -or as a _VSCP CANAL_ compatible library ([_libCANAL_](#libCANAL)), as well as my beloved CAN utilities [`can_moni`](#can_moni) and [`can_test`](#can_test), and some C/C++, Swift, and Python example programs. _CAN API V3_ is a wrapper specification to have a uniform CAN Interface API for various CAN interfaces from different vendors running under multiple operating systems. See header file `CANAPI.h` for the CAN API V3 wrapper specification. +Note: _This project does not aim to implement Rusoku´s CANAL library on macOS._ + ### TouCAN API ```C++ @@ -58,6 +61,12 @@ public: CANAPI_Return_t GetProperty(uint16_t param, void *value, uint32_t nbyte); CANAPI_Return_t SetProperty(uint16_t param, const void *value, uint32_t nbyte); + CANAPI_Return_t SetFilter11Bit(uint32_t code, uint32_t mask); + CANAPI_Return_t SetFilter29Bit(uint32_t code, uint32_t mask); + CANAPI_Return_t GetFilter11Bit(uint32_t &code, uint32_t &mask); + CANAPI_Return_t GetFilter29Bit(uint32_t &code, uint32_t &mask); + CANAPI_Return_t ResetFilters(); + char *GetHardwareVersion(); // (for compatibility reasons) char *GetFirmwareVersion(); // (for compatibility reasons) static char *GetVersion(); // (for compatibility reasons) @@ -87,7 +96,7 @@ uv-pc013mac:TouCAN eris$ make all uv-pc013mac:TouCAN eris$ sudo make install uv-pc013mac:TouCAN eris$ ``` -_(The version number of the library can be adapted by editing the appropriated `Makefile` and changing the variable `VERSION` accordingly. Don´t forget to set the version number also in the source files.)_ +_(The version number of the library can be adapted by editing the appropriated `Makefile` and changing the variable `VERSION` accordingly. Don´t forget to set the version number also in the header file `Version.h`.)_ #### libTouCAN @@ -99,12 +108,6 @@ See header file `TouCAN.h` for a description of all class members. ___libUVCANTOU___ is a dynamic library with a CAN API V3 compatible application programming interface for use in __C__ applications. See header file `can_api.h` for a description of all API functions. -#### libCANAL (_Sorry, not realized yet!_) - -___libCANAL___ is a dynamic library with a VSCP CANAL compatible application programming interface. -The TouCAN USB hardware is delivered with a CANAL (CAN Application Layer) DLL for Windows. -See [Rusoku](https://github.com/rusoku)´s GitHub page for further information. - #### can_moni `can_moni` is a command line tool to view incoming CAN messages. @@ -122,19 +125,19 @@ Type `can_test --help` to display all program options. ### Target Platform -- macOS 11.0 and later (Intel x64 and Apple silicon) +- macOS 12.0 and later (Intel x64 and Apple silicon) -### Development Environment +### Development Environments -#### macOS Ventura +#### macOS Sonoma -- macOS Ventura (13.6.1) on a Mac mini (M1, 2020) -- Apple clang version 15.0.0 (clang-1500.0.40.1) -- Xcode Version 15.0.1 (15A507) +- macOS Sonoma (14.4.1) on a Mac mini (M1, 2020) +- Apple clang version 15.0.0 (clang-1500.3.9.4) +- Xcode Version 15.3 (15E204a) -#### macOS Big Sur +#### macOS Monterey -- macOS Big Sur (11.7.10) on a MacBook Pro (2019) +- macOS Monterey (12.7.4) on a MacBook Pro (2019) - Apple clang version 13.0.0 (clang-1300.0.29.30) - Xcode Version 13.2.1 (13C100) @@ -150,32 +153,15 @@ For a list of known bugs and caveats see tab [Issues](https://github.com/mac-can ### CAN API V3 Reference -A generic documentation of the CAN API V3 application programming interface can be found [here](https://uv-software.github.io/CANAPI-Docs). - -### Licenses - -#### MacCAN-TouCAN License - -MacCAN-TouCAN is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -MacCAN-TouCAN is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with MacCAN-TouCAN. If not, see <http://www.gnu.org/licenses/>. +A generic documentation of the CAN API V3 application programming interface can be found [here](https://uv-software.github.io/CANAPI-Docs/#/). -#### MacCAN-Core License +### Dual-License -MacCAN-Core (which includes CAN API V3) is dual-licensed under the terms of the BSD 2-Clause "Simplified" License +Except where otherwise noted, this work is dual-licensed under the terms of the BSD 2-Clause "Simplified" License and under the terms of the GNU General Public License v3.0 (or any later version). -The terms of the GNU General Public License v3.0 (or any later version) apply to this work, see above. +You can choose between one of them if you use these portions of this work in whole or in part. -`SPDX-License-Identifier: GPL-3.0-or-later` +`SPDX-License-Identifier: BSD-2-Clause OR GPL-3.0-or-later` ### Trademarks diff --git a/Sources/CANAPI/CANAPI.h b/Sources/CANAPI/CANAPI.h index b62b8ce..c774abb 100644 --- a/Sources/CANAPI/CANAPI.h +++ b/Sources/CANAPI/CANAPI.h @@ -2,13 +2,13 @@ // // CAN Interface API, Version 3 (Interface Definition) // -// Copyright (c) 2004-2023 Uwe Vogt, UV Software, Berlin (info@uv-software.com) +// Copyright (c) 2004-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) // All rights reserved. // // This file is part of CAN API V3. // -// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License and -// under the GNU General Public License v3.0 (or any later version). +// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License +// and under the GNU General Public License v3.0 (or any later version). // You can choose between one of them if you use this file. // // BSD 2-Clause "Simplified" License: @@ -43,7 +43,7 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with CAN API V3. If not, see . +// along with CAN API V3. If not, see . // /// \file CANAPI.h // @@ -73,9 +73,9 @@ /// zero to compile your program with the CAN API source files or to /// link your program with the static library at compile-time. /// -/// \author $Author: haumea $ +/// \author $Author: eris $ // -/// \version $Rev: 1212 $ +/// \version $Rev: 1270 $ // /// \defgroup can_api CAN Interface API, Version 3 /// \{ @@ -227,21 +227,16 @@ class CANCPP CCanApi { static bool GetFirstChannel(SChannelInfo &info, void *param = NULL); #endif - /// \brief query channel information of the first CAN interface in the + /// \brief query channel information of the next CAN interface in the /// list of CAN interfaces, if any. // - /// \param[in] library - library id of the CAN interface list, or -1 for all vendors /// \param[out] info - the channel information of the next entry in the list /// \param[out] param - pointer to channel-specific parameters // /// \returns true if channel information have been successfully read, or /// false on error. // -#if (OPTION_CANAPI_LIBRARY != 0) - static bool GetNextChannel(int32_t library, SChannelInfo &info, void *param = NULL); -#else - static bool GetNextChannel(SChannelInfo &info, void *param = NULL); -#endif + static bool GetNextChannel(SChannelInfo &info, void *param = NULL); /// \brief probes if the CAN interface (hardware and driver) given by /// the argument [ 'library' and ] 'channel' is present, @@ -397,7 +392,7 @@ class CANCPP CCanApi { // /// \param[in] param - property id to be read /// \param[out] value - pointer to a buffer for the value to be read - /// \param[in] nbyte - size of the given buffer in byte + /// \param[in] nbyte - size of the given buffer in byte // /// \returns 0 if successful, or a negative value on error. // @@ -407,12 +402,54 @@ class CANCPP CCanApi { // /// \param[in] param - property id to be written /// \param[in] value - pointer to a buffer with the value to be written - /// \param[in] nbyte - size of the given buffer in byte + /// \param[in] nbyte - size of the given buffer in byte // /// \returns 0 if successful, or a negative value on error. // virtual CANAPI_Return_t SetProperty(uint16_t param, const void *value, uint32_t nbyte) = 0; + /// \brief sets the filter for 11-bit CAN identifiers. + // + /// \param[in] code - 11-bit code for the filter + /// \param[in] mask - 11-bit mask for the filter + // + /// \returns 0 if successful, or a negative value on error. + // + virtual CANAPI_Return_t SetFilter11Bit(uint32_t code, uint32_t mask) = 0; + + /// \brief retrieves the filter for 11-bit CAN identifiers. + // + /// \param[out] code - 11-bit code for the filter + /// \param[out] mask - 11-bit mask for the filter + // + /// \returns 0 if successful, or a negative value on error. + // + virtual CANAPI_Return_t GetFilter11Bit(uint32_t &code, uint32_t &mask) = 0; + + /// \brief sets the filter for 29-bit CAN identifiers. + // + /// \param[in] code - 29-bit code for the filter + /// \param[in] mask - 29-bit mask for the filter + // + /// \returns 0 if successful, or a negative value on error. + // + virtual CANAPI_Return_t SetFilter29Bit(uint32_t code, uint32_t mask) = 0; + + /// \brief retrieves the filter for 29-bit CAN identifiers. + // + /// \param[out] code - 29-bit code for the filter + /// \param[out] mask - 29-bit mask for the filter + // + /// \returns 0 if successful, or a negative value on error. + // + virtual CANAPI_Return_t GetFilter29Bit(uint32_t &code, uint32_t &mask) = 0; + + /// \brief resets the filters for CAN identifiers (11-bit and 29-bit). + // + /// \returns 0 if successful, or a negative value on error. + // + virtual CANAPI_Return_t ResetFilters() = 0; + /// \brief retrieves the hardware version of the CAN controller /// board as a zero-terminated string. // @@ -478,4 +515,4 @@ class CANCPP CCanApi { /// \} #endif // CANAPI_H_INCLUDED /// \} -// $Id: CANAPI.h 1212 2023-10-04 15:41:24Z haumea $ Copyright (c) UV Software // +// $Id: CANAPI.h 1270 2024-04-15 18:42:43Z eris $ Copyright (c) UV Software // diff --git a/Sources/CANAPI/CANAPI_Defines.h b/Sources/CANAPI/CANAPI_Defines.h index f17d8eb..e9b8bef 100644 --- a/Sources/CANAPI/CANAPI_Defines.h +++ b/Sources/CANAPI/CANAPI_Defines.h @@ -2,13 +2,13 @@ /* * CAN Interface API, Version 3 (Definitions and Options) * - * Copyright (c) 2004-2021 Uwe Vogt, UV Software, Berlin (info@uv-software.com) + * Copyright (c) 2004-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) * All rights reserved. * * This file is part of CAN API V3. * - * CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License and - * under the GNU General Public License v3.0 (or any later version). + * CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License + * and under the GNU General Public License v3.0 (or any later version). * You can choose between one of them if you use this file. * * BSD 2-Clause "Simplified" License: @@ -43,7 +43,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with CAN API V3. If not, see . + * along with CAN API V3. If not, see . */ /** @file CANAPI_Defines.h * @@ -51,7 +51,7 @@ * * @author $Author: eris $ * - * @version $Rev: 993 $ + * @version $Rev: 1270 $ * * @addtogroup can_api * @{ diff --git a/Sources/CANAPI/CANAPI_Types.h b/Sources/CANAPI/CANAPI_Types.h index 453afb1..c3ab159 100644 --- a/Sources/CANAPI/CANAPI_Types.h +++ b/Sources/CANAPI/CANAPI_Types.h @@ -2,13 +2,13 @@ /* * CAN Interface API, Version 3 (Data Types and Defines) * - * Copyright (c) 2004-2023 Uwe Vogt, UV Software, Berlin (info@uv-software.com) + * Copyright (c) 2004-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) * All rights reserved. * * This file is part of CAN API V3. * - * CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License and - * under the GNU General Public License v3.0 (or any later version). + * CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License + * and under the GNU General Public License v3.0 (or any later version). * You can choose between one of them if you use this file. * * BSD 2-Clause "Simplified" License: @@ -43,15 +43,15 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with CAN API V3. If not, see . + * along with CAN API V3. If not, see . */ /** @file CANAPI_Types.h * * @brief CAN API V3 for generic CAN Interfaces - Data Types and Defines * - * @author $Author: haumea $ + * @author $Author: eris $ * - * @version $Rev: 1212 $ + * @version $Rev: 1270 $ * * @addtogroup can_api * @{ @@ -112,6 +112,7 @@ extern "C" { /** @name CAN Identifier * @brief CAN Identifier range + * @todo Make it unsigned! * @{ */ #define CAN_MAX_STD_ID 0x7FF /**< highest 11-bit identifier */ #define CAN_MAX_XTD_ID 0x1FFFFFFF /**< highest 29-bit identifier */ @@ -119,6 +120,7 @@ extern "C" { /** @name CAN Data Length * @brief CAN payload length and DLC definition + * @todo Make it unsigned? * @{ */ #define CAN_MAX_DLC 8 /**< max. data length code (CAN 2.0) */ #define CAN_MAX_LEN 8 /**< max. payload length (CAN 2.0) */ @@ -131,6 +133,16 @@ extern "C" { #define CANFD_MAX_LEN 64 /**< max. payload length (CAN FD) */ /** @} */ +/** @name CAN Acceptance Filter + * @brief CAN acceptance filter defaults to let all messages pass + * @note Acceptance condition: (code ^ id) & mask == 0 + * @{ */ +#define CANACC_CODE_11BIT 0x000U /**< mask for 11-bit acceptance code */ +#define CANACC_MASK_11BIT 0x000U /**< mask for 11-bit acceptance mask */ +#define CANACC_CODE_29BIT 0x00000000U /**< mask for 29-bit acceptance code */ +#define CANACC_MASK_29BIT 0x00000000U /**< mask for 29-bit acceptance mask */ +/** @} */ + /** @name CAN Baud Rate Indexes (for compatibility) * @brief CAN baud rate indexes defined by CiA (for CANopen) * @note They must be passed with a minus sign to can_start() @@ -333,14 +345,11 @@ extern "C" { #define CANPROP_GET_TRM_QUEUE_SIZE 30U /**< maximum number of message the transmit queue can hold (uint32_t) */ #define CANPROP_GET_TRM_QUEUE_HIGH 31U /**< maximum number of message the transmit queue has hold (uint32_t) */ #define CANPROP_GET_TRM_QUEUE_OVFL 32U /**< overflow counter of the transmit queue (uint64_t) */ -#define CANPROP_GET_FLT_11BIT_CODE 40U /**< acceptance filter code of 11-bit identifier (int32_t) */ -#define CANPROP_GET_FLT_11BIT_MASK 41U /**< acceptance filter mask of 11-bit identifier (int32_t) */ -#define CANPROP_GET_FLT_29BIT_CODE 42U /**< acceptance filter code of 29-bit identifier (int32_t) */ -#define CANPROP_GET_FLT_29BIT_MASK 43U /**< acceptance filter mask of 29-bit identifier (int32_t) */ -#define CANPROP_SET_FLT_11BIT_CODE 44U /**< set value for acceptance filter code of 11-bit identifier (int32_t) */ -#define CANPROP_SET_FLT_11BIT_MASK 45U /**< set value for acceptance filter mask of 11-bit identifier (int32_t) */ -#define CANPROP_SET_FLT_29BIT_CODE 46U /**< set value for acceptance filter code of 29-bit identifier (int32_t) */ -#define CANPROP_SET_FLT_29BIT_MASK 47U /**< set value for acceptance filter mask of 29-bit identifier (int32_t) */ +#define CANPROP_GET_FILTER_11BIT 40U /**< acceptance filter code and mask for 11-bit identifier (uint64_t) */ +#define CANPROP_GET_FILTER_29BIT 41U /**< acceptance filter code and mask for 29-bit identifier (uint64_t) */ +#define CANPROP_SET_FILTER_11BIT 42U /**< set value for acceptance filter code and mask for 11-bit identifier (uint64_t) */ +#define CANPROP_SET_FILTER_29BIT 43U /**< set value for acceptance filter code and mask for 29-bit identifier (uint64_t) */ +#define CANPROP_SET_FILTER_RESET 44U /**< reset acceptance filter code and mask to default values (NULL) */ #if (OPTION_CANAPI_LIBRARY != 0) /* - - build-in bit-rate conversion - - - - - - - - - - - - - - - - - */ #define CANPROP_GET_BTR_INDEX 64U /**< bit-rate as CiA index (int32_t) */ diff --git a/Sources/CANAPI/CANBTR_Defaults.h b/Sources/CANAPI/CANBTR_Defaults.h index 448e575..7229339 100644 --- a/Sources/CANAPI/CANBTR_Defaults.h +++ b/Sources/CANAPI/CANBTR_Defaults.h @@ -1,174 +1,174 @@ -/* SPDX-License-Identifier: BSD-2-Clause OR GPL-3.0-or-later */ -/* - * CAN Interface API, Version 3 (Definitions and Options) - * - * Copyright (c) 2004-2021 Uwe Vogt, UV Software, Berlin (info@uv-software.com) - * All rights reserved. - * - * This file is part of CAN API V3. - * - * CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License and - * under the GNU General Public License v3.0 (or any later version). - * You can choose between one of them if you use this file. - * - * BSD 2-Clause "Simplified" License: - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * CAN API V3 IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF CAN API V3, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * GNU General Public License v3.0 or later: - * CAN API V3 is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * CAN API V3 is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with CAN API V3. If not, see . - */ -/** @file CANBTR_Defines.h - * - * @brief CAN API V3 for generic CAN Interfaces - Definitions and Options - * - * @author $Author: eris $ - * - * @version $Rev: 1090 $ - * - * @addtogroup can_btr - * @{ - */ -#ifndef CANBTR_DEFINES_H_INCLUDED -#define CANBTR_DEFINES_H_INCLUDED - -#ifdef __cplusplus -extern "C" { -#endif - -/* ----------- includes ------------------------------------------------ - */ - - -/* ----------- options ------------------------------------------------ - */ - - -/* ----------- defines ------------------------------------------------ - */ - -/** @name SJA1000 CAN Clock - * @brief Frequency of the SJA1000 CAN controller. - * @{ */ -#define SJA1000_CAN_CLOCK 8000000 /**< 8 MHz */ -/** @} */ - -/** @name SJA1000 Bit-timing Values - * @brief Predefined BTR0BTR1 register values (complies to CiA CANopen DS-301 spec.). - * - * @note 800 kbps is not supported by all CAN controller
- * 100 kbps is an obsolete CANopen bit-rate
- * 5 kbps is not defined in CANopen - * @{ */ -#define SJA1000_1M 0x0014U /**< 1000 kbps (SP=75.0%, SJW=1) */ -#define SJA1000_800K 0x0016U /**< 800 kbps (SP=80.0%, SJW=1) */ -#define SJA1000_500K 0x001CU /**< 500 kbps (SP=87.5%, SJW=1) */ -#define SJA1000_250K 0x011CU /**< 250 kbps (SP=87.5%, SJW=1) */ -#define SJA1000_125K 0x031CU /**< 125 kbps (SP=87.5%, SJW=1) */ -#define SJA1000_100K 0x441CU /**< 100 kbps (SP=87.5%, SJW=2) */ -#define SJA1000_50K 0x491CU /**< 50 kbps (SP=87.5%, SJW=2) */ -#define SJA1000_20K 0x581CU /**< 20 kbps (SP=87.5%, SJW=2) */ -#define SJA1000_10K 0x711CU /**< 10 kbps (SP=87.5%, SJW=2) */ -#define SJA1000_5K 0x7F7FU /**< 5 kbps (SP=68.0%, SJW=2) */ -/** @} */ - -/** @name SJA1000 Bit-rate Settings - * @brief Predefined BTR0BTR1 register values as CAN API V3 bit-rate settings. - * @{ */ -#define SJA1000_BR_1M(x) do {x.btr.frequency=SJA1000_CAN_CLOCK;x.btr.nominal.brp=1; x.btr.nominal.tseg1=5; x.btr.nominal.tseg2=2;x.btr.nominal.sjw=1;x.btr.nominal.sam=0;} while(0) -#define SJA1000_BR_800K(x) do {x.btr.frequency=SJA1000_CAN_CLOCK;x.btr.nominal.brp=1; x.btr.nominal.tseg1=7; x.btr.nominal.tseg2=2;x.btr.nominal.sjw=1;x.btr.nominal.sam=0;} while(0) -#define SJA1000_BR_500K(x) do {x.btr.frequency=SJA1000_CAN_CLOCK;x.btr.nominal.brp=1; x.btr.nominal.tseg1=13;x.btr.nominal.tseg2=2;x.btr.nominal.sjw=1;x.btr.nominal.sam=0;} while(0) -#define SJA1000_BR_250K(x) do {x.btr.frequency=SJA1000_CAN_CLOCK;x.btr.nominal.brp=2; x.btr.nominal.tseg1=13;x.btr.nominal.tseg2=2;x.btr.nominal.sjw=1;x.btr.nominal.sam=0;} while(0) -#define SJA1000_BR_125K(x) do {x.btr.frequency=SJA1000_CAN_CLOCK;x.btr.nominal.brp=4; x.btr.nominal.tseg1=13;x.btr.nominal.tseg2=2;x.btr.nominal.sjw=1;x.btr.nominal.sam=0;} while(0) -#define SJA1000_BR_100K(x) do {x.btr.frequency=SJA1000_CAN_CLOCK;x.btr.nominal.brp=5; x.btr.nominal.tseg1=13;x.btr.nominal.tseg2=2;x.btr.nominal.sjw=2;x.btr.nominal.sam=0;} while(0) -#define SJA1000_BR_50K(x) do {x.btr.frequency=SJA1000_CAN_CLOCK;x.btr.nominal.brp=10;x.btr.nominal.tseg1=13;x.btr.nominal.tseg2=2;x.btr.nominal.sjw=2;x.btr.nominal.sam=0;} while(0) -#define SJA1000_BR_20K(x) do {x.btr.frequency=SJA1000_CAN_CLOCK;x.btr.nominal.brp=25;x.btr.nominal.tseg1=13;x.btr.nominal.tseg2=2;x.btr.nominal.sjw=2;x.btr.nominal.sam=0;} while(0) -#define SJA1000_BR_10K(x) do {x.btr.frequency=SJA1000_CAN_CLOCK;x.btr.nominal.brp=50;x.btr.nominal.tseg1=13;x.btr.nominal.tseg2=2;x.btr.nominal.sjw=2;x.btr.nominal.sam=0;} while(0) -#define SJA1000_BR_5K(x) do {x.btr.frequency=SJA1000_CAN_CLOCK;x.btr.nominal.brp=64;x.btr.nominal.tseg1=16;x.btr.nominal.tseg2=8;x.btr.nominal.sjw=2;x.btr.nominal.sam=0;} while(0) -/** @} */ - -/** @name CAN API CAN Clock - * @brief Default value for CAN 2.0 and CAN FD operation modes. - * @{ */ -#define DEFAULT_CAN_CLOCK SJA1000_CAN_CLOCK /**< SJA1000 CAN Clock (8 MHz) */ -#define DEFAULT_CAN_FD_CLOCK 80000000 /**< CAN FD Clock (80 MHz) */ -/** @} */ - -/** @name CAN 2.0 Bit-rate Settings - * @brief Default values according to CANopen spec. (CAN API requirement). - * @{ */ -#define DEFAULT_CAN_BR_1M(x) SJA1000_BR_1M(x) -#define DEFAULT_CAN_BR_800K(x) SJA1000_BR_800K(x) -#define DEFAULT_CAN_BR_500K(x) SJA1000_BR_500K(x) -#define DEFAULT_CAN_BR_250K(x) SJA1000_BR_250K(x) -#define DEFAULT_CAN_BR_125K(x) SJA1000_BR_125K(x) -#define DEFAULT_CAN_BR_100K(x) SJA1000_BR_100K(x) -#define DEFAULT_CAN_BR_50K(x) SJA1000_BR_50K(x) -#define DEFAULT_CAN_BR_20K(x) SJA1000_BR_20K(x) -#define DEFAULT_CAN_BR_10K(x) SJA1000_BR_10K(x) -#define DEFAULT_CAN_BR_5K(x) SJA1000_BR_5K(x) -/** @} */ - -#if (OPTION_CAN_2_0_ONLY == 0) -/** @name CAN FD Bit-rate Settings w/o Bit-rate Switching - * @brief Default values for long frames only (0 to 64 bytes). - * - * @note Actual bit-rate settings for specific controllers may vary. - * The settings made here are for Peak CAN FD interfaces. - * @{ */ -#define DEFAULT_CAN_FD_BR_1M(x) do {x.btr.frequency=DEFAULT_CAN_FD_CLOCK;x.btr.nominal.brp=2;x.btr.nominal.tseg1=31; x.btr.nominal.tseg2=8; x.btr.nominal.sjw=8; } while(0) -#define DEFAULT_CAN_FD_BR_500K(x) do {x.btr.frequency=DEFAULT_CAN_FD_CLOCK;x.btr.nominal.brp=2;x.btr.nominal.tseg1=63; x.btr.nominal.tseg2=16;x.btr.nominal.sjw=16;} while(0) -#define DEFAULT_CAN_FD_BR_250K(x) do {x.btr.frequency=DEFAULT_CAN_FD_CLOCK;x.btr.nominal.brp=2;x.btr.nominal.tseg1=127;x.btr.nominal.tseg2=32;x.btr.nominal.sjw=32;} while(0) -#define DEFAULT_CAN_FD_BR_125K(x) do {x.btr.frequency=DEFAULT_CAN_FD_CLOCK;x.btr.nominal.brp=2;x.btr.nominal.tseg1=255;x.btr.nominal.tseg2=64;x.btr.nominal.sjw=64;} while(0) -/** @} */ - -/** @name CAN FD Bit-rate Settings with Bit-rate Switching - * @brief Default values for long and fast frames only (up to 8 Mbps). - * - * @note Actual bit-rate settings for specific controllers may vary. - * The settings made here are for Peak CAN FD interfaces. - * @{ */ -#define DEFAULT_CAN_FD_BR_1M8M(x) do {x.btr.frequency=DEFAULT_CAN_FD_CLOCK;x.btr.nominal.brp=2;x.btr.nominal.tseg1=31; x.btr.nominal.tseg2=8; x.btr.nominal.sjw=8; x.btr.data.brp=2; x.btr.data.tseg1=3; x.btr.data.tseg2=1; x.btr.data.sjw=1; } while(0) -#define DEFAULT_CAN_FD_BR_500K4M(x) do {x.btr.frequency=DEFAULT_CAN_FD_CLOCK;x.btr.nominal.brp=2;x.btr.nominal.tseg1=63; x.btr.nominal.tseg2=16;x.btr.nominal.sjw=16; x.btr.data.brp=2; x.btr.data.tseg1=7; x.btr.data.tseg2=2; x.btr.data.sjw=2; } while(0) -#define DEFAULT_CAN_FD_BR_250K2M(x) do {x.btr.frequency=DEFAULT_CAN_FD_CLOCK;x.btr.nominal.brp=2;x.btr.nominal.tseg1=127;x.btr.nominal.tseg2=32;x.btr.nominal.sjw=32; x.btr.data.brp=2; x.btr.data.tseg1=15; x.btr.data.tseg2=4; x.btr.data.sjw=4; } while(0) -#define DEFAULT_CAN_FD_BR_125K1M(x) do {x.btr.frequency=DEFAULT_CAN_FD_CLOCK;x.btr.nominal.brp=2;x.btr.nominal.tseg1=255;x.btr.nominal.tseg2=64;x.btr.nominal.sjw=64; x.btr.data.brp=2; x.btr.data.tseg1=31; x.btr.data.tseg2=8; x.btr.data.sjw=8; } while(0) -/** @} */ -#endif -#ifdef __cplusplus -} -#endif -#endif /* CANBTR_DEFINES_H_INCLUDED */ -/** @} - */ -/* ---------------------------------------------------------------------- - * Uwe Vogt, UV Software, Chausseestrasse 33 A, 10115 Berlin, Germany - * Tel.: +49-30-46799872, Fax: +49-30-46799873, Mobile: +49-170-3801903 - * E-Mail: uwe.vogt@uv-software.de, Homepage: http://www.uv-software.de/ - */ +/* SPDX-License-Identifier: BSD-2-Clause OR GPL-3.0-or-later */ +/* + * CAN Interface API, Version 3 (Definitions and Options) + * + * Copyright (c) 2004-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) + * All rights reserved. + * + * This file is part of CAN API V3. + * + * CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License + * and under the GNU General Public License v3.0 (or any later version). + * You can choose between one of them if you use this file. + * + * BSD 2-Clause "Simplified" License: + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * CAN API V3 IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF CAN API V3, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * GNU General Public License v3.0 or later: + * CAN API V3 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * CAN API V3 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with CAN API V3. If not, see . + */ +/** @file CANBTR_Defines.h + * + * @brief CAN API V3 for generic CAN Interfaces - Definitions and Options + * + * @author $Author: eris $ + * + * @version $Rev: 1270 $ + * + * @addtogroup can_btr + * @{ + */ +#ifndef CANBTR_DEFINES_H_INCLUDED +#define CANBTR_DEFINES_H_INCLUDED + +#ifdef __cplusplus +extern "C" { +#endif + +/* ----------- includes ------------------------------------------------ + */ + + +/* ----------- options ------------------------------------------------ + */ + + +/* ----------- defines ------------------------------------------------ + */ + +/** @name SJA1000 CAN Clock + * @brief Frequency of the SJA1000 CAN controller. + * @{ */ +#define SJA1000_CAN_CLOCK 8000000 /**< 8 MHz */ +/** @} */ + +/** @name SJA1000 Bit-timing Values + * @brief Predefined BTR0BTR1 register values (complies to CiA CANopen DS-301 spec.). + * + * @note 800 kbps is not supported by all CAN controller
+ * 100 kbps is an obsolete CANopen bit-rate
+ * 5 kbps is not defined in CANopen + * @{ */ +#define SJA1000_1M 0x0014U /**< 1000 kbps (SP=75.0%, SJW=1) */ +#define SJA1000_800K 0x0016U /**< 800 kbps (SP=80.0%, SJW=1) */ +#define SJA1000_500K 0x001CU /**< 500 kbps (SP=87.5%, SJW=1) */ +#define SJA1000_250K 0x011CU /**< 250 kbps (SP=87.5%, SJW=1) */ +#define SJA1000_125K 0x031CU /**< 125 kbps (SP=87.5%, SJW=1) */ +#define SJA1000_100K 0x441CU /**< 100 kbps (SP=87.5%, SJW=2) */ +#define SJA1000_50K 0x491CU /**< 50 kbps (SP=87.5%, SJW=2) */ +#define SJA1000_20K 0x581CU /**< 20 kbps (SP=87.5%, SJW=2) */ +#define SJA1000_10K 0x711CU /**< 10 kbps (SP=87.5%, SJW=2) */ +#define SJA1000_5K 0x7F7FU /**< 5 kbps (SP=68.0%, SJW=2) */ +/** @} */ + +/** @name SJA1000 Bit-rate Settings + * @brief Predefined BTR0BTR1 register values as CAN API V3 bit-rate settings. + * @{ */ +#define SJA1000_BR_1M(x) do {x.btr.frequency=SJA1000_CAN_CLOCK;x.btr.nominal.brp=1; x.btr.nominal.tseg1=5; x.btr.nominal.tseg2=2;x.btr.nominal.sjw=1;x.btr.nominal.sam=0;} while(0) +#define SJA1000_BR_800K(x) do {x.btr.frequency=SJA1000_CAN_CLOCK;x.btr.nominal.brp=1; x.btr.nominal.tseg1=7; x.btr.nominal.tseg2=2;x.btr.nominal.sjw=1;x.btr.nominal.sam=0;} while(0) +#define SJA1000_BR_500K(x) do {x.btr.frequency=SJA1000_CAN_CLOCK;x.btr.nominal.brp=1; x.btr.nominal.tseg1=13;x.btr.nominal.tseg2=2;x.btr.nominal.sjw=1;x.btr.nominal.sam=0;} while(0) +#define SJA1000_BR_250K(x) do {x.btr.frequency=SJA1000_CAN_CLOCK;x.btr.nominal.brp=2; x.btr.nominal.tseg1=13;x.btr.nominal.tseg2=2;x.btr.nominal.sjw=1;x.btr.nominal.sam=0;} while(0) +#define SJA1000_BR_125K(x) do {x.btr.frequency=SJA1000_CAN_CLOCK;x.btr.nominal.brp=4; x.btr.nominal.tseg1=13;x.btr.nominal.tseg2=2;x.btr.nominal.sjw=1;x.btr.nominal.sam=0;} while(0) +#define SJA1000_BR_100K(x) do {x.btr.frequency=SJA1000_CAN_CLOCK;x.btr.nominal.brp=5; x.btr.nominal.tseg1=13;x.btr.nominal.tseg2=2;x.btr.nominal.sjw=2;x.btr.nominal.sam=0;} while(0) +#define SJA1000_BR_50K(x) do {x.btr.frequency=SJA1000_CAN_CLOCK;x.btr.nominal.brp=10;x.btr.nominal.tseg1=13;x.btr.nominal.tseg2=2;x.btr.nominal.sjw=2;x.btr.nominal.sam=0;} while(0) +#define SJA1000_BR_20K(x) do {x.btr.frequency=SJA1000_CAN_CLOCK;x.btr.nominal.brp=25;x.btr.nominal.tseg1=13;x.btr.nominal.tseg2=2;x.btr.nominal.sjw=2;x.btr.nominal.sam=0;} while(0) +#define SJA1000_BR_10K(x) do {x.btr.frequency=SJA1000_CAN_CLOCK;x.btr.nominal.brp=50;x.btr.nominal.tseg1=13;x.btr.nominal.tseg2=2;x.btr.nominal.sjw=2;x.btr.nominal.sam=0;} while(0) +#define SJA1000_BR_5K(x) do {x.btr.frequency=SJA1000_CAN_CLOCK;x.btr.nominal.brp=64;x.btr.nominal.tseg1=16;x.btr.nominal.tseg2=8;x.btr.nominal.sjw=2;x.btr.nominal.sam=0;} while(0) +/** @} */ + +/** @name CAN API CAN Clock + * @brief Default value for CAN 2.0 and CAN FD operation modes. + * @{ */ +#define DEFAULT_CAN_CLOCK SJA1000_CAN_CLOCK /**< SJA1000 CAN Clock (8 MHz) */ +#define DEFAULT_CAN_FD_CLOCK 80000000 /**< CAN FD Clock (80 MHz) */ +/** @} */ + +/** @name CAN 2.0 Bit-rate Settings + * @brief Default values according to CANopen spec. (CAN API requirement). + * @{ */ +#define DEFAULT_CAN_BR_1M(x) SJA1000_BR_1M(x) +#define DEFAULT_CAN_BR_800K(x) SJA1000_BR_800K(x) +#define DEFAULT_CAN_BR_500K(x) SJA1000_BR_500K(x) +#define DEFAULT_CAN_BR_250K(x) SJA1000_BR_250K(x) +#define DEFAULT_CAN_BR_125K(x) SJA1000_BR_125K(x) +#define DEFAULT_CAN_BR_100K(x) SJA1000_BR_100K(x) +#define DEFAULT_CAN_BR_50K(x) SJA1000_BR_50K(x) +#define DEFAULT_CAN_BR_20K(x) SJA1000_BR_20K(x) +#define DEFAULT_CAN_BR_10K(x) SJA1000_BR_10K(x) +#define DEFAULT_CAN_BR_5K(x) SJA1000_BR_5K(x) +/** @} */ + +#if (OPTION_CAN_2_0_ONLY == 0) +/** @name CAN FD Bit-rate Settings w/o Bit-rate Switching + * @brief Default values for long frames only (0 to 64 bytes). + * + * @note Actual bit-rate settings for specific controllers may vary. + * The settings made here are for Peak CAN FD interfaces. + * @{ */ +#define DEFAULT_CAN_FD_BR_1M(x) do {x.btr.frequency=DEFAULT_CAN_FD_CLOCK;x.btr.nominal.brp=2;x.btr.nominal.tseg1=31; x.btr.nominal.tseg2=8; x.btr.nominal.sjw=8; } while(0) +#define DEFAULT_CAN_FD_BR_500K(x) do {x.btr.frequency=DEFAULT_CAN_FD_CLOCK;x.btr.nominal.brp=2;x.btr.nominal.tseg1=63; x.btr.nominal.tseg2=16;x.btr.nominal.sjw=16;} while(0) +#define DEFAULT_CAN_FD_BR_250K(x) do {x.btr.frequency=DEFAULT_CAN_FD_CLOCK;x.btr.nominal.brp=2;x.btr.nominal.tseg1=127;x.btr.nominal.tseg2=32;x.btr.nominal.sjw=32;} while(0) +#define DEFAULT_CAN_FD_BR_125K(x) do {x.btr.frequency=DEFAULT_CAN_FD_CLOCK;x.btr.nominal.brp=2;x.btr.nominal.tseg1=255;x.btr.nominal.tseg2=64;x.btr.nominal.sjw=64;} while(0) +/** @} */ + +/** @name CAN FD Bit-rate Settings with Bit-rate Switching + * @brief Default values for long and fast frames only (up to 8 Mbps). + * + * @note Actual bit-rate settings for specific controllers may vary. + * The settings made here are for Peak CAN FD interfaces. + * @{ */ +#define DEFAULT_CAN_FD_BR_1M8M(x) do {x.btr.frequency=DEFAULT_CAN_FD_CLOCK;x.btr.nominal.brp=2;x.btr.nominal.tseg1=31; x.btr.nominal.tseg2=8; x.btr.nominal.sjw=8; x.btr.data.brp=2; x.btr.data.tseg1=3; x.btr.data.tseg2=1; x.btr.data.sjw=1; } while(0) +#define DEFAULT_CAN_FD_BR_500K4M(x) do {x.btr.frequency=DEFAULT_CAN_FD_CLOCK;x.btr.nominal.brp=2;x.btr.nominal.tseg1=63; x.btr.nominal.tseg2=16;x.btr.nominal.sjw=16; x.btr.data.brp=2; x.btr.data.tseg1=7; x.btr.data.tseg2=2; x.btr.data.sjw=2; } while(0) +#define DEFAULT_CAN_FD_BR_250K2M(x) do {x.btr.frequency=DEFAULT_CAN_FD_CLOCK;x.btr.nominal.brp=2;x.btr.nominal.tseg1=127;x.btr.nominal.tseg2=32;x.btr.nominal.sjw=32; x.btr.data.brp=2; x.btr.data.tseg1=15; x.btr.data.tseg2=4; x.btr.data.sjw=4; } while(0) +#define DEFAULT_CAN_FD_BR_125K1M(x) do {x.btr.frequency=DEFAULT_CAN_FD_CLOCK;x.btr.nominal.brp=2;x.btr.nominal.tseg1=255;x.btr.nominal.tseg2=64;x.btr.nominal.sjw=64; x.btr.data.brp=2; x.btr.data.tseg1=31; x.btr.data.tseg2=8; x.btr.data.sjw=8; } while(0) +/** @} */ +#endif +#ifdef __cplusplus +} +#endif +#endif /* CANBTR_DEFINES_H_INCLUDED */ +/** @} + */ +/* ---------------------------------------------------------------------- + * Uwe Vogt, UV Software, Chausseestrasse 33 A, 10115 Berlin, Germany + * Tel.: +49-30-46799872, Fax: +49-30-46799873, Mobile: +49-170-3801903 + * E-Mail: uwe.vogt@uv-software.de, Homepage: http://www.uv-software.de/ + */ diff --git a/Sources/CANAPI/LICENSE.BSD-2-Clause b/Sources/CANAPI/LICENSE.BSD-2-Clause index d7d391e..08b6473 100644 --- a/Sources/CANAPI/LICENSE.BSD-2-Clause +++ b/Sources/CANAPI/LICENSE.BSD-2-Clause @@ -1,25 +1,25 @@ -BSD 2-Clause License - -Copyright (c) 2021, Uwe Vogt, UV Software -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +BSD 2-Clause License + +Copyright (c) 2004-2024, Uwe Vogt, UV Software +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/Sources/CANAPI/LICENSE.GPL-3.0-or-later b/Sources/CANAPI/LICENSE.GPL-3.0-or-later index f288702..3877ae0 100644 --- a/Sources/CANAPI/LICENSE.GPL-3.0-or-later +++ b/Sources/CANAPI/LICENSE.GPL-3.0-or-later @@ -1,674 +1,674 @@ - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU General Public License is a free, copyleft license for -software and other kinds of works. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - Copyright (C) - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -. + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/Sources/CANAPI/README.md b/Sources/CANAPI/README.md index 1c962ac..98691ec 100644 --- a/Sources/CANAPI/README.md +++ b/Sources/CANAPI/README.md @@ -1,9 +1,9 @@ ### CAN Interface API, Version 3 -_Copyright © 2004-2023 Uwe Vogt, UV Software, Berlin (info@uv-software.com)_ \ +_Copyright © 2004-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com)_ \ _All rights reserved._ -Version $Rev: 1212 $ +Version $Rev: 1270 $ # A CAN Interface Wrapper Specification @@ -65,9 +65,9 @@ See header file `can_api.h` for a description of the provided functions. ## This and That -### SVN Repo +### CAN API V3 Reference -The CAN API V3 sources are maintained in a SVN repo to synchronized them between the different CAN API V3 wrapper repos. +A generic documentation of the CAN API V3 application programming interface can be found [here](https://uv-software.github.io/CANAPI-Docs/#/). ### Dual-License diff --git a/Sources/CANAPI/can_api.h b/Sources/CANAPI/can_api.h index a490c6f..9291285 100644 --- a/Sources/CANAPI/can_api.h +++ b/Sources/CANAPI/can_api.h @@ -2,13 +2,13 @@ /* * CAN Interface API, Version 3 (generic) * - * Copyright (c) 2004-2023 Uwe Vogt, UV Software, Berlin (info@uv-software.com) + * Copyright (c) 2004-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) * All rights reserved. * * This file is part of CAN API V3. * - * CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License and - * under the GNU General Public License v3.0 (or any later version). + * CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License + * and under the GNU General Public License v3.0 (or any later version). * You can choose between one of them if you use this file. * * BSD 2-Clause "Simplified" License: @@ -43,7 +43,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with CAN API V3. If not, see . + * along with CAN API V3. If not, see . */ /** @file can_api.h * @@ -51,7 +51,7 @@ * * @author $Author: eris $ * - * @version $Rev: 1090 $ + * @version $Rev: 1270 $ * * @defgroup can_api CAN Interface API, Version 3 * @{ @@ -136,7 +136,7 @@ typedef int can_handle_t; #elif (OPTION_CANAPI_DRIVER != 0) #define CAN_BOARD(lib, brd) brd #else -#error Remove the unneeded definition(s)! +#error Remove the unneeded definition(s) #endif /* ----------- types -------------------------------------------------- diff --git a/Sources/CANAPI/can_btr.c b/Sources/CANAPI/can_btr.c index d25cbce..f8fa1d1 100644 --- a/Sources/CANAPI/can_btr.c +++ b/Sources/CANAPI/can_btr.c @@ -2,13 +2,13 @@ /* * CAN Interface API, Version 3 (Bit-rate Conversion) * - * Copyright (c) 2017-2023 Uwe Vogt, UV Software, Berlin (info@uv-software.com) + * Copyright (c) 2017-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) * All rights reserved. * * This file is part of CAN API V3. * - * CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License and - * under the GNU General Public License v3.0 (or any later version). + * CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License + * and under the GNU General Public License v3.0 (or any later version). * You can choose between one of them if you use this file. * * BSD 2-Clause "Simplified" License: @@ -43,7 +43,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with CAN API V3. If not, see . + * along with CAN API V3. If not, see . */ /** @file can_btr.c * @@ -55,9 +55,9 @@ * | SJW | BRP |SAM| TSEG2 | TSEG1 |
* +-7-+-6-+-5-+---+---+---+---+-0-+-7-+-6-+---+-4-+-3-+---+---+-0-+
* - * @author $Author: makemake $ + * @author $Author: eris $ * - * @version $Rev: 1186 $ + * @version $Rev: 1270 $ * * @addtogroup can_btr * @{ @@ -166,6 +166,8 @@ int btr_check_bitrate(const btr_bitrate_t *bitrate, bool fdoe, bool brse) { if ((bitrate->btr.nominal.sjw < BTR_NOMINAL_SJW_MIN) || (BTR_NOMINAL_SJW_MAX < bitrate->btr.nominal.sjw)) return BTRERR_BAUDRATE; #if (OPTION_CAN_2_0_ONLY != OPTION_DISABLED) + (void)fdoe; (void)brse; // To avoid compiler warnings + if ((bitrate->btr.nominal.sam != BTR_NOMINAL_SAM_SINGLE) && (BTR_NOMINAL_SAM_TRIPLE != bitrate->btr.nominal.sam)) return BTRERR_BAUDRATE; #else @@ -278,6 +280,8 @@ int btr_compare_bitrates(const btr_bitrate_t *bitrate1, const btr_bitrate_t *bit if (cmp_sp && (data_sp1 != data_sp2)) return (data_sp1 < data_sp2) ? -4 : +4; } +#else + (void)fdoe; (void)brse; // To avoid compiler warnings #endif /* if the bit-rates are equal return 1*/ return 0; diff --git a/Sources/CANAPI/can_btr.h b/Sources/CANAPI/can_btr.h index c318bdd..43c9ea6 100644 --- a/Sources/CANAPI/can_btr.h +++ b/Sources/CANAPI/can_btr.h @@ -2,13 +2,13 @@ /* * CAN Interface API, Version 3 (Bit-rate Conversion) * - * Copyright (c) 2017-2023 Uwe Vogt, UV Software, Berlin (info@uv-software.com) + * Copyright (c) 2017-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) * All rights reserved. * * This file is part of CAN API V3. * - * CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License and - * under the GNU General Public License v3.0 (or any later version). + * CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License + * and under the GNU General Public License v3.0 (or any later version). * You can choose between one of them if you use this file. * * BSD 2-Clause "Simplified" License: @@ -43,15 +43,15 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with CAN API V3. If not, see . + * along with CAN API V3. If not, see . */ /** @file can_btr.h * * @brief CAN API V3 for generic CAN Interfaces (Bit-rate Conversion) * - * @author $Author: haumea $ + * @author $Author: eris $ * - * @version $Rev: 1096 $ + * @version $Rev: 1270 $ * * @defgroup can_btr CAN Bit-rate Conversion * @{ diff --git a/Sources/CANAPI/can_msg.c b/Sources/CANAPI/can_msg.c index 73d03a6..0a785d7 100644 --- a/Sources/CANAPI/can_msg.c +++ b/Sources/CANAPI/can_msg.c @@ -2,13 +2,13 @@ /* * CAN Interface API, Version 3 (Message Formatter) * - * Copyright (c) 2019-2023 Uwe Vogt, UV Software, Berlin (info@uv-software.com) + * Copyright (c) 2019-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) * All rights reserved. * * This file is part of CAN API V3. * - * CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License and - * under the GNU General Public License v3.0 (or any later version). + * CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License + * and under the GNU General Public License v3.0 (or any later version). * You can choose between one of them if you use this file. * * BSD 2-Clause "Simplified" License: @@ -43,15 +43,15 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with CAN API V3. If not, see . + * along with CAN API V3. If not, see . */ /** @file can_msg.c * * @brief CAN Message Formatter * - * @author $Author: makemake $ + * @author $Author: eris $ * - * @version $Rev: 1187 $ + * @version $Rev: 1270 $ * * @addtogroup can_msg * @{ diff --git a/Sources/CANAPI/can_msg.h b/Sources/CANAPI/can_msg.h index 23d118c..2f5eae9 100644 --- a/Sources/CANAPI/can_msg.h +++ b/Sources/CANAPI/can_msg.h @@ -2,13 +2,13 @@ /* * CAN Interface API, Version 3 (Message Formatter) * - * Copyright (c) 2019-2022 Uwe Vogt, UV Software, Berlin (info@uv-software.com) + * Copyright (c) 2019-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) * All rights reserved. * * This file is part of CAN API V3. * - * CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License and - * under the GNU General Public License v3.0 (or any later version). + * CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License + * and under the GNU General Public License v3.0 (or any later version). * You can choose between one of them if you use this file. * * BSD 2-Clause "Simplified" License: @@ -43,15 +43,15 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with CAN API V3. If not, see . + * along with CAN API V3. If not, see . */ /** @file can_msg.h * * @brief CAN Message Formatter * - * @author $Author: haumea $ + * @author $Author: eris $ * - * @version $Rev: 1044 $ + * @version $Rev: 1270 $ * * @defgroup can_msg CAN Message Formatter * @{ diff --git a/Sources/Driver/TouCAN_Driver.c b/Sources/Driver/TouCAN_Driver.c index 94c3ada..4f2c382 100644 --- a/Sources/Driver/TouCAN_Driver.c +++ b/Sources/Driver/TouCAN_Driver.c @@ -1,11 +1,37 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* SPDX-License-Identifier: BSD-2-Clause OR GPL-3.0-or-later */ /* * TouCAN - macOS User-Space Driver for Rusoku TouCAN USB Adapters * - * Copyright (C) 2021 Uwe Vogt, UV Software, Berlin (info@mac-can.com) + * Copyright (c) 2021-2024 Uwe Vogt, UV Software, Berlin (info@mac-can.com) + * All rights reserved. * * This file is part of MacCAN-TouCAN. * + * MacCAN-TouCAN is dual-licensed under the BSD 2-Clause "Simplified" License + * and under the GNU General Public License v3.0 (or any later version). You can + * choose between one of them if you use MacCAN-TouCAN in whole or in part. + * + * BSD 2-Clause "Simplified" License: + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * MacCAN-TouCAN IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF MacCAN-TouCAN, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * GNU General Public License v3.0 or later: * MacCAN-TouCAN is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or @@ -246,6 +272,60 @@ CANUSB_Return_t TouCAN_GetBusStatus(TouCAN_Device_t *device, TouCAN_Status_t *st return retVal; } +CANUSB_Return_t TouCAN_SetStdFilter(TouCAN_Device_t *device, uint32_t code, uint32_t mask) { + CANUSB_Return_t retVal = CANUSB_ERROR_FATAL; + + /* sanity check */ + if (!device) + return CANUSB_ERROR_NULLPTR; + if (!device->configured) + return CANUSB_ERROR_NOTINIT; + + /* set standard acceptance filter */ + switch (device->productId) { + case TOUCAN_USB_PRODUCT_ID: + retVal = TouCAN_USB_SetStdFilter(device, code, mask); + break; + } + return retVal; +} + +CANUSB_Return_t TouCAN_SetXtdFilter(TouCAN_Device_t *device, uint32_t code, uint32_t mask) { + CANUSB_Return_t retVal = CANUSB_ERROR_FATAL; + + /* sanity check */ + if (!device) + return CANUSB_ERROR_NULLPTR; + if (!device->configured) + return CANUSB_ERROR_NOTINIT; + + /* set extended acceptance filter */ + switch (device->productId) { + case TOUCAN_USB_PRODUCT_ID: + retVal = TouCAN_USB_SetXtdFilter(device, code, mask); + break; + } + return retVal; +} + +CANUSB_Return_t TouCAN_ResetFilters(TouCAN_Device_t *device) { + CANUSB_Return_t retVal = CANUSB_ERROR_FATAL; + + /* sanity check */ + if (!device) + return CANUSB_ERROR_NULLPTR; + if (!device->configured) + return CANUSB_ERROR_NOTINIT; + + /* reset all acceptance filters */ + switch (device->productId) { + case TOUCAN_USB_PRODUCT_ID: + retVal = TouCAN_USB_ResetFilters(device); + break; + } + return retVal; +} + bool TouCAN_Index2Bitrate(TouCAN_Device_t *device, int32_t index, TouCAN_Bitrate_t *bitrate) { bool retVal = false; diff --git a/Sources/Driver/TouCAN_Driver.h b/Sources/Driver/TouCAN_Driver.h index 2907896..f824f58 100644 --- a/Sources/Driver/TouCAN_Driver.h +++ b/Sources/Driver/TouCAN_Driver.h @@ -1,11 +1,37 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* SPDX-License-Identifier: BSD-2-Clause OR GPL-3.0-or-later */ /* - * TouCAN - macOS User-Space Driver for Rusoku TouCAN USB Interfaces + * TouCAN - macOS User-Space Driver for Rusoku TouCAN USB Adapters * - * Copyright (C) 2021 Uwe Vogt, UV Software, Berlin (info@mac-can.com) + * Copyright (c) 2021-2024 Uwe Vogt, UV Software, Berlin (info@mac-can.com) + * All rights reserved. * * This file is part of MacCAN-TouCAN. * + * MacCAN-TouCAN is dual-licensed under the BSD 2-Clause "Simplified" License + * and under the GNU General Public License v3.0 (or any later version). You can + * choose between one of them if you use MacCAN-TouCAN in whole or in part. + * + * BSD 2-Clause "Simplified" License: + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * MacCAN-TouCAN IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF MacCAN-TouCAN, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * GNU General Public License v3.0 or later: * MacCAN-TouCAN is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or @@ -48,6 +74,10 @@ extern CANUSB_Return_t TouCAN_WriteMessage(TouCAN_Device_t *device, const TouCAN extern CANUSB_Return_t TouCAN_ReadMessage(TouCAN_Device_t *device, TouCAN_CanMessage_t *message, uint16_t timeout); extern CANUSB_Return_t TouCAN_GetBusStatus(TouCAN_Device_t *device, TouCAN_Status_t *status); +extern CANUSB_Return_t TouCAN_SetStdFilter(TouCAN_Device_t *device, uint32_t code, uint32_t mask); +extern CANUSB_Return_t TouCAN_SetXtdFilter(TouCAN_Device_t *device, uint32_t code, uint32_t mask); +extern CANUSB_Return_t TouCAN_ResetFilters(TouCAN_Device_t *device); + extern bool TouCAN_Index2Bitrate(TouCAN_Device_t *device, int32_t index, TouCAN_Bitrate_t *bitrate); #ifdef __cplusplus diff --git a/Sources/Driver/TouCAN_USB.c b/Sources/Driver/TouCAN_USB.c deleted file mode 100644 index 86a224c..0000000 --- a/Sources/Driver/TouCAN_USB.c +++ /dev/null @@ -1,598 +0,0 @@ -/* - * TouCAN - macOS User-Space Driver for Rusoku TouCAN USB Adapters - * - * Copyright (C) 2020-2022 Uwe Vogt, UV Software, Berlin (info@mac-can.com) - * - * The following source code was copied from Rusoku's CANAL-DLL for Windows - * and modified to run under macOS 10.13 and later. - * - * source https://github.com/rusoku/CANAL-DLL/blob/master/CTouCANobjCmdMsg.cpp - * commit 0e7510019561157ac2ee4199ddbf39652b146451 - */ -/* - * CANAL interface DLL for RUSOKU technologies for TouCAN, TouCAN Marine, TouCAN Duo USB to CAN bus converter - * - * Copyright (C) 2000-2008 Ake Hedman, eurosource, - * Copyright (C) 2020 Gediminas Simanskis (gediminas@rusoku.com) - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published - * by the Free Software Foundation; version 3.0 of the License. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. - * - */ -#include "TouCAN_USB.h" - -#include "MacCAN_IOUsbKit.h" - -#include -#include -#include -#include - -////////////////////////////////////////////////////////////////////// -// TouCAN init -// - -int TouCAN_init(CANUSB_Handle_t handle, UInt16 brp, UInt8 tseg1, UInt8 tseg2, UInt8 sjw, UInt32 flags) { - CANUSB_SetupPacket_t SetupPacket; - CANUSB_Return_t retVal; - UInt8 res; - UInt8 data[9]; - bzero(data, 9); - - SetupPacket.RequestType = USB_HOST_TO_DEVICE | USB_REQ_TYPE_CLASS | USB_REQ_RECIPIENT_INTERFACE; - SetupPacket.Request = TouCAN_CAN_INTERFACE_INIT; - SetupPacket.Value = 0; - SetupPacket.Index = 0; - SetupPacket.Length = 9; - - // tseg1 - data[0] = tseg1; - // tseg2 - data[1] = tseg2; - // sjw - data[2] = sjw; - // Brp - - data[3] = (UInt8) ((brp >> 8) & 0xFF); - data[4] = (UInt8) (brp & 0xFF); - - // flags - data[5] = (UInt8) ((flags >> 24) & 0xFF); - data[6] = (UInt8) ((flags >> 16) & 0xFF); - data[7] = (UInt8) ((flags >> 8) & 0xFF); - data[8] = (UInt8) (flags & 0xFF); - - // TouCAN_CAN_INTERFACE_INIT - retVal = CANUSB_DeviceRequest(handle, SetupPacket, (void *)data, 9, NULL); - if (retVal < 0) - return (int)retVal; - - retVal = TouCAN_get_last_error_code(handle, &res); - if (retVal < 0) - return (int)retVal; - - if (res != TouCAN_RETVAL_OK) - return (int)TOUCAN_ERROR_OFFSET - (int)res; - - return (int)TOUCAN_ERROR_SUCCESS; -} - -////////////////////////////////////////////////////////////////////// -// TouCAN deinit -// - -int TouCAN_deinit(CANUSB_Handle_t handle) { - CANUSB_SetupPacket_t SetupPacket; - CANUSB_Return_t retVal; - UInt8 res; - - SetupPacket.RequestType = USB_HOST_TO_DEVICE | USB_REQ_TYPE_CLASS | USB_REQ_RECIPIENT_INTERFACE; - SetupPacket.Request = TouCAN_CAN_INTERFACE_DEINIT; - SetupPacket.Value = 0; - SetupPacket.Index = 0; - SetupPacket.Length = 0; - - // TouCAN_CAN_INTERFACE_DEINIT - retVal = CANUSB_DeviceRequest(handle, SetupPacket, NULL, 0, NULL); - if (retVal < 0) - return (int)retVal; - - retVal = TouCAN_get_last_error_code(handle, &res); - if (retVal < 0) - return (int)retVal; - - if (res != TouCAN_RETVAL_OK) - return (int)TOUCAN_ERROR_OFFSET - (int)res; - - return (int)TOUCAN_ERROR_SUCCESS; -} - -////////////////////////////////////////////////////////////////////// -// TouCAN start -// - -int TouCAN_start(CANUSB_Handle_t handle) { - CANUSB_SetupPacket_t SetupPacket; - CANUSB_Return_t retVal; - UInt8 res; - - SetupPacket.RequestType = USB_HOST_TO_DEVICE | USB_REQ_TYPE_CLASS | USB_REQ_RECIPIENT_INTERFACE; - SetupPacket.Request = TouCAN_CAN_INTERFACE_START; - SetupPacket.Value = 0; - SetupPacket.Index = 0; - SetupPacket.Length = 0; - - // TouCAN_CAN_INTERFACE_START - retVal = CANUSB_DeviceRequest(handle, SetupPacket, NULL, 0, NULL); - if (retVal < 0) - return (int)retVal; - - retVal = TouCAN_get_last_error_code(handle, &res); - if (retVal < 0) - return (int)retVal; - - if (res != TouCAN_RETVAL_OK) - return (int)TOUCAN_ERROR_OFFSET - (int)res; - - return (int)TOUCAN_ERROR_SUCCESS; -} - -////////////////////////////////////////////////////////////////////// -// TouCAN stop -// - -int TouCAN_stop(CANUSB_Handle_t handle) { - CANUSB_SetupPacket_t SetupPacket; - CANUSB_Return_t retVal; - UInt8 res; - - SetupPacket.RequestType = USB_HOST_TO_DEVICE | USB_REQ_TYPE_CLASS | USB_REQ_RECIPIENT_INTERFACE; - SetupPacket.Request = TouCAN_CAN_INTERFACE_STOP; - SetupPacket.Value = 0; - SetupPacket.Index = 0; - SetupPacket.Length = 0; - - // TouCAN_CAN_INTERFACE_STOP - retVal = CANUSB_DeviceRequest(handle, SetupPacket, NULL, 0, NULL); - if (retVal < 0) - return (int)retVal; - - retVal = TouCAN_get_last_error_code(handle, &res); - if (retVal < 0) - return (int)retVal; - - if (res != TouCAN_RETVAL_OK) - return (int)TOUCAN_ERROR_OFFSET - (int)res; - - return (int)TOUCAN_ERROR_SUCCESS; -} - -////////////////////////////////////////////////////////////////////// -// TouCAN HAL get last error -// - -int TouCAN_get_last_error_code(CANUSB_Handle_t handle, UInt8 *res) { - CANUSB_SetupPacket_t SetupPacket; - CANUSB_Return_t retVal; - UInt32 wLenDone; - UInt8 LastErrorCode; - - SetupPacket.RequestType = USB_DEVICE_TO_HOST | USB_REQ_TYPE_CLASS | USB_REQ_RECIPIENT_INTERFACE; - SetupPacket.Request = TouCAN_GET_LAST_ERROR_CODE; - SetupPacket.Value = 0; - SetupPacket.Index = 0; - SetupPacket.Length = 1; - - retVal = CANUSB_DeviceRequest(handle, SetupPacket, (void *)&LastErrorCode, 1, &wLenDone); - if (retVal < 0) - return (int)retVal; - - if ((wLenDone != 1) && (LastErrorCode != HAL_OK)) // FIXME: OR? - return (int)TOUCAN_ERROR_OFFSET; - - if (res) - *res = LastErrorCode; - - return (int)TOUCAN_ERROR_SUCCESS; -} - -/////////////////////////////////////////////////////// -// TouCAN get CAN interface ERROR: hcan->ErrorCode; -// - -int TouCAN_get_interface_error_code(CANUSB_Handle_t handle, UInt32 *ErrorCode) { - CANUSB_SetupPacket_t SetupPacket; - CANUSB_Return_t retVal; - UInt8 buf[4]; - UInt8 res; - - SetupPacket.RequestType = USB_DEVICE_TO_HOST | USB_REQ_TYPE_CLASS | USB_REQ_RECIPIENT_INTERFACE; - SetupPacket.Request = TouCAN_GET_CAN_INTERFACE_ERROR_CODE; - SetupPacket.Value = 0; - SetupPacket.Index = 0; - SetupPacket.Length = 4; - - retVal = CANUSB_DeviceRequest(handle, SetupPacket, (void *)buf, 4, NULL); - if (retVal < 0) - return (int)retVal; - - retVal = TouCAN_get_last_error_code(handle, &res); - if (retVal < 0) - return (int)retVal; - - if (res != TouCAN_RETVAL_OK) - return (int)TOUCAN_ERROR_OFFSET - (int)res; - - if (ErrorCode) { - *ErrorCode = (UInt32)buf[0] << 24; - *ErrorCode |= (UInt32)buf[1] << 16; - *ErrorCode |= (UInt32)buf[2] << 8; - *ErrorCode |= (UInt32)buf[3]; - } - return (int)TOUCAN_ERROR_SUCCESS; -} - -/////////////////////////////////////////////////////// -// TouCAN TouCAN_CLEAR_CAN_INTERFACE_ERROR_CODE: hcan->ErrorCode; -// - -int TouCAN_clear_interface_error_code(CANUSB_Handle_t handle) { - CANUSB_SetupPacket_t SetupPacket; - CANUSB_Return_t retVal; - UInt8 res; - - SetupPacket.RequestType = USB_HOST_TO_DEVICE | USB_REQ_TYPE_CLASS | USB_REQ_RECIPIENT_INTERFACE; - SetupPacket.Request = TouCAN_CLEAR_CAN_INTERFACE_ERROR_CODE; - SetupPacket.Value = 0; - SetupPacket.Index = 0; - SetupPacket.Length = 0; - - retVal = CANUSB_DeviceRequest(handle, SetupPacket, NULL, 0, NULL); - if (retVal < 0) - return (int)retVal; - - retVal = TouCAN_get_last_error_code(handle, &res); - if (retVal < 0) - return (int)retVal; - - if (res != TouCAN_RETVAL_OK) - return (int)TOUCAN_ERROR_OFFSET - (int)res; - - return (int)TOUCAN_ERROR_SUCCESS; -} - -////////////////////////////////////////////////////////////////////// -// TouCAN TouCAN_GET_CAN_INTERFACE_STATE hcan->State; -// - -int TouCAN_get_interface_state(CANUSB_Handle_t handle, UInt8 *state) { - CANUSB_SetupPacket_t SetupPacket; - CANUSB_Return_t retVal; - UInt8 buf[1]; - UInt8 res; - - SetupPacket.RequestType = USB_DEVICE_TO_HOST | USB_REQ_TYPE_CLASS | USB_REQ_RECIPIENT_INTERFACE; - SetupPacket.Request = TouCAN_GET_CAN_INTERFACE_STATE; - SetupPacket.Value = 0; - SetupPacket.Index = 0; - SetupPacket.Length = 1; - - retVal = CANUSB_DeviceRequest(handle, SetupPacket, (void *)buf, 1, NULL); - if (retVal < 0) - return (int)retVal; - - retVal = TouCAN_get_last_error_code(handle, &res); - if (retVal < 0) - return (int)retVal; - - if (res != TouCAN_RETVAL_OK) - return (int)TOUCAN_ERROR_OFFSET - (int)res; - - if (state) { - *state = buf[0]; - } - return (int)TOUCAN_ERROR_SUCCESS; -} - -#if (OPTION_TOUCAN_CANAL != 0) -////////////////////////////////////////////////////////////////////// -// TouCAN TouCAN_get_statistics VSCP -// - -int TouCAN_get_statistics(CANUSB_Handle_t handle, PCANALSTATISTICS statistics) { - return (int)TOUCAN_ERROR_OFFSET; -} - -////////////////////////////////////////////////////////////////////// -// TouCAN_clear_statistics VSCP -// - -int TouCAN_clear_statistics(CANUSB_Handle_t handle) { - return (int)TOUCAN_ERROR_OFFSET; -} - -////////////////////////////////////////////////////////////////////// -// TouCAN_get_status VSCP -// - -int TouCAN_get_canal_status(CANUSB_Handle_t handle, canalStatus *status) { - return (int)TOUCAN_ERROR_OFFSET; -} -#endif - -////////////////////////////////////////////////////////////////////// -// TouCAN_get_hardware_version -// - -int TouCAN_get_hardware_version(CANUSB_Handle_t handle, UInt32 *ver) { - CANUSB_SetupPacket_t SetupPacket; - CANUSB_Return_t retVal; - UInt8 buf[4]; - UInt8 res; - - SetupPacket.RequestType = USB_DEVICE_TO_HOST | USB_REQ_TYPE_CLASS | USB_REQ_RECIPIENT_INTERFACE; - SetupPacket.Request = TouCAN_GET_HARDWARE_VERSION; - SetupPacket.Value = 0; - SetupPacket.Index = 0; - SetupPacket.Length = 4; - - retVal = CANUSB_DeviceRequest(handle, SetupPacket, (void *)buf, 4, NULL); - if (retVal < 0) - return (int)retVal; - - retVal = TouCAN_get_last_error_code(handle, &res); - if (retVal < 0) - return (int)retVal; - - if (res != TouCAN_RETVAL_OK) - return (int)TOUCAN_ERROR_OFFSET - (int)res; - - if (ver) { - *ver = (UInt32)buf[0] << 24; - *ver |= (UInt32)buf[1] << 16; - *ver |= (UInt32)buf[2] << 8; - *ver |= (UInt32)buf[3]; - } - return retVal; -} - -////////////////////////////////////////////////////////////////////// -// TouCAN_get_firmware_version -// -// -int TouCAN_get_firmware_version(CANUSB_Handle_t handle, UInt32 *ver) { - CANUSB_SetupPacket_t SetupPacket; - CANUSB_Return_t retVal; - UInt8 buf[4]; - UInt8 res; - - SetupPacket.RequestType = USB_DEVICE_TO_HOST | USB_REQ_TYPE_CLASS | USB_REQ_RECIPIENT_INTERFACE; - SetupPacket.Request = TouCAN_GET_FIRMWARE_VERSION; - SetupPacket.Value = 0; - SetupPacket.Index = 0; - SetupPacket.Length = 4; - - retVal = CANUSB_DeviceRequest(handle, SetupPacket, (void *)buf, 4, NULL); - if (retVal < 0) - return (int)retVal; - - retVal = TouCAN_get_last_error_code(handle, &res); - if (retVal < 0) - return (int)retVal; - - if (res != TouCAN_RETVAL_OK) - return (int)TOUCAN_ERROR_OFFSET - (int)res; - - if (ver) { - *ver = (UInt32)buf[0] << 24; - *ver |= (UInt32)buf[1] << 16; - *ver |= (UInt32)buf[2] << 8; - *ver |= (UInt32)buf[3]; - } - return retVal; -} - -////////////////////////////////////////////////////////////////////// -// TouCAN_get_bootloader_version -// -// -int TouCAN_get_bootloader_version(CANUSB_Handle_t handle, UInt32 *ver) { - CANUSB_SetupPacket_t SetupPacket; - CANUSB_Return_t retVal; - UInt8 buf[4]; - UInt8 res; - - SetupPacket.RequestType = USB_DEVICE_TO_HOST | USB_REQ_TYPE_CLASS | USB_REQ_RECIPIENT_INTERFACE; - SetupPacket.Request = TouCAN_GET_BOOTLOADER_VERSION; - SetupPacket.Value = 0; - SetupPacket.Index = 0; - SetupPacket.Length = 4; - - retVal = CANUSB_DeviceRequest(handle, SetupPacket, (void *)buf, 4, NULL); - if (retVal < 0) - return (int)retVal; - - retVal = TouCAN_get_last_error_code(handle, &res); - if (retVal < 0) - return (int)retVal; - - if (res != TouCAN_RETVAL_OK) - return (int)TOUCAN_ERROR_OFFSET - (int)res; - - if (ver) { - *ver = (UInt32)buf[0] << 24; - *ver |= (UInt32)buf[1] << 16; - *ver |= (UInt32)buf[2] << 8; - *ver |= (UInt32)buf[3]; - } - return retVal; -} - -////////////////////////////////////////////////////////////////////// -// TouCAN_get_serial_number -// -// -int TouCAN_get_serial_number(CANUSB_Handle_t handle, UInt32 *ver) { - CANUSB_SetupPacket_t SetupPacket; - CANUSB_Return_t retVal; - UInt8 buf[4]; - UInt8 res; - - SetupPacket.RequestType = USB_DEVICE_TO_HOST | USB_REQ_TYPE_CLASS | USB_REQ_RECIPIENT_INTERFACE; - SetupPacket.Request = TouCAN_GET_SERIAL_NUMBER; - SetupPacket.Value = 0; - SetupPacket.Index = 0; - SetupPacket.Length = 4; - - retVal = CANUSB_DeviceRequest(handle, SetupPacket, (void *)buf, 4, NULL); - if (retVal < 0) - return (int)retVal; - - retVal = TouCAN_get_last_error_code(handle, &res); - if (retVal < 0) - return (int)retVal; - - if (res != TouCAN_RETVAL_OK) - return (int)TOUCAN_ERROR_OFFSET - (int)res; - - if (ver) { - *ver = (UInt32)buf[0] << 24; - *ver |= (UInt32)buf[1] << 16; - *ver |= (UInt32)buf[2] << 8; - *ver |= (UInt32)buf[3]; - } - return retVal; - -} - -////////////////////////////////////////////////////////////////////// -// TouCAN_get_vid_pid -// -// -int TouCAN_get_vid_pid(CANUSB_Handle_t handle, UInt32 *ver) { - CANUSB_SetupPacket_t SetupPacket; - CANUSB_Return_t retVal; - UInt8 buf[4]; - UInt8 res; - - SetupPacket.RequestType = USB_DEVICE_TO_HOST | USB_REQ_TYPE_CLASS | USB_REQ_RECIPIENT_INTERFACE; - SetupPacket.Request = TouCAN_GET_VID_PID; - SetupPacket.Value = 0; - SetupPacket.Index = 0; - SetupPacket.Length = 4; - - retVal = CANUSB_DeviceRequest(handle, SetupPacket, (void *)buf, 4, NULL); - if (retVal < 0) - return (int)retVal; - - retVal = TouCAN_get_last_error_code(handle, &res); - if (retVal < 0) - return (int)retVal; - - if (res != TouCAN_RETVAL_OK) - return (int)TOUCAN_ERROR_OFFSET - (int)res; - - if (ver) { - *ver = (UInt32)buf[0] << 24; - *ver |= (UInt32)buf[1] << 16; - *ver |= (UInt32)buf[2] << 8; - *ver |= (UInt32)buf[3]; - } - return retVal; -} - -////////////////////////////////////////////////////////////////////// -// TouCAN_get_device_id -// -// -int TouCAN_get_device_id(CANUSB_Handle_t handle, UInt32 *ver) { - CANUSB_SetupPacket_t SetupPacket; - CANUSB_Return_t retVal; - UInt8 buf[4]; - UInt8 res; - - SetupPacket.RequestType = USB_DEVICE_TO_HOST | USB_REQ_TYPE_CLASS | USB_REQ_RECIPIENT_INTERFACE; - SetupPacket.Request = TouCAN_GET_DEVICE_ID; - SetupPacket.Value = 0; - SetupPacket.Index = 0; - SetupPacket.Length = 4; - - retVal = CANUSB_DeviceRequest(handle, SetupPacket, (void *)buf, 4, NULL); - if (retVal < 0) - return (int)retVal; - - retVal = TouCAN_get_last_error_code(handle, &res); - if (retVal < 0) - return (int)retVal; - - if (res != TouCAN_RETVAL_OK) - return (int)TOUCAN_ERROR_OFFSET - (int)res; - - if (ver) { - *ver = (UInt32)buf[0] << 24; - *ver |= (UInt32)buf[1] << 16; - *ver |= (UInt32)buf[2] << 8; - *ver |= (UInt32)buf[3]; - } - return retVal; -} - -////////////////////////////////////////////////////////////////////// -// TouCAN_get_vendor -// -// -int TouCAN_get_vendor(CANUSB_Handle_t handle, unsigned int size, char *str) { - CANUSB_SetupPacket_t SetupPacket; - CANUSB_Return_t retVal; - UInt8 buf[32]; - UInt8 res; - - SetupPacket.RequestType = USB_DEVICE_TO_HOST | USB_REQ_TYPE_CLASS | USB_REQ_RECIPIENT_INTERFACE; - SetupPacket.Request = TouCAN_GET_VENDOR; - SetupPacket.Value = 0; - SetupPacket.Index = 0; - SetupPacket.Length = 32; // FIXME: 4(?) - - retVal = CANUSB_DeviceRequest(handle, SetupPacket, (void *)buf, 32, NULL); - if (retVal < 0) - return (int)retVal; - - retVal = TouCAN_get_last_error_code(handle, &res); - if (retVal < 0) - return (int)retVal; - - if (res != TouCAN_RETVAL_OK) - return (int)TOUCAN_ERROR_OFFSET - (int)res; - - if (str) - strncpy(str, (const char *)buf, (size_t)size); - - return retVal; - -} - -//int TouCAN_get_interface_transmit_delay(CANUSB_Handle_t handle, UInt8 channel,UInt32 *delay) { -// return (int)TOUCAN_ERROR_OFFSET; -//} - -//int TouCAN_set_interface_transmit_delay(CANUSB_Handle_t handle, UInt8 channel,UInt32 *delay) { -// return (int)TOUCAN_ERROR_OFFSET; -//} - -///////////////////////////////////////// LIST, MASK //////////////////////////////////////////// -//int TouCAN_set_filter_std_list_mask(CANUSB_Handle_t handle, Filter_Type_TypeDef type, UInt32 list, UInt32 mask) { -// return (int)TOUCAN_ERROR_OFFSET; -//} - -//int TouCAN_set_filter_ext_list_mask(CANUSB_Handle_t handle, Filter_Type_TypeDef type, UInt32 list, UInt32 mask) { -// return (int)TOUCAN_ERROR_OFFSET; -//} diff --git a/Sources/Driver/TouCAN_USB.h b/Sources/Driver/TouCAN_USB.h deleted file mode 100644 index 0b09056..0000000 --- a/Sources/Driver/TouCAN_USB.h +++ /dev/null @@ -1,63 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * TouCAN - macOS User-Space Driver for Rusoku TouCAN USB Interfaces - * - * Copyright (C) 2020-2021 Uwe Vogt, UV Software, Berlin (info@mac-can.com) - * - * This file is part of MacCAN-TouCAN. - * - * MacCAN-TouCAN is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * MacCAN-TouCAN is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with MacCAN-TouCAN. If not, see . - */ -#ifndef TOUCAN_USB_H_INCLUDED -#define TOUCAN_USB_H_INCLUDED - -#include "TouCAN_USB_Common.h" - -typedef int TouCAN_Handle_t; - -#ifdef __cplusplus -extern "C" { -#endif - -extern int TouCAN_init(TouCAN_Handle_t handle, uint16_t brp, uint8_t tseg1, uint8_t tseg2, uint8_t sjw, uint32_t flags); -extern int TouCAN_deinit(TouCAN_Handle_t handle); -extern int TouCAN_start(TouCAN_Handle_t handle); -extern int TouCAN_stop(TouCAN_Handle_t handle); - -extern int TouCAN_get_last_error_code(TouCAN_Handle_t handle, uint8_t *res); -extern int TouCAN_get_interface_error_code(TouCAN_Handle_t handle, uint32_t *ErrorCode); -extern int TouCAN_clear_interface_error_code(TouCAN_Handle_t handle); -extern int TouCAN_get_interface_state(TouCAN_Handle_t handle, uint8_t *state); -#if (OPTION_TOUCAN_CANAL != 0) -extern int TouCAN_get_statistics(TouCAN_Handle_t handle, PCANALSTATISTICS statistics); -extern int TouCAN_clear_statistics(TouCAN_Handle_t handle); -extern int TouCAN_get_canal_status(TouCAN_Handle_t handle, canalStatus *status); -#endif -extern int TouCAN_get_hardware_version(TouCAN_Handle_t handle, uint32_t *ver); -extern int TouCAN_get_firmware_version(TouCAN_Handle_t handle, uint32_t *ver); -extern int TouCAN_get_bootloader_version(TouCAN_Handle_t handle, uint32_t *ver); -extern int TouCAN_get_serial_number(TouCAN_Handle_t handle, uint32_t *ver); -extern int TouCAN_get_vid_pid(TouCAN_Handle_t handle, uint32_t *ver); -extern int TouCAN_get_device_id(TouCAN_Handle_t handle, uint32_t *ver); -extern int TouCAN_get_vendor(TouCAN_Handle_t handle, unsigned int size, char *str); -extern int TouCAN_get_interface_transmit_delay(TouCAN_Handle_t handle, uint8_t channel,uint32_t *delay); -extern int TouCAN_set_interface_transmit_delay(TouCAN_Handle_t handle, uint8_t channel,uint32_t *delay); - -extern int TouCAN_set_filter_std_list_mask(TouCAN_Handle_t handle, Filter_Type_TypeDef type, uint32_t list, uint32_t mask); -extern int TouCAN_set_filter_ext_list_mask(TouCAN_Handle_t handle, Filter_Type_TypeDef type, uint32_t list, uint32_t mask); - -#ifdef __cplusplus -} -#endif -#endif /* TOUCAN_USB_H_INCLUDED */ diff --git a/Sources/Driver/TouCAN_USB_CmdMsg.c b/Sources/Driver/TouCAN_USB_CmdMsg.c new file mode 100644 index 0000000..284e505 --- /dev/null +++ b/Sources/Driver/TouCAN_USB_CmdMsg.c @@ -0,0 +1,918 @@ +/* SPDX-License-Identifier: BSD-2-Clause OR GPL-3.0-or-later */ +/* + * TouCAN - macOS User-Space Driver for Rusoku TouCAN USB Adapters + * + * Copyright (c) 2024 Uwe Vogt, UV Software, Berlin (info@mac-can.com) + * All rights reserved. + * + * This file is part of MacCAN-TouCAN. + * + * MacCAN-TouCAN is dual-licensed under the BSD 2-Clause "Simplified" License + * and under the GNU General Public License v3.0 (or any later version). You can + * choose between one of them if you use MacCAN-TouCAN in whole or in part. + * + * BSD 2-Clause "Simplified" License: + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * MacCAN-TouCAN IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF MacCAN-TouCAN, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * GNU General Public License v3.0 or later: + * MacCAN-TouCAN is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * MacCAN-TouCAN is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with MacCAN-TouCAN. If not, see . + */ +#include "TouCAN_USB_CmdMsg.h" + +#include "MacCAN_IOUsbKit.h" + +#include +#include +#include +#include + +/* TouCAN USB commands for control transfer + */ +#define CMD_RESET 0x00U +#define CMD_CAN_INTERFACE_INIT 0x01U +#define CMD_CAN_INTERFACE_DEINIT 0x02U +#define CMD_CAN_INTERFACE_START 0x03U +#define CMD_CAN_INTERFACE_STOP 0x04U +#define CMD_FILTER_STD_ACCEPT_ALL 0x05U +#define CMD_FILTER_STD_REJECT_ALL 0x06U +#define CMD_FILTER_EXT_ACCEPT_ALL 0x07U +#define CMD_FILTER_EXT_REJECT_ALL 0x08U +#define CMD_SET_FILTER_STD_LIST_MASK 0x09U +#define CMD_SET_FILTER_EXT_LIST_MASK 0x0AU +#define CMD_GET_FILTER_STD_LIST_MASK 0x0BU +#define CMD_GET_FILTER_EXT_LIST_MASK 0x0CU +#define CMD_GET_CAN_ERROR_STATUS 0x0DU +#define CMD_CLEAR_CAN_ERROR_STATUS 0x0DU +#define CMD_GET_STATISTICS 0x0EU +#define CMD_CLEAR_STATISTICS 0x0FU +#define CMD_GET_HARDWARE_VERSION 0x10U +#define CMD_GET_FIRMWARE_VERSION 0x11U +#define CMD_GET_BOOTLOADER_VERSION 0x12U +#define CMD_GET_SERIAL_NUMBER 0x13U +#define CMD_SET_SERIAL_NUMBER 0x14U +#define CMD_RESET_SERIAL_NUMBER 0x15U +#define CMD_GET_VID_PID 0x16U +#define CMD_GET_DEVICE_ID 0x17U +#define CMD_GET_VENDOR 0x18U +#define CMD_GET_LAST_ERROR_CODE 0x20U +#define CMD_CLEAR_LAST_ERROR_CODE 0x21U +#define CMD_GET_CAN_INTERFACE_STATE 0x22U +#define CMD_CLEAR_CAN_INTERFACE_STATE 0x23U +#define CMD_GET_CAN_INTERFACE_ERROR_CODE 0x24U +#define CMD_CLEAR_CAN_INTERFACE_ERROR_CODE 0x25U +#define CMD_SET_CAN_INTERFACE_DELAY 0x26U +#define CMD_GET_CAN_INTERFACE_DELAY 0x27U + +#define LEN_RESET 0U +#define LEN_CAN_INTERFACE_INIT 9U +#define LEN_CAN_INTERFACE_DEINIT 0U +#define LEN_CAN_INTERFACE_START 0U +#define LEN_CAN_INTERFACE_STOP 0U +#define LEN_FILTER_STD_ACCEPT_ALL 0U +#define LEN_FILTER_STD_REJECT_ALL 0U +#define LEN_FILTER_EXT_ACCEPT_ALL 0U +#define LEN_FILTER_EXT_REJECT_ALL 0U +#define LEN_SET_FILTER_STD_LIST_MASK 8U +#define LEN_SET_FILTER_EXT_LIST_MASK 8U +#define LEN_GET_FILTER_STD_LIST_MASK 8U +#define LEN_GET_FILTER_EXT_LIST_MASK 8U +#define LEN_GET_CAN_ERROR_STATUS 4U +#define LEN_CLEAR_CAN_ERROR_STATUS 0U +#define LEN_GET_STATISTICS 28U +#define LEN_CLEAR_STATISTICS 0U +#define LEN_GET_HARDWARE_VERSION 4U +#define LEN_GET_FIRMWARE_VERSION 4U +#define LEN_GET_BOOTLOADER_VERSION 4U +#define LEN_GET_SERIAL_NUMBER 4U +#define LEN_SET_SERIAL_NUMBER 4U +#define LEN_RESET_SERIAL_NUMBER 4U +#define LEN_GET_VID_PID 4U +#define LEN_GET_DEVICE_ID 4U +#define LEN_GET_VENDOR 32U +#define LEN_GET_LAST_ERROR_CODE 1U +#define LEN_CLEAR_LAST_ERROR_CODE 0U +#define LEN_GET_CAN_INTERFACE_STATE 1U +#define LEN_CLEAR_CAN_INTERFACE_STATE 0U +#define LEN_GET_CAN_INTERFACE_ERROR_CODE 4U +#define LEN_CLEAR_CAN_INTERFACE_ERROR_CODE 0U +#define LEN_SET_CAN_INTERFACE_DELAY 4U +#define LEN_GET_CAN_INTERFACE_DELAY 4U + +/* TouCAN init + */ +int TouCAN_USB_CmdInitInterface(TouCAN_Handle_t handle, uint16_t brp, uint8_t tseg1, uint8_t tseg2, uint8_t sjw, uint32_t flags) { + CANUSB_SetupPacket_t SetupPacket; + CANUSB_Return_t retVal; + uint8_t res = TOUCAN_RETVAL_UNKNOWN; + uint8_t data[TOUCAN_USB_CMD_PIPE_SIZE]; + memset(data, 0, TOUCAN_USB_CMD_PIPE_SIZE); + UInt32 Transferred = 0U; + + SetupPacket.RequestType = USBREQ_HOST_TO_DEVICE | USBREQ_TYPE_CLASS | USBREQ_RECIPIENT_INTERFACE; + SetupPacket.Request = CMD_CAN_INTERFACE_INIT; + SetupPacket.Value = 0U; + SetupPacket.Index = 0U; + SetupPacket.Length = 9U; + + // tseg1 + data[0] = tseg1; + // tseg2 + data[1] = tseg2; + // sjw + data[2] = sjw; + // brp + data[3] = (uint8_t)((brp >> 8) & 0xFFU); + data[4] = (uint8_t)(brp & 0xFFU); + // flags + data[5] = (uint8_t)((flags >> 24) & 0xFFU); + data[6] = (uint8_t)((flags >> 16) & 0xFFU); + data[7] = (uint8_t)((flags >> 8) & 0xFFU); + data[8] = (uint8_t)(flags & 0xFFU); + + // TouCAN_CAN_INTERFACE_INIT + retVal = CANUSB_DeviceRequest(handle, SetupPacket, (void*)data, (UInt16)LEN_CAN_INTERFACE_INIT, &Transferred); + if (retVal < 0) + return (int)retVal; + + retVal = TouCAN_USB_CmdGetLastErrorCode(handle, &res); + if (retVal < 0) + return (int)retVal; + + if (res != TOUCAN_RETVAL_OK) + return (int)TOUCAN_ERROR_OFFSET - (int)res; + else if (Transferred != LEN_CAN_INTERFACE_INIT) + return (int)TOUCAN_ERROR_OFFSET - (int)TOUCAN_RETVAL_UNKNOWN; + + return (int)retVal; +} + +/* TouCAN deinit + */ +int TouCAN_USB_CmdDeinitInterface(TouCAN_Handle_t handle) { + CANUSB_SetupPacket_t SetupPacket; + CANUSB_Return_t retVal; + uint8_t res = TOUCAN_RETVAL_UNKNOWN; + + SetupPacket.RequestType = USBREQ_HOST_TO_DEVICE | USBREQ_TYPE_CLASS | USBREQ_RECIPIENT_INTERFACE; + SetupPacket.Request = CMD_CAN_INTERFACE_DEINIT; + SetupPacket.Value = 0U; + SetupPacket.Index = 0U; + SetupPacket.Length = 0U; + + // TouCAN_CAN_INTERFACE_DEINIT + retVal = CANUSB_DeviceRequest(handle, SetupPacket, NULL, 0U, NULL); + if (retVal < 0) + return (int)retVal; + + retVal = TouCAN_USB_CmdGetLastErrorCode(handle, &res); + if (retVal < 0) + return (int)retVal; + + if (res != TOUCAN_RETVAL_OK) + return (int)TOUCAN_ERROR_OFFSET - (int)res; + + return (int)retVal; +} + +/* TouCAN start + */ +int TouCAN_USB_CmdStartInterface(TouCAN_Handle_t handle) { + CANUSB_SetupPacket_t SetupPacket; + CANUSB_Return_t retVal; + uint8_t res = TOUCAN_RETVAL_UNKNOWN; + + SetupPacket.RequestType = USBREQ_HOST_TO_DEVICE | USBREQ_TYPE_CLASS | USBREQ_RECIPIENT_INTERFACE; + SetupPacket.Request = CMD_CAN_INTERFACE_START; + SetupPacket.Value = 0U; + SetupPacket.Index = 0U; + SetupPacket.Length = 0U; + + // TouCAN_CAN_INTERFACE_START + retVal = CANUSB_DeviceRequest(handle, SetupPacket, NULL, 0U, NULL); + if (retVal < 0) + return (int)retVal; + + retVal = TouCAN_USB_CmdGetLastErrorCode(handle, &res); + if (retVal < 0) + return (int)retVal; + + if (res != TOUCAN_RETVAL_OK) + return (int)TOUCAN_ERROR_OFFSET - (int)res; + + return (int)retVal; +} + +/* TouCAN stop + */ +int TouCAN_USB_CmdStopInterface(TouCAN_Handle_t handle) { + CANUSB_SetupPacket_t SetupPacket; + CANUSB_Return_t retVal; + uint8_t res = TOUCAN_RETVAL_UNKNOWN; + + SetupPacket.RequestType = USBREQ_HOST_TO_DEVICE | USBREQ_TYPE_CLASS | USBREQ_RECIPIENT_INTERFACE; + SetupPacket.Request = CMD_CAN_INTERFACE_STOP; + SetupPacket.Value = 0U; + SetupPacket.Index = 0U; + SetupPacket.Length = 0U; + + // TouCAN_CAN_INTERFACE_STOP + retVal = CANUSB_DeviceRequest(handle, SetupPacket, NULL, 0U, NULL); + if (retVal < 0) + return (int)retVal; + + retVal = TouCAN_USB_CmdGetLastErrorCode(handle, &res); + if (retVal < 0) + return (int)retVal; + + if (res != TOUCAN_RETVAL_OK) + return (int)TOUCAN_ERROR_OFFSET - (int)res; + + return (int)retVal; +} + +/* TouCAN HAL get last error + */ +int TouCAN_USB_CmdGetLastErrorCode(TouCAN_Handle_t handle, uint8_t *error) { + CANUSB_SetupPacket_t SetupPacket; + CANUSB_Return_t retVal; + UInt8 LastErrorCode = 0U; + UInt32 Transferred = 0U; + + SetupPacket.RequestType = USBREQ_DEVICE_TO_HOST | USBREQ_TYPE_CLASS | USBREQ_RECIPIENT_INTERFACE; + SetupPacket.Request = CMD_GET_LAST_ERROR_CODE; + SetupPacket.Value = 0U; + SetupPacket.Index = 0U; + SetupPacket.Length = 1U; + + retVal = CANUSB_DeviceRequest(handle, SetupPacket, (void*)&LastErrorCode, (UInt16)sizeof(LastErrorCode), &Transferred); + if (retVal < 0) + return (int)retVal; + + if ((LastErrorCode != HAL_OK) & (Transferred != 1U)) // note: equivalent to logical OR ! + return (int)TOUCAN_ERROR_OFFSET - (int)LastErrorCode; + + if (error) + *error = (uint8_t)LastErrorCode; + + return (int)retVal; +} + +/* TouCAN get CAN interface ERROR: hcan->ErrorCode; + */ +int TouCAN_USB_CmdGetInterfaceErrorCode(TouCAN_Handle_t handle, uint32_t *error) { + CANUSB_SetupPacket_t SetupPacket; + CANUSB_Return_t retVal; + uint8_t res = TOUCAN_RETVAL_UNKNOWN; + uint8_t data[TOUCAN_USB_CMD_PIPE_SIZE]; + memset(data, 0, TOUCAN_USB_CMD_PIPE_SIZE); + + SetupPacket.RequestType = USBREQ_DEVICE_TO_HOST | USBREQ_TYPE_CLASS | USBREQ_RECIPIENT_INTERFACE; + SetupPacket.Request = CMD_GET_CAN_INTERFACE_ERROR_CODE; + SetupPacket.Value = 0U; + SetupPacket.Index = 0U; + SetupPacket.Length = 4U; + + retVal = CANUSB_DeviceRequest(handle, SetupPacket, (void*)data, (UInt16)LEN_GET_CAN_INTERFACE_ERROR_CODE, NULL); + if (retVal < 0) + return (int)retVal; + + retVal = TouCAN_USB_CmdGetLastErrorCode(handle, &res); + if (retVal < 0) + return (int)retVal; + + if (res != TOUCAN_RETVAL_OK) + return (int)TOUCAN_ERROR_OFFSET - (int)res; + + if (error) { + *error = (uint32_t)data[0] << 24; + *error |= (uint32_t)data[1] << 16; + *error |= (uint32_t)data[2] << 8; + *error |= (uint32_t)data[3]; + } + return (int)retVal; +} + +/* TouCAN TouCAN_CLEAR_CAN_INTERFACE_ERROR_CODE: hcan->ErrorCode; + */ +int TouCAN_USB_CmdClearInterfaceErrorCode(TouCAN_Handle_t handle) { + CANUSB_SetupPacket_t SetupPacket; + CANUSB_Return_t retVal; + uint8_t res = TOUCAN_RETVAL_UNKNOWN; + + SetupPacket.RequestType = USBREQ_HOST_TO_DEVICE | USBREQ_TYPE_CLASS | USBREQ_RECIPIENT_INTERFACE; + SetupPacket.Request = CMD_CLEAR_CAN_INTERFACE_ERROR_CODE; + SetupPacket.Value = 0U; + SetupPacket.Index = 0U; + SetupPacket.Length = 0U; + + retVal = CANUSB_DeviceRequest(handle, SetupPacket, NULL, 0U, NULL); + if (retVal < 0) + return (int)retVal; + + retVal = TouCAN_USB_CmdGetLastErrorCode(handle, &res); + if (retVal < 0) + return (int)retVal; + + if (res != TOUCAN_RETVAL_OK) + return (int)TOUCAN_ERROR_OFFSET - (int)res; + + return (int)retVal; +} + +/* TouCAN TouCAN_GET_CAN_INTERFACE_STATE hcan->State; + */ +int TouCAN_USB_CmdGetInterfaceState(TouCAN_Handle_t handle, uint8_t *state) { + CANUSB_SetupPacket_t SetupPacket; + CANUSB_Return_t retVal; + uint8_t res = TOUCAN_RETVAL_UNKNOWN; + uint8_t data[TOUCAN_USB_CMD_PIPE_SIZE]; + memset(data, 0, TOUCAN_USB_CMD_PIPE_SIZE); + + SetupPacket.RequestType = USBREQ_DEVICE_TO_HOST | USBREQ_TYPE_CLASS | USBREQ_RECIPIENT_INTERFACE; + SetupPacket.Request = CMD_GET_CAN_INTERFACE_STATE; + SetupPacket.Value = 0U; + SetupPacket.Index = 0U; + SetupPacket.Length = 1U; + + retVal = CANUSB_DeviceRequest(handle, SetupPacket, (void*)data, (UInt16)LEN_GET_CAN_INTERFACE_STATE, NULL); + if (retVal < 0) + return (int)retVal; + + retVal = TouCAN_USB_CmdGetLastErrorCode(handle, &res); + if (retVal < 0) + return (int)retVal; + + if (res != TOUCAN_RETVAL_OK) + return (int)TOUCAN_ERROR_OFFSET - (int)res; + + if (state) { + *state = (uint8_t)data[0]; + } + return (int)retVal; +} + +#if (OPTION_TOUCAN_CANAL != 0) +/* TouCAN TouCAN_get_statistics VSCP + */ +int TouCAN_get_statistics(TouCAN_Handle_t handle, PCANALSTATISTICS statistics) { + CANUSB_SetupPacket_t SetupPacket; + CANUSB_Return_t retVal; + uint8_t res = TOUCAN_RETVAL_UNKNOWN; + uint8_t data[TOUCAN_USB_CMD_PIPE_SIZE]; + memset(data, 0, TOUCAN_USB_CMD_PIPE_SIZE); + UInt32 Transferred = 0U; + //UCHAR LastErrorCode = 0U; + + SetupPacket.RequestType = USBREQ_DEVICE_TO_HOST | USBREQ_TYPE_CLASS | USBREQ_RECIPIENT_INTERFACE; + SetupPacket.Request = CMD_GET_STATISTICS; + SetupPacket.Value = 0U; + SetupPacket.Index = 0U; + SetupPacket.Length = 28U; + + retVal = CANUSB_DeviceRequest(handle, SetupPacket, (void*)data, (UInt16)LEN_GET_STATISTICS, &Transferred); + if (retVal < 0) + return (int)retVal; + + retVal = TouCAN_USB_CmdGetLastErrorCode(handle, &res); + if (retVal < 0) + return (int)retVal; + + if ((res != TOUCAN_RETVAL_OK) || (Transferred != 28U)) + return (int)TOUCAN_ERROR_OFFSET - (int)res; + + if (statistics) { + statistics->cntReceiveFrames = (((uint32_t)data[0] << 24) & 0xFF000000U); + statistics->cntReceiveFrames |= (((uint32_t)data[1] << 16) & 0x00FF0000U); + statistics->cntReceiveFrames |= (((uint32_t)data[2] << 8) & 0x0000FF00U); + statistics->cntReceiveFrames |= ((uint32_t)data[3] & 0x000000FFU); + + statistics->cntTransmitFrames = (((uint32_t)data[4] << 24) & 0xFF000000U); + statistics->cntTransmitFrames |= (((uint32_t)data[5] << 16) & 0x00FF0000U); + statistics->cntTransmitFrames |= (((uint32_t)data[6] << 8) & 0x0000FF00U); + statistics->cntTransmitFrames |= ((uint32_t)data[7] & 0x000000FFU); + + statistics->cntReceiveData = (((uint32_t)data[8] << 24) & 0xFF000000U); + statistics->cntReceiveData |= (((uint32_t)data[9] << 16) & 0x00FF0000U); + statistics->cntReceiveData |= (((uint32_t)data[10] << 8) & 0x0000FF00U); + statistics->cntReceiveData |= ((uint32_t)data[11] & 0x000000FFU); + + statistics->cntTransmitData = (((uint32_t)data[12] << 24) & 0xFF000000U); + statistics->cntTransmitData |= (((uint32_t)data[13] << 16) & 0x00FF0000U); + statistics->cntTransmitData |= (((uint32_t)data[14] << 8) & 0x0000FF00U); + statistics->cntTransmitData |= ((uint32_t)data[15] & 0x000000FFU); + + statistics->cntOverruns = (((uint32_t)data[16] << 24) & 0xFF000000U); + statistics->cntOverruns |= (((uint32_t)data[17] << 16) & 0x00FF0000U); + statistics->cntOverruns |= (((uint32_t)data[18] << 8) & 0x0000FF00U); + statistics->cntOverruns |= ((uint32_t)data[19] & 0x000000FFU); + + statistics->cntBusWarnings = (((uint32_t)data[20] << 24) & 0xFF000000U); + statistics->cntBusWarnings |= (((uint32_t)data[21] << 16) & 0x00FF0000U); + statistics->cntBusWarnings |= (((uint32_t)data[22] << 8) & 0x0000FF00U); + statistics->cntBusWarnings |= ((uint32_t)data[23] & 0x000000FFU); + + statistics->cntBusOff = (((uint32_t)data[24] << 24) & 0xFF000000U); + statistics->cntBusOff |= (((uint32_t)data[25] << 16) & 0x00FF0000U); + statistics->cntBusOff |= (((uint32_t)data[26] << 8) & 0x0000FF00U); + statistics->cntBusOff |= ((uint32_t)data[27] & 0x000000FFU); + } + //TouCAN_clear_statistics(); + return (int)retVal; +} + +/* TouCAN_clear_statistics VSCP + */ +int TouCAN_clear_statistics(TouCAN_Handle_t handle) { + CANUSB_SetupPacket_t SetupPacket; + CANUSB_Return_t retVal; + uint8_t res = TOUCAN_RETVAL_UNKNOWN; + + SetupPacket.RequestType = USBREQ_HOST_TO_DEVICE | USBREQ_TYPE_CLASS | USBREQ_RECIPIENT_INTERFACE; + SetupPacket.Request = CMD_CLEAR_STATISTICS; + SetupPacket.Value = 0U; + SetupPacket.Index = 0U; + SetupPacket.Length = 0U; + + retVal = CANUSB_ControlTransfer(handle, SetupPacket, NULL, 0U, NULL); + if (retVal < 0) + return (int)retVal; + + retVal = TouCAN_USB_CmdGetLastErrorCode(handle, &res); + if (retVal < 0) + return (int)retVal; + + if (res != TOUCAN_RETVAL_OK) + return (int)TOUCAN_ERROR_OFFSET - (int)res; + + return (int)retVal; +} + +/* TouCAN_get_status VSCP + */ +int TouCAN_USB_CmdGetChannelStatus(TouCAN_Handle_t handle, PCANALSTATUS status) { + CANUSB_SetupPacket_t SetupPacket; + CANUSB_Return_t retVal; + uint8_t res = TOUCAN_RETVAL_UNKNOWN; + uint8_t data[TOUCAN_USB_CMD_PIPE_SIZE]; + memset(data, 0, TOUCAN_USB_CMD_PIPE_SIZE); + UInt32 Transferred = 0U; + + SetupPacket.RequestType = USBREQ_DEVICE_TO_HOST | USBREQ_TYPE_CLASS | USBREQ_RECIPIENT_INTERFACE; + SetupPacket.Request = CMD_GET_CAN_ERROR_STATUS; + SetupPacket.Value = 0U; + SetupPacket.Index = 0U; + SetupPacket.Length = 4U; + + retVal = CANUSB_DeviceRequest(handle, SetupPacket, (void*)data, (UInt16)LEN_GET_CAN_ERROR_STATUS, &Transferred); + if (retVal < 0) + return (int)retVal; + + retVal = TouCAN_USB_CmdGetLastErrorCode(handle, &res); + if (retVal < 0) + return (int)retVal; + + if ((res != TOUCAN_RETVAL_OK) || (Transferred != 4U)) + return (int)TOUCAN_ERROR_OFFSET - (int)res; + + if (status) { + status->channel_status = (((uint32_t)data[0] << 24) & 0xFF000000U); + status->channel_status |= (((uint32_t)data[1] << 16) & 0x00FF0000U); + status->channel_status |= (((uint32_t)data[2] << 8) & 0x0000FF00U); + status->channel_status |= (((uint32_t)data[3]) & 0x000000FFU); + } + return (int)retVal; +} +#endif + +/* TouCAN_get_hardware_version + */ +int TouCAN_USB_CmdGetHardwareVersion(TouCAN_Handle_t handle, uint32_t *value) { + CANUSB_SetupPacket_t SetupPacket; + CANUSB_Return_t retVal; + uint8_t res = TOUCAN_RETVAL_UNKNOWN; + uint8_t data[TOUCAN_USB_CMD_PIPE_SIZE]; + memset(data, 0, TOUCAN_USB_CMD_PIPE_SIZE); + + SetupPacket.RequestType = USBREQ_DEVICE_TO_HOST | USBREQ_TYPE_CLASS | USBREQ_RECIPIENT_INTERFACE; + SetupPacket.Request = CMD_GET_HARDWARE_VERSION; + SetupPacket.Value = 0U; + SetupPacket.Index = 0U; + SetupPacket.Length = 4U; + + retVal = CANUSB_DeviceRequest(handle, SetupPacket, (void*)data, (UInt16)LEN_GET_HARDWARE_VERSION, NULL); + if (retVal < 0) + return (int)retVal; + + retVal = TouCAN_USB_CmdGetLastErrorCode(handle, &res); + if (retVal < 0) + return (int)retVal; + + if (res != TOUCAN_RETVAL_OK) + return (int)TOUCAN_ERROR_OFFSET - (int)res; + + if (value) { + *value = (uint32_t)data[0] << 24; + *value |= (uint32_t)data[1] << 16; + *value |= (uint32_t)data[2] << 8; + *value |= (uint32_t)data[3]; + } + return (int)retVal; +} + +/* TouCAN_get_firmware_version + */ +int TouCAN_USB_CmdGetFirmwareVersion(TouCAN_Handle_t handle, uint32_t *value) { + CANUSB_SetupPacket_t SetupPacket; + CANUSB_Return_t retVal; + uint8_t res = TOUCAN_RETVAL_UNKNOWN; + uint8_t data[TOUCAN_USB_CMD_PIPE_SIZE]; + memset(data, 0, TOUCAN_USB_CMD_PIPE_SIZE); + + SetupPacket.RequestType = USBREQ_DEVICE_TO_HOST | USBREQ_TYPE_CLASS | USBREQ_RECIPIENT_INTERFACE; + SetupPacket.Request = CMD_GET_FIRMWARE_VERSION; + SetupPacket.Value = 0U; + SetupPacket.Index = 0U; + SetupPacket.Length = 4U; + + retVal = CANUSB_DeviceRequest(handle, SetupPacket, (void*)data, (UInt16)LEN_GET_FIRMWARE_VERSION, NULL); + if (retVal < 0) + return (int)retVal; + + retVal = TouCAN_USB_CmdGetLastErrorCode(handle, &res); + if (retVal < 0) + return (int)retVal; + + if (res != TOUCAN_RETVAL_OK) + return (int)TOUCAN_ERROR_OFFSET - (int)res; + + if (value) { + *value = (uint32_t)data[0] << 24; + *value |= (uint32_t)data[1] << 16; + *value |= (uint32_t)data[2] << 8; + *value |= (uint32_t)data[3]; + } + return (int)retVal; +} + +/* TouCAN_get_bootloader_version + */ +int TouCAN_USB_CmdGetBootloaderVersion(TouCAN_Handle_t handle, uint32_t *value) { + CANUSB_SetupPacket_t SetupPacket; + CANUSB_Return_t retVal; + uint8_t res = TOUCAN_RETVAL_UNKNOWN; + uint8_t data[TOUCAN_USB_CMD_PIPE_SIZE]; + memset(data, 0, TOUCAN_USB_CMD_PIPE_SIZE); + + SetupPacket.RequestType = USBREQ_DEVICE_TO_HOST | USBREQ_TYPE_CLASS | USBREQ_RECIPIENT_INTERFACE; + SetupPacket.Request = CMD_GET_BOOTLOADER_VERSION; + SetupPacket.Value = 0U; + SetupPacket.Index = 0U; + SetupPacket.Length = 4U; + + retVal = CANUSB_DeviceRequest(handle, SetupPacket, (void*)data, (UInt16)LEN_GET_BOOTLOADER_VERSION, NULL); + if (retVal < 0) + return (int)retVal; + + retVal = TouCAN_USB_CmdGetLastErrorCode(handle, &res); + if (retVal < 0) + return (int)retVal; + + if (res != TOUCAN_RETVAL_OK) + return (int)TOUCAN_ERROR_OFFSET - (int)res; + + if (value) { + *value = (uint32_t)data[0] << 24; + *value |= (uint32_t)data[1] << 16; + *value |= (uint32_t)data[2] << 8; + *value |= (uint32_t)data[3]; + } + return (int)retVal; +} + +/* TouCAN_get_serial_number + */ +int TouCAN_USB_CmdGetSerialNumber(TouCAN_Handle_t handle, uint32_t *value) { + CANUSB_SetupPacket_t SetupPacket; + CANUSB_Return_t retVal; + uint8_t res = TOUCAN_RETVAL_UNKNOWN; + uint8_t data[TOUCAN_USB_CMD_PIPE_SIZE]; + memset(data, 0, TOUCAN_USB_CMD_PIPE_SIZE); + + SetupPacket.RequestType = USBREQ_DEVICE_TO_HOST | USBREQ_TYPE_CLASS | USBREQ_RECIPIENT_INTERFACE; + SetupPacket.Request = CMD_GET_SERIAL_NUMBER; + SetupPacket.Value = 0U; + SetupPacket.Index = 0U; + SetupPacket.Length = 4U; + + retVal = CANUSB_DeviceRequest(handle, SetupPacket, (void*)data, (UInt16)LEN_GET_SERIAL_NUMBER, NULL); + if (retVal < 0) + return (int)retVal; + + retVal = TouCAN_USB_CmdGetLastErrorCode(handle, &res); + if (retVal < 0) + return (int)retVal; + + if (res != TOUCAN_RETVAL_OK) + return (int)TOUCAN_ERROR_OFFSET - (int)res; + + if (value) { + *value = (uint32_t)data[0] << 24; + *value |= (uint32_t)data[1] << 16; + *value |= (uint32_t)data[2] << 8; + *value |= (uint32_t)data[3]; + } + return (int)retVal; +} + +/* TouCAN_get_vid_pid + */ +int TouCAN_USB_CmdGetVidPid(TouCAN_Handle_t handle, uint32_t *value) { + CANUSB_SetupPacket_t SetupPacket; + CANUSB_Return_t retVal; + uint8_t res = TOUCAN_RETVAL_UNKNOWN; + uint8_t data[TOUCAN_USB_CMD_PIPE_SIZE]; + memset(data, 0, TOUCAN_USB_CMD_PIPE_SIZE); + + SetupPacket.RequestType = USBREQ_DEVICE_TO_HOST | USBREQ_TYPE_CLASS | USBREQ_RECIPIENT_INTERFACE; + SetupPacket.Request = CMD_GET_VID_PID; + SetupPacket.Value = 0U; + SetupPacket.Index = 0U; + SetupPacket.Length = 4U; + + retVal = CANUSB_DeviceRequest(handle, SetupPacket, (void*)data, (UInt16)LEN_GET_VID_PID, NULL); + if (retVal < 0) + return (int)retVal; + + retVal = TouCAN_USB_CmdGetLastErrorCode(handle, &res); + if (retVal < 0) + return (int)retVal; + + if (res != TOUCAN_RETVAL_OK) + return (int)TOUCAN_ERROR_OFFSET - (int)res; + + if (value) { + *value = (uint32_t)data[0] << 24; + *value |= (uint32_t)data[1] << 16; + *value |= (uint32_t)data[2] << 8; + *value |= (uint32_t)data[3]; + } + return (int)retVal; +} + +/* TouCAN_get_device_id + */ +int TouCAN_USB_CmdGetDeviceId(TouCAN_Handle_t handle, uint32_t *value) { + CANUSB_SetupPacket_t SetupPacket; + CANUSB_Return_t retVal; + uint8_t res = TOUCAN_RETVAL_UNKNOWN; + uint8_t data[TOUCAN_USB_CMD_PIPE_SIZE]; + memset(data, 0, TOUCAN_USB_CMD_PIPE_SIZE); + + SetupPacket.RequestType = USBREQ_DEVICE_TO_HOST | USBREQ_TYPE_CLASS | USBREQ_RECIPIENT_INTERFACE; + SetupPacket.Request = CMD_GET_DEVICE_ID; + SetupPacket.Value = 0U; + SetupPacket.Index = 0U; + SetupPacket.Length = 4U; + + retVal = CANUSB_DeviceRequest(handle, SetupPacket, (void*)data, (UInt16)LEN_GET_DEVICE_ID, NULL); + if (retVal < 0) + return (int)retVal; + + retVal = TouCAN_USB_CmdGetLastErrorCode(handle, &res); + if (retVal < 0) + return (int)retVal; + + if (res != TOUCAN_RETVAL_OK) + return (int)TOUCAN_ERROR_OFFSET - (int)res; + + if (value) { + *value = (uint32_t)data[0] << 24; + *value |= (uint32_t)data[1] << 16; + *value |= (uint32_t)data[2] << 8; + *value |= (uint32_t)data[3]; + } + return (int)retVal; +} + +/* TouCAN_get_vendor + */ +int TouCAN_USB_CmdGetVendorName(TouCAN_Handle_t handle, size_t size, char *name) { + CANUSB_SetupPacket_t SetupPacket; + CANUSB_Return_t retVal; + uint8_t res = TOUCAN_RETVAL_UNKNOWN; + uint8_t data[TOUCAN_USB_CMD_PIPE_SIZE]; + memset(data, 0, TOUCAN_USB_CMD_PIPE_SIZE); + + SetupPacket.RequestType = USBREQ_DEVICE_TO_HOST | USBREQ_TYPE_CLASS | USBREQ_RECIPIENT_INTERFACE; + SetupPacket.Request = CMD_GET_VENDOR; + SetupPacket.Value = 0U; + SetupPacket.Index = 0U; + SetupPacket.Length = 32U; // FIXME: 4(?) + + retVal = CANUSB_DeviceRequest(handle, SetupPacket, (void*)data, (UInt16)LEN_GET_VENDOR, NULL); + if (retVal < 0) + return (int)retVal; + + retVal = TouCAN_USB_CmdGetLastErrorCode(handle, &res); + if (retVal < 0) + return (int)retVal; + + if (res != TOUCAN_RETVAL_OK) + return (int)TOUCAN_ERROR_OFFSET - (int)res; + + if (name) { + data[LEN_GET_VENDOR] = '\0'; + strncpy(name, (const char *)data, size); + } + return (int)retVal; +} + +int TouCAN_USB_CmdGetTransmitDelay(TouCAN_Handle_t handle, /*uint8_t channel,*/ uint32_t *delay) { + CANUSB_SetupPacket_t SetupPacket; + CANUSB_Return_t retVal; + uint8_t res = TOUCAN_RETVAL_UNKNOWN; + uint8_t data[TOUCAN_USB_CMD_PIPE_SIZE]; + memset(data, 0, TOUCAN_USB_CMD_PIPE_SIZE); + + SetupPacket.RequestType = USBREQ_DEVICE_TO_HOST | USBREQ_TYPE_CLASS | USBREQ_RECIPIENT_INTERFACE; + SetupPacket.Request = CMD_GET_CAN_INTERFACE_DELAY; + SetupPacket.Value = 0U; + SetupPacket.Index = 0U; + SetupPacket.Length = 0U; + + retVal = CANUSB_DeviceRequest(handle, SetupPacket, (void*)data, (UInt16)LEN_GET_CAN_INTERFACE_DELAY, NULL); + if (retVal < 0) + return (int)retVal; + + retVal = TouCAN_USB_CmdGetLastErrorCode(handle, &res); + if (retVal < 0) + return (int)retVal; + + if (res != TOUCAN_RETVAL_OK) + return (int)TOUCAN_ERROR_OFFSET - (int)res; + + if (delay) { + *delay = (uint32_t)data[0] << 24; + *delay |= (uint32_t)data[1] << 16; + *delay |= (uint32_t)data[2] << 8; + *delay |= (uint32_t)data[3]; + } + return (int)retVal; +} + +int TouCAN_USB_CmdSetTransmitDelay(TouCAN_Handle_t handle, /*uint8_t channel,*/ uint32_t delay) { + CANUSB_SetupPacket_t SetupPacket; + CANUSB_Return_t retVal; + uint8_t res = TOUCAN_RETVAL_UNKNOWN; + uint8_t data[TOUCAN_USB_CMD_PIPE_SIZE]; + memset(data, 0, TOUCAN_USB_CMD_PIPE_SIZE); + UInt32 Transferred = 0U; + + SetupPacket.RequestType = USBREQ_HOST_TO_DEVICE | USBREQ_TYPE_CLASS | USBREQ_RECIPIENT_INTERFACE; + SetupPacket.Request = CMD_SET_CAN_INTERFACE_DELAY; + SetupPacket.Value = 0U; + SetupPacket.Index = 0U; + SetupPacket.Length = 0U; + + data[0] = (uint8_t)((delay >> 24) & 0xFFU); + data[1] = (uint8_t)((delay >> 16) & 0xFFU); + data[2] = (uint8_t)((delay >> 8) & 0xFFU); + data[3] = (uint8_t)(delay & 0xFFU); + + retVal = CANUSB_DeviceRequest(handle, SetupPacket, (void*)data, (UInt16)LEN_SET_CAN_INTERFACE_DELAY, &Transferred); + if (retVal < 0) + return (int)retVal; + + retVal = TouCAN_USB_CmdGetLastErrorCode(handle, &res); + if (retVal < 0) + return (int)retVal; + + if (res != TOUCAN_RETVAL_OK) + return (int)TOUCAN_ERROR_OFFSET - (int)res; + else if (Transferred != LEN_SET_CAN_INTERFACE_DELAY) + return (int)TOUCAN_ERROR_OFFSET - (int)TOUCAN_RETVAL_UNKNOWN; + + return (int)retVal; +} + +int TouCAN_USB_CmdSetStandardFilter(TouCAN_Handle_t handle, TouCAN_FilterMode_t mode, uint32_t code, uint32_t mask) { + CANUSB_SetupPacket_t SetupPacket; + CANUSB_Return_t retVal; + uint8_t res = TOUCAN_RETVAL_UNKNOWN; + uint8_t data[TOUCAN_USB_CMD_PIPE_SIZE]; + memset(data, 0, TOUCAN_USB_CMD_PIPE_SIZE); + UInt32 Transferred = 0U; + UInt16 Length = 0U; + + SetupPacket.RequestType = USBREQ_HOST_TO_DEVICE | USBREQ_TYPE_CLASS | USBREQ_RECIPIENT_INTERFACE; + switch (mode) { + case FILTER_ACCEPT_ALL: SetupPacket.Request = CMD_FILTER_STD_ACCEPT_ALL; Length = LEN_FILTER_STD_ACCEPT_ALL; break; + case FILTER_REJECT_ALL: SetupPacket.Request = CMD_FILTER_STD_REJECT_ALL; Length = LEN_FILTER_STD_REJECT_ALL; break; + case FILTER_VALUE: SetupPacket.Request = CMD_SET_FILTER_STD_LIST_MASK; Length = LEN_SET_FILTER_STD_LIST_MASK; break; + default: + return (int)CANUSB_ERROR_ILLPARA; + } + SetupPacket.Value = 0U; + SetupPacket.Index = 0U; + SetupPacket.Length = Length; + + data[0] = (uint8_t)((code >> 24) & 0xFFU); + data[1] = (uint8_t)((code >> 16) & 0xFFU); + data[2] = (uint8_t)((code >> 8) & 0xFFU); + data[3] = (uint8_t) (code & 0xFFU); + + data[4] = (uint8_t)((mask >> 24) & 0xFFU); + data[5] = (uint8_t)((mask >> 16) & 0xFFU); + data[6] = (uint8_t)((mask >> 8) & 0xFFU); + data[7] = (uint8_t) (mask & 0xFFU); + + retVal = CANUSB_DeviceRequest(handle, SetupPacket, (void*)data, Length, &Transferred); + if (retVal < 0) + return (int)retVal; + + retVal = TouCAN_USB_CmdGetLastErrorCode(handle, &res); + if (retVal < 0) + return (int)retVal; + + if (res != TOUCAN_RETVAL_OK) + return (int)TOUCAN_ERROR_OFFSET - (int)res; + else if (Transferred != (UInt32)Length) + return (int)TOUCAN_ERROR_OFFSET - (int)TOUCAN_RETVAL_UNKNOWN; + + return (int)retVal; +} + +int TouCAN_USB_CmdSetExtendedFilter(TouCAN_Handle_t handle, TouCAN_FilterMode_t mode, uint32_t code, uint32_t mask) { + CANUSB_SetupPacket_t SetupPacket; + CANUSB_Return_t retVal; + uint8_t res = TOUCAN_RETVAL_UNKNOWN; + uint8_t data[TOUCAN_USB_CMD_PIPE_SIZE]; + memset(data, 0, TOUCAN_USB_CMD_PIPE_SIZE); + UInt32 Transferred = 0U; + UInt16 Length = 0U; + + SetupPacket.RequestType = USBREQ_HOST_TO_DEVICE | USBREQ_TYPE_CLASS | USBREQ_RECIPIENT_INTERFACE; + switch (mode) { + case FILTER_ACCEPT_ALL: SetupPacket.Request = CMD_FILTER_EXT_ACCEPT_ALL; Length = LEN_FILTER_EXT_ACCEPT_ALL; break; + case FILTER_REJECT_ALL: SetupPacket.Request = CMD_FILTER_EXT_REJECT_ALL; Length = LEN_FILTER_EXT_REJECT_ALL; break; + case FILTER_VALUE: SetupPacket.Request = CMD_SET_FILTER_EXT_LIST_MASK; Length = LEN_SET_FILTER_EXT_LIST_MASK; break; + default: + return (int)CANUSB_ERROR_ILLPARA; + } + SetupPacket.Value = 0U; + SetupPacket.Index = 0U; + SetupPacket.Length = Length; + + data[0] = (uint8_t)((code >> 24) & 0xFFU); + data[1] = (uint8_t)((code >> 16) & 0xFFU); + data[2] = (uint8_t)((code >> 8) & 0xFFU); + data[3] = (uint8_t)(code & 0xFFU); + + data[4] = (uint8_t)((mask >> 24) & 0xFFU); + data[5] = (uint8_t)((mask >> 16) & 0xFFU); + data[6] = (uint8_t)((mask >> 8) & 0xFFU); + data[7] = (uint8_t)(mask & 0xFFU); + + retVal = CANUSB_DeviceRequest(handle, SetupPacket, (void*)data, Length, &Transferred); + if (retVal < 0) + return (int)retVal; + + retVal = TouCAN_USB_CmdGetLastErrorCode(handle, &res); + if (retVal < 0) + return (int)retVal; + + if (res != TOUCAN_RETVAL_OK) + return (int)TOUCAN_ERROR_OFFSET - (int)res; + else if (Transferred != (UInt32)Length) + return (int)TOUCAN_ERROR_OFFSET - (int)TOUCAN_RETVAL_UNKNOWN; + + return (int)retVal; +} diff --git a/Sources/Driver/TouCAN_USB_CmdMsg.h b/Sources/Driver/TouCAN_USB_CmdMsg.h new file mode 100644 index 0000000..dad279a --- /dev/null +++ b/Sources/Driver/TouCAN_USB_CmdMsg.h @@ -0,0 +1,84 @@ +/* SPDX-License-Identifier: BSD-2-Clause OR GPL-3.0-or-later */ +/* + * TouCAN - macOS User-Space Driver for Rusoku TouCAN USB Adapters + * + * Copyright (c) 2024 Uwe Vogt, UV Software, Berlin (info@mac-can.com) + * All rights reserved. + * + * This file is part of MacCAN-TouCAN. + * + * MacCAN-TouCAN is dual-licensed under the BSD 2-Clause "Simplified" License + * and under the GNU General Public License v3.0 (or any later version). You can + * choose between one of them if you use MacCAN-TouCAN in whole or in part. + * + * BSD 2-Clause "Simplified" License: + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * MacCAN-TouCAN IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF MacCAN-TouCAN, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * GNU General Public License v3.0 or later: + * MacCAN-TouCAN is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * MacCAN-TouCAN is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with MacCAN-TouCAN. If not, see . + */ +#ifndef TOUCAN_USB_COMMANDS_H_INCLUDED +#define TOUCAN_USB_COMMANDS_H_INCLUDED + +#include "TouCAN_USB_Common.h" + +typedef int TouCAN_Handle_t; + +#ifdef __cplusplus +extern "C" { +#endif + +extern int TouCAN_USB_CmdInitInterface(TouCAN_Handle_t handle, uint16_t brp, uint8_t tseg1, uint8_t tseg2, uint8_t sjw, uint32_t flags); +extern int TouCAN_USB_CmdDeinitInterface(TouCAN_Handle_t handle); +extern int TouCAN_USB_CmdStartInterface(TouCAN_Handle_t handle); +extern int TouCAN_USB_CmdStopInterface(TouCAN_Handle_t handle); + +extern int TouCAN_USB_CmdGetLastErrorCode(TouCAN_Handle_t handle, uint8_t *error); +extern int TouCAN_USB_CmdGetInterfaceErrorCode(TouCAN_Handle_t handle, uint32_t *error); +extern int TouCAN_USB_CmdClearInterfaceErrorCode(TouCAN_Handle_t handle); +extern int TouCAN_USB_CmdGetInterfaceState(TouCAN_Handle_t handle, uint8_t *state); + +extern int TouCAN_USB_CmdGetHardwareVersion(TouCAN_Handle_t handle, uint32_t *value); +extern int TouCAN_USB_CmdGetFirmwareVersion(TouCAN_Handle_t handle, uint32_t *value); +extern int TouCAN_USB_CmdGetBootloaderVersion(TouCAN_Handle_t handle, uint32_t *value); +extern int TouCAN_USB_CmdGetSerialNumber(TouCAN_Handle_t handle, uint32_t *value); +extern int TouCAN_USB_CmdGetVidPid(TouCAN_Handle_t handle, uint32_t *value); +extern int TouCAN_USB_CmdGetDeviceId(TouCAN_Handle_t handle, uint32_t *value); +extern int TouCAN_USB_CmdGetVendorName(TouCAN_Handle_t handle, size_t size, char *name); +extern int TouCAN_USB_CmdGetTransmitDelay(TouCAN_Handle_t handle, uint32_t *delay); +extern int TouCAN_USB_CmdSetTransmitDelay(TouCAN_Handle_t handle, uint32_t delay); +extern int TouCAN_USB_CmdSetStandardFilter(TouCAN_Handle_t handle, TouCAN_FilterMode_t mode, uint32_t code, uint32_t mask); +extern int TouCAN_USB_CmdSetExtendedFilter(TouCAN_Handle_t handle, TouCAN_FilterMode_t mode, uint32_t code, uint32_t mask); + +#ifdef __cplusplus +} +#endif +#endif /* TOUCAN_USB_COMMANDS_H_INCLUDED */ diff --git a/Sources/Driver/TouCAN_USB_Common.h b/Sources/Driver/TouCAN_USB_Common.h index 5c46bd4..ecf7476 100644 --- a/Sources/Driver/TouCAN_USB_Common.h +++ b/Sources/Driver/TouCAN_USB_Common.h @@ -1,11 +1,37 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* SPDX-License-Identifier: BSD-2-Clause OR GPL-3.0-or-later */ /* - * TouCAN - macOS User-Space Driver for Rusoku TouCAN USB Interfaces + * TouCAN - macOS User-Space Driver for Rusoku TouCAN USB Adapters * - * Copyright (C) 2021-2022 Uwe Vogt, UV Software, Berlin (info@mac-can.com) + * Copyright (c) 2021-2024 Uwe Vogt, UV Software, Berlin (info@mac-can.com) + * All rights reserved. * * This file is part of MacCAN-TouCAN. * + * MacCAN-TouCAN is dual-licensed under the BSD 2-Clause "Simplified" License + * and under the GNU General Public License v3.0 (or any later version). You can + * choose between one of them if you use MacCAN-TouCAN in whole or in part. + * + * BSD 2-Clause "Simplified" License: + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * MacCAN-TouCAN IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF MacCAN-TouCAN, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * GNU General Public License v3.0 or later: * MacCAN-TouCAN is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or @@ -25,13 +51,15 @@ #include #include -#define TOUCAN_VENDOR_ID (UInt16)0x16D0 -#define TOUCAN_USB_ID (UInt16)0x0EAC +#define TOUCAN_VENDOR_ID (uint16_t)0x16D0 +#define TOUCAN_USB_ID (uint16_t)0x0EAC #define TOUCAN_VENDOR_NAME "Rusoku technologijos UAB, Lithuania" #define TOUCAN_VENDOR_URL "www.rusoku.com" -// TODO: move this into USB_Driver.h (when MacCAN enpoind module realized) +// TODO: move this into USB_Driver.h (when enpoind enumerator is realized) +#define TOUCAN_USB_CMD_PIPE_REF 0U +#define TOUCAN_USB_CMD_PIPE_SIZE 64U #define TOUCAN_USB_TX_DATA_PIPE_REF 1U #define TOUCAN_USB_RX_DATA_PIPE_REF 2U #define TOUCAN_USB_TX_DATA_PIPE_SIZE 64U @@ -43,7 +71,7 @@ // TODO: end! #define TOUCAN_RCV_QUEUE_SIZE 65536 -#define TOUCAN_TRM_QUEUE_SIZE 256 +#define TOUCAN_TRM_QUEUE_SIZE 0 #define TOUCAN_MAX_NAME_LENGTH 256 #define TOUCAN_MAX_STRING_LENGTH 80 @@ -63,188 +91,79 @@ // TODO: insert coin here #endif -/* --- Defines and typdefs copied from CANAL interface DLL (CTouCANobj.h) --- - * - * CANAL interface DLL for RUSOKU technologies for TouCAN, TouCAN Marine, TouCAN Duo USB to CAN bus converter - * - * Copyright (C) 2000-2008 Ake Hedman, eurosource, - * Copyright (C) 2020 Gediminas Simanskis (gediminas@rusoku.com) - * Copyright (C) 2020 Alexander Sorokin (sorockin@yandex.ru) - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published - * by the Free Software Foundation; version 3.0 of the License. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. - * +/* TouCAN return error codes (HAL) */ -///////////////////////////////////////////////////// -// USB request types & mask defines - -#define USB_HOST_TO_DEVICE 0x00 -#define USB_DEVICE_TO_HOST 0x80 - -#define USB_REQ_TYPE_STANDARD 0x00 -#define USB_REQ_TYPE_CLASS 0x20 -#define USB_REQ_TYPE_VENDOR 0x40 -#define USB_REQ_TYPE_MASK 0x60 - -#define USB_REQ_RECIPIENT_DEVICE 0x00 -#define USB_REQ_RECIPIENT_INTERFACE 0x01 -#define USB_REQ_RECIPIENT_ENDPOINT 0x02 -#define USB_REQ_RECIPIENT_MASK 0x03 - -///////////////////////////////////////////////////// -// TouCAN requests types (Command) - -#define TouCAN_RESET 0x00 // OK -#define TouCAN_CAN_INTERFACE_INIT 0x01 // OK -#define TouCAN_CAN_INTERFACE_DEINIT 0x02 // OK -#define TouCAN_CAN_INTERFACE_START 0x03 // OK -#define TouCAN_CAN_INTERFACE_STOP 0x04 // OK - -#define TouCAN_FILTER_STD_ACCEPT_ALL 0x05 -#define TouCAN_FILTER_STD_REJECT_ALL 0x06 - -#define TouCAN_FILTER_EXT_ACCEPT_ALL 0x07 -#define TouCAN_FILTER_EXT_REJECT_ALL 0x08 - -#define TouCAN_SET_FILTER_STD_LIST_MASK 0x09 -#define TouCAN_SET_FILTER_EXT_LIST_MASK 0x0A -#define TouCAN_GET_FILTER_STD_LIST_MASK 0x0B -#define TouCAN_GET_FILTER_EXT_LIST_MASK 0x0C - -#define TouCAN_GET_CAN_ERROR_STATUS 0x0D // OK - CAN_Error_Status(&hcan1) -#define TouCAN_CLEAR_CAN_ERROR_STATUS 0x0D // NOK - CAN_Error_Status(&hcan1) // nenusistato -#define TouCAN_GET_STATISTICS 0x0E // OK (VSCP CAN state) -#define TouCAN_CLEAR_STATISTICS 0x0F // OK (VSCP CAN state) -#define TouCAN_GET_HARDWARE_VERSION 0x10 // OK -#define TouCAN_GET_FIRMWARE_VERSION 0x11 // OK -#define TouCAN_GET_BOOTLOADER_VERSION 0x12 // OK -#define TouCAN_GET_SERIAL_NUMBER 0x13 // OK -//#define TouCAN_SET_SERIAL_NUMBER 0x14 -//#define TouCAN_RESET_SERIAL_NUMBER 0x15 -#define TouCAN_GET_VID_PID 0x16 // OK -#define TouCAN_GET_DEVICE_ID 0x17 // OK -#define TouCAN_GET_VENDOR 0x18 // OK - -#define TouCAN_GET_LAST_ERROR_CODE 0x20 // HAL return error code 8bit // OK -#define TouCAN_CLEAR_LAST_ERROR_CODE 0x21 // HAL return error code 8bit // OK -#define TouCAN_GET_CAN_INTERFACE_STATE 0x22 // HAL_CAN_GetState(&hcan1) 8bit // OK -#define TouCAN_CLEAR_CAN_INTERFACE_STATE 0x23 // HAL_CAN_GetState(&hcan1); ----------------------------- NOK -#define TouCAN_GET_CAN_INTERFACE_ERROR_CODE 0x24 // hcan->ErrorCode; 32bit // OK HAL_CAN_GetError(&hcan1); -#define TouCAN_CLEAR_CAN_INTERFACE_ERROR_CODE 0x25 // hcan->ErrorCode; 32bit // OK HAL_CAN_GetError(&hcan1); - -#define TouCAN_SET_CAN_INTERFACE_DELAY 0x26 // OK -#define TouCAN_GET_CAN_INTERFACE_DELAY 0x27 // OK - -/////////////////////////////////////////////////////// -// TouCAN return error codes (HAL) - -#define TouCAN_RETVAL_OK 0x00 -#define TouCAN_RETVAL_ERROR 0x01 -#define TouCAN_RETVAL_BUSY 0x02 -#define TouCAN_RETVAL_TIMEOUT 0x03 - -////////////////////////////////////////////////////// -// TouCAN init string FLAGS (32 bit) - -#define TouCAN_ENABLE_SILENT_MODE 0x00000001 // 1 -#define TouCAN_ENABLE_LOOPBACK_MODE 0x00000002 // 2 -#define TouCAN_DISABLE_RETRANSMITION 0x00000004 // 4 -#define TouCAN_ENABLE_AUTOMATIC_WAKEUP_MODE 0x00000008 // 8 -#define TouCAN_ENABLE_AUTOMATIC_BUS_OFF 0x00000010 // 16 -#define TouCAN_ENABLE_TTM_MODE 0x00000020 // 32 -#define TouCAN_ENABLE_RX_FIFO_LOCKED_MODE 0x00000040 // 64 -#define TouCAN_ENABLE_TX_FIFO_PRIORITY 0x00000080 // 128 +#define TOUCAN_RETVAL_OK 0x00U +#define TOUCAN_RETVAL_ERROR 0x01U +#define TOUCAN_RETVAL_BUSY 0x02U +#define TOUCAN_RETVAL_TIMEOUT 0x03U +#define TOUCAN_RETVAL_UNKNOWN 0x63U -#define TouCAN_ENABLE_STATUS_MESSAGES 0x00000100 // 256 -#define TouCAN_ENABLE_TIMESTAMP_DELAY 0x00000200 // 512 - -///////////////////////////////////////////////////// -// TouCAN HAL return error codes - -typedef enum -{ +/* TouCAN init string flags (32 bit) + */ +#define TOUCAN_ENABLE_SILENT_MODE 0x00000001U +#define TOUCAN_ENABLE_LOOPBACK_MODE 0x00000002U +#define TouCAN_DISABLE_RETRANSMITION 0x00000004U +#define TOUCAN_ENABLE_AUTOMATIC_WAKEUP_MODE 0x00000008U +#define TOUCAN_ENABLE_AUTOMATIC_BUS_OFF 0x00000010U +#define TOUCAN_ENABLE_TTM_MODE 0x00000020U +#define TOUCAN_ENABLE_RX_FIFO_LOCKED_MODE 0x00000040U +#define TOUCAN_ENABLE_TX_FIFO_PRIORITY 0x00000080U +#define TOUCAN_ENABLE_STATUS_MESSAGES 0x00000100U +#define TOUCAN_ENABLE_TIMESTAMP_DELAY 0x00000200U + +/* TouCAN HAL return error codes + */ +typedef enum { HAL_OK = 0x00U, HAL_ERROR = 0x01U, - HAL_BUSY = 0x02U, + HAL_BUSY = 0x02U, HAL_TIMEOUT = 0x03U -} HAL_StatusTypeDef; - - -///////////////////////////////////////////////////// -// TouCAN CAN interface state - -typedef enum -{ - HAL_CAN_STATE_RESET = 0x00U, /*!< CAN not yet initialized or disabled */ - HAL_CAN_STATE_READY = 0x01U, /*!< CAN initialized and ready for use */ - HAL_CAN_STATE_LISTENING = 0x02U, /*!< CAN receive process is ongoing */ - HAL_CAN_STATE_SLEEP_PENDING = 0x03U, /*!< CAN sleep request is pending */ - HAL_CAN_STATE_SLEEP_ACTIVE = 0x04U, /*!< CAN sleep mode is active */ - HAL_CAN_STATE_ERROR = 0x05U /*!< CAN error state */ - -} HAL_CAN_StateTypeDef; - - -//////////////////////////////////////////////////// -// TouCAN CAN interface ERROR codes +} HAL_Status_t; -#define HAL_CAN_ERROR_NONE (0x00000000U) /*!< No error */ -#define HAL_CAN_ERROR_EWG (0x00000001U) /*!< Protocol Error Warning */ -#define HAL_CAN_ERROR_EPV (0x00000002U) /*!< Error Passive */ -#define HAL_CAN_ERROR_BOF (0x00000004U) /*!< Bus-off error */ -#define HAL_CAN_ERROR_STF (0x00000008U) /*!< Stuff error */ -#define HAL_CAN_ERROR_FOR (0x00000010U) /*!< Form error */ -#define HAL_CAN_ERROR_ACK (0x00000020U) /*!< Acknowledgment error */ -#define HAL_CAN_ERROR_BR (0x00000040U) /*!< Bit recessive error */ -#define HAL_CAN_ERROR_BD (0x00000080U) /*!< Bit dominant error */ -#define HAL_CAN_ERROR_CRC (0x00000100U) /*!< CRC error */ -#define HAL_CAN_ERROR_RX_FOV0 (0x00000200U) /*!< Rx FIFO0 overrun error */ -#define HAL_CAN_ERROR_RX_FOV1 (0x00000400U) /*!< Rx FIFO1 overrun error */ -#define HAL_CAN_ERROR_TX_ALST0 (0x00000800U) /*!< TxMailbox 0 transmit failure due to arbitration lost */ -#define HAL_CAN_ERROR_TX_TERR0 (0x00001000U) /*!< TxMailbox 1 transmit failure due to tranmit error */ -#define HAL_CAN_ERROR_TX_ALST1 (0x00002000U) /*!< TxMailbox 0 transmit failure due to arbitration lost */ -#define HAL_CAN_ERROR_TX_TERR1 (0x00004000U) /*!< TxMailbox 1 transmit failure due to tranmit error */ -#define HAL_CAN_ERROR_TX_ALST2 (0x00008000U) /*!< TxMailbox 0 transmit failure due to arbitration lost */ -#define HAL_CAN_ERROR_TX_TERR2 (0x00010000U) /*!< TxMailbox 1 transmit failure due to tranmit error */ -#define HAL_CAN_ERROR_TIMEOUT (0x00020000U) /*!< Timeout error */ -#define HAL_CAN_ERROR_NOT_INITIALIZED (0x00040000U) /*!< Peripheral not initialized */ -#define HAL_CAN_ERROR_NOT_READY (0x00080000U) /*!< Peripheral not ready */ -#define HAL_CAN_ERROR_NOT_STARTED (0x00100000U) /*!< Peripheral not started */ -#define HAL_CAN_ERROR_PARAM (0x00200000U) /*!< Parameter error */ - -/* --- Defines and typdefs copied from CANAL interface DLL (vscp_common/canal_a.h) --- - * - * CANAL interface DLL for RUSOKU technologies for TouCAN, TouCAN Marine, TouCAN Duo USB to CAN bus converter - * - * Copyright (C) 2018 Gediminas Simanskis (gediminas@rusoku.com) - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published - * by the Free Software Foundation; version 3.0 of the License. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. - * +/* TouCAN CAN interface state + */ +typedef enum { + HAL_CAN_STATE_RESET = 0x00U, + HAL_CAN_STATE_READY = 0x01U, + HAL_CAN_STATE_LISTENING = 0x02U, + HAL_CAN_STATE_SLEEP_PENDING = 0x03U, + HAL_CAN_STATE_SLEEP_ACTIVE = 0x04U, + HAL_CAN_STATE_ERROR = 0x05U +} HAL_CAN_State_t; + +/* TouCAN CAN interface ERROR codes + */ +#define HAL_CAN_ERROR_NONE 0x00000000U +#define HAL_CAN_ERROR_EWG 0x00000001U +#define HAL_CAN_ERROR_EPV 0x00000002U +#define HAL_CAN_ERROR_BOF 0x00000004U +#define HAL_CAN_ERROR_STF 0x00000008U +#define HAL_CAN_ERROR_FOR 0x00000010U +#define HAL_CAN_ERROR_ACK 0x00000020U +#define HAL_CAN_ERROR_BR 0x00000040U +#define HAL_CAN_ERROR_BD 0x00000080U +#define HAL_CAN_ERROR_CRC 0x00000100U +#define HAL_CAN_ERROR_RX_FOV0 0x00000200U +#define HAL_CAN_ERROR_RX_FOV1 0x00000400U +#define HAL_CAN_ERROR_TX_ALST0 0x00000800U +#define HAL_CAN_ERROR_TX_TERR0 0x00001000U +#define HAL_CAN_ERROR_TX_ALST1 0x00002000U +#define HAL_CAN_ERROR_TX_TERR1 0x00004000U +#define HAL_CAN_ERROR_TX_ALST2 0x00008000U +#define HAL_CAN_ERROR_TX_TERR2 0x00010000U +#define HAL_CAN_ERROR_TIMEOUT 0x00020000U +#define HAL_CAN_ERROR_NOT_INITIALIZED 0x00040000U +#define HAL_CAN_ERROR_NOT_READY 0x00080000U +#define HAL_CAN_ERROR_NOT_STARTED 0x00100000U +#define HAL_CAN_ERROR_PARAM 0x00200000U + +/* TouCAN CAN acceptance filter modes */ -/* FILTER req type */ typedef enum { - FILTER_ACCEPT_ALL = 0, - FILTER_REJECT_ALL, - FILTER_VALUE, -}Filter_Type_TypeDef; + FILTER_ACCEPT_ALL = 0, + FILTER_REJECT_ALL = 1, + FILTER_VALUE = 2 +} TouCAN_FilterMode_t; #endif /* TOUCAN_USB_COMMON_H_INCLUDED */ diff --git a/Sources/Driver/TouCAN_USB_Device.c b/Sources/Driver/TouCAN_USB_Device.c index 18fbdaf..c0e5171 100644 --- a/Sources/Driver/TouCAN_USB_Device.c +++ b/Sources/Driver/TouCAN_USB_Device.c @@ -1,11 +1,37 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* SPDX-License-Identifier: BSD-2-Clause OR GPL-3.0-or-later */ /* * TouCAN - macOS User-Space Driver for Rusoku TouCAN USB Adapters * - * Copyright (C) 2021-2023 Uwe Vogt, UV Software, Berlin (info@mac-can.com) + * Copyright (c) 2021-2024 Uwe Vogt, UV Software, Berlin (info@mac-can.com) + * All rights reserved. * * This file is part of MacCAN-TouCAN. * + * MacCAN-TouCAN is dual-licensed under the BSD 2-Clause "Simplified" License + * and under the GNU General Public License v3.0 (or any later version). You can + * choose between one of them if you use MacCAN-TouCAN in whole or in part. + * + * BSD 2-Clause "Simplified" License: + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * MacCAN-TouCAN IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF MacCAN-TouCAN, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * GNU General Public License v3.0 or later: * MacCAN-TouCAN is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or diff --git a/Sources/Driver/TouCAN_USB_Device.h b/Sources/Driver/TouCAN_USB_Device.h index 9b31dbd..7efc12a 100644 --- a/Sources/Driver/TouCAN_USB_Device.h +++ b/Sources/Driver/TouCAN_USB_Device.h @@ -1,11 +1,37 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* SPDX-License-Identifier: BSD-2-Clause OR GPL-3.0-or-later */ /* - * TouCAN - macOS User-Space Driver for Rusoku TouCAN USB Interfaces + * TouCAN - macOS User-Space Driver for Rusoku TouCAN USB Adapters * - * Copyright (C) 2021-2023 Uwe Vogt, UV Software, Berlin (info@mac-can.com) + * Copyright (c) 2021-2024 Uwe Vogt, UV Software, Berlin (info@mac-can.com) + * All rights reserved. * * This file is part of MacCAN-TouCAN. * + * MacCAN-TouCAN is dual-licensed under the BSD 2-Clause "Simplified" License + * and under the GNU General Public License v3.0 (or any later version). You can + * choose between one of them if you use MacCAN-TouCAN in whole or in part. + * + * BSD 2-Clause "Simplified" License: + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * MacCAN-TouCAN IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF MacCAN-TouCAN, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * GNU General Public License v3.0 or later: * MacCAN-TouCAN is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or diff --git a/Sources/Driver/TouCAN_USB_Driver.c b/Sources/Driver/TouCAN_USB_Driver.c index 1cc20bc..9403ceb 100644 --- a/Sources/Driver/TouCAN_USB_Driver.c +++ b/Sources/Driver/TouCAN_USB_Driver.c @@ -1,11 +1,37 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* SPDX-License-Identifier: BSD-2-Clause OR GPL-3.0-or-later */ /* * TouCAN - macOS User-Space Driver for Rusoku TouCAN USB Adapters * - * Copyright (C) 2021-2023 Uwe Vogt, UV Software, Berlin (info@mac-can.com) + * Copyright (c) 2021-2024 Uwe Vogt, UV Software, Berlin (info@mac-can.com) + * All rights reserved. * * This file is part of MacCAN-TouCAN. * + * MacCAN-TouCAN is dual-licensed under the BSD 2-Clause "Simplified" License + * and under the GNU General Public License v3.0 (or any later version). You can + * choose between one of them if you use MacCAN-TouCAN in whole or in part. + * + * BSD 2-Clause "Simplified" License: + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * MacCAN-TouCAN IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF MacCAN-TouCAN, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * GNU General Public License v3.0 or later: * MacCAN-TouCAN is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or @@ -20,7 +46,7 @@ * along with MacCAN-TouCAN. If not, see . */ #include "TouCAN_USB_Driver.h" -#include "TouCAN_USB.h" +#include "TouCAN_USB_CmdMsg.h" #include #include @@ -33,22 +59,22 @@ #include "MacCAN_Debug.h" #include -#define TOUCAN_MSG_STD_FRAME (UInt8)0x00 // CANAL_IDFLAG_STANDARD -#define TOUCAN_MSG_XTD_FRAME (UInt8)0x01 // CANAL_IDFLAG_EXTENDED -#define TOUCAN_MSG_RTR_FRAME (UInt8)0x02 // CANAL_IDFLAG_RTR -#define TOUCAN_MSG_STS_FRAME (UInt8)0x04 // CANAL_IDFLAG_STATUS - -#define TOUCAN_STS_OK (UInt8)0x00 // CANAL_STATUSMSG_OK -#define TOUCAN_STS_OVERRUN (UInt8)0x01 // CANAL_STATUSMSG_OVERRUN -#define TOUCAN_STS_BUSLIGHT (UInt8)0x02 // CANAL_STATUSMSG_BUSLIGHT -#define TOUCAN_STS_BUSHEAVY (UInt8)0x03 // CANAL_STATUSMSG_BUSHEAVY -#define TOUCAN_STS_BUSOFF (UInt8)0x04 // CANAL_STATUSMSG_BUSOFF -#define TOUCAN_STS_STUFF (UInt8)0x20 // CANAL_STATUSMSG_STUFF -#define TOUCAN_STS_FORM (UInt8)0x21 // CANAL_STATUSMSG_FORM -#define TOUCAN_STS_ACK (UInt8)0x23 // CANAL_STATUSMSG_ACK -#define TOUCAN_STS_BIT1 (UInt8)0x24 // CANAL_STATUSMSG_BIT1 -#define TOUCAN_STS_BIT0 (UInt8)0x25 // CANAL_STATUSMSG_BIT0 -#define TOUCAN_STS_CRC (UInt8)0x27 // CANAL_STATUSMSG_CRC +#define TOUCAN_MSG_STD_FRAME (UInt8)0x00 +#define TOUCAN_MSG_XTD_FRAME (UInt8)0x01 +#define TOUCAN_MSG_RTR_FRAME (UInt8)0x02 +#define TOUCAN_MSG_STS_FRAME (UInt8)0x04 + +#define TOUCAN_STS_OK (UInt8)0x00 +#define TOUCAN_STS_OVERRUN (UInt8)0x01 +#define TOUCAN_STS_BUSLIGHT (UInt8)0x02 +#define TOUCAN_STS_BUSHEAVY (UInt8)0x03 +#define TOUCAN_STS_BUSOFF (UInt8)0x04 +#define TOUCAN_STS_STUFF (UInt8)0x20 +#define TOUCAN_STS_FORM (UInt8)0x21 +#define TOUCAN_STS_ACK (UInt8)0x23 +#define TOUCAN_STS_BIT1 (UInt8)0x24 +#define TOUCAN_STS_BIT0 (UInt8)0x25 +#define TOUCAN_STS_CRC (UInt8)0x27 static void ReceptionCallback(void *refCon, UInt8 *buffer, UInt32 length); static int TouCAN_EncodeMessage(UInt8 *buffer, const TouCAN_CanMessage_t *message); @@ -122,34 +148,34 @@ CANUSB_Return_t TouCAN_USB_InitializeChannel(TouCAN_Device_t *device, TouCAN_OpM goto end_init; } /* get device information (don't care about the result) */ - retVal = TouCAN_get_hardware_version(device->handle, &device->deviceInfo.hardware); + retVal = TouCAN_USB_CmdGetHardwareVersion(device->handle, &device->deviceInfo.hardware); if (retVal < 0) { MACCAN_DEBUG_ERROR("+++ %s (device #%u): hardware version could not be read (%i)\n", device->name, device->handle, retVal); } - retVal = TouCAN_get_firmware_version(device->handle, &device->deviceInfo.firmware); + retVal = TouCAN_USB_CmdGetFirmwareVersion(device->handle, &device->deviceInfo.firmware); if (retVal < 0) { MACCAN_DEBUG_ERROR("+++ %s (device #%u): firmware version could not be read (%i)\n", device->name, device->handle, retVal); } - retVal = TouCAN_get_bootloader_version(device->handle, &device->deviceInfo.bootloader); + retVal = TouCAN_USB_CmdGetBootloaderVersion(device->handle, &device->deviceInfo.bootloader); if (retVal < 0) { MACCAN_DEBUG_ERROR("+++ %s (device #%u): bootloader version could not be read (%i)\n", device->name, device->handle, retVal); } - retVal = TouCAN_get_serial_number(device->handle, &device->deviceInfo.serialNo); + retVal = TouCAN_USB_CmdGetSerialNumber(device->handle, &device->deviceInfo.serialNo); if (retVal < 0) { MACCAN_DEBUG_ERROR("+++ %s (device #%u): serial no. could not be read (%i)\n", device->name, device->handle, retVal); } - retVal = TouCAN_get_device_id(device->handle, &device->deviceInfo.deviceId); + retVal = TouCAN_USB_CmdGetDeviceId(device->handle, &device->deviceInfo.deviceId); if (retVal < 0) { MACCAN_DEBUG_ERROR("+++ %s (device #%u): device id. could not be read (%i)\n", device->name, device->handle, retVal); } - retVal = TouCAN_get_vid_pid(device->handle, &device->deviceInfo.vid_pid); + retVal = TouCAN_USB_CmdGetVidPid(device->handle, &device->deviceInfo.vid_pid); if (retVal < 0) { MACCAN_DEBUG_ERROR("+++ %s (device #%u): VID & PID could not be read (%i)\n", device->name, device->handle, retVal); } /* initialize with default bit-rate and mode flags */ /* note: CAN API provides this at a later stage */ - retVal = TouCAN_init(device->handle, device->bitRate.brp, device->bitRate.tseg1, - device->bitRate.tseg2, device->bitRate.sjw, 0x00000000U); + retVal = TouCAN_USB_CmdInitInterface(device->handle, device->bitRate.brp, device->bitRate.tseg1, + device->bitRate.tseg2, device->bitRate.sjw, 0x00000000U); if (retVal < 0) { MACCAN_DEBUG_ERROR("+++ %s (device #%u): device could not be initialized (%i)\n", device->name, device->handle, retVal); goto err_init; @@ -214,8 +240,8 @@ CANUSB_Return_t TouCAN_USB_SetBitrate(TouCAN_Device_t *device, const TouCAN_Bitr return CANUSB_ERROR_NOTINIT; /* set mode flags depending on the operation mode */ - modeFlags |= (device->opMode & CANMODE_MON) ? TouCAN_ENABLE_SILENT_MODE : 0x00000000U; - modeFlags |= (device->opMode & CANMODE_ERR) ? TouCAN_ENABLE_STATUS_MESSAGES : 0x00000000U; + modeFlags |= (device->opMode & CANMODE_MON) ? TOUCAN_ENABLE_SILENT_MODE : 0x00000000U; + modeFlags |= (device->opMode & CANMODE_ERR) ? TOUCAN_ENABLE_STATUS_MESSAGES : 0x00000000U; /* reset device state and pending errors */ retVal = TouCAN_ResetDevice(device->handle); @@ -224,12 +250,8 @@ CANUSB_Return_t TouCAN_USB_SetBitrate(TouCAN_Device_t *device, const TouCAN_Bitr goto end_set; } /* initialize with demanded bit-rate and mode-flags */ - retVal = TouCAN_init(device->handle, - bitrate->brp, - bitrate->tseg1, - bitrate->tseg2, - bitrate->sjw, - modeFlags); + retVal = TouCAN_USB_CmdInitInterface(device->handle, bitrate->brp, bitrate->tseg1, + bitrate->tseg2, bitrate->sjw, modeFlags); if (retVal < 0) { MACCAN_DEBUG_ERROR("+++ %s (device #%u): device could not be re-initialized (%i)\n", device->name, device->handle, retVal); goto end_set; @@ -251,7 +273,7 @@ CANUSB_Return_t TouCAN_USB_StartCan(TouCAN_Device_t *device) { return CANUSB_ERROR_NOTINIT; /* enter LISTENING state */ - retVal = TouCAN_start(device->handle); + retVal = TouCAN_USB_CmdStartInterface(device->handle); return retVal; } @@ -266,7 +288,7 @@ CANUSB_Return_t TouCAN_USB_StopCan(TouCAN_Device_t *device) { return CANUSB_ERROR_NOTINIT; /* enter READY state again */ - retVal = TouCAN_stop(device->handle); + retVal = TouCAN_USB_CmdStopInterface(device->handle); return retVal; } @@ -336,7 +358,7 @@ CANUSB_Return_t TouCAN_USB_GetBusStatus(TouCAN_Device_t *device, TouCAN_Status_t tmpStatus = device->recvData.msgParam.statusByte; /* get (and clear) interface error code */ - retVal = TouCAN_get_interface_error_code(device->handle, &errorCode); + retVal = TouCAN_USB_CmdGetInterfaceErrorCode(device->handle, &errorCode); if (retVal == CANUSB_SUCCESS) { // FIXME: error code is always 0 even when there are errors on the bus #if (0) @@ -359,7 +381,7 @@ CANUSB_Return_t TouCAN_USB_GetBusStatus(TouCAN_Device_t *device, TouCAN_Status_t HAL_CAN_ERROR_TX_TERR2)) ? CANSTAT_TX_BUSY :0; #endif } - (void)TouCAN_clear_interface_error_code(device->handle); + (void)TouCAN_USB_CmdClearInterfaceErrorCode(device->handle); /* return updated status register */ if (status) @@ -367,6 +389,53 @@ CANUSB_Return_t TouCAN_USB_GetBusStatus(TouCAN_Device_t *device, TouCAN_Status_t return retVal; } +CANUSB_Return_t TouCAN_USB_SetStdFilter(TouCAN_Device_t *device, uint32_t code, uint32_t mask) { + CANUSB_Return_t retVal = CANUSB_ERROR_FATAL; + + /* sanity check */ + if (!device) + return CANUSB_ERROR_NULLPTR; + if (!device->configured) + return CANUSB_ERROR_NOTINIT; + + /* set standard filter */ + retVal = TouCAN_USB_CmdSetStandardFilter(device->handle, FILTER_VALUE, code, mask); + + return retVal; +} + +CANUSB_Return_t TouCAN_USB_SetXtdFilter(TouCAN_Device_t *device, uint32_t code, uint32_t mask) { + CANUSB_Return_t retVal = CANUSB_ERROR_FATAL; + + /* sanity check */ + if (!device) + return CANUSB_ERROR_NULLPTR; + if (!device->configured) + return CANUSB_ERROR_NOTINIT; + + /* set extended filter */ + retVal = TouCAN_USB_CmdSetExtendedFilter(device->handle, FILTER_VALUE, code, mask); + + return retVal; +} + +CANUSB_Return_t TouCAN_USB_ResetFilters(TouCAN_Device_t *device) { + CANUSB_Return_t retStd = CANUSB_ERROR_FATAL; + CANUSB_Return_t retXtd = CANUSB_ERROR_FATAL; + + /* sanity check */ + if (!device) + return CANUSB_ERROR_NULLPTR; + if (!device->configured) + return CANUSB_ERROR_NOTINIT; + + /* reset both filters to accept all identifiers */ + retStd = TouCAN_USB_CmdSetStandardFilter(device->handle, FILTER_ACCEPT_ALL, 0x0U, 0x0U); + retXtd = TouCAN_USB_CmdSetExtendedFilter(device->handle, FILTER_ACCEPT_ALL, 0x0U, 0x0U); + + return (retStd != CANUSB_SUCCESS) ? retStd : retXtd; +} + bool TouCAN_USB_Index2Bitrate(int32_t index, TouCAN_Bitrate_t *bitrate) { bool retVal = true; @@ -436,27 +505,27 @@ static int TouCAN_ResetDevice(CANUSB_Handle_t handle) { UInt32 error = 0; /* get device state */ - retVal = TouCAN_get_interface_state(handle, &state); + retVal = TouCAN_USB_CmdGetInterfaceState(handle, &state); if (retVal < 0) return retVal; /* state LISTENING ==> state READY */ if (state == (UInt8)HAL_CAN_STATE_LISTENING) { - retVal = TouCAN_stop(handle); + retVal = TouCAN_USB_CmdStopInterface(handle); if (retVal < 0) return retVal; /* get new device state */ - retVal = TouCAN_get_interface_state(handle, &state); + retVal = TouCAN_USB_CmdGetInterfaceState(handle, &state); if (retVal < 0) return retVal; } /* state READY++ ==> state RESET */ if (state != (UInt8)HAL_CAN_STATE_RESET) { - retVal = TouCAN_deinit(handle); + retVal = TouCAN_USB_CmdDeinitInterface(handle); if (retVal < 0) return retVal; } /* get interface error code */ - retVal = TouCAN_get_interface_error_code(handle, &error); + retVal = TouCAN_USB_CmdGetInterfaceErrorCode(handle, &error); if (retVal < 0) return retVal; /* clear pending error(s) */ @@ -467,27 +536,27 @@ static int TouCAN_ResetDevice(CANUSB_Handle_t handle) { * RESET but the CAN controller is in an error state. We have first to * initialize the interface to reset the error and then to clear it. */ - retVal = TouCAN_init(handle, 10U, 14U, 5U, 4U, 0x00000000U); - //fprintf(stderr, "!!! TouCAN_init returned %i\n", retVal); + retVal = TouCAN_USB_CmdInitInterface(handle, 10U, 14U, 5U, 4U, 0x00000000U); + //fprintf(stderr, "!!! TouCAN_USB_CmdInitInterface returned %i\n", retVal); if (retVal < 0) return retVal; - retVal = TouCAN_clear_interface_error_code(handle); + retVal = TouCAN_USB_CmdClearInterfaceErrorCode(handle); //fprintf(stderr, "!!! TouCAN_clear_interface_error_code returned %i\n", retVal); if (retVal < 0) return retVal; /* again get interface error code, but in any case return an error */ - retVal = TouCAN_get_interface_error_code(handle, &error); - //fprintf(stderr, "!!! TouCAN_get_interface_error_code returned %i\n", retVal); + retVal = TouCAN_USB_CmdGetInterfaceErrorCode(handle, &error); + //fprintf(stderr, "!!! TouCAN_USB_CmdGetinterface_error_code returned %i\n", retVal); if (retVal < 0) return retVal; //fprintf(stderr, " interface error code is 0x%x\n", error); if (error != (UInt32)HAL_CAN_ERROR_NONE) retVal = (int)TOUCAN_ERROR_OFFSET - (int)99; // FATAL_ERROR; else - retVal = (int)TOUCAN_ERROR_OFFSET - (int)TouCAN_RETVAL_ERROR; + retVal = (int)TOUCAN_ERROR_OFFSET - (int)TOUCAN_RETVAL_ERROR; /* finally tear off all the crap */ - (void)TouCAN_stop(handle); - (void)TouCAN_deinit(handle); + (void)TouCAN_USB_CmdStopInterface(handle); + (void)TouCAN_USB_CmdDeinitInterface(handle); } return retVal; } diff --git a/Sources/Driver/TouCAN_USB_Driver.h b/Sources/Driver/TouCAN_USB_Driver.h index fac388d..3ed670e 100644 --- a/Sources/Driver/TouCAN_USB_Driver.h +++ b/Sources/Driver/TouCAN_USB_Driver.h @@ -1,11 +1,37 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* SPDX-License-Identifier: BSD-2-Clause OR GPL-3.0-or-later */ /* - * TouCAN - macOS User-Space Driver for Rusoku TouCAN USB Interfaces + * TouCAN - macOS User-Space Driver for Rusoku TouCAN USB Adapters * - * Copyright (C) 2020-2023 Uwe Vogt, UV Software, Berlin (info@mac-can.com) + * Copyright (c) 2020-2024 Uwe Vogt, UV Software, Berlin (info@mac-can.com) + * All rights reserved. * * This file is part of MacCAN-TouCAN. * + * MacCAN-TouCAN is dual-licensed under the BSD 2-Clause "Simplified" License + * and under the GNU General Public License v3.0 (or any later version). You can + * choose between one of them if you use MacCAN-TouCAN in whole or in part. + * + * BSD 2-Clause "Simplified" License: + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * MacCAN-TouCAN IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF MacCAN-TouCAN, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * GNU General Public License v3.0 or later: * MacCAN-TouCAN is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or @@ -71,6 +97,10 @@ extern CANUSB_Return_t TouCAN_USB_WriteMessage(TouCAN_Device_t *device, const To extern CANUSB_Return_t TouCAN_USB_ReadMessage(TouCAN_Device_t *device, TouCAN_CanMessage_t *message, uint16_t timeout); extern CANUSB_Return_t TouCAN_USB_GetBusStatus(TouCAN_Device_t *device, TouCAN_Status_t *status); +extern CANUSB_Return_t TouCAN_USB_SetStdFilter(TouCAN_Device_t *device, uint32_t code, uint32_t mask); +extern CANUSB_Return_t TouCAN_USB_SetXtdFilter(TouCAN_Device_t *device, uint32_t code, uint32_t mask); +extern CANUSB_Return_t TouCAN_USB_ResetFilters(TouCAN_Device_t *device); + extern bool TouCAN_USB_Index2Bitrate(int32_t index, TouCAN_Bitrate_t *bitrate); #ifdef __cplusplus diff --git a/Sources/Swift/CANAPI.swift b/Sources/Swift/CANAPI.swift index 940f5d3..88d47a4 100644 --- a/Sources/Swift/CANAPI.swift +++ b/Sources/Swift/CANAPI.swift @@ -2,13 +2,13 @@ // // CAN Interface API, Version 3 (Interface Definition) // -// Copyright (C) 2004-2023 Uwe Vogt, UV Software, Berlin (info@uv-software.com) +// Copyright (c) 2004-2024 Uwe Vogt, UV Software, Berlin (info@mac-can.com) // All rights reserved. // // This file is part of CAN API V3. // -// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License and -// under the GNU General Public License v3.0 (or any later version). +// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License +// and under the GNU General Public License v3.0 (or any later version). // You can choose between one of them if you use this file. // // BSD 2-Clause "Simplified" License: @@ -43,7 +43,7 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with CAN API V3. If not, see . +// along with CAN API V3. If not, see . // /*! CAN API V3 Swift Wrapper for generic CAN Interfaces. @@ -54,12 +54,12 @@ @author $Author: makemake $ - @version $Rev: 1196 $ + @version $Rev: 1277 $ */ import Foundation import CCanApi -private let version = (major: 0, minor: 3, patch: 2) +private let version = (major: 0, minor: 4, patch: 0) public class CanApi { private lazy var handle: CInt = -1 // CAN interface handle @@ -140,10 +140,15 @@ public class CanApi { public var isBitrateSwitchingEnabled: Bool { get { return 0x40 == self.rawValue & 0x40 } } public var isNonIsoOperationEnabled: Bool { get { return 0x20 == self.rawValue & 0x20 } } public var isSharedAccessEnabled : Bool { get { return 0x10 == self.rawValue & 0x10 } } + public var areExtendedFramesDisabled: Bool { get { return 0x08 == self.rawValue & 0x08 } } + public var areRemoteFramesDisabled: Bool { get { return 0x04 == self.rawValue & 0x04 } } + public var areErrorFramesEnabled: Bool { get { return 0x02 == self.rawValue & 0x02 } } + public var isMonitorModeEnabled: Bool { get { return 0x01 == self.rawValue & 0x01 } } + // --- deprecated --- public var isExtendedFramesDisabled: Bool { get { return 0x08 == self.rawValue & 0x08 } } public var isRemoteFramesDisabled: Bool { get { return 0x04 == self.rawValue & 0x04 } } public var isErrorFramesEnabled: Bool { get { return 0x02 == self.rawValue & 0x02 } } - public var isMonitorModeEnabled: Bool { get { return 0x01 == self.rawValue & 0x01 } } + public var isListenOnlyEnabled: Bool { get { return 0x01 == self.rawValue & 0x01 } } } /*! @brief CAN bit-rate settings (nominal and data phase): @@ -503,7 +508,7 @@ public class CanApi { case MessageLost = -10 // message lost case TransmitterBusy = -20 // transmitter busy case ReceiverEmpty = -30 // receiver empty - case ErrorFrame = -40 // error frame + case QueueOverrun = -40 // queue overrun case Timeout = -50 // timed out case ResourceError = -90 // resource allocation case InvalidBaudrate = -91 // illegal baudrate @@ -529,7 +534,7 @@ public class CanApi { case .MessageLost: return "message lost" case .TransmitterBusy: return "transmitter busy" case .ReceiverEmpty: return "receiver empty" - case .ErrorFrame: return "error frame" + case .QueueOverrun: return "queue overrun" case .Timeout: return "timed out" case .ResourceError: return "resource allocation" case .InvalidBaudrate: return "illegal baudrate" @@ -556,7 +561,7 @@ public class CanApi { /*! @brief constant: blocking read (wait infinitely) */ - public static let blocking = UInt16(CANREAD_INFINITE) + public static let blocking = UInt16(CANWAIT_INFINITE) // MARK: - properties @@ -626,6 +631,42 @@ public class CanApi { return Mode(rawValue: mode.byte) } } + /*! + @brief property: CAN acceptance filter for 11-bit identifier + */ + public var filter: (code: UInt32, mask: UInt32)? { + get { + var filter: UInt64 = 0 + let result: CInt = can_property(self.handle, UInt16(CANPROP_GET_FILTER_11BIT), &filter, UInt32(MemoryLayout.size)) + guard result == CANERR_NOERROR else { return nil } + return (code: UInt32(filter >> 32), mask: UInt32(filter & 0xFFFFFFFF)) + } + set { + if let value = newValue { + var filter: UInt64 = (UInt64(value.code) << 32) | UInt64(value.mask) + let result: CInt = can_property(self.handle, UInt16(CANPROP_SET_FILTER_11BIT), &filter, UInt32(MemoryLayout.size)) + guard result == CANERR_NOERROR else { return } + } + } + } + /*! + @brief property: CAN acceptance filter for 29-bit identifier + */ + public var xtdFilter: (code: UInt32, mask: UInt32)? { + get { + var filter: UInt64 = 0 + let result: CInt = can_property(self.handle, UInt16(CANPROP_GET_FILTER_29BIT), &filter, UInt32(MemoryLayout.size)) + guard result == CANERR_NOERROR else { return nil } + return (code: UInt32(filter >> 32), mask: UInt32(filter & 0xFFFFFFFF)) + } + set { + if let value = newValue { + var filter: UInt64 = (UInt64(value.code) << 32) | UInt64(value.mask) + let result: CInt = can_property(self.handle, UInt16(CANPROP_SET_FILTER_29BIT), &filter, UInt32(MemoryLayout.size)) + guard result == CANERR_NOERROR else { return } + } + } + } /*! @brief property: CAN statistical counters (read-only) */ @@ -1012,6 +1053,32 @@ public class CanApi { let result: CInt = can_property(self.handle, param, &array, nbyte) guard result == CANERR_NOERROR else { throw Error(rawValue: result) ?? Error.FatalError } } + public func GetFilter11Bit() throws -> (code: UInt32, mask: UInt32) { + var filter: UInt64 = 0 + let result: CInt = can_property(self.handle, UInt16(CANPROP_GET_FILTER_11BIT), &filter, UInt32(MemoryLayout.size)) + guard result == CANERR_NOERROR else { throw Error(rawValue: result) ?? Error.FatalError } + return (code: UInt32(filter >> 32), mask: UInt32(filter & 0xFFFFFFFF)) + } + public func SetFilter11Bit(code: UInt32, mask: UInt32) throws { + var filter: UInt64 = (UInt64(code) << 32) | UInt64(mask) + let result: CInt = can_property(self.handle, UInt16(CANPROP_SET_FILTER_11BIT), &filter, UInt32(MemoryLayout.size)) + guard result == CANERR_NOERROR else { throw Error(rawValue: result) ?? Error.FatalError } + } + public func GetFilter29Bit() throws -> (code: UInt32, mask: UInt32) { + var filter: UInt64 = 0 + let result: CInt = can_property(self.handle, UInt16(CANPROP_GET_FILTER_29BIT), &filter, UInt32(MemoryLayout.size)) + guard result == CANERR_NOERROR else { throw Error(rawValue: result) ?? Error.FatalError } + return (code: UInt32(filter >> 32), mask: UInt32(filter & 0xFFFFFFFF)) + } + public func SetFilter29Bit(code: UInt32, mask: UInt32) throws { + var filter: UInt64 = (UInt64(code) << 32) | UInt64(mask) + let result: CInt = can_property(self.handle, UInt16(CANPROP_SET_FILTER_29BIT), &filter, UInt32(MemoryLayout.size)) + guard result == CANERR_NOERROR else { throw Error(rawValue: result) ?? Error.FatalError } + } + public func ResetFilters() throws { + let result: CInt = can_property(self.handle, UInt16(CANPROP_SET_FILTER_RESET), nil, UInt32(0)) + guard result == CANERR_NOERROR else { throw Error(rawValue: result) ?? Error.FatalError } + } public func GetHardwareVersion() throws -> String { guard let version = can_hardware(self.handle) else { throw Error.NullPointer } return String(cString: version) @@ -1026,4 +1093,4 @@ public class CanApi { } } -// $Id: CANAPI.swift 1196 2023-09-06 17:55:16Z makemake $ Copyright (c) UV Software, Berlin // +// $Id: CANAPI.swift 1277 2024-04-22 09:04:58Z makemake $ Copyright (c) UV Software, Berlin // diff --git a/Sources/Swift/TouCAN.swift b/Sources/Swift/TouCAN.swift index a0e16ad..fa57f62 100644 --- a/Sources/Swift/TouCAN.swift +++ b/Sources/Swift/TouCAN.swift @@ -1,12 +1,37 @@ -// SPDX-License-Identifier: GPL-3.0-or-later +// SPDX-License-Identifier: BSD-2-Clause OR GPL-3.0-or-later // -// TouCAN - macOS User-Space Driver for Rusoku TouCAN USB Interfaces +// TouCAN - macOS User-Space Driver for Rusoku TouCAN USB Adapters // -// Copyright (c) 2020-2021 Uwe Vogt, UV Software, Berlin (info@mac-can.com) +// Copyright (c) 2020-2024 Uwe Vogt, UV Software, Berlin (info@mac-can.com) // All rights reserved. // // This file is part of MacCAN-TouCAN. // +// MacCAN-TouCAN is dual-licensed under the BSD 2-Clause "Simplified" License +// and under the GNU General Public License v3.0 (or any later version). You can +// choose between one of them if you use MacCAN-TouCAN in whole or in part. +// +// BSD 2-Clause "Simplified" License: +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// 1. Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// MacCAN-TouCAN IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF MacCAN-TouCAN, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// GNU General Public License v3.0 or later: // MacCAN-TouCAN is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or @@ -18,7 +43,7 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with MacCAN-TouCAN. If not, see . +// along with MacCAN-TouCAN. If not, see . // import Foundation diff --git a/Sources/TouCAN.cpp b/Sources/TouCAN.cpp index 7baf764..586c37e 100644 --- a/Sources/TouCAN.cpp +++ b/Sources/TouCAN.cpp @@ -1,11 +1,37 @@ -// SPDX-License-Identifier: GPL-3.0-or-later +// SPDX-License-Identifier: BSD-2-Clause OR GPL-3.0-or-later // -// TouCAN - macOS User-Space Driver for Rusoku TouCAN USB Interfaces +// TouCAN - macOS User-Space Driver for Rusoku TouCAN USB Adapters // -// Copyright (C) 2020-2023 Uwe Vogt, UV Software, Berlin (info@mac-can.com) +// Copyright (c) 2020-2024 Uwe Vogt, UV Software, Berlin (info@mac-can.com) +// All rights reserved. // // This file is part of MacCAN-TouCAN. // +// MacCAN-TouCAN is dual-licensed under the BSD 2-Clause "Simplified" License +// and under the GNU General Public License v3.0 (or any later version). You can +// choose between one of them if you use MacCAN-TouCAN in whole or in part. +// +// BSD 2-Clause "Simplified" License: +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// 1. Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// MacCAN-TouCAN IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF MacCAN-TouCAN, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// GNU General Public License v3.0 or later: // MacCAN-TouCAN is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or @@ -19,20 +45,9 @@ // You should have received a copy of the GNU General Public License // along with MacCAN-TouCAN. If not, see . // -#include "build_no.h" -#define VERSION_MAJOR 0 -#define VERSION_MINOR 2 -#define VERSION_PATCH 6 -#define VERSION_BUILD BUILD_NO -#define VERSION_STRING TOSTRING(VERSION_MAJOR) "." TOSTRING(VERSION_MINOR) "." TOSTRING(VERSION_PATCH) " (" TOSTRING(BUILD_NO) ")" -#if defined(__APPLE__) -#define PLATFORM "macOS" -#else -#error Unsupported architecture -#endif -static const char version[] = "CAN API V3 for Rusoku TouCAN USB Interfaces, Version " VERSION_STRING; - #include "TouCAN.h" +#include "Version.h" + #include "can_defs.h" #include "can_api.h" #include "can_btr.h" @@ -43,25 +58,16 @@ static const char version[] = "CAN API V3 for Rusoku TouCAN USB Interfaces, Vers #include #include -#if (OPTION_TOUCAN_DYLIB != 0) -__attribute__((constructor)) -static void _initializer() { - // default initializer -} -__attribute__((destructor)) -static void _finalizer() { - // default finalizer -} -#define EXPORT __attribute__((visibility("default"))) +#if defined(__APPLE__) +#define PLATFORM "macOS" #else -#define EXPORT +#error Platform not supported #endif - #ifndef _MSC_VER #define STRCPY_S(dest,size,src) strcpy(dest,src) #define STRNCPY_S(dest,size,src,len) strncpy(dest,src,len) #define SSCANF_S(buf,format,...) sscanf(buf,format,__VA_ARGS__) -#define SPRINTF_S(buf,size,format,...) sprintf(buf,format,__VA_ARGS__) +#define SPRINTF_S(buf,size,format,...) snprintf(buf,size,format,__VA_ARGS__) #else #define STRCPY_S(dest,size,src) strcpy_s(dest,size,src) #define STRNCPY_S(dest,size,src,len) strncpy_s(dest,size,src,len) @@ -71,25 +77,25 @@ static void _finalizer() { #define TOUCAN_USB_CLOCK_DOMAIN 50000000 // FIXME: replace this +#if (OPTION_TOUCAN_DYLIB != 0) +__attribute__((constructor)) +static void _initializer() { + // default initializer +} +__attribute__((destructor)) +static void _finalizer() { + // default finalizer +} +#define EXPORT __attribute__((visibility("default"))) +#else +#define EXPORT +#endif + +static const char version[] = "CAN API V3 for Rusoku TouCAN USB Interfaces, Version " VERSION_STRING; + EXPORT CTouCAN::CTouCAN() { m_Handle = (-1); - m_OpMode.byte = CANMODE_DEFAULT; - m_Bitrate.btr.frequency = TOUCAN_USB_CLOCK_DOMAIN; - m_Bitrate.btr.nominal.brp = 10; - m_Bitrate.btr.nominal.tseg1 = 14; - m_Bitrate.btr.nominal.tseg2 = 5; - m_Bitrate.btr.nominal.sjw = 4; - m_Bitrate.btr.nominal.sam = 0; -#if (OPTION_CAN_2_0_ONLY == 0) - m_Bitrate.btr.data.brp = m_Bitrate.btr.nominal.brp; - m_Bitrate.btr.data.tseg1 = m_Bitrate.btr.nominal.tseg1; - m_Bitrate.btr.data.tseg2 = m_Bitrate.btr.nominal.tseg2; - m_Bitrate.btr.data.sjw = m_Bitrate.btr.nominal.sjw; -#endif - m_Counter.u64TxMessages = 0U; - m_Counter.u64RxMessages = 0U; - m_Counter.u64ErrorFrames = 0U; } EXPORT @@ -106,7 +112,7 @@ bool CTouCAN::GetFirstChannel(SChannelInfo &info, void *param) { // set index to the first entry in the interface list (if any) CANAPI_Return_t rc = can_property((-1), CANPROP_SET_FIRST_CHANNEL, NULL, 0U); if (CANERR_NOERROR == rc) { - // get channel no, device name and device DLL name at actual index in the interface list + // get channel no, device name, etc. at actual index in the interface list if (((can_property((-1), CANPROP_GET_CHANNEL_NO, (void*)&info.m_nChannelNo, sizeof(int32_t))) == 0) && ((can_property((-1), CANPROP_GET_CHANNEL_NAME, (void*)&info.m_szDeviceName, CANPROP_MAX_BUFFER_SIZE)) == 0) && ((can_property((-1), CANPROP_GET_CHANNEL_DLLNAME, (void*)&info.m_szDeviceDllName, CANPROP_MAX_BUFFER_SIZE)) == 0)) { @@ -128,7 +134,7 @@ bool CTouCAN::GetNextChannel(SChannelInfo &info, void *param) { // set index to the next entry in the interface list (if any) CANAPI_Return_t rc = can_property((-1), CANPROP_SET_NEXT_CHANNEL, NULL, 0U); if (CANERR_NOERROR == rc) { - // get channel no, device name and device DLL name at actual index in the interface list + // get channel no, device name, etc. at actual index in the interface list if (((can_property((-1), CANPROP_GET_CHANNEL_NO, (void*)&info.m_nChannelNo, sizeof(int32_t))) == 0) && ((can_property((-1), CANPROP_GET_CHANNEL_NAME, (void*)&info.m_szDeviceName, CANPROP_MAX_BUFFER_SIZE)) == 0) && ((can_property((-1), CANPROP_GET_CHANNEL_DLLNAME, (void*)&info.m_szDeviceDllName, CANPROP_MAX_BUFFER_SIZE)) == 0)) { @@ -164,7 +170,6 @@ CANAPI_Return_t CTouCAN::InitializeChannel(int32_t channel, const CANAPI_OpMode_ CANAPI_Handle_t hnd = can_init(channel, opMode.byte, param); if (0 <= hnd) { m_Handle = hnd; // we got a handle - m_OpMode = opMode; rc = CANERR_NOERROR; } else { rc = (CANAPI_Return_t)hnd; @@ -198,12 +203,7 @@ CANAPI_Return_t CTouCAN::SignalChannel() { EXPORT CANAPI_Return_t CTouCAN::StartController(CANAPI_Bitrate_t bitrate) { // start the CAN controller with the given bit-rate settings - CANAPI_Return_t rc = can_start(m_Handle, &bitrate); - if (CANERR_NOERROR == rc) { - m_Bitrate = bitrate; - memset(&m_Counter, 0, sizeof(m_Counter)); - } - return rc; + return can_start(m_Handle, &bitrate); } EXPORT @@ -215,22 +215,13 @@ CANAPI_Return_t CTouCAN::ResetController() { EXPORT CANAPI_Return_t CTouCAN::WriteMessage(CANAPI_Message_t message, uint16_t timeout) { // transmit a message over the CAN bus - CANAPI_Return_t rc = can_write(m_Handle, &message, timeout); - if (CANERR_NOERROR == rc) { - m_Counter.u64TxMessages++; - } - return rc; + return can_write(m_Handle, &message, timeout); } EXPORT CANAPI_Return_t CTouCAN::ReadMessage(CANAPI_Message_t &message, uint16_t timeout) { // read one message from the message queue of the CAN interface, if any - CANAPI_Return_t rc = can_read(m_Handle, &message, timeout); - if (CANERR_NOERROR == rc) { - m_Counter.u64RxMessages += !message.sts ? 1U : 0U; - m_Counter.u64ErrorFrames += message.sts ? 1U : 0U; - } - return rc; + return can_read(m_Handle, &message, timeout); } EXPORT @@ -248,17 +239,13 @@ CANAPI_Return_t CTouCAN::GetBusLoad(uint8_t &load) { EXPORT CANAPI_Return_t CTouCAN::GetBitrate(CANAPI_Bitrate_t &bitrate) { // retrieve the bit-rate setting of the CAN interface - CANAPI_Return_t rc = can_bitrate(m_Handle, &bitrate, NULL); - if (CANERR_NOERROR == rc) { - m_Bitrate = bitrate; - } - return rc; + return can_bitrate(m_Handle, &bitrate, NULL); } EXPORT CANAPI_Return_t CTouCAN::GetBusSpeed(CANAPI_BusSpeed_t &speed) { // retrieve the transmission rate of the CAN interface - return can_bitrate(m_Handle, &m_Bitrate, &speed); + return can_bitrate(m_Handle, NULL, &speed); } EXPORT @@ -285,6 +272,50 @@ CANAPI_Return_t CTouCAN::SetProperty(uint16_t param, const void *value, uint32_t return can_property(m_Handle, param, (void*)value, nbyte); } +EXPORT +CANAPI_Return_t CTouCAN::SetFilter11Bit(uint32_t code, uint32_t mask) { + uint64_t filter = ((uint64_t)code << 32) | (uint64_t)mask; + // set the 11-bit acceptance filter of the CAN interface + return can_property(m_Handle, CANPROP_SET_FILTER_11BIT, (void*)&filter, sizeof(uint64_t)); +} + +EXPORT +CANAPI_Return_t CTouCAN::SetFilter29Bit(uint32_t code, uint32_t mask) { + uint64_t filter = ((uint64_t)code << 32) | (uint64_t)mask; + // set the 29-bit acceptance filter of the CAN interface + return can_property(m_Handle, CANPROP_SET_FILTER_29BIT, (void*)&filter, sizeof(uint64_t)); +} + +EXPORT +CANAPI_Return_t CTouCAN::GetFilter11Bit(uint32_t &code, uint32_t &mask) { + uint64_t filter = 0U; + // retrieve the 11-bit acceptance filter of the CAN interface + CANAPI_Return_t rc = can_property(m_Handle, CANPROP_GET_FILTER_11BIT, (void*)&filter, sizeof(uint64_t)); + if (CANERR_NOERROR == rc) { + code = (uint32_t)(filter >> 32); + mask = (uint32_t)(filter >> 0); + } + return rc; +} + +EXPORT +CANAPI_Return_t CTouCAN::GetFilter29Bit(uint32_t &code, uint32_t &mask) { + uint64_t filter = 0U; + // retrieve the 29-bit acceptance filter of the CAN interface + CANAPI_Return_t rc = can_property(m_Handle, CANPROP_GET_FILTER_29BIT, (void*)&filter, sizeof(uint64_t)); + if (CANERR_NOERROR == rc) { + code = (uint32_t)(filter >> 32); + mask = (uint32_t)(filter >> 0); + } + return rc; +} + +EXPORT +CANAPI_Return_t CTouCAN::ResetFilters() { + // reset all acceptance filters of the CAN interface + return can_property(m_Handle, CANPROP_SET_FILTER_RESET, NULL, 0U); +} + EXPORT char *CTouCAN::GetHardwareVersion() { // retrieve the hardware version of the CAN controller diff --git a/Sources/TouCAN.h b/Sources/TouCAN.h index f7a4e21..4afa6db 100644 --- a/Sources/TouCAN.h +++ b/Sources/TouCAN.h @@ -1,10 +1,37 @@ +// SPDX-License-Identifier: BSD-2-Clause OR GPL-3.0-or-later // -// TouCAN - macOS User-Space Driver for Rusoku TouCAN USB Interfaces +// TouCAN - macOS User-Space Driver for Rusoku TouCAN USB Adapters // -// Copyright (C) 2020-2023 Uwe Vogt, UV Software, Berlin (info@mac-can.com) +// Copyright (c) 2020-2024 Uwe Vogt, UV Software, Berlin (info@mac-can.com) +// All rights reserved. // // This file is part of MacCAN-TouCAN. // +// MacCAN-TouCAN is dual-licensed under the BSD 2-Clause "Simplified" License +// and under the GNU General Public License v3.0 (or any later version). You can +// choose between one of them if you use MacCAN-TouCAN in whole or in part. +// +// BSD 2-Clause "Simplified" License: +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// 1. Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// MacCAN-TouCAN IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF MacCAN-TouCAN, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// GNU General Public License v3.0 or later: // MacCAN-TouCAN is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or @@ -35,8 +62,8 @@ #define TOUCAN_LIBRARY_NAME "libTouCAN.dylib" #endif #define TOUCAN_LIBRARY_VENDOR "UV Software, Berlin" -#define TOUCAN_LIBRARY_LICENSE "GNU General Public License, Version 3" -#define TOUCAN_LIBRARY_COPYRIGHT "Copyright (C) 2020-2023 Uwe Vogt, UV Software, Berlin" +#define TOUCAN_LIBRARY_LICENSE "BSD-2-Clause OR GPL-3.0-or-later" +#define TOUCAN_LIBRARY_COPYRIGHT "Copyright (c) 2020-2024 by Uwe Vogt, UV Software, Berlin" #define TOUCAN_LIBRARY_HAZARD_NOTE "If you connect your CAN device to a real CAN network when using this library,\n" \ "you might damage your application." /// \} @@ -48,13 +75,6 @@ class CANCPP CTouCAN : public CCanApi { private: CANAPI_Handle_t m_Handle; ///< CAN interface handle - CANAPI_OpMode_t m_OpMode; ///< CAN operation mode - CANAPI_Bitrate_t m_Bitrate; ///< CAN bitrate settings - struct { - uint64_t u64TxMessages; ///< number of transmitted CAN messages - uint64_t u64RxMessages; ///< number of received CAN messages - uint64_t u64ErrorFrames; ///< number of received status messages - } m_Counter; public: // constructor / destructor CTouCAN(); @@ -79,7 +99,7 @@ class CANCPP CTouCAN : public CCanApi { CANAPI_Return_t ResetController(); CANAPI_Return_t WriteMessage(CANAPI_Message_t message, uint16_t timeout = 0U); - CANAPI_Return_t ReadMessage(CANAPI_Message_t &message, uint16_t timeout = CANREAD_INFINITE); + CANAPI_Return_t ReadMessage(CANAPI_Message_t &message, uint16_t timeout = CANWAIT_INFINITE); CANAPI_Return_t GetStatus(CANAPI_Status_t &status); CANAPI_Return_t GetBusLoad(uint8_t &load); @@ -90,6 +110,12 @@ class CANCPP CTouCAN : public CCanApi { CANAPI_Return_t GetProperty(uint16_t param, void *value, uint32_t nbyte); CANAPI_Return_t SetProperty(uint16_t param, const void *value, uint32_t nbyte); + CANAPI_Return_t SetFilter11Bit(uint32_t code, uint32_t mask); + CANAPI_Return_t SetFilter29Bit(uint32_t code, uint32_t mask); + CANAPI_Return_t GetFilter11Bit(uint32_t &code, uint32_t &mask); + CANAPI_Return_t GetFilter29Bit(uint32_t &code, uint32_t &mask); + CANAPI_Return_t ResetFilters(); + char *GetHardwareVersion(); // (for compatibility reasons) char *GetFirmwareVersion(); // (for compatibility reasons) static char *GetVersion(); // (for compatibility reasons) @@ -98,6 +124,9 @@ class CANCPP CTouCAN : public CCanApi { static CANAPI_Return_t MapString2Bitrate(const char *string, CANAPI_Bitrate_t &bitrate, bool &data, bool &sam); static CANAPI_Return_t MapBitrate2String(CANAPI_Bitrate_t bitrate, char *string, size_t length, bool data = false, bool sam = false); static CANAPI_Return_t MapBitrate2Speed(CANAPI_Bitrate_t bitrate, CANAPI_BusSpeed_t &speed); +public: + static uint8_t Dlc2Len(uint8_t dlc) { return CCanApi::Dlc2Len(dlc); } + static uint8_t Len2Dlc(uint8_t len) { return CCanApi::Len2Dlc(len); } }; /// \} @@ -113,8 +142,8 @@ class CANCPP CTouCAN : public CCanApi { #define TOUCAN_PROPERTY_LIBRARY_VENDOR (CANPROP_GET_LIBRARY_VENDOR) #define TOUCAN_PROPERTY_DEVICE_TYPE (CANPROP_GET_DEVICE_TYPE) #define TOUCAN_PROPERTY_DEVICE_NAME (CANPROP_GET_DEVICE_NAME) -#define TOUCAN_PROPERTY_DEVICE_DRIVER (CANPROP_GET_DEVICE_DLLNAME) #define TOUCAN_PROPERTY_DEVICE_VENDOR (CANPROP_GET_DEVICE_VENDOR) +#define TOUCAN_PROPERTY_DEVICE_DRIVER (CANPROP_GET_DEVICE_DLLNAME) #define TOUCAN_PROPERTY_OP_CAPABILITY (CANPROP_GET_OP_CAPABILITY) #define TOUCAN_PROPERTY_OP_MODE (CANPROP_GET_OP_MODE) #define TOUCAN_PROPERTY_BITRATE (CANPROP_GET_BITRATE) @@ -138,5 +167,4 @@ class CANCPP CTouCAN : public CCanApi { #define TOUCAN_PROPERTY_DEVICE_ID (TOUCAN_GET_DEVICE_ID) #define TOUCAN_PROPERTY_VENDOR_URL (TOUCAN_GET_VENDOR_URL) /// \} - #endif // TOUCAN_H_INCLUDED diff --git a/Sources/TouCAN_Defaults.h b/Sources/TouCAN_Defaults.h index 33a3b9b..0c57b09 100644 --- a/Sources/TouCAN_Defaults.h +++ b/Sources/TouCAN_Defaults.h @@ -1,23 +1,49 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* SPDX-License-Identifier: BSD-2-Clause OR GPL-3.0-or-later */ /* - * CAN Interface API, Version 3 (for Rusoku TouCAN Interface) + * TouCAN - macOS User-Space Driver for Rusoku TouCAN USB Adapters * - * Copyright (C) 2020-2023 Uwe Vogt, UV Software, Berlin (info@mac-can.com) + * Copyright (c) 2020-2024 Uwe Vogt, UV Software, Berlin (info@mac-can.com) + * All rights reserved. * * This file is part of MacCAN-TouCAN. * - * MacCAN-TouCAN is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by + * MacCAN-TouCAN is dual-licensed under the BSD 2-Clause "Simplified" License + * and under the GNU General Public License v3.0 (or any later version). You can + * choose between one of them if you use MacCAN-TouCAN in whole or in part. + * + * BSD 2-Clause "Simplified" License: + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * MacCAN-TouCAN IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF MacCAN-TouCAN, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * GNU General Public License v3.0 or later: + * MacCAN-TouCAN is free software : you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * MacCAN-TouCAN is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. + * GNU General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public License - * along with MacCAN-TouCAN. If not, see . + * You should have received a copy of the GNU General Public License + * along with MacCAN-TouCAN. If not, see . */ /** @addtogroup can_btr * @{ @@ -91,5 +117,5 @@ extern "C" { /* ---------------------------------------------------------------------- * Uwe Vogt, UV Software, Chausseestrasse 33 A, 10115 Berlin, Germany * Tel.: +49-30-46799872, Fax: +49-30-46799873, Mobile: +49-170-3801903 - * E-Mail: uwe.vogt@uv-software.de, Homepage: http://www.uv-software.de/ + * E-Mail: uwe.vogt@uv-software.de, Homepage: https://www.uv-software.de/ */ diff --git a/Sources/TouCAN_Defines.h b/Sources/TouCAN_Defines.h index 7cab2a4..ea13b8d 100644 --- a/Sources/TouCAN_Defines.h +++ b/Sources/TouCAN_Defines.h @@ -1,27 +1,53 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* SPDX-License-Identifier: BSD-2-Clause OR GPL-3.0-or-later */ /* - * CAN Interface API, Version 3 (for Rusoku TouCAN Interface) + * TouCAN - macOS User-Space Driver for Rusoku TouCAN USB Adapters * - * Copyright (C) 2020-2023 Uwe Vogt, UV Software, Berlin (info@mac-can.com) + * Copyright (c) 2020-2024 Uwe Vogt, UV Software, Berlin (info@mac-can.com) + * All rights reserved. * * This file is part of MacCAN-TouCAN. * - * MacCAN-TouCAN is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by + * MacCAN-TouCAN is dual-licensed under the BSD 2-Clause "Simplified" License + * and under the GNU General Public License v3.0 (or any later version). You can + * choose between one of them if you use MacCAN-TouCAN in whole or in part. + * + * BSD 2-Clause "Simplified" License: + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * MacCAN-TouCAN IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF MacCAN-TouCAN, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * GNU General Public License v3.0 or later: + * MacCAN-TouCAN is free software : you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * MacCAN-TouCAN is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. + * GNU General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public License - * along with MacCAN-TouCAN. If not, see . + * You should have received a copy of the GNU General Public License + * along with MacCAN-TouCAN. If not, see . + */ +/** @addtogroup can_api + * @{ */ - /** @addtogroup can_api - * @{ - */ #ifndef CANAPI_TOUCAN_H_INCLUDED #define CANAPI_TOUCAN_H_INCLUDED @@ -39,6 +65,16 @@ extern "C" { /* ----------- options ------------------------------------------------ */ +/** @name Compiler Switches + * @brief Options for conditional compilation. + * @{ */ +/** @note Set define OPTION_CAN_2_0_ONLY to a non-zero value to compile + * with CAN 2.0 frame format only (e.g. in the build environment). + */ +#ifndef OPTION_DISABLED +#define OPTION_DISABLED 0 /**< if a define is not defined, it is automatically set to 0 */ +#endif +/** @} */ /* ----------- defines ------------------------------------------------ */ @@ -83,10 +119,6 @@ extern "C" { #define TOUCAN_GET_VID_PID (CANPROP_GET_VENDOR_PROP + 0x16U) /**< VID & PID (uint23_t) */ #define TOUCAN_GET_DEVICE_ID (CANPROP_GET_VENDOR_PROP + 0x17U) /**< device id. (uint23_t) */ #define TOUCAN_GET_VENDOR_URL (CANPROP_GET_VENDOR_PROP + 0x18U) /**< URL of Rusoku's website (uint23_t) */ -#if (OPTION_TOUCAN_CANAL != 0) -#define TOUCAN_GET_CANAL_ERROR_STATUS (CANPROP_GET_VENDOR_PROP + 0xF0U) // CANAL API (r?) -#define TOUCAN_GET_CANAL_STATISTICS (CANPROP_GET_VENDOR_PROP + 0xF1U) // CANAL API (rw) -#endif #define TOUCAN_MAX_BUFFER_SIZE 256U /**< max. buffer size for CAN_GetValue/CAN_SetValue */ /** @} */ @@ -95,7 +127,7 @@ extern "C" { * @{ */ #define TOUCAN_LIB_ID 500 /**< library ID (CAN/COP API V1 compatible) */ #if defined(_WIN32) || defined (_WIN64) - #define TOUCAN_LIB_CANLIB "CANAL.dll" + #define TOUCAN_LIB_CANLIB "(none)" #define TOUCAN_LIB_WRAPPER "u3cantou.dll" #elif defined(__APPLE__) #define TOUCAN_LIB_CANLIB "(none)" @@ -110,8 +142,8 @@ extern "C" { * @{ */ #define TOUCAN_LIB_VENDOR "Rusoku technologijos UAB, Lithuania" #define TOUCAN_LIB_WEBSITE "www.rusoku.com" -#define TOUCAN_LIB_HAZARD_NOTE "Do not connect your CAN device to a real CAN network when using this program.\n" \ - "This can damage your application." +#define TOUCAN_LIB_HAZARD_NOTE "If you connect your CAN device to a real CAN network when using this library,\n" \ + "you might damage your application." /** @} */ #ifdef __cplusplus @@ -123,5 +155,5 @@ extern "C" { /* ---------------------------------------------------------------------- * Uwe Vogt, UV Software, Chausseestrasse 33 A, 10115 Berlin, Germany * Tel.: +49-30-46799872, Fax: +49-30-46799873, Mobile: +49-170-3801903 - * E-Mail: uwe.vogt@uv-software.de, Homepage: http://www.uv-software.de/ + * E-Mail: uwe.vogt@uv-software.de, Homepage: https://www.uv-software.de/ */ diff --git a/Sources/Version.h b/Sources/Version.h new file mode 100644 index 0000000..05981fd --- /dev/null +++ b/Sources/Version.h @@ -0,0 +1,60 @@ +/* SPDX-License-Identifier: BSD-2-Clause OR GPL-3.0-or-later */ +/* + * TouCAN - macOS User-Space Driver for Rusoku TouCAN USB Adapters + * + * Copyright (c) 2020-2024 Uwe Vogt, UV Software, Berlin (info@mac-can.com) + * All rights reserved. + * + * This file is part of MacCAN-TouCAN. + * + * MacCAN-TouCAN is dual-licensed under the BSD 2-Clause "Simplified" License + * and under the GNU General Public License v3.0 (or any later version). You can + * choose between one of them if you use MacCAN-TouCAN in whole or in part. + * + * BSD 2-Clause "Simplified" License: + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * MacCAN-TouCAN IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF MacCAN-TouCAN, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * GNU General Public License v3.0 or later: + * MacCAN-TouCAN is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * MacCAN-TouCAN is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with MacCAN-TouCAN. If not, see . + */ +#ifndef VERSION_H_INCLUDED +#define VERSION_H_INCLUDED +#include "build_no.h" +#define VERSION_MAJOR 0 +#define VERSION_MINOR 3 +#define VERSION_PATCH 0 +#define VERSION_BUILD BUILD_NO +#if (VERSION_PATCH == 0) +#define VERSION_STRING TOSTRING(VERSION_MAJOR) "." TOSTRING(VERSION_MINOR) " (" TOSTRING(BUILD_NO) ")" +#else +#define VERSION_STRING TOSTRING(VERSION_MAJOR) "." TOSTRING(VERSION_MINOR) "." TOSTRING(VERSION_PATCH) " (" TOSTRING(BUILD_NO) ")" +#endif +#endif diff --git a/Sources/Wrapper/can_api.c b/Sources/Wrapper/can_api.c index c0afef6..c78ac88 100644 --- a/Sources/Wrapper/can_api.c +++ b/Sources/Wrapper/can_api.c @@ -1,39 +1,58 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* SPDX-License-Identifier: BSD-2-Clause OR GPL-3.0-or-later */ /* - * CAN Interface API, Version 3 (for Rusoku TouCAN Interface) + * CAN Interface API, Version 3 (for Rusoku TouCAN Adapters) * - * Copyright (C) 2020-2023 Uwe Vogt, UV Software, Berlin (info@mac-can.com) + * Copyright (c) 2020-2024 Uwe Vogt, UV Software, Berlin (info@mac-can.com) + * All rights reserved. * * This file is part of MacCAN-TouCAN. * - * MacCAN-TouCAN is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by + * MacCAN-TouCAN is dual-licensed under the BSD 2-Clause "Simplified" License + * and under the GNU General Public License v3.0 (or any later version). You can + * choose between one of them if you use MacCAN-TouCAN in whole or in part. + * + * BSD 2-Clause "Simplified" License: + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * MacCAN-TouCAN IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF MacCAN-TouCAN, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * GNU General Public License v3.0 or later: + * MacCAN-TouCAN is free software : you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * MacCAN-TouCAN is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. + * GNU General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public License - * along with MacCAN-TouCAN. If not, see . + * You should have received a copy of the GNU General Public License + * along with MacCAN-TouCAN. If not, see . */ /** @addtogroup can_api * @{ */ -#include "build_no.h" -#define VERSION_MAJOR 0 -#define VERSION_MINOR 2 -#define VERSION_PATCH 6 -#define VERSION_BUILD BUILD_NO -#define VERSION_STRING TOSTRING(VERSION_MAJOR) "." TOSTRING(VERSION_MINOR) "." TOSTRING(VERSION_PATCH) " (" TOSTRING(BUILD_NO) ")" #if defined(__APPLE__) -#define PLATFORM "macOS" +#define PLATFORM "macOS" #else -#error Unsupported architecture +#error Platform not supported #endif -static const char version[] = "CAN API V3 for Rusoku TouCAN USB Interfaces, Version " VERSION_STRING; /* ----------- includes ----------------------------------------------- */ @@ -42,6 +61,7 @@ static const char version[] = "CAN API V3 for Rusoku TouCAN USB Interfaces, Vers #include "can_btr.h" #include "TouCAN_Driver.h" +#include "Version.h" #include #include @@ -49,12 +69,21 @@ static const char version[] = "CAN API V3 for Rusoku TouCAN USB Interfaces, Vers /* ----------- options ------------------------------------------------ */ +#if (OPTION_CAN_2_0_ONLY != 0) +#ifdef _MSC_VER +#pragma message ( "Compilation with legacy CAN 2.0 frame format!" ) +#else +#warning Compilation with legacy CAN 2.0 frame format! +#endif +#endif #if (OPTION_CANAPI_TOUCAN_DYLIB != 0) __attribute__((constructor)) static void _initializer() { + // default initializer } __attribute__((destructor)) static void _finalizer() { + // default finalizer } #define EXPORT __attribute__((visibility("default"))) #else @@ -69,7 +98,7 @@ static void _finalizer() { #define INVALID_HANDLE (-1) #define IS_HANDLE_VALID(hnd) ((0 <= (hnd)) && ((hnd) < CAN_MAX_HANDLES)) #ifndef DLC2LEN -#define DLC2LEN(x) dlc_table[(x) & 0xF] +#define DLC2LEN(x) dlc_table[((x) < 16) ? (x) : 15] #endif #ifndef LEN2DLC #define LEN2DLC(x) ((x) > 48) ? 0xF : \ @@ -80,9 +109,27 @@ static void _finalizer() { ((x) > 12) ? 0xA : \ ((x) > 8) ? 0x9 : (x) #endif +#define FILTER_STD_CODE (uint32_t)(0x000) +#define FILTER_STD_MASK (uint32_t)(0x000) +#define FILTER_XTD_CODE (uint32_t)(0x00000000) +#define FILTER_XTD_MASK (uint32_t)(0x00000000) + +#define LIB_ID TOUCAN_LIB_ID +#define LIB_DLLNAME TOUCAN_LIB_WRAPPER +#define DEV_VENDOR TOUCAN_LIB_VENDOR +#define DEV_DLLNAME TOUCAN_LIB_CANLIB +#define NUM_CHANNELS TOUCAN_BOARDS /* ----------- types -------------------------------------------------- */ +typedef struct { // message filtering: + struct { // acceptance filter: + uint32_t code; // acceptance code + uint32_t mask; // acceptance mask + } std, xtd; // for standard and extended frames + bool reset; // flag to reset std. and xtd. filter +} can_filter_t; + typedef struct { // frame counters: uint64_t tx; // number of transmitted CAN frames uint64_t rx; // number of received CAN frames @@ -92,20 +139,27 @@ typedef struct { // frame counters: typedef struct { // TouCAN interface: TouCAN_Device_t device; // USB device descriptor can_mode_t mode; // CAN operation mode + can_filter_t filter; // message filter settings can_status_t status; // 8-bit status register can_counter_t counters; // statistical counters } can_interface_t; /* ----------- prototypes --------------------------------------------- */ +static void var_init(void); // initialize variables + +static int set_filter(int handle, uint64_t filter, bool xtd); +static int reset_filter(int handle); + static int lib_parameter(uint16_t param, void *value, size_t nbyte); static int drv_parameter(int handle, uint16_t param, void *value, size_t nbyte); /* ----------- variables ---------------------------------------------- */ +static const char version[] = "CAN API V3 for Rusoku TouCAN USB Interfaces, Version " VERSION_STRING; + EXPORT -can_board_t can_boards[8+1] = { // list of supported CAN Interfaces - // TODO: rework this (either by an own can_defs.h or by a json file) +can_board_t can_boards[NUM_CHANNELS+1] = { // list of supported CAN channels {TOUCAN_USB_CHANNEL0, (char *)"TouCAN-USB1"}, {TOUCAN_USB_CHANNEL1, (char *)"TouCAN-USB2"}, {TOUCAN_USB_CHANNEL2, (char *)"TouCAN-USB3"}, @@ -120,7 +174,7 @@ can_board_t can_boards[8+1] = { // list of supported CAN Interfaces // 0,1,2,3,4,5,6,7,8,12,16,20,24,32,48,64 //}; static can_interface_t can[CAN_MAX_HANDLES]; // interface handles -static int init = 0; // initialization flag +static int init = 0; // initialization flag /* ----------- functions ---------------------------------------------- */ @@ -128,17 +182,11 @@ EXPORT int can_test(int32_t channel, uint8_t mode, const void *param, int *result) { int rc = CANERR_FATAL; // return value - int i; if (result) // the last resort *result = CANBRD_NOT_TESTABLE; if (!init) { // when not initialized: - for (i = 0; i < CAN_MAX_HANDLES; i++) { - memset(&can[i], 0, sizeof(can_interface_t)); - can[i].device.configured = false; - can[i].mode.byte = CANMODE_DEFAULT; - can[i].status.byte = CANSTAT_RESET; - } + var_init(); // initialize the variables // initialize the driver (MacCAN-Core driver) if ((rc = TouCAN_InitializeDriver()) != CANERR_NOERROR) return rc; @@ -166,15 +214,9 @@ EXPORT int can_init(int32_t channel, uint8_t mode, const void *param) { int rc = CANERR_FATAL; // return value - int i; if (!init) { // when not initialized: - for (i = 0; i < CAN_MAX_HANDLES; i++) { - memset(&can[i], 0, sizeof(can_interface_t)); - can[i].device.configured = false; - can[i].mode.byte = CANMODE_DEFAULT; - can[i].status.byte = CANSTAT_RESET; - } + var_init(); // initialize the variables // initialize the driver (MacCAN-Core driver) if ((rc = TouCAN_InitializeDriver()) != CANERR_NOERROR) return rc; @@ -209,7 +251,7 @@ int can_exit(int handle) if (handle != CANEXIT_ALL) { if (!IS_HANDLE_VALID(handle)) // must be a valid handle return CANERR_HANDLE; - if (!can[handle].device.configured) // must be an opened handle + if (!can[handle].device.configured) // must be an open handle return CANERR_HANDLE; /*if (!can[handle].status.can_stopped) // go to CAN INIT mode (bus off)*/ (void)TouCAN_StopCan(&can[handle].device); @@ -220,7 +262,7 @@ int can_exit(int handle) } else { for (i = 0; i < CAN_MAX_HANDLES; i++) { - if (can[i].device.configured) // must be an opened handle + if (can[i].device.configured) // must be an open handle { /*if (!can[handle].status.can_stopped) // go to CAN INIT mode (bus off)*/ (void)TouCAN_StopCan(&can[i].device); @@ -252,14 +294,14 @@ int can_kill(int handle) if (handle != CANEXIT_ALL) { if (!IS_HANDLE_VALID(handle)) // must be a valid handle return CANERR_HANDLE; - if (!can[handle].device.configured) // must be an opened handle + if (!can[handle].device.configured) // must be an open handle return CANERR_HANDLE; if ((rc = TouCAN_SignalChannel(&can[handle].device)) < CANERR_NOERROR) return rc; } else { for (i = 0; i < CAN_MAX_HANDLES; i++) { - if (can[i].device.configured) // must be an opened handle + if (can[i].device.configured) // must be an open handle (void)TouCAN_SignalChannel(&can[i].device); } } @@ -278,7 +320,7 @@ int can_start(int handle, const can_bitrate_t *bitrate) return CANERR_NOTINIT; if (!IS_HANDLE_VALID(handle)) // must be a valid handle return CANERR_HANDLE; - if (!can[handle].device.configured) // must be an opened handle + if (!can[handle].device.configured) // must be an open handle return CANERR_HANDLE; if (bitrate == NULL) // check for null-pointer return CANERR_NULLPTR; @@ -303,7 +345,7 @@ int can_start(int handle, const can_bitrate_t *bitrate) if (bitrate->btr.frequency != (int32_t)can[handle].device.canClock) return CANERR_BAUDRATE; // note: bit-rate settings are checked by the conversion function - if (btr_check_bitrate(bitrate, fdoe, brse) < 0) + if (btr_check_bitrate(bitrate, fdoe, brse) < CANERR_NOERROR) return CANERR_BAUDRATE; touBitrate.brp = bitrate->btr.nominal.brp; touBitrate.tseg1 = bitrate->btr.nominal.tseg1; @@ -311,7 +353,7 @@ int can_start(int handle, const can_bitrate_t *bitrate) touBitrate.sjw = bitrate->btr.nominal.sjw; } // set bit-rate (with respect of the selected operation mode) - if ((rc = TouCAN_SetBitrate(&can[handle].device, &touBitrate)) < 0) + if ((rc = TouCAN_SetBitrate(&can[handle].device, &touBitrate)) < CANERR_NOERROR) return (rc != CANUSB_ERROR_ILLPARA) ? rc : CANERR_BAUDRATE; // clear status, counters, and the receive queue can[handle].status.byte = CANSTAT_RESET; @@ -319,8 +361,24 @@ int can_start(int handle, const can_bitrate_t *bitrate) can[handle].counters.rx = 0U; can[handle].counters.err = 0U; (void)CANQUE_Reset(can[handle].device.recvData.msgQueue); + // start the CAN controller with the selected operation mode - rc = TouCAN_StartCan(&can[handle].device); + if ((rc = TouCAN_StartCan(&can[handle].device)) < CANERR_NOERROR) + return rc; + // set acceptance filter (can only be set when the CAN controller has been started) + if (!can[handle].filter.reset) { + if ((rc = TouCAN_SetStdFilter(&can[handle].device, + can[handle].filter.std.code, + can[handle].filter.std.mask)) == CANERR_NOERROR) + rc = TouCAN_SetXtdFilter(&can[handle].device, + can[handle].filter.xtd.code, + can[handle].filter.xtd.mask); + } else { + rc = TouCAN_ResetFilters(&can[handle].device); + } + if (rc != CANERR_NOERROR) // on error: stop the CAN controller + (void)TouCAN_StopCan(&can[handle].device); + // set the status bit accordingly can[handle].status.can_stopped = (rc == CANUSB_SUCCESS) ? 0 : 1; return rc; } @@ -334,13 +392,13 @@ int can_reset(int handle) return CANERR_NOTINIT; if (!IS_HANDLE_VALID(handle)) // must be a valid handle return CANERR_HANDLE; - if (!can[handle].device.configured) // must be an opened handle + if (!can[handle].device.configured) // must be an open handle return CANERR_HANDLE; if (can[handle].status.can_stopped) // must be running #ifndef OPTION_CANAPI_RETVALS return CANERR_OFFLINE; #else - // note: can_reset shall return CANERR_NOERROR even when + // note: can_reset shall return CANERR_NOERROR even if // the CAN controller has not been started return CANERR_NOERROR; #endif @@ -359,7 +417,7 @@ int can_write(int handle, const can_message_t *message, uint16_t timeout) return CANERR_NOTINIT; if (!IS_HANDLE_VALID(handle)) // must be a valid handle return CANERR_HANDLE; - if (!can[handle].device.configured) // must be an opened handle + if (!can[handle].device.configured) // must be an open handle return CANERR_HANDLE; if (message == NULL) // check for null-pointer return CANERR_NULLPTR; @@ -402,7 +460,7 @@ int can_read(int handle, can_message_t *message, uint16_t timeout) return CANERR_NOTINIT; if (!IS_HANDLE_VALID(handle)) // must be a valid handle return CANERR_HANDLE; - if (!can[handle].device.configured) // must be an opened handle + if (!can[handle].device.configured) // must be an open handle return CANERR_HANDLE; if (message == NULL) // check for null-pointer return CANERR_NULLPTR; @@ -429,7 +487,7 @@ int can_status(int handle, uint8_t *status) return CANERR_NOTINIT; if (!IS_HANDLE_VALID(handle)) // must be a valid handle return CANERR_HANDLE; - if (!can[handle].device.configured) // must be an opened handle + if (!can[handle].device.configured) // must be an open handle return CANERR_HANDLE; // get status-register from device (CAN API V1 compatible) @@ -455,7 +513,7 @@ int can_busload(int handle, uint8_t *load, uint8_t *status) return CANERR_NOTINIT; if (!IS_HANDLE_VALID(handle)) // must be a valid handle return CANERR_HANDLE; - if (!can[handle].device.configured) // must be an opened handle + if (!can[handle].device.configured) // must be an open handle return CANERR_HANDLE; #if (0) @@ -490,7 +548,7 @@ int can_bitrate(int handle, can_bitrate_t *bitrate, can_speed_t *speed) return CANERR_NOTINIT; if (!IS_HANDLE_VALID(handle)) // must be a valid handle return CANERR_HANDLE; - if (!can[handle].device.configured) // must be an opened handle + if (!can[handle].device.configured) // must be an open handle return CANERR_HANDLE; // get bit-rate settings from device @@ -501,14 +559,14 @@ int can_bitrate(int handle, can_bitrate_t *bitrate, can_speed_t *speed) tmpBitrate.btr.nominal.sjw = can[handle].device.bitRate.sjw; tmpBitrate.btr.nominal.sam = 0U; // note: SAM not used by TouCAN // calculate bus speed from bit-rate settings - if ((rc = btr_bitrate2speed(&tmpBitrate, &tmpSpeed)) < 0) + if ((rc = btr_bitrate2speed(&tmpBitrate, &tmpSpeed)) < CANERR_NOERROR) return CANERR_BAUDRATE; if (bitrate) memcpy(bitrate, &tmpBitrate, sizeof(can_bitrate_t)); if (speed) memcpy(speed, &tmpSpeed, sizeof(can_speed_t)); #ifdef OPTION_CANAPI_RETVALS - // note: can_bitrate shall return CANERR_OFFLINE when + // note: can_bitrate shall return CANERR_OFFLINE if // the CAN controller has not been started if (can[handle].status.can_stopped) rc = CANERR_OFFLINE; @@ -527,7 +585,7 @@ int can_property(int handle, uint16_t param, void *value, uint32_t nbyte) return CANERR_NOTINIT; if (!IS_HANDLE_VALID(handle)) // must be a valid handle return CANERR_HANDLE; - if (!can[handle].device.configured) // must be an opened handle + if (!can[handle].device.configured) // must be an open handle return CANERR_HANDLE; // note: device properties must be queried with a valid handle return drv_parameter(handle, param, value, (size_t)nbyte); @@ -542,16 +600,15 @@ char *can_hardware(int handle) return NULL; if (!IS_HANDLE_VALID(handle)) // must be a valid handle return NULL; - if (!can[handle].device.configured) // must be an opened handle + if (!can[handle].device.configured) // must be an open handle return NULL; - // get hardware version (zero-terminated string) + // return hardware version (zero-terminated string) uint8_t major = (uint8_t)(can[handle].device.deviceInfo.hardware >> 24); uint8_t minor = (uint8_t)(can[handle].device.deviceInfo.hardware >> 16); uint8_t patch = (uint8_t)(can[handle].device.deviceInfo.hardware >> 8); sprintf(string, "%s, hardware %u.%u.%u (s/n %08x)", can[handle].device.deviceInfo.name, major, minor, patch, can[handle].device.deviceInfo.serialNo); - return string; } @@ -564,33 +621,94 @@ char *can_firmware(int handle) return NULL; if (!IS_HANDLE_VALID(handle)) // must be a valid handle return NULL; - if (!can[handle].device.configured) // must be an opened handle + if (!can[handle].device.configured) // must be an open handle return NULL; - // get firmware version (zero-terminated string) + // return firmware version (zero-terminated string) uint8_t major = (uint8_t)(can[handle].device.deviceInfo.firmware >> 24); uint8_t minor = (uint8_t)(can[handle].device.deviceInfo.firmware >> 16); uint8_t patch = (uint8_t)(can[handle].device.deviceInfo.firmware >> 8); sprintf(string, "%s, firmware %u.%u.%u (%s)", can[handle].device.deviceInfo.name, major, minor, patch, can[handle].device.website); - return string; } /* ----------- local functions ---------------------------------------- */ +static void var_init(void) +{ + int i; + + for (i = 0; i < CAN_MAX_HANDLES; i++) { + memset(&can[i], 0, sizeof(can_interface_t)); + can[i].device.configured = false; + can[i].mode.byte = CANMODE_DEFAULT; + can[i].status.byte = CANSTAT_RESET; + can[i].filter.reset = true; + can[i].filter.std.code = FILTER_STD_CODE; + can[i].filter.std.mask = FILTER_STD_MASK; + can[i].filter.xtd.code = FILTER_XTD_CODE; + can[i].filter.xtd.mask = FILTER_XTD_MASK; + //can[i].error.lec = 0x00u; + //can[i].error.rx_err = 0u; + //can[i].error.tx_err = 0u; + can[i].counters.tx = 0ull; + can[i].counters.rx = 0ull; + can[i].counters.err = 0ull; + } +} + +static int set_filter(int handle, uint64_t filter, bool xtd) +{ + assert(IS_HANDLE_VALID(handle)); // just to make sure + + /* the acceptance code and mask are coded together in a 64-bit value, each of them using 4 bytes + * the acceptance code is in the most significant bytes, the mask in the least significant bytes + */ + unsigned int code = (unsigned int)((filter >> 32)) & (unsigned int)(xtd ? CAN_MAX_XTD_ID : CAN_MAX_STD_ID); + unsigned int mask = (unsigned int)((filter >> 0)) & (unsigned int)(xtd ? CAN_MAX_XTD_ID : CAN_MAX_STD_ID); + + /* store the acceptance filter values: + * a) they can only be set when the controller has been started + * b) they cannot be read directly from the controller + */ + if (!xtd) { + can[handle].filter.std.code = code; + can[handle].filter.std.mask = mask; + } else { + can[handle].filter.xtd.code = code; + can[handle].filter.xtd.mask = mask; + } + can[handle].filter.reset = false; + + return CANERR_NOERROR; +} + +static int reset_filter(int handle) +{ + assert(IS_HANDLE_VALID(handle)); // just to make sure + + /* reset the acceptance filter for standard and extended identifier */ + can[handle].filter.reset = true; + can[handle].filter.std.code = FILTER_STD_CODE; + can[handle].filter.std.mask = FILTER_STD_MASK; + can[handle].filter.xtd.code = FILTER_XTD_CODE; + can[handle].filter.xtd.mask = FILTER_XTD_MASK; + + return CANERR_NOERROR; +} /* - - - - - - CAN API V3 properties - - - - - - - - - - - - - - - - - */ static int lib_parameter(uint16_t param, void *value, size_t nbyte) { int rc = CANERR_ILLPARA; // suppose an invalid parameter - static int idx_board = EOF; // actual index in the interface list if (value == NULL) { // check for null-pointer if ((param != CANPROP_SET_FIRST_CHANNEL) && - (param != CANPROP_SET_NEXT_CHANNEL)) + (param != CANPROP_SET_NEXT_CHANNEL) && + (param != CANPROP_SET_FILTER_RESET)) return CANERR_NULLPTR; } /* CAN library properties */ @@ -604,7 +722,7 @@ static int lib_parameter(uint16_t param, void *value, size_t nbyte) case CANPROP_GET_VERSION: // version number of the library (uint16_t) if (nbyte >= sizeof(uint16_t)) { *(uint16_t*)value = ((uint16_t)VERSION_MAJOR << 8) - | ((uint16_t)VERSION_MINOR & 0xFu); + | ((uint16_t)VERSION_MINOR & 0xFU); rc = CANERR_NOERROR; } break; @@ -622,7 +740,7 @@ static int lib_parameter(uint16_t param, void *value, size_t nbyte) break; case CANPROP_GET_LIBRARY_ID: // library id of the library (int32_t) if (nbyte >= sizeof(int32_t)) { - *(int32_t*)value = (int32_t)TOUCAN_LIB_ID; + *(int32_t*)value = (int32_t)LIB_ID; rc = CANERR_NOERROR; } break; @@ -633,20 +751,20 @@ static int lib_parameter(uint16_t param, void *value, size_t nbyte) } break; case CANPROP_GET_LIBRARY_DLLNAME: // file name of the library (char[256]) - if ((nbyte > strlen(TOUCAN_LIB_WRAPPER)) && (nbyte <= CANPROP_MAX_BUFFER_SIZE)) { - strcpy((char*)value, TOUCAN_LIB_WRAPPER); + if ((nbyte > strlen(LIB_DLLNAME)) && (nbyte <= CANPROP_MAX_BUFFER_SIZE)) { + strcpy((char*)value, LIB_DLLNAME); rc = CANERR_NOERROR; } break; case CANPROP_GET_DEVICE_VENDOR: // vendor name of the CAN interface (char[256]) - if ((nbyte > strlen(TOUCAN_LIB_VENDOR)) && (nbyte <= CANPROP_MAX_BUFFER_SIZE)) { - strcpy((char*)value, TOUCAN_LIB_VENDOR); + if ((nbyte > strlen(DEV_VENDOR)) && (nbyte <= CANPROP_MAX_BUFFER_SIZE)) { + strcpy((char*)value, DEV_VENDOR); rc = CANERR_NOERROR; } break; - case CANPROP_GET_DEVICE_DLLNAME: // file name of the CAN interface (char[256]) - if ((nbyte > strlen(TOUCAN_LIB_CANLIB)) && (nbyte <= CANPROP_MAX_BUFFER_SIZE)) { - strcpy((char*)value, TOUCAN_LIB_CANLIB); + case CANPROP_GET_DEVICE_DLLNAME: // file name of the CAN interface DLL (char[256]) + if ((nbyte > strlen(DEV_DLLNAME)) && (nbyte <= CANPROP_MAX_BUFFER_SIZE)) { + strcpy((char*)value, DEV_DLLNAME); rc = CANERR_NOERROR; } break; @@ -655,7 +773,7 @@ static int lib_parameter(uint16_t param, void *value, size_t nbyte) rc = (can_boards[idx_board].type != EOF) ? CANERR_NOERROR : CANERR_RESOURCE; break; case CANPROP_SET_NEXT_CHANNEL: // set index to the next entry in the interface list (NULL) - if ((0 <= idx_board) && (idx_board < TOUCAN_BOARDS)) { + if ((0 <= idx_board) && (idx_board < NUM_CHANNELS)) { if (can_boards[idx_board].type != EOF) idx_board++; rc = (can_boards[idx_board].type != EOF) ? CANERR_NOERROR : CANERR_RESOURCE; @@ -663,9 +781,9 @@ static int lib_parameter(uint16_t param, void *value, size_t nbyte) else rc = CANERR_RESOURCE; break; - case CANPROP_GET_CHANNEL_TYPE: // get device type at actual index in the interface list (int32_t) + case CANPROP_GET_CHANNEL_NO: // get channel no. at actual index in the interface list (int32_t) if (nbyte >= sizeof(int32_t)) { - if ((0 <= idx_board) && (idx_board < TOUCAN_BOARDS) && + if ((0 <= idx_board) && (idx_board < NUM_CHANNELS) && (can_boards[idx_board].type != EOF)) { *(int32_t*)value = (int32_t)can_boards[idx_board].type; rc = CANERR_NOERROR; @@ -674,9 +792,9 @@ static int lib_parameter(uint16_t param, void *value, size_t nbyte) rc = CANERR_RESOURCE; } break; - case CANPROP_GET_CHANNEL_NAME: // get device name at actual index in the interface list (char[256]) + case CANPROP_GET_CHANNEL_NAME: // get channel name at actual index in the interface list (char[256]) if ((0U < nbyte) && (nbyte <= CANPROP_MAX_BUFFER_SIZE)) { - if ((0 <= idx_board) && (idx_board < TOUCAN_BOARDS) && + if ((0 <= idx_board) && (idx_board < NUM_CHANNELS) && (can_boards[idx_board].type != EOF)) { strncpy((char*)value, can_boards[idx_board].name, nbyte); ((char*)value)[(nbyte - 1)] = '\0'; @@ -688,9 +806,9 @@ static int lib_parameter(uint16_t param, void *value, size_t nbyte) break; case CANPROP_GET_CHANNEL_DLLNAME: // get file name of the DLL at actual index in the interface list (char[256]) if ((0U < nbyte) && (nbyte <= CANPROP_MAX_BUFFER_SIZE)) { - if ((0 <= idx_board) && (idx_board < TOUCAN_BOARDS) && + if ((0 <= idx_board) && (idx_board < NUM_CHANNELS) && (can_boards[idx_board].type != EOF)) { - strncpy((char*)value, TOUCAN_LIB_CANLIB, nbyte); + strncpy((char*)value, DEV_DLLNAME, nbyte); ((char*)value)[(nbyte - 1)] = '\0'; rc = CANERR_NOERROR; } @@ -700,9 +818,9 @@ static int lib_parameter(uint16_t param, void *value, size_t nbyte) break; case CANPROP_GET_CHANNEL_VENDOR_ID: // get library id at actual index in the interface list (int32_t) if (nbyte >= sizeof(int32_t)) { - if ((0 <= idx_board) && (idx_board < TOUCAN_BOARDS) && + if ((0 <= idx_board) && (idx_board < NUM_CHANNELS) && (can_boards[idx_board].type != EOF)) { - *(int32_t*)value = (int32_t)TOUCAN_LIB_ID; + *(int32_t*)value = (int32_t)LIB_ID; rc = CANERR_NOERROR; } else @@ -711,9 +829,9 @@ static int lib_parameter(uint16_t param, void *value, size_t nbyte) break; case CANPROP_GET_CHANNEL_VENDOR_NAME: // get vendor name at actual index in the interface list (char[256]) if ((0U < nbyte) && (nbyte <= CANPROP_MAX_BUFFER_SIZE)) { - if ((0 <= idx_board) && (idx_board < TOUCAN_BOARDS) && + if ((0 <= idx_board) && (idx_board < NUM_CHANNELS) && (can_boards[idx_board].type != EOF)) { - strncpy((char*)value, TOUCAN_LIB_VENDOR, nbyte); + strncpy((char*)value, DEV_VENDOR, nbyte); ((char*)value)[(nbyte - 1)] = '\0'; rc = CANERR_NOERROR; } @@ -728,7 +846,7 @@ static int lib_parameter(uint16_t param, void *value, size_t nbyte) case CANPROP_GET_BITRATE: // active bit-rate of the CAN controller (can_bitrate_t) case CANPROP_GET_SPEED: // active bus speed of the CAN controller (can_speed_t) case CANPROP_GET_STATUS: // current status register of the CAN controller (uint8_t) - case CANPROP_GET_BUSLOAD: // current bus load of the CAN controller (uint8_t) + case CANPROP_GET_BUSLOAD: // current bus load of the CAN controller (uint16_t) case CANPROP_GET_NUM_CHANNELS: // numbers of CAN channels on the CAN interface (uint8_t) case CANPROP_GET_CAN_CHANNEL: // active CAN channel on the CAN interface (uint8_t) case CANPROP_GET_CAN_CLOCK: // frequency of the CAN controller clock in [Hz] (int32_t) @@ -738,6 +856,18 @@ static int lib_parameter(uint16_t param, void *value, size_t nbyte) case CANPROP_GET_RCV_QUEUE_SIZE: // maximum number of message the receive queue can hold (uint32_t) case CANPROP_GET_RCV_QUEUE_HIGH: // maximum number of message the receive queue has hold (uint32_t) case CANPROP_GET_RCV_QUEUE_OVFL: // overflow counter of the receive queue (uint64_t) + case CANPROP_GET_FILTER_11BIT: // acceptance filter code and mask for 11-bit identifier (uint64_t) + case CANPROP_GET_FILTER_29BIT: // acceptance filter code and mask for 29-bit identifier (uint64_t) + case CANPROP_SET_FILTER_11BIT: // set value for acceptance filter code and mask for 11-bit identifier (uint64_t) + case CANPROP_SET_FILTER_29BIT: // set value for acceptance filter code and mask for 29-bit identifier (uint64_t) + case CANPROP_SET_FILTER_RESET: // reset acceptance filter code and mask to default values (NULL) + case TOUCAN_GET_HARDWARE_VERSION: // TouCAN USB: hardware version as "0xggrrss00" (uint32_t) + case TOUCAN_GET_FIRMWARE_VERSION: // TouCAN USB: firmware version as "0xggrrss00" (uint32_t) + case TOUCAN_GET_BOOTLOADER_VERSION: // TouCAN USB: boot-loader version as "0xggrrss00" (uint32_t) + case TOUCAN_GET_SERIAL_NUMBER: // TouCAN USB: serial no. in hex (uint32_t) + case TOUCAN_GET_VID_PID: // TouCAN USB: VID & PID (uint32_t) + case TOUCAN_GET_DEVICE_ID: // TouCAN USB: device id. (uint32_t) + case TOUCAN_GET_VENDOR_URL: // TouCAN USB: URL of Rusoku's website (uint32_t) // note: a device parameter requires a valid handle. if (!init) rc = CANERR_NOTINIT; @@ -763,7 +893,8 @@ static int drv_parameter(int handle, uint16_t param, void *value, size_t nbyte) if (value == NULL) { // check for null-pointer if ((param != CANPROP_SET_FIRST_CHANNEL) && - (param != CANPROP_SET_NEXT_CHANNEL)) + (param != CANPROP_SET_NEXT_CHANNEL) && + (param != CANPROP_SET_FILTER_RESET)) return CANERR_NULLPTR; } /* CAN interface properties */ @@ -780,15 +911,16 @@ static int drv_parameter(int handle, uint16_t param, void *value, size_t nbyte) rc = CANERR_NOERROR; } break; - case CANPROP_GET_DEVICE_VENDOR: // file name of the CAN interface DLL (char[256]) + case CANPROP_GET_DEVICE_VENDOR: // vendor name of the CAN interface (char[256]) if ((nbyte > strlen(can[handle].device.vendor)) && (nbyte <= CANPROP_MAX_BUFFER_SIZE)) { strcpy((char*)value, can[handle].device.vendor); rc = CANERR_NOERROR; } break; - case CANPROP_GET_DEVICE_DLLNAME: // vendor name of the CAN interface (char[256]) + case CANPROP_GET_DEVICE_DLLNAME: // file name of the CAN interface DLL (char[256]) if ((nbyte > strlen("(driverless)")) && (nbyte <= CANPROP_MAX_BUFFER_SIZE)) { - strcpy((char*)value, "(driverless)"); // note: there is no kernel driver! + strncpy((char*)value, "(driverless)", nbyte); // note: there is no kernel driver! + ((char*)value)[nbyte-1] = '\0'; rc = CANERR_NOERROR; } break; @@ -828,13 +960,13 @@ static int drv_parameter(int handle, uint16_t param, void *value, size_t nbyte) } } break; - case CANPROP_GET_BUSLOAD: // current bus load of the CAN controller (uint8_t) + case CANPROP_GET_BUSLOAD: // current bus load of the CAN controller (uint16_t) if (nbyte >= sizeof(uint8_t)) { - if ((rc = can_busload(handle, &load, NULL)) == CANERR_NOERROR) { // FIXME: legacy resolution - if (nbyte >= sizeof(uint16_t)) - *(uint16_t*)value = (uint16_t)load * 100U; // 0 - 10000 ==> 0.00% - 100.00% + if ((rc = can_busload(handle, &load, NULL)) == CANERR_NOERROR) { + if (nbyte > sizeof(uint8_t)) + *(uint16_t*)value = (uint16_t)load * 100U; // 0..10000 ==> 0.00%..100.00% else - *(uint8_t*)value = (uint8_t)load; // 0 - 100 ==> 0.00% - 100.00% + *(uint8_t*)value = (uint8_t)load; // 0..100% (note: legacy resolution) rc = CANERR_NOERROR; } } @@ -893,6 +1025,58 @@ static int drv_parameter(int handle, uint16_t param, void *value, size_t nbyte) rc = CANERR_NOERROR; } break; + case CANPROP_GET_FILTER_11BIT: // acceptance filter code and mask for 11-bit identifier (uint64_t) + if (nbyte >= sizeof(uint64_t)) { + *(uint64_t*)value = ((uint64_t)can[handle].filter.std.code << 32) + | ((uint64_t)can[handle].filter.std.mask); + rc = CANERR_NOERROR; + } + break; + case CANPROP_GET_FILTER_29BIT: // acceptance filter code and mask for 29-bit identifier (uint64_t) + if (nbyte >= sizeof(uint64_t)) { + *(uint64_t*)value = ((uint64_t)can[handle].filter.xtd.code << 32) + | ((uint64_t)can[handle].filter.xtd.mask); + rc = CANERR_NOERROR; + } + break; + case CANPROP_SET_FILTER_11BIT: // set value for acceptance filter code and mask for 11-bit identifier (uint64_t) + if (nbyte >= sizeof(uint64_t)) { + if (!(*(uint64_t*)value & 0xFFFFF800FFFFF800ULL)) { + // note: code and mask must not exceed 11-bit identifier + if (can[handle].status.can_stopped) { + // note: set filter only if the CAN controller is in INIT mode + rc= set_filter(handle, *(uint64_t*)value, false); + } + else + rc = CANERR_ONLINE; + } + else + rc = CANERR_ILLPARA; + } + break; + case CANPROP_SET_FILTER_29BIT: // set value for acceptance filter code and mask for 29-bit identifier (uint64_t) + if (nbyte >= sizeof(uint64_t)) { + if (!(*(uint64_t*)value & 0xE0000000E0000000ULL) && !can[handle].mode.nxtd) { + // note: code and mask must not exceed 29-bit identifier and 29-bit mode must not be suppressed + if (can[handle].status.can_stopped) { + // note: set filter only if the CAN controller is in INIT mode + rc = set_filter(handle, *(uint64_t*)value, true); + } + else + rc = CANERR_ONLINE; + } + else + rc = CANERR_ILLPARA; + } + break; + case CANPROP_SET_FILTER_RESET: // reset acceptance filter code and mask to default values (NULL) + if (can[handle].status.can_stopped) { + // note: reset filter only if the CAN controller is in INIT mode + rc = reset_filter(handle); + } + else + rc = CANERR_ONLINE; + break; /* TouCAN specific properties */ case TOUCAN_GET_HARDWARE_VERSION: // TouCAN USB: hardware version as "0xggrrss00" (uint32_t) if ((size_t)nbyte >= sizeof(uint32_t)) { @@ -937,33 +1121,14 @@ static int drv_parameter(int handle, uint16_t param, void *value, size_t nbyte) } break; default: -// if ((CANPROP_GET_VENDOR_PROP <= param) && // get a vendor-specific property value (void*) -// (param < (CANPROP_GET_VENDOR_PROP + CANPROP_VENDOR_PROP_RANGE))) { -// if ((sts = canIoCtl(can[handle].handle, (unsigned int)(param - CANPROP_GET_VENDOR_PROP), -// (void*)value, (DWORD)nbyte)) == canOK) -// rc = CANERR_NOERROR; -// else -// rc = kvaser_error(sts); -// } -// else if ((CANPROP_SET_VENDOR_PROP <= param) && // set a vendor-specific property value (void*) -// (param < (CANPROP_SET_VENDOR_PROP + CANPROP_VENDOR_PROP_RANGE))) { -// if ((sts = canIoCtl(can[handle].handle, (unsigned int)(param - CANPROP_SET_VENDOR_PROP), -// (void*)value, (DWORD)nbyte)) == canOK) -// rc = CANERR_NOERROR; -// else -// rc = kvaser_error(sts); -// } -// else // or general library properties (see lib_parameter) - rc = lib_parameter(param, value, nbyte); + rc = lib_parameter(param, value, nbyte); // library properties (see lib_parameter) break; } return rc; } - /* ----------- revision control --------------------------------------- */ - EXPORT char *can_version(void) { @@ -974,5 +1139,5 @@ char *can_version(void) /* ---------------------------------------------------------------------- * Uwe Vogt, UV Software, Chausseestrasse 33 A, 10115 Berlin, Germany * Tel.: +49-30-46799872, Fax: +49-30-46799873, Mobile: +49-170-3801903 - * E-Mail: uwe.vogt@uv-software.de, Homepage: http://www.uv-software.de/ + * E-Mail: uwe.vogt@uv-software.de, Homepage: https://www.uv-software.de/ */ diff --git a/Sources/Wrapper/can_defs.h b/Sources/Wrapper/can_defs.h index 76e6224..053fc96 100644 --- a/Sources/Wrapper/can_defs.h +++ b/Sources/Wrapper/can_defs.h @@ -1,23 +1,49 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ +/* SPDX-License-Identifier: BSD-2-Clause OR GPL-3.0-or-later */ /* - * CAN Interface API, Version 3 (for Rusoku TouCAN Interface) + * CAN Interface API, Version 3 (for Rusoku TouCAN Adapters) * - * Copyright (C) 2020-2022 Uwe Vogt, UV Software, Berlin (info@mac-can.com) + * Copyright (c) 2020-2024 Uwe Vogt, UV Software, Berlin (info@mac-can.com) + * All rights reserved. * * This file is part of MacCAN-TouCAN. * - * MacCAN-TouCAN is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by + * MacCAN-TouCAN is dual-licensed under the BSD 2-Clause "Simplified" License + * and under the GNU General Public License v3.0 (or any later version). You can + * choose between one of them if you use MacCAN-TouCAN in whole or in part. + * + * BSD 2-Clause "Simplified" License: + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * MacCAN-TouCAN IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF MacCAN-TouCAN, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * GNU General Public License v3.0 or later: + * MacCAN-TouCAN is free software : you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * MacCAN-TouCAN is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. + * GNU General Public License for more details. * - * You should have received a copy of the GNU Lesser General Public License - * along with MacCAN-TouCAN. If not, see . + * You should have received a copy of the GNU General Public License + * along with MacCAN-TouCAN. If not, see . */ /** @addtogroup can_api * @{ @@ -53,5 +79,5 @@ /* ---------------------------------------------------------------------- * Uwe Vogt, UV Software, Chausseestrasse 33 A, 10115 Berlin, Germany * Tel.: +49-30-46799872, Fax: +49-30-46799873, Mobile: +49-170-3801903 - * E-Mail: uwe.vogt@uv-software.de, Homepage: http://www.uv-software.de/ + * E-Mail: uwe.vogt@uv-software.de, Homepage: https://www.uv-software.de/ */ diff --git a/Tests/CANAPI/Driver.h b/Tests/CANAPI/Driver.h index 59f1d35..38f384b 100644 --- a/Tests/CANAPI/Driver.h +++ b/Tests/CANAPI/Driver.h @@ -1,15 +1,15 @@ // SPDX-License-Identifier: BSD-2-Clause OR GPL-3.0-or-later // -// CAN Interface API, Version 3 (Testing) +// TouCAN - macOS User-Space Driver for Rusoku TouCAN USB Adapters // -// Copyright (c) 2004-2023 Uwe Vogt, UV Software, Berlin (info@uv-software.com) +// Copyright (c) 2020-2024 Uwe Vogt, UV Software, Berlin (info@mac-can.com) // All rights reserved. // -// This file is part of CAN API V3. +// This file is part of MacCAN-TouCAN. // -// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License and -// under the GNU General Public License v3.0 (or any later version). -// You can choose between one of them if you use this file. +// MacCAN-TouCAN is dual-licensed under the BSD 2-Clause "Simplified" License +// and under the GNU General Public License v3.0 (or any later version). You can +// choose between one of them if you use MacCAN-TouCAN in whole or in part. // // BSD 2-Clause "Simplified" License: // Redistribution and use in source and binary forms, with or without @@ -20,7 +20,7 @@ // this list of conditions and the following disclaimer in the documentation // and/or other materials provided with the distribution. // -// CAN API V3 IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// MacCAN-TouCAN IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE @@ -29,21 +29,21 @@ // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF CAN API V3, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// OF MacCAN-TouCAN, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // // GNU General Public License v3.0 or later: -// CAN API V3 is free software: you can redistribute it and/or modify +// MacCAN-TouCAN is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // -// CAN API V3 is distributed in the hope that it will be useful, +// MacCAN-TouCAN is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with CAN API V3. If not, see . +// along with MacCAN-TouCAN. If not, see . // #ifndef DRIVER_H_INCLUDED #define DRIVER_H_INCLUDED @@ -68,6 +68,7 @@ typedef CTouCAN CCanDriver; #define FEATURE_BITRATE_SAM FEATURE_UNSUPPORTED #define FEATURE_BITRATE_FD_SAM FEATURE_UNSUPPORTED #define FEATURE_BITRATE_SJA1000 FEATURE_UNSUPPORTED +#define FEATURE_FILTERING FEATURE_SUPPORTED #define FEATURE_ERROR_FRAMES FEATURE_UNSUPPORTED #define FEATURE_ERROR_CODE_CAPTURE FEATURE_UNSUPPORTED #define FEATURE_BLOCKING_READ FEATURE_SUPPORTED diff --git a/Tests/CANAPI/Makefile b/Tests/CANAPI/Makefile index 6b54796..8130c8a 100644 --- a/Tests/CANAPI/Makefile +++ b/Tests/CANAPI/Makefile @@ -1,13 +1,13 @@ # # CAN Interface API, Version 3 (Testing) # -# Copyright (c) 2004-2023 Uwe Vogt, UV Software, Berlin (info@uv-software.com) +# Copyright (c) 2004-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) # All rights reserved. # # This file is part of CAN API V3. # -# CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License and -# under the GNU General Public License v3.0 (or any later version). +# CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License +# and under the GNU General Public License v3.0 (or any later version). # You can choose between one of them if you use this file. # # BSD 2-Clause "Simplified" License: @@ -42,7 +42,7 @@ # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with CAN API V3. If not, see . +# along with CAN API V3. If not, see . # current_OS := $(shell sh -c 'uname 2>/dev/null || echo Unknown OS') current_OS := $(patsubst CYGWIN%,Cygwin,$(current_OS)) @@ -68,8 +68,10 @@ OBJECTS = $(OUTDIR)/main.o $(OUTDIR)/Device.o $(OUTDIR)/Options.o \ $(OUTDIR)/TC09_GetStatus.o \ $(OUTDIR)/TC11_GetBitrate.o $(OUTDIR)/Bitrates.o \ $(OUTDIR)/TC12_GetProperty.o $(OUTDIR)/Properties.o \ + $(OUTDIR)/TC23_SetFilter11Bit.o $(OUTDIR)/TC25_SetFilter29Bit.o \ + $(OUTDIR)/TC27_ResetFilter.o \ $(OUTDIR)/TCx1_CallSequences.o $(OUTDIR)/TCx2_BitrateConverter.o \ - $(OUTDIR)/Timer64.o $(OUTDIR)/Progress.o + $(OUTDIR)/Timer.o $(OUTDIR)/Progress.o ifeq ($(current_OS),Darwin) # macOS - libTouCAN.dylib @@ -173,6 +175,15 @@ $(OUTDIR)/TC11_GetBitrate.o: $(TEST_DIR)/TC11_GetBitrate.cc $(OUTDIR)/TC12_GetProperty.o: $(TEST_DIR)/TC12_GetProperty.cc $(CXX) $(CXXFLAGS) -MMD -MF $*.d -o $@ -c $< +$(OUTDIR)/TC23_SetFilter11Bit.o: $(TEST_DIR)/TC23_SetFilter11Bit.cc + $(CXX) $(CXXFLAGS) -MMD -MF $*.d -o $@ -c $< + +$(OUTDIR)/TC25_SetFilter29Bit.o: $(TEST_DIR)/TC25_SetFilter29Bit.cc + $(CXX) $(CXXFLAGS) -MMD -MF $*.d -o $@ -c $< + +$(OUTDIR)/TC27_ResetFilter.o: $(TEST_DIR)/TC27_ResetFilter.cc + $(CXX) $(CXXFLAGS) -MMD -MF $*.d -o $@ -c $< + $(OUTDIR)/TCx1_CallSequences.o: $(TEST_DIR)/TCx1_CallSequences.cc $(CXX) $(CXXFLAGS) -MMD -MF $*.d -o $@ -c $< @@ -188,7 +199,7 @@ $(OUTDIR)/Device.o: $(MAIN_DIR)/Device.cpp $(OUTDIR)/Options.o: $(MAIN_DIR)/Options.cpp $(CXX) $(CXXFLAGS) -MMD -MF $*.d -o $@ -c $< -$(OUTDIR)/Timer64.o: $(MAIN_DIR)/Timer64.cpp +$(OUTDIR)/Timer.o: $(MAIN_DIR)/Timer.cpp $(CXX) $(CXXFLAGS) -MMD -MF $*.d -o $@ -c $< $(OUTDIR)/Progress.o: $(MAIN_DIR)/Progress.cpp diff --git a/Tests/CANAPI/README.md b/Tests/CANAPI/README.md index d1a43b8..f2f6dfe 100644 --- a/Tests/CANAPI/README.md +++ b/Tests/CANAPI/README.md @@ -1,9 +1,9 @@ ### CAN API V3 Testing with GoogleTest -_Copyright © 2004-2023 Uwe Vogt, UV Software, Berlin (info@uv-software.com)_ \ +_Copyright © 2004-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com)_ \ _All rights reserved._ -Version $Rev: 1205 $ +Version $Rev: 1273 $ # CAN Interface Wrapper Specification @@ -81,17 +81,23 @@ public: #else virtual CANAPI_Return_t InitializeChannel(int32_t channel, const CANAPI_OpMode_t &opMode, const void *param = NULL) = 0; #endif + virtual CANAPI_Return_t TeardownChannel() = 0; virtual CANAPI_Return_t SignalChannel() = 0; virtual CANAPI_Return_t StartController(CANAPI_Bitrate_t bitrate) = 0; virtual CANAPI_Return_t ResetController() = 0; virtual CANAPI_Return_t WriteMessage(CANAPI_Message_t message, uint16_t timeout = 0U) = 0; - virtual CANAPI_Return_t ReadMessage(CANAPI_Message_t &message, uint16_t timeout = CANREAD_INFINITE) = 0; + virtual CANAPI_Return_t ReadMessage(CANAPI_Message_t &message, uint16_t timeout = CANWAIT_INFINITE) = 0; virtual CANAPI_Return_t GetStatus(CANAPI_Status_t &status) = 0; virtual CANAPI_Return_t GetBusLoad(uint8_t &load) = 0; // deprecated virtual CANAPI_Return_t GetBitrate(CANAPI_Bitrate_t &bitrate) = 0; virtual CANAPI_Return_t GetBusSpeed(CANAPI_BusSpeed_t &speed) = 0; virtual CANAPI_Return_t GetProperty(uint16_t param, void *value, uint32_t nbyte) = 0; virtual CANAPI_Return_t SetProperty(uint16_t param, const void *value, uint32_t nbyte) = 0; + virtual CANAPI_Return_t SetFilter11Bit(uint32_t code, uint32_t mask) = 0; + virtual CANAPI_Return_t GetFilter11Bit(uint32_t &code, uint32_t &mask) = 0; + virtual CANAPI_Return_t SetFilter29Bit(uint32_t code, uint32_t mask) = 0; + virtual CANAPI_Return_t GetFilter29Bit(uint32_t &code, uint32_t &mask) = 0; + virtual CANAPI_Return_t ResetFilters() = 0; virtual char *GetHardwareVersion() = 0; // deprecated virtual char *GetFirmwareVersion() = 0; // deprecated static char *GetVersion(); diff --git a/Tests/CANAPI/Sources/Bitrates.cpp b/Tests/CANAPI/Sources/Bitrates.cpp index ebd4467..d8ff469 100644 --- a/Tests/CANAPI/Sources/Bitrates.cpp +++ b/Tests/CANAPI/Sources/Bitrates.cpp @@ -2,13 +2,13 @@ // // CAN Interface API, Version 3 (Testing) // -// Copyright (c) 2004-2022 Uwe Vogt, UV Software, Berlin (info@uv-software.com) +// Copyright (c) 2004-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) // All rights reserved. // // This file is part of CAN API V3. // -// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License and -// under the GNU General Public License v3.0 (or any later version). +// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License +// and under the GNU General Public License v3.0 (or any later version). // You can choose between one of them if you use this file. // // BSD 2-Clause "Simplified" License: @@ -43,7 +43,7 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with CAN API V3. If not, see . +// along with CAN API V3. If not, see . // #include "pch.h" #include @@ -308,4 +308,4 @@ bool CBitrates::IsCanFdWithBrse() { (aBitrateString[m_nIndex].m_fCanFdWithBrse)) ? true : false; } -// $Id: Bitrates.cpp 1170 2023-08-23 14:01:13Z haumea $ Copyright (c) UV Software, Berlin // +// $Id: Bitrates.cpp 1272 2024-04-16 19:55:27Z makemake $ Copyright (c) UV Software, Berlin // diff --git a/Tests/CANAPI/Sources/Bitrates.h b/Tests/CANAPI/Sources/Bitrates.h index 606837f..d5bfae2 100644 --- a/Tests/CANAPI/Sources/Bitrates.h +++ b/Tests/CANAPI/Sources/Bitrates.h @@ -2,13 +2,13 @@ // // CAN Interface API, Version 3 (Testing) // -// Copyright (c) 2004-2023 Uwe Vogt, UV Software, Berlin (info@uv-software.com) +// Copyright (c) 2004-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) // All rights reserved. // // This file is part of CAN API V3. // -// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License and -// under the GNU General Public License v3.0 (or any later version). +// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License +// and under the GNU General Public License v3.0 (or any later version). // You can choose between one of them if you use this file. // // BSD 2-Clause "Simplified" License: @@ -43,7 +43,7 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with CAN API V3. If not, see . +// along with CAN API V3. If not, see . // #ifndef BITRATES_H_INCLUDED #define BITRATES_H_INCLUDED @@ -66,5 +66,5 @@ class CBitrates { }; #endif // BITRATES_H_INCLUDED -// $Id: Bitrates.h 1148 2023-08-15 16:20:55Z haumea $ Copyright (c) UV Software, Berlin // +// $Id: Bitrates.h 1272 2024-04-16 19:55:27Z makemake $ Copyright (c) UV Software, Berlin // diff --git a/Tests/CANAPI/Sources/Config.h b/Tests/CANAPI/Sources/Config.h index a9eef35..6125e27 100644 --- a/Tests/CANAPI/Sources/Config.h +++ b/Tests/CANAPI/Sources/Config.h @@ -2,13 +2,13 @@ // // CAN Interface API, Version 3 (Testing) // -// Copyright (c) 2004-2023 Uwe Vogt, UV Software, Berlin (info@uv-software.com) +// Copyright (c) 2004-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) // All rights reserved. // // This file is part of CAN API V3. // -// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License and -// under the GNU General Public License v3.0 (or any later version). +// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License +// and under the GNU General Public License v3.0 (or any later version). // You can choose between one of them if you use this file. // // BSD 2-Clause "Simplified" License: @@ -43,7 +43,7 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with CAN API V3. If not, see . +// along with CAN API V3. If not, see . // #ifndef CONFIG_H_INCLUDED #define CONFIG_H_INCLUDED @@ -67,5 +67,5 @@ #define GTEST_DISABLED DISABLE_GTEST #endif // CONFIG_H_INCLUDED -// $Id: Config.h 1171 2023-08-23 15:08:43Z haumea $ Copyright (c) UV Software, Berlin. +// $Id: Config.h 1272 2024-04-16 19:55:27Z makemake $ Copyright (c) UV Software, Berlin. diff --git a/Tests/CANAPI/Sources/Device.cpp b/Tests/CANAPI/Sources/Device.cpp index a7fc5d4..31d084f 100644 --- a/Tests/CANAPI/Sources/Device.cpp +++ b/Tests/CANAPI/Sources/Device.cpp @@ -2,13 +2,13 @@ // // CAN Interface API, Version 3 (Testing) // -// Copyright (c) 2004-2023 Uwe Vogt, UV Software, Berlin (info@uv-software.com) +// Copyright (c) 2004-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) // All rights reserved. // // This file is part of CAN API V3. // -// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License and -// under the GNU General Public License v3.0 (or any later version). +// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License +// and under the GNU General Public License v3.0 (or any later version). // You can choose between one of them if you use this file. // // BSD 2-Clause "Simplified" License: @@ -43,7 +43,7 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with CAN API V3. If not, see . +// along with CAN API V3. If not, see . // #include "pch.h" #include @@ -590,4 +590,4 @@ void CCanDevice::ShowChannelCapabilities(const char* prefix) { std::cout << std::endl; } -// $Id: Device.cpp 1217 2023-10-10 19:28:31Z haumea $ Copyright (c) UV Software, Berlin // +// $Id: Device.cpp 1272 2024-04-16 19:55:27Z makemake $ Copyright (c) UV Software, Berlin // diff --git a/Tests/CANAPI/Sources/Device.h b/Tests/CANAPI/Sources/Device.h index 7df3d3e..21aaa1a 100644 --- a/Tests/CANAPI/Sources/Device.h +++ b/Tests/CANAPI/Sources/Device.h @@ -2,13 +2,13 @@ // // CAN Interface API, Version 3 (Testing) // -// Copyright (c) 2004-2023 Uwe Vogt, UV Software, Berlin (info@uv-software.com) +// Copyright (c) 2004-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) // All rights reserved. // // This file is part of CAN API V3. // -// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License and -// under the GNU General Public License v3.0 (or any later version). +// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License +// and under the GNU General Public License v3.0 (or any later version). // You can choose between one of them if you use this file. // // BSD 2-Clause "Simplified" License: @@ -43,7 +43,7 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with CAN API V3. If not, see . +// along with CAN API V3. If not, see . // #ifndef DEVICE_H_INCLUDED #define DEVICE_H_INCLUDED @@ -118,6 +118,9 @@ class CCanDevice : public CCanDriver { EChannelState state = CCanApi::ChannelNotTestable; return (CCanDriver::ProbeChannel(m_nChannelNo, opCapa, state) == CCanApi::NoError) ? true : false; } + bool IsCanIdAccepted(uint32_t canId, uint32_t accCode, uint32_t accMask) { + return (((canId ^ accCode) & accMask) == 0x00000000U) ? true : false; + } // properties CANAPI_Return_t GetOpCapabilities(CANAPI_OpMode_t &opCapa) { return CCanDriver::GetProperty(CANPROP_GET_OP_CAPABILITY, (void*)&opCapa.byte, sizeof(uint8_t)); @@ -170,4 +173,4 @@ class CCanDevice : public CCanDriver { #endif // DEVICE_H_INCLUDED -// $Id: Device.h 1217 2023-10-10 19:28:31Z haumea $ Copyright (c) UV Software, Berlin. +// $Id: Device.h 1272 2024-04-16 19:55:27Z makemake $ Copyright (c) UV Software, Berlin. diff --git a/Tests/CANAPI/Sources/Options.cpp b/Tests/CANAPI/Sources/Options.cpp index d0e2ce1..1ca26f1 100644 --- a/Tests/CANAPI/Sources/Options.cpp +++ b/Tests/CANAPI/Sources/Options.cpp @@ -2,13 +2,13 @@ // // CAN Interface API, Version 3 (Testing) // -// Copyright (c) 2004-2023 Uwe Vogt, UV Software, Berlin (info@uv-software.com) +// Copyright (c) 2004-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) // All rights reserved. // // This file is part of CAN API V3. // -// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License and -// under the GNU General Public License v3.0 (or any later version). +// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License +// and under the GNU General Public License v3.0 (or any later version). // You can choose between one of them if you use this file. // // BSD 2-Clause "Simplified" License: @@ -43,7 +43,7 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with CAN API V3. If not, see . +// along with CAN API V3. If not, see . // #ifdef _MSC_VER //no Microsoft extensions please! @@ -716,4 +716,4 @@ int COptions::ShowHelp() { return m_fShowHelp; } -// $Id: Options.cpp 1193 2023-09-06 10:21:35Z haumea $ Copyright (c) UV Software, Berlin // +// $Id: Options.cpp 1272 2024-04-16 19:55:27Z makemake $ Copyright (c) UV Software, Berlin // diff --git a/Tests/CANAPI/Sources/Options.h b/Tests/CANAPI/Sources/Options.h index 4062a6b..92cbeca 100644 --- a/Tests/CANAPI/Sources/Options.h +++ b/Tests/CANAPI/Sources/Options.h @@ -2,13 +2,13 @@ // // CAN Interface API, Version 3 (Testing) // -// Copyright (c) 2004-2023 Uwe Vogt, UV Software, Berlin (info@uv-software.com) +// Copyright (c) 2004-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) // All rights reserved. // // This file is part of CAN API V3. // -// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License and -// under the GNU General Public License v3.0 (or any later version). +// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License +// and under the GNU General Public License v3.0 (or any later version). // You can choose between one of them if you use this file. // // BSD 2-Clause "Simplified" License: @@ -43,7 +43,7 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with CAN API V3. If not, see . +// along with CAN API V3. If not, see . // #ifndef OPTIONS_H_INCLUDED #define OPTIONS_H_INCLUDED @@ -139,4 +139,4 @@ extern COptions g_Options; // global access to testing options #endif // OPTIONS_H_INCLUDED -// $Id: Options.h 1193 2023-09-06 10:21:35Z haumea $ Copyright (c) UV Software, Berlin. +// $Id: Options.h 1272 2024-04-16 19:55:27Z makemake $ Copyright (c) UV Software, Berlin. diff --git a/Tests/CANAPI/Sources/Progress.cpp b/Tests/CANAPI/Sources/Progress.cpp index 650e6e5..9e6e809 100644 --- a/Tests/CANAPI/Sources/Progress.cpp +++ b/Tests/CANAPI/Sources/Progress.cpp @@ -2,11 +2,13 @@ // // Software for Industrial Communication, Motion Control and Automation // -// Copyright (c) 2002-2022 Uwe Vogt, UV Software, Berlin (info@uv-software.com) +// Copyright (c) 2002-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) // All rights reserved. // -// This class is dual-licensed under the BSD 2-Clause "Simplified" License and -// under the GNU General Public License v3.0 (or any later version). +// Class CProgress +// +// This class is dual-licensed under the BSD 2-Clause "Simplified" License +// and under the GNU General Public License v3.0 (or any later version). // You can choose between one of them if you use this class. // // BSD 2-Clause "Simplified" License: @@ -41,7 +43,7 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with this class. If not, see . +// along with this class. If not, see . // #include "Progress.h" #include @@ -138,4 +140,4 @@ void CCounter::Increment() { #endif } -// $Id: Progress.cpp 798 2023-10-07 19:01:13Z makemake $ Copyright (c) UV Software, Berlin // +// $Id: Progress.cpp 811 2024-04-18 14:03:48Z quaoar $ Copyright (c) UV Software, Berlin // diff --git a/Tests/CANAPI/Sources/Progress.h b/Tests/CANAPI/Sources/Progress.h index 1c04a81..0b96d40 100644 --- a/Tests/CANAPI/Sources/Progress.h +++ b/Tests/CANAPI/Sources/Progress.h @@ -2,11 +2,13 @@ // // Software for Industrial Communication, Motion Control and Automation // -// Copyright (c) 2002-2022 Uwe Vogt, UV Software, Berlin (info@uv-software.com) +// Copyright (c) 2002-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) // All rights reserved. // -// This class is dual-licensed under the BSD 2-Clause "Simplified" License and -// under the GNU General Public License v3.0 (or any later version). +// Class CProgress +// +// This class is dual-licensed under the BSD 2-Clause "Simplified" License +// and under the GNU General Public License v3.0 (or any later version). // You can choose between one of them if you use this class. // // BSD 2-Clause "Simplified" License: @@ -41,7 +43,7 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with this class. If not, see . +// along with this class. If not, see . // #ifndef PROGRESS_H_INCLUDED #define PROGRESS_H_INCLUDED @@ -80,4 +82,4 @@ class CCounter { #endif // PROGRESS_H_INCLUDED -// $Id: Progress.h 798 2023-10-07 19:01:13Z makemake $ Copyright (c) UV Software, Berlin // +// $Id: Progress.h 811 2024-04-18 14:03:48Z quaoar $ Copyright (c) UV Software, Berlin // diff --git a/Tests/CANAPI/Sources/Properties.cpp b/Tests/CANAPI/Sources/Properties.cpp index 726d39e..fbde633 100644 --- a/Tests/CANAPI/Sources/Properties.cpp +++ b/Tests/CANAPI/Sources/Properties.cpp @@ -2,13 +2,13 @@ // // CAN Interface API, Version 3 (Testing) // -// Copyright (c) 2004-2022 Uwe Vogt, UV Software, Berlin (info@uv-software.com) +// Copyright (c) 2004-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) // All rights reserved. // // This file is part of CAN API V3. // -// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License and -// under the GNU General Public License v3.0 (or any later version). +// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License +// and under the GNU General Public License v3.0 (or any later version). // You can choose between one of them if you use this file. // // BSD 2-Clause "Simplified" License: @@ -43,14 +43,14 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with CAN API V3. If not, see . +// along with CAN API V3. If not, see . // #include "pch.h" #include #include #include -#define MAX_PROPERTIES 37 +#define MAX_PROPERTIES 42 #define LIB_PARAM true #define DRV_PARAM false @@ -61,55 +61,70 @@ #define PROP_REQUIRED true #define PROP_OPTIONAL false +#if (FEATURE_FILTERING != FEATURE_SUPPORTED) +#define PROP_FILTERING PROP_OPTIONAL +#else +#define PROP_FILTERING PROP_REQUIRED +#endif + +#define MODE_RUNNING true +#define MODE_STOPPED false + static struct SProperty { uint16_t m_nId; uint32_t m_nSize; bool m_fPreInit; bool m_fSetter; bool m_fRequired; + bool m_fModeRunning; const char* m_szDescription; } aProperties[MAX_PROPERTIES + 1] = { - { CANPROP_GET_SPEC , sizeof(uint16_t), LIB_PARAM, PROP_GETTER, PROP_REQUIRED, "version of the wrapper specification (uint16_t)" }, - { CANPROP_GET_VERSION , sizeof(uint16_t), LIB_PARAM, PROP_GETTER, PROP_REQUIRED, "version number of the library (uint16_t)" }, - { CANPROP_GET_PATCH_NO , sizeof(uint8_t), LIB_PARAM, PROP_GETTER, PROP_REQUIRED, "patch number of the library (uint8_t)" }, - { CANPROP_GET_BUILD_NO , sizeof(uint32_t), LIB_PARAM, PROP_GETTER, PROP_REQUIRED, "build number of the library (uint32_t)" }, - { CANPROP_GET_LIBRARY_ID , sizeof(int32_t), LIB_PARAM, PROP_GETTER, PROP_REQUIRED, "library id of the library (int32_t)" }, - { CANPROP_GET_LIBRARY_VENDOR , CANPROP_MAX_BUFFER_SIZE, LIB_PARAM, PROP_GETTER, PROP_REQUIRED, "vendor name of the library (char[256])" }, - { CANPROP_GET_LIBRARY_DLLNAME , CANPROP_MAX_BUFFER_SIZE, LIB_PARAM, PROP_GETTER, PROP_REQUIRED, "file name of the library DLL (char[256])" }, - { CANPROP_GET_DEVICE_TYPE , sizeof(int32_t), DRV_PARAM, PROP_GETTER, PROP_REQUIRED, "device type of the CAN interface (int32_t)" }, - { CANPROP_GET_DEVICE_NAME , CANPROP_MAX_BUFFER_SIZE, DRV_PARAM, PROP_GETTER, PROP_REQUIRED, "device name of the CAN interface (char[256])" }, - { CANPROP_GET_DEVICE_VENDOR , CANPROP_MAX_BUFFER_SIZE, LIB_PARAM, PROP_GETTER, PROP_REQUIRED, "vendor name of the CAN interface (char[256])" }, - { CANPROP_GET_DEVICE_DLLNAME , CANPROP_MAX_BUFFER_SIZE, LIB_PARAM, PROP_GETTER, PROP_REQUIRED, "file name of the CAN interface DLL (char[256])" }, - { CANPROP_GET_DEVICE_PARAM , CANPROP_MAX_BUFFER_SIZE, DRV_PARAM, PROP_GETTER, PROP_OPTIONAL, "device parameter of the CAN interface (char[256])" }, - { CANPROP_GET_OP_CAPABILITY , sizeof(uint8_t), DRV_PARAM, PROP_GETTER, PROP_REQUIRED, "supported operation modes of the CAN controller (uint8_t)" }, - { CANPROP_GET_OP_MODE , sizeof(uint8_t), DRV_PARAM, PROP_GETTER, PROP_REQUIRED, "active operation mode of the CAN controller (uint8_t)" }, - { CANPROP_GET_BITRATE , sizeof(can_bitrate_t), DRV_PARAM, PROP_GETTER, PROP_REQUIRED, "active bit-rate of the CAN controller (can_bitrate_t)" }, - { CANPROP_GET_SPEED , sizeof(can_speed_t), DRV_PARAM, PROP_GETTER, PROP_REQUIRED, "active bus speed of the CAN controller (can_speed_t)" }, - { CANPROP_GET_STATUS , sizeof(can_mode_t), DRV_PARAM, PROP_GETTER, PROP_REQUIRED, "current status register of the CAN controller (uint8_t)" }, - { CANPROP_GET_BUSLOAD , sizeof(uint16_t), DRV_PARAM, PROP_GETTER, PROP_REQUIRED, "current bus load of the CAN controller (uint16_t)" }, - { CANPROP_GET_NUM_CHANNELS , sizeof(uint8_t), DRV_PARAM, PROP_GETTER, PROP_OPTIONAL, "numbers of CAN channels on the CAN interface (uint8_t)" }, - { CANPROP_GET_CAN_CHANNEL , sizeof(uint8_t), DRV_PARAM, PROP_GETTER, PROP_OPTIONAL, "active CAN channel on the CAN interface (uint8_t)" }, - { CANPROP_GET_CAN_CLOCK , sizeof(int32_t), DRV_PARAM, PROP_GETTER, PROP_OPTIONAL, "frequency of the CAN controller clock in [Hz] (int32_t)" }, - { CANPROP_GET_TX_COUNTER , sizeof(uint64_t), DRV_PARAM, PROP_GETTER, PROP_REQUIRED, "total number of sent messages (uint64_t)" }, - { CANPROP_GET_RX_COUNTER , sizeof(uint64_t), DRV_PARAM, PROP_GETTER, PROP_REQUIRED, "total number of reveiced messages (uint64_t)" }, - { CANPROP_GET_ERR_COUNTER , sizeof(uint64_t), DRV_PARAM, PROP_GETTER, PROP_REQUIRED, "total number of reveiced error frames (uint64_t)" }, - { CANPROP_GET_RCV_QUEUE_SIZE , sizeof(uint32_t), DRV_PARAM, PROP_GETTER, PROP_OPTIONAL, "maximum number of message the receive queue can hold (uint32_t)" }, - { CANPROP_GET_RCV_QUEUE_HIGH , sizeof(uint32_t), DRV_PARAM, PROP_GETTER, PROP_OPTIONAL, "maximum number of message the receive queue has hold (uint32_t)" }, - { CANPROP_GET_RCV_QUEUE_OVFL , sizeof(uint64_t), DRV_PARAM, PROP_GETTER, PROP_OPTIONAL, "overflow counter of the receive queue (uint64_t)" }, - { CANPROP_GET_TRM_QUEUE_SIZE , sizeof(uint32_t), DRV_PARAM, PROP_GETTER, PROP_OPTIONAL, "maximum number of message the transmit queue can hold (uint32_t)" }, - { CANPROP_GET_TRM_QUEUE_HIGH , sizeof(uint32_t), DRV_PARAM, PROP_GETTER, PROP_OPTIONAL, "maximum number of message the transmit queue has hold (uint32_t)" }, - { CANPROP_GET_TRM_QUEUE_OVFL , sizeof(uint64_t), DRV_PARAM, PROP_GETTER, PROP_OPTIONAL, "overflow counter of the transmit queue (uint64_t)" }, + { CANPROP_GET_SPEC , sizeof(uint16_t), LIB_PARAM, PROP_GETTER, PROP_REQUIRED, MODE_RUNNING, "version of the wrapper specification (uint16_t)" }, + { CANPROP_GET_VERSION , sizeof(uint16_t), LIB_PARAM, PROP_GETTER, PROP_REQUIRED, MODE_RUNNING, "version number of the library (uint16_t)" }, + { CANPROP_GET_PATCH_NO , sizeof(uint8_t), LIB_PARAM, PROP_GETTER, PROP_REQUIRED, MODE_RUNNING, "patch number of the library (uint8_t)" }, + { CANPROP_GET_BUILD_NO , sizeof(uint32_t), LIB_PARAM, PROP_GETTER, PROP_REQUIRED, MODE_RUNNING, "build number of the library (uint32_t)" }, + { CANPROP_GET_LIBRARY_ID , sizeof(int32_t), LIB_PARAM, PROP_GETTER, PROP_REQUIRED, MODE_RUNNING, "library id of the library (int32_t)" }, + { CANPROP_GET_LIBRARY_VENDOR , CANPROP_MAX_BUFFER_SIZE, LIB_PARAM, PROP_GETTER, PROP_REQUIRED, MODE_RUNNING, "vendor name of the library (char[256])" }, + { CANPROP_GET_LIBRARY_DLLNAME , CANPROP_MAX_BUFFER_SIZE, LIB_PARAM, PROP_GETTER, PROP_REQUIRED, MODE_RUNNING, "file name of the library DLL (char[256])" }, + { CANPROP_GET_DEVICE_TYPE , sizeof(int32_t), DRV_PARAM, PROP_GETTER, PROP_REQUIRED, MODE_RUNNING, "device type of the CAN interface (int32_t)" }, + { CANPROP_GET_DEVICE_NAME , CANPROP_MAX_BUFFER_SIZE, DRV_PARAM, PROP_GETTER, PROP_REQUIRED, MODE_RUNNING, "device name of the CAN interface (char[256])" }, + { CANPROP_GET_DEVICE_VENDOR , CANPROP_MAX_BUFFER_SIZE, LIB_PARAM, PROP_GETTER, PROP_REQUIRED, MODE_RUNNING, "vendor name of the CAN interface (char[256])" }, + { CANPROP_GET_DEVICE_DLLNAME , CANPROP_MAX_BUFFER_SIZE, LIB_PARAM, PROP_GETTER, PROP_REQUIRED, MODE_RUNNING, "file name of the CAN interface DLL (char[256])" }, + { CANPROP_GET_DEVICE_PARAM , CANPROP_MAX_BUFFER_SIZE, DRV_PARAM, PROP_GETTER, PROP_OPTIONAL, MODE_RUNNING, "device parameter of the CAN interface (char[256])" }, + { CANPROP_GET_OP_CAPABILITY , sizeof(uint8_t), DRV_PARAM, PROP_GETTER, PROP_REQUIRED, MODE_RUNNING, "supported operation modes of the CAN controller (uint8_t)" }, + { CANPROP_GET_OP_MODE , sizeof(uint8_t), DRV_PARAM, PROP_GETTER, PROP_REQUIRED, MODE_RUNNING, "active operation mode of the CAN controller (uint8_t)" }, + { CANPROP_GET_BITRATE , sizeof(can_bitrate_t), DRV_PARAM, PROP_GETTER, PROP_REQUIRED, MODE_RUNNING, "active bit-rate of the CAN controller (can_bitrate_t)" }, + { CANPROP_GET_SPEED , sizeof(can_speed_t), DRV_PARAM, PROP_GETTER, PROP_REQUIRED, MODE_RUNNING, "active bus speed of the CAN controller (can_speed_t)" }, + { CANPROP_GET_STATUS , sizeof(can_mode_t), DRV_PARAM, PROP_GETTER, PROP_REQUIRED, MODE_RUNNING, "current status register of the CAN controller (uint8_t)" }, + { CANPROP_GET_BUSLOAD , sizeof(uint16_t), DRV_PARAM, PROP_GETTER, PROP_REQUIRED, MODE_RUNNING, "current bus load of the CAN controller (uint16_t)" }, + { CANPROP_GET_NUM_CHANNELS , sizeof(uint8_t), DRV_PARAM, PROP_GETTER, PROP_OPTIONAL, MODE_RUNNING, "numbers of CAN channels on the CAN interface (uint8_t)" }, + { CANPROP_GET_CAN_CHANNEL , sizeof(uint8_t), DRV_PARAM, PROP_GETTER, PROP_OPTIONAL, MODE_RUNNING, "active CAN channel on the CAN interface (uint8_t)" }, + { CANPROP_GET_CAN_CLOCK , sizeof(int32_t), DRV_PARAM, PROP_GETTER, PROP_OPTIONAL, MODE_RUNNING, "frequency of the CAN controller clock in [Hz] (int32_t)" }, + { CANPROP_GET_TX_COUNTER , sizeof(uint64_t), DRV_PARAM, PROP_GETTER, PROP_REQUIRED, MODE_RUNNING, "total number of sent messages (uint64_t)" }, + { CANPROP_GET_RX_COUNTER , sizeof(uint64_t), DRV_PARAM, PROP_GETTER, PROP_REQUIRED, MODE_RUNNING, "total number of reveiced messages (uint64_t)" }, + { CANPROP_GET_ERR_COUNTER , sizeof(uint64_t), DRV_PARAM, PROP_GETTER, PROP_REQUIRED, MODE_RUNNING, "total number of reveiced error frames (uint64_t)" }, + { CANPROP_GET_RCV_QUEUE_SIZE , sizeof(uint32_t), DRV_PARAM, PROP_GETTER, PROP_OPTIONAL, MODE_RUNNING, "maximum number of message the receive queue can hold (uint32_t)" }, + { CANPROP_GET_RCV_QUEUE_HIGH , sizeof(uint32_t), DRV_PARAM, PROP_GETTER, PROP_OPTIONAL, MODE_RUNNING, "maximum number of message the receive queue has hold (uint32_t)" }, + { CANPROP_GET_RCV_QUEUE_OVFL , sizeof(uint64_t), DRV_PARAM, PROP_GETTER, PROP_OPTIONAL, MODE_RUNNING, "overflow counter of the receive queue (uint64_t)" }, + { CANPROP_GET_TRM_QUEUE_SIZE , sizeof(uint32_t), DRV_PARAM, PROP_GETTER, PROP_OPTIONAL, MODE_RUNNING, "maximum number of message the transmit queue can hold (uint32_t)" }, + { CANPROP_GET_TRM_QUEUE_HIGH , sizeof(uint32_t), DRV_PARAM, PROP_GETTER, PROP_OPTIONAL, MODE_RUNNING, "maximum number of message the transmit queue has hold (uint32_t)" }, + { CANPROP_GET_TRM_QUEUE_OVFL , sizeof(uint64_t), DRV_PARAM, PROP_GETTER, PROP_OPTIONAL, MODE_RUNNING, "overflow counter of the transmit queue (uint64_t)" }, + { CANPROP_GET_FILTER_11BIT , sizeof(uint64_t), DRV_PARAM, PROP_GETTER, PROP_FILTERING, MODE_RUNNING, "acceptance filter code and mask for 11-bit identifier (uint64_t)" }, + { CANPROP_GET_FILTER_29BIT , sizeof(uint64_t), DRV_PARAM, PROP_GETTER, PROP_FILTERING, MODE_RUNNING, "acceptance filter code and mask for 29-bit identifier (uint64_t)" }, + { CANPROP_SET_FILTER_11BIT , sizeof(uint64_t), DRV_PARAM, PROP_SETTER, PROP_FILTERING, MODE_STOPPED, "set value for acceptance filter code and mask for 11-bit identifier (uint64_t)" }, + { CANPROP_SET_FILTER_29BIT , sizeof(uint64_t), DRV_PARAM, PROP_SETTER, PROP_FILTERING, MODE_STOPPED, "set value for acceptance filter code and mask for 29-bit identifier (uint64_t)" }, + { CANPROP_SET_FILTER_RESET , 0U /* NULL pointer*/, DRV_PARAM, PROP_SETTER, PROP_FILTERING, MODE_STOPPED, "reset acceptance filter code and mask to default values (NULL)" }, /* note: SET_FIRST_CHANNEL must be called before any GET_CHANNEL_xyz, therefore we define it as a PROP_GETTER because it gets a (virtual) index */ - { CANPROP_SET_FIRST_CHANNEL , 0U /* NULL pointer*/, LIB_PARAM, PROP_GETTER, PROP_REQUIRED, "set index to the first entry in the interface list (NULL)" }, - { CANPROP_GET_CHANNEL_NO , sizeof(int32_t), LIB_PARAM, PROP_GETTER, PROP_REQUIRED, "get channel no. at actual index in the interface list (int32_t)" }, - { CANPROP_GET_CHANNEL_NAME , CANPROP_MAX_BUFFER_SIZE, LIB_PARAM, PROP_GETTER, PROP_REQUIRED, "get channel name at actual index in the interface list (char[256])" }, - { CANPROP_GET_CHANNEL_DLLNAME , CANPROP_MAX_BUFFER_SIZE, LIB_PARAM, PROP_GETTER, PROP_REQUIRED, "get file name of the DLL at actual index in the interface list (char[256])" }, - { CANPROP_GET_CHANNEL_VENDOR_ID , sizeof(int32_t), LIB_PARAM, PROP_GETTER, PROP_REQUIRED, "get library id at actual index in the interface list (int32_t)" }, - { CANPROP_GET_CHANNEL_VENDOR_NAME , CANPROP_MAX_BUFFER_SIZE, LIB_PARAM, PROP_GETTER, PROP_REQUIRED, "get vendor name at actual index in the interface list(char[256])" }, + { CANPROP_SET_FIRST_CHANNEL , 0U /* NULL pointer*/, LIB_PARAM, PROP_GETTER, PROP_REQUIRED, MODE_RUNNING, "set index to the first entry in the interface list (NULL)" }, + { CANPROP_GET_CHANNEL_NO , sizeof(int32_t), LIB_PARAM, PROP_GETTER, PROP_REQUIRED, MODE_RUNNING, "get channel no. at actual index in the interface list (int32_t)" }, + { CANPROP_GET_CHANNEL_NAME , CANPROP_MAX_BUFFER_SIZE, LIB_PARAM, PROP_GETTER, PROP_REQUIRED, MODE_RUNNING, "get channel name at actual index in the interface list (char[256])" }, + { CANPROP_GET_CHANNEL_DLLNAME , CANPROP_MAX_BUFFER_SIZE, LIB_PARAM, PROP_GETTER, PROP_REQUIRED, MODE_RUNNING, "get file name of the DLL at actual index in the interface list (char[256])" }, + { CANPROP_GET_CHANNEL_VENDOR_ID , sizeof(int32_t), LIB_PARAM, PROP_GETTER, PROP_REQUIRED, MODE_RUNNING, "get library id at actual index in the interface list (int32_t)" }, + { CANPROP_GET_CHANNEL_VENDOR_NAME , CANPROP_MAX_BUFFER_SIZE, LIB_PARAM, PROP_GETTER, PROP_REQUIRED, MODE_RUNNING, "get vendor name at actual index in the interface list(char[256])" }, /* note: SET_NEXT_CHANNEL is also defined as a setter because it gets the next (virtual) index (see above), but it can be EOF when there is no device entry */ - { CANPROP_SET_NEXT_CHANNEL , 0U /* NULL pointer*/, LIB_PARAM, PROP_GETTER, PROP_REQUIRED, "set index to the next entry in the interface list (NULL)" }, + { CANPROP_SET_NEXT_CHANNEL , 0U /* NULL pointer*/, LIB_PARAM, PROP_GETTER, PROP_REQUIRED, MODE_RUNNING, "set index to the next entry in the interface list (NULL)" }, /* end marker */ - { CANPROP_INVALID, 0U, false, false, false, "" } + { CANPROP_INVALID, 0U, false, false, false, false, "" } }; CProperties::CProperties() { @@ -151,6 +166,13 @@ bool CProperties::IsRequired() { return false; } +bool CProperties::IsModeRunning() { + if (m_nIndex < MAX_PROPERTIES) + return aProperties[m_nIndex].m_fModeRunning; + else + return false; +} + uint32_t CProperties::SizeOf() { if (m_nIndex < MAX_PROPERTIES) return aProperties[m_nIndex].m_nSize; @@ -165,4 +187,4 @@ const char* CProperties::Description() { return aProperties[MAX_PROPERTIES].m_szDescription; } -// $Id: Properties.cpp 1170 2023-08-23 14:01:13Z haumea $ Copyright (c) UV Software, Berlin // +// $Id: Properties.cpp 1272 2024-04-16 19:55:27Z makemake $ Copyright (c) UV Software, Berlin // diff --git a/Tests/CANAPI/Sources/Properties.h b/Tests/CANAPI/Sources/Properties.h index 6cf70fd..7bb43c2 100644 --- a/Tests/CANAPI/Sources/Properties.h +++ b/Tests/CANAPI/Sources/Properties.h @@ -2,13 +2,13 @@ // // CAN Interface API, Version 3 (Testing) // -// Copyright (c) 2004-2023 Uwe Vogt, UV Software, Berlin (info@uv-software.com) +// Copyright (c) 2004-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) // All rights reserved. // // This file is part of CAN API V3. // -// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License and -// under the GNU General Public License v3.0 (or any later version). +// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License +// and under the GNU General Public License v3.0 (or any later version). // You can choose between one of them if you use this file. // // BSD 2-Clause "Simplified" License: @@ -43,7 +43,7 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with CAN API V3. If not, see . +// along with CAN API V3. If not, see . // #ifndef PROPERTIES_H_INCLUDED #define PROPERTIES_H_INCLUDED @@ -68,10 +68,11 @@ class CProperties { bool IsSetter(); bool IsPreInit(); bool IsRequired(); + bool IsModeRunning(); uint32_t SizeOf(); const char* Description(); }; #endif // PROPERTIES_H_INCLUDED -// $Id: Properties.h 1157 2023-08-18 16:51:09Z haumea $ Copyright (c) UV Software, Berlin // +// $Id: Properties.h 1272 2024-04-16 19:55:27Z makemake $ Copyright (c) UV Software, Berlin // diff --git a/Tests/CANAPI/Sources/Settings.h b/Tests/CANAPI/Sources/Settings.h index 869d0a8..dba564c 100644 --- a/Tests/CANAPI/Sources/Settings.h +++ b/Tests/CANAPI/Sources/Settings.h @@ -2,13 +2,13 @@ // // CAN Interface API, Version 3 (Testing) // -// Copyright (c) 2004-2023 Uwe Vogt, UV Software, Berlin (info@uv-software.com) +// Copyright (c) 2004-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) // All rights reserved. // // This file is part of CAN API V3. // -// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License and -// under the GNU General Public License v3.0 (or any later version). +// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License +// and under the GNU General Public License v3.0 (or any later version). // You can choose between one of them if you use this file. // // BSD 2-Clause "Simplified" License: @@ -43,7 +43,7 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with CAN API V3. If not, see . +// along with CAN API V3. If not, see . // #ifndef SETTINGS_H_INCLUDED #define SETTINGS_H_INCLUDED @@ -158,4 +158,4 @@ #endif #endif // SETTINGS_H_INCLUDED -// $Id: Settings.h 1217 2023-10-10 19:28:31Z haumea $ Copyright (c) UV Software, Berlin. +// $Id: Settings.h 1272 2024-04-16 19:55:27Z makemake $ Copyright (c) UV Software, Berlin. diff --git a/Tests/CANAPI/Sources/Timer.cpp b/Tests/CANAPI/Sources/Timer.cpp index 42858d6..afc35ee 100644 --- a/Tests/CANAPI/Sources/Timer.cpp +++ b/Tests/CANAPI/Sources/Timer.cpp @@ -2,11 +2,13 @@ // // Software for Industrial Communication, Motion Control and Automation // -// Copyright (c) 2002-2023 Uwe Vogt, UV Software, Berlin (info@uv-software.com) +// Copyright (c) 2002-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) // All rights reserved. // -// This class is dual-licensed under the BSD 2-Clause "Simplified" License and -// under the GNU General Public License v3.0 (or any later version). +// Class CTimer +// +// This class is dual-licensed under the BSD 2-Clause "Simplified" License +// and under the GNU General Public License v3.0 (or any later version). // You can choose between one of them if you use this class. // // BSD 2-Clause "Simplified" License: @@ -41,7 +43,7 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with this class. If not, see . +// along with this class. If not, see . // #ifdef _DEBUG #undef THIS_FILE @@ -58,48 +60,50 @@ static char THIS_FILE[]=__FILE__; #endif #define POSIX_DEPRECATED 0 /* set to non-zero value to use 'gettimeofday' and 'usleep'*/ -CTimer::CTimer(uint32_t u32Microseconds) { +CTimer::CTimer(uint64_t u64Microseconds) { #if !defined(_WIN32) && !defined(_WIN64) #if (POSIX_DEPRECATED != 0) struct timeval tv; gettimeofday(&tv, NULL); m_u64UntilStop = ((uint64_t)tv.tv_sec * (uint64_t)1000000) + (uint64_t)tv.tv_usec - + ((uint64_t)u32Microseconds); + + ((uint64_t)u64Microseconds); #else struct timespec now = { 0, 0 }; clock_gettime(CLOCK_MONOTONIC, &now); m_u64UntilStop = ((uint64_t)now.tv_sec * (uint64_t)1000000) + ((uint64_t)now.tv_nsec / (uint64_t)1000) - + ((uint64_t)u32Microseconds); + + ((uint64_t)u64Microseconds); #endif #else LARGE_INTEGER largeCounter; // high-resolution performance counter + m_llUntilStop = (LONGLONG)0; // counter value for the desired time-out + // retrieve the frequency of the high-resolution performance counter if(!QueryPerformanceFrequency(&m_largeFrequency)) return; // retrieve the current value of the high-resolution performance counter - if(!QueryPerformanceCounter(&largeCounter)) + if (!QueryPerformanceCounter(&largeCounter)) return; // calculate the counter value for the desired time-out - m_llUntilStop = largeCounter.QuadPart + ((m_largeFrequency.QuadPart * (LONGLONG)u32Microseconds) + m_llUntilStop = largeCounter.QuadPart + ((m_largeFrequency.QuadPart * (LONGLONG)u64Microseconds) / (LONGLONG)1000000); #endif } -bool CTimer::Restart(uint32_t u32Microseconds) { +bool CTimer::Restart(uint64_t u64Microseconds) { #if !defined(_WIN32) && !defined(_WIN64) #if (POSIX_DEPRECATED != 0) struct timeval tv; gettimeofday(&tv, NULL); m_u64UntilStop = ((uint64_t)tv.tv_sec * (uint64_t)1000000) + (uint64_t)tv.tv_usec - + ((uint64_t)u32Microseconds); + + ((uint64_t)u64Microseconds); #else struct timespec now = { 0, 0 }; clock_gettime(CLOCK_MONOTONIC, &now); m_u64UntilStop = ((uint64_t)now.tv_sec * (uint64_t)1000000) + ((uint64_t)now.tv_nsec / (uint64_t)1000) - + ((uint64_t)u32Microseconds); + + ((uint64_t)u64Microseconds); #endif return true; #else @@ -109,7 +113,7 @@ bool CTimer::Restart(uint32_t u32Microseconds) { if(!QueryPerformanceCounter(&largeCounter)) return false; // calculate the counter value for the desired time-out - m_llUntilStop = largeCounter.QuadPart + ((m_largeFrequency.QuadPart * (LONGLONG)u32Microseconds) + m_llUntilStop = largeCounter.QuadPart + ((m_largeFrequency.QuadPart * (LONGLONG)u64Microseconds) / (LONGLONG)1000000); return true; #endif @@ -146,15 +150,15 @@ bool CTimer::Timeout() { #endif } -bool CTimer::Delay(uint32_t u32Microseconds) { +bool CTimer::Delay(uint64_t u64Microseconds) { #if !defined(_WIN32) && !defined(_WIN64) #if (POSIX_DEPRECATED != 0) - return (usleep((useconds_t)u32Microseconds) != 0) ? false : true; + return (usleep((useconds_t)u64Microseconds) != 0) ? false : true; #else int rc; struct timespec delay; - delay.tv_sec = (time_t)(u32Microseconds / CTimer::SEC); - delay.tv_nsec = (long)((u32Microseconds % CTimer::SEC) * (uint32_t)1000); + delay.tv_sec = (time_t)(u64Microseconds / CTimer::SEC); + delay.tv_nsec = (long)((u64Microseconds % CTimer::SEC) * (uint32_t)1000); errno = 0; while ((rc = nanosleep(&delay, &delay))) { if (errno != EINTR) @@ -175,7 +179,7 @@ bool CTimer::Delay(uint32_t u32Microseconds) { if(!QueryPerformanceFrequency(&largeFrequency)) return false; // calculate the counter value for the desired delay - llUntilStop = largeCounter.QuadPart + ((largeFrequency.QuadPart * (LONGLONG)u32Microseconds) + llUntilStop = largeCounter.QuadPart + ((largeFrequency.QuadPart * (LONGLONG)u64Microseconds) / (LONGLONG)1000000); // wait until the counter overruns the delay time for(;;) @@ -189,9 +193,9 @@ bool CTimer::Delay(uint32_t u32Microseconds) { HANDLE timer; LARGE_INTEGER ft; - ft.QuadPart = -(10 * (LONGLONG)u32Microseconds); // Convert to 100 nanosecond interval, negative value indicates relative time + ft.QuadPart = -(10 * (LONGLONG)u64Microseconds); // Convert to 100 nanosecond interval, negative value indicates relative time - if(u32Microseconds >= 100) { // FIXME: Who made this decision? + if(u64Microseconds >= 100) { // FIXME: Who made this decision? if ((timer = CreateWaitableTimer(NULL, TRUE, NULL)) != NULL) { SetWaitableTimer(timer, &ft, 0, NULL, NULL, 0); WaitForSingleObject(timer, INFINITE); @@ -256,4 +260,4 @@ double CTimer::DiffTime(struct timespec start, struct timespec stop) { ((double)start.tv_sec + ((double)start.tv_nsec / 1000000000.f))); } -// $Id: Timer.cpp 1213 2023-10-07 19:43:58Z makemake $ Copyright (c) UV Software, Berlin // +// $Id: Timer.cpp 1273 2024-04-18 16:59:22Z makemake $ Copyright (c) UV Software, Berlin // diff --git a/Tests/CANAPI/Sources/Timer.h b/Tests/CANAPI/Sources/Timer.h index 5f0ebc5..3bb4460 100644 --- a/Tests/CANAPI/Sources/Timer.h +++ b/Tests/CANAPI/Sources/Timer.h @@ -2,11 +2,13 @@ // // Software for Industrial Communication, Motion Control and Automation // -// Copyright (c) 2002-2023 Uwe Vogt, UV Software, Berlin (info@uv-software.com) +// Copyright (c) 2002-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) // All rights reserved. // -// This class is dual-licensed under the BSD 2-Clause "Simplified" License and -// under the GNU General Public License v3.0 (or any later version). +// Class CTimer +// +// This class is dual-licensed under the BSD 2-Clause "Simplified" License +// and under the GNU General Public License v3.0 (or any later version). // You can choose between one of them if you use this class. // // BSD 2-Clause "Simplified" License: @@ -41,7 +43,7 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with this class. If not, see . +// along with this class. If not, see . // #ifndef TIMER_H_INCLUDED #define TIMER_H_INCLUDED @@ -62,10 +64,10 @@ class CTimer { public: - static const uint32_t USEC = 1U; // 1 microsecond - static const uint32_t MSEC = 1000U; // 1 millisecond - static const uint32_t SEC = 1000000U; // 1 second - static const uint32_t MIN = 60000000U; // 1 minute + static const uint64_t USEC = 1U; // 1 microsecond + static const uint64_t MSEC = 1000U; // 1 millisecond + static const uint64_t SEC = 1000000U; // 1 second + static const uint64_t MIN = 60000000U; // 1 minute private: #if !defined(_WIN32) && !defined(_WIN64) uint64_t m_u64UntilStop; // counter value for the desired time-out @@ -74,13 +76,13 @@ class CTimer { LONGLONG m_llUntilStop; // counter value for the desired time-out #endif public: - CTimer(uint32_t u32Microseconds = 0); + CTimer(uint64_t u64Microseconds = 0); virtual ~CTimer() {}; - bool Restart(uint32_t u32Timeout); // restart the timer! - bool Timeout(); // time-out occurred? + bool Restart(uint64_t u64Microseconds); // restart the timer! + bool Timeout(); // time-out occurred? - static bool Delay(uint32_t u32Delay); // delay timer + static bool Delay(uint64_t u64Microseconds); // delay timer static struct timespec GetTime(); // time with nanosecond resolution static double DiffTime(struct timespec start, struct timespec stop); @@ -88,4 +90,4 @@ class CTimer { #endif // TIMER_H_INCLUDED -// $Id: Timer.h 799 2023-10-07 19:15:23Z makemake $ Copyright (c) UV Software, Berlin // +// $Id: Timer.h 810 2024-04-18 14:01:00Z quaoar $ Copyright (c) UV Software, Berlin // diff --git a/Tests/CANAPI/Sources/Timer64.cpp b/Tests/CANAPI/Sources/Timer64.cpp deleted file mode 100644 index be8efec..0000000 --- a/Tests/CANAPI/Sources/Timer64.cpp +++ /dev/null @@ -1,261 +0,0 @@ -// SPDX-License-Identifier: BSD-2-Clause OR GPL-3.0-or-later -// -// Software for Industrial Communication, Motion Control and Automation -// -// Copyright (c) 2002-2023 Uwe Vogt, UV Software, Berlin (info@uv-software.com) -// All rights reserved. -// -// This class is dual-licensed under the BSD 2-Clause "Simplified" License and -// under the GNU General Public License v3.0 (or any later version). -// You can choose between one of them if you use this class. -// -// BSD 2-Clause "Simplified" License: -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// 1. Redistributions of source code must retain the above copyright notice, this -// list of conditions and the following disclaimer. -// 2. Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// -// THIS CLASS IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS CLASS, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// GNU General Public License v3.0 or later: -// This class is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This class is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this class. If not, see . -// -#ifdef _DEBUG -#undef THIS_FILE -static char THIS_FILE[]=__FILE__; -#define new DEBUG_NEW -#endif - -#include "Timer64.h" - -#if !defined(_WIN32) && !defined(_WIN64) -#include -#include -#include -#endif -#define POSIX_DEPRECATED 0 /* set to non-zero value to use 'gettimeofday' and 'usleep'*/ - -CTimer::CTimer(uint64_t u64Microseconds) { -#if !defined(_WIN32) && !defined(_WIN64) -#if (POSIX_DEPRECATED != 0) - struct timeval tv; - gettimeofday(&tv, NULL); - m_u64UntilStop = ((uint64_t)tv.tv_sec * (uint64_t)1000000) + (uint64_t)tv.tv_usec - + ((uint64_t)u64Microseconds); -#else - struct timespec now = { 0, 0 }; - clock_gettime(CLOCK_MONOTONIC, &now); - m_u64UntilStop = ((uint64_t)now.tv_sec * (uint64_t)1000000) - + ((uint64_t)now.tv_nsec / (uint64_t)1000) - + ((uint64_t)u64Microseconds); -#endif -#else - LARGE_INTEGER largeCounter; // high-resolution performance counter - - m_llUntilStop = (LONGLONG)0; // counter value for the desired time-out - - // retrieve the frequency of the high-resolution performance counter - if(!QueryPerformanceFrequency(&m_largeFrequency)) - return; - // retrieve the current value of the high-resolution performance counter - if(!QueryPerformanceCounter(&largeCounter)) - return; - // calculate the counter value for the desired time-out - m_llUntilStop = largeCounter.QuadPart + ((m_largeFrequency.QuadPart * (LONGLONG)u64Microseconds) - / (LONGLONG)1000000); -#endif -} - -bool CTimer::Restart(uint64_t u64Microseconds) { -#if !defined(_WIN32) && !defined(_WIN64) -#if (POSIX_DEPRECATED != 0) - struct timeval tv; - gettimeofday(&tv, NULL); - m_u64UntilStop = ((uint64_t)tv.tv_sec * (uint64_t)1000000) + (uint64_t)tv.tv_usec - + ((uint64_t)u64Microseconds); -#else - struct timespec now = { 0, 0 }; - clock_gettime(CLOCK_MONOTONIC, &now); - m_u64UntilStop = ((uint64_t)now.tv_sec * (uint64_t)1000000) - + ((uint64_t)now.tv_nsec / (uint64_t)1000) - + ((uint64_t)u64Microseconds); -#endif - return true; -#else - LARGE_INTEGER largeCounter; // high-resolution performance counter - - // retrieve the current value of the high-resolution performance counter - if(!QueryPerformanceCounter(&largeCounter)) - return false; - // calculate the counter value for the desired time-out - m_llUntilStop = largeCounter.QuadPart + ((m_largeFrequency.QuadPart * (LONGLONG)u64Microseconds) - / (LONGLONG)1000000); - return true; -#endif -} - -bool CTimer::Timeout() { -#if !defined(_WIN32) && !defined(_WIN64) - uint64_t u64Now; -#if (POSIX_DEPRECATED != 0) - struct timeval tv; - gettimeofday(&tv, NULL); - u64Now = ((uint64_t)tv.tv_sec * (uint64_t)1000000) + (uint64_t)tv.tv_usec; -#else - struct timespec now = { 0, 0 }; - clock_gettime(CLOCK_MONOTONIC, &now); - u64Now = ((uint64_t)now.tv_sec * (uint64_t)1000000) - + ((uint64_t)now.tv_nsec / (uint64_t)1000); -#endif - if(u64Now < this->m_u64UntilStop) - return false; - else - return true; -#else - LARGE_INTEGER largeCounter; // high-resolution performance counter - - // retrieve the current value of the high-resolution performance counter - if(!QueryPerformanceCounter(&largeCounter)) - return false; - // a time-out occurred, if the counter overruns the time-out value - if(largeCounter.QuadPart < m_llUntilStop) - return false; - else - return true; -#endif -} - -bool CTimer::Delay(uint64_t u64Microseconds) { -#if !defined(_WIN32) && !defined(_WIN64) -#if (POSIX_DEPRECATED != 0) - return (usleep((useconds_t)u64Microseconds) != 0) ? false : true; -#else - int rc; - struct timespec delay; - delay.tv_sec = (time_t)(u64Microseconds / CTimer::SEC); - delay.tv_nsec = (long)((u64Microseconds % CTimer::SEC) * (uint32_t)1000); - errno = 0; - while ((rc = nanosleep(&delay, &delay))) { - if (errno != EINTR) - break; - } - return (rc != 0) ? false : true; -#endif -#else -# ifndef CTIMER_WAITABLE_TIMER - LARGE_INTEGER largeFrequency; // frequency in counts per second - LARGE_INTEGER largeCounter; // high-resolution performance counter - LONGLONG llUntilStop; // counter value for the desired delay - - // retrieve the current value of the high-resolution performance counter - if(!QueryPerformanceCounter(&largeCounter)) - return false; - // retrieve the frequency of the high-resolution performance counter - if(!QueryPerformanceFrequency(&largeFrequency)) - return false; - // calculate the counter value for the desired delay - llUntilStop = largeCounter.QuadPart + ((largeFrequency.QuadPart * (LONGLONG)u64Microseconds) - / (LONGLONG)1000000); - // wait until the counter overruns the delay time - for(;;) - { - if(!QueryPerformanceCounter(&largeCounter)) - return false; - if(largeCounter.QuadPart >= llUntilStop) - return true; - } -# else - HANDLE timer; - LARGE_INTEGER ft; - - ft.QuadPart = -(10 * (LONGLONG)u64Microseconds); // Convert to 100 nanosecond interval, negative value indicates relative time - - if(u64Microseconds >= 100) { // FIXME: Who made this decision? - if ((timer = CreateWaitableTimer(NULL, TRUE, NULL)) != NULL) { - SetWaitableTimer(timer, &ft, 0, NULL, NULL, 0); - WaitForSingleObject(timer, INFINITE); - CloseHandle(timer); - } - } - else { - // According to MSDN's documentation for Sleep: - // | A value of zero causes the thread to relinquish the remainder of its time slice to any other - // | thread that is ready to run.If there are no other threads ready to run, the function returns - // | immediately, and the thread continues execution. - Sleep(0); - } - return true; -# endif -#endif -} - -struct timespec CTimer::GetTime() { - struct timespec now = { 0, 0 }; -#if !defined(_WIN32) && !defined(_WIN64) - clock_gettime(CLOCK_REALTIME, &now); -#else - static bool fInitialied = false; // initialization flag - static struct timespec tsStartTime; // time at first call (UTC) - static LARGE_INTEGER largeFrequency; // frequency in counts per second - static LARGE_INTEGER largeStartCounter; // high-resolution performance counter - LARGE_INTEGER largeCurrentCounter; - - if (!fInitialied) { - // retrieve the frequency of the high-resolution performance counter - if (!QueryPerformanceFrequency(&largeFrequency)) - return now; - // retrieve the value of the high-resolution performance counter - if (!QueryPerformanceCounter(&largeStartCounter)) - return now; - // retrieve the time as struct timespec - if (!timespec_get(&tsStartTime, TIME_UTC)) - return now; - fInitialied = true; - } - // retrieve the current value of the high-resolution performance counter - if (!QueryPerformanceCounter(&largeCurrentCounter)) - return now; - // calculate the current time with nanosecond resolution - largeCurrentCounter.QuadPart -= largeStartCounter.QuadPart; - time_t sec = largeCurrentCounter.QuadPart / largeFrequency.QuadPart; - long nsec = (long)(((largeCurrentCounter.QuadPart - (sec * largeFrequency.QuadPart)) - * 1000000000UL) / largeFrequency.QuadPart); - now.tv_sec = tsStartTime.tv_sec + sec; - now.tv_nsec = tsStartTime.tv_nsec + nsec; - if (now.tv_nsec >= 1000000000UL) { - now.tv_sec += 1; - now.tv_nsec -= 1000000000UL; - } -#endif - return now; -} - -double CTimer::DiffTime(struct timespec start, struct timespec stop) { - return (((double)stop.tv_sec + ((double)stop.tv_nsec / 1000000000.f)) - - ((double)start.tv_sec + ((double)start.tv_nsec / 1000000000.f))); -} - -// $Id$ Copyright (c) UV Software, Berlin // diff --git a/Tests/CANAPI/Sources/Timer64.h b/Tests/CANAPI/Sources/Timer64.h deleted file mode 100644 index 10bdc4f..0000000 --- a/Tests/CANAPI/Sources/Timer64.h +++ /dev/null @@ -1,91 +0,0 @@ -// SPDX-License-Identifier: BSD-2-Clause OR GPL-3.0-or-later -// -// Software for Industrial Communication, Motion Control and Automation -// -// Copyright (c) 2002-2023 Uwe Vogt, UV Software, Berlin (info@uv-software.com) -// All rights reserved. -// -// This class is dual-licensed under the BSD 2-Clause "Simplified" License and -// under the GNU General Public License v3.0 (or any later version). -// You can choose between one of them if you use this class. -// -// BSD 2-Clause "Simplified" License: -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// 1. Redistributions of source code must retain the above copyright notice, this -// list of conditions and the following disclaimer. -// 2. Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// -// THIS CLASS IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS CLASS, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// GNU General Public License v3.0 or later: -// This class is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This class is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this class. If not, see . -// -#ifndef TIMER_H_INCLUDED -#define TIMER_H_INCLUDED - -#if _MSC_VER > 1000 -#pragma once -#endif - -#include -#include -#if defined(_WIN32) || defined(_WIN64) -#include -#endif - -#if defined(_WIN32) || defined(_WIN64) -#define CTIMER_WAITABLE_TIMER // a Windows alternative for usleep() -#endif - -class CTimer { -public: - static const uint64_t USEC = 1U; // 1 microsecond - static const uint64_t MSEC = 1000U; // 1 millisecond - static const uint64_t SEC = 1000000U; // 1 second - static const uint64_t MIN = 60000000U; // 1 minute -private: -#if !defined(_WIN32) && !defined(_WIN64) - uint64_t m_u64UntilStop; // counter value for the desired time-out -#else - LARGE_INTEGER m_largeFrequency; // frequency in counts per second - LONGLONG m_llUntilStop; // counter value for the desired time-out -#endif -public: - CTimer(uint64_t u64Microseconds = 0); - virtual ~CTimer() {}; - - bool Restart(uint64_t u64Microseconds); // restart the timer! - bool Timeout(); // time-out occurred? - - static bool Delay(uint64_t u64Microseconds); // delay timer - - static struct timespec GetTime(); // time with nanosecond resolution - static double DiffTime(struct timespec start, struct timespec stop); -}; - -#endif // TIMER_H_INCLUDED - -// $Id$ Copyright (c) UV Software, Berlin // diff --git a/Tests/CANAPI/Sources/main.cpp b/Tests/CANAPI/Sources/main.cpp index f5f44be..1dd850c 100644 --- a/Tests/CANAPI/Sources/main.cpp +++ b/Tests/CANAPI/Sources/main.cpp @@ -2,13 +2,13 @@ // // CAN Interface API, Version 3 (Testing) // -// Copyright (c) 2004-2023 Uwe Vogt, UV Software, Berlin (info@uv-software.com) +// Copyright (c) 2004-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) // All rights reserved. // // This file is part of CAN API V3. // -// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License and -// under the GNU General Public License v3.0 (or any later version). +// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License +// and under the GNU General Public License v3.0 (or any later version). // You can choose between one of them if you use this file. // // BSD 2-Clause "Simplified" License: @@ -43,7 +43,7 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with CAN API V3. If not, see . +// along with CAN API V3. If not, see . // #include #include @@ -62,7 +62,7 @@ GTEST_API_ int main(int argc, char **argv) { #endif std::cout << CCanDriver::GetVersion() << std::endl; std::cout << "Copyright (c) 2004-2012 by UV Software, Friedrichshafen" << std::endl; - std::cout << "Copyright (c) 2013-2023 by UV Software, Berlin" << std::endl; + std::cout << "Copyright (c) 2013-2024 by UV Software, Berlin" << std::endl; std::cout << "Build: " << __DATE__ << " " << __TIME__ << " (" << REVISION_NO << ")" << std::endl; // --- initialize GoogleTest framework -- printf("Running main() from %s\n", __FILE__); @@ -80,4 +80,4 @@ GTEST_API_ int main(int argc, char **argv) { return RUN_ALL_TESTS(); } -// $Id: main.cpp 1185 2023-08-29 10:42:03Z haumea $ Copyright (c) UV Software, Berlin // +// $Id: main.cpp 1272 2024-04-16 19:55:27Z makemake $ Copyright (c) UV Software, Berlin // diff --git a/Tests/CANAPI/Sources/pch.h b/Tests/CANAPI/Sources/pch.h index 3216ecc..6614a7d 100644 --- a/Tests/CANAPI/Sources/pch.h +++ b/Tests/CANAPI/Sources/pch.h @@ -28,7 +28,7 @@ #include "Bitrates.h" #include "Properties.h" #include "Progress.h" -#include "Timer64.h" +#include "Timer.h" #include "Version.h" #endif // PRECOMPILED_HEADERS_INCLUDED diff --git a/Tests/CANAPI/Testcases/TC00_SmokeTest.cc b/Tests/CANAPI/Testcases/TC00_SmokeTest.cc index e7d13b4..4e0b0a5 100644 --- a/Tests/CANAPI/Testcases/TC00_SmokeTest.cc +++ b/Tests/CANAPI/Testcases/TC00_SmokeTest.cc @@ -2,13 +2,13 @@ // // CAN Interface API, Version 3 (Testing) // -// Copyright (c) 2004-2023 Uwe Vogt, UV Software, Berlin (info@uv-software.com) +// Copyright (c) 2004-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) // All rights reserved. // // This file is part of CAN API V3. // -// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License and -// under the GNU General Public License v3.0 (or any later version). +// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License +// and under the GNU General Public License v3.0 (or any later version). // You can choose between one of them if you use this file. // // BSD 2-Clause "Simplified" License: @@ -43,7 +43,7 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with CAN API V3. If not, see . +// along with CAN API V3. If not, see . // #include "pch.h" @@ -300,4 +300,4 @@ TEST_F(SmokeTest, DefaultScenario) { // @end. } -// $Id: TC00_SmokeTest.cc 1217 2023-10-10 19:28:31Z haumea $ Copyright (c) UV Software, Berlin. +// $Id: TC00_SmokeTest.cc 1272 2024-04-16 19:55:27Z makemake $ Copyright (c) UV Software, Berlin. diff --git a/Tests/CANAPI/Testcases/TC01_ProbeChannel.cc b/Tests/CANAPI/Testcases/TC01_ProbeChannel.cc index 3002d3f..9e10318 100644 --- a/Tests/CANAPI/Testcases/TC01_ProbeChannel.cc +++ b/Tests/CANAPI/Testcases/TC01_ProbeChannel.cc @@ -2,13 +2,13 @@ // // CAN Interface API, Version 3 (Testing) // -// Copyright (c) 2004-2023 Uwe Vogt, UV Software, Berlin (info@uv-software.com) +// Copyright (c) 2004-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) // All rights reserved. // // This file is part of CAN API V3. // -// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License and -// under the GNU General Public License v3.0 (or any later version). +// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License +// and under the GNU General Public License v3.0 (or any later version). // You can choose between one of them if you use this file. // // BSD 2-Clause "Simplified" License: @@ -43,7 +43,7 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with CAN API V3. If not, see . +// along with CAN API V3. If not, see . // #include "pch.h" @@ -1031,4 +1031,4 @@ TEST_F(ProbeChannel, GTEST_TESTCASE(WithInvalidLibraryId, GTEST_DISABLED)) { } #endif // (OPTION_CANAPI_LIBRARY != OPTION_DISBALED) -// $Id: TC01_ProbeChannel.cc 1217 2023-10-10 19:28:31Z haumea $ Copyright (c) UV Software, Berlin. +// $Id: TC01_ProbeChannel.cc 1272 2024-04-16 19:55:27Z makemake $ Copyright (c) UV Software, Berlin. diff --git a/Tests/CANAPI/Testcases/TC02_InitializeChannel.cc b/Tests/CANAPI/Testcases/TC02_InitializeChannel.cc index f00d17f..af62aac 100644 --- a/Tests/CANAPI/Testcases/TC02_InitializeChannel.cc +++ b/Tests/CANAPI/Testcases/TC02_InitializeChannel.cc @@ -2,13 +2,13 @@ // // CAN Interface API, Version 3 (Testing) // -// Copyright (c) 2004-2023 Uwe Vogt, UV Software, Berlin (info@uv-software.com) +// Copyright (c) 2004-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) // All rights reserved. // // This file is part of CAN API V3. // -// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License and -// under the GNU General Public License v3.0 (or any later version). +// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License +// and under the GNU General Public License v3.0 (or any later version). // You can choose between one of them if you use this file. // // BSD 2-Clause "Simplified" License: @@ -43,7 +43,7 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with CAN API V3. If not, see . +// along with CAN API V3. If not, see . // #include "pch.h" @@ -913,4 +913,4 @@ TEST_F(InitializeChannel, GTEST_TESTCASE(WithInvalidLibraryId, GTEST_DISABLED)) } #endif // (OPTION_CANAPI_LIBRARY != OPTION_DISBALED) -// $Id: TC02_InitializeChannel.cc 1169 2023-08-22 19:55:08Z makemake $ Copyright (c) UV Software, Berlin. +// $Id: TC02_InitializeChannel.cc 1272 2024-04-16 19:55:27Z makemake $ Copyright (c) UV Software, Berlin. diff --git a/Tests/CANAPI/Testcases/TC03_StartController.cc b/Tests/CANAPI/Testcases/TC03_StartController.cc index 5a17f19..9b18950 100644 --- a/Tests/CANAPI/Testcases/TC03_StartController.cc +++ b/Tests/CANAPI/Testcases/TC03_StartController.cc @@ -2,13 +2,13 @@ // // CAN Interface API, Version 3 (Testing) // -// Copyright (c) 2004-2023 Uwe Vogt, UV Software, Berlin (info@uv-software.com) +// Copyright (c) 2004-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) // All rights reserved. // // This file is part of CAN API V3. // -// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License and -// under the GNU General Public License v3.0 (or any later version). +// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License +// and under the GNU General Public License v3.0 (or any later version). // You can choose between one of them if you use this file. // // BSD 2-Clause "Simplified" License: @@ -43,7 +43,7 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with CAN API V3. If not, see . +// along with CAN API V3. If not, see . // #include "pch.h" @@ -2313,4 +2313,4 @@ TEST_F(StartController, GTEST_TESTCASE(WithCanFdBitrateSettingsInCan20Mode, GTES } #endif // (CAN_FD_SUPPORTED == FEATURE_SUPPORTED) -// $Id: TC03_StartController.cc 1218 2023-10-14 12:18:19Z makemake $ Copyright (c) UV Software, Berlin. +// $Id: TC03_StartController.cc 1272 2024-04-16 19:55:27Z makemake $ Copyright (c) UV Software, Berlin. diff --git a/Tests/CANAPI/Testcases/TC04_ReadMessage.cc b/Tests/CANAPI/Testcases/TC04_ReadMessage.cc index d695618..eb20a3a 100644 --- a/Tests/CANAPI/Testcases/TC04_ReadMessage.cc +++ b/Tests/CANAPI/Testcases/TC04_ReadMessage.cc @@ -2,13 +2,13 @@ // // CAN Interface API, Version 3 (Testing) // -// Copyright (c) 2004-2023 Uwe Vogt, UV Software, Berlin (info@uv-software.com) +// Copyright (c) 2004-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) // All rights reserved. // // This file is part of CAN API V3. // -// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License and -// under the GNU General Public License v3.0 (or any later version). +// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License +// and under the GNU General Public License v3.0 (or any later version). // You can choose between one of them if you use this file. // // BSD 2-Clause "Simplified" License: @@ -43,7 +43,7 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with CAN API V3. If not, see . +// along with CAN API V3. If not, see . // #include "pch.h" @@ -1978,4 +1978,4 @@ TEST_F(ReadMessage, GTEST_TESTCASE(WithDifferentTimeoutValues, GTEST_ENABLED)) { // @todo: (1) blocking read // @todo: (2) test reentrancy -// $Id: TC04_ReadMessage.cc 1218 2023-10-14 12:18:19Z makemake $ Copyright (c) UV Software, Berlin. +// $Id: TC04_ReadMessage.cc 1272 2024-04-16 19:55:27Z makemake $ Copyright (c) UV Software, Berlin. diff --git a/Tests/CANAPI/Testcases/TC05_WriteMessage.cc b/Tests/CANAPI/Testcases/TC05_WriteMessage.cc index be0037e..dc45d96 100644 --- a/Tests/CANAPI/Testcases/TC05_WriteMessage.cc +++ b/Tests/CANAPI/Testcases/TC05_WriteMessage.cc @@ -2,13 +2,13 @@ // // CAN Interface API, Version 3 (Testing) // -// Copyright (c) 2004-2023 Uwe Vogt, UV Software, Berlin (info@uv-software.com) +// Copyright (c) 2004-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) // All rights reserved. // // This file is part of CAN API V3. // -// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License and -// under the GNU General Public License v3.0 (or any later version). +// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License +// and under the GNU General Public License v3.0 (or any later version). // You can choose between one of them if you use this file. // // BSD 2-Clause "Simplified" License: @@ -43,7 +43,7 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with CAN API V3. If not, see . +// along with CAN API V3. If not, see . // #include "pch.h" @@ -2169,12 +2169,18 @@ TEST_F(WriteMessage, GTEST_TESTCASE(WithFlagEsi, GTEST_ENABLED)) { retVal = dut2.ReadMessage(rcvMsg, TEST_READ_TIMEOUT); EXPECT_EQ(CCanApi::NoError, retVal); // @- compare sent and received message - EXPECT_TRUE(dut2.CompareMessages(trmMsg, rcvMsg)); + EXPECT_TRUE(dut2.CompareMessages(trmMsg, rcvMsg, false)); +#if (1) + // @ note: flag ESI is not set in received message in CAN FD mode + // @ (KvaserCAN-Wrapper and PCANBasic-Wrapper on Windows) + EXPECT_EQ(0, rcvMsg.esi); +#else // @ note: flag ESI should also be set in received message in CAN FD mode if (dut2.GetOpMode().fdoe) EXPECT_EQ(1, rcvMsg.esi); else EXPECT_EQ(0, rcvMsg.esi); +#endif // @post: counter.Clear(); // @- send some frames to DUT2 and receive some frames from DUT2 @@ -2205,4 +2211,4 @@ TEST_F(WriteMessage, GTEST_TESTCASE(WithFlagEsi, GTEST_ENABLED)) { // @todo: (1) blocking write // @todo: (2) test reentrancy -// $Id: TC05_WriteMessage.cc 1218 2023-10-14 12:18:19Z makemake $ Copyright (c) UV Software, Berlin. +// $Id: TC05_WriteMessage.cc 1272 2024-04-16 19:55:27Z makemake $ Copyright (c) UV Software, Berlin. diff --git a/Tests/CANAPI/Testcases/TC06_ResetController.cc b/Tests/CANAPI/Testcases/TC06_ResetController.cc index 03fee7c..d4c0017 100644 --- a/Tests/CANAPI/Testcases/TC06_ResetController.cc +++ b/Tests/CANAPI/Testcases/TC06_ResetController.cc @@ -2,13 +2,13 @@ // // CAN Interface API, Version 3 (Testing) // -// Copyright (c) 2004-2023 Uwe Vogt, UV Software, Berlin (info@uv-software.com) +// Copyright (c) 2004-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) // All rights reserved. // // This file is part of CAN API V3. // -// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License and -// under the GNU General Public License v3.0 (or any later version). +// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License +// and under the GNU General Public License v3.0 (or any later version). // You can choose between one of them if you use this file. // // BSD 2-Clause "Simplified" License: @@ -43,7 +43,7 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with CAN API V3. If not, see . +// along with CAN API V3. If not, see . // #include "pch.h" @@ -481,4 +481,4 @@ TEST_F(ResetController, GTEST_TESTCASE(CheckStatisticalCounters, GTEST_ENABLED)) // @end. } -// $Id: TC06_ResetController.cc 1165 2023-08-22 06:57:25Z haumea $ Copyright (c) UV Software, Berlin. +// $Id: TC06_ResetController.cc 1272 2024-04-16 19:55:27Z makemake $ Copyright (c) UV Software, Berlin. diff --git a/Tests/CANAPI/Testcases/TC08_TeardownChannel.cc b/Tests/CANAPI/Testcases/TC08_TeardownChannel.cc index a4b7684..91c932f 100644 --- a/Tests/CANAPI/Testcases/TC08_TeardownChannel.cc +++ b/Tests/CANAPI/Testcases/TC08_TeardownChannel.cc @@ -2,13 +2,13 @@ // // CAN Interface API, Version 3 (Testing) // -// Copyright (c) 2004-2023 Uwe Vogt, UV Software, Berlin (info@uv-software.com) +// Copyright (c) 2004-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) // All rights reserved. // // This file is part of CAN API V3. // -// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License and -// under the GNU General Public License v3.0 (or any later version). +// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License +// and under the GNU General Public License v3.0 (or any later version). // You can choose between one of them if you use this file. // // BSD 2-Clause "Simplified" License: @@ -43,7 +43,7 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with CAN API V3. If not, see . +// along with CAN API V3. If not, see . // #include "pch.h" @@ -333,4 +333,4 @@ TEST_F(TeardownChannel, GTEST_TESTCASE(IfChannelTornDown, GTEST_ENABLED)) { // @note: shuting down all channels is not possible with the C++ API! -// $Id: TC08_TeardownChannel.cc 1165 2023-08-22 06:57:25Z haumea $ Copyright (c) UV Software, Berlin. +// $Id: TC08_TeardownChannel.cc 1272 2024-04-16 19:55:27Z makemake $ Copyright (c) UV Software, Berlin. diff --git a/Tests/CANAPI/Testcases/TC09_GetStatus.cc b/Tests/CANAPI/Testcases/TC09_GetStatus.cc index 84a8f05..634d9d5 100644 --- a/Tests/CANAPI/Testcases/TC09_GetStatus.cc +++ b/Tests/CANAPI/Testcases/TC09_GetStatus.cc @@ -2,13 +2,13 @@ // // CAN Interface API, Version 3 (Testing) // -// Copyright (c) 2004-2023 Uwe Vogt, UV Software, Berlin (info@uv-software.com) +// Copyright (c) 2004-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) // All rights reserved. // // This file is part of CAN API V3. // -// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License and -// under the GNU General Public License v3.0 (or any later version). +// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License +// and under the GNU General Public License v3.0 (or any later version). // You can choose between one of them if you use this file. // // BSD 2-Clause "Simplified" License: @@ -43,7 +43,7 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with CAN API V3. If not, see . +// along with CAN API V3. If not, see . // #include "pch.h" @@ -1318,4 +1318,4 @@ TEST_F(GetStatus, GTEST_TESTCASE(IfReceiveQueueFull, GTEST_TC09_14_ENABLED)) { // @end. } -// $Id: TC09_GetStatus.cc 1218 2023-10-14 12:18:19Z makemake $ Copyright (c) UV Software, Berlin. +// $Id: TC09_GetStatus.cc 1272 2024-04-16 19:55:27Z makemake $ Copyright (c) UV Software, Berlin. diff --git a/Tests/CANAPI/Testcases/TC11_GetBitrate.cc b/Tests/CANAPI/Testcases/TC11_GetBitrate.cc index c66ddfc..d8f8522 100644 --- a/Tests/CANAPI/Testcases/TC11_GetBitrate.cc +++ b/Tests/CANAPI/Testcases/TC11_GetBitrate.cc @@ -2,13 +2,13 @@ // // CAN Interface API, Version 3 (Testing) // -// Copyright (c) 2004-2023 Uwe Vogt, UV Software, Berlin (info@uv-software.com) +// Copyright (c) 2004-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) // All rights reserved. // // This file is part of CAN API V3. // -// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License and -// under the GNU General Public License v3.0 (or any later version). +// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License +// and under the GNU General Public License v3.0 (or any later version). // You can choose between one of them if you use this file. // // BSD 2-Clause "Simplified" License: @@ -43,7 +43,7 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with CAN API V3. If not, see . +// along with CAN API V3. If not, see . // #include "pch.h" @@ -662,4 +662,4 @@ TEST_F(GetBitrate, GTEST_TESTCASE(WithVariousCanFdBitrateSettings, GTEST_ENABLED } #endif // (CAN_FD_SUPPORTED == FEATURE_SUPPORTED) -// $Id: TC11_GetBitrate.cc 1204 2023-09-24 15:26:57Z makemake $ Copyright (c) UV Software, Berlin. +// $Id: TC11_GetBitrate.cc 1272 2024-04-16 19:55:27Z makemake $ Copyright (c) UV Software, Berlin. diff --git a/Tests/CANAPI/Testcases/TC12_GetProperty.cc b/Tests/CANAPI/Testcases/TC12_GetProperty.cc index c9411e2..30afb88 100644 --- a/Tests/CANAPI/Testcases/TC12_GetProperty.cc +++ b/Tests/CANAPI/Testcases/TC12_GetProperty.cc @@ -2,13 +2,13 @@ // // CAN Interface API, Version 3 (Testing) // -// Copyright (c) 2004-2023 Uwe Vogt, UV Software, Berlin (info@uv-software.com) +// Copyright (c) 2004-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) // All rights reserved. // // This file is part of CAN API V3. // -// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License and -// under the GNU General Public License v3.0 (or any later version). +// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License +// and under the GNU General Public License v3.0 (or any later version). // You can choose between one of them if you use this file. // // BSD 2-Clause "Simplified" License: @@ -43,7 +43,7 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with CAN API V3. If not, see . +// along with CAN API V3. If not, see . // #include "pch.h" @@ -528,7 +528,10 @@ TEST_F(GetProperty, GTEST_TESTCASE(IfControllerStarted, GTEST_ENABLED)) { // @-- get property value (incl. pre-initialization parameter) retVal = dut1.GetProperty(param, (void*)buffer, testcase.SizeOf()); if (testcase.IsRequired()) { - EXPECT_EQ(CCanApi::NoError, retVal); + if (testcase.IsModeRunning()) + EXPECT_EQ(CCanApi::NoError, retVal); + else + EXPECT_EQ(CCanApi::ControllerOnline, retVal); } else if (retVal != CCanApi::NoError){ EXPECT_EQ(CCanApi::NotSupported, retVal); } @@ -708,4 +711,4 @@ TEST_F(GetProperty, GTEST_TESTCASE(IfChannelTornDown, GTEST_ENABLED)) { } -// $Id: TC12_GetProperty.cc 1201 2023-09-13 11:09:28Z makemake $ Copyright (c) UV Software, Berlin. +// $Id: TC12_GetProperty.cc 1272 2024-04-16 19:55:27Z makemake $ Copyright (c) UV Software, Berlin. diff --git a/Tests/CANAPI/Testcases/TC21_GetBusSpeed.cc b/Tests/CANAPI/Testcases/TC21_GetBusSpeed.cc index af32326..40b5651 100644 --- a/Tests/CANAPI/Testcases/TC21_GetBusSpeed.cc +++ b/Tests/CANAPI/Testcases/TC21_GetBusSpeed.cc @@ -2,13 +2,13 @@ // // CAN Interface API, Version 3 (Testing) // -// Copyright (c) 2004-2023 Uwe Vogt, UV Software, Berlin (info@uv-software.com) +// Copyright (c) 2004-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) // All rights reserved. // // This file is part of CAN API V3. // -// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License and -// under the GNU General Public License v3.0 (or any later version). +// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License +// and under the GNU General Public License v3.0 (or any later version). // You can choose between one of them if you use this file. // // BSD 2-Clause "Simplified" License: @@ -43,7 +43,7 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with CAN API V3. If not, see . +// along with CAN API V3. If not, see . // #include "pch.h" @@ -663,4 +663,4 @@ TEST_F(GetBusSpeed, GTEST_TESTCASE(WithVariousCanFdBitrateSettings, GTEST_DISABL } #endif // (CAN_FD_SUPPORTED == FEATURE_SUPPORTED) -// $Id: TC21_GetBusSpeed.cc 1158 2023-08-18 17:05:41Z haumea $ Copyright (c) UV Software, Berlin. +// $Id: TC21_GetBusSpeed.cc 1272 2024-04-16 19:55:27Z makemake $ Copyright (c) UV Software, Berlin. diff --git a/Tests/CANAPI/Testcases/TC23_SetFilter11Bit.cc b/Tests/CANAPI/Testcases/TC23_SetFilter11Bit.cc new file mode 100644 index 0000000..e559191 --- /dev/null +++ b/Tests/CANAPI/Testcases/TC23_SetFilter11Bit.cc @@ -0,0 +1,772 @@ +// SPDX-License-Identifier: BSD-2-Clause OR GPL-3.0-or-later +// +// CAN Interface API, Version 3 (Testing) +// +// Copyright (c) 2004-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) +// All rights reserved. +// +// This file is part of CAN API V3. +// +// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License +// and under the GNU General Public License v3.0 (or any later version). +// You can choose between one of them if you use this file. +// +// BSD 2-Clause "Simplified" License: +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// 1. Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// CAN API V3 IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF CAN API V3, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// GNU General Public License v3.0 or later: +// CAN API V3 is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// CAN API V3 is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with CAN API V3. If not, see . +// +#include "pch.h" + +// @note: This test suite tests the following methods: +// @ - CCanApi::SetFilter11Bit() [TC23.*] +// @ - CCanApi::GetFilter11Bit() [TC24.*] +// @ +#ifndef FEATURE_FILTERING +#define FEATURE_FILTERING FEATURE_UNSUPPORTED +#ifdef _MSC_VER +#pragma message ( "FEATURE_FILTERING not set, default = FEATURE_UNSUPPORTED" ) +#else +#warning FEATURE_FILTERING not set, default = FEATURE_UNSUPPORTED +#endif +#endif +#if (FEATURE_FILTERING != FEATURE_UNSUPPORTED) + +class SetFilter11Bit : public testing::Test { + virtual void SetUp() {} + virtual void TearDown() {} +protected: + void CheckFilter11Bit(CCanDevice& dut1, uint32_t accCode, uint32_t accMask) { + CCanDevice dut2 = CCanDevice(TEST_DEVICE(DUT2)); + CANAPI_Message_t trmMsg = {}; + CANAPI_Message_t rcvMsg = {}; + CANAPI_Return_t retVal; + // CAN message + trmMsg.id = 0U; + trmMsg.xtd = 0; + trmMsg.rtr = 0; + trmMsg.sts = 0; +#if (OPTION_CAN_2_0_ONLY != 0) + trmMsg.dlc = 0U; // CAN_MAX_DLC; + memset(trmMsg.data, 0, CAN_MAX_LEN); +#else + trmMsg.fdf = g_Options.GetOpMode(DUT1).fdoe ? 1 : 0; + trmMsg.brs = g_Options.GetOpMode(DUT1).brse ? 1 : 0; + trmMsg.esi = 0; + trmMsg.dlc = 0U; // g_Options.GetOpMode(DUT1).fdoe ? CANFD_MAX_DLC : CAN_MAX_DLC; + memset(trmMsg.data, 0, CANFD_MAX_LEN); +#endif + // initialize DUT2 with configured settings + retVal = dut2.InitializeChannel(); + ASSERT_EQ(CCanApi::NoError, retVal) << "[ ERROR! ] dut2.InitializeChannel() failed with error code " << retVal; + // start DUT2 with configured bit-rate settings + retVal = dut2.StartController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // DUT2 send 2048 standard messages + int n = 0, frames = 2048; + CProgress progress = CProgress(frames); + for (int i = 0; i < frames; i++) { + trmMsg.id = (uint32_t)i; + // send one message (retry if busy) + do { + retVal = dut2.WriteMessage(trmMsg, DEVICE_SEND_TIMEOUT); + if (retVal == CCanApi::TransmitterBusy) + PCBUSB_QXMT_DELAY(); + } while (retVal == CCanApi::TransmitterBusy); + // on error abort + if (retVal != CCanApi::NoError) { + EXPECT_EQ(retVal, CCanApi::NoError); + n = 0; + break; + } + PCBUSB_QXMT_DELAY(); // TODO: why here? + // update number of transmitted CAN messages + progress.Update((int)(i + 1), (int)0); + // update number of accepted CAN messages + if (dut1.IsCanIdAccepted(trmMsg.id, accCode, accMask)) { + n++; + } + } + // DUT1 process all messages with acceptance filter + uint64_t timeout = (((uint64_t)dut1.TransmissionTime(dut1.GetBitrate(), (n + DEVICE_LOOP_EXTRA)) + * (uint64_t)DEVICE_LOOP_FACTOR) / (uint64_t)DEVICE_LOOP_DIVISOR); // bit-rate dependent timeout + CTimer timer = CTimer(timeout); + int j = 0; + while ((j < n) && !timer.Timeout()) { + // read one message from receiver's queue, if any + retVal = dut1.ReadMessage(rcvMsg, DEVICE_READ_TIMEOUT); + if (retVal == CCanApi::NoError) { + // ignore status messages/error frames + if (!rcvMsg.sts) { + // update number of received CAN messages + progress.Update((int)frames, (int)(j + 1)); + // check if received message is accepted by acceptance filter + if (!dut1.IsCanIdAccepted(rcvMsg.id, accCode, accMask)) { + EXPECT_TRUE(dut1.IsCanIdAccepted(rcvMsg.id, accCode, accMask)); + break; + } + j++; + } + } + // on error abort (if receiver is empty, continue) + else if (retVal != CCanApi::ReceiverEmpty) { + EXPECT_EQ(retVal, CCanApi::ReceiverEmpty); + break; + } + } + progress.Clear(); + // tear down DUT2 + retVal = dut2.TeardownChannel(); + EXPECT_EQ(CCanApi::NoError, retVal); + } +}; + +// @gtest TC23/TC24.0: Set CAN acceptance filter for 11-bit identifier (sunnyday scenario) +// +// @expected: CANERR_NOERROR +// +TEST_F(SetFilter11Bit, GTEST_TESTCASE(SunnydayScenario, GTEST_SUNNYDAY)) { + CCanDevice dut1 = CCanDevice(TEST_DEVICE(DUT1)); + CCanDevice dut2 = CCanDevice(TEST_DEVICE(DUT2)); + CCanApi::EChannelState state; + CANAPI_Status_t status = {}; + uint32_t codeGet, maskGet; + uint32_t codeSet, maskSet; + CANAPI_Return_t retVal; + // @pre: + // @- probe if DUT1 is present and not occupied + retVal = dut1.ProbeChannel(state); + ASSERT_EQ(CCanApi::NoError, retVal) << "[ ERROR! ] dut1.ProbeChannel() failed with error code " << retVal; + ASSERT_EQ(CCanApi::ChannelAvailable, state) << "[ ERROR! ] " << g_Options.GetDeviceName(DUT1) << " is not available"; + // @- probe if DUT2 is present and not occupied + retVal = dut2.ProbeChannel(state); + ASSERT_EQ(CCanApi::NoError, retVal) << "[ ERROR! ] dut2.ProbeChannel() failed with error code " << retVal; + ASSERT_EQ(CCanApi::ChannelAvailable, state) << "[ ERROR! ] " << g_Options.GetDeviceName(DUT2) << " is not available"; + // @- check if different channels have been selected + ASSERT_TRUE((g_Options.GetChannelNo(DUT1) != g_Options.GetChannelNo(DUT2)) || \ + (g_Options.GetLibraryId(DUT1) != g_Options.GetLibraryId(DUT2))) << "[ ERROR! ] same channel selected twice"; + // @- initialize DUT1 with configured settings + retVal = dut1.InitializeChannel(); + ASSERT_EQ(CCanApi::NoError, retVal) << "[ ERROR! ] dut1.InitializeChannel() failed with error code " << retVal; + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @test: + // @- get 11-bit filter (code 0x000 and mask 0x000) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter11Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(CANACC_CODE_11BIT, codeGet); + EXPECT_EQ(CANACC_MASK_11BIT, maskGet); + // @- set 11-bit filter (code 0x000 and mask 0x500) + codeSet = 0x00000000U; maskSet = 0x00000500U; + retVal = dut1.SetFilter11Bit(codeSet, maskSet); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get 11-bit filter (code 0x000 and mask 0x500) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter11Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(codeSet, codeGet); + EXPECT_EQ(maskGet, maskGet); + // @- reset acceptance filter + // @ note: SJA100 has only one filter for 11-bit and 29-bit identifier! + retVal = dut1.ResetFilters(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get 11-bit filter (code 0x000 and mask 0x000) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter11Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(CANACC_CODE_11BIT, codeGet); + EXPECT_EQ(CANACC_MASK_11BIT, maskGet); + // @post: + // @- start DUT1 with configured bit-rate settings + retVal = dut1.StartController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- send some frames to DUT2 and receive some frames from DUT2 + int32_t frames = g_Options.GetNumberOfTestFrames(); + EXPECT_EQ(frames, dut1.SendSomeFrames(dut2, frames)); + EXPECT_EQ(frames, dut1.ReceiveSomeFrames(dut2, frames)); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- stop/reset DUT1 + retVal = dut1.ResetController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @- tear down DUT1 + retVal = dut1.TeardownChannel(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @end. +} + +// @gtest TC23/TC24.1: Set CAN acceptance filter for 11-bit identifier with invalid interface handle(s) +// +// @note: checking channel handles is not possible with the C++ API! + +// @gtest TC24.2: Give a NULL pointer as argument for parameter 'code and 'mask' +// +// @note: passing pointers for 'code and 'mask' is not possible with the C++ API! + +// @gtest TC23/TC24.3: Set CAN acceptance filter for 11-bit identifier if CAN channel is not initialized +// +// @expected: CANERR_NOTINIT +// +TEST_F(SetFilter11Bit, GTEST_TESTCASE(IfChannelNotInitialized, GTEST_ENABLED)) { + CCanDevice dut1 = CCanDevice(TEST_DEVICE(DUT1)); + CCanDevice dut2 = CCanDevice(TEST_DEVICE(DUT2)); + CANAPI_Status_t status = {}; + uint32_t codeGet, maskGet; + uint32_t codeSet, maskSet; + CANAPI_Return_t retVal; + + // @test: + // @- try to get 11-bit filter (code 0x000 and mask 0x000) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter11Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NotInitialized, retVal); + // @- try to set 11-bit filter (code 0x000 and mask 0x500) + codeSet = 0x00000000U; maskSet = 0x00000500U; + retVal = dut1.SetFilter11Bit(codeSet, maskSet); + EXPECT_EQ(CCanApi::NotInitialized, retVal); + // @post: + // @- initialize DUT1 with configured settings + retVal = dut1.InitializeChannel(); + ASSERT_EQ(CCanApi::NoError, retVal) << "[ ERROR! ] dut1.InitializeChannel() failed with error code " << retVal; + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @- start DUT1 with configured bit-rate settings + retVal = dut1.StartController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- send some frames to DUT2 and receive some frames from DUT2 + int32_t frames = g_Options.GetNumberOfTestFrames(); + EXPECT_EQ(frames, dut1.SendSomeFrames(dut2, frames)); + EXPECT_EQ(frames, dut1.ReceiveSomeFrames(dut2, frames)); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- stop/reset DUT1 + retVal = dut1.ResetController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @- tear down DUT1 + retVal = dut1.TeardownChannel(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @end. +} + +// @gtest TC23/TC24.4: Set CAN acceptance filter for 11-bit identifier if CAN controller is not started +// +// @expected: CANERR_NOERROR +// +TEST_F(SetFilter11Bit, GTEST_TESTCASE(IfControllerNotStarted, GTEST_ENABLED)) { + CCanDevice dut1 = CCanDevice(TEST_DEVICE(DUT1)); + CCanDevice dut2 = CCanDevice(TEST_DEVICE(DUT2)); + CANAPI_Status_t status = {}; + uint32_t codeGet, maskGet; + uint32_t codeSet, maskSet; + CANAPI_Return_t retVal; + // @pre: + // @- initialize DUT1 with configured settings + retVal = dut1.InitializeChannel(); + ASSERT_EQ(CCanApi::NoError, retVal) << "[ ERROR! ] dut1.InitializeChannel() failed with error code " << retVal; + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @test: + // @- get 11-bit filter (code 0x000 and mask 0x000) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter11Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(CANACC_CODE_11BIT, codeGet); + EXPECT_EQ(CANACC_MASK_11BIT, maskGet); + // @- set 11-bit filter (code 0x000 and mask 0x500) + codeSet = 0x00000000U; maskSet = 0x00000500U; + retVal = dut1.SetFilter11Bit(codeSet, maskSet); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get 11-bit filter (code 0x000 and mask 0x500) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter11Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(codeSet, codeGet); + EXPECT_EQ(maskGet, maskGet); + // @- reset acceptance filter + // @ note: SJA100 has only one filter for 11-bit and 29-bit identifier! + retVal = dut1.ResetFilters(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get 11-bit filter (code 0x000 and mask 0x000) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter11Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(CANACC_CODE_11BIT, codeGet); + EXPECT_EQ(CANACC_MASK_11BIT, maskGet); + // @post: + // @- start DUT1 with configured bit-rate settings + retVal = dut1.StartController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- send some frames to DUT2 and receive some frames from DUT2 + int32_t frames = g_Options.GetNumberOfTestFrames(); + EXPECT_EQ(frames, dut1.SendSomeFrames(dut2, frames)); + EXPECT_EQ(frames, dut1.ReceiveSomeFrames(dut2, frames)); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- stop/reset DUT1 + retVal = dut1.ResetController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @- tear down DUT1 + retVal = dut1.TeardownChannel(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @end. +} + +// @gtest TC23/TC24.5: Set CAN acceptance filter for 11-bit identifier if CAN controller is started +// +// @expected: CANERR_ONLINE +// +TEST_F(SetFilter11Bit, GTEST_TESTCASE(IfControllerStarted, GTEST_ENABLED)) { + CCanDevice dut1 = CCanDevice(TEST_DEVICE(DUT1)); + CCanDevice dut2 = CCanDevice(TEST_DEVICE(DUT2)); + CANAPI_Status_t status = {}; + uint32_t codeGet, maskGet; + uint32_t codeSet, maskSet; + CANAPI_Return_t retVal; + + // @pre: + // @- initialize DUT1 with configured settings + retVal = dut1.InitializeChannel(); + ASSERT_EQ(CCanApi::NoError, retVal) << "[ ERROR! ] dut1.InitializeChannel() failed with error code " << retVal; + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @- start DUT1 with configured bit-rate settings + retVal = dut1.StartController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @test: + // @- try to set 11-bit filter (code 0x000 and mask 0x500) + codeSet = 0x00000000U; maskSet = 0x00000500U; + retVal = dut1.SetFilter11Bit(codeSet, maskSet); + EXPECT_EQ(CCanApi::ControllerOnline, retVal); + // @- get 11-bit filter (code 0x000 and mask 0x000) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter11Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(CANACC_CODE_11BIT, codeGet); + EXPECT_EQ(CANACC_MASK_11BIT, maskGet); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @post: + // @- send some frames to DUT2 and receive some frames from DUT2 + int32_t frames = g_Options.GetNumberOfTestFrames(); + EXPECT_EQ(frames, dut1.SendSomeFrames(dut2, frames)); + EXPECT_EQ(frames, dut1.ReceiveSomeFrames(dut2, frames)); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- stop/reset DUT1 + retVal = dut1.ResetController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @- tear down DUT1 + retVal = dut1.TeardownChannel(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @end. +} + +// @gtest TC23/TC24.6: Set CAN acceptance filter for 11-bit identifier if CAN controller was previously stopped +// +// @expected: CANERR_NOERROR +// +TEST_F(SetFilter11Bit, GTEST_TESTCASE(IfControllerStopped, GTEST_ENABLED)) { + CCanDevice dut1 = CCanDevice(TEST_DEVICE(DUT1)); + CCanDevice dut2 = CCanDevice(TEST_DEVICE(DUT2)); + CANAPI_Status_t status = {}; + uint32_t codeGet, maskGet; + uint32_t codeSet, maskSet; + CANAPI_Return_t retVal; + // @pre: + // @- initialize DUT1 with configured settings + retVal = dut1.InitializeChannel(); + ASSERT_EQ(CCanApi::NoError, retVal) << "[ ERROR! ] dut1.InitializeChannel() failed with error code " << retVal; + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @- start DUT1 with configured bit-rate settings + retVal = dut1.StartController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- send some frames to DUT2 and receive some frames from DUT2 + int32_t frames = g_Options.GetNumberOfTestFrames(); + EXPECT_EQ(frames, dut1.SendSomeFrames(dut2, frames)); + EXPECT_EQ(frames, dut1.ReceiveSomeFrames(dut2, frames)); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- stop/reset DUT1 + retVal = dut1.ResetController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @test: + // @- get 11-bit filter (code 0x000 and mask 0x000) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter11Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(CANACC_CODE_11BIT, codeGet); + EXPECT_EQ(CANACC_MASK_11BIT, maskGet); + // @- set 11-bit filter (code 0x000 and mask 0x500) + codeSet = 0x00000000U; maskSet = 0x00000500U; + retVal = dut1.SetFilter11Bit(codeSet, maskSet); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get 11-bit filter (code 0x000 and mask 0x500) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter11Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(codeSet, codeGet); + EXPECT_EQ(maskGet, maskGet); + // @- reset acceptance filter + // @ note: SJA100 has only one filter for 11-bit and 29-bit identifier! + retVal = dut1.ResetFilters(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get 11-bit filter (code 0x000 and mask 0x000) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter11Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(CANACC_CODE_11BIT, codeGet); + EXPECT_EQ(CANACC_MASK_11BIT, maskGet); + // @post: + // @- start DUT1 with configured bit-rate settings + retVal = dut1.StartController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- send some frames to DUT2 and receive some frames from DUT2 + /*int32_t*/ frames = g_Options.GetNumberOfTestFrames(); + EXPECT_EQ(frames, dut1.SendSomeFrames(dut2, frames)); + EXPECT_EQ(frames, dut1.ReceiveSomeFrames(dut2, frames)); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- stop/reset DUT1 + retVal = dut1.ResetController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @- tear down DUT1 + retVal = dut1.TeardownChannel(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @end. +} + +// @gtest TC23/TC24.7: Set CAN acceptance filter for 11-bit identifier if CAN channel was previously torn down +// +// @expected: CANERR_NOTINIT +// +TEST_F(SetFilter11Bit, GTEST_TESTCASE(IfChannelTornDown, GTEST_ENABLED)) { + CCanDevice dut1 = CCanDevice(TEST_DEVICE(DUT1)); + CCanDevice dut2 = CCanDevice(TEST_DEVICE(DUT2)); + CANAPI_Status_t status = {}; + uint32_t codeGet, maskGet; + uint32_t codeSet, maskSet; + CANAPI_Return_t retVal; + + // @pre: + // @- initialize DUT1 with configured settings + retVal = dut1.InitializeChannel(); + ASSERT_EQ(CCanApi::NoError, retVal) << "[ ERROR! ] dut1.InitializeChannel() failed with error code " << retVal; + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @- start DUT1 with configured bit-rate settings + retVal = dut1.StartController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- send some frames to DUT2 and receive some frames from DUT2 + int32_t frames = g_Options.GetNumberOfTestFrames(); + EXPECT_EQ(frames, dut1.SendSomeFrames(dut2, frames)); + EXPECT_EQ(frames, dut1.ReceiveSomeFrames(dut2, frames)); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- stop/reset DUT1 + retVal = dut1.ResetController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @- tear down DUT1 + retVal = dut1.TeardownChannel(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @test: + // @- try to get 11-bit filter (code 0x000 and mask 0x000) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter11Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NotInitialized, retVal); + // @- try to set 11-bit filter (code 0x000 and mask 0x500) + codeSet = 0x00000000U; maskSet = 0x00000500U; + retVal = dut1.SetFilter11Bit(codeSet, maskSet); + EXPECT_EQ(CCanApi::NotInitialized, retVal); + // @end. +} + +// @gtest TC23.8: Set CAN acceptance filter for 11-bit identifier with valid values +// +// @expected: CANERR_NOERROR +// +TEST_F(SetFilter11Bit, GTEST_TESTCASE(WithValidValues, GTEST_ENABLED)) { + CCanDevice dut1 = CCanDevice(TEST_DEVICE(DUT1)); + CCanDevice dut2 = CCanDevice(TEST_DEVICE(DUT2)); + CANAPI_Status_t status = {}; + uint32_t codeGet, maskGet; + const uint32_t codeSet[4] = { 0x000U, 0x0F0U, 0x70FU, 0x7FFU }; + const uint32_t maskSet[4] = { 0x000U, 0x0F0U, 0x70FU, 0x7FFU }; + CANAPI_Return_t retVal; + // @ + // @note: This test can take a very long time + if (g_Options.RunQuick()) + GTEST_SKIP() << "This test can take a very long time!"; + // @pre: + // @- initialize DUT1 with configured settings + retVal = dut1.InitializeChannel(); + ASSERT_EQ(CCanApi::NoError, retVal) << "[ ERROR! ] dut1.InitializeChannel() failed with error code " << retVal; + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @- get 11-bit filter (code 0x000 and mask 0x000) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter11Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(CANACC_CODE_11BIT, codeGet); + EXPECT_EQ(CANACC_MASK_11BIT, maskGet); + // @test: + CCounter counter = CCounter(); + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + counter.Increment(); + // @-- set 11-bit filter + retVal = dut1.SetFilter11Bit(codeSet[i], maskSet[j]); + EXPECT_EQ(CCanApi::NoError, retVal); + // @-- get 11-bit filter + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter11Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(codeSet[i], codeGet); + EXPECT_EQ(maskSet[j], maskGet); + // @-- start DUT1 with configured bit-rate settings + retVal = dut1.StartController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @-- check acceptance filter on DUT1 (DUT2 sends frames with 11-bit identifier) + counter.Clear(); + CheckFilter11Bit(dut1, codeSet[i], maskSet[j]); + // @-- stop/reset DUT1 + retVal = dut1.ResetController(); + EXPECT_EQ(CCanApi::NoError, retVal); + } + } + counter.Reset(); + // @post: + // @- reset acceptance filter + // @ note: SJA100 has only one filter for 11-bit and 29-bit identifier! + retVal = dut1.ResetFilters(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get 11-bit filter (code 0x000 and mask 0x000) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter11Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(CANACC_CODE_11BIT, codeGet); + EXPECT_EQ(CANACC_MASK_11BIT, maskGet); + // @- start DUT1 with configured bit-rate settings + retVal = dut1.StartController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- send some frames to DUT2 and receive some frames from DUT2 + int32_t frames = g_Options.GetNumberOfTestFrames(); + EXPECT_EQ(frames, dut1.SendSomeFrames(dut2, frames)); + EXPECT_EQ(frames, dut1.ReceiveSomeFrames(dut2, frames)); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- stop/reset DUT1 + retVal = dut1.ResetController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @- tear down DUT1 + retVal = dut1.TeardownChannel(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @end. +} + +// @gtest TC23.9: Set CAN acceptance filter for 11-bit identifier with invalid values +// +// @expected: CANERR_ILLPARAM +// +TEST_F(SetFilter11Bit, GTEST_TESTCASE(WithInvalidValues, GTEST_ENABLED)) { + CCanDevice dut1 = CCanDevice(TEST_DEVICE(DUT1)); + CCanDevice dut2 = CCanDevice(TEST_DEVICE(DUT2)); + CANAPI_Status_t status = {}; + uint32_t codeGet, maskGet; + uint32_t codeSet, maskSet; + CANAPI_Return_t retVal; + // @pre: + // @- initialize DUT1 with configured settings + retVal = dut1.InitializeChannel(); + ASSERT_EQ(CCanApi::NoError, retVal) << "[ ERROR! ] dut1.InitializeChannel() failed with error code " << retVal; + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @- get 11-bit filter (code 0x000 and mask 0x000) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter11Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(CANACC_CODE_11BIT, codeGet); + EXPECT_EQ(CANACC_MASK_11BIT, maskGet); + // @test: + // @- try to set 11-bit filter with invalid value (code 0x800 and mask 0x800) + codeSet = 0x00000800U; maskSet = 0x00000800U; + retVal = dut1.SetFilter11Bit(codeSet, maskSet); + EXPECT_EQ(CCanApi::IllegalParameter, retVal); + // @- try to set 11-bit filter with invalid value (code 0x000 and mask 0xFFFF) + codeSet = 0x00000000U; maskSet = 0x0000FFFFU; + retVal = dut1.SetFilter11Bit(codeSet, maskSet); + EXPECT_EQ(CCanApi::IllegalParameter, retVal); + // @- try to set 11-bit filter with invalid value (code 0x1FFFFFFF and mask 0x000) + codeSet = 0x1FFFFFFFU; maskSet = 0x00000000U; + retVal = dut1.SetFilter11Bit(codeSet, maskSet); + EXPECT_EQ(CCanApi::IllegalParameter, retVal); + // @- try to set 11-bit filter with invalid value (code 0xFFFFFFFF and mask 0xE0000000) + codeSet = 0xFFFFFFFFU; maskSet = 0xE0000000U; + retVal = dut1.SetFilter11Bit(codeSet, maskSet); + EXPECT_EQ(CCanApi::IllegalParameter, retVal); + // @post: + // @- get 11-bit filter (code 0x000 and mask 0x000) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter11Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(CANACC_CODE_11BIT, codeGet); + EXPECT_EQ(CANACC_MASK_11BIT, maskGet); + // @- start DUT1 with configured bit-rate settings + retVal = dut1.StartController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- send some frames to DUT2 and receive some frames from DUT2 + int32_t frames = g_Options.GetNumberOfTestFrames(); + EXPECT_EQ(frames, dut1.SendSomeFrames(dut2, frames)); + EXPECT_EQ(frames, dut1.ReceiveSomeFrames(dut2, frames)); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- stop/reset DUT1 + retVal = dut1.ResetController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @- tear down DUT1 + retVal = dut1.TeardownChannel(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @end. +} + +#endif // FEATURE_FILTERING != FEATURE_UNSUPPORTED + +// $Id: TC23_SetFilter11Bit.cc 1272 2024-04-16 19:55:27Z makemake $ Copyright (c) UV Software, Berlin. diff --git a/Tests/CANAPI/Testcases/TC25_SetFilter29Bit.cc b/Tests/CANAPI/Testcases/TC25_SetFilter29Bit.cc new file mode 100644 index 0000000..b036890 --- /dev/null +++ b/Tests/CANAPI/Testcases/TC25_SetFilter29Bit.cc @@ -0,0 +1,841 @@ +// SPDX-License-Identifier: BSD-2-Clause OR GPL-3.0-or-later +// +// CAN Interface API, Version 3 (Testing) +// +// Copyright (c) 2004-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) +// All rights reserved. +// +// This file is part of CAN API V3. +// +// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License +// and under the GNU General Public License v3.0 (or any later version). +// You can choose between one of them if you use this file. +// +// BSD 2-Clause "Simplified" License: +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// 1. Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// CAN API V3 IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF CAN API V3, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// GNU General Public License v3.0 or later: +// CAN API V3 is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// CAN API V3 is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with CAN API V3. If not, see . +// +#include "pch.h" + +// @note: This test suite tests the following methods: +// @ - CCanApi::SetFilter29Bit() [TC25.*] +// @ - CCanApi::GetFilter29Bit() [TC26.*] +// @ +#ifndef FEATURE_FILTERING +#define FEATURE_FILTERING FEATURE_UNSUPPORTED +#ifdef _MSC_VER +#pragma message ( "FEATURE_FILTERING not set, default = FEATURE_UNSUPPORTED" ) +#else +#warning FEATURE_FILTERING not set, default = FEATURE_UNSUPPORTED +#endif +#endif +#if (FEATURE_FILTERING != FEATURE_UNSUPPORTED) + +class SetFilter29Bit : public testing::Test { + virtual void SetUp() {} + virtual void TearDown() {} +protected: + void CheckFilter29Bit(CCanDevice& dut1, uint32_t accCode, uint32_t accMask) { + CCanDevice dut2 = CCanDevice(TEST_DEVICE(DUT2)); + CANAPI_Message_t trmMsg = {}; + CANAPI_Message_t rcvMsg = {}; + CANAPI_Return_t retVal; + // CAN message + trmMsg.id = 0U; + trmMsg.xtd = 1; + trmMsg.rtr = 0; + trmMsg.sts = 0; +#if (OPTION_CAN_2_0_ONLY != 0) + trmMsg.dlc = 0U; // CAN_MAX_DLC; + memset(trmMsg.data, 0, CAN_MAX_LEN); +#else + trmMsg.fdf = g_Options.GetOpMode(DUT1).fdoe ? 1 : 0; + trmMsg.brs = g_Options.GetOpMode(DUT1).brse ? 1 : 0; + trmMsg.esi = 0; + trmMsg.dlc = 0U; // g_Options.GetOpMode(DUT1).fdoe ? CANFD_MAX_DLC : CAN_MAX_DLC; + memset(trmMsg.data, 0, CANFD_MAX_LEN); +#endif + // initialize DUT2 with configured settings + retVal = dut2.InitializeChannel(); + ASSERT_EQ(CCanApi::NoError, retVal) << "[ ERROR! ] dut2.InitializeChannel() failed with error code " << retVal; + // start DUT2 with configured bit-rate settings + retVal = dut2.StartController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // DUT2 send 2048 standard messages + int n = 0, frames = 2048; + CProgress progress = CProgress(frames); + for (int i = 0; i < frames; i++) { + trmMsg.id = (uint32_t)i; + // send one message (retry if busy) + do { + retVal = dut2.WriteMessage(trmMsg, DEVICE_SEND_TIMEOUT); + if (retVal == CCanApi::TransmitterBusy) + PCBUSB_QXMT_DELAY(); + } while (retVal == CCanApi::TransmitterBusy); + // on error abort + if (retVal != CCanApi::NoError) { + EXPECT_EQ(retVal, CCanApi::NoError); + n = 0; + break; + } + PCBUSB_QXMT_DELAY(); // TODO: why here? + // update number of transmitted CAN messages + progress.Update((int)(i + 1), (int)0); + // update number of accepted CAN messages + if (dut1.IsCanIdAccepted(trmMsg.id, accCode, accMask)) { + n++; + } + } + // DUT1 process all messages with acceptance filter + uint64_t timeout = (((uint64_t)dut1.TransmissionTime(dut1.GetBitrate(), (n + DEVICE_LOOP_EXTRA)) + * (uint64_t)DEVICE_LOOP_FACTOR) / (uint64_t)DEVICE_LOOP_DIVISOR); // bit-rate dependent timeout + CTimer timer = CTimer(timeout); + int j = 0; + while ((j < n) && !timer.Timeout()) { + // read one message from receiver's queue, if any + retVal = dut1.ReadMessage(rcvMsg, DEVICE_READ_TIMEOUT); + if (retVal == CCanApi::NoError) { + // ignore status messages/error frames + if (!rcvMsg.sts) { + // update number of received CAN messages + progress.Update((int)frames, (int)(j + 1)); + // check if received message is accepted by acceptance filter + if (!dut1.IsCanIdAccepted(rcvMsg.id, accCode, accMask)) { + EXPECT_TRUE(dut1.IsCanIdAccepted(rcvMsg.id, accCode, accMask)); + break; + } + j++; + } + } + // on error abort (if receiver is empty, continue) + else if (retVal != CCanApi::ReceiverEmpty) { + EXPECT_EQ(retVal, CCanApi::ReceiverEmpty); + break; + } + } + progress.Clear(); + // tear down DUT2 + retVal = dut2.TeardownChannel(); + EXPECT_EQ(CCanApi::NoError, retVal); + } +}; + +// @gtest TC25/TC26.0: CAN acceptance filter for 29-bit identifier (sunnyday scenario) +// +// @expected: CANERR_NOERROR +// +TEST_F(SetFilter29Bit, GTEST_TESTCASE(SunnydayScenario, GTEST_SUNNYDAY)) { + CCanDevice dut1 = CCanDevice(TEST_DEVICE(DUT1)); + CCanDevice dut2 = CCanDevice(TEST_DEVICE(DUT2)); + CCanApi::EChannelState state; + CANAPI_Status_t status = {}; + uint32_t codeGet, maskGet; + uint32_t codeSet, maskSet; + CANAPI_Return_t retVal; + // @pre: + // @- probe if DUT1 is present and not occupied + retVal = dut1.ProbeChannel(state); + ASSERT_EQ(CCanApi::NoError, retVal) << "[ ERROR! ] dut1.ProbeChannel() failed with error code " << retVal; + ASSERT_EQ(CCanApi::ChannelAvailable, state) << "[ ERROR! ] " << g_Options.GetDeviceName(DUT1) << " is not available"; + // @- probe if DUT2 is present and not occupied + retVal = dut2.ProbeChannel(state); + ASSERT_EQ(CCanApi::NoError, retVal) << "[ ERROR! ] dut2.ProbeChannel() failed with error code " << retVal; + ASSERT_EQ(CCanApi::ChannelAvailable, state) << "[ ERROR! ] " << g_Options.GetDeviceName(DUT2) << " is not available"; + // @- check if different channels have been selected + ASSERT_TRUE((g_Options.GetChannelNo(DUT1) != g_Options.GetChannelNo(DUT2)) || \ + (g_Options.GetLibraryId(DUT1) != g_Options.GetLibraryId(DUT2))) << "[ ERROR! ] same channel selected twice"; + // @- initialize DUT1 with configured settings + retVal = dut1.InitializeChannel(); + ASSERT_EQ(CCanApi::NoError, retVal) << "[ ERROR! ] dut1.InitializeChannel() failed with error code " << retVal; + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @test: + // @- get 29-bit filter (code 0x00000000 and mask 0x00000000) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter29Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(CANACC_CODE_29BIT, codeGet); + EXPECT_EQ(CANACC_MASK_29BIT, maskGet); + // @- set 29-bit filter (code 0x00001000 and mask 0x00000500) + codeSet = 0x00001000U; maskSet = 0x00000500U; + retVal = dut1.SetFilter29Bit(codeSet, maskSet); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get 29-bit filter (code 0x00001000 and mask 0x00000500) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter29Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(codeSet, codeGet); + EXPECT_EQ(maskGet, maskGet); + // @- reset acceptance filter + // @ note: SJA100 has only one filter for 11-bit and 29-bit identifier! + retVal = dut1.ResetFilters(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get 29-bit filter (code 0x00000000 and mask 0x00000000) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter29Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(CANACC_CODE_29BIT, codeGet); + EXPECT_EQ(CANACC_MASK_29BIT, maskGet); + // @post: + // @- start DUT1 with configured bit-rate settings + retVal = dut1.StartController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- send some frames to DUT2 and receive some frames from DUT2 + int32_t frames = g_Options.GetNumberOfTestFrames(); + EXPECT_EQ(frames, dut1.SendSomeFrames(dut2, frames)); + EXPECT_EQ(frames, dut1.ReceiveSomeFrames(dut2, frames)); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- stop/reset DUT1 + retVal = dut1.ResetController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @- tear down DUT1 + retVal = dut1.TeardownChannel(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @end. +} + +// @gtest TC25/TC26.1: CAN acceptance filter for 29-bit identifier with invalid interface handle(s) +// +// @note: checking channel handles is not possible with the C++ API! + +// @gtest TC26.2: Give a NULL pointer as argument for parameter 'code and 'mask' +// +// @note: passing pointers for 'code and 'mask' is not possible with the C++ API! + +// @gtest TC25/TC26.3: CAN acceptance filter for 29-bit identifier if CAN channel is not initialized +// +// @expected: CANERR_NOTINIT +// +TEST_F(SetFilter29Bit, GTEST_TESTCASE(IfChannelNotInitialized, GTEST_ENABLED)) { + CCanDevice dut1 = CCanDevice(TEST_DEVICE(DUT1)); + CCanDevice dut2 = CCanDevice(TEST_DEVICE(DUT2)); + CANAPI_Status_t status = {}; + uint32_t codeGet, maskGet; + uint32_t codeSet, maskSet; + CANAPI_Return_t retVal; + + // @test: + // @sub(1): 11-bit identifier + // @- try to get 29-bit filter (code 0x00000000 and mask 0x00000000) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter29Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NotInitialized, retVal); + // @- try to set 29-bit filter (code 0x00001000 and mask 0x00000500) + codeSet = 0x00001000U; maskSet = 0x00000500U; + retVal = dut1.SetFilter29Bit(codeSet, maskSet); + EXPECT_EQ(CCanApi::NotInitialized, retVal); + // @post: + // @- initialize DUT1 with configured settings + retVal = dut1.InitializeChannel(); + ASSERT_EQ(CCanApi::NoError, retVal) << "[ ERROR! ] dut1.InitializeChannel() failed with error code " << retVal; + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @- start DUT1 with configured bit-rate settings + retVal = dut1.StartController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- send some frames to DUT2 and receive some frames from DUT2 + int32_t frames = g_Options.GetNumberOfTestFrames(); + EXPECT_EQ(frames, dut1.SendSomeFrames(dut2, frames)); + EXPECT_EQ(frames, dut1.ReceiveSomeFrames(dut2, frames)); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- stop/reset DUT1 + retVal = dut1.ResetController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @- tear down DUT1 + retVal = dut1.TeardownChannel(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @end. +} + +// @gtest TC25/TC26.4: CAN acceptance filter for 29-bit identifier if CAN controller is not started +// +// @expected: CANERR_NOERROR +// +TEST_F(SetFilter29Bit, GTEST_TESTCASE(IfControllerNotStarted, GTEST_ENABLED)) { + CCanDevice dut1 = CCanDevice(TEST_DEVICE(DUT1)); + CCanDevice dut2 = CCanDevice(TEST_DEVICE(DUT2)); + CANAPI_Status_t status = {}; + uint32_t codeGet, maskGet; + uint32_t codeSet, maskSet; + CANAPI_Return_t retVal; + // @pre: + // @- initialize DUT1 with configured settings + retVal = dut1.InitializeChannel(); + ASSERT_EQ(CCanApi::NoError, retVal) << "[ ERROR! ] dut1.InitializeChannel() failed with error code " << retVal; + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @test: + // @- get 29-bit filter (code 0x00000000 and mask 0x00000000) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter29Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(CANACC_CODE_29BIT, codeGet); + EXPECT_EQ(CANACC_MASK_29BIT, maskGet); + // @- set 29-bit filter (code 0x00001000 and mask 0x00000500) + codeSet = 0x00001000U; maskSet = 0x00000500U; + retVal = dut1.SetFilter29Bit(codeSet, maskSet); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get 29-bit filter (code 0x00001000 and mask 0x00000500) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter29Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(codeSet, codeGet); + EXPECT_EQ(maskGet, maskGet); + // @- reset acceptance filter + // @ note: SJA100 has only one filter for 11-bit and 29-bit identifier! + retVal = dut1.ResetFilters(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get 29-bit filter (code 0x00000000 and mask 0x00000000) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter29Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(CANACC_CODE_29BIT, codeGet); + EXPECT_EQ(CANACC_MASK_29BIT, maskGet); + // @post: + // @- start DUT1 with configured bit-rate settings + retVal = dut1.StartController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- send some frames to DUT2 and receive some frames from DUT2 + int32_t frames = g_Options.GetNumberOfTestFrames(); + EXPECT_EQ(frames, dut1.SendSomeFrames(dut2, frames)); + EXPECT_EQ(frames, dut1.ReceiveSomeFrames(dut2, frames)); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- stop/reset DUT1 + retVal = dut1.ResetController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @- tear down DUT1 + retVal = dut1.TeardownChannel(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @end. +} + +// @gtest TC25/TC26.5: CAN acceptance filter for 29-bit identifier if CAN controller is started +// +// @expected: CANERR_ONLINE +// +TEST_F(SetFilter29Bit, GTEST_TESTCASE(IfControllerStarted, GTEST_ENABLED)) { + CCanDevice dut1 = CCanDevice(TEST_DEVICE(DUT1)); + CCanDevice dut2 = CCanDevice(TEST_DEVICE(DUT2)); + CANAPI_Status_t status = {}; + uint32_t codeGet, maskGet; + uint32_t codeSet, maskSet; + CANAPI_Return_t retVal; + + // @pre: + // @- initialize DUT1 with configured settings + retVal = dut1.InitializeChannel(); + ASSERT_EQ(CCanApi::NoError, retVal) << "[ ERROR! ] dut1.InitializeChannel() failed with error code " << retVal; + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @- start DUT1 with configured bit-rate settings + retVal = dut1.StartController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @test: + // @- try to set 29-bit filter (code 0x00001000 and mask 0x00000500) + codeSet = 0x00001000U; maskSet = 0x00000500U; + retVal = dut1.SetFilter29Bit(codeSet, maskSet); + EXPECT_EQ(CCanApi::ControllerOnline, retVal); + // @- get 29-bit filter (code 0x00000000 and mask 0x00000000) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter29Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(CANACC_CODE_29BIT, codeGet); + EXPECT_EQ(CANACC_MASK_29BIT, maskGet); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @post: + // @- send some frames to DUT2 and receive some frames from DUT2 + int32_t frames = g_Options.GetNumberOfTestFrames(); + EXPECT_EQ(frames, dut1.SendSomeFrames(dut2, frames)); + EXPECT_EQ(frames, dut1.ReceiveSomeFrames(dut2, frames)); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- stop/reset DUT1 + retVal = dut1.ResetController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @- tear down DUT1 + retVal = dut1.TeardownChannel(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @end. +} + +// @gtest TC25/TC26.6: CAN acceptance filter for 29-bit identifier if CAN controller was previously stopped +// +// @expected: CANERR_NOERROR +// +TEST_F(SetFilter29Bit, GTEST_TESTCASE(IfControllerStopped, GTEST_ENABLED)) { + CCanDevice dut1 = CCanDevice(TEST_DEVICE(DUT1)); + CCanDevice dut2 = CCanDevice(TEST_DEVICE(DUT2)); + CANAPI_Status_t status = {}; + uint32_t codeGet, maskGet; + uint32_t codeSet, maskSet; + CANAPI_Return_t retVal; + // @pre: + // @- initialize DUT1 with configured settings + retVal = dut1.InitializeChannel(); + ASSERT_EQ(CCanApi::NoError, retVal) << "[ ERROR! ] dut1.InitializeChannel() failed with error code " << retVal; + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @- start DUT1 with configured bit-rate settings + retVal = dut1.StartController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- send some frames to DUT2 and receive some frames from DUT2 + int32_t frames = g_Options.GetNumberOfTestFrames(); + EXPECT_EQ(frames, dut1.SendSomeFrames(dut2, frames)); + EXPECT_EQ(frames, dut1.ReceiveSomeFrames(dut2, frames)); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- stop/reset DUT1 + retVal = dut1.ResetController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @test: + // @- get 29-bit filter (code 0x00000000 and mask 0x00000000) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter29Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(CANACC_CODE_29BIT, codeGet); + EXPECT_EQ(CANACC_MASK_29BIT, maskGet); + // @- set 29-bit filter (code 0x00001000 and mask 0x00000500) + codeSet = 0x00001000U; maskSet = 0x00000500U; + retVal = dut1.SetFilter29Bit(codeSet, maskSet); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get 29-bit filter (code 0x00001000 and mask 0x00000500) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter29Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(codeSet, codeGet); + EXPECT_EQ(maskGet, maskGet); + // @- reset acceptance filter + // @ note: SJA100 has only one filter for 11-bit and 29-bit identifier! + retVal = dut1.ResetFilters(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get 29-bit filter (code 0x00000000 and mask 0x00000000) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter29Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(CANACC_CODE_29BIT, codeGet); + EXPECT_EQ(CANACC_MASK_29BIT, maskGet); + // @post: + // @- start DUT1 with configured bit-rate settings + retVal = dut1.StartController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- send some frames to DUT2 and receive some frames from DUT2 + /*int32_t*/ frames = g_Options.GetNumberOfTestFrames(); + EXPECT_EQ(frames, dut1.SendSomeFrames(dut2, frames)); + EXPECT_EQ(frames, dut1.ReceiveSomeFrames(dut2, frames)); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- stop/reset DUT1 + retVal = dut1.ResetController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @- tear down DUT1 + retVal = dut1.TeardownChannel(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @end. +} + +// @gtest TC25/TC26.7: CAN acceptance filter for 29-bit identifier if CAN channel was previously torn down +// +// @expected: CANERR_NOTINIT +// +TEST_F(SetFilter29Bit, GTEST_TESTCASE(IfChannelTornDown, GTEST_ENABLED)) { + CCanDevice dut1 = CCanDevice(TEST_DEVICE(DUT1)); + CCanDevice dut2 = CCanDevice(TEST_DEVICE(DUT2)); + CANAPI_Status_t status = {}; + uint32_t codeGet, maskGet; + uint32_t codeSet, maskSet; + CANAPI_Return_t retVal; + + // @pre: + // @- initialize DUT1 with configured settings + retVal = dut1.InitializeChannel(); + ASSERT_EQ(CCanApi::NoError, retVal) << "[ ERROR! ] dut1.InitializeChannel() failed with error code " << retVal; + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @- start DUT1 with configured bit-rate settings + retVal = dut1.StartController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- send some frames to DUT2 and receive some frames from DUT2 + int32_t frames = g_Options.GetNumberOfTestFrames(); + EXPECT_EQ(frames, dut1.SendSomeFrames(dut2, frames)); + EXPECT_EQ(frames, dut1.ReceiveSomeFrames(dut2, frames)); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- stop/reset DUT1 + retVal = dut1.ResetController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @- tear down DUT1 + retVal = dut1.TeardownChannel(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @test: + // @- try to get 29-bit filter (code 0x00000000 and mask 0x00000000) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter29Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NotInitialized, retVal); + // @- try to set 29-bit filter (code 0x00001000 and mask 0x00000500) + codeSet = 0x00001000U; maskSet = 0x00000500U; + retVal = dut1.SetFilter29Bit(codeSet, maskSet); + EXPECT_EQ(CCanApi::NotInitialized, retVal); + // @end. +} + +// @gtest TC25.8: CAN acceptance filter for 29-bit identifier with valid values +// +// @expected: CANERR_NOERROR +// +TEST_F(SetFilter29Bit, GTEST_TESTCASE(WithValidValues, GTEST_ENABLED)) { + CCanDevice dut1 = CCanDevice(TEST_DEVICE(DUT1)); + CCanDevice dut2 = CCanDevice(TEST_DEVICE(DUT2)); + CANAPI_Status_t status = {}; + uint32_t codeGet, maskGet; + const uint32_t codeSet[4] = { 0x00000000U, 0x000000F0U, 0x0000070FU, 0x000007FFU }; + const uint32_t maskSet[4] = { 0x00000000U, 0x000000F0U, 0x0000070FU, 0x000007FFU }; + CANAPI_Return_t retVal; + // @ + // @note: This test can take a very long time + if (g_Options.RunQuick()) + GTEST_SKIP() << "This test can take a very long time!"; + // @pre: + // @- initialize DUT1 with configured settings + retVal = dut1.InitializeChannel(); + ASSERT_EQ(CCanApi::NoError, retVal) << "[ ERROR! ] dut1.InitializeChannel() failed with error code " << retVal; + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @- get 29-bit filter (code 0x00000000 and mask 0x00000000) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter29Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(CANACC_CODE_29BIT, codeGet); + EXPECT_EQ(CANACC_MASK_29BIT, maskGet); + // @test: + CCounter counter = CCounter(); + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + counter.Increment(); + // @-- set 29-bit filter + retVal = dut1.SetFilter29Bit(codeSet[i], maskSet[j]); + EXPECT_EQ(CCanApi::NoError, retVal); + // @-- get 29-bit filter + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter29Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(codeSet[i], codeGet); + EXPECT_EQ(maskSet[j], maskGet); + // @-- start DUT1 with configured bit-rate settings + retVal = dut1.StartController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @-- check acceptance filter on DUT1 (DUT2 sends frames with 29-bit identifier) + counter.Clear(); + CheckFilter29Bit(dut1, codeSet[i], maskSet[j]); + // @-- stop/reset DUT1 + retVal = dut1.ResetController(); + EXPECT_EQ(CCanApi::NoError, retVal); + } + } + counter.Reset(); + // @post: + // @- reset acceptance filter + // @ note: SJA100 has only one filter for 11-bit and 29-bit identifier! + retVal = dut1.ResetFilters(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get 29-bit filter (code 0x00000000 and mask 0x00000000) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter29Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(CANACC_CODE_29BIT, codeGet); + EXPECT_EQ(CANACC_MASK_29BIT, maskGet); + // @- start DUT1 with configured bit-rate settings + retVal = dut1.StartController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- send some frames to DUT2 and receive some frames from DUT2 + int32_t frames = g_Options.GetNumberOfTestFrames(); + EXPECT_EQ(frames, dut1.SendSomeFrames(dut2, frames)); + EXPECT_EQ(frames, dut1.ReceiveSomeFrames(dut2, frames)); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- stop/reset DUT1 + retVal = dut1.ResetController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @- tear down DUT1 + retVal = dut1.TeardownChannel(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @end. +} + +// @gtest TC25.9: CAN acceptance filter for 29-bit identifier with invalid values +// +// @expected: CANERR_ILLPARAM +// +TEST_F(SetFilter29Bit, GTEST_TESTCASE(WithInvalidValues, GTEST_ENABLED)) { + CCanDevice dut1 = CCanDevice(TEST_DEVICE(DUT1)); + CCanDevice dut2 = CCanDevice(TEST_DEVICE(DUT2)); + CANAPI_Status_t status = {}; + uint32_t codeGet, maskGet; + uint32_t codeSet, maskSet; + CANAPI_Return_t retVal; + // @pre: + // @- initialize DUT1 with configured settings + retVal = dut1.InitializeChannel(); + ASSERT_EQ(CCanApi::NoError, retVal) << "[ ERROR! ] dut1.InitializeChannel() failed with error code " << retVal; + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @- get 29-bit filter (code 0x00000000 and mask 0x00000000) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter29Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(CANACC_CODE_29BIT, codeGet); + EXPECT_EQ(CANACC_MASK_29BIT, maskGet); + // @test: + // @- try to set 29-bit filter with invalid value (code 0xE0000000 and mask 0xFFFFFFFF) + codeSet = 0xE0000000U; maskSet = 0xFFFFFFFFU; + retVal = dut1.SetFilter29Bit(codeSet, maskSet); + EXPECT_EQ(CCanApi::IllegalParameter, retVal); + // @- try to set 29-bit filter with invalid value (code 0x00000000 and mask 0xFFFFFFFF) + codeSet = 0x00000000U; maskSet = 0xFFFFFFFFU; + retVal = dut1.SetFilter29Bit(codeSet, maskSet); + EXPECT_EQ(CCanApi::IllegalParameter, retVal); + // @- try to set 29-bit filter with invalid value (code 0xE0000000 and mask 0x00000000) + codeSet = 0xE0000000U; maskSet = 0x00000000U; + retVal = dut1.SetFilter29Bit(codeSet, maskSet); + EXPECT_EQ(CCanApi::IllegalParameter, retVal); + // @post: + // @- get 29-bit filter (code 0x00000000 and mask 0x00000000) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter29Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(CANACC_CODE_29BIT, codeGet); + EXPECT_EQ(CANACC_MASK_29BIT, maskGet); + // @- start DUT1 with configured bit-rate settings + retVal = dut1.StartController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- send some frames to DUT2 and receive some frames from DUT2 + int32_t frames = g_Options.GetNumberOfTestFrames(); + EXPECT_EQ(frames, dut1.SendSomeFrames(dut2, frames)); + EXPECT_EQ(frames, dut1.ReceiveSomeFrames(dut2, frames)); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- stop/reset DUT1 + retVal = dut1.ResetController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @- tear down DUT1 + retVal = dut1.TeardownChannel(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @end. +} + +// @gtest TC25.10: CAN acceptance filter for 29-bit identifier if extended identifiers are suppressed +// +// @expected: CANERR_ILLPARAM +// +TEST_F(SetFilter29Bit, GTEST_TESTCASE(IfXtdFramesSuppressed, GTEST_ENABLED)) { + CCanDevice dut1 = CCanDevice(TEST_DEVICE(DUT1)); + CCanDevice dut2 = CCanDevice(TEST_DEVICE(DUT2)); + CANAPI_OpMode_t opMode = { TEST_CANMODE }; + CANAPI_Status_t status = {}; + uint32_t codeGet, maskGet; + uint32_t codeSet, maskSet; + CANAPI_Return_t retVal; + // @pre: + // @- set operation mode bit NXTD (suppress extended frames) + opMode = dut1.GetOpMode(); + opMode.nxtd = 1; + dut1.SetOpMode(opMode); + //dut1.ShowOperationMode(); + // @test: + // @- initialize DUT1 with operation mode bit NXTD set + retVal = dut1.InitializeChannel(); + ASSERT_EQ(CCanApi::NoError, retVal) << "[ ERROR! ] dut1.InitializeChannel() failed with error code " << retVal; + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @test: + // @- get 29-bit filter (code 0x00000000 and mask 0x00000000) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter29Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(CANACC_CODE_29BIT, codeGet); + EXPECT_EQ(CANACC_MASK_29BIT, maskGet); + // @- try to set 29-bit filter (code 0x00001000 and mask 0x00000500) + codeSet = 0x00001000U; maskSet = 0x00000500U; + retVal = dut1.SetFilter29Bit(codeSet, maskSet); + EXPECT_EQ(CCanApi::IllegalParameter, retVal); + // @- get 29-bit filter (code 0x00000000 and mask 0x00000000) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter29Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(CANACC_CODE_29BIT, codeGet); + EXPECT_EQ(CANACC_MASK_29BIT, maskGet); + // @post: + // @- start DUT1 with configured bit-rate settings + retVal = dut1.StartController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- send some frames to DUT2 and receive some frames from DUT2 + int32_t frames = g_Options.GetNumberOfTestFrames(); + EXPECT_EQ(frames, dut1.SendSomeFrames(dut2, frames)); + EXPECT_EQ(frames, dut1.ReceiveSomeFrames(dut2, frames)); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- stop/reset DUT1 + retVal = dut1.ResetController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @- tear down DUT1 + retVal = dut1.TeardownChannel(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @end. +} + +#endif // FEATURE_FILTERING != FEATURE_UNSUPPORTED + +// $Id: TC25_SetFilter29Bit.cc 1272 2024-04-16 19:55:27Z makemake $ Copyright (c) UV Software, Berlin. diff --git a/Tests/CANAPI/Testcases/TC27_ResetFilter.cc b/Tests/CANAPI/Testcases/TC27_ResetFilter.cc new file mode 100644 index 0000000..9358939 --- /dev/null +++ b/Tests/CANAPI/Testcases/TC27_ResetFilter.cc @@ -0,0 +1,601 @@ +// SPDX-License-Identifier: BSD-2-Clause OR GPL-3.0-or-later +// +// CAN Interface API, Version 3 (Testing) +// +// Copyright (c) 2004-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) +// All rights reserved. +// +// This file is part of CAN API V3. +// +// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License +// and under the GNU General Public License v3.0 (or any later version). +// You can choose between one of them if you use this file. +// +// BSD 2-Clause "Simplified" License: +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// 1. Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// CAN API V3 IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF CAN API V3, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// GNU General Public License v3.0 or later: +// CAN API V3 is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// CAN API V3 is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with CAN API V3. If not, see . +// +#include "pch.h" + +#ifndef FEATURE_FILTERING +#define FEATURE_FILTERING FEATURE_UNSUPPORTED +#ifdef _MSC_VER +#pragma message ( "FEATURE_FILTERING not set, default = FEATURE_UNSUPPORTED" ) +#else +#warning FEATURE_FILTERING not set, default = FEATURE_UNSUPPORTED +#endif +#endif +#if (FEATURE_FILTERING != FEATURE_UNSUPPORTED) + +class ResetFilter : public testing::Test { + virtual void SetUp() {} + virtual void TearDown() {} +protected: + // ... +}; + +// @gtest TC27.0: Reset CAN acceptance filter (sunnyday scenario) +// +// @expected: CANERR_NOERROR +// +TEST_F(ResetFilter, GTEST_TESTCASE(SunnydayScenario, GTEST_SUNNYDAY)) { + CCanDevice dut1 = CCanDevice(TEST_DEVICE(DUT1)); + CCanDevice dut2 = CCanDevice(TEST_DEVICE(DUT2)); + CCanApi::EChannelState state; + CANAPI_Status_t status = {}; + uint32_t codeGet, maskGet; + uint32_t codeSet, maskSet; + CANAPI_Return_t retVal; + // @pre: + // @- probe if DUT1 is present and not occupied + retVal = dut1.ProbeChannel(state); + ASSERT_EQ(CCanApi::NoError, retVal) << "[ ERROR! ] dut1.ProbeChannel() failed with error code " << retVal; + ASSERT_EQ(CCanApi::ChannelAvailable, state) << "[ ERROR! ] " << g_Options.GetDeviceName(DUT1) << " is not available"; + // @- probe if DUT2 is present and not occupied + retVal = dut2.ProbeChannel(state); + ASSERT_EQ(CCanApi::NoError, retVal) << "[ ERROR! ] dut2.ProbeChannel() failed with error code " << retVal; + ASSERT_EQ(CCanApi::ChannelAvailable, state) << "[ ERROR! ] " << g_Options.GetDeviceName(DUT2) << " is not available"; + // @- check if different channels have been selected + ASSERT_TRUE((g_Options.GetChannelNo(DUT1) != g_Options.GetChannelNo(DUT2)) || \ + (g_Options.GetLibraryId(DUT1) != g_Options.GetLibraryId(DUT2))) << "[ ERROR! ] same channel selected twice"; + // @- initialize DUT1 with configured settings + retVal = dut1.InitializeChannel(); + ASSERT_EQ(CCanApi::NoError, retVal) << "[ ERROR! ] dut1.InitializeChannel() failed with error code " << retVal; + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @test: + // @sub(1): 11-bit identifier + // @- get 11-bit filter (code 0x000 and mask 0x000) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter11Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(CANACC_CODE_11BIT, codeGet); + EXPECT_EQ(CANACC_MASK_11BIT, maskGet); + // @- set 11-bit filter (code 0x000 and mask 0x500) + // @ note: DUT2 is sending test frames with 0x200! + codeSet = 0x00000000U; maskSet = 0x0000000500U; + retVal = dut1.SetFilter11Bit(codeSet, maskSet); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get 11-bit filter (code 0x000 and mask 0x500) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter11Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(codeSet, codeGet); + EXPECT_EQ(maskGet, maskGet); + // @- reset acceptance filter + // @ note: SJA100 has only one filter for 11-bit and 29-bit identifier! + retVal = dut1.ResetFilters(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get 11-bit filter (code 0x000 and mask 0x000) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter11Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(CANACC_CODE_11BIT, codeGet); + EXPECT_EQ(CANACC_MASK_11BIT, maskGet); + // @sub(2): 29-bit identifier + // @- get 29-bit filter (code 0x00000000 and mask 0x00000000) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter29Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(CANACC_CODE_29BIT, codeGet); + EXPECT_EQ(CANACC_MASK_29BIT, maskGet); + // @- set 29-bit filter (code 0x00001000 and mask 0x00000500) + codeSet = 0x00001000U; maskSet = 0x00000500U; + retVal = dut1.SetFilter29Bit(codeSet, maskSet); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get 29-bit filter (code 0x00001000 and mask 0x00000500) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter29Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(codeSet, codeGet); + EXPECT_EQ(maskGet, maskGet); + // @- reset acceptance filter + // @ note: SJA100 has only one filter for 11-bit and 29-bit identifier! + retVal = dut1.ResetFilters(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get 29-bit filter (code 0x00000000 and mask 0x00000000) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter29Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(CANACC_CODE_29BIT, codeGet); + EXPECT_EQ(CANACC_MASK_29BIT, maskGet); + // @post: + // @- start DUT1 with configured bit-rate settings + retVal = dut1.StartController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- send some frames to DUT2 and receive some frames from DUT2 + int32_t frames = g_Options.GetNumberOfTestFrames(); + EXPECT_EQ(frames, dut1.SendSomeFrames(dut2, frames)); + EXPECT_EQ(frames, dut1.ReceiveSomeFrames(dut2, frames)); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- stop/reset DUT1 + retVal = dut1.ResetController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @- tear down DUT1 + retVal = dut1.TeardownChannel(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @end. +} + +// @gtest TC27.1: Reset CAN acceptance filter with invalid interface handle(s) +// +// @note: checking channel handles is not possible with the C++ API! + +// @gtest TC27.2: Reset CAN acceptance filter if CAN channel is not initialized +// +// @expected: CANERR_NOTINIT +// +TEST_F(ResetFilter, GTEST_TESTCASE(IfChannelNotInitialized, GTEST_ENABLED)) { + CCanDevice dut1 = CCanDevice(TEST_DEVICE(DUT1)); + CCanDevice dut2 = CCanDevice(TEST_DEVICE(DUT2)); + CANAPI_Status_t status = {}; + CANAPI_Return_t retVal; + + // @test: + // @- try to reset acceptance filter + retVal = dut1.ResetFilters(); + EXPECT_EQ(CCanApi::NotInitialized, retVal); + // @post: + // @- initialize DUT1 with configured settings + retVal = dut1.InitializeChannel(); + ASSERT_EQ(CCanApi::NoError, retVal) << "[ ERROR! ] dut1.InitializeChannel() failed with error code " << retVal; + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @- start DUT1 with configured bit-rate settings + retVal = dut1.StartController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- send some frames to DUT2 and receive some frames from DUT2 + int32_t frames = g_Options.GetNumberOfTestFrames(); + EXPECT_EQ(frames, dut1.SendSomeFrames(dut2, frames)); + EXPECT_EQ(frames, dut1.ReceiveSomeFrames(dut2, frames)); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- stop/reset DUT1 + retVal = dut1.ResetController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @- tear down DUT1 + retVal = dut1.TeardownChannel(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @end. +} + +// @gtest TC27.2: Reset CAN acceptance filter if CAN controller is not started +// +// @expected: CANERR_NOERROR +// +TEST_F(ResetFilter, GTEST_TESTCASE(IfControllerNotStarted, GTEST_ENABLED)) { + CCanDevice dut1 = CCanDevice(TEST_DEVICE(DUT1)); + CCanDevice dut2 = CCanDevice(TEST_DEVICE(DUT2)); + CANAPI_Status_t status = {}; + uint32_t codeGet, maskGet; + uint32_t codeSet, maskSet; + CANAPI_Return_t retVal; + // @pre: + // @- initialize DUT1 with configured settings + retVal = dut1.InitializeChannel(); + ASSERT_EQ(CCanApi::NoError, retVal) << "[ ERROR! ] dut1.InitializeChannel() failed with error code " << retVal; + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @test: + // @sub(1): 11-bit identifier + // @- get 11-bit filter (code 0x000 and mask 0x000) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter11Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(CANACC_CODE_11BIT, codeGet); + EXPECT_EQ(CANACC_MASK_11BIT, maskGet); + // @- set 11-bit filter (code 0x000 and mask 0x500) + // @ note: DUT2 is sending test frames with 0x200! + codeSet = 0x00000000U; maskSet = 0x0000000500U; + retVal = dut1.SetFilter11Bit(codeSet, maskSet); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get 11-bit filter (code 0x000 and mask 0x500) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter11Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(codeSet, codeGet); + EXPECT_EQ(maskGet, maskGet); + // @- reset acceptance filter + // @ note: SJA100 has only one filter for 11-bit and 29-bit identifier! + retVal = dut1.ResetFilters(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get 11-bit filter (code 0x000 and mask 0x000) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter11Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(CANACC_CODE_11BIT, codeGet); + EXPECT_EQ(CANACC_MASK_11BIT, maskGet); + // @sub(2): 29-bit identifier + // @- get 29-bit filter (code 0x00000000 and mask 0x00000000) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter29Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(CANACC_CODE_29BIT, codeGet); + EXPECT_EQ(CANACC_MASK_29BIT, maskGet); + // @- set 29-bit filter (code 0x00001000 and mask 0x00000500) + codeSet = 0x00001000U; maskSet = 0x00000500U; + retVal = dut1.SetFilter29Bit(codeSet, maskSet); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get 29-bit filter (code 0x00001000 and mask 0x00000500) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter29Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(codeSet, codeGet); + EXPECT_EQ(maskGet, maskGet); + // @- reset acceptance filter + // @ note: SJA100 has only one filter for 11-bit and 29-bit identifier! + retVal = dut1.ResetFilters(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get 29-bit filter (code 0x00000000 and mask 0x00000000) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter29Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(CANACC_CODE_29BIT, codeGet); + EXPECT_EQ(CANACC_MASK_29BIT, maskGet); + // @post: + // @- start DUT1 with configured bit-rate settings + retVal = dut1.StartController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- send some frames to DUT2 and receive some frames from DUT2 + int32_t frames = g_Options.GetNumberOfTestFrames(); + EXPECT_EQ(frames, dut1.SendSomeFrames(dut2, frames)); + EXPECT_EQ(frames, dut1.ReceiveSomeFrames(dut2, frames)); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- stop/reset DUT1 + retVal = dut1.ResetController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @- tear down DUT1 + retVal = dut1.TeardownChannel(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @end. +} + +// @gtest TC27.4: Reset CAN acceptance filter if CAN controller is started +// +// @expected: CANERR_ONLINE +// +TEST_F(ResetFilter, GTEST_TESTCASE(IfControllerStarted, GTEST_ENABLED)) { + CCanDevice dut1 = CCanDevice(TEST_DEVICE(DUT1)); + CCanDevice dut2 = CCanDevice(TEST_DEVICE(DUT2)); + CANAPI_Status_t status = {}; + uint32_t codeGet, maskGet; + CANAPI_Return_t retVal; + + // @pre: + // @- initialize DUT1 with configured settings + retVal = dut1.InitializeChannel(); + ASSERT_EQ(CCanApi::NoError, retVal) << "[ ERROR! ] dut1.InitializeChannel() failed with error code " << retVal; + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @- start DUT1 with configured bit-rate settings + retVal = dut1.StartController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @test: + // @sub(1): 11-bit identifier + // @- reset acceptance filter + // @ note: SJA100 has only one filter for 11-bit and 29-bit identifier! + retVal = dut1.ResetFilters(); + EXPECT_EQ(CCanApi::ControllerOnline, retVal); + // @- get 11-bit filter (code 0x000 and mask 0x000) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter11Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(CANACC_CODE_11BIT, codeGet); + EXPECT_EQ(CANACC_MASK_11BIT, maskGet); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @sub(2): 29-bit identifier + // @- reset acceptance filter + // @ note: SJA100 has only one filter for 11-bit and 29-bit identifier! + retVal = dut1.ResetFilters(); + EXPECT_EQ(CCanApi::ControllerOnline, retVal); + // @- get 29-bit filter (code 0x00000000 and mask 0x00000000) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter29Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(CANACC_CODE_29BIT, codeGet); + EXPECT_EQ(CANACC_MASK_29BIT, maskGet); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- try to reset acceptance filter + retVal = dut1.ResetFilters(); + EXPECT_EQ(CCanApi::ControllerOnline, retVal); + // @post: + // @- send some frames to DUT2 and receive some frames from DUT2 + int32_t frames = g_Options.GetNumberOfTestFrames(); + EXPECT_EQ(frames, dut1.SendSomeFrames(dut2, frames)); + EXPECT_EQ(frames, dut1.ReceiveSomeFrames(dut2, frames)); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- stop/reset DUT1 + retVal = dut1.ResetController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @- tear down DUT1 + retVal = dut1.TeardownChannel(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @end. +} + +// @gtest TC27.5: Reset CAN acceptance filter if CAN controller was previously stopped +// +// @expected: CANERR_NOERROR +// +TEST_F(ResetFilter, GTEST_TESTCASE(IfControllerStopped, GTEST_ENABLED)) { + CCanDevice dut1 = CCanDevice(TEST_DEVICE(DUT1)); + CCanDevice dut2 = CCanDevice(TEST_DEVICE(DUT2)); + CANAPI_Status_t status = {}; + uint32_t codeGet, maskGet; + uint32_t codeSet, maskSet; + CANAPI_Return_t retVal; + // @pre: + // @- initialize DUT1 with configured settings + retVal = dut1.InitializeChannel(); + ASSERT_EQ(CCanApi::NoError, retVal) << "[ ERROR! ] dut1.InitializeChannel() failed with error code " << retVal; + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @- start DUT1 with configured bit-rate settings + retVal = dut1.StartController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- send some frames to DUT2 and receive some frames from DUT2 + int32_t frames = g_Options.GetNumberOfTestFrames(); + EXPECT_EQ(frames, dut1.SendSomeFrames(dut2, frames)); + EXPECT_EQ(frames, dut1.ReceiveSomeFrames(dut2, frames)); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- stop/reset DUT1 + retVal = dut1.ResetController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @test: + // @sub(1): 11-bit identifier + // @- get 11-bit filter (code 0x000 and mask 0x000) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter11Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(CANACC_CODE_11BIT, codeGet); + EXPECT_EQ(CANACC_MASK_11BIT, maskGet); + // @- set 11-bit filter (code 0x000 and mask 0x500) + // @ note: DUT2 is sending test frames with 0x200! + codeSet = 0x00000000U; maskSet = 0x0000000500U; + retVal = dut1.SetFilter11Bit(codeSet, maskSet); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get 11-bit filter (code 0x000 and mask 0x500) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter11Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(codeSet, codeGet); + EXPECT_EQ(maskGet, maskGet); + // @- reset acceptance filter + // @ note: SJA100 has only one filter for 11-bit and 29-bit identifier! + retVal = dut1.ResetFilters(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get 11-bit filter (code 0x000 and mask 0x000) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter11Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(CANACC_CODE_11BIT, codeGet); + EXPECT_EQ(CANACC_MASK_11BIT, maskGet); + // @sub(2): 29-bit identifier + // @- get 29-bit filter (code 0x00000000 and mask 0x00000000) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter29Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(CANACC_CODE_29BIT, codeGet); + EXPECT_EQ(CANACC_MASK_29BIT, maskGet); + // @- set 29-bit filter (code 0x00001000 and mask 0x00000500) + codeSet = 0x00001000U; maskSet = 0x00000500U; + retVal = dut1.SetFilter29Bit(codeSet, maskSet); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get 29-bit filter (code 0x00001000 and mask 0x00000500) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter29Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(codeSet, codeGet); + EXPECT_EQ(maskGet, maskGet); + // @- reset acceptance filter + // @ note: SJA100 has only one filter for 11-bit and 29-bit identifier! + retVal = dut1.ResetFilters(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get 29-bit filter (code 0x00000000 and mask 0x00000000) + codeGet = 0xFFFFFFFFU; maskGet = 0xFFFFFFFFU; + retVal = dut1.GetFilter29Bit(codeGet, maskGet); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_EQ(CANACC_CODE_29BIT, codeGet); + EXPECT_EQ(CANACC_MASK_29BIT, maskGet); + // @post: + // @- start DUT1 with configured bit-rate settings + retVal = dut1.StartController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- send some frames to DUT2 and receive some frames from DUT2 + /*int32_t*/ frames = g_Options.GetNumberOfTestFrames(); + EXPECT_EQ(frames, dut1.SendSomeFrames(dut2, frames)); + EXPECT_EQ(frames, dut1.ReceiveSomeFrames(dut2, frames)); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- stop/reset DUT1 + retVal = dut1.ResetController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @- tear down DUT1 + retVal = dut1.TeardownChannel(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @end. +} + +// @gtest TC27.6: Reset CAN acceptance filter if CAN channel was previously torn down +// +// @expected: CANERR_NOTINIT +// +TEST_F(ResetFilter, GTEST_TESTCASE(IfChannelTornDown, GTEST_ENABLED)) { + CCanDevice dut1 = CCanDevice(TEST_DEVICE(DUT1)); + CCanDevice dut2 = CCanDevice(TEST_DEVICE(DUT2)); + CANAPI_Status_t status = {}; + CANAPI_Return_t retVal; + + // @pre: + // @- initialize DUT1 with configured settings + retVal = dut1.InitializeChannel(); + ASSERT_EQ(CCanApi::NoError, retVal) << "[ ERROR! ] dut1.InitializeChannel() failed with error code " << retVal; + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @- start DUT1 with configured bit-rate settings + retVal = dut1.StartController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- send some frames to DUT2 and receive some frames from DUT2 + int32_t frames = g_Options.GetNumberOfTestFrames(); + EXPECT_EQ(frames, dut1.SendSomeFrames(dut2, frames)); + EXPECT_EQ(frames, dut1.ReceiveSomeFrames(dut2, frames)); + // @- get status of DUT1 and check to be in RUNNING state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_FALSE(status.can_stopped); + // @- stop/reset DUT1 + retVal = dut1.ResetController(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @- get status of DUT1 and check to be in INIT state + retVal = dut1.GetStatus(status); + EXPECT_EQ(CCanApi::NoError, retVal); + EXPECT_TRUE(status.can_stopped); + // @- tear down DUT1 + retVal = dut1.TeardownChannel(); + EXPECT_EQ(CCanApi::NoError, retVal); + // @test: + // @- try to reset acceptance filter + retVal = dut1.ResetFilters(); + EXPECT_EQ(CCanApi::NotInitialized, retVal); + // @end. +} + +#endif // FEATURE_FILTERING != FEATURE_UNSUPPORTED + +// $Id: TC27_ResetFilter.cc 1272 2024-04-16 19:55:27Z makemake $ Copyright (c) UV Software, Berlin. diff --git a/Tests/CANAPI/Testcases/TCx1_CallSequences.cc b/Tests/CANAPI/Testcases/TCx1_CallSequences.cc index 77d987a..35b189c 100644 --- a/Tests/CANAPI/Testcases/TCx1_CallSequences.cc +++ b/Tests/CANAPI/Testcases/TCx1_CallSequences.cc @@ -2,13 +2,13 @@ // // CAN Interface API, Version 3 (Testing) // -// Copyright (c) 2004-2023 Uwe Vogt, UV Software, Berlin (info@uv-software.com) +// Copyright (c) 2004-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) // All rights reserved. // // This file is part of CAN API V3. // -// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License and -// under the GNU General Public License v3.0 (or any later version). +// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License +// and under the GNU General Public License v3.0 (or any later version). // You can choose between one of them if you use this file. // // BSD 2-Clause "Simplified" License: @@ -43,7 +43,7 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with CAN API V3. If not, see . +// along with CAN API V3. If not, see . // #include "pch.h" @@ -1504,4 +1504,4 @@ TEST_F(CallSequences, GTEST_TESTCASE(ReadInitializeTeardown, GTEST_DISABLED)) { // @end. } -// $Id: TCx1_CallSequences.cc 1134 2023-08-06 17:58:59Z haumea $ Copyright (c) UV Software, Berlin. +// $Id: TCx1_CallSequences.cc 1272 2024-04-16 19:55:27Z makemake $ Copyright (c) UV Software, Berlin. diff --git a/Tests/CANAPI/Testcases/TCx2_BitrateConverter.cc b/Tests/CANAPI/Testcases/TCx2_BitrateConverter.cc index b445d55..222f267 100644 --- a/Tests/CANAPI/Testcases/TCx2_BitrateConverter.cc +++ b/Tests/CANAPI/Testcases/TCx2_BitrateConverter.cc @@ -2,13 +2,13 @@ // // CAN Interface API, Version 3 (Testing) // -// Copyright (c) 2004-2023 Uwe Vogt, UV Software, Berlin (info@uv-software.com) +// Copyright (c) 2004-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) // All rights reserved. // // This file is part of CAN API V3. // -// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License and -// under the GNU General Public License v3.0 (or any later version). +// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License +// and under the GNU General Public License v3.0 (or any later version). // You can choose between one of them if you use this file. // // BSD 2-Clause "Simplified" License: @@ -43,7 +43,7 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with CAN API V3. If not, see . +// along with CAN API V3. If not, see . // #include "pch.h" #include @@ -1603,4 +1603,4 @@ TEST_F(BitrateConverter, GTEST_TESTCASE(BitrateToStringWithNullPointerForString, // // @note: passing a pointer for 'btr0btr1' is not possible with the C++ API! -// $Id: TCx2_BitrateConverter.cc 1218 2023-10-14 12:18:19Z makemake $ Copyright (c) UV Software, Berlin. +// $Id: TCx2_BitrateConverter.cc 1272 2024-04-16 19:55:27Z makemake $ Copyright (c) UV Software, Berlin. diff --git a/Tests/CANAPI/Version.h b/Tests/CANAPI/Version.h index 6d2a370..d37c8c3 100644 --- a/Tests/CANAPI/Version.h +++ b/Tests/CANAPI/Version.h @@ -2,13 +2,13 @@ // // CAN Interface API, Version 3 (Testing) // -// Copyright (c) 2004-2023 Uwe Vogt, UV Software, Berlin (info@uv-software.com) +// Copyright (c) 2004-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) // All rights reserved. // // This file is part of CAN API V3. // -// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License and -// under the GNU General Public License v3.0 (or any later version). +// CAN API V3 is dual-licensed under the BSD 2-Clause "Simplified" License +// and under the GNU General Public License v3.0 (or any later version). // You can choose between one of them if you use this file. // // BSD 2-Clause "Simplified" License: @@ -43,12 +43,12 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with CAN API V3. If not, see . +// along with CAN API V3. If not, see . // #ifndef VERSION_H_INCLUDED #define VERSION_H_INCLUDED -// SVN revision number (update with each commit: VII) -#define REVISION_NO "$Rev: 1219 $" +// SVN revision number (update with each commit: XI) +#define REVISION_NO "$Rev: 1273 $" #endif // VERSION_H_INCLUDED -// $Id: Version.h 1219 2023-10-14 12:23:07Z makemake $ Copyright (c) UV Software, Berlin // +// $Id: Version.h 1273 2024-04-18 16:59:22Z makemake $ Copyright (c) UV Software, Berlin // diff --git a/Tests/UnitTests/Driver.h b/Tests/UnitTests/Driver.h index b60dfcc..0ea7e37 100644 --- a/Tests/UnitTests/Driver.h +++ b/Tests/UnitTests/Driver.h @@ -1,12 +1,37 @@ -// SPDX-License-Identifier: GPL-3.0-or-later +// SPDX-License-Identifier: BSD-2-Clause OR GPL-3.0-or-later // -// TouCAN - macOS User-Space Driver for Rusoku TouCAN USB Interfaces +// TouCAN - macOS User-Space Driver for Rusoku TouCAN USB Adapters // -// Copyright (c) 2021-2022 Uwe Vogt, UV Software, Berlin (info@mac-can.com) +// Copyright (c) 2021-2024 Uwe Vogt, UV Software, Berlin (info@mac-can.com) // All rights reserved. // // This file is part of MacCAN-TouCAN. // +// MacCAN-TouCAN is dual-licensed under the BSD 2-Clause "Simplified" License +// and under the GNU General Public License v3.0 (or any later version). You can +// choose between one of them if you use MacCAN-TouCAN in whole or in part. +// +// BSD 2-Clause "Simplified" License: +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// 1. Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// MacCAN-TouCAN IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF MacCAN-TouCAN, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// GNU General Public License v3.0 or later: // MacCAN-TouCAN is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or @@ -20,13 +45,6 @@ // You should have received a copy of the GNU General Public License // along with MacCAN-TouCAN. If not, see . // -// IMPORTANT NOTE -// -// CAN API V3 and CAN API V3 Testing are dual-licensed under the terms of the -// BSD 2-Clause "Simplified" License and under the terms of the GNU General -// Public License v3.0 (or any later version). The terms of the GNU General -// Public License v3.0 (or any later version) apply to this work, see above. -// #ifndef DRIVER_H_INCLUDED #define DRIVER_H_INCLUDED diff --git a/Trial/Makefile b/Trial/Makefile index 9a1be4e..74b734f 100644 --- a/Trial/Makefile +++ b/Trial/Makefile @@ -1,13 +1,18 @@ # # Trial Program # MacCAN-TouCAN -# Bart Simpson didn´t do it +# Bart Simpson didn't do it # current_OS := $(shell sh -c 'uname 2>/dev/null || echo Unknown OS') current_OS := $(patsubst CYGWIN%,Cygwin,$(current_OS)) current_OS := $(patsubst MINGW%,MinGW,$(current_OS)) current_OS := $(patsubst MSYS%,MinGW,$(current_OS)) + +TARGET = tou_test + +INSTALL = ~/bin + HOME_DIR = .. MAIN_DIR = ./Sources @@ -20,17 +25,9 @@ WRAPPER_DIR = $(HOME_DIR)/Sources/Wrapper OBJECTS = $(OUTDIR)/main.o $(OUTDIR)/MacCAN_Debug.o $(OUTDIR)/MacCAN_Devices.o \ $(OUTDIR)/MacCAN_IOUsbKit.o $(OUTDIR)/MacCAN_MsgQueue.o \ $(OUTDIR)/TouCAN.o $(OUTDIR)/TouCAN_Driver.o $(OUTDIR)/TouCAN_USB_Driver.o \ - $(OUTDIR)/TouCAN_USB_Device.o $(OUTDIR)/TouCAN_USB.o \ + $(OUTDIR)/TouCAN_USB_Device.o $(OUTDIR)/TouCAN_USB_CmdMsg.o \ $(OUTDIR)/can_api.o $(OUTDIR)/can_btr.o -ifeq ($(current_OS),Darwin) # macOS - libTouCAN.dylib - -VERSION = 0 - -TARGET = tou_test - -INSTALL = ~/bin - DEFINES = -DOPTION_CAN_2_0_ONLY=1 \ -DOPTION_CANAPI_DRIVER=1 \ -DOPTION_CANAPI_RETVALS=1 \ @@ -49,6 +46,9 @@ HEADERS = -I$(SOURCE_DIR) \ -I$(WRAPPER_DIR) \ -I$(MAIN_DIR) + +ifeq ($(current_OS),Darwin) # macOS - libTouCAN.dylib + CFLAGS += -O0 -g -Wall -Wextra -Wno-parentheses \ -fmessage-length=0 -fno-strict-aliasing \ $(DEFINES) \ @@ -58,10 +58,7 @@ CXXFLAGS += -O0 -g -Wall -Wextra -pthread \ $(DEFINES) \ $(HEADERS) -LIBRARIES = - -LDFLAGS += -lpthread \ - -Wl,-framework -Wl,IOKit -Wl,-framework -Wl,CoreFoundation +LDFLAGS += -Wl,-framework -Wl,IOKit -Wl,-framework -Wl,CoreFoundation ifeq ($(BINARY),UNIVERSAL) CFLAGS += -arch arm64 -arch x86_64 @@ -69,8 +66,10 @@ CXXFLAGS += -arch arm64 -arch x86_64 LDFLAGS += -arch arm64 -arch x86_64 endif +LIBRARIES = -lpthread + CHECKER = warning,information -IGNORE = -i MacCAN_MsgPipe.c -i can_msg.c -i can_dev.c +IGNORE = -i MacCAN_MsgPipe.c -i can_dev.c ifeq ($(HUNTER),BUGS) CHECKER += --bug-hunting endif @@ -152,7 +151,7 @@ $(OUTDIR)/TouCAN_USB_Driver.o: $(DRIVER_DIR)/TouCAN_USB_Driver.c $(OUTDIR)/TouCAN_USB_Device.o: $(DRIVER_DIR)/TouCAN_USB_Device.c $(CC) $(CFLAGS) -MMD -MF $*.d -o $@ -c $< -$(OUTDIR)/TouCAN_USB.o: $(DRIVER_DIR)/TouCAN_USB.c +$(OUTDIR)/TouCAN_USB_CmdMsg.o: $(DRIVER_DIR)/TouCAN_USB_CmdMsg.c $(CC) $(CFLAGS) -MMD -MF $*.d -o $@ -c $< $(OUTDIR)/can_api.o: $(WRAPPER_DIR)/can_api.c diff --git a/Trial/Sources/main.cpp b/Trial/Sources/main.cpp index 92176ce..a29cfce 100644 --- a/Trial/Sources/main.cpp +++ b/Trial/Sources/main.cpp @@ -99,6 +99,10 @@ int main(int argc, const char * argv[]) { message.timestamp.tv_nsec = 0; CANAPI_Return_t retVal = 0; int32_t channel = (int32_t)CHANNEL; + uint32_t accCode11 = CANACC_CODE_11BIT; + uint32_t accMask11 = CANACC_MASK_11BIT; + uint32_t accCode29 = CANACC_CODE_29BIT; + uint32_t accMask29 = CANACC_MASK_29BIT; uint16_t rxTimeout = CANWAIT_INFINITE; uint16_t txTimeout = 0U; useconds_t txDelay = 0U; @@ -202,6 +206,11 @@ int main(int argc, const char * argv[]) { if (!strcmp(argv[i], "ERR:ON")) opMode.err = 1; if (!strcmp(argv[i], "XTD:OFF")) opMode.nxtd = 1; if (!strcmp(argv[i], "RTR:OFF")) opMode.nrtr = 1; + /* acceptance filtering */ + if (!strncmp(argv[i], "CODE:", 5) && sscanf(argv[i], "CODE:%x", &opt) == 1) accCode11 = (uint32_t)opt; + if (!strncmp(argv[i], "MASK:", 5) && sscanf(argv[i], "MASK:%x", &opt) == 1) accMask11 = (uint32_t)opt; + if (!strncmp(argv[i], "XCODE:", 6) && sscanf(argv[i], "XCODE:%x", &opt) == 1) accCode29 = (uint32_t)opt; + if (!strncmp(argv[i], "XMASK:", 6) && sscanf(argv[i], "XMASK:%x", &opt) == 1) accMask29 = (uint32_t)opt; } fprintf(stdout, ">>> %s\n", CCanDriver::GetVersion()); if ((signal(SIGINT, sigterm) == SIG_ERR) || @@ -234,7 +243,7 @@ int main(int argc, const char * argv[]) { fprintf(stderr, "+++ error: myDriver.GetProperty(CANPROP_GET_PATCH_NO) returned %i\n", retVal); retVal = myDriver.GetProperty(CANPROP_GET_BUILD_NO, (void *)&u32Val, sizeof(uint32_t)); if (retVal == CCanApi::NoError) - fprintf(stdout, ">>> myDriver.GetProperty(CANPROP_GET_BUILD_NO): value = 0x%07" PRIx32 "\n", u32Val); + fprintf(stdout, ">>> myDriver.GetProperty(CANPROP_GET_BUILD_NO): value = %07" PRIx32 "\n", u32Val); else fprintf(stderr, "+++ error: myDriver.GetProperty(CANPROP_GET_BUILD_NO) returned %i\n", retVal); retVal = myDriver.GetProperty(CANPROP_GET_LIBRARY_ID, (void *)&i32Val, sizeof(int32_t)); @@ -432,6 +441,21 @@ int main(int argc, const char * argv[]) { if (myDriver.GetProperty(CANPROP_GET_OP_MODE, (void *)&u8Val, sizeof(uint8_t)) == CCanApi::NoError) fprintf(stdout, ">>> myDriver.GetProperty(CANPROP_GET_OP_MODE): value = 0x%02X\n", u8Val); } + /* acceptance filtering */ + if ((accCode11 != CANACC_CODE_11BIT) || (accMask11 != CANACC_MASK_11BIT)) { + retVal = myDriver.SetFilter11Bit(accCode11, accMask11); + if (retVal != CCanApi::NoError) { + fprintf(stderr, "+++ error: myDriver.SetFilter11Bit returned %i\n", retVal); + goto teardown; + } + } + if ((accCode29 != CANACC_CODE_29BIT) || (accMask29 != CANACC_MASK_29BIT)) { + retVal = myDriver.SetFilter29Bit(accCode29, accMask29); + if (retVal != CCanApi::NoError) { + fprintf(stderr, "+++ error: myDriver.SetFilter29Bit returned %i\n", retVal); + goto teardown; + } + } /* start communication */ retVal = myDriver.StartController(bitrate); if (retVal != CCanApi::NoError) { @@ -446,6 +470,14 @@ int main(int argc, const char * argv[]) { if ((myDriver.GetBitrate(bitrate) == CCanApi::NoError) && (myDriver.GetBusSpeed(speed) == CCanApi::NoError)) verbose(opMode, bitrate, speed); + + uint32_t code, mask; + if ((myDriver.GetFilter11Bit(code, mask) == CCanApi::NoError) && + ((code != CANACC_CODE_11BIT) || (mask != CANACC_MASK_11BIT))) + fprintf(stdout, " Filter11: code = 0x%03X, mask = 0x%03X\n", code, mask); + if ((myDriver.GetFilter29Bit(code, mask) == CCanApi::NoError) && + ((code != CANACC_CODE_29BIT) || (mask != CANACC_MASK_29BIT))) + fprintf(stdout, " Filter29: code = 0x%08X, mask = 0x%08X\n", code, mask); } #ifdef SECOND_CHANNEL retVal = mySecond.InitializeChannel(channel+1U, opMode); @@ -460,14 +492,16 @@ int main(int argc, const char * argv[]) { #endif /* transmit messages */ if (option_transmit) { -// if (!option_retry) +// if ((txTimeout == 0U) && !option_retry) // fprintf(stdout, "Attention: The program will be aborted when the transmitter is busy.\n" // " Use program option RETRY or T: to avoid this.\n"); fprintf(stdout, "Press Ctrl+C to abort..."); fflush(stdout); frames = 0; now = time(NULL); while (running && (option_transmit > frames)) { -#if (OPTION_CAN_2_0_ONLY == 0) +#if (OPTION_CAN_2_0_ONLY != 0) + message.dlc = CAN_MAX_DLC; +#else if (!opMode.fdoe) { message.fdf = 0; message.brs = 0; @@ -477,8 +511,6 @@ int main(int argc, const char * argv[]) { message.brs = opMode.brse; message.dlc = CANFD_MAX_DLC; } -#else - message.dlc = CAN_MAX_DLC; #endif message.id = (uint32_t)frames & (message.xtd ? CAN_MAX_XTD_ID : CAN_MAX_STD_ID); message.data[0] = (uint8_t)(((uint64_t)frames & 0x00000000000000FF) >> 0); @@ -506,6 +538,8 @@ int main(int argc, const char * argv[]) { fprintf(stdout, ">>> myDriver.WriteMessage: status = 0x%02X\n", status.byte); } fprintf(stdout, " %i message(s) sent (took %.1lfs)\n", frames, difftime(time(NULL), now)); + if (option_exit) + goto teardown; } /* receiving message */ fprintf(stdout, "Press Ctrl+C to abort...\n"); @@ -514,10 +548,17 @@ int main(int argc, const char * argv[]) { if ((retVal = myDriver.ReadMessage(message, rxTimeout)) == CCanApi::NoError) { if (option_echo) { fprintf(stdout, ">>> %i\t", frames++); - fprintf(stdout, "%7li.%04li %03x %c%c [%i]", - message.timestamp.tv_sec, message.timestamp.tv_nsec / 100000, - message.id, message.xtd? 'X' : 'S', message.rtr? 'R' : ' ', message.dlc); - for (uint8_t i = 0; i < message.dlc; i++) + fprintf(stdout, "%7li.%04li\t", (long)message.timestamp.tv_sec, message.timestamp.tv_nsec / 100000); +#if (OPTION_CAN_2_0_ONLY != 0) + fprintf(stdout, "%03x\t%c%c [%i]", message.id, message.xtd ? 'X' : 'S', message.rtr ? 'R' : ' ', message.dlc); +#else + if (!opMode.fdoe) + fprintf(stdout, "%03x\t%c%c [%i]", message.id, message.xtd ? 'X' : 'S', message.rtr ? 'R' : ' ', message.dlc); + else + fprintf(stdout, "%03x\t%c%c%c%c%c [%i]", message.id, message.xtd ? 'X' : 'S', message.rtr ? 'R' : ' ', + message.fdf ? 'F' : ' ', message.brs ? 'B' : ' ', message.esi ? 'E' :' ', CCanApi::Dlc2Len(message.dlc)); +#endif + for (uint8_t i = 0; i < CCanApi::Dlc2Len(message.dlc); i++) fprintf(stdout, " %02x", message.data[i]); if (message.sts) { fprintf(stdout, " <<< status frame"); diff --git a/Trial/TouCAN.xcodeproj/project.pbxproj b/Trial/TouCAN.xcodeproj/project.pbxproj index b78d6c1..381691e 100644 --- a/Trial/TouCAN.xcodeproj/project.pbxproj +++ b/Trial/TouCAN.xcodeproj/project.pbxproj @@ -11,12 +11,13 @@ 0F0F805B276C92030012597F /* can_api.c in Sources */ = {isa = PBXBuildFile; fileRef = 0F0F8058276C8FF80012597F /* can_api.c */; }; 0F0F8061276D1CCD0012597F /* TouCAN_USB_Driver.c in Sources */ = {isa = PBXBuildFile; fileRef = 0F0F805D276D133C0012597F /* TouCAN_USB_Driver.c */; }; 0F0F8062276D1CD40012597F /* TouCAN_USB_Device.c in Sources */ = {isa = PBXBuildFile; fileRef = 0F0F805E276D133C0012597F /* TouCAN_USB_Device.c */; }; - 0F60A9E623F803E800D34D0E /* TouCAN_USB.c in Sources */ = {isa = PBXBuildFile; fileRef = 0F60A9E423F803E800D34D0E /* TouCAN_USB.c */; }; 0F60A9F023F8043100D34D0E /* MacCAN_Devices.c in Sources */ = {isa = PBXBuildFile; fileRef = 0F60A9EB23F8043100D34D0E /* MacCAN_Devices.c */; }; 0F60A9F123F8043100D34D0E /* MacCAN_IOUsbKit.c in Sources */ = {isa = PBXBuildFile; fileRef = 0F60A9EC23F8043100D34D0E /* MacCAN_IOUsbKit.c */; }; 0F60A9F223F8043100D34D0E /* MacCAN_Debug.c in Sources */ = {isa = PBXBuildFile; fileRef = 0F60A9EE23F8043100D34D0E /* MacCAN_Debug.c */; }; 0F68BB0F24104206005DAB17 /* can_btr.c in Sources */ = {isa = PBXBuildFile; fileRef = 0F68BB0D24104206005DAB17 /* can_btr.c */; }; 0F8B2A9E259F60BA00C8841C /* MacCAN_MsgQueue.c in Sources */ = {isa = PBXBuildFile; fileRef = 0F8B2A9D259F60BA00C8841C /* MacCAN_MsgQueue.c */; }; + 0FBF34A62BCDBD45000D9A61 /* TouCAN_USB_CmdMsg.c in Sources */ = {isa = PBXBuildFile; fileRef = 0FBF34A42BCDBD45000D9A61 /* TouCAN_USB_CmdMsg.c */; }; + 0FBF34A72BCDBD45000D9A61 /* TouCAN_USB_CmdMsg.c in Sources */ = {isa = PBXBuildFile; fileRef = 0FBF34A42BCDBD45000D9A61 /* TouCAN_USB_CmdMsg.c */; }; 0FC21A0D276E77A900863E5A /* TouCAN.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F60A9E223F803E800D34D0E /* TouCAN.cpp */; }; 0FC21A12276E90C100863E5A /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0FC21A11276E90BC00863E5A /* main.cpp */; }; 440625D82A9FB7E900EEC97D /* test_can_btr.mm in Sources */ = {isa = PBXBuildFile; fileRef = 440625D52A9FB7E900EEC97D /* test_can_btr.mm */; }; @@ -46,7 +47,6 @@ 44912E8327BD972D000EE31D /* MacCAN_Devices.c in Sources */ = {isa = PBXBuildFile; fileRef = 0F60A9EB23F8043100D34D0E /* MacCAN_Devices.c */; }; 44912E8427BD9734000EE31D /* MacCAN_Debug.c in Sources */ = {isa = PBXBuildFile; fileRef = 0F60A9EE23F8043100D34D0E /* MacCAN_Debug.c */; }; 44912E8527BD9738000EE31D /* TouCAN_USB_Device.c in Sources */ = {isa = PBXBuildFile; fileRef = 0F0F805E276D133C0012597F /* TouCAN_USB_Device.c */; }; - 44912E8627BD973D000EE31D /* TouCAN_USB.c in Sources */ = {isa = PBXBuildFile; fileRef = 0F60A9E423F803E800D34D0E /* TouCAN_USB.c */; }; 44912E8727BD9742000EE31D /* TouCAN_USB_Driver.c in Sources */ = {isa = PBXBuildFile; fileRef = 0F0F805D276D133C0012597F /* TouCAN_USB_Driver.c */; }; 44912E8827BD9747000EE31D /* TouCAN_Driver.c in Sources */ = {isa = PBXBuildFile; fileRef = 0F0F8057276C8FC40012597F /* TouCAN_Driver.c */; }; 44912E8927BD974E000EE31D /* TouCAN.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0F60A9E223F803E800D34D0E /* TouCAN.cpp */; }; @@ -78,8 +78,6 @@ 0F60A9BD23F7FDD700D34D0E /* TouCAN */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = TouCAN; sourceTree = BUILT_PRODUCTS_DIR; }; 0F60A9E123F803E800D34D0E /* TouCAN.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TouCAN.h; path = ../../Sources/TouCAN.h; sourceTree = ""; }; 0F60A9E223F803E800D34D0E /* TouCAN.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = TouCAN.cpp; path = ../../Sources/TouCAN.cpp; sourceTree = ""; }; - 0F60A9E323F803E800D34D0E /* TouCAN_USB.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TouCAN_USB.h; path = ../../Sources/Driver/TouCAN_USB.h; sourceTree = ""; }; - 0F60A9E423F803E800D34D0E /* TouCAN_USB.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = TouCAN_USB.c; path = ../../Sources/Driver/TouCAN_USB.c; sourceTree = ""; }; 0F60A9E823F8043100D34D0E /* MacCAN_Devices.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MacCAN_Devices.h; path = ../../Sources/MacCAN/MacCAN_Devices.h; sourceTree = ""; }; 0F60A9E923F8043100D34D0E /* MacCAN_Debug.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MacCAN_Debug.h; path = ../../Sources/MacCAN/MacCAN_Debug.h; sourceTree = ""; }; 0F60A9EB23F8043100D34D0E /* MacCAN_Devices.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = MacCAN_Devices.c; path = ../../Sources/MacCAN/MacCAN_Devices.c; sourceTree = ""; }; @@ -94,6 +92,8 @@ 0F8B2A9B259F60BA00C8841C /* MacCAN_MsgQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MacCAN_MsgQueue.h; path = ../../Sources/MacCAN/MacCAN_MsgQueue.h; sourceTree = ""; }; 0F8B2A9C259F60BA00C8841C /* MacCAN_Common.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MacCAN_Common.h; path = ../../Sources/MacCAN/MacCAN_Common.h; sourceTree = ""; }; 0F8B2A9D259F60BA00C8841C /* MacCAN_MsgQueue.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = MacCAN_MsgQueue.c; path = ../../Sources/MacCAN/MacCAN_MsgQueue.c; sourceTree = ""; }; + 0FBF34A42BCDBD45000D9A61 /* TouCAN_USB_CmdMsg.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = TouCAN_USB_CmdMsg.c; path = ../../Sources/Driver/TouCAN_USB_CmdMsg.c; sourceTree = ""; }; + 0FBF34A52BCDBD45000D9A61 /* TouCAN_USB_CmdMsg.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TouCAN_USB_CmdMsg.h; path = ../../Sources/Driver/TouCAN_USB_CmdMsg.h; sourceTree = ""; }; 0FC21A0E276E78C900863E5A /* CANAPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CANAPI.h; path = ../../Sources/CANAPI/CANAPI.h; sourceTree = ""; }; 0FC21A0F276E78C900863E5A /* can_api.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = can_api.h; path = ../../Sources/CANAPI/can_api.h; sourceTree = ""; }; 0FC21A10276E78C900863E5A /* CANAPI_Defines.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = CANAPI_Defines.h; path = ../../Sources/CANAPI/CANAPI_Defines.h; sourceTree = ""; }; @@ -191,8 +191,8 @@ 0F0F805E276D133C0012597F /* TouCAN_USB_Device.c */, 0F0F8060276D133C0012597F /* TouCAN_USB_Device.h */, 0F7FF6F7276BE741000033BE /* TouCAN_USB_Common.h */, - 0F60A9E423F803E800D34D0E /* TouCAN_USB.c */, - 0F60A9E323F803E800D34D0E /* TouCAN_USB.h */, + 0FBF34A42BCDBD45000D9A61 /* TouCAN_USB_CmdMsg.c */, + 0FBF34A52BCDBD45000D9A61 /* TouCAN_USB_CmdMsg.h */, 0F0F805D276D133C0012597F /* TouCAN_USB_Driver.c */, 0F0F805F276D133C0012597F /* TouCAN_USB_Driver.h */, 0F0F8057276C8FC40012597F /* TouCAN_Driver.c */, @@ -327,10 +327,10 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 0FBF34A62BCDBD45000D9A61 /* TouCAN_USB_CmdMsg.c in Sources */, 0F0F8061276D1CCD0012597F /* TouCAN_USB_Driver.c in Sources */, 0F0F805A276C91FD0012597F /* TouCAN_Driver.c in Sources */, 0FC21A0D276E77A900863E5A /* TouCAN.cpp in Sources */, - 0F60A9E623F803E800D34D0E /* TouCAN_USB.c in Sources */, 0F8B2A9E259F60BA00C8841C /* MacCAN_MsgQueue.c in Sources */, 0F60A9F123F8043100D34D0E /* MacCAN_IOUsbKit.c in Sources */, 0FC21A12276E90C100863E5A /* main.cpp in Sources */, @@ -359,6 +359,7 @@ 44912E7527BD9707000EE31D /* test_can_busload.mm in Sources */, 44912E8827BD9747000EE31D /* TouCAN_Driver.c in Sources */, 44912E8927BD974E000EE31D /* TouCAN.cpp in Sources */, + 0FBF34A72BCDBD45000D9A61 /* TouCAN_USB_CmdMsg.c in Sources */, 44912E7427BD9707000EE31D /* Tester.cpp in Sources */, 44912E8427BD9734000EE31D /* MacCAN_Debug.c in Sources */, 44912E7027BD9707000EE31D /* test_can_read.mm in Sources */, @@ -375,7 +376,6 @@ 44912E7827BD9707000EE31D /* test_can_bitrate.mm in Sources */, 44912E7B27BD9707000EE31D /* test_can_init.mm in Sources */, 44912E8127BD9725000EE31D /* MacCAN_IOUsbKit.c in Sources */, - 44912E8627BD973D000EE31D /* TouCAN_USB.c in Sources */, 44912E6E27BD9707000EE31D /* test_can_version.mm in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Utilities/Makefile b/Utilities/Makefile index 984c1e0..e733de3 100644 --- a/Utilities/Makefile +++ b/Utilities/Makefile @@ -1,7 +1,7 @@ # # CAN Utilities for generic CAN Interfaces # -# Copyright (c) 2007-2023 Uwe Vogt, UV Software, Berlin (info@mac-can.com) +# Copyright (c) 2007-2024 Uwe Vogt, UV Software, Berlin (info@mac-can.com) # # These utilities is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -14,7 +14,7 @@ # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with these utilities. If not, see . +# along with these utilities. If not, see . # all: @echo "\033[1mBuilding my beloved CAN Utilities...\033[0m" diff --git a/Utilities/can_moni/COPYING b/Utilities/can_moni/COPYING new file mode 100644 index 0000000..f288702 --- /dev/null +++ b/Utilities/can_moni/COPYING @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/Utilities/can_moni/Driver.h b/Utilities/can_moni/Driver.h index e325fe8..342e59b 100644 --- a/Utilities/can_moni/Driver.h +++ b/Utilities/can_moni/Driver.h @@ -1,8 +1,8 @@ // SPDX-License-Identifier: GPL-3.0-or-later // -// CAN Monitor for generic Interfaces (CAN API V3) +// CAN Monitor for Rusoku TouCAN USB Adapters (CAN API V3) // -// Copyright (c) 2007,2012-2023 Uwe Vogt, UV Software, Berlin (info@mac-can.com) +// Copyright (c) 2007,2012-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -15,38 +15,35 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with this program. If not, see . +// along with this program. If not, see . // #ifndef DRIVER_H_INCLUDED #define DRIVER_H_INCLUDED -#include "build_no.h" -#define VERSION_MAJOR 0 -#define VERSION_MINOR 2 -#define VERSION_PATCH 6 -#define VERSION_BUILD BUILD_NO -#define VERSION_STRING TOSTRING(VERSION_MAJOR) "." TOSTRING(VERSION_MINOR) "." TOSTRING(VERSION_PATCH) " (" TOSTRING(BUILD_NO) ")" -#if defined(_WIN64) -#define PLATFORM "x64" -#elif defined(_WIN32) -#define PLATFORM "x86" -#elif defined(__linux__) -#define PLATFORM "Linux" -#elif defined(__APPLE__) -#define PLATFORM "macOS" -#elif defined(__CYGWIN__) -#define PLATFORM "Cygwin" + +#include "TouCAN.h" + +#if (OPTION_CAN_2_0_ONLY != 0) +#ifdef _MSC_VER +#pragma message ( "Compilation with legacy CAN 2.0 frame format!" ) #else -#error Unsupported architecture +#warning Compilation with legacy CAN 2.0 frame format! #endif -#if (OPTION_CAN_2_0_ONLY != 0) -#error Compilation with legacy CAN 2.0 frame format! #else #define CAN_FD_SUPPORTED 0 // set to non-zero once CAN FD is supported #endif +#define BITRATE_800K_UNSUPPORTED 1 // set to zero if 800kbps is supported + #define MONITOR_INTEFACE "Rusoku TouCAN USB Interfaces" -#define MONITOR_COPYRIGHT "2007,2012-2023 by Uwe Vogt, UV Software, Berlin" +#define MONITOR_COPYRIGHT "2007,2012-2024 by Uwe Vogt, UV Software, Berlin" -#include "TouCAN.h" +#define BITRATE_1M(x) TOUCAN_BR_1M(x) +#define BITRATE_500K(x) TOUCAN_BR_500K(x) +#define BITRATE_250K(x) TOUCAN_BR_250K(x) +#define BITRATE_125K(x) TOUCAN_BR_125K(x) +#define BITRATE_100K(x) TOUCAN_BR_100K(x) +#define BITRATE_50K(x) TOUCAN_BR_50K(x) +#define BITRATE_20K(x) TOUCAN_BR_20K(x) +#define BITRATE_10K(x) TOUCAN_BR_10K(x) typedef CTouCAN CCanDriver; diff --git a/Utilities/can_moni/Makefile b/Utilities/can_moni/Makefile index 7ac9e97..22a4628 100644 --- a/Utilities/can_moni/Makefile +++ b/Utilities/can_moni/Makefile @@ -1,7 +1,7 @@ # # CAN Monitor for Rusoku TouCAN USB Interfaces (CAN API V3) # -# Copyright (c) 2007,2012-2023 Uwe Vogt, UV Software, Berlin (info@mac-can.com) +# Copyright (c) 2007,2012-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -14,13 +14,18 @@ # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with this program If not, see . +# along with this program If not, see . # current_OS := $(shell sh -c 'uname 2>/dev/null || echo Unknown OS') current_OS := $(patsubst CYGWIN%,Cygwin,$(current_OS)) current_OS := $(patsubst MINGW%,MinGW,$(current_OS)) current_OS := $(patsubst MSYS%,MinGW,$(current_OS)) + +TARGET = can_moni + +INSTALL = ~/bin + PROJ_DIR = ../.. HOME_DIR = . MAIN_DIR = ./Sources @@ -28,18 +33,7 @@ MAIN_DIR = ./Sources DRIVER_DIR = $(PROJ_DIR)/Sources CANAPI_DIR = $(PROJ_DIR)/Sources/CANAPI -OBJECTS = $(OUTDIR)/main.o $(OUTDIR)/Timer.o \ - $(OUTDIR)/Message.o $(OUTDIR)/can_msg.o \ - $(BINDIR)/libTouCAN.a - - -ifeq ($(current_OS),Darwin) # macOS - libTouCAN.dylib - -VERSION = 0.2.6 - -TARGET = can_moni - -INSTALL = ~/bin +OBJECTS = $(OUTDIR)/main.o $(OUTDIR)/Timer.o $(OUTDIR)/Message.o $(OUTDIR)/can_msg.o DEFINES = -DOPTION_CANAPI_DRIVER=1 \ -DOPTION_CANAPI_COMPANIONS=1 @@ -49,6 +43,11 @@ HEADERS = -I$(MAIN_DIR) \ -I$(DRIVER_DIR) \ -I$(CANAPI_DIR) + +ifeq ($(current_OS),Darwin) # macOS - libTouCAN.dylib + +OBJECTS += $(BINDIR)/libTouCAN.a + CFLAGS += -O2 -Wall -Wextra -Wno-parentheses \ -fno-strict-aliasing \ $(DEFINES) \ @@ -58,9 +57,7 @@ CXXFLAGS += -O2 -g -Wall -Wextra -pthread \ $(DEFINES) \ $(HEADERS) -LIBRARIES = - -LDFLAGS += -lpthread \ +LDFLAGS += -rpath /usr/local/lib \ -Wl,-framework -Wl,IOKit -Wl,-framework -Wl,CoreFoundation ifeq ($(BINARY),UNIVERSAL) @@ -69,6 +66,8 @@ CXXFLAGS += -arch arm64 -arch x86_64 LDFLAGS += -arch arm64 -arch x86_64 endif +LIBRARIES = -lpthread + CXX = clang++ CC = clang LD = clang++ diff --git a/Utilities/can_moni/README.md b/Utilities/can_moni/README.md index 68ff941..a92037c 100644 --- a/Utilities/can_moni/README.md +++ b/Utilities/can_moni/README.md @@ -1,27 +1,32 @@ -__CAN Monitor for Rusoku TouCAN USB Interfaces, Version 0.2.6__ \ -Copyright © 2007,2012-2023 by Uwe Vogt, UV Software, Berlin +__CAN Monitor for Rusoku TouCAN USB Interfaces, Version 0.3__ \ +Copyright © 2007,2012-2024 by Uwe Vogt, UV Software, Berlin ``` Usage: can_moni [