Skip to content

Commit

Permalink
Merge pull request #16 from uv-software/development
Browse files Browse the repository at this point in the history
Release candidate 4 for version 0,5
  • Loading branch information
uv-software authored Apr 7, 2024
2 parents 11cc7ce + d1eddc0 commit 2d646ea
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 51 deletions.
47 changes: 7 additions & 40 deletions Sources/PeakCAN.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 Peak-System PCAN 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
CPeakCAN::CPeakCAN() {
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 Down Expand Up @@ -194,7 +180,6 @@ CANAPI_Return_t CPeakCAN::InitializeChannel(int32_t channel, const CANAPI_OpMode
CANAPI_Handle_t hnd = can_init(channel, opMode.byte, param);
if (0 <= hnd) {
m_Handle = hnd; // we got a handle
m_OpMode = opMode;
rc = CANERR_NOERROR;
} else {
rc = (CANAPI_Return_t)hnd;
Expand Down Expand Up @@ -228,12 +213,7 @@ CANAPI_Return_t CPeakCAN::SignalChannel() {
EXPORT
CANAPI_Return_t CPeakCAN::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 CPeakCAN::ResetController() {
EXPORT
CANAPI_Return_t CPeakCAN::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 CPeakCAN::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 CPeakCAN::GetBusLoad(uint8_t &load) {
EXPORT
CANAPI_Return_t CPeakCAN::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 CPeakCAN::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/PeakCAN.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,6 @@
class CANCPP CPeakCAN : 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
CPeakCAN();
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\u3canpcb.dll C:\Windows\System32
copy /Y .\Libraries\PeakCAN\x64\Release_dll\uvPeakCAN.dll C:\Windows\System32
copy /Y .\Binaries\x64\u3canpcb.dll C:\Windows\System32
copy /Y .\Binaries\x64\uvPeakCAN.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\u3canpcb.dll C:\Windows\SysWOW64
copy /Y .\Libraries\PeakCAN\Release_dll\uvPeakCAN.dll C:\Windows\SysWOW64
copy /Y .\Binaries\x86\u3canpcb.dll C:\Windows\SysWOW64
copy /Y .\Binaries\x86\uvPeakCAN.dll C:\Windows\SysWOW64
popd
dir C:\Windows\SysWOW64\u*can*.dll
pause

0 comments on commit 2d646ea

Please sign in to comment.