Skip to content

Commit

Permalink
Merge pull request #15 from uv-software/development
Browse files Browse the repository at this point in the history
Release candidate 4 for version 0.3
  • Loading branch information
uv-software authored Apr 7, 2024
2 parents 642fac4 + 2a22b90 commit 50fe616
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 53 deletions.
51 changes: 9 additions & 42 deletions Sources/KvaserCAN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
#elif defined(_WIN32)
#define PLATFORM "x86"
#else
#error Unsupported architecture
#error Platform not supported
#endif
static const char version[] = "CAN API V3 for Kvaser CAN Interfaces, Version " VERSION_STRING;

Expand Down Expand Up @@ -95,7 +95,7 @@ static void _finalizer() {
#define STRCPY_S(dest,size,src) strcpy(dest,src)
#define STRNCPY_S(dest,size,src,len) strncpy(dest,src,len)
#define SSCANF_S(buf,format,...) sscanf(buf,format,__VA_ARGS__)
#define SPRINTF_S(buf,size,format,...) sprintf(buf,format,__VA_ARGS__)
#define SPRINTF_S(buf,size,format,...) snprintf(buf,size,format,__VA_ARGS__)
#else
#define STRCPY_S(dest,size,src) strcpy_s(dest,size,src)
#define STRNCPY_S(dest,size,src,len) strncpy_s(dest,size,src,len)
Expand All @@ -106,20 +106,6 @@ static void _finalizer() {
EXPORT
CKvaserCAN::CKvaserCAN() {
m_Handle = -1;
m_OpMode.byte = CANMODE_DEFAULT;
m_Bitrate.index = CANBTR_INDEX_250K;
m_Bitrate.btr.nominal.brp = 0;
m_Bitrate.btr.nominal.tseg1 = 0;
m_Bitrate.btr.nominal.tseg2 = 0;
m_Bitrate.btr.nominal.sjw = 0;
m_Bitrate.btr.nominal.sam = 0;
m_Bitrate.btr.data.brp = m_Bitrate.btr.nominal.brp;
m_Bitrate.btr.data.tseg1 = m_Bitrate.btr.nominal.tseg1;
m_Bitrate.btr.data.tseg2 = m_Bitrate.btr.nominal.tseg2;
m_Bitrate.btr.data.sjw = m_Bitrate.btr.nominal.sjw;
m_Counter.u64TxMessages = 0U;
m_Counter.u64RxMessages = 0U;
m_Counter.u64ErrorFrames = 0U;
}

EXPORT
Expand All @@ -136,7 +122,7 @@ bool CKvaserCAN::GetFirstChannel(SChannelInfo &info, void *param) {
// set index to the first entry in the interface list (if any)
CANAPI_Return_t rc = can_property((-1), CANPROP_SET_FIRST_CHANNEL, NULL, 0U);
if (CANERR_NOERROR == rc) {
// get channel no, device name and device DLL name at actual index in the interface list
// get channel no, device name, etc. at actual index in the interface list
if (((can_property((-1), CANPROP_GET_CHANNEL_NO, (void*)&info.m_nChannelNo, sizeof(int32_t))) == 0) &&
((can_property((-1), CANPROP_GET_CHANNEL_NAME, (void*)&info.m_szDeviceName, CANPROP_MAX_BUFFER_SIZE)) == 0) &&
((can_property((-1), CANPROP_GET_CHANNEL_DLLNAME, (void*)&info.m_szDeviceDllName, CANPROP_MAX_BUFFER_SIZE)) == 0)) {
Expand All @@ -158,7 +144,7 @@ bool CKvaserCAN::GetNextChannel(SChannelInfo &info, void *param) {
// set index to the next entry in the interface list (if any)
CANAPI_Return_t rc = can_property((-1), CANPROP_SET_NEXT_CHANNEL, NULL, 0U);
if (CANERR_NOERROR == rc) {
// get channel no, device name and device DLL name at actual index in the interface list
// get channel no, device name, etc. at actual index in the interface list
if (((can_property((-1), CANPROP_GET_CHANNEL_NO, (void*)&info.m_nChannelNo, sizeof(int32_t))) == 0) &&
((can_property((-1), CANPROP_GET_CHANNEL_NAME, (void*)&info.m_szDeviceName, CANPROP_MAX_BUFFER_SIZE)) == 0) &&
((can_property((-1), CANPROP_GET_CHANNEL_DLLNAME, (void*)&info.m_szDeviceDllName, CANPROP_MAX_BUFFER_SIZE)) == 0)) {
Expand Down Expand Up @@ -194,7 +180,6 @@ CANAPI_Return_t CKvaserCAN::InitializeChannel(int32_t channel, const CANAPI_OpMo
CANAPI_Handle_t hnd = can_init(channel, opMode.byte, param);
if (0 <= hnd) {
m_Handle = hnd; // we got a handle
m_OpMode = opMode;
rc = CANERR_NOERROR;
} else {
rc = (CANAPI_Return_t)hnd;
Expand Down Expand Up @@ -228,12 +213,7 @@ CANAPI_Return_t CKvaserCAN::SignalChannel() {
EXPORT
CANAPI_Return_t CKvaserCAN::StartController(CANAPI_Bitrate_t bitrate) {
// start the CAN controller with the given bit-rate settings
CANAPI_Return_t rc = can_start(m_Handle, &bitrate);
if (CANERR_NOERROR == rc) {
m_Bitrate = bitrate;
memset(&m_Counter, 0, sizeof(m_Counter));
}
return rc;
return can_start(m_Handle, &bitrate);
}

EXPORT
Expand All @@ -245,22 +225,13 @@ CANAPI_Return_t CKvaserCAN::ResetController() {
EXPORT
CANAPI_Return_t CKvaserCAN::WriteMessage(CANAPI_Message_t message, uint16_t timeout) {
// transmit a message over the CAN bus
CANAPI_Return_t rc = can_write(m_Handle, &message, timeout);
if (CANERR_NOERROR == rc) {
m_Counter.u64TxMessages++;
}
return rc;
return can_write(m_Handle, &message, timeout);
}

EXPORT
CANAPI_Return_t CKvaserCAN::ReadMessage(CANAPI_Message_t &message, uint16_t timeout) {
// read one message from the message queue of the CAN interface, if any
CANAPI_Return_t rc = can_read(m_Handle, &message, timeout);
if (CANERR_NOERROR == rc) {
m_Counter.u64RxMessages += !message.sts ? 1U : 0U;
m_Counter.u64ErrorFrames += message.sts ? 1U : 0U;
}
return rc;
return can_read(m_Handle, &message, timeout);
}

EXPORT
Expand All @@ -278,17 +249,13 @@ CANAPI_Return_t CKvaserCAN::GetBusLoad(uint8_t &load) {
EXPORT
CANAPI_Return_t CKvaserCAN::GetBitrate(CANAPI_Bitrate_t &bitrate) {
// retrieve the bit-rate setting of the CAN interface
CANAPI_Return_t rc = can_bitrate(m_Handle, &bitrate, NULL);
if (CANERR_NOERROR == rc) {
m_Bitrate = bitrate;
}
return rc;
return can_bitrate(m_Handle, &bitrate, NULL);
}

EXPORT
CANAPI_Return_t CKvaserCAN::GetBusSpeed(CANAPI_BusSpeed_t &speed) {
// retrieve the transmission rate of the CAN interface
return can_bitrate(m_Handle, &m_Bitrate, &speed);
return can_bitrate(m_Handle, NULL, &speed);
}

EXPORT
Expand Down
7 changes: 0 additions & 7 deletions Sources/KvaserCAN.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,6 @@
class CANCPP CKvaserCAN : public CCanApi {
private:
CANAPI_Handle_t m_Handle; ///< CAN interface handle
CANAPI_OpMode_t m_OpMode; ///< CAN operation mode
CANAPI_Bitrate_t m_Bitrate; ///< CAN bitrate settings
struct {
uint64_t u64TxMessages; ///< number of transmitted CAN messages
uint64_t u64RxMessages; ///< number of received CAN messages
uint64_t u64ErrorFrames; ///< number of received status messages
} m_Counter;
public:
// constructor / destructor
CKvaserCAN();
Expand Down
5 changes: 3 additions & 2 deletions x64_install.bat
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
rem Requires administrator rights!
@echo off
set PWD="%~dp0"
pushd
cd /D %PWD%
copy /Y .\Libraries\CANAPI\x64\Release_dll\u3cankvl.dll C:\Windows\System32
copy /Y .\Libraries\KvaserCAN\x64\Release_dll\uvKvaserCAN.dll C:\Windows\System32
copy /Y .\Binaries\x64\u3cankvl.dll C:\Windows\System32
copy /Y .\Binaries\x64\uvKvaserCAN.dll C:\Windows\System32
popd
dir C:\Windows\System32\u*can*.dll
pause
5 changes: 3 additions & 2 deletions x86_install.bat
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
rem Requires administrator rights!
@echo off
set PWD="%~dp0"
pushd
cd /D %PWD%
copy /Y .\Libraries\CANAPI\Release_dll\u3cankvl.dll C:\Windows\SysWOW64
copy /Y .\Libraries\KvaserCAN\Release_dll\uvKvaserCAN.dll C:\Windows\SysWOW64
copy /Y .\Binaries\x86\u3cankvl.dll C:\Windows\SysWOW64
copy /Y .\Binaries\x86\uvKvaserCAN.dll C:\Windows\SysWOW64
popd
dir C:\Windows\SysWOW64\u*can*.dll
pause

0 comments on commit 50fe616

Please sign in to comment.