diff --git a/Libraries/CANAPI/Makefile b/Libraries/CANAPI/Makefile
index 5f656f6..6eb63e4 100644
--- a/Libraries/CANAPI/Makefile
+++ b/Libraries/CANAPI/Makefile
@@ -64,7 +64,7 @@ LIBRARY = libUVCANPCB
MAJOR = 0
MINOR = 2
-PATCH = 2
+PATCH = 3
VERSION = $(MAJOR).$(MINOR).$(PATCH)
TARGET = $(LIBRARY).$(VERSION).dylib
diff --git a/Libraries/PeakCAN/Makefile b/Libraries/PeakCAN/Makefile
index a24dbe4..60a6ee1 100644
--- a/Libraries/PeakCAN/Makefile
+++ b/Libraries/PeakCAN/Makefile
@@ -64,7 +64,7 @@ LIBRARY = libPeakCAN
MAJOR = 0
MINOR = 2
-PATCH = 2
+PATCH = 3
VERSION = $(MAJOR).$(MINOR).$(PATCH)
TARGET = $(LIBRARY).$(VERSION).dylib
diff --git a/README.md b/README.md
index 2c72033..bd2fb5b 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
### macOS® Wrapper Library for PCAN-USB Interfaces from Peak-System
-_Copyright © 2005-2010, 2012-2022 Uwe Vogt, UV Software, Berlin (info@mac-can.com)_
+_Copyright © 2005-2010, 2012-2022 Uwe Vogt, UV Software, Berlin (info@mac-can.com)_
# CAN API V3 for PCAN-USB Interfaces
@@ -31,6 +31,9 @@ public:
~CPeakCAN();
// CCanApi overrides
+ static bool GetFirstChannel(SChannelInfo &info, void *param = NULL);
+ static bool GetNextChannel(SChannelInfo &info, void *param = NULL);
+
static CANAPI_Return_t ProbeChannel(int32_t channel, const CANAPI_OpMode_t &opMode, const void *param, EChannelState &state);
static CANAPI_Return_t ProbeChannel(int32_t channel, const CANAPI_OpMode_t &opMode, EChannelState &state);
diff --git a/Sources/CANAPI/.gitignore b/Sources/CANAPI/.gitignore
index 1dbd7ad..3ed3371 100644
--- a/Sources/CANAPI/.gitignore
+++ b/Sources/CANAPI/.gitignore
@@ -1,3 +1,3 @@
-.svn
+.svn/
# we don't use the JSON files yet
can_dev.?
diff --git a/Sources/CANAPI/CANAPI.h b/Sources/CANAPI/CANAPI.h
index 9960c65..8e185b4 100644
--- a/Sources/CANAPI/CANAPI.h
+++ b/Sources/CANAPI/CANAPI.h
@@ -2,7 +2,7 @@
//
// CAN Interface API, Version 3 (Interface Definition)
//
-// Copyright (c) 2004-2021 Uwe Vogt, UV Software, Berlin (info@uv-software.com)
+// Copyright (c) 2004-2022 Uwe Vogt, UV Software, Berlin (info@uv-software.com)
// All rights reserved.
//
// This file is part of CAN API V3.
@@ -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: eris $
+/// \author $Author: makemake $
//
-/// \version $Rev: 1013 $
+/// \version $Rev: 1033 $
//
/// \defgroup can_api CAN Interface API, Version 3
/// \{
@@ -144,13 +144,6 @@ typedef int CANAPI_Return_t;
/// \{
class CANCPP CCanApi {
public:
- /// \brief CAN channel states
- enum EChannelState {
- ChannelOccupied = CANBRD_OCCUPIED, ///< channel is available, but occupied
- ChannelAvailable = CANBRD_PRESENT, ///< channel is available and can be used
- ChannelNotAvailable = CANBRD_NOT_PRESENT, ///< channel is not available
- ChannelNotTestable = CANBRD_NOT_TESTABLE ///< channel is not testable
- };
/// \brief Common error codes (CAN API V3 compatible)
enum EErrorCodes {
NoError = CANERR_NOERROR, ///< no error!
@@ -176,6 +169,80 @@ class CANCPP CCanApi {
FatalError = CANERR_FATAL, ///< fatal error
VendorSpecific = CANERR_VENDOR ///< offset for vendor-specific error code
};
+ /// \brief CAN channel states
+ enum EChannelState {
+ ChannelOccupied = CANBRD_OCCUPIED, ///< channel is available, but occupied
+ ChannelAvailable = CANBRD_PRESENT, ///< channel is available and can be used
+ ChannelNotAvailable = CANBRD_NOT_PRESENT, ///< channel is not available
+ ChannelNotTestable = CANBRD_NOT_TESTABLE ///< channel is not testable
+ };
+ /// \brief CAN channel information
+ struct SChannelInfo {
+ int32_t m_nChannelNo; ///< channel no. at actual index in the interface list
+ char m_szDeviceName[CANPROP_MAX_BUFFER_SIZE]; ///< device name at actual index in the interface list
+ char m_szDeviceDllName[CANPROP_MAX_BUFFER_SIZE]; ///< file name of the DLL at actual index in the interface list
+ int32_t m_nLibraryId; ///< library id at actual index in the interface list
+ char m_szVendorName[CANPROP_MAX_BUFFER_SIZE]; ///< vendor name at actual index in the interface list
+ };
+#if (OPTION_CANAPI_LIBRARY != 0)
+ /// \brief CAN API library information
+ struct SLibraryInfo {
+ int32_t m_nLibraryId; ///< library id at actual index in the vendor list
+ char m_szVendorName[CANPROP_MAX_BUFFER_SIZE]; ///< vendor name at actual index in the vendor list
+ char m_szVendorDllName[CANPROP_MAX_BUFFER_SIZE]; ///< file name of the DLL at actual index in the vendor list
+ };
+ /// \brief query library information of the first CAN API library in the
+ /// list of vendors, if any.
+ //
+ /// \param[out] info - the library information of the first entry in the list
+ //
+ /// \returns true if library information have been successfully read, or
+ /// false on error.
+ //
+ static bool GetFirstLibrary(SLibraryInfo &info);
+
+ /// \brief query library information of the next CAN API library in the
+ /// list of vendors, if any.
+ //
+ /// \param[out] info - the library information of the next entry in the list
+ //
+ /// \returns true if library information have been successfully read, or
+ /// false on error.
+ //
+ static bool GetNextLibrary(SLibraryInfo &info);
+#endif
+ /// \brief query channel information of the first 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 first 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 GetFirstChannel(int32_t library, SChannelInfo &info, void *param = NULL);
+#else
+ static bool GetFirstChannel(SChannelInfo &info, void *param = NULL);
+#endif
+
+ /// \brief query channel information of the first 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
+
/// \brief probes if the CAN interface (hardware and driver) given by
/// the argument [ 'library' and ] 'channel' is present,
/// and if the requested operation mode is supported by the
@@ -306,7 +373,7 @@ class CANCPP CCanApi {
//
/// \returns 0 if successful, or a negative value on error.
//
- virtual CANAPI_Return_t GetBusLoad(uint8_t &load) = 0;
+ virtual CANAPI_Return_t GetBusLoad(uint8_t &load) = 0; // deprecated
/// \brief retrieves the bit-rate setting of the CAN interface. The
/// CAN controller must be in operation state 'running'.
@@ -351,14 +418,14 @@ class CANCPP CCanApi {
//
/// \returns pointer to a zero-terminated string, or NULL on error.
//
- virtual char *GetHardwareVersion() = 0;
+ virtual char *GetHardwareVersion() = 0; // deprecated
/// \brief retrieves the firmware version of the CAN controller
/// board as a zero-terminated string.
//
/// \returns pointer to a zero-terminated string, or NULL on error.
//
- virtual char *GetFirmwareVersion() = 0;
+ virtual char *GetFirmwareVersion() = 0; // deprecated
/// \brief retrieves version information of the CAN API V3 driver
/// as a zero-terminated string.
@@ -411,4 +478,4 @@ class CANCPP CCanApi {
/// \}
#endif // CANAPI_H_INCLUDED
/// \}
-// $Id: CANAPI.h 1013 2021-12-13 21:34:15Z eris $ Copyright (c) UV Software //
+// $Id: CANAPI.h 1033 2022-01-11 19:58:04Z makemake $ Copyright (c) UV Software //
diff --git a/Sources/CANAPI/CANAPI_Types.h b/Sources/CANAPI/CANAPI_Types.h
index 61b9d94..1b09e58 100644
--- a/Sources/CANAPI/CANAPI_Types.h
+++ b/Sources/CANAPI/CANAPI_Types.h
@@ -2,7 +2,7 @@
/*
* CAN Interface API, Version 3 (Data Types and Defines)
*
- * Copyright (c) 2004-2021 Uwe Vogt, UV Software, Berlin (info@uv-software.com)
+ * Copyright (c) 2004-2022 Uwe Vogt, UV Software, Berlin (info@uv-software.com)
* All rights reserved.
*
* This file is part of CAN API V3.
@@ -49,9 +49,9 @@
*
* @brief CAN API V3 for generic CAN Interfaces - Data Types and Defines
*
- * @author $Author: makemake $
+ * @author $Author: haumea $
*
- * @version $Rev: 1017 $
+ * @version $Rev: 1036 $
*
* @addtogroup can_api
* @{
@@ -292,7 +292,7 @@ extern "C" {
#define CANPROP_GET_LIBRARY_ID 4U /**< library id of the library (int32_t) */
#define CANPROP_GET_LIBRARY_VENDOR 5U /**< vendor name of the library (char[256]) */
#define CANPROP_GET_LIBRARY_DLLNAME 6U /**< file name of the library DLL (char[256]) */
-#define CANPROP_GET_DEVICE_CHANNEL 10U /**< device type of the CAN interface (int32_t) */
+#define CANPROP_GET_DEVICE_TYPE 10U /**< device type of the CAN interface (int32_t) */
#define CANPROP_GET_DEVICE_NAME 11U /**< device name of the CAN interface (char[256]) */
#define CANPROP_GET_DEVICE_VENDOR 12U /**< vendor name of the CAN interface (char[256]) */
#define CANPROP_GET_DEVICE_DLLNAME 13U /**< file name of the CAN interface DLL (char[256]) */
@@ -302,24 +302,23 @@ extern "C" {
#define CANPROP_GET_BITRATE 17U /**< active bit-rate of the CAN controller (can_bitrate_t) */
#define CANPROP_GET_SPEED 18U /**< active bus speed of the CAN controller (can_speed_t) */
#define CANPROP_GET_STATUS 19U /**< current status register of the CAN controller (uint8_t) */
-#define CANPROP_GET_BUSLOAD 20U /**< current bus load of the CAN controller (uint8_t) */
+#define CANPROP_GET_BUSLOAD 20U /**< current bus load of the CAN controller (uint16_t) */
#define CANPROP_GET_NUM_CHANNELS 21U /**< numbers of CAN channels on the CAN interface (uint8_t) */
#define CANPROP_GET_CAN_CHANNEL 22U /**< active CAN channel on the CAN interface (uint8_t) */
-#define CANPROP_GET_CAN_CLOCKS 23U /**< supported CAN clocks (in [Hz]) (int32_t[64]) */
#define CANPROP_GET_TX_COUNTER 24U /**< total number of sent messages (uint64_t) */
-#define CANPROP_GET_RX_COUNTER 25U /**< total number of reveiced messages (uint64_t) */
-#define CANPROP_GET_ERR_COUNTER 26U /**< total number of reveiced error frames (uint64_t) */
+#define CANPROP_GET_RX_COUNTER 25U /**< total number of received messages (uint64_t) */
+#define CANPROP_GET_ERR_COUNTER 26U /**< total number of received error frames (uint64_t) */
#define CANPROP_GET_RCV_QUEUE_SIZE 27U /**< maximum number of message the receive queue can hold (uint32_t) */
#define CANPROP_GET_RCV_QUEUE_HIGH 28U /**< maximum number of message the receive queue has hold (uint32_t) */
#define CANPROP_GET_RCV_QUEUE_OVFL 29U /**< overflow counter of the receive queue (uint64_t) */
-#define CANPROP_GET_FLT_11BIT_CODE 32U /**< accecptance filter code of 11-bit identifier (int32_t) */
-#define CANPROP_GET_FLT_11BIT_MASK 33U /**< accecptance filter mask of 11-bit identifier (int32_t) */
-#define CANPROP_GET_FLT_29BIT_CODE 34U /**< accecptance filter code of 29-bit identifier (int32_t) */
-#define CANPROP_GET_FLT_29BIT_MASK 35U /**< accecptance filter mask of 29-bit identifier (int32_t) */
-#define CANPROP_SET_FLT_11BIT_CODE 36U /**< set value for accecptance filter code of 11-bit identifier (int32_t) */
-#define CANPROP_SET_FLT_11BIT_MASK 37U /**< set value for accecptance filter mask of 11-bit identifier (int32_t) */
-#define CANPROP_SET_FLT_29BIT_CODE 38U /**< set value for accecptance filter code of 29-bit identifier (int32_t) */
-#define CANPROP_SET_FLT_29BIT_MASK 39U /**< set value for accecptance filter mask of 29-bit identifier (int32_t) */
+#define CANPROP_GET_FLT_11BIT_CODE 32U /**< acceptance filter code of 11-bit identifier (int32_t) */
+#define CANPROP_GET_FLT_11BIT_MASK 33U /**< acceptance filter mask of 11-bit identifier (int32_t) */
+#define CANPROP_GET_FLT_29BIT_CODE 34U /**< acceptance filter code of 29-bit identifier (int32_t) */
+#define CANPROP_GET_FLT_29BIT_MASK 35U /**< acceptance filter mask of 29-bit identifier (int32_t) */
+#define CANPROP_SET_FLT_11BIT_CODE 36U /**< set value for acceptance filter code of 11-bit identifier (int32_t) */
+#define CANPROP_SET_FLT_11BIT_MASK 37U /**< set value for acceptance filter mask of 11-bit identifier (int32_t) */
+#define CANPROP_SET_FLT_29BIT_CODE 38U /**< set value for acceptance filter code of 29-bit identifier (int32_t) */
+#define CANPROP_SET_FLT_29BIT_MASK 39U /**< set value for acceptance filter mask of 29-bit identifier (int32_t) */
#if (OPTION_CANAPI_LIBRARY != 0)
/* - - build-in bit-rate conversion - - - - - - - - - - - - - - - - - */
#define CANPROP_GET_BTR_INDEX 64U /**< bit-rate as CiA index (int32_t) */
@@ -369,7 +368,7 @@ extern "C" {
#define CANPROP_GET_VENDOR_NAME 227U /**< get vendor name at actual index in the vendor list (char[256]) */
#define CANPROP_GET_VENDOR_DLLNAME 228U /**< get file name of the DLL at actual index in the vendor list (char[256]) */
#endif
-#define CANPROP_SET_FIRST_CHANNEL 240U /**< set index to the first entry in the interface list (int32_t) */
+#define CANPROP_SET_FIRST_CHANNEL 240U /**< set index to the first entry in the interface list (int32_t or NULL) */
#define CANPROP_SET_NEXT_CHANNEL 241U /**< set index to the next entry in the interface list (NULL) */
#define CANPROP_GET_CHANNEL_NO 242U /**< get channel no. at actual index in the interface list (int32_t) */
#define CANPROP_GET_CHANNEL_NAME 243U /**< get channel name at actual index in the interface list (char[256]) */
@@ -377,17 +376,18 @@ extern "C" {
#define CANPROP_GET_CHANNEL_VENDOR_ID 245U /**< get library id at actual index in the interface list (int32_t) */
#define CANPROP_GET_CHANNEL_VENDOR_NAME 246U /**< get vendor name at actual index in the interface list (char[256]) */
/* - - search path for JSON files (for C++ wrapper classes) - - - - - */
+#if (OPTION_CANAPI_LIBRARY != 0)
#define CANPROP_SET_SEARCH_PATH 253U /**< set search path for interface configuration files (char[256]) */
+#endif
/* - - access to device handle (for C++ wrapper classes) - - - - - - - */
#define CANPROP_GET_CPP_BACKDOOR 255U /**< get device handle (int32_t) */
/* - - access to vendor-specific properties - - - - - - - - - - - - - */
-#define CANPROP_GET_VENDOR_PROP 256U /**< get a vendor-specific property value (void*) */
-#define CANPROP_SET_VENDOR_PROP 512U /**< set a vendor-specific property value (void*) */
+#define CANPROP_GET_VENDOR_PROP 256U /**< offset to get a vendor-specific property value (void*) */
+#define CANPROP_SET_VENDOR_PROP 512U /**< offset to set a vendor-specific property value (void*) */
#define CANPROP_VENDOR_PROP_RANGE 256U /**< range for vendor-specific property values */
#define CANPROP_MAX_BUFFER_SIZE 256U /**< max. buffer size for property values */
#define CANPROP_MAX_STRING_LENGTH 1024U /**< max. length of a formatted message */
/* - - aliases (legacy names) - - - - - - - - - - - - - - - - - - - - */
-#define CANPROP_GET_DEVICE_TYPE CANPROP_GET_DEVICE_CHANNEL
#define CANPROP_GET_CHANNEL_TYPE CANPROP_GET_CHANNEL_NO
#define CANPROP_GET_RCV_QUEUE_MAX CANPROP_GET_RCV_QUEUE_SIZE
/** @} */
diff --git a/Sources/CANAPI/README.md b/Sources/CANAPI/README.md
index 8cfb2d8..2d6a3cf 100644
--- a/Sources/CANAPI/README.md
+++ b/Sources/CANAPI/README.md
@@ -3,7 +3,7 @@
_Copyright © 2004-2022 Uwe Vogt, UV Software, Berlin (info@uv-software.com)_ \
_All rights reserved._
-Version $Rev: 1020 $
+Version $Rev: 1036 $
# A CAN Interface Wrapper Specification
diff --git a/Sources/PeakCAN.cpp b/Sources/PeakCAN.cpp
index 1adaa0a..d7fc193 100644
--- a/Sources/PeakCAN.cpp
+++ b/Sources/PeakCAN.cpp
@@ -49,11 +49,11 @@
#ifdef _MSC_VER
#define VERSION_MAJOR 0
#define VERSION_MINOR 4
-#define VERSION_PATCH 2
+#define VERSION_PATCH 3
#else
#define VERSION_MAJOR 0
#define VERSION_MINOR 2
-#define VERSION_PATCH 2
+#define VERSION_PATCH 3
#endif
#define VERSION_BUILD BUILD_NO
#define VERSION_STRING TOSTRING(VERSION_MAJOR) "." TOSTRING(VERSION_MINOR) "." TOSTRING(VERSION_PATCH) " (" TOSTRING(BUILD_NO) ")"
@@ -138,6 +138,50 @@ CPeakCAN::~CPeakCAN() {
(void)TeardownChannel();
}
+EXPORT
+bool CPeakCAN::GetFirstChannel(SChannelInfo &info, void *param) {
+ bool result = false;
+ memset(&info, 0, sizeof(SChannelInfo));
+ info.m_nChannelNo = (-1);
+ // 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
+ 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)) {
+ // we know the library id and its vendor already
+ info.m_nLibraryId = PCAN_LIB_ID;
+ strncpy(info.m_szVendorName, PCAN_LIB_VENDOR, CANPROP_MAX_BUFFER_SIZE-1);
+ result = true;
+ }
+ }
+ (void)param;
+ return result;
+}
+
+EXPORT
+bool CPeakCAN::GetNextChannel(SChannelInfo &info, void *param) {
+ bool result = false;
+ memset(&info, 0, sizeof(SChannelInfo));
+ info.m_nChannelNo = (-1);
+ // 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
+ 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)) {
+ // we know the library id and its vendor already
+ info.m_nLibraryId = PCAN_LIB_ID;
+ strncpy(info.m_szVendorName, PCAN_LIB_VENDOR, CANPROP_MAX_BUFFER_SIZE-1);
+ result = true;
+ }
+ }
+ (void)param;
+ return result;
+}
+
EXPORT
CANAPI_Return_t CPeakCAN::ProbeChannel(int32_t channel, const CANAPI_OpMode_t &opMode, const void *param, EChannelState &state) {
// test the CAN interface (hardware and driver)
diff --git a/Sources/PeakCAN.h b/Sources/PeakCAN.h
index 88b986a..f1593ed 100644
--- a/Sources/PeakCAN.h
+++ b/Sources/PeakCAN.h
@@ -102,6 +102,9 @@ class CANCPP CPeakCAN : public CCanApi {
UnkownError = -299 ///< PCAN_ERROR_UNKNOWN: unknown error
};
// CCanApi overrides
+ static bool GetFirstChannel(SChannelInfo &info, void *param = NULL);
+ static bool GetNextChannel(SChannelInfo &info, void *param = NULL);
+
static CANAPI_Return_t ProbeChannel(int32_t channel, const CANAPI_OpMode_t &opMode, const void *param, EChannelState &state);
static CANAPI_Return_t ProbeChannel(int32_t channel, const CANAPI_OpMode_t &opMode, EChannelState &state);
@@ -144,37 +147,37 @@ class CANCPP CPeakCAN : public CCanApi {
/// \name PeakCAN Property IDs
/// \brief Properties that can be read (or written)
/// \{
-#define PEAKCAN_PROPERTY_CANAPI (CANPROP_GET_SPEC)
-#define PEAKCAN_PROPERTY_VERSION (CANPROP_GET_VERSION)
-#define PEAKCAN_PROPERTY_PATCH_NO (CANPROP_GET_PATCH_NO)
-#define PEAKCAN_PROPERTY_BUILD_NO (CANPROP_GET_BUILD_NO)
-#define PEAKCAN_PROPERTY_LIBRARY_ID (CANPROP_GET_LIBRARY_ID)
-#define PEAKCAN_PROPERTY_LIBRARY_NAME (CANPROP_GET_LIBRARY_DLLNAME)
-#define PEAKCAN_PROPERTY_LIBRARY_VENDOR (CANPROP_GET_LIBRARY_VENDOR)
-#define PEAKCAN_PROPERTY_DEVICE_CHANNEL (CANPROP_GET_DEVICE_CHANNEL)
-#define PEAKCAN_PROPERTY_DEVICE_NAME (CANPROP_GET_DEVICE_NAME)
-#define PEAKCAN_PROPERTY_DEVICE_VENDOR (CANPROP_GET_DEVICE_VENDOR)
-#define PEAKCAN_PROPERTY_DEVICE_DRIVER (CANPROP_GET_DEVICE_DLLNAME)
-#define PEAKCAN_PROPERTY_OP_CAPABILITY (CANPROP_GET_OP_CAPABILITY)
-#define PEAKCAN_PROPERTY_OP_MODE (CANPROP_GET_OP_MODE)
-#define PEAKCAN_PROPERTY_BITRATE (CANPROP_GET_BITRATE)
-#define PEAKCAN_PROPERTY_SPEED (CANPROP_GET_SPEED)
-#define PEAKCAN_PROPERTY_STATUS (CANPROP_GET_STATUS)
-#define PEAKCAN_PROPERTY_BUSLOAD (CANPROP_GET_BUSLOAD)
-//#define PEAKCAN_PROPERTY_NUM_CHANNELS (CANPROP_GET_NUM_CHANNELS)
-//#define PEAKCAN_PROPERTY_CAN_CHANNEL (CANPROP_GET_CAN_CHANNEL)
-//#define PEAKCAN_PROPERTY_CAN_CLOCKS (CANPROP_GET_CAN_CLOCKS)
-#define PEAKCAN_PROPERTY_TX_COUNTER (CANPROP_GET_TX_COUNTER)
-#define PEAKCAN_PROPERTY_RX_COUNTER (CANPROP_GET_RX_COUNTER)
-#define PEAKCAN_PROPERTY_ERR_COUNTER (CANPROP_GET_ERR_COUNTER)
-//#define PEAKCAN_PROPERTY_RCV_QUEUE_SIZE (CANPROP_GET_RCV_QUEUE_SIZE)
-//#define PEAKCAN_PROPERTY_RCV_QUEUE_HIGH (CANPROP_GET_RCV_QUEUE_HIGH)
-//#define PEAKCAN_PROPERTY_RCV_QUEUE_OVFL (CANPROP_GET_RCV_QUEUE_OVFL)
-#define PEAKCAN_PROPERTY_DEVICE_ID (CANPROP_GET_VENDOR_PROP + PCAN_DEVICE_ID)
-#define PEAKCAN_PROPERTY_API_VERSION (CANPROP_GET_VENDOR_PROP + PCAN_API_VERSION)
-#define PEAKCAN_PROPERTY_CHANNEL_VERSION (CANPROP_GET_VENDOR_PROP + PCAN_CHANNEL_VERSION)
-#define PEAKCAN_PROPERTY_HARDWARE_NAME (CANPROP_GET_VENDOR_PROP + PCAN_HARDWARE_NAME)
-//#define PEAKCAN_PROPERTY_SERIAL_NUMBER (CANPROP_GET_VENDOR_PROP + PCAN_SERIAL_NUMBER)
-//#define PEAKCAN_PROPERTY_CLOCK_DOMAIN (CANPROP_GET_VENDOR_PROP + PCAN_CLOCK_DOMAIN)
+#define PEAKCAN_PROPERTY_CANAPI (CANPROP_GET_SPEC)
+#define PEAKCAN_PROPERTY_VERSION (CANPROP_GET_VERSION)
+#define PEAKCAN_PROPERTY_PATCH_NO (CANPROP_GET_PATCH_NO)
+#define PEAKCAN_PROPERTY_BUILD_NO (CANPROP_GET_BUILD_NO)
+#define PEAKCAN_PROPERTY_LIBRARY_ID (CANPROP_GET_LIBRARY_ID)
+#define PEAKCAN_PROPERTY_LIBRARY_NAME (CANPROP_GET_LIBRARY_DLLNAME)
+#define PEAKCAN_PROPERTY_LIBRARY_VENDOR (CANPROP_GET_LIBRARY_VENDOR)
+#define PEAKCAN_PROPERTY_DEVICE_TYPE (CANPROP_GET_DEVICE_TYPE)
+#define PEAKCAN_PROPERTY_DEVICE_NAME (CANPROP_GET_DEVICE_NAME)
+#define PEAKCAN_PROPERTY_DEVICE_VENDOR (CANPROP_GET_DEVICE_VENDOR)
+#define PEAKCAN_PROPERTY_DEVICE_DRIVER (CANPROP_GET_DEVICE_DLLNAME)
+#define PEAKCAN_PROPERTY_OP_CAPABILITY (CANPROP_GET_OP_CAPABILITY)
+#define PEAKCAN_PROPERTY_OP_MODE (CANPROP_GET_OP_MODE)
+#define PEAKCAN_PROPERTY_BITRATE (CANPROP_GET_BITRATE)
+#define PEAKCAN_PROPERTY_SPEED (CANPROP_GET_SPEED)
+#define PEAKCAN_PROPERTY_STATUS (CANPROP_GET_STATUS)
+#define PEAKCAN_PROPERTY_BUSLOAD (CANPROP_GET_BUSLOAD)
+//#define PEAKCAN_PROPERTY_NUM_CHANNELS (CANPROP_GET_NUM_CHANNELS)
+//#define PEAKCAN_PROPERTY_CAN_CHANNEL (CANPROP_GET_CAN_CHANNEL)
+//#define PEAKCAN_PROPERTY_CAN_CLOCKS (CANPROP_GET_CAN_CLOCKS)
+#define PEAKCAN_PROPERTY_TX_COUNTER (CANPROP_GET_TX_COUNTER)
+#define PEAKCAN_PROPERTY_RX_COUNTER (CANPROP_GET_RX_COUNTER)
+#define PEAKCAN_PROPERTY_ERR_COUNTER (CANPROP_GET_ERR_COUNTER)
+//#define PEAKCAN_PROPERTY_RCV_QUEUE_SIZE (CANPROP_GET_RCV_QUEUE_SIZE)
+//#define PEAKCAN_PROPERTY_RCV_QUEUE_HIGH (CANPROP_GET_RCV_QUEUE_HIGH)
+//#define PEAKCAN_PROPERTY_RCV_QUEUE_OVFL (CANPROP_GET_RCV_QUEUE_OVFL)
+#define PEAKCAN_PROPERTY_DEVICE_ID (CANPROP_GET_VENDOR_PROP + PCAN_DEVICE_ID)
+#define PEAKCAN_PROPERTY_API_VERSION (CANPROP_GET_VENDOR_PROP + PCAN_API_VERSION)
+#define PEAKCAN_PROPERTY_CHANNEL_VERSION (CANPROP_GET_VENDOR_PROP + PCAN_CHANNEL_VERSION)
+#define PEAKCAN_PROPERTY_HARDWARE_NAME (CANPROP_GET_VENDOR_PROP + PCAN_HARDWARE_NAME)
+//#define PEAKCAN_PROPERTY_SERIAL_NUMBER (CANPROP_GET_VENDOR_PROP + PCAN_SERIAL_NUMBER)
+//#define PEAKCAN_PROPERTY_CLOCK_DOMAIN (CANPROP_GET_VENDOR_PROP + PCAN_CLOCK_DOMAIN)
/// \}
#endif // PEAKCAN_H_INCLUDED
diff --git a/Sources/PeakCAN_Defines.h b/Sources/PeakCAN_Defines.h
index 39790bb..d8c868a 100644
--- a/Sources/PeakCAN_Defines.h
+++ b/Sources/PeakCAN_Defines.h
@@ -91,6 +91,8 @@ extern "C" {
#define PCAN_USB15 0x50FU /**< PCAN-USB interface, channel 15 */
#define PCAN_USB16 0x510U /**< PCAN-USB interface, channel 16 */
#define PCAN_BOARDS 16 /**< number of PCAN interface boards */
+
+#define PCAN_BOARD_TYPE(x) ((((x) > 0x0FFU) ? (x) >> 8 : (x) >> 4) & 0xFU)
/** @} */
/** @name CAN API Error Codes
diff --git a/Sources/Wrapper/can_api.c b/Sources/Wrapper/can_api.c
index c70b52b..cdfd555 100755
--- a/Sources/Wrapper/can_api.c
+++ b/Sources/Wrapper/can_api.c
@@ -52,11 +52,11 @@
#ifdef _MSC_VER
#define VERSION_MAJOR 0
#define VERSION_MINOR 4
-#define VERSION_PATCH 2
+#define VERSION_PATCH 3
#else
#define VERSION_MAJOR 0
#define VERSION_MINOR 2
-#define VERSION_PATCH 2
+#define VERSION_PATCH 3
#endif
#define VERSION_BUILD BUILD_NO
#define VERSION_STRING TOSTRING(VERSION_MAJOR) "." TOSTRING(VERSION_MINOR) "." TOSTRING(VERSION_PATCH) " (" TOSTRING(BUILD_NO) ")"
@@ -101,6 +101,11 @@ static const char version[] = "CAN API V3 for PEAK PCAN-USB Interfaces, Version
/* ----------- options ------------------------------------------------
*/
+
+#if (OPTION_CAN_2_0_ONLY != 0)
+#error Compilation with legacy CAN 2.0 frame format!
+#endif
+
#if (OPTION_CANAPI_PCBUSB_DYLIB != 0)
__attribute__((constructor))
static void _initializer() {
@@ -712,6 +717,9 @@ int can_read(int handle, can_msg_t *msg, uint16_t timeout)
return CANERR_NULLPTR;
if (can[handle].status.can_stopped) // must be running
return CANERR_OFFLINE;
+ memset(msg, 0, sizeof(can_msg_t)); // invalidate the message
+ msg->id = 0xFFFFFFFFU;
+ msg->sts = 1;
// blocking read
#if !defined(_WIN32) && !defined(_WIN64)
@@ -747,6 +755,7 @@ int can_read(int handle, can_msg_t *msg, uint16_t timeout)
}
if (!can[handle].mode.fdoe) { // CAN 2.0 message:
if ((can_msg.MSGTYPE & PCAN_MESSAGE_STATUS)) {
+ // TODO: encode status message (status)
can[handle].status.bus_off = (can_msg.DATA[3] & PCAN_ERROR_BUSOFF) != PCAN_ERROR_OK;
can[handle].status.bus_error = (can_msg.DATA[3] & PCAN_ERROR_BUSPASSIVE) != PCAN_ERROR_OK;
can[handle].status.warning_level = (can_msg.DATA[3] & PCAN_ERROR_BUSWARNING) != PCAN_ERROR_OK;
@@ -755,6 +764,7 @@ int can_read(int handle, can_msg_t *msg, uint16_t timeout)
return CANERR_RX_EMPTY; // receiver empty
}
if ((can_msg.MSGTYPE & PCAN_MESSAGE_ERRFRAME)) {
+ // TODO: encode status message (error frame)
can[handle].status.receiver_empty = 1;
can[handle].counters.err++;
return CANERR_ERR_FRAME; // error frame received
@@ -765,6 +775,7 @@ int can_read(int handle, can_msg_t *msg, uint16_t timeout)
msg->fdf = 0;
msg->brs = 0;
msg->esi = 0;
+ msg->sts = 0;
msg->dlc = (uint8_t)can_msg.LEN;
memcpy(msg->data, can_msg.DATA, CAN_MAX_LEN);
msec = ((uint64_t)timestamp.millis_overflow << 32) + (uint64_t)timestamp.millis;
@@ -791,6 +802,7 @@ int can_read(int handle, can_msg_t *msg, uint16_t timeout)
msg->fdf = (can_msg_fd.MSGTYPE & PCAN_MESSAGE_FD) ? 1 : 0;
msg->brs = (can_msg_fd.MSGTYPE & PCAN_MESSAGE_BRS) ? 1 : 0;
msg->esi = (can_msg_fd.MSGTYPE & PCAN_MESSAGE_ESI) ? 1 : 0;
+ msg->sts = 0;
msg->dlc = (uint8_t)can_msg_fd.DLC;
memcpy(msg->data, can_msg_fd.DATA, CANFD_MAX_LEN);
msg->timestamp.tv_sec = (time_t)(timestamp_fd / 1000000ull);
@@ -1020,7 +1032,7 @@ static int pcan_compatibility(void) {
TPCANStatus sts; // channel status
unsigned int major = 0, minor = 0; // channel version
char version[256] = "PCBUSB library, version 0.0.0.0";
-
+
/* (ยง1) get library version (as a string) */
if ((sts = CAN_GetValue(PCAN_NONEBUS, PCAN_EXT_SOFTWARE_VERSION, (void*)version, 256)) != PCAN_ERROR_OK)
return pcan_error(sts);
@@ -1273,7 +1285,6 @@ static int lib_parameter(uint16_t param, void *value, size_t nbyte)
rc = CANERR_NOERROR;
}
break;
- /* *** **
case CANPROP_GET_DEVICE_VENDOR: // vendor name of the CAN interface (char[256])
if ((nbyte > strlen(PCAN_LIB_VENDOR)) && (nbyte <= CANPROP_MAX_BUFFER_SIZE)) {
strcpy((char*)value, PCAN_LIB_VENDOR);
@@ -1286,7 +1297,6 @@ static int lib_parameter(uint16_t param, void *value, size_t nbyte)
rc = CANERR_NOERROR;
}
break;
- ** *** */
case CANPROP_SET_FIRST_CHANNEL: // set index to the first entry in the interface list (NULL)
idx_board = 0;
rc = (can_boards[idx_board].type != EOF) ? CANERR_NOERROR : CANERR_RESOURCE;
@@ -1360,17 +1370,14 @@ static int lib_parameter(uint16_t param, void *value, size_t nbyte)
break;
case CANPROP_GET_DEVICE_TYPE: // device type of the CAN interface (int32_t)
case CANPROP_GET_DEVICE_NAME: // device name of the CAN interface (char[256])
- case CANPROP_GET_DEVICE_VENDOR: // vendor name of the CAN interface (char[256])
- case CANPROP_GET_DEVICE_DLLNAME: // file name of the CAN interface DLL (char[256])
case CANPROP_GET_OP_CAPABILITY: // supported operation modes of the CAN controller (uint8_t)
case CANPROP_GET_OP_MODE: // active operation mode of the CAN controller (uint8_t)
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_CLOCKS: // supported CAN clocks (in [Hz]) (int32_t[64])
case CANPROP_GET_TX_COUNTER: // total number of sent messages (uint64_t)
case CANPROP_GET_RX_COUNTER: // total number of reveiced messages (uint64_t)
case CANPROP_GET_ERR_COUNTER: // total number of reveiced error frames (uint64_t)
@@ -1428,7 +1435,7 @@ static int drv_parameter(int handle, uint16_t param, void *value, size_t nbyte)
switch (param) {
case CANPROP_GET_DEVICE_TYPE: // device type of the CAN interface (int32_t)
if (nbyte >= sizeof(int32_t)) {
- *(int32_t*)value = (int32_t)can[handle].board;
+ *(int32_t*)value = (int32_t)PCAN_BOARD_TYPE(can[handle].board);
rc = CANERR_NOERROR;
}
break;
@@ -1500,14 +1507,22 @@ 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) {
- *(uint8_t*)value = (uint8_t)load;
+ 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%
rc = CANERR_NOERROR;
}
}
break;
+ 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)
+ // TODO: insert coin here
+ rc = CANERR_NOTSUPP;
+ break;
case CANPROP_GET_TX_COUNTER: // total number of sent messages (uint64_t)
if (nbyte >= sizeof(uint64_t)) {
*(uint64_t*)value = (uint64_t)can[handle].counters.tx;
@@ -1526,6 +1541,12 @@ static int drv_parameter(int handle, uint16_t param, void *value, size_t nbyte)
rc = CANERR_NOERROR;
}
break;
+ 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)
+ // note: cannot be determined
+ rc = CANERR_NOTSUPP; // FIXME: ?
+ break;
default:
if ((CANPROP_GET_VENDOR_PROP <= param) && // get a vendor-specific property value (void*)
(param < (CANPROP_GET_VENDOR_PROP + CANPROP_VENDOR_PROP_RANGE))) {
diff --git a/Tests/UnitTests/Template.h b/Tests/UnitTests/Driver.h
similarity index 97%
rename from Tests/UnitTests/Template.h
rename to Tests/UnitTests/Driver.h
index a84a2d0..bbca55a 100644
--- a/Tests/UnitTests/Template.h
+++ b/Tests/UnitTests/Driver.h
@@ -1,7 +1,7 @@
//
// PeakCAN - macOS User-Space Driver for Peak-System USB-to-CAN Interfaces
//
-// Copyright (C) 2021 Uwe Vogt, UV Software, Berlin (info@mac-can.com)
+// Copyright (C) 2021-2022 Uwe Vogt, UV Software, Berlin (info@mac-can.com)
// All rights reserved.
//
// This file is part of MacCAN-PeakCAN.
@@ -44,8 +44,8 @@
// You should have received a copy of the GNU General Public License
// along with MacCAN-PeakCAN. If not, see .
//
-#ifndef TEMPLATE_H_INCLUDED
-#define TEMPLATE_H_INCLUDED
+#ifndef DRIVER_H_INCLUDED
+#define DRIVER_H_INCLUDED
// A Template for CAN API V3 Testing
//
@@ -97,6 +97,6 @@
//#define TX0x_y_WORKARAOUND 1
#endif // CAN_FD_SUPPORTED
-#endif // TEMPLATE_H_INCLUDED
+#endif // DRIVER_H_INCLUDED
// $Id: Template.h 1035 2021-12-21 12:03:27Z makemake $ Copyright (c) UV Software, Berlin //
diff --git a/Tests/UnitTests/Settings.h b/Tests/UnitTests/Settings.h
index 5ceba7f..cd10321 100644
--- a/Tests/UnitTests/Settings.h
+++ b/Tests/UnitTests/Settings.h
@@ -59,25 +59,60 @@
#define TEST_CANMODE CANMODE_DEFAULT
#define TEST_BTRINDEX CANBTR_INDEX_250K
-// General test options:
+// General test settings:
// - number of CAN frames to be send during test cases
-#define TEST_FRAMES 8
+// note: a small number speeds up the test duration.
+#define TEST_FRAMES 8 /// default = 8
// - number of CAN frames to be send during smoke test
-#define TEST_TRAFFIC 2048
+// note: long-term stress test with a large number.
+#define TEST_TRAFFIC 2048 /// default = 2048
+// - number of CAN frames to be send during time-stamp test
+// note: not too small because of statistic evaluation.
+#define TEST_TIMESTAMP 1000 /// default = 1000
// - number of CAN frames to be send until queue overrun
-#define TEST_QUEUE_FULL 65536
+// note: maybe delay for buffered transmission required.
+#define TEST_QUEUE_FULL 65536 /// default = 65'536
#if (TX_ACKNOWLEDGE_UNSUPPORTED != 0)
-#define TEST_AFTER_BURNER 3000 /* [ms] */
+#define TEST_AFTER_BURNER 3000 /// default = 3000 (in [ms])
#endif
-// - enable/disable sending of CAN frames during test cases
-#define SEND_TEST_FRAMES 1
+// - enable/disable sending of CAN frames during sunnyday scenarios
+// note: disable this option to not repeat the same crap forever.
+#define SEND_TEST_FRAMES 1 /// default = enabled
// - enable/disable sending of CAN frames with non-default baudrate
// note: disable this option when a 3rd CAN device is on the bus.
-#define SEND_WITH_NONE_DEFAULT_BAUDRATE 0
+#define SEND_WITH_NONE_DEFAULT_BAUDRATE 1 /// default = enabled
+// - enable/disable exiting loops over properties on error
+// note: enable this option to debug a failing property.
+#define EXIT_PROPERTY_LOOP_ON_ERROR 0 /// default = disabled
+
+// Settings for time-stamp accuracy:
+// - time-stamp test with 10ms transmission delay
+#define TEST_TIMESTAMP_10MS 1 /// default = enabled
+#define TIMESTAMP_LOWER_10MS 9500 /// lower threshold = delay - 500usec
+#define TIMESTAMP_UPPER_10MS 10500 /// upper threshold = delay + 500usec
+// - time-stamp test with 7ms transmission delay
+#define TEST_TIMESTAMP_7MS 1 /// default = enabled
+#define TIMESTAMP_LOWER_7MS 6500 /// lower threshold = delay - 500usec
+#define TIMESTAMP_UPPER_7MS 7500 /// upper threshold = delay + 500usec
+// - time-stamp test with 5ms transmission delay
+#define TEST_TIMESTAMP_5MS 1 /// default = enabled
+#define TIMESTAMP_LOWER_5MS 4500 /// lower threshold = delay - 500usec
+#define TIMESTAMP_UPPER_5MS 5500 /// upper threshold = delay + 500usec
+// - time-stamp test with 2ms transmission delay
+#define TEST_TIMESTAMP_2MS 1 /// default = enabled
+#define TIMESTAMP_LOWER_2MS 1500 /// lower threshold = delay - 500usec
+#define TIMESTAMP_UPPER_2MS 2500 /// upper threshold = delay + 500usec
+// - time-stamp test with 1ms transmission delay
+#define TEST_TIMESTAMP_1MS 1 /// default = enabled
+#define TIMESTAMP_LOWER_1MS 500 /// lower threshold = delay - 500usec
+#define TIMESTAMP_UPPER_1MS 1500 /// upper threshold = delay + 500usec
+// - time-stamp test without transmission delay
+#define TEST_TIMESTAMP_0MS 1 /// cannot be disabled
+#define TIMESTAMP_UPPER_0MS 25000 /// approx. time @ 5kbps
// Useful stuff:
#define INVALID_HANDLE (-1)
#endif // SETTINGS_H_INCLUDED
-// $Id: Settings.h 1037 2021-12-21 19:27:26Z makemake $ Copyright (c) UV Software, Berlin //
+// $Id: Settings.h 1084 2022-01-07 13:31:39Z makemake $ Copyright (c) UV Software, Berlin //
diff --git a/Tests/UnitTests/Tester.h b/Tests/UnitTests/Tester.h
index be3b424..c16fabd 100644
--- a/Tests/UnitTests/Tester.h
+++ b/Tests/UnitTests/Tester.h
@@ -2,7 +2,7 @@
//
// CAN Interface API, Version 3 (Testing)
//
-// Copyright (c) 2004-2021 Uwe Vogt, UV Software, Berlin (info@uv-software.com)
+// Copyright (c) 2004-2022 Uwe Vogt, UV Software, Berlin (info@uv-software.com)
// All rights reserved.
//
// This file is part of CAN API V3.
@@ -48,7 +48,10 @@
#ifndef TESTER_H_INCLUDED
#define TESTER_H_INCLUDED
-#include "Template.h"
+// HowTo: make a copy of header 'Template.h' and name it 'Driver.h'
+// set define 'CDriverCAN' to your MacCAN Driver Under Test
+// and adapt the driver specific test settings there
+#include "Driver.h"
class CTester : CDriverCAN {
public:
@@ -68,4 +71,4 @@ class CTester : CDriverCAN {
#endif // TESTER_H_INCLUDED
-// $Id: Tester.h 1035 2021-12-21 12:03:27Z makemake $ Copyright (c) UV Software, Berlin //
+// $Id: Tester.h 1083 2022-01-07 07:58:25Z makemake $ Copyright (c) UV Software, Berlin //
diff --git a/Tests/UnitTests/test_can_bitrate.mm b/Tests/UnitTests/test_can_bitrate.mm
index c0faeda..9d248b0 100644
--- a/Tests/UnitTests/test_can_bitrate.mm
+++ b/Tests/UnitTests/test_can_bitrate.mm
@@ -78,6 +78,8 @@ - (void)testWithInvalidHandle {
// @- initialize DUT1 with configured settings
handle = can_init(DUT1, TEST_CANMODE, NULL);
XCTAssertLessThanOrEqual(0, handle);
+
+ // @pre:
// @- try to get bit-rate of DUT1 with invalid handle -1
rc = can_bitrate(INVALID_HANDLE, &bitrate, NULL);
XCTAssertEqual(CANERR_HANDLE, rc);
@@ -95,7 +97,7 @@ - (void)testWithInvalidHandle {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -115,6 +117,8 @@ - (void)testWithInvalidHandle {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertTrue(status.can_stopped);
+
+ // @post:
// @- shutdown DUT1
rc = can_exit(handle);
XCTAssertEqual(CANERR_NOERROR, rc);
@@ -153,7 +157,7 @@ - (void)testWithNullPointerForBitrate {
XCTAssertFalse(status.can_stopped);
// @post:
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -207,7 +211,7 @@ - (void)testWithNullPointerForSpeed {
XCTAssertFalse(status.can_stopped);
// @post:
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -261,7 +265,7 @@ - (void)testWithNullPointerForBoth {
XCTAssertFalse(status.can_stopped);
// @post:
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -298,11 +302,11 @@ - (void)testWhenInterfaceNotInitialized {
rc = can_bitrate(INVALID_HANDLE, &bitrate, NULL);
XCTAssertEqual(CANERR_NOTINIT, rc);
// @- try to get bit-rate of DUT1 with invalid handle INT32_MIN
- rc = can_bitrate(INT32_MAX, &bitrate, NULL);
- XCTAssertEqual(CANERR_NOTINIT, rc);
- // @- try to get bit-rate of DUT1 with invalid handle INT32_MIN
rc = can_bitrate(INT32_MIN, &bitrate, NULL);
XCTAssertEqual(CANERR_NOTINIT, rc);
+ // @- try to get bit-rate of DUT1 with invalid handle INT32_MAX
+ rc = can_bitrate(INT32_MAX, &bitrate, NULL);
+ XCTAssertEqual(CANERR_NOTINIT, rc);
// @post:
// @- initialize DUT1 with configured settings
@@ -319,7 +323,7 @@ - (void)testWhenInterfaceNotInitialized {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -373,7 +377,7 @@ - (void)testWhenInterfaceInitialized {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -420,7 +424,7 @@ - (void)testWhenInterfaceStarted {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -478,7 +482,7 @@ - (void)testWhenInterfaceStopped {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -531,7 +535,7 @@ - (void)testWhenInterfaceShutdown {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -568,7 +572,8 @@ - (void)testWithVariousCan20BitrateSettings {
int handle = INVALID_HANDLE;
int rc = CANERR_FATAL;
- // @test: loop over selected bit-rate settings
+ // @test:
+ // @- loop over selected bit-rate settings
for (int i = 0; i < 4; i++) {
switch (i) {
case 0: BITRATE_1M(bitrate); break;
@@ -578,47 +583,54 @@ - (void)testWithVariousCan20BitrateSettings {
default: return;
}
can_bitrate_t result = {};
- // @- initialize DUT1 with configured settings
+ // @-- initialize DUT1 with configured settings
handle = can_init(DUT1, TEST_CANMODE, NULL);
XCTAssertLessThanOrEqual(0, handle);
- // @- get status of DUT1 and check to be in INIT state
+ // @-- get status of DUT1 and check to be in INIT state
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertTrue(status.can_stopped);
- // @- start DUT1 with selected bit-rate settings
+ // @-- start DUT1 with selected bit-rate settings
rc = can_start(handle, &bitrate);
XCTAssertEqual(CANERR_NOERROR, rc);
- // @- get status of DUT1 and check to be in RUNNING state
+ // @-- get status of DUT1 and check to be in RUNNING state
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- get bitrate from DUT1 and compare with selected settings
+ // @-- get bitrate from DUT1 and compare with selected settings
rc = can_bitrate(handle, &result, NULL);
XCTAssertEqual(CANERR_NOERROR, rc);
+#if (KVASER_BUSPARAMS_WORKAROUND == 0)
XCTAssertEqual(bitrate.btr.frequency, result.btr.frequency);
XCTAssertEqual(bitrate.btr.nominal.brp, result.btr.nominal.brp);
+#else
+ if (bitrate.btr.nominal.brp && result.btr.nominal.brp)
+ XCTAssertEqual((bitrate.btr.frequency / bitrate.btr.nominal.brp), (result.btr.frequency / result.btr.nominal.brp));
+ else
+ XCTAssertTrue(false, @"Devide by Zero!");
+#endif
XCTAssertEqual(bitrate.btr.nominal.tseg1, result.btr.nominal.tseg1);
XCTAssertEqual(bitrate.btr.nominal.tseg2, result.btr.nominal.tseg2);
XCTAssertEqual(bitrate.btr.nominal.sjw, result.btr.nominal.sjw);
XCTAssertEqual(bitrate.btr.nominal.sam, result.btr.nominal.sam);
- // @- sunnyday traffic (optional):
+ // @-- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0) && (SEND_WITH_NONE_DEFAULT_BAUDRATE != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
XCTAssertEqual(TEST_FRAMES, tester.ReceiveSomeFrames(handle, DUT2, TEST_FRAMES));
- // @- get status of DUT1 and check to be in RUNNING state
+ // @-- get status of DUT1 and check to be in RUNNING state
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
#endif
- // @- stop/reset DUT1
+ // @-- stop/reset DUT1
rc = can_reset(handle);
XCTAssertEqual(CANERR_NOERROR, rc);
- // @- get status of DUT1 and check to be in INIT state
+ // @-- get status of DUT1 and check to be in INIT state
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertTrue(status.can_stopped);
- // @- shutdown DUT1
+ // @-- shutdown DUT1
rc = can_exit(handle);
XCTAssertEqual(CANERR_NOERROR, rc);
}
@@ -629,9 +641,9 @@ - (void)testWithVariousCan20BitrateSettings {
// @expected: CANERR_NOERROR
//
//- (void)testWithVariousCanFdBitrateSettings {
-// TODO: insert coin here
+// @todo: insert coin here
//}
@end
-// $Id: test_can_bitrate.mm 1075 2022-01-04 22:00:43Z makemake $ Copyright (c) UV Software, Berlin //
+// $Id: test_can_bitrate.mm 1088 2022-01-10 21:14:15Z makemake $ Copyright (c) UV Software, Berlin //
diff --git a/Tests/UnitTests/test_can_busload.mm b/Tests/UnitTests/test_can_busload.mm
index aa052c8..53bc19f 100644
--- a/Tests/UnitTests/test_can_busload.mm
+++ b/Tests/UnitTests/test_can_busload.mm
@@ -75,10 +75,12 @@ - (void)testWithInvalidHandle {
int handle = INVALID_HANDLE;
int rc = CANERR_FATAL;
- // @test:
+ // @pre:
// @- initialize DUT1 with configured settings
handle = can_init(DUT1, TEST_CANMODE, NULL);
XCTAssertLessThanOrEqual(0, handle);
+
+ // @test:
// @- try to get bus-load with invalid handle -1
rc = can_busload(INVALID_HANDLE, &load, &status.byte);
XCTAssertEqual(CANERR_HANDLE, rc);
@@ -96,7 +98,7 @@ - (void)testWithInvalidHandle {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -116,6 +118,8 @@ - (void)testWithInvalidHandle {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertTrue(status.can_stopped);
+
+ // @post:
// @- shutdown DUT1
rc = can_exit(handle);
XCTAssertEqual(CANERR_NOERROR, rc);
@@ -131,10 +135,12 @@ - (void)testWithNullPointerForLoad {
int handle = INVALID_HANDLE;
int rc = CANERR_FATAL;
- // @test:
+ // @pre:
// @- initialize DUT1 with configured settings
handle = can_init(DUT1, TEST_CANMODE, NULL);
XCTAssertLessThanOrEqual(0, handle);
+
+ // @test:
// @- get bus-load of DUT1 with NULL for parameter 'load'
rc = can_busload(handle, NULL, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
@@ -152,7 +158,7 @@ - (void)testWithNullPointerForLoad {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -172,6 +178,8 @@ - (void)testWithNullPointerForLoad {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertTrue(status.can_stopped);
+
+ // @post:
// @- shutdown DUT1
rc = can_exit(handle);
XCTAssertEqual(CANERR_NOERROR, rc);
@@ -188,10 +196,12 @@ - (void)testWithNullPointerForStatus {
int handle = INVALID_HANDLE;
int rc = CANERR_FATAL;
- // @test:
+ // @pre:
// @- initialize DUT1 with configured settings
handle = can_init(DUT1, TEST_CANMODE, NULL);
XCTAssertLessThanOrEqual(0, handle);
+
+ // @test:
// @- get bus-load of DUT1 with NULL for parameter 'status'
rc = can_busload(handle, &load, NULL);
XCTAssertEqual(CANERR_NOERROR, rc);
@@ -209,7 +219,7 @@ - (void)testWithNullPointerForStatus {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -229,6 +239,8 @@ - (void)testWithNullPointerForStatus {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertTrue(status.can_stopped);
+
+ // @post:
// @- shutdown DUT1
rc = can_exit(handle);
XCTAssertEqual(CANERR_NOERROR, rc);
@@ -244,10 +256,12 @@ - (void)testWithNullPointerForBoth {
int handle = INVALID_HANDLE;
int rc = CANERR_FATAL;
- // @test:
+ // @pre:
// @- initialize DUT1 with configured settings
handle = can_init(DUT1, TEST_CANMODE, NULL);
XCTAssertLessThanOrEqual(0, handle);
+
+ // @test:
// @- get bus-load of DUT1 with NULL for both parameter
rc = can_busload(handle, NULL, NULL);
XCTAssertEqual(CANERR_NOERROR, rc);
@@ -265,7 +279,7 @@ - (void)testWithNullPointerForBoth {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -285,6 +299,8 @@ - (void)testWithNullPointerForBoth {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertTrue(status.can_stopped);
+
+ // @post:
// @- shutdown DUT1
rc = can_exit(handle);
XCTAssertEqual(CANERR_NOERROR, rc);
@@ -327,7 +343,7 @@ - (void)testWhenInterfaceNotInitialized {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -389,7 +405,7 @@ - (void)testWhenInterfaceInitialized {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -437,7 +453,7 @@ - (void)testWhenInterfaceStarted {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -492,7 +508,7 @@ - (void)testWhenInterfaceStopped {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -554,7 +570,7 @@ - (void)testWhenInterfaceShutdown {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -625,4 +641,4 @@ - (void)testWhenInterfaceShutdown {
@end
-// $Id: test_can_busload.mm 1075 2022-01-04 22:00:43Z makemake $ Copyright (c) UV Software, Berlin //
+// $Id: test_can_busload.mm 1086 2022-01-09 20:01:00Z haumea $ Copyright (c) UV Software, Berlin //
diff --git a/Tests/UnitTests/test_can_exit.mm b/Tests/UnitTests/test_can_exit.mm
index 3c4a0fe..ee5f44e 100644
--- a/Tests/UnitTests/test_can_exit.mm
+++ b/Tests/UnitTests/test_can_exit.mm
@@ -74,7 +74,7 @@ - (void)testWithInvalidHandle {
int handle = INVALID_HANDLE;
int rc = CANERR_FATAL;
- // @pre
+ // @pre:
// @- initialize DUT1 with configured settings
handle = can_init(DUT1, TEST_CANMODE, NULL);
XCTAssertLessThanOrEqual(0, handle);
@@ -89,7 +89,7 @@ - (void)testWithInvalidHandle {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -109,12 +109,12 @@ - (void)testWithInvalidHandle {
// @test:
// @note: value -1 is used to shutdown all interfaces!
- // @- try to shutdown DUT1 with invalid handle INT32_MAX
- rc = can_exit(INT32_MAX);
- XCTAssertEqual(CANERR_HANDLE, rc);
// @- try to shutdown DUT1 with invalid handle INT32_MIN
rc = can_exit(INT32_MIN);
XCTAssertEqual(CANERR_HANDLE, rc);
+ // @- try to shutdown DUT1 with invalid handle INT32_MAX
+ rc = can_exit(INT32_MAX);
+ XCTAssertEqual(CANERR_HANDLE, rc);
// @- get status of DUT1 and check to be in INIT state
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
@@ -141,12 +141,12 @@ - (void)testWhenInterfaceNotInitialized {
rc = can_exit(INVALID_HANDLE);
XCTAssertEqual(CANERR_NOTINIT, rc);
// @- try to shutdown DUT1 with invalid handle INT32_MIN
- rc = can_exit(INT32_MAX);
- XCTAssertEqual(CANERR_NOTINIT, rc);
- // @- try to shutdown DUT1 with invalid handle INT32_MIN
rc = can_exit(INT32_MIN);
XCTAssertEqual(CANERR_NOTINIT, rc);
- // TODO: loop over list of valid handles
+ // @- try to shutdown DUT1 with invalid handle INT32_MAX
+ rc = can_exit(INT32_MAX);
+ XCTAssertEqual(CANERR_NOTINIT, rc);
+ // @todo: loop over list of valid handles
// @post:
// @- initialize DUT1 with configured settings
@@ -163,7 +163,7 @@ - (void)testWhenInterfaceNotInitialized {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -237,7 +237,7 @@ - (void)testWhenInterfaceStarted {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -281,7 +281,7 @@ - (void)testWhenInterfaceStopped {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -333,7 +333,7 @@ - (void)testWhenInterfaceShutdown {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -411,4 +411,4 @@ - (void)testShutdownAllInterfaces {
@end
-// $Id: test_can_exit.mm 1075 2022-01-04 22:00:43Z makemake $ Copyright (c) UV Software, Berlin //
+// $Id: test_can_exit.mm 1086 2022-01-09 20:01:00Z haumea $ Copyright (c) UV Software, Berlin //
diff --git a/Tests/UnitTests/test_can_firmware.mm b/Tests/UnitTests/test_can_firmware.mm
index ebf1ea4..a8edb7a 100644
--- a/Tests/UnitTests/test_can_firmware.mm
+++ b/Tests/UnitTests/test_can_firmware.mm
@@ -75,10 +75,12 @@ - (void)testWithInvalidHandle {
int handle = INVALID_HANDLE;
int rc = CANERR_FATAL;
- // @test:
+ // @pre:
// @- initialize DUT1 with configured settings
handle = can_init(DUT1, TEST_CANMODE, NULL);
XCTAssertLessThanOrEqual(0, handle);
+
+ // @test:
// @- try to get version of DUT1 with invalid handle -1
string = can_firmware(INVALID_HANDLE);
XCTAssertTrue(NULL == string);
@@ -90,13 +92,13 @@ - (void)testWithInvalidHandle {
rc = can_start(handle, &bitrate);
XCTAssertEqual(CANERR_NOERROR, rc);
// @- try to get version of DUT1 with invalid handle INT32_MIN
- string = can_firmware(INT32_MAX);
+ string = can_firmware(INT32_MIN);
XCTAssertTrue(NULL == string);
// @- get status of DUT1 and check to be in RUNNING state
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -109,13 +111,15 @@ - (void)testWithInvalidHandle {
// @- stop/reset DUT1
rc = can_reset(handle);
XCTAssertEqual(CANERR_NOERROR, rc);
- // @- try to get version of DUT1 with invalid handle INT32_MIN
- string = can_firmware(INT32_MIN);
+ // @- try to get version of DUT1 with invalid handle INT32_MAX
+ string = can_firmware(INT32_MAX);
XCTAssertTrue(NULL == string);
// @- get status of DUT1 and check to be in INIT state
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertTrue(status.can_stopped);
+
+ // @post:
// @- shutdown DUT1
rc = can_exit(handle);
XCTAssertEqual(CANERR_NOERROR, rc);
@@ -137,12 +141,13 @@ - (void)testWhenInterfaceNotInitialized {
string = can_firmware(INVALID_HANDLE);
XCTAssertTrue(NULL == string);
// @- try to get version of DUT1 with invalid handle INT32_MIN
- string = can_firmware(INT32_MAX);
- XCTAssertTrue(NULL == string);
- // @- try to get version of DUT1 with invalid handle INT32_MIN
string = can_firmware(INT32_MIN);
XCTAssertTrue(NULL == string);
+ // @- try to get version of DUT1 with invalid handle INT32_MAX
+ string = can_firmware(INT32_MAX);
+ XCTAssertTrue(NULL == string);
+ // @post:
// @- initialize DUT1 with configured settings
handle = can_init(DUT1, TEST_CANMODE, NULL);
XCTAssertLessThanOrEqual(0, handle);
@@ -157,7 +162,7 @@ - (void)testWhenInterfaceNotInitialized {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -205,7 +210,7 @@ - (void)testWhenInterfaceShutdown {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -264,7 +269,7 @@ - (void)testAnyPlaceAnyTime {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -291,4 +296,4 @@ - (void)testAnyPlaceAnyTime {
@end
-// $Id: test_can_firmware.mm 1073 2022-01-03 18:52:16Z eris $ Copyright (c) UV Software, Berlin //
+// $Id: test_can_firmware.mm 1086 2022-01-09 20:01:00Z haumea $ Copyright (c) UV Software, Berlin //
diff --git a/Tests/UnitTests/test_can_hardware.mm b/Tests/UnitTests/test_can_hardware.mm
index 46ccc46..d1c2258 100644
--- a/Tests/UnitTests/test_can_hardware.mm
+++ b/Tests/UnitTests/test_can_hardware.mm
@@ -75,10 +75,12 @@ - (void)testWithInvalidHandle {
int handle = INVALID_HANDLE;
int rc = CANERR_FATAL;
- // @test:
+ // @pre:
// @- initialize DUT1 with configured settings
handle = can_init(DUT1, TEST_CANMODE, NULL);
XCTAssertLessThanOrEqual(0, handle);
+
+ // @test:
// @- try to get version of DUT1 with invalid handle -1
string = can_hardware(INVALID_HANDLE);
XCTAssertTrue(NULL == string);
@@ -90,13 +92,13 @@ - (void)testWithInvalidHandle {
rc = can_start(handle, &bitrate);
XCTAssertEqual(CANERR_NOERROR, rc);
// @- try to get version of DUT1 with invalid handle INT32_MIN
- string = can_hardware(INT32_MAX);
+ string = can_hardware(INT32_MIN);
XCTAssertTrue(NULL == string);
// @- get status of DUT1 and check to be in RUNNING state
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -109,13 +111,15 @@ - (void)testWithInvalidHandle {
// @- stop/reset DUT1
rc = can_reset(handle);
XCTAssertEqual(CANERR_NOERROR, rc);
- // @- try to get version of DUT1 with invalid handle INT32_MIN
- string = can_hardware(INT32_MIN);
+ // @- try to get version of DUT1 with invalid handle INT32_MAX
+ string = can_hardware(INT32_MAX);
XCTAssertTrue(NULL == string);
// @- get status of DUT1 and check to be in INIT state
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertTrue(status.can_stopped);
+
+ // @post:
// @- shutdown DUT1
rc = can_exit(handle);
XCTAssertEqual(CANERR_NOERROR, rc);
@@ -137,12 +141,13 @@ - (void)testWhenInterfaceNotInitialized {
string = can_hardware(INVALID_HANDLE);
XCTAssertTrue(NULL == string);
// @- try to get version of DUT1 with invalid handle INT32_MIN
- string = can_hardware(INT32_MAX);
- XCTAssertTrue(NULL == string);
- // @- try to get version of DUT1 with invalid handle INT32_MIN
string = can_hardware(INT32_MIN);
XCTAssertTrue(NULL == string);
+ // @- try to get version of DUT1 with invalid handle INT32_MAX
+ string = can_hardware(INT32_MAX);
+ XCTAssertTrue(NULL == string);
+ // @post:
// @- initialize DUT1 with configured settings
handle = can_init(DUT1, TEST_CANMODE, NULL);
XCTAssertLessThanOrEqual(0, handle);
@@ -157,7 +162,7 @@ - (void)testWhenInterfaceNotInitialized {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -205,7 +210,7 @@ - (void)testWhenInterfaceShutdown {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -264,7 +269,7 @@ - (void)testAnyPlaceAnyTime {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -291,4 +296,4 @@ - (void)testAnyPlaceAnyTime {
@end
-// $Id: test_can_hardware.mm 1035 2021-12-21 12:03:27Z makemake $ Copyright (c) UV Software, Berlin //
+// $Id: test_can_hardware.mm 1086 2022-01-09 20:01:00Z haumea $ Copyright (c) UV Software, Berlin //
diff --git a/Tests/UnitTests/test_can_init.mm b/Tests/UnitTests/test_can_init.mm
index 4586bb7..e4ba4a1 100644
--- a/Tests/UnitTests/test_can_init.mm
+++ b/Tests/UnitTests/test_can_init.mm
@@ -2,7 +2,7 @@
//
// CAN Interface API, Version 3 (Testing)
//
-// Copyright (c) 2004-2021 Uwe Vogt, UV Software, Berlin (info@uv-software.com)
+// Copyright (c) 2004-2022 Uwe Vogt, UV Software, Berlin (info@uv-software.com)
// All rights reserved.
//
// This file is part of CAN API V3.
@@ -100,7 +100,7 @@ - (void)testWhenInterfaceInitialized {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -158,7 +158,7 @@ - (void)testWhenInterfaceStarted {
XCTAssertFalse(status.can_stopped);
// @post:
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -205,7 +205,7 @@ - (void)testWhenInterfaceStopped {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -262,7 +262,7 @@ - (void)testWhenInterfaceShutdown {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -445,7 +445,7 @@ - (void)testMonitorModeEnableDisable {
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertEqual(CANMODE_MON, mode.byte);
- // TODO: try to send a frame & receive some frames
+ // @todo: try to send a frame & receive some frames
// @- shutdown DUT1
rc = can_exit(handle);
XCTAssertEqual(CANERR_NOERROR, rc);
@@ -487,7 +487,7 @@ - (void)testErrorFramesEnableDisable {
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertEqual(CANMODE_ERR, mode.byte);
- // TODO: receive some error frames
+ // @todo: receive some error frames
// @- shutdown DUT1
rc = can_exit(handle);
XCTAssertEqual(CANERR_NOERROR, rc);
@@ -529,7 +529,7 @@ - (void)testRemoteFramesDisableEnable {
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertEqual(CANMODE_NRTR, mode.byte);
- // TODO: try to request & receive some remote frames
+ // @todo: try to request & receive some remote frames
// @- shutdown DUT1
rc = can_exit(handle);
XCTAssertEqual(CANERR_NOERROR, rc);
@@ -571,7 +571,7 @@ - (void)testExtendedFramesDisableEnable {
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertEqual(CANMODE_NXTD, mode.byte);
- // TODO: try to send & receive some extended frames
+ // @todo: try to send & receive some extended frames
// @- shutdown DUT1
rc = can_exit(handle);
XCTAssertEqual(CANERR_NOERROR, rc);
@@ -677,4 +677,4 @@ - (void)testBitrateSwitchingEnableDisable {
@end
-// $Id: test_can_init.mm 1067 2021-12-28 21:18:35Z makemake $ Copyright (c) UV Software, Berlin //
+// $Id: test_can_init.mm 1086 2022-01-09 20:01:00Z haumea $ Copyright (c) UV Software, Berlin //
diff --git a/Tests/UnitTests/test_can_read.mm b/Tests/UnitTests/test_can_read.mm
index 076149b..083377f 100644
--- a/Tests/UnitTests/test_can_read.mm
+++ b/Tests/UnitTests/test_can_read.mm
@@ -49,6 +49,13 @@
#import "can_api.h"
#import
+#define TIMESTAMP_DELAY_10MS 10U
+#define TIMESTAMP_DELAY_7MS 7U
+#define TIMESTAMP_DELAY_5MS 5U
+#define TIMESTAMP_DELAY_2MS 2U
+#define TIMESTAMP_DELAY_1MS 1U
+#define TIMESTAMP_DELAY_0MS 0U
+
@interface test_can_read : XCTestCase
@end
@@ -95,7 +102,7 @@ - (void)testWithInvalidHandle {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -108,8 +115,8 @@ - (void)testWithInvalidHandle {
// @- stop/reset DUT1
rc = can_reset(handle);
XCTAssertEqual(CANERR_NOERROR, rc);
- // @- try to read a message from DUT1 with invalid handle INT32_MIN
- rc = can_read(INT32_MIN, &message, 0U);
+ // @- try to read a message from DUT1 with invalid handle INT32_MAX
+ rc = can_read(INT32_MAX, &message, 0U);
XCTAssertEqual(CANERR_HANDLE, rc);
// @- get status of DUT1 and check to be in INIT state
rc = can_status(handle, &status.byte);
@@ -130,6 +137,7 @@ - (void)testWithNullPointerForMessage {
int handle = INVALID_HANDLE;
int rc = CANERR_FATAL;
+ // @pre:
// @- initialize DUT1 with configured settings
handle = can_init(DUT1, TEST_CANMODE, NULL);
XCTAssertLessThanOrEqual(0, handle);
@@ -151,7 +159,7 @@ - (void)testWithNullPointerForMessage {
XCTAssertFalse(status.can_stopped);
// @post:
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -191,8 +199,8 @@ - (void)testWhenInterfaceNotInitialized {
// @- try to read a message from DUT1 with invalid handle INT32_MIN
rc = can_read(INT32_MIN, &message, 0U);
XCTAssertEqual(CANERR_NOTINIT, rc);
- // @- try to read a message from DUT1 with invalid handle INT32_MIN
- rc = can_read(INT32_MIN, &message, 0U);
+ // @- try to read a message from DUT1 with invalid handle INT32_MAX
+ rc = can_read(INT32_MAX, &message, 0U);
XCTAssertEqual(CANERR_NOTINIT, rc);
// @post:
@@ -210,7 +218,7 @@ - (void)testWhenInterfaceNotInitialized {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -265,7 +273,7 @@ - (void)testWhenInterfaceNotStarted {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -313,7 +321,7 @@ - (void)testWhenInterfaceStopped {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -368,7 +376,7 @@ - (void)testWhenInterfaceShutdown {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -428,7 +436,7 @@ - (void)testWhenReceiveQueueIsEmpty {
XCTAssertFalse(status.can_stopped);
// @- check if bit CANSTAT_RX_EMPTY is set in status register
XCTAssertTrue(status.receiver_empty);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -482,7 +490,6 @@ - (void)testWhenReceiveQueueIsFull {
memset(message2.data, 0, CANFD_MAX_LEN);
// @pre:
- mode.nxtd = 0;
// @- initialize DUT1 with configured settings
handle1 = can_init(DUT1, mode.byte, NULL);
XCTAssertLessThanOrEqual(0, handle1);
@@ -591,6 +598,403 @@ - (void)testWhenReceiveQueueIsFull {
// TODO: insert coin here
// FIXME: How to loose a message?
//
+
+// @xctest TC04.10: Measure time-stamp accuracy of the device.
+//
+// @expected: CANERR_NOERROR
+//
+- (void)testTimestampAccuracy {
+ can_bitrate_t bitrate = { TEST_BTRINDEX };
+ can_status_t status = { CANSTAT_RESET };
+ can_message_t message1 = {};
+ can_message_t message2 = {};
+ can_mode_t mode = { TEST_CANMODE };
+ int handle1 = INVALID_HANDLE;
+ int handle2 = INVALID_HANDLE;
+ int rc = CANERR_FATAL;
+ int i, n;
+
+ CTimer timer = CTimer();
+ CTimer delay = CTimer();
+ int64_t usec = 0;
+ int64_t last = 0;
+ int64_t sum = 0;
+ int64_t avg = 0;
+
+ message2.id = 0x000U;
+ message2.fdf = mode.fdoe ? 1 : 0;
+ message2.brs = mode.brse ? 1 : 0;
+ message2.xtd = 0;
+ message2.rtr = 0;
+ message2.esi = 0;
+ message2.sts = 0;
+ message2.dlc = mode.fdoe ? CANFD_MAX_DLC : CAN_MAX_DLC;
+ memset(message2.data, 0, CANFD_MAX_LEN);
+
+ // @pre:
+ // @- initialize DUT1 with configured settings
+ handle1 = can_init(DUT1, mode.byte, NULL);
+ XCTAssertLessThanOrEqual(0, handle1);
+ // @- get status of DUT1 and check to be in INIT state
+ rc = can_status(handle1, &status.byte);
+ XCTAssertEqual(CANERR_NOERROR, rc);
+ XCTAssertTrue(status.can_stopped);
+ // @- initialize DUT2 with configured settings
+ handle2 = can_init(DUT2, mode.byte, NULL);
+ XCTAssertLessThanOrEqual(0, handle1);
+ // @- get status of DUT2 and check to be in INIT state
+ rc = can_status(handle2, &status.byte);
+ XCTAssertEqual(CANERR_NOERROR, rc);
+ XCTAssertTrue(status.can_stopped);
+ // @- start DUT1 with configured bit-rate settings
+ rc = can_start(handle1, &bitrate);
+ XCTAssertEqual(CANERR_NOERROR, rc);
+ // @- get status of DUT1 and check to be in RUNNING state
+ rc = can_status(handle1, &status.byte);
+ XCTAssertEqual(CANERR_NOERROR, rc);
+ XCTAssertFalse(status.can_stopped);
+ // @- start DUT2 with configured bit-rate settings
+ rc = can_start(handle2, &bitrate);
+ XCTAssertEqual(CANERR_NOERROR, rc);
+ // @- get status of DUT2 and check to be in RUNNING state
+ rc = can_status(handle2, &status.byte);
+ XCTAssertEqual(CANERR_NOERROR, rc);
+ XCTAssertFalse(status.can_stopped);
+
+#if (TEST_TIMESTAMP_10MS != 0)
+ // @test:
+ NSLog(@"Be patient...");
+ timer.Restart((uint32_t)TEST_TIMESTAMP * 100U * CTimer::MSEC);
+ // @- send n CAN messages with 10ms delay from DUT2 to DUT1
+ message2.id = 0x010U;
+ for (i = n = 0; i < TEST_TIMESTAMP; i++) {
+ message2.data[0] = (uint8_t)((uint64_t)i >> 0);
+ message2.data[1] = (uint8_t)((uint64_t)i >> 8);
+ message2.data[2] = (uint8_t)((uint64_t)i >> 16);
+ message2.data[3] = (uint8_t)((uint64_t)i >> 24);
+ message2.data[4] = (uint8_t)((uint64_t)i >> 32);
+ message2.data[5] = (uint8_t)((uint64_t)i >> 40);
+ message2.data[6] = (uint8_t)((uint64_t)i >> 48);
+ message2.data[7] = (uint8_t)((uint64_t)i >> 56);
+ // @-- start a timer and send the message
+ delay.Restart(TIMESTAMP_DELAY_10MS * CTimer::MSEC);
+ do {
+ rc = can_write(handle2, &message2, 0U);
+ } while (CANERR_TX_BUSY == rc);
+ XCTAssertEqual(CANERR_NOERROR, rc);
+ if (CANERR_NOERROR != rc)
+ break;
+ while (!delay.Timeout());
+ }
+ NSLog(@"%d frame(s) sent with %u.000ms delay", i, TIMESTAMP_DELAY_10MS);
+ sum = last = 0;
+ // @- read all CAN messages from DUT1 receive queue
+ while ((n < i) && !timer.Timeout()) {
+ memset(&message1, 0, sizeof(can_message_t));
+ // @-- read one message and sum up the time differences
+ rc = can_read(handle1, &message1, 1000U);
+ XCTAssertEqual(CANERR_NOERROR, rc);
+ if (!message1.sts) {
+ usec = ((int64_t)message1.timestamp.tv_sec * (int64_t)1000000)
+ + ((int64_t)message1.timestamp.tv_nsec / (int64_t)1000);
+ if (last)
+ sum += (usec - last);
+ last = usec;
+ n++;
+ }
+ }
+ XCTAssertEqual(i, n);
+ // @- calculate the time average and check for tolerance
+ avg = (0 < n) ? (sum / (int64_t)(n-1)) : 0;
+ XCTAssert((TIMESTAMP_LOWER_10MS <= avg) && (avg <= TIMESTAMP_UPPER_10MS));
+ NSLog(@"%d frame(s) read with %.3fms average", n, (float)avg / 1000.0);
+ // @- get status of DUT1 and check to be in RUNNING state
+ rc = can_status(handle1, &status.byte);
+ XCTAssertEqual(CANERR_NOERROR, rc);
+ XCTAssertFalse(status.can_stopped);
+#endif
+
+#if (TEST_TIMESTAMP_7MS != 0)
+ // @test:
+ NSLog(@"Be patient...");
+ timer.Restart((uint32_t)TEST_TIMESTAMP * 100U * CTimer::MSEC);
+ // @- send n CAN messages with 7ms delay from DUT2 to DUT1
+ message2.id = 0x010U;
+ for (i = n = 0; i < TEST_TIMESTAMP; i++) {
+ message2.data[0] = (uint8_t)((uint64_t)i >> 0);
+ message2.data[1] = (uint8_t)((uint64_t)i >> 8);
+ message2.data[2] = (uint8_t)((uint64_t)i >> 16);
+ message2.data[3] = (uint8_t)((uint64_t)i >> 24);
+ message2.data[4] = (uint8_t)((uint64_t)i >> 32);
+ message2.data[5] = (uint8_t)((uint64_t)i >> 40);
+ message2.data[6] = (uint8_t)((uint64_t)i >> 48);
+ message2.data[7] = (uint8_t)((uint64_t)i >> 56);
+ // @-- start a timer and send the message
+ delay.Restart(TIMESTAMP_DELAY_7MS * CTimer::MSEC);
+ do {
+ rc = can_write(handle2, &message2, 0U);
+ } while (CANERR_TX_BUSY == rc);
+ XCTAssertEqual(CANERR_NOERROR, rc);
+ if (CANERR_NOERROR != rc)
+ break;
+ while (!delay.Timeout());
+ }
+ NSLog(@"%d frame(s) sent with %u.000ms delay", i, TIMESTAMP_DELAY_7MS);
+ sum = last = 0;
+ // @- read all CAN messages from DUT1 receive queue
+ while ((n < i) && !timer.Timeout()) {
+ memset(&message1, 0, sizeof(can_message_t));
+ // @-- read one message and sum up the time differences
+ rc = can_read(handle1, &message1, 1000U);
+ XCTAssertEqual(CANERR_NOERROR, rc);
+ if (!message1.sts) {
+ usec = ((int64_t)message1.timestamp.tv_sec * (int64_t)1000000)
+ + ((int64_t)message1.timestamp.tv_nsec / (int64_t)1000);
+ if (last)
+ sum += (usec - last);
+ last = usec;
+ n++;
+ }
+ }
+ XCTAssertEqual(i, n);
+ // @- calculate the time average and check for tolerance
+ avg = (0 < n) ? (sum / (int64_t)(n-1)) : 0;
+ XCTAssert((TIMESTAMP_LOWER_7MS <= avg) && (avg <= TIMESTAMP_UPPER_7MS));
+ NSLog(@"%d frame(s) read with %.3fms average", n, (float)avg / 1000.0);
+ // @- get status of DUT1 and check to be in RUNNING state
+ rc = can_status(handle1, &status.byte);
+ XCTAssertEqual(CANERR_NOERROR, rc);
+ XCTAssertFalse(status.can_stopped);
+#endif
+
+#if (TEST_TIMESTAMP_5MS != 0)
+ // @test:
+ NSLog(@"Be patient...");
+ timer.Restart((uint32_t)TEST_TIMESTAMP * 100U * CTimer::MSEC);
+ // @- send n CAN messages with 5ms delay from DUT2 to DUT1
+ message2.id = 0x010U;
+ for (i = n = 0; i < TEST_TIMESTAMP; i++) {
+ message2.data[0] = (uint8_t)((uint64_t)i >> 0);
+ message2.data[1] = (uint8_t)((uint64_t)i >> 8);
+ message2.data[2] = (uint8_t)((uint64_t)i >> 16);
+ message2.data[3] = (uint8_t)((uint64_t)i >> 24);
+ message2.data[4] = (uint8_t)((uint64_t)i >> 32);
+ message2.data[5] = (uint8_t)((uint64_t)i >> 40);
+ message2.data[6] = (uint8_t)((uint64_t)i >> 48);
+ message2.data[7] = (uint8_t)((uint64_t)i >> 56);
+ // @-- start a timer and send the message
+ delay.Restart(TIMESTAMP_DELAY_5MS * CTimer::MSEC);
+ do {
+ rc = can_write(handle2, &message2, 0U);
+ } while (CANERR_TX_BUSY == rc);
+ XCTAssertEqual(CANERR_NOERROR, rc);
+ if (CANERR_NOERROR != rc)
+ break;
+ while (!delay.Timeout());
+ }
+ NSLog(@"%d frame(s) sent with %u.000ms delay", i, TIMESTAMP_DELAY_5MS);
+ sum = last = 0;
+ // @- read all CAN messages from DUT1 receive queue
+ while ((n < i) && !timer.Timeout()) {
+ memset(&message1, 0, sizeof(can_message_t));
+ // @-- read one message and sum up the time differences
+ rc = can_read(handle1, &message1, 1000U);
+ XCTAssertEqual(CANERR_NOERROR, rc);
+ if (!message1.sts) {
+ usec = ((int64_t)message1.timestamp.tv_sec * (int64_t)1000000)
+ + ((int64_t)message1.timestamp.tv_nsec / (int64_t)1000);
+ if (last)
+ sum += (usec - last);
+ last = usec;
+ n++;
+ }
+ }
+ XCTAssertEqual(i, n);
+ // @- calculate the time average and check for tolerance
+ avg = (0 < n) ? (sum / (int64_t)(n-1)) : 0;
+ XCTAssert((TIMESTAMP_LOWER_5MS <= avg) && (avg <= TIMESTAMP_UPPER_5MS));
+ NSLog(@"%d frame(s) read with %.3fms average", n, (float)avg / 1000.0);
+ // @- get status of DUT1 and check to be in RUNNING state
+ rc = can_status(handle1, &status.byte);
+ XCTAssertEqual(CANERR_NOERROR, rc);
+ XCTAssertFalse(status.can_stopped);
+#endif
+
+#if (TEST_TIMESTAMP_2MS != 0)
+ // @test:
+ NSLog(@"Be patient...");
+ timer.Restart((uint32_t)TEST_TIMESTAMP * 100U * CTimer::MSEC);
+ // @- send n CAN messages with 2ms delay from DUT2 to DUT1
+ message2.id = 0x010U;
+ for (i = n = 0; i < TEST_TIMESTAMP; i++) {
+ message2.data[0] = (uint8_t)((uint64_t)i >> 0);
+ message2.data[1] = (uint8_t)((uint64_t)i >> 8);
+ message2.data[2] = (uint8_t)((uint64_t)i >> 16);
+ message2.data[3] = (uint8_t)((uint64_t)i >> 24);
+ message2.data[4] = (uint8_t)((uint64_t)i >> 32);
+ message2.data[5] = (uint8_t)((uint64_t)i >> 40);
+ message2.data[6] = (uint8_t)((uint64_t)i >> 48);
+ message2.data[7] = (uint8_t)((uint64_t)i >> 56);
+ // @-- start a timer and send the message
+ delay.Restart(TIMESTAMP_DELAY_2MS * CTimer::MSEC);
+ do {
+ rc = can_write(handle2, &message2, 0U);
+ } while (CANERR_TX_BUSY == rc);
+ XCTAssertEqual(CANERR_NOERROR, rc);
+ if (CANERR_NOERROR != rc)
+ break;
+ while (!delay.Timeout());
+ }
+ NSLog(@"%d frame(s) sent with %u.000ms delay", i, TIMESTAMP_DELAY_2MS);
+ sum = last = 0;
+ // @- read all CAN messages from DUT1 receive queue
+ while ((n < i) && !timer.Timeout()) {
+ memset(&message1, 0, sizeof(can_message_t));
+ // @-- read one message and sum up the time differences
+ rc = can_read(handle1, &message1, 1000U);
+ XCTAssertEqual(CANERR_NOERROR, rc);
+ if (!message1.sts) {
+ usec = ((int64_t)message1.timestamp.tv_sec * (int64_t)1000000)
+ + ((int64_t)message1.timestamp.tv_nsec / (int64_t)1000);
+ if (last)
+ sum += (usec - last);
+ last = usec;
+ n++;
+ }
+ }
+ XCTAssertEqual(i, n);
+ // @- calculate the time average and check for tolerance
+ avg = (0 < n) ? (sum / (int64_t)(n-1)) : 0;
+ XCTAssert((TIMESTAMP_LOWER_2MS <= avg) && (avg <= TIMESTAMP_UPPER_2MS));
+ NSLog(@"%d frame(s) read with %.3fms average", n, (float)avg / 1000.0);
+ // @- get status of DUT1 and check to be in RUNNING state
+ rc = can_status(handle1, &status.byte);
+ XCTAssertEqual(CANERR_NOERROR, rc);
+ XCTAssertFalse(status.can_stopped);
+#endif
+
+#if (TEST_TIMESTAMP_1MS != 0)
+ // @test:
+ NSLog(@"Be patient...");
+ timer.Restart((uint32_t)TEST_TIMESTAMP * 100U * CTimer::MSEC);
+ // @- send n CAN messages with 1ms delay from DUT2 to DUT1
+ message2.id = 0x010U;
+ for (i = n = 0; i < TEST_TIMESTAMP; i++) {
+ message2.data[0] = (uint8_t)((uint64_t)i >> 0);
+ message2.data[1] = (uint8_t)((uint64_t)i >> 8);
+ message2.data[2] = (uint8_t)((uint64_t)i >> 16);
+ message2.data[3] = (uint8_t)((uint64_t)i >> 24);
+ message2.data[4] = (uint8_t)((uint64_t)i >> 32);
+ message2.data[5] = (uint8_t)((uint64_t)i >> 40);
+ message2.data[6] = (uint8_t)((uint64_t)i >> 48);
+ message2.data[7] = (uint8_t)((uint64_t)i >> 56);
+ // @-- start a timer and send the message
+ delay.Restart(TIMESTAMP_DELAY_1MS * CTimer::MSEC);
+ do {
+ rc = can_write(handle2, &message2, 0U);
+ } while (CANERR_TX_BUSY == rc);
+ XCTAssertEqual(CANERR_NOERROR, rc);
+ if (CANERR_NOERROR != rc)
+ break;
+ while (!delay.Timeout());
+ }
+ NSLog(@"%d frame(s) sent with %u.000ms delay", i, TIMESTAMP_DELAY_1MS);
+ sum = last = 0;
+ // @- read all CAN messages from DUT1 receive queue
+ while ((n < i) && !timer.Timeout()) {
+ memset(&message1, 0, sizeof(can_message_t));
+ // @-- read one message and sum up the time differences
+ rc = can_read(handle1, &message1, 1000U);
+ XCTAssertEqual(CANERR_NOERROR, rc);
+ if (!message1.sts) {
+ usec = ((int64_t)message1.timestamp.tv_sec * (int64_t)1000000)
+ + ((int64_t)message1.timestamp.tv_nsec / (int64_t)1000);
+ if (last)
+ sum += (usec - last);
+ last = usec;
+ n++;
+ }
+ }
+ XCTAssertEqual(i, n);
+ // @- calculate the time average and check for tolerance
+ avg = (0 < n) ? (sum / (int64_t)(n-1)) : 0;
+ XCTAssert((TIMESTAMP_LOWER_1MS <= avg) && (avg <= TIMESTAMP_UPPER_1MS));
+ NSLog(@"%d frame(s) read with %.3fms average", n, (float)avg / 1000.0);
+ // @- get status of DUT1 and check to be in RUNNING state
+ rc = can_status(handle1, &status.byte);
+ XCTAssertEqual(CANERR_NOERROR, rc);
+ XCTAssertFalse(status.can_stopped);
+#endif
+
+ // @test:
+ NSLog(@"Be patient...");
+ timer.Restart((uint32_t)TEST_TIMESTAMP * 100U * CTimer::MSEC);
+ // @- send n CAN messages without delay from DUT2 to DUT1
+ message2.id = 0x010U;
+ for (i = n = 0; i < TEST_TIMESTAMP; i++) {
+ message2.data[0] = (uint8_t)((uint64_t)i >> 0);
+ message2.data[1] = (uint8_t)((uint64_t)i >> 8);
+ message2.data[2] = (uint8_t)((uint64_t)i >> 16);
+ message2.data[3] = (uint8_t)((uint64_t)i >> 24);
+ message2.data[4] = (uint8_t)((uint64_t)i >> 32);
+ message2.data[5] = (uint8_t)((uint64_t)i >> 40);
+ message2.data[6] = (uint8_t)((uint64_t)i >> 48);
+ message2.data[7] = (uint8_t)((uint64_t)i >> 56);
+ // @-- start a timer and send the message
+ delay.Restart(TIMESTAMP_DELAY_0MS * CTimer::MSEC);
+ do {
+ rc = can_write(handle2, &message2, 0U);
+ } while (CANERR_TX_BUSY == rc);
+ XCTAssertEqual(CANERR_NOERROR, rc);
+ if (CANERR_NOERROR != rc)
+ break;
+ //while (!delay.Timeout());
+ }
+ NSLog(@"%d frame(s) sent without delay", i);
+ sum = last = 0;
+ // @- read all CAN messages from DUT1 receive queue
+ while ((n < i) && !timer.Timeout()) {
+ memset(&message1, 0, sizeof(can_message_t));
+ // @-- read one message and sum up the time differences
+ rc = can_read(handle1, &message1, 1000U);
+ XCTAssertEqual(CANERR_NOERROR, rc);
+ if (!message1.sts) {
+ usec = ((int64_t)message1.timestamp.tv_sec * (int64_t)1000000)
+ + ((int64_t)message1.timestamp.tv_nsec / (int64_t)1000);
+ if (last)
+ sum += (usec - last);
+#if (0)
+ NSLog(@"%d %li.%09li %lli %lli %lli %lli",n,message1.timestamp.tv_sec,message1.timestamp.tv_nsec,usec,last,usec-last,sum);
+#endif
+ last = usec;
+ n++;
+ }
+ }
+ XCTAssertEqual(i, n);
+ // @- calculate the time average and check for tolerance
+ avg = (0 < n) ? (sum / (int64_t)(n-1)) : 0;
+ XCTAssert((0 <= avg) && (avg <= TIMESTAMP_UPPER_0MS));
+ NSLog(@"%d frame(s) read with %.3fms average", n, (float)avg / 1000.0);
+ // @- get status of DUT1 and check to be in RUNNING state
+ rc = can_status(handle1, &status.byte);
+ XCTAssertEqual(CANERR_NOERROR, rc);
+ XCTAssertFalse(status.can_stopped);
+ // @post:
+ // @- stop/reset DUT1
+ rc = can_reset(handle1);
+ XCTAssertEqual(CANERR_NOERROR, rc);
+ // @- get status of DUT1 and check to be in INIT state
+ rc = can_status(handle1, &status.byte);
+ XCTAssertEqual(CANERR_NOERROR, rc);
+ XCTAssertTrue(status.can_stopped);
+ // @- shutdown DUT1
+ rc = can_exit(handle1);
+ XCTAssertEqual(CANERR_NOERROR, rc);
+ // @- shutdown DUT2
+ rc = can_exit(handle2);
+ XCTAssertEqual(CANERR_NOERROR, rc);
+
+}
@end
-// $Id: test_can_read.mm 1075 2022-01-04 22:00:43Z makemake $ Copyright (c) UV Software, Berlin //
+// $Id: test_can_read.mm 1086 2022-01-09 20:01:00Z haumea $ Copyright (c) UV Software, Berlin //
diff --git a/Tests/UnitTests/test_can_reset.mm b/Tests/UnitTests/test_can_reset.mm
index 2facb43..06664df 100644
--- a/Tests/UnitTests/test_can_reset.mm
+++ b/Tests/UnitTests/test_can_reset.mm
@@ -89,7 +89,7 @@ - (void)testWithInvalidHandle {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -104,18 +104,18 @@ - (void)testWithInvalidHandle {
rc = can_reset(INVALID_HANDLE);
XCTAssertEqual(CANERR_HANDLE, rc);
// @- try to stop DUT1 with invalid handle INT32_MIN
- rc = can_reset(INT32_MAX);
- XCTAssertEqual(CANERR_HANDLE, rc);
- // @- try to stop DUT1 with invalid handle INT32_MIN
rc = can_reset(INT32_MIN);
XCTAssertEqual(CANERR_HANDLE, rc);
+ // @- try to stop DUT1 with invalid handle INT32_MAX
+ rc = can_reset(INT32_MAX);
+ XCTAssertEqual(CANERR_HANDLE, rc);
// @- get status of DUT1 and check to be in RUNNING state
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
// @post:
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
XCTAssertEqual(TEST_FRAMES, tester.ReceiveSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -151,11 +151,11 @@ - (void)testWhenInterfaceNotInitialized {
rc = can_reset(INVALID_HANDLE);
XCTAssertEqual(CANERR_NOTINIT, rc);
// @- try to stop DUT1 with invalid handle INT32_MIN
- rc = can_reset(INT32_MAX);
- XCTAssertEqual(CANERR_NOTINIT, rc);
- // @- try to stop DUT1 with invalid handle INT32_MIN
rc = can_reset(INT32_MIN);
XCTAssertEqual(CANERR_NOTINIT, rc);
+ // @- try to stop DUT1 with invalid handle INT32_MAX
+ rc = can_reset(INT32_MAX);
+ XCTAssertEqual(CANERR_NOTINIT, rc);
// @post:
// @- initialize DUT1 with configured settings
@@ -172,7 +172,7 @@ - (void)testWhenInterfaceNotInitialized {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -236,7 +236,7 @@ - (void)testWhenInterfaceInitialized {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -283,7 +283,7 @@ - (void)testWhenInterfaceStopped {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -347,7 +347,7 @@ - (void)testWhenInterfaceShutdown {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -376,4 +376,4 @@ - (void)testWhenInterfaceShutdown {
@end
-// $Id: test_can_reset.mm 1075 2022-01-04 22:00:43Z makemake $ Copyright (c) UV Software, Berlin //
+// $Id: test_can_reset.mm 1086 2022-01-09 20:01:00Z haumea $ Copyright (c) UV Software, Berlin //
diff --git a/Tests/UnitTests/test_can_start.mm b/Tests/UnitTests/test_can_start.mm
index b2b76fd..426f369 100644
--- a/Tests/UnitTests/test_can_start.mm
+++ b/Tests/UnitTests/test_can_start.mm
@@ -88,11 +88,11 @@ - (void)testWithInvalidHandle {
rc = can_start(INVALID_HANDLE, &bitrate);
XCTAssertEqual(CANERR_HANDLE, rc);
// @- try to start DUT1 with invalid handle INT32_MIN
- rc = can_start(INT32_MAX, &bitrate);
- XCTAssertEqual(CANERR_HANDLE, rc);
- // @- try to start DUT1 with invalid handle INT32_MIN
rc = can_start(INT32_MIN, &bitrate);
XCTAssertEqual(CANERR_HANDLE, rc);
+ // @- try to start DUT1 with invalid handle INT32_MAX
+ rc = can_start(INT32_MAX, &bitrate);
+ XCTAssertEqual(CANERR_HANDLE, rc);
// @- get status of DUT1 and check to be in INIT state
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
@@ -106,7 +106,7 @@ - (void)testWithInvalidHandle {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -164,7 +164,7 @@ - (void)testWithNullPointerForBitrate {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -216,7 +216,7 @@ - (void)testWhenInterfaceNotInitialized {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -274,7 +274,7 @@ - (void)testWhenInterfaceStarted {
XCTAssertFalse(status.can_stopped);
// @post:
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -321,7 +321,7 @@ - (void)testWhenInterfaceStopped {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -349,7 +349,7 @@ - (void)testWhenInterfaceStopped {
XCTAssertFalse(status.can_stopped);
// @post:
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
XCTAssertEqual(TEST_FRAMES, tester.ReceiveSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -395,7 +395,7 @@ - (void)testWhenInterfaceShutdown {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -443,7 +443,7 @@ - (void)testCheckCiaIndex0 {
// @test:
// @note: pre-defined BTR0BTR1 bit-timing table has 10 entries, index 0 to 9.
- // But the index must be given as negative value to 'bitbate.index'!
+ // But the index must be given as negative value to 'library.index'!
XCTAssertEqual(0, bitrate.index);
// @- start DUT1 with CiA table index 0 (1000kbps)
rc = can_start(handle, &bitrate);
@@ -454,7 +454,7 @@ - (void)testCheckCiaIndex0 {
XCTAssertFalse(status.can_stopped);
// @post:
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0) && (SEND_WITH_NONE_DEFAULT_BAUDRATE != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -500,7 +500,7 @@ - (void)testCheckCiaIndex1 {
// @test:
// @note: pre-defined BTR0BTR1 bit-timing table has 10 entries, index 0 to 9.
- // But the index must be given as negative value to 'bitbate.index'!
+ // But the index must be given as negative value to 'library.index'!
XCTAssertEqual(-1, bitrate.index);
// @- start DUT1 with CiA table index 1 (800kbps)
rc = can_start(handle, &bitrate);
@@ -511,7 +511,7 @@ - (void)testCheckCiaIndex1 {
XCTAssertFalse(status.can_stopped);
// @post:
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0) && (SEND_WITH_NONE_DEFAULT_BAUDRATE != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -555,7 +555,7 @@ - (void)testCheckCiaIndex2 {
// @test:
// @note: pre-defined BTR0BTR1 bit-timing table has 10 entries, index 0 to 9.
- // But the index must be given as negative value to 'bitbate.index'!
+ // But the index must be given as negative value to 'library.index'!
XCTAssertEqual(-2, bitrate.index);
// @- start DUT1 with CiA table index 1 (500kbps)
rc = can_start(handle, &bitrate);
@@ -566,7 +566,7 @@ - (void)testCheckCiaIndex2 {
XCTAssertFalse(status.can_stopped);
// @post:
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0) && (SEND_WITH_NONE_DEFAULT_BAUDRATE != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -609,7 +609,7 @@ - (void)testCheckCiaIndex3 {
// @test:
// @note: pre-defined BTR0BTR1 bit-timing table has 10 entries, index 0 to 9.
- // But the index must be given as negative value to 'bitbate.index'!
+ // But the index must be given as negative value to 'library.index'!
XCTAssertEqual(-3, bitrate.index);
// @- start DUT1 with CiA table index 3 (250kbps)
rc = can_start(handle, &bitrate);
@@ -620,7 +620,7 @@ - (void)testCheckCiaIndex3 {
XCTAssertFalse(status.can_stopped);
// @post:
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0) && (SEND_WITH_NONE_DEFAULT_BAUDRATE != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -663,7 +663,7 @@ - (void)testCheckCiaIndex4 {
// @test:
// @note: pre-defined BTR0BTR1 bit-timing table has 10 entries, index 0 to 9.
- // But the index must be given as negative value to 'bitbate.index'!
+ // But the index must be given as negative value to 'library.index'!
XCTAssertEqual(-4, bitrate.index);
// @- start DUT1 with CiA table index 4 (125kbps)
rc = can_start(handle, &bitrate);
@@ -674,7 +674,7 @@ - (void)testCheckCiaIndex4 {
XCTAssertFalse(status.can_stopped);
// @post:
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0) && (SEND_WITH_NONE_DEFAULT_BAUDRATE != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -717,7 +717,7 @@ - (void)testCheckCiaIndex5 {
// @test:
// @note: pre-defined BTR0BTR1 bit-timing table has 10 entries, index 0 to 9.
- // But the index must be given as negative value to 'bitbate.index'!
+ // But the index must be given as negative value to 'library.index'!
XCTAssertEqual(-5, bitrate.index);
// @- start DUT1 with CiA table index 5 (100kbps)
rc = can_start(handle, &bitrate);
@@ -728,7 +728,7 @@ - (void)testCheckCiaIndex5 {
XCTAssertFalse(status.can_stopped);
// @post:
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0) && (SEND_WITH_NONE_DEFAULT_BAUDRATE != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -771,7 +771,7 @@ - (void)testCheckCiaIndex6 {
// @test:
// @note: pre-defined BTR0BTR1 bit-timing table has 10 entries, index 0 to 9.
- // But the index must be given as negative value to 'bitbate.index'!
+ // But the index must be given as negative value to 'library.index'!
XCTAssertEqual(-6, bitrate.index);
// @- start DUT1 with CiA table index 6 (50kbps)
rc = can_start(handle, &bitrate);
@@ -782,7 +782,7 @@ - (void)testCheckCiaIndex6 {
XCTAssertFalse(status.can_stopped);
// @post:
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0) && (SEND_WITH_NONE_DEFAULT_BAUDRATE != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -825,7 +825,7 @@ - (void)testCheckCiaIndex7 {
// @test:
// @note: pre-defined BTR0BTR1 bit-timing table has 10 entries, index 0 to 9.
- // But the index must be given as negative value to 'bitbate.index'!
+ // But the index must be given as negative value to 'library.index'!
XCTAssertEqual(-7, bitrate.index);
// @- start DUT1 with CiA table index 7 (20kbps)
rc = can_start(handle, &bitrate);
@@ -836,7 +836,7 @@ - (void)testCheckCiaIndex7 {
XCTAssertFalse(status.can_stopped);
// @post:
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0) && (SEND_WITH_NONE_DEFAULT_BAUDRATE != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -879,7 +879,7 @@ - (void)testCheckCiaIndex8 {
// @test:
// @note: pre-defined BTR0BTR1 bit-timing table has 10 entries, index 0 to 9.
- // But the index must be given as negative value to 'bitbate.index'!
+ // But the index must be given as negative value to 'library.index'!
XCTAssertEqual(-8, bitrate.index);
// @- start DUT1 with CiA table index 8 (10kbps)
rc = can_start(handle, &bitrate);
@@ -890,7 +890,7 @@ - (void)testCheckCiaIndex8 {
XCTAssertFalse(status.can_stopped);
// @post:
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0) && (SEND_WITH_NONE_DEFAULT_BAUDRATE != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -933,7 +933,7 @@ - (void)testCheckInvalidCiaIndex {
// @test:
// @note: pre-defined BTR0BTR1 bit-timing table has 10 entries, index 0 to 9.
- // But the index must be given as negative value to 'bitbate.index'!
+ // But the index must be given as negative value to 'library.index'!
// Remark: The CiA bit-timing table has only 9 entries!
#if (BITRATE_5K_UNSUPPORTED != 0)
bitrate.index = -9;
@@ -943,6 +943,22 @@ - (void)testCheckInvalidCiaIndex {
// @- try to start DUT1 with invalid index value -10
rc = can_start(handle, &bitrate);
XCTAssertEqual(CANERR_BAUDRATE, rc);
+ // @- try to start DUT1 with invalid index value INT8_MIN
+ bitrate.index = INT8_MIN;
+ rc = can_start(handle, &bitrate);
+ XCTAssertEqual(CANERR_BAUDRATE, rc);
+ // @- try to start DUT1 with invalid index value INT16_MIN
+ bitrate.index = INT16_MIN;
+ rc = can_start(handle, &bitrate);
+ XCTAssertEqual(CANERR_BAUDRATE, rc);
+ // @- try to start DUT1 with invalid index value INT32_MIN+1
+ bitrate.index = INT32_MIN+1;
+ rc = can_start(handle, &bitrate);
+ XCTAssertEqual(CANERR_BAUDRATE, rc);
+ // @- try to start DUT1 with invalid index value INT32_MIN
+ bitrate.index = INT32_MIN;
+ rc = can_start(handle, &bitrate);
+ XCTAssertEqual(CANERR_BAUDRATE, rc);
// @note: Positive values represent the CAN clock in Hertz, but there will
// be probably no clock below 10 Hertz (or above 999'999'999 Hertz).
@@ -994,33 +1010,20 @@ - (void)testCheckInvalidCiaIndex {
rc = can_start(handle, &bitrate);
XCTAssertEqual(CANERR_BAUDRATE, rc);
+ // @todo: - try to start DUT1 with invalid index value 9
+ // @todo: - try to start DUT1 with invalid index value 10
+ // @todo: - try to start DUT1 with invalid index value 1000000000
// @- try to start DUT1 with invalid index value INT32_MAX
bitrate.index = INT32_MAX;
rc = can_start(handle, &bitrate);
XCTAssertEqual(CANERR_BAUDRATE, rc);
- // @- try to start DUT1 with invalid index value INT8_MIN
- bitrate.index = INT8_MIN;
- rc = can_start(handle, &bitrate);
- XCTAssertEqual(CANERR_BAUDRATE, rc);
- // @- try to start DUT1 with invalid index value INT16_MIN
- bitrate.index = INT16_MIN;
- rc = can_start(handle, &bitrate);
- XCTAssertEqual(CANERR_BAUDRATE, rc);
- // @- try to start DUT1 with invalid index value INT32_MIN+1
- bitrate.index = INT32_MIN+1;
- rc = can_start(handle, &bitrate);
- XCTAssertEqual(CANERR_BAUDRATE, rc);
- // @- try to start DUT1 with invalid index value INT32_MIN
- bitrate.index = INT32_MIN;
- rc = can_start(handle, &bitrate);
- XCTAssertEqual(CANERR_BAUDRATE, rc);
// @post: shutdown DUT1
rc = can_exit(handle);
XCTAssertEqual(CANERR_NOERROR, rc);
}
-// @xctest TC03.17: Re-Start CAN controller with the same CiA bit-tining index after it was stopped.
+// @xctest TC03.17: Re-Start CAN controller with the same CiA bit-timing index after it was stopped.
//
// @expected: CANERR_NOERROR
//
@@ -1052,7 +1055,7 @@ - (void)testWithSameCiaIndexAfterCanStopped {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0) && (SEND_WITH_NONE_DEFAULT_BAUDRATE != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -1077,7 +1080,7 @@ - (void)testWithSameCiaIndexAfterCanStopped {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0) && (SEND_WITH_NONE_DEFAULT_BAUDRATE != 0)
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
XCTAssertEqual(TEST_FRAMES, tester.ReceiveSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -1099,7 +1102,7 @@ - (void)testWithSameCiaIndexAfterCanStopped {
}
}
-// @xctest TC03.18: Re-Start CAN controller with a different CiA bit-tining index after it was stopped.
+// @xctest TC03.18: Re-Start CAN controller with a different CiA bit-timing index after it was stopped.
//
// @expected: CANERR_NOERROR
//
@@ -1131,7 +1134,7 @@ - (void)testWithDifferentCiaIndexAfterCanStopped {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0) && (SEND_WITH_NONE_DEFAULT_BAUDRATE != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -1163,7 +1166,7 @@ - (void)testWithDifferentCiaIndexAfterCanStopped {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0) && (SEND_WITH_NONE_DEFAULT_BAUDRATE != 0)
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
XCTAssertEqual(TEST_FRAMES, tester.ReceiveSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -1254,4 +1257,4 @@ - (void)testWithDifferentCiaIndexAfterCanStopped {
@end
-// $Id: test_can_start.mm 1075 2022-01-04 22:00:43Z makemake $ Copyright (c) UV Software, Berlin //
+// $Id: test_can_start.mm 1086 2022-01-09 20:01:00Z haumea $ Copyright (c) UV Software, Berlin //
diff --git a/Tests/UnitTests/test_can_status.mm b/Tests/UnitTests/test_can_status.mm
index 09b5936..3458da8 100644
--- a/Tests/UnitTests/test_can_status.mm
+++ b/Tests/UnitTests/test_can_status.mm
@@ -74,10 +74,12 @@ - (void)testWithInvalidHandle {
int handle = INVALID_HANDLE;
int rc = CANERR_FATAL;
- // @test:
+ // @pre:
// @- initialize DUT1 with configured settings
handle = can_init(DUT1, TEST_CANMODE, NULL);
XCTAssertLessThanOrEqual(0, handle);
+
+ // @test:
// @- try to get status with invalid handle -1
rc = can_status(INVALID_HANDLE, &status.byte);
XCTAssertEqual(CANERR_HANDLE, rc);
@@ -88,14 +90,14 @@ - (void)testWithInvalidHandle {
// @- start DUT1 with configured bit-rate settings
rc = can_start(handle, &bitrate);
XCTAssertEqual(CANERR_NOERROR, rc);
- // @- try to get status with invalid handle INT32_MAX
- rc = can_status(INT32_MAX, &status.byte);
+ // @- try to get status with invalid handle INT32_MIN
+ rc = can_status(INT32_MIN, &status.byte);
XCTAssertEqual(CANERR_HANDLE, rc);
// @- get status of DUT1 and check to be in RUNNING state
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -108,13 +110,15 @@ - (void)testWithInvalidHandle {
// @- stop/reset DUT1
rc = can_reset(handle);
XCTAssertEqual(CANERR_NOERROR, rc);
- // @- try to get status with invalid handle INT32_MIN
- rc = can_status(INT32_MIN, &status.byte);
+ // @- try to get status with invalid handle INT32_MAX
+ rc = can_status(INT32_MAX, &status.byte);
XCTAssertEqual(CANERR_HANDLE, rc);
// @- get status of DUT1 and check to be in INIT state
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertTrue(status.can_stopped);
+
+ // @post:
// @- shutdown DUT1
rc = can_exit(handle);
XCTAssertEqual(CANERR_NOERROR, rc);
@@ -129,10 +133,13 @@ - (void)testWithNullPointerForStatus {
can_status_t status = { CANSTAT_RESET };
int handle = INVALID_HANDLE;
int rc = CANERR_FATAL;
- // @test:
+
+ // @pre:
// @- initialize DUT1 with configured settings
handle = can_init(DUT1, TEST_CANMODE, NULL);
XCTAssertLessThanOrEqual(0, handle);
+
+ // @test:
// @- get status of DUT1 with NULL for parameter 'status'
rc = can_status(handle, NULL);
XCTAssertEqual(CANERR_NOERROR, rc);
@@ -150,7 +157,7 @@ - (void)testWithNullPointerForStatus {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -170,6 +177,8 @@ - (void)testWithNullPointerForStatus {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertTrue(status.can_stopped);
+
+ // @post:
// @- shutdown DUT1
rc = can_exit(handle);
XCTAssertEqual(CANERR_NOERROR, rc);
@@ -190,11 +199,11 @@ - (void)testWhenInterfaceNotInitialized {
rc = can_status(INVALID_HANDLE, &status.byte);
XCTAssertEqual(CANERR_NOTINIT, rc);
// @- try to get status of DUT1 with invalid handle INT32_MIN
- rc = can_status(INT32_MAX, &status.byte);
- XCTAssertEqual(CANERR_NOTINIT, rc);
- // @- try to get status of DUT1 with invalid handle INT32_MIN
rc = can_status(INT32_MIN, &status.byte);
XCTAssertEqual(CANERR_NOTINIT, rc);
+ // @- try to get status of DUT1 with invalid handle INT32_MAX
+ rc = can_status(INT32_MAX, &status.byte);
+ XCTAssertEqual(CANERR_NOTINIT, rc);
// @post:
// @- initialize DUT1 with configured settings
@@ -211,7 +220,7 @@ - (void)testWhenInterfaceNotInitialized {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -262,7 +271,7 @@ - (void)testWhenInterfaceInitialized {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -311,7 +320,7 @@ - (void)testWhenInterfaceStarted {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -359,7 +368,7 @@ - (void)testWhenInterfaceStopped {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -410,7 +419,7 @@ - (void)testWhenInterfaceShutdown {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -481,4 +490,4 @@ - (void)testWhenInterfaceShutdown {
@end
-// $Id: test_can_status.mm 1075 2022-01-04 22:00:43Z makemake $ Copyright (c) UV Software, Berlin //
+// $Id: test_can_status.mm 1086 2022-01-09 20:01:00Z haumea $ Copyright (c) UV Software, Berlin //
diff --git a/Tests/UnitTests/test_can_test.mm b/Tests/UnitTests/test_can_test.mm
index 985c8a6..6b6662c 100644
--- a/Tests/UnitTests/test_can_test.mm
+++ b/Tests/UnitTests/test_can_test.mm
@@ -64,7 +64,7 @@ - (void)tearDown {
(void)can_exit(CANKILL_ALL);
}
-// @xctest TC01.1: Probe interface when not initialzed.
+// @xctest TC01.1: Probe interface when not initialized.
//
// @expected: CANERR_NOERROR and interface state CANBRD_PRESENT
//
@@ -79,7 +79,7 @@ - (void)testWhenInterfaceNotOccupied {
XCTAssertEqual(CANBRD_PRESENT, state);
}
-// @xctest TC01.2: Probe interface when already initialzed (by own process).
+// @xctest TC01.2: Probe interface when already initialized (by own process).
//
// @expected: CANERR_NOERROR and interface state CANBRD_OCCUPIED
//
@@ -115,7 +115,7 @@ - (void)testWhenInterfaceOccupiedByOwnProcess {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -452,4 +452,4 @@ - (void)testBitrateSwitchingEnableDisable {
@end
-// $Id: test_can_test.mm 1036 2021-12-21 14:42:37Z makemake $ Copyright (c) UV Software, Berlin //
+// $Id: test_can_test.mm 1086 2022-01-09 20:01:00Z haumea $ Copyright (c) UV Software, Berlin //
diff --git a/Tests/UnitTests/test_can_version.mm b/Tests/UnitTests/test_can_version.mm
index 54fd79e..7bf587c 100644
--- a/Tests/UnitTests/test_can_version.mm
+++ b/Tests/UnitTests/test_can_version.mm
@@ -99,7 +99,7 @@ - (void)testAnyPlaceAnyTime {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -129,4 +129,4 @@ - (void)testAnyPlaceAnyTime {
@end
-// $Id: test_can_version.mm 1035 2021-12-21 12:03:27Z makemake $ Copyright (c) UV Software, Berlin //
+// $Id: test_can_version.mm 1086 2022-01-09 20:01:00Z haumea $ Copyright (c) UV Software, Berlin //
diff --git a/Tests/UnitTests/test_can_write.mm b/Tests/UnitTests/test_can_write.mm
index 27607af..e57dde7 100644
--- a/Tests/UnitTests/test_can_write.mm
+++ b/Tests/UnitTests/test_can_write.mm
@@ -86,10 +86,12 @@ - (void)testWithInvalidHandle {
message.dlc = mode.fdoe ? CANFD_MAX_DLC : CAN_MAX_DLC;
memset(message.data, 0, CANFD_MAX_LEN);
- // @test:
+ // @pre:
// @- initialize DUT1 with configured settings
handle = can_init(DUT1, mode.byte, NULL);
XCTAssertLessThanOrEqual(0, handle);
+
+ // @test:
// @- try to send a message from DUT1 with invalid handle -1
rc = can_write(INVALID_HANDLE, &message, 0U);
XCTAssertEqual(CANERR_HANDLE, rc);
@@ -107,7 +109,7 @@ - (void)testWithInvalidHandle {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -120,13 +122,15 @@ - (void)testWithInvalidHandle {
// @- stop/reset DUT1
rc = can_reset(handle);
XCTAssertEqual(CANERR_NOERROR, rc);
- // @- try to send a message from DUT1 with invalid handle INT32_MIN
- rc = can_write(INT32_MIN, &message, 0U);
+ // @- try to send a message from DUT1 with invalid handle INT32_MAX
+ rc = can_write(INT32_MAX, &message, 0U);
XCTAssertEqual(CANERR_HANDLE, rc);
// @- get status of DUT1 and check to be in INIT state
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertTrue(status.can_stopped);
+
+ // @post:
// @- shutdown DUT1
rc = can_exit(handle);
XCTAssertEqual(CANERR_NOERROR, rc);
@@ -142,6 +146,7 @@ - (void)testWithNullPointerForMessage {
int handle = INVALID_HANDLE;
int rc = CANERR_FATAL;
+ // @pre:
// @- initialize DUT1 with configured settings
handle = can_init(DUT1, TEST_CANMODE, NULL);
XCTAssertLessThanOrEqual(0, handle);
@@ -163,7 +168,7 @@ - (void)testWithNullPointerForMessage {
XCTAssertFalse(status.can_stopped);
// @post:
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -214,8 +219,8 @@ - (void)testWhenInterfaceNotInitialized {
// @- try to send a message from DUT1 with invalid handle INT32_MIN
rc = can_write(INT32_MIN, &message, 0U);
XCTAssertEqual(CANERR_NOTINIT, rc);
- // @- try to send a message from DUT1 with invalid handle INT32_MIN
- rc = can_write(INT32_MIN, &message, 0U);
+ // @- try to send a message from DUT1 with invalid handle INT32_MAX
+ rc = can_write(INT32_MAX, &message, 0U);
XCTAssertEqual(CANERR_NOTINIT, rc);
// @post:
@@ -233,7 +238,7 @@ - (void)testWhenInterfaceNotInitialized {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -299,7 +304,7 @@ - (void)testWhenInterfaceNotStarted {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -358,7 +363,7 @@ - (void)testWhenInterfaceStopped {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -424,7 +429,7 @@ - (void)testWhenInterfaceShutdown {
rc = can_status(handle, &status.byte);
XCTAssertEqual(CANERR_NOERROR, rc);
XCTAssertFalse(status.can_stopped);
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -648,7 +653,7 @@ - (void)testWithInvalid11bitIdentifier {
XCTAssertEqual(CANERR_ILLPARA, rc);
// @post:
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -819,7 +824,7 @@ - (void)testWithInvalid29bitIdentifier {
XCTAssertEqual(CANERR_ILLPARA, rc);
// @post:
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -1020,7 +1025,7 @@ - (void)testWithInvalidDataLengthCode {
XCTAssertEqual(CANERR_ILLPARA, rc);
// @post:
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -1105,7 +1110,7 @@ - (void)testCheckFlagXtdWhenOperationModeNoXtd {
XCTAssertFalse(status.can_stopped);
// @post:
- // @-- sunnyday traffic (optional):
+ // @-- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -1191,7 +1196,7 @@ - (void)testCheckFlagRtrWhenOperationModeNoRtr {
XCTAssertFalse(status.can_stopped);
// @post:
- // @-- sunnyday traffic (optional):
+ // @-- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -1278,7 +1283,7 @@ - (void)testCheckFlagFdfInCan20OperationMode {
XCTAssertFalse(status.can_stopped);
// @post:
- // @-- sunnyday traffic (optional):
+ // @-- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -1365,7 +1370,7 @@ - (void)testCheckFlagBrsInCan20OperationMode {
XCTAssertFalse(status.can_stopped);
// @post:
- // @-- sunnyday traffic (optional):
+ // @-- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -1453,7 +1458,7 @@ - (void)testCheckFlagBrsWithoutFlagFdf {
XCTAssertFalse(status.can_stopped);
// @post:
- // @-- sunnyday traffic (optional):
+ // @-- send and receive some frames to/from DUT2 (optional)
#if (0)
// FIXME: 2nd device must also be CAN FD capable!
#if (SEND_TEST_FRAMES != 0)
@@ -1528,7 +1533,7 @@ - (void)testCheckFlagSts {
XCTAssertFalse(status.can_stopped);
// @post:
- // @- sunnyday traffic (optional):
+ // @- send and receive some frames to/from DUT2 (optional)
#if (SEND_TEST_FRAMES != 0)
CTester tester;
XCTAssertEqual(TEST_FRAMES, tester.SendSomeFrames(handle, DUT2, TEST_FRAMES));
@@ -1652,4 +1657,4 @@ - (void)testWhenTransmitterIsBusy {
@end
-// $Id: test_can_write.mm 1075 2022-01-04 22:00:43Z makemake $ Copyright (c) UV Software, Berlin //
+// $Id: test_can_write.mm 1086 2022-01-09 20:01:00Z haumea $ Copyright (c) UV Software, Berlin //
diff --git a/Trial/PCBUSB.xcodeproj/project.pbxproj b/Trial/PCBUSB.xcodeproj/project.pbxproj
index 1151dcf..dfaffc5 100644
--- a/Trial/PCBUSB.xcodeproj/project.pbxproj
+++ b/Trial/PCBUSB.xcodeproj/project.pbxproj
@@ -52,7 +52,6 @@
0F8328CB27820ABC00BE8BBA /* Tester.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Tester.h; path = ../Tests/UnitTests/Tester.h; sourceTree = ""; };
0F8328CC27820ABC00BE8BBA /* Tester.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = Tester.cpp; path = ../Tests/UnitTests/Tester.cpp; sourceTree = ""; };
0F8328CD27820ABC00BE8BBA /* Settings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Settings.h; path = ../Tests/UnitTests/Settings.h; sourceTree = ""; };
- 0F8328CE27820ABC00BE8BBA /* Template.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Template.h; path = ../Tests/UnitTests/Template.h; sourceTree = ""; };
0F8328D527822DE400BE8BBA /* test_can_write.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = test_can_write.mm; path = ../Tests/UnitTests/test_can_write.mm; sourceTree = ""; };
0F8328D627822DE400BE8BBA /* test_can_start.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = test_can_start.mm; path = ../Tests/UnitTests/test_can_start.mm; sourceTree = ""; };
0F8328D727822DE400BE8BBA /* test_can_firmware.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = test_can_firmware.mm; path = ../Tests/UnitTests/test_can_firmware.mm; sourceTree = ""; };
@@ -81,6 +80,7 @@
0FC6171C25CC67360010B15D /* PCBUSB.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PCBUSB.h; path = ../Sources/Wrapper/PCBUSB.h; sourceTree = ""; };
0FC6171D25CC67360010B15D /* can_api.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = can_api.c; path = ../Sources/Wrapper/can_api.c; sourceTree = ""; };
0FE14B1725AEEA4900E87475 /* PCBUSB */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = PCBUSB; sourceTree = BUILT_PRODUCTS_DIR; };
+ 44FAED34279200C000B44E88 /* Driver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Driver.h; path = ../Tests/UnitTests/Driver.h; sourceTree = ""; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -104,8 +104,8 @@
0F8328C727820A0900BE8BBA /* Testing */ = {
isa = PBXGroup;
children = (
+ 44FAED34279200C000B44E88 /* Driver.h */,
0F8328CD27820ABC00BE8BBA /* Settings.h */,
- 0F8328CE27820ABC00BE8BBA /* Template.h */,
0F8328CA27820ABC00BE8BBA /* Testing.mm */,
0F8328DC27822DE400BE8BBA /* test_can_test.mm */,
0F8328DB27822DE400BE8BBA /* test_can_init.mm */,
diff --git a/Trial/Sources/main.cpp b/Trial/Sources/main.cpp
index d1f6b59..8640305 100644
--- a/Trial/Sources/main.cpp
+++ b/Trial/Sources/main.cpp
@@ -84,6 +84,7 @@ int main(int argc, const char * argv[]) {
int32_t channel = (int32_t)PCAN_USB1;
uint16_t timeout = CANREAD_INFINITE;
useconds_t delay = 0U;
+ CCanApi::SChannelInfo info;
CCanApi::EChannelState state;
//int32_t clocks[CANPROP_MAX_BUFFER_SIZE/sizeof(int32_t)];
char szVal[CANPROP_MAX_BUFFER_SIZE];
@@ -232,12 +233,24 @@ int main(int argc, const char * argv[]) {
return 0;
}
if (option_test) {
+#if (1)
+ bool result = CPeakCAN::GetFirstChannel(info);
+ while (result) {
+ retVal = CPeakCAN::ProbeChannel(info.m_nChannelNo, opMode, state);
+ fprintf(stdout, ">>> CCanAPI::ProbeChannel(%i): state = %s", info.m_nChannelNo,
+ (state == CCanApi::ChannelOccupied) ? "occupied" :
+ (state == CCanApi::ChannelAvailable) ? "available" :
+ (state == CCanApi::ChannelNotAvailable) ? "not available" : "not testable");
+ fprintf(stdout, "%s", (retVal == CCanApi::IllegalParameter) ? " (warning: Op.-Mode not supported)\n" : "\n");
+ result = CPeakCAN::GetNextChannel(info);
+ }
+#else
retVal = myDriver.SetProperty(CANPROP_SET_FIRST_CHANNEL, (void *)NULL, 0U);
while (retVal == CCanApi::NoError) {
- retVal = myDriver.GetProperty(CANPROP_GET_CHANNEL_NO, (void *)&i32Val, sizeof(int32_t));
+ retVal = myDriver.GetProperty(CANPROP_GET_CHANNEL_TYPE, (void *)&i32Val, sizeof(int32_t));
if (retVal == CCanApi::NoError) {
retVal = CPeakCAN::ProbeChannel(i32Val, opMode, state);
- fprintf(stdout, ">>> CCanApi.ProbeChannel(%i): state = %s", i32Val,
+ fprintf(stdout, ">>> CCanApi::ProbeChannel(%i): state = %s", i32Val,
(state == CCanApi::ChannelOccupied) ? "occupied" :
(state == CCanApi::ChannelAvailable) ? "available" :
(state == CCanApi::ChannelNotAvailable) ? "not available" : "not testable");
@@ -245,6 +258,7 @@ int main(int argc, const char * argv[]) {
}
retVal = myDriver.SetProperty(CANPROP_SET_NEXT_CHANNEL, (void *)NULL, 0U);
}
+#endif
if (option_exit)
return 0;
}
@@ -265,11 +279,21 @@ int main(int argc, const char * argv[]) {
fprintf(stdout, "%s", (retVal == CCanApi::IllegalParameter) ? " (warning: Op.-Mode not supported)\n" : "\n");
}
if (option_info) {
- retVal = myDriver.GetProperty(CANPROP_GET_DEVICE_CHANNEL, (void *)&i32Val, sizeof(int32_t));
+ retVal = myDriver.GetProperty(CANPROP_GET_NUM_CHANNELS, (void*)&u8Val, sizeof(uint8_t));
+ if (retVal == CCanApi::NoError)
+ fprintf(stdout, ">>> myDriver.GetProperty(CANPROP_GET_NUM_CHANNELS): value = %d\n", u8Val);
+ //else [optional property]
+ // fprintf(stderr, "+++ error: myDriver.GetProperty(CANPROP_GET_NUM_CHANNELS) returned %i\n", retVal);
+ retVal = myDriver.GetProperty(CANPROP_GET_CAN_CHANNEL, (void*)&u8Val, sizeof(uint8_t));
+ if (retVal == CCanApi::NoError)
+ fprintf(stdout, ">>> myDriver.GetProperty(CANPROP_GET_CAN_CHANNEL): value = %u\n", u8Val + 1U);
+ //else [optional property]
+ // fprintf(stderr, "+++ error: myDriver.GetProperty(CANPROP_GET_CAN_CHANNEL) returned %i\n", retVal);
+ retVal = myDriver.GetProperty(CANPROP_GET_DEVICE_TYPE, (void *)&i32Val, sizeof(int32_t));
if (retVal == CCanApi::NoError)
- fprintf(stdout, ">>> myDriver.GetProperty(CANPROP_GET_DEVICE_CHANNEL): value = 0x%02X\n", i32Val);
+ fprintf(stdout, ">>> myDriver.GetProperty(CANPROP_GET_DEVICE_TYPE): value = %d\n", i32Val);
else
- fprintf(stderr, "+++ error: myDriver.GetProperty(CANPROP_GET_DEVICE_CHANNEL) returned %i\n", retVal);
+ fprintf(stderr, "+++ error: myDriver.GetProperty(CANPROP_GET_DEVICE_TYPE) returned %i\n", retVal);
retVal = myDriver.GetProperty(CANPROP_GET_DEVICE_NAME, (void *)szVal, CANPROP_MAX_BUFFER_SIZE);
if (retVal == CCanApi::NoError)
fprintf(stdout, ">>> myDriver.GetProperty(CANPROP_GET_DEVICE_NAME): value = '%s'\n", szVal);
@@ -285,18 +309,6 @@ int main(int argc, const char * argv[]) {
fprintf(stdout, ">>> myDriver.GetProperty(CANPROP_GET_DEVICE_DLLNAME): value = '%s'\n", szVal);
else
fprintf(stderr, "+++ error: myDriver.GetProperty(CANPROP_GET_DEVICE_DLLNAME) returned %i\n", retVal);
-#if (0)
- retVal = myDriver.GetProperty(CANPROP_GET_NUM_CHANNELS, (void *)&u8Val, sizeof(uint8_t));
- if (retVal == CCanApi::NoError)
- fprintf(stdout, ">>> myDriver.GetProperty(CANPROP_GET_NUM_CHANNELS): value = %d\n", u8Val);
- else
- fprintf(stderr, "+++ error: myDriver.GetProperty(CANPROP_GET_NUM_CHANNELS) returned %i\n", retVal);
- retVal = myDriver.GetProperty(CANPROP_GET_CAN_CHANNEL, (void *)&u8Val, sizeof(uint8_t));
- if (retVal == CCanApi::NoError)
- fprintf(stdout, ">>> myDriver.GetProperty(CANPROP_GET_CAN_CHANNEL): value = %u\n", u8Val + 1U);
- else
- fprintf(stderr, "+++ error: myDriver.GetProperty(CANPROP_GET_CAN_CHANNEL) returned %i\n", retVal);
-#endif
// vendor-specific properties
retVal = myDriver.GetProperty(PEAKCAN_PROPERTY_DEVICE_ID, (void *)&u32Val, sizeof(uint32_t));
if (retVal == CCanApi::NoError)
@@ -498,7 +510,7 @@ int main(int argc, const char * argv[]) {
if ((myDriver.GetProperty(CANPROP_GET_RCV_QUEUE_SIZE, (void *)&u32QueSize, sizeof(uint32_t)) == CCanApi::NoError) &&
(myDriver.GetProperty(CANPROP_GET_RCV_QUEUE_HIGH, (void *)&u32QueHigh, sizeof(uint32_t)) == CCanApi::NoError) &&
(myDriver.GetProperty(CANPROP_GET_RCV_QUEUE_OVFL, (void *)&u64QueOvfl, sizeof(uint64_t)) == CCanApi::NoError))
- fprintf(stdout, ">>> myDriver.GetProperty(CANPROP_GET_QUEUE_*): size = %" PRIu32 " high = %" PRIu32 " overflows = %" PRIu64 "\n", u32QueSize, u32QueHigh, u64QueOvfl);
+ fprintf(stdout, ">>> myDriver.GetProperty(CANPROP_GET_QUEUE_*): SIZE = %" PRIu32 " HIGH = %" PRIu32 " OVFL = %" PRIu64 "\n", u32QueSize, u32QueHigh, u64QueOvfl);
}
if (option_info) {
char *hardware = myDriver.GetHardwareVersion();
diff --git a/Utilities/can_moni/README.md b/Utilities/can_moni/README.md
index d091195..eb8b385 100644
--- a/Utilities/can_moni/README.md
+++ b/Utilities/can_moni/README.md
@@ -1,4 +1,4 @@
-__CAN Monitor for PEAK PCAN-USB Interfaces, Version 0.2.2__ \
+__CAN Monitor for PEAK PCAN-USB Interfaces, Version 0.2.3__ \
Copyright © 2008-2010,2012-2022 by Uwe Vogt, UV Software, Berlin
```
diff --git a/Utilities/can_moni/Sources/main.cpp b/Utilities/can_moni/Sources/main.cpp
index cebd50d..122c8cd 100755
--- a/Utilities/can_moni/Sources/main.cpp
+++ b/Utilities/can_moni/Sources/main.cpp
@@ -20,7 +20,7 @@
#include "build_no.h"
#define VERSION_MAJOR 0
#define VERSION_MINOR 2
-#define VERSION_PATCH 2
+#define VERSION_PATCH 3
#define VERSION_BUILD BUILD_NO
#define VERSION_STRING TOSTRING(VERSION_MAJOR) "." TOSTRING(VERSION_MINOR) "." TOSTRING(VERSION_PATCH) " (" TOSTRING(BUILD_NO) ")"
#if defined(_WIN64)
@@ -51,6 +51,7 @@ static const char LICENSE[] = "This program is free software: you can redist
"along with this program. If not, see .";
#define basename(x) "can_moni" // FIXME: Where is my `basename' function?
+#include "PeakCAN_Defines.h"
#include "PeakCAN.h"
#include "Timer.h"
#include "Message.h"
@@ -81,8 +82,9 @@ class CCanDriver : public CPeakCAN {
public:
uint64_t ReceptionLoop();
public:
- static int ListCanDevices(const char *vendor = NULL);
- static int TestCanDevices(CANAPI_OpMode_t opMode, const char *vendor = NULL);
+ static int ListCanDevices(void);
+ static int TestCanDevices(CANAPI_OpMode_t opMode);
+#if (0)
// list of CAN interface vendors
static const struct TCanVendor {
int32_t id;
@@ -119,6 +121,7 @@ const CCanDriver::TCanDevice CCanDriver::m_CanDevices[] = {
{PEAKCAN_LIBRARY_ID, PCAN_USB16, (char *)"PCAN-USB16" },
#endif
{EOF, EOF, NULL}
+#endif
};
static void sigterm(int signo);
@@ -134,7 +137,7 @@ static CCanDriver canDriver = CCanDriver();
// TODO: this code could be made more C++ alike
int main(int argc, const char * argv[]) {
int opt;
- int channel = 0;
+ CCanDriver::SChannelInfo channel;
int op = 0, rf = 0, xf = 0, ef = 0, lo = 0, sh = 0;
long baudrate = CANBDR_250; int bd = 0;
CCanMessage::EFormatTimestamp modeTime = CCanMessage::OptionZero; int mt = 0;
@@ -465,13 +468,13 @@ int main(int argc, const char * argv[]) {
case 'L': /* option `--list-boards[=]' (-L) */
fprintf(stdout, "%s\n%s\n\n%s\n\n", APPLICATION, COPYRIGHT, WARRANTY);
/* list all supported interfaces */
- num_boards = CCanDriver::ListCanDevices(optarg);
+ num_boards = CCanDriver::ListCanDevices(/*optarg*/);
fprintf(stdout, "Number of supported CAN interfaces: %i\n", num_boards);
return (num_boards >= 0) ? 0 : 1;
case 'T': /* option `--test-boards[=]' (-T) */
fprintf(stdout, "%s\n%s\n\n%s\n\n", APPLICATION, COPYRIGHT, WARRANTY);
/* list all available interfaces */
- num_boards = CCanDriver::TestCanDevices(opMode, optarg);
+ num_boards = CCanDriver::TestCanDevices(opMode/*, optarg*/);
fprintf(stdout, "Number of present CAN interfaces: %i\n", num_boards);
return (num_boards >= 0) ? 0 : 1;
case 'h':
@@ -500,6 +503,19 @@ int main(int argc, const char * argv[]) {
fprintf(stderr, "%s: too many arguments given\n", basename(argv[0]));
return 1;
}
+#if (1)
+ bool result = CCanDriver::GetFirstChannel(channel);
+ while (result) {
+ if (strcasecmp(argv[optind], channel.m_szDeviceName) == 0) {
+ break;
+ }
+ result = CCanDriver::GetNextChannel(channel);
+ }
+ if (!result) {
+ fprintf(stderr, "%s: illegal argument `%s'\n", basename(argv[0]), argv[optind]);
+ return 1;
+ }
+#else
for (channel = 0; CCanDriver::m_CanDevices[channel].adapter != EOF; channel++) {
if (strcasecmp(argv[optind], CCanDriver::m_CanDevices[channel].name) == 0) {
break;
@@ -509,6 +525,7 @@ int main(int argc, const char * argv[]) {
fprintf(stderr, "%s: illegal argument `%s'\n", basename(argv[0]), argv[optind]);
return 1;
}
+#endif
/* - check bit-timing index (n/a for CAN FD) */
if (opMode.fdoe && (bitrate.btr.frequency <= 0)) {
fprintf(stderr, "%s: illegal combination of options `--mode' (m) and `--bitrate'\n", basename(argv[0]));
@@ -559,12 +576,18 @@ int main(int argc, const char * argv[]) {
}
}
/* - initialize interface */
+#if (1)
+ fprintf(stdout, "Hardware=%s...", channel.m_szDeviceName);
+ fflush (stdout);
+ retVal = canDriver.InitializeChannel(channel.m_nChannelNo, opMode);
+#else
fprintf(stdout, "Hardware=%s...", CCanDriver::m_CanDevices[channel].name);
fflush (stdout);
retVal = canDriver.InitializeChannel(CCanDriver::m_CanDevices[channel].adapter, opMode);
+#endif
if (retVal != CCanApi::NoError) {
fprintf(stdout, "FAILED!\n");
- fprintf(stderr, "+++ error: CAN Controller could not be initialized (%i)\n", retVal);
+ fprintf(stderr, "+++ error: CAN Controller could not be initialized (%i)", retVal);
if (retVal == CCanApi::NotSupported)
fprintf(stderr, " - possibly CAN operating mode %02Xh not supported", opMode.byte);
fputc('\n', stderr);
@@ -622,74 +645,44 @@ int main(int argc, const char * argv[]) {
return retVal;
}
-int CCanDriver::ListCanDevices(const char *vendor) {
- int32_t library = EOF; int n = 0;
-
- if (vendor != NULL) {
- /* search library ID in the vendor list */
- for (int32_t i = 0; CCanDriver::m_CanVendors[i].id != EOF; i++) {
- if (!strcmp(vendor, CCanDriver::m_CanVendors[i].name)) {
- library = CCanDriver::m_CanVendors[i].id;
- break;
- }
- }
- fprintf(stdout, "Suppored hardware from \"%s\":\n", vendor);
- }
- else
- fprintf(stdout, "Suppored hardware:\n");
- for (int32_t i = 0; CCanDriver::m_CanDevices[i].library != EOF; i++) {
- /* list all boards or from a specific vendor */
- if ((vendor == NULL) || (library == CCanDriver::m_CanDevices[i].library) ||
- !strcmp(vendor, "*")) { // TODO: pattern matching
- fprintf(stdout, "\"%s\" ", CCanDriver::m_CanDevices[i].name);
- /* search vendor name in the vendor list */
- for (int32_t j = 0; CCanDriver::m_CanVendors[j].id != EOF; j++) {
- if (CCanDriver::m_CanDevices[i].library == CCanDriver::m_CanVendors[j].id) {
- fprintf(stdout, "(VendorName=\"%s\", LibraryId=%" PRIi32 ", AdapterId=%" PRIi32 ")",
- CCanDriver::m_CanVendors[j].name, CCanDriver::m_CanDevices[i].library, CCanDriver::m_CanDevices[i].adapter);
- break;
- }
- }
- fprintf(stdout, "\n");
- n++;
- }
+int CCanDriver::ListCanDevices(void) {
+ CCanDriver::SChannelInfo info;
+ int n = 0;
+
+ fprintf(stdout, "Suppored hardware:\n");
+ bool result = CCanDriver::GetFirstChannel(info);
+ while (result) {
+ fprintf(stdout, "\"%s\" (VendorName=\"%s\", LibraryId=%" PRIi32 ", ChannelNo=%" PRIi32 ")\n",
+ info.m_szDeviceName, info.m_szVendorName, info.m_nLibraryId, info.m_nChannelNo);
+ n++;
+ result = CCanDriver::GetNextChannel(info);
}
return n;
}
-int CCanDriver::TestCanDevices(CANAPI_OpMode_t opMode, const char *vendor) {
- int32_t library = EOF; int n = 0;
-
- if (vendor != NULL) {
- /* search library ID in the vendor list */
- for (int32_t i = 0; CCanDriver::m_CanVendors[i].id != EOF; i++) {
- if (!strcmp(vendor, CCanDriver::m_CanVendors[i].name)) {
- library = CCanDriver::m_CanVendors[i].id;
- break;
- }
- }
- }
- for (int32_t i = 0; CCanDriver::m_CanDevices[i].library != EOF; i++) {
- /* test all boards or from a specific vendor */
- if ((vendor == NULL) || (library == CCanDriver::m_CanDevices[i].library) ||
- !strcmp(vendor, "*")) { // TODO: pattern matching
- fprintf(stdout, "Hardware=%s...", CCanDriver::m_CanDevices[i].name);
- fflush(stdout);
- EChannelState state;
- CANAPI_Return_t retVal = CCanDriver::ProbeChannel(CCanDriver::m_CanDevices[i].adapter, opMode, state);
- if ((retVal == CCanApi::NoError) || (retVal == CCanApi::IllegalParameter)) {
- CTimer::Delay(333U * CTimer::MSEC); // to fake probing a hardware
- switch (state) {
- case CCanApi::ChannelOccupied: fprintf(stdout, "occupied\n"); n++; break;
- case CCanApi::ChannelAvailable: fprintf(stdout, "available\n"); n++; break;
- case CCanApi::ChannelNotAvailable: fprintf(stdout, "not available\n"); break;
- default: fprintf(stdout, "not testable\n"); break;
- }
- if (retVal == CCanApi::IllegalParameter)
- fprintf(stderr, "+++ warning: CAN operation mode not supported (%02x)\n", opMode.byte);
- } else
- fprintf(stdout, "FAILED!\n");
- }
+int CCanDriver::TestCanDevices(CANAPI_OpMode_t opMode) {
+ CCanDriver::SChannelInfo info;
+ int n = 0;
+
+ bool result = CCanDriver::GetFirstChannel(info);
+ while (result) {
+ fprintf(stdout, "Hardware=%s...", info.m_szDeviceName);
+ fflush(stdout);
+ EChannelState state;
+ CANAPI_Return_t retVal = CCanDriver::ProbeChannel(info.m_nChannelNo, opMode, state);
+ if ((retVal == CCanApi::NoError) || (retVal == CCanApi::IllegalParameter)) {
+ CTimer::Delay(333U * CTimer::MSEC); // to fake probing a hardware
+ switch (state) {
+ case CCanApi::ChannelOccupied: fprintf(stdout, "occupied\n"); n++; break;
+ case CCanApi::ChannelAvailable: fprintf(stdout, "available\n"); n++; break;
+ case CCanApi::ChannelNotAvailable: fprintf(stdout, "not available\n"); break;
+ default: fprintf(stdout, "not testable\n"); break;
+ }
+ if (retVal == CCanApi::IllegalParameter)
+ fprintf(stderr, "+++ warning: CAN operation mode not supported (%02xh)\n", opMode.byte);
+ } else
+ fprintf(stdout, "FAILED!\n");
+ result = CCanDriver::GetNextChannel(info);
}
return n;
}
@@ -812,7 +805,9 @@ static void usage(FILE *stream, const char *program)
fprintf(stream, " -w, --wrap=(NO|8|10|16|32|64) wraparound after n data bytes (default=NO)\n");
fprintf(stream, " -x, --exclude=[~] exclude CAN-IDs: [-]{,[-]}\n");
// fprintf(stream, " -s, --script= execute a script file\n"); // TODO: script engine
+#if (OPTION_CAN_2_0_ONLY == 0)
fprintf(stream, " -m, --mode=(2.0|FDF[+BSR]) CAN operation mode: CAN 2.0 or CAN FD format\n");
+#endif
fprintf(stream, " --shared shared CAN controller access (when supported)\n");
fprintf(stream, " --listen-only monitor mode (listen-only, transmitter is off)\n");
fprintf(stream, " --error-frames allow reception of error frames\n");
@@ -844,5 +839,5 @@ static void version(FILE *stream, const char *program)
{
fprintf(stdout, "%s\n%s\n\n%s\n\n", APPLICATION, COPYRIGHT, LICENSE);
(void)program;
- fprintf(stream, "Written by Uwe Vogt, UV Software, Berlin \n");
+ fprintf(stream, "Written by Uwe Vogt, UV Software, Berlin \n");
}
diff --git a/Utilities/can_test/README.md b/Utilities/can_test/README.md
index 7106538..0cc1554 100644
--- a/Utilities/can_test/README.md
+++ b/Utilities/can_test/README.md
@@ -1,4 +1,4 @@
-__CAN Tester for PEAK PCAN-USB Interfaces, Version 0.2.2__ \
+__CAN Tester for PEAK PCAN-USB Interfaces, Version 0.2.3__ \
Copyright © 2008-2010,2012-2022 by Uwe Vogt, UV Software, Berlin
```
diff --git a/Utilities/can_test/Sources/main.cpp b/Utilities/can_test/Sources/main.cpp
index 4467756..016076f 100644
--- a/Utilities/can_test/Sources/main.cpp
+++ b/Utilities/can_test/Sources/main.cpp
@@ -20,7 +20,7 @@
#include "build_no.h"
#define VERSION_MAJOR 0
#define VERSION_MINOR 2
-#define VERSION_PATCH 2
+#define VERSION_PATCH 3
#define VERSION_BUILD BUILD_NO
#define VERSION_STRING TOSTRING(VERSION_MAJOR) "." TOSTRING(VERSION_MINOR) "." TOSTRING(VERSION_PATCH) " (" TOSTRING(BUILD_NO) ")"
#if defined(_WIN64)
@@ -51,6 +51,7 @@ static const char LICENSE[] = "This program is free software: you can redist
"along with this program. If not, see .";
#define basename(x) "can_test" // FIXME: Where is my `basename' function?
+#include "PeakCAN_Defines.h"
#include "PeakCAN.h"
#include "Timer.h"
@@ -83,8 +84,9 @@ class CCanDriver : public CPeakCAN {
uint64_t TransmitterTest(time_t duration, CANAPI_OpMode_t opMode, uint32_t id = 0x100U, uint8_t dlc = 0U, uint32_t delay = 0U, uint64_t offset = 0U);
uint64_t TransmitterTest(uint64_t count, CANAPI_OpMode_t opMode, bool random = false, uint32_t id = 0x100U, uint8_t dlc = 0U, uint32_t delay = 0U, uint64_t offset = 0U);
public:
- static int ListCanDevices(const char *vendor = NULL);
- static int TestCanDevices(CANAPI_OpMode_t opMode, const char *vendor = NULL);
+ static int ListCanDevices(void);
+ static int TestCanDevices(CANAPI_OpMode_t opMode);
+#if (0)
// list of CAN interface vendors
static const struct TCanVendor {
int32_t id;
@@ -121,6 +123,7 @@ const CCanDriver::TCanDevice CCanDriver::m_CanDevices[] = {
{PEAKCAN_LIBRARY_ID, PCAN_USB16, (char *)"PCAN-USB16" },
#endif
{EOF, EOF, NULL}
+#endif
};
static void sigterm(int signo);
@@ -135,7 +138,7 @@ static CCanDriver canDriver = CCanDriver();
// TODO: this code could be made more C++ alike
int main(int argc, const char * argv[]) {
int opt;
- int channel = 0;
+ CCanDriver::SChannelInfo channel;
int mode = RxMODE, m = 0;
int op = 0, rf = 0, xf = 0, ef = 0, lo = 0, sh = 0;
long baudrate = CANBDR_250; int bd = 0;
@@ -457,13 +460,13 @@ int main(int argc, const char * argv[]) {
case 'L': /* option `--list-boards[=]' (-L) */
fprintf(stdout, "%s\n%s\n\n%s\n\n", APPLICATION, COPYRIGHT, WARRANTY);
/* list all supported interfaces */
- num_boards = CCanDriver::ListCanDevices(optarg);
+ num_boards = CCanDriver::ListCanDevices(/*optarg*/);
fprintf(stdout, "Number of supported CAN interfaces: %i\n", num_boards);
return (num_boards >= 0) ? 0 : 1;
case 'T': /* option `--test-boards[=]' (-T) */
fprintf(stdout, "%s\n%s\n\n%s\n\n", APPLICATION, COPYRIGHT, WARRANTY);
/* list all available interfaces */
- num_boards = CCanDriver::TestCanDevices(opMode, optarg);
+ num_boards = CCanDriver::TestCanDevices(opMode/*, optarg*/);
fprintf(stdout, "Number of present CAN interfaces: %i\n", num_boards);
return (num_boards >= 0) ? 0 : 1;
case 'h':
@@ -492,6 +495,19 @@ int main(int argc, const char * argv[]) {
fprintf(stderr, "%s: too many arguments given\n", basename(argv[0]));
return 1;
}
+#if (1)
+ bool result = CCanDriver::GetFirstChannel(channel);
+ while (result) {
+ if (strcasecmp(argv[optind], channel.m_szDeviceName) == 0) {
+ break;
+ }
+ result = CCanDriver::GetNextChannel(channel);
+ }
+ if (!result) {
+ fprintf(stderr, "%s: illegal argument `%s'\n", basename(argv[0]), argv[optind]);
+ return 1;
+ }
+#else
for (channel = 0; CCanDriver::m_CanDevices[channel].adapter != EOF; channel++) {
if (strcasecmp(argv[optind], CCanDriver::m_CanDevices[channel].name) == 0) {
break;
@@ -501,6 +517,7 @@ int main(int argc, const char * argv[]) {
fprintf(stderr, "%s: illegal argument `%s'\n", basename(argv[0]), argv[optind]);
return 1;
}
+#endif
/* - check data length length and make CAN FD DLC (0x0..0xF) */
if (!opMode.fdoe && (dlc > CAN_MAX_LEN)) {
fprintf(stderr, "%s: illegal combination of options `--mode' (m) and `--dlc' (d)\n", basename(argv[0]));
@@ -581,12 +598,18 @@ int main(int argc, const char * argv[]) {
}
}
/* - initialize interface */
+#if (1)
+ fprintf(stdout, "Hardware=%s...", channel.m_szDeviceName);
+ fflush (stdout);
+ retVal = canDriver.InitializeChannel(channel.m_nChannelNo, opMode);
+#else
fprintf(stdout, "Hardware=%s...", CCanDriver::m_CanDevices[channel].name);
fflush (stdout);
retVal = canDriver.InitializeChannel(CCanDriver::m_CanDevices[channel].adapter, opMode);
+#endif
if (retVal != CCanApi::NoError) {
fprintf(stdout, "FAILED!\n");
- fprintf(stderr, "+++ error: CAN Controller could not be initialized (%i)\n", retVal);
+ fprintf(stderr, "+++ error: CAN Controller could not be initialized (%i)", retVal);
if (retVal == CCanApi::NotSupported)
fprintf(stderr, " - possibly CAN operating mode %02Xh not supported", opMode.byte);
fputc('\n', stderr);
@@ -657,74 +680,44 @@ int main(int argc, const char * argv[]) {
return retVal;
}
-int CCanDriver::ListCanDevices(const char *vendor) {
- int32_t library = EOF; int n = 0;
-
- if (vendor != NULL) {
- /* search library ID in the vendor list */
- for (int32_t i = 0; CCanDriver::m_CanVendors[i].id != EOF; i++) {
- if (!strcmp(vendor, CCanDriver::m_CanVendors[i].name)) {
- library = CCanDriver::m_CanVendors[i].id;
- break;
- }
- }
- fprintf(stdout, "Suppored hardware from \"%s\":\n", vendor);
- }
- else
- fprintf(stdout, "Suppored hardware:\n");
- for (int32_t i = 0; CCanDriver::m_CanDevices[i].library != EOF; i++) {
- /* list all boards or from a specific vendor */
- if ((vendor == NULL) || (library == CCanDriver::m_CanDevices[i].library) ||
- !strcmp(vendor, "*")) { // TODO: pattern matching
- fprintf(stdout, "\"%s\" ", CCanDriver::m_CanDevices[i].name);
- /* search vendor name in the vendor list */
- for (int32_t j = 0; CCanDriver::m_CanVendors[j].id != EOF; j++) {
- if (CCanDriver::m_CanDevices[i].library == CCanDriver::m_CanVendors[j].id) {
- fprintf(stdout, "(VendorName=\"%s\", LibraryId=%" PRIi32 ", AdapterId=%" PRIi32 ")",
- CCanDriver::m_CanVendors[j].name, CCanDriver::m_CanDevices[i].library, CCanDriver::m_CanDevices[i].adapter);
- break;
- }
- }
- fprintf(stdout, "\n");
- n++;
- }
+int CCanDriver::ListCanDevices(void) {
+ CCanDriver::SChannelInfo info;
+ int n = 0;
+
+ fprintf(stdout, "Suppored hardware:\n");
+ bool result = CCanDriver::GetFirstChannel(info);
+ while (result) {
+ fprintf(stdout, "\"%s\" (VendorName=\"%s\", LibraryId=%" PRIi32 ", ChannelNo=%" PRIi32 ")\n",
+ info.m_szDeviceName, info.m_szVendorName, info.m_nLibraryId, info.m_nChannelNo);
+ n++;
+ result = CCanDriver::GetNextChannel(info);
}
return n;
}
-int CCanDriver::TestCanDevices(CANAPI_OpMode_t opMode, const char *vendor) {
- int32_t library = EOF; int n = 0;
-
- if (vendor != NULL) {
- /* search library ID in the vendor list */
- for (int32_t i = 0; CCanDriver::m_CanVendors[i].id != EOF; i++) {
- if (!strcmp(vendor, CCanDriver::m_CanVendors[i].name)) {
- library = CCanDriver::m_CanVendors[i].id;
- break;
- }
- }
- }
- for (int32_t i = 0; CCanDriver::m_CanDevices[i].library != EOF; i++) {
- /* test all boards or from a specific vendor */
- if ((vendor == NULL) || (library == CCanDriver::m_CanDevices[i].library) ||
- !strcmp(vendor, "*")) { // TODO: pattern matching
- fprintf(stdout, "Hardware=%s...", CCanDriver::m_CanDevices[i].name);
- fflush(stdout);
- EChannelState state;
- CANAPI_Return_t retVal = CCanDriver::ProbeChannel(CCanDriver::m_CanDevices[i].adapter, opMode, state);
- if ((retVal == CCanApi::NoError) || (retVal == CCanApi::IllegalParameter)) {
- CTimer::Delay(333U * CTimer::MSEC); // to fake probing a hardware
- switch (state) {
- case CCanApi::ChannelOccupied: fprintf(stdout, "occupied\n"); n++; break;
- case CCanApi::ChannelAvailable: fprintf(stdout, "available\n"); n++; break;
- case CCanApi::ChannelNotAvailable: fprintf(stdout, "not available\n"); break;
- default: fprintf(stdout, "not testable\n"); break;
- }
- if (retVal == CCanApi::IllegalParameter)
- fprintf(stderr, "+++ warning: CAN operation mode not supported (%02x)\n", opMode.byte);
- } else
- fprintf(stdout, "FAILED!\n");
- }
+int CCanDriver::TestCanDevices(CANAPI_OpMode_t opMode) {
+ CCanDriver::SChannelInfo info;
+ int n = 0;
+
+ bool result = CCanDriver::GetFirstChannel(info);
+ while (result) {
+ fprintf(stdout, "Hardware=%s...", info.m_szDeviceName);
+ fflush(stdout);
+ EChannelState state;
+ CANAPI_Return_t retVal = CCanDriver::ProbeChannel(info.m_nChannelNo, opMode, state);
+ if ((retVal == CCanApi::NoError) || (retVal == CCanApi::IllegalParameter)) {
+ CTimer::Delay(333U * CTimer::MSEC); // to fake probing a hardware
+ switch (state) {
+ case CCanApi::ChannelOccupied: fprintf(stdout, "occupied\n"); n++; break;
+ case CCanApi::ChannelAvailable: fprintf(stdout, "available\n"); n++; break;
+ case CCanApi::ChannelNotAvailable: fprintf(stdout, "not available\n"); break;
+ default: fprintf(stdout, "not testable\n"); break;
+ }
+ if (retVal == CCanApi::IllegalParameter)
+ fprintf(stderr, "+++ warning: CAN operation mode not supported (%02xh)\n", opMode.byte);
+ } else
+ fprintf(stdout, "FAILED!\n");
+ result = CCanDriver::GetNextChannel(info);
}
return n;
}
@@ -738,6 +731,8 @@ uint64_t CCanDriver::TransmitterTest(time_t duration, CANAPI_OpMode_t opMode, ui
uint64_t errors = 0;
uint64_t calls = 0;
+ memset(&message, 0, sizeof(CANAPI_Message_t));
+
fprintf(stderr, "\nPress ^C to abort.\n");
message.id = id;
message.xtd = 0;
@@ -800,6 +795,7 @@ uint64_t CCanDriver::TransmitterTest(uint64_t count, CANAPI_OpMode_t opMode, boo
uint64_t calls = 0;
srand((unsigned int)time(NULL));
+ memset(&message, 0, sizeof(CANAPI_Message_t));
fprintf(stderr, "\nPress ^C to abort.\n");
message.id = id;
@@ -1012,5 +1008,5 @@ static void version(FILE *stream, const char *program)
{
fprintf(stdout, "%s\n%s\n\n%s\n\n", APPLICATION, COPYRIGHT, LICENSE);
(void)program;
- fprintf(stream, "Written by Uwe Vogt, UV Software, Berlin \n");
+ fprintf(stream, "Written by Uwe Vogt, UV Software, Berlin \n");
}