Skip to content

Commit

Permalink
Merge pull request #4 from uv-software/development
Browse files Browse the repository at this point in the history
Release candidate 2 for version v0.2.1 (service release)
  • Loading branch information
uv-software authored Jan 5, 2022
2 parents 9d04100 + 9ddc1e6 commit c4bb537
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 29 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
### Wrapper Library for Kvaser CAN Interfaces (Windows®)

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

# CAN API V3 for Kvaser CAN Interfaces

Expand Down Expand Up @@ -152,4 +152,4 @@ _If you connect your CAN device to a real CAN network when using this library, y
### Contact
E-Mail: mailto://[email protected] \
Internet: https://www.uv-software.com
Internet: https://www.uv-software.com
4 changes: 2 additions & 2 deletions Sources/CANAPI/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
_Copyright © 2004-2022 Uwe Vogt, UV Software, Berlin ([email protected])_ \
_All rights reserved._

Version $Rev: 1019 $
Version $Rev: 1020 $

# A CAN Interface Wrapper Specification

Expand Down Expand Up @@ -54,7 +54,7 @@ extern int can_bitrate(int handle, can_bitrate_t *bitrate, can_speed_t *speed);
extern int can_property(int handle, uint16_t param, void *value, uint32_t nbyte);

extern char *can_hardware(int handle);
extern char *can_software(int handle);
extern char *can_firmware(int handle);

#if (OPTION_CANAPI_LIBRARY != 0)
extern char *can_library(int handle);
Expand Down
7 changes: 4 additions & 3 deletions Sources/CANAPI/can_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
* CAN Interface API, Version 3 (generic)
*
* 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 @@ -51,7 +51,7 @@
*
* @author $Author: eris $
*
* @version $Rev: 993 $
* @version $Rev: 1020 $
*
* @defgroup can_api CAN Interface API, Version 3
* @{
Expand Down Expand Up @@ -120,6 +120,7 @@ typedef int can_handle_t;
* @{ */
#define can_transmit(hnd, msg) can_write(hnd, msg, 0U)
#define can_receive(hnd, msg) can_read(hnd, msg, 0U)
#define can_software(hnd) can_firmware(hnd)
#define can_msg_t can_message_t
/** @} */

Expand Down Expand Up @@ -445,7 +446,7 @@ CANAPI char *can_hardware(int handle);
*
* @returns pointer to a zero-terminated string, or NULL on error.
*/
CANAPI char *can_software(int handle);
CANAPI char *can_firmware(int handle);


#if (OPTION_CANAPI_LIBRARY != 0)
Expand Down
7 changes: 4 additions & 3 deletions Sources/KvaserCAN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@
#ifdef _MSC_VER
#define VERSION_MAJOR 0
#define VERSION_MINOR 2
#define VERSION_PATCH 99
#define VERSION_PATCH 1
#else
#define VERSION_MAJOR 0
#define VERSION_MINOR 0
#define VERSION_MINOR 2
#define VERSION_PATCH 0
#endif
#define VERSION_BUILD BUILD_NO
Expand Down Expand Up @@ -133,6 +133,7 @@ CKvaserCAN::CKvaserCAN() {

EXPORT
CKvaserCAN::~CKvaserCAN() {
// set CAN contoller into INIT mode and close USB device
(void)TeardownChannel();
}

Expand Down Expand Up @@ -288,7 +289,7 @@ char *CKvaserCAN::GetHardwareVersion() {
EXPORT
char *CKvaserCAN::GetFirmwareVersion() {
// retrieve the firmware version of the CAN controller
return can_software(m_Handle);
return can_firmware(m_Handle);
}

EXPORT
Expand Down
46 changes: 30 additions & 16 deletions Sources/Wrapper/can_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@
#ifdef _MSC_VER
#define VERSION_MAJOR 0
#define VERSION_MINOR 2
#define VERSION_PATCH 99
#define VERSION_PATCH 1
#else
#define VERSION_MAJOR 0
#define VERSION_MINOR 0
#define VERSION_MINOR 2
#define VERSION_PATCH 0
#endif
#define VERSION_BUILD BUILD_NO
Expand Down Expand Up @@ -98,6 +98,9 @@ static const char version[] = "CAN API V3 for Kvaser CAN Interfaces, Version " V
/* ----------- options ------------------------------------------------
*/

#if (OPTION_CAN_2_0_ONLY != 0)
#error Compilation with legacy CAN 2.0 frame format!
#endif

/* ----------- defines ------------------------------------------------
*/
Expand Down Expand Up @@ -685,11 +688,7 @@ int can_read(int handle, can_msg_t *msg, uint16_t timeout)
msg->brs = (flags & canFDMSG_BRS)? 1 : 0;
msg->esi = (flags & canFDMSG_ESI)? 1 : 0;
msg->dlc = (uint8_t)LEN2DLC(len); // unclear: is it a length or a DLC?
#ifndef CAN_20_ONLY
memcpy(msg->data, data, CANFD_MAX_LEN);
#else
memcpy(msg->data, data, CAN_MAX_LEN);
#endif
msg->timestamp.tv_sec = (time_t)(timestamp / 1000ul);
msg->timestamp.tv_nsec = (long)(timestamp % 1000ul) * 1000000l;
can[handle].status.receiver_empty = 0; // message read
Expand Down Expand Up @@ -810,6 +809,8 @@ int can_property(int handle, uint16_t param, void *value, uint32_t nbyte)
char *can_hardware(int handle)
{
static char hardware[256] = ""; // hardware version
char str[256]; // channel name
uint64_t rev; // revision

if (!init) // must be initialized
return NULL;
Expand All @@ -818,25 +819,40 @@ char *can_hardware(int handle)
if (can[handle].handle == canINVALID_HANDLE) // must be an opened handle
return NULL;

if (canGetChannelData(can[handle].channel, canCHANNELDATA_CHANNEL_NAME, hardware, 255) != canOK)
if (canGetChannelData(can[handle].channel, canCHANNELDATA_CHANNEL_NAME, (void*)str, 256) != canOK)
return NULL;
if (canGetChannelData(can[handle].channel, canCHANNELDATA_CARD_HARDWARE_REV, (void*)&rev, sizeof(uint64_t)) != canOK)
return NULL;
snprintf(hardware, 256, "%s, hardware revision %u.%u", str,
(uint16_t)((rev & 0x00000000FFFF0000UL) >> 16),
(uint16_t)((rev & 0x000000000000FFFFUL) >> 0));

return (char*)hardware; // hardware version
}

char *can_software(int handle)
char *can_firmware(int handle)
{
static char software[256] = ""; // software version
unsigned short version; // version number
static char firmware[256] = ""; // firmware version
char str[256]; // channel name
uint64_t rev; // revision

if (!init) // must be initialized
return NULL;
(void)handle; // handle not needed here
if (!IS_HANDLE_VALID(handle)) // must be a valid handle
return NULL;
if (can[handle].handle == canINVALID_HANDLE) // must be an opened handle
return NULL;

version = canGetVersion(); // FIXME: check encoding
snprintf(software, 256, "Kvaser CANlib SDK V%d.%d (canlib32.dll)", (version >> 8), (version & 0xFF));
if (canGetChannelData(can[handle].channel, canCHANNELDATA_CHANNEL_NAME, (void*)str, 256) != canOK)
return NULL;
if (canGetChannelData(can[handle].channel, canCHANNELDATA_CARD_FIRMWARE_REV, (void*)&rev, sizeof(uint64_t)) != canOK)
return NULL;
snprintf(firmware, 256, "%s, firmware version %u.%u.%u", str,
(uint16_t)((rev & 0xFFFF000000000000UL) >> 48),
(uint16_t)((rev & 0x0000FFFF00000000UL) >> 32),
(uint16_t)((rev & 0x00000000FFFF0000UL) >> 16));

return (char*)software; // software version
return (char*)firmware; // firmware version
}

/* ----------- local functions ----------------------------------------
Expand Down Expand Up @@ -997,8 +1013,6 @@ static int map_paramsFd2bitrate(const btr_data_t *busParams, long frequency, can
static int lib_parameter(uint16_t param, void *value, size_t nbyte)
{
int rc = CANERR_ILLPARA; // suppose an invalid parameter
// int i = 0; // one always needs an i

static int idx_board = EOF; // actual index in the interface list

if (value == NULL) { // check for null-pointer
Expand Down
2 changes: 1 addition & 1 deletion Trial/Sources/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ int main(int argc, const char * argv[]) {
retVal = myDriver.GetProperty(CANPROP_GET_CHANNEL_NO, (void *)&i32Val, sizeof(int32_t));
if (retVal == CCanApi::NoError) {
retVal = CKvaserCAN::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");
Expand Down
2 changes: 1 addition & 1 deletion Utilities/can_moni/Sources/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -985,5 +985,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 <http://www.uv-software.com/>\n");
fprintf(stream, "Written by Uwe Vogt, UV Software, Berlin <https://uv-software.com/>\n");
}
2 changes: 1 addition & 1 deletion Utilities/can_test/Sources/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1198,5 +1198,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 <http://www.uv-software.com/>\n");
fprintf(stream, "Written by Uwe Vogt, UV Software, Berlin <https://uv-software.com/>\n");
}

0 comments on commit c4bb537

Please sign in to comment.