Skip to content

Commit

Permalink
Merge pull request #7 from mac-can/development
Browse files Browse the repository at this point in the history
Release candidate 1 for version 0.2.3
  • Loading branch information
mac-can authored Feb 5, 2022
2 parents 58dd221 + 65421a4 commit b9994e5
Show file tree
Hide file tree
Showing 33 changed files with 1,116 additions and 476 deletions.
2 changes: 1 addition & 1 deletion Libraries/CANAPI/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ LIBRARY = libUVCANPCB

MAJOR = 0
MINOR = 2
PATCH = 2
PATCH = 3

VERSION = $(MAJOR).$(MINOR).$(PATCH)
TARGET = $(LIBRARY).$(VERSION).dylib
Expand Down
2 changes: 1 addition & 1 deletion Libraries/PeakCAN/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ LIBRARY = libPeakCAN

MAJOR = 0
MINOR = 2
PATCH = 2
PATCH = 3

VERSION = $(MAJOR).$(MINOR).$(PATCH)
TARGET = $(LIBRARY).$(VERSION).dylib
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
### macOS® Wrapper Library for PCAN-USB Interfaces from Peak-System

_Copyright © 2005-2010, 2012-2022 Uwe Vogt, UV Software, Berlin ([email protected])_
_Copyright © 2005-2010, 2012-2022 Uwe Vogt, UV Software, Berlin ([email protected])_

# CAN API V3 for PCAN-USB Interfaces

Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion Sources/CANAPI/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.svn
.svn/
# we don't use the JSON files yet
can_dev.?
95 changes: 81 additions & 14 deletions Sources/CANAPI/CANAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// CAN Interface API, Version 3 (Interface Definition)
//
// Copyright (c) 2004-2021 Uwe Vogt, UV Software, Berlin ([email protected])
// Copyright (c) 2004-2022 Uwe Vogt, UV Software, Berlin ([email protected])
// All rights reserved.
//
// This file is part of CAN API V3.
Expand Down Expand Up @@ -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
/// \{
Expand Down Expand Up @@ -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!
Expand All @@ -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
Expand Down Expand Up @@ -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'.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 //
40 changes: 20 additions & 20 deletions Sources/CANAPI/CANAPI_Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
* CAN Interface API, Version 3 (Data Types and Defines)
*
* Copyright (c) 2004-2021 Uwe Vogt, UV Software, Berlin ([email protected])
* Copyright (c) 2004-2022 Uwe Vogt, UV Software, Berlin ([email protected])
* All rights reserved.
*
* This file is part of CAN API V3.
Expand Down Expand Up @@ -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
* @{
Expand Down Expand Up @@ -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]) */
Expand All @@ -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) */
Expand Down Expand Up @@ -369,25 +368,26 @@ 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]) */
#define CANPROP_GET_CHANNEL_DLLNAME 244U /**< get file name of the DLL at actual index in the interface list (char[256]) */
#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
/** @} */
Expand Down
2 changes: 1 addition & 1 deletion Sources/CANAPI/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
_Copyright &copy; 2004-2022 Uwe Vogt, UV Software, Berlin ([email protected])_ \
_All rights reserved._

Version $Rev: 1020 $
Version $Rev: 1036 $

# A CAN Interface Wrapper Specification

Expand Down
48 changes: 46 additions & 2 deletions Sources/PeakCAN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) ")"
Expand Down Expand Up @@ -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)
Expand Down
Loading

0 comments on commit b9994e5

Please sign in to comment.