Kvaser ISO-TP SDK
Loading...
Searching...
No Matches
IsoTpWrapper Class Reference

Wrapper class for loading and using the Kvaser Iso-TP library. More...

#include <kvisotplib_wrapper.h>

Public Member Functions

 IsoTpWrapper ()
 Constructor for the IsoTpWrapper class.
 
 ~IsoTpWrapper ()
 Destroy the IsoTpWrapper object.
 
bool load_library (const char *lib_path)
 Load the Kvaser ISO-TP library.
 
void unload_library ()
 Unload the Kvaser ISO-TP library.
 
bool start_log ()
 Starts the logger for the library.
 
int create (const struct CreateParams *create_params)
 Creates and opens a new ISO-TP channel.
 
void destroy (int isotp_handle)
 Closes and removes the ISO-TP channel with the specified handle.
 
bool register_callbacks (int isotp_handle, FFIndicationCallback ff_indication_callback, IndicationCallback indication_callback, ConfirmCallback confirm_callback)
 Registers callback functions to be used by the ISO-TP channel to inform the upper layers on events.
 
bool set_full_duplex (int isotp_handle, bool value)
 Sets the full_duplex settings.
 
bool set_j1939_priority_masking (int isotp_handle, bool value)
 Sets the j1939_priority_masking settings.
 
bool set_pad_value (int isotp_handle, uint8_t value)
 Sets the pad_value settings.
 
bool set_block_size (int isotp_handle, uint8_t value)
 Sets the block_size settings.
 
bool set_min_separation_time (int isotp_handle, uint8_t value)
 Sets the min_separation_time settings.
 
bool set_block_size_override (int isotp_handle, uint8_t value)
 Sets the block_size_override settings.
 
bool set_min_separation_time_override (int isotp_handle, uint8_t value)
 Sets the min_separation_time_override settings.
 
bool set_cr_max (int isotp_handle, unsigned int value)
 Sets the cr_max settings.
 
bool set_a_max (int isotp_handle, unsigned int value)
 Sets the a_max settings.
 
bool set_bs_max (int isotp_handle, unsigned int value)
 Sets the bs_max settings.
 
bool set_wft_max (int isotp_handle, unsigned int value)
 Sets the wft_max settings.
 
int open (int isotp_handle)
 Opens the specified ISO-TP channel and takes its CAN channel bus-on.
 
int close (int isotp_handle)
 Closes this channel and takes its CAN channel off-bus.
 
bool write (int isotp_handle, const struct WriteParams *write_params)
 Sends a message.
 

Detailed Description

Wrapper class for loading and using the Kvaser Iso-TP library.

This class handles loading the library, unloading it, and providing access to its functions.

Examples
/examples/cpp_obd_reader/obd_reader.cpp.

Member Function Documentation

◆ close()

int IsoTpWrapper::close ( int  isotp_handle)
inline

Closes this channel and takes its CAN channel off-bus.

Parameters
isotp_handleThe handle to the ISO-TP channel.
Returns
Zero if success, or an error code if failure.
Code Snippet:
// Use the Kvaser ISO-TP Wrapper to load the library and create a channel.
isotp.load_library("kvisotplib.dll");
CreateParams create_params = {
0, // channel
CanMode::Can,
true, // support_virtual
500000, // bit_rate
0, // data_phase_bit_rate
false, // block_standard_ids
false // block_extended_ids
};
int handle = isotp.create(&create_params);
isotp.open(handle);
int result = isotp.close(handle);
if (result != 0) {
std::cerr << "Failed to close ISO-TP channel!" << std::endl;
}
Wrapper class for loading and using the Kvaser Iso-TP library.
Definition kvisotplib_wrapper.h:34
int close(int isotp_handle)
Closes this channel and takes its CAN channel off-bus.
Definition kvisotplib_wrapper.h:688
int open(int isotp_handle)
Opens the specified ISO-TP channel and takes its CAN channel bus-on.
Definition kvisotplib_wrapper.h:651
int create(const struct CreateParams *create_params)
Creates and opens a new ISO-TP channel.
Definition kvisotplib_wrapper.h:125
bool load_library(const char *lib_path)
Load the Kvaser ISO-TP library.
Definition kvisotplib_wrapper.h:68
Kvaser ISO-TP C++ Wrapper.
A struct that holds the parameters for creating an ISO-TP channel.
Definition kvisotplib.h:132
Examples
/examples/cpp_obd_reader/obd_reader.cpp.

◆ create()

int IsoTpWrapper::create ( const struct CreateParams *  create_params)
inline

Creates and opens a new ISO-TP channel.

Parameters
create_paramsThe parameters for creating the ISO-TP channel.
Returns
The ISO-TP handle to be used in subsequent calls to this API.
Code Snippet:
// Use the Kvaser ISO-TP Wrapper to load the library and create a channel.
isotp.load_library("kvisotplib.dll");
CreateParams create_params = {
0, // channel
CanMode::Can,
true, // support_virtual
500000, // bit_rate
0, // data_phase_bit_rate
false, // block_standard_ids
false // block_extended_ids
};
int handle = isotp.create(&create_params);
if (handle < 0) {
std::cerr << "Failed to create ISO-TP channel!" << std::endl;
return;
}
Examples
/examples/cpp_obd_reader/obd_reader.cpp.

◆ destroy()

void IsoTpWrapper::destroy ( int  isotp_handle)
inline

Closes and removes the ISO-TP channel with the specified handle.

Parameters
isotp_handleThe handle to the ISO-TP channel to be removed.
Code Snippet:
// Use the Kvaser ISO-TP Wrapper to load the library and create a channel.
isotp.load_library("kvisotplib.dll");
CreateParams create_params = {
0, // channel
CanMode::Can,
true, // support_virtual
500000, // bit_rate
0, // data_phase_bit_rate
false, // block_standard_ids
false // block_extended_ids
};
int handle = isotp.create(&create_params);
isotp.destroy(handle);
void destroy(int isotp_handle)
Closes and removes the ISO-TP channel with the specified handle.
Definition kvisotplib_wrapper.h:156
Examples
/examples/cpp_obd_reader/obd_reader.cpp.

◆ load_library()

bool IsoTpWrapper::load_library ( const char *  lib_path)
inline

Load the Kvaser ISO-TP library.

Parameters
lib_pathThe path to the library file. Pass NULL to use default names, "kvisotplib.dll" on Windows and "libkvisotplib.so" on Linux.
Returns
True if the library was loaded successfully; otherwise false.
Code Snippet:
// Use the Kvaser ISO-TP Wrapper to load the library and create a channel.
isotp.load_library("kvisotplib.dll");
Examples
/examples/cpp_obd_reader/obd_reader.cpp.

◆ open()

int IsoTpWrapper::open ( int  isotp_handle)
inline

Opens the specified ISO-TP channel and takes its CAN channel bus-on.

Parameters
isotp_handleThe handle to the ISO-TP channel.
Returns
Zero if success, or an error code if failure.
Code Snippet:
// Use the Kvaser ISO-TP Wrapper to load the library and create a channel.
isotp.load_library("kvisotplib.dll");
CreateParams create_params = {
0, // channel
CanMode::Can,
true, // support_virtual
500000, // bit_rate
0, // data_phase_bit_rate
false, // block_standard_ids
false // block_extended_ids
};
int handle = isotp.create(&create_params);
int result = isotp.open(handle);
if (result != 0) {
std::cerr << "Failed to open ISO-TP channel!" << std::endl;
}
Examples
/examples/cpp_obd_reader/obd_reader.cpp.

◆ register_callbacks()

bool IsoTpWrapper::register_callbacks ( int  isotp_handle,
FFIndicationCallback  ff_indication_callback,
IndicationCallback  indication_callback,
ConfirmCallback  confirm_callback 
)
inline

Registers callback functions to be used by the ISO-TP channel to inform the upper layers on events.

Parameters
isotp_handleThe handle to the ISO-TP channel to add callbacks to.
ff_indication_callbackThe FirstFrame (FF) indication callback.
indication_callbackThe message received indication callback.
confirm_callbackThe message transmitted confirmation callback.
Returns
True if succeeded; otherwise false.
Code Snippet:
// Use the Kvaser ISO-TP Wrapper to load the library and create a channel.
isotp.load_library("kvisotplib.dll");
CreateParams create_params = {
0, // channel
CanMode::Can,
true, // support_virtual
500000, // bit_rate
0, // data_phase_bit_rate
false, // block_standard_ids
false // block_extended_ids
};
int handle = isotp.create(&create_params);
isotp.register_callbacks(handle, ff_indication_callback, indication_callback, confirm_callback);
bool register_callbacks(int isotp_handle, FFIndicationCallback ff_indication_callback, IndicationCallback indication_callback, ConfirmCallback confirm_callback)
Registers callback functions to be used by the ISO-TP channel to inform the upper layers on events.
Definition kvisotplib_wrapper.h:192
Examples
/examples/cpp_obd_reader/obd_reader.cpp.

◆ set_a_max()

bool IsoTpWrapper::set_a_max ( int  isotp_handle,
unsigned int  value 
)
inline

Sets the a_max settings.

Max time allowed between a request and its confirmation, N_As_Max and N_Ar_Max. Specified as milliseconds.

Parameters
isotp_handleThe handle to the ISO-TP channel.
valueThe new value.
Returns
True if succeeded; otherwise false.
Code Snippet:
// Use the Kvaser ISO-TP Wrapper to load the library and create a channel.
isotp.load_library("kvisotplib.dll");
CreateParams create_params = {
0, // channel
CanMode::Can,
true, // support_virtual
500000, // bit_rate
0, // data_phase_bit_rate
false, // block_standard_ids
false // block_extended_ids
};
int handle = isotp.create(&create_params);
if (!isotp.set_a_max(handle, 1000)) {
std::cerr << "Failed to set a_max!" << std::endl;
}
bool set_a_max(int isotp_handle, unsigned int value)
Sets the a_max settings.
Definition kvisotplib_wrapper.h:540

◆ set_block_size()

bool IsoTpWrapper::set_block_size ( int  isotp_handle,
uint8_t  value 
)
inline

Sets the block_size settings.

Parameters
isotp_handleThe handle to the ISO-TP channel.
valueThe new value.
Returns
True if succeeded; otherwise false.
Code Snippet:
// Use the Kvaser ISO-TP Wrapper to load the library and create a channel.
isotp.load_library("kvisotplib.dll");
CreateParams create_params = {
0, // channel
CanMode::Can,
true, // support_virtual
500000, // bit_rate
0, // data_phase_bit_rate
false, // block_standard_ids
false // block_extended_ids
};
int handle = isotp.create(&create_params);
if (!isotp.set_block_size(handle, 128)) {
std::cerr << "Failed to set block size!" << std::endl;
}
bool set_block_size(int isotp_handle, uint8_t value)
Sets the block_size settings.
Definition kvisotplib_wrapper.h:345

◆ set_block_size_override()

bool IsoTpWrapper::set_block_size_override ( int  isotp_handle,
uint8_t  value 
)
inline

Sets the block_size_override settings.

An optional block size override. If set, then this value will be used instead of the value specified in the flow control frame.

Parameters
isotp_handleThe handle to the ISO-TP channel.
valueThe new value.
Returns
True if succeeded; otherwise false.
Code Snippet:
// Use the Kvaser ISO-TP Wrapper to load the library and create a channel.
isotp.load_library("kvisotplib.dll");
CreateParams create_params = {
0, // channel
CanMode::Can,
true, // support_virtual
500000, // bit_rate
0, // data_phase_bit_rate
false, // block_standard_ids
false // block_extended_ids
};
int handle = isotp.create(&create_params);
if (!isotp.set_block_size_override(handle, 0x0A)) {
std::cerr << "Failed to set block size override!" << std::endl;
}
bool set_block_size_override(int isotp_handle, uint8_t value)
Sets the block_size_override settings.
Definition kvisotplib_wrapper.h:424

◆ set_bs_max()

bool IsoTpWrapper::set_bs_max ( int  isotp_handle,
unsigned int  value 
)
inline

Sets the bs_max settings.

Max allowed time until reception of next flow control frame, N_Bs_Max. Specified as milliseconds.

Parameters
isotp_handleThe handle to the ISO-TP channel.
valueThe new value.
Returns
True if succeeded; otherwise false.
Code Snippet:
// Use the Kvaser ISO-TP Wrapper to load the library and create a channel.
isotp.load_library("kvisotplib.dll");
CreateParams create_params = {
0, // channel
CanMode::Can,
true, // support_virtual
500000, // bit_rate
0, // data_phase_bit_rate
false, // block_standard_ids
false // block_extended_ids
};
int handle = isotp.create(&create_params);
if (!isotp.set_bs_max(handle, 1000)) {
std::cerr << "Failed to set bs_max!" << std::endl;
}
bool set_bs_max(int isotp_handle, unsigned int value)
Sets the bs_max settings.
Definition kvisotplib_wrapper.h:577

◆ set_cr_max()

bool IsoTpWrapper::set_cr_max ( int  isotp_handle,
unsigned int  value 
)
inline

Sets the cr_max settings.

Max allowed time until reception of the next consecutive frame, N_Cr_Max. Specified as milliseconds.

Parameters
isotp_handleThe handle to the ISO-TP channel.
valueThe new value.
Returns
True if succeeded; otherwise false.
Code Snippet:
// Use the Kvaser ISO-TP Wrapper to load the library and create a channel.
isotp.load_library("kvisotplib.dll");
CreateParams create_params = {
0, // channel
CanMode::Can,
true, // support_virtual
500000, // bit_rate
0, // data_phase_bit_rate
false, // block_standard_ids
false // block_extended_ids
};
int handle = isotp.create(&create_params);
if (!isotp.set_cr_max(handle, 1000)) {
std::cerr << "Failed to set cr_max!" << std::endl;
}
bool set_cr_max(int isotp_handle, unsigned int value)
Sets the cr_max settings.
Definition kvisotplib_wrapper.h:503

◆ set_full_duplex()

bool IsoTpWrapper::set_full_duplex ( int  isotp_handle,
bool  value 
)
inline

Sets the full_duplex settings.

True if full duplex is used.

Parameters
isotp_handleThe handle to the ISO-TP channel.
valueThe new value.
Returns
True if succeeded; otherwise false.
Code Snippet:
// Use the Kvaser ISO-TP Wrapper to load the library and create a channel.
isotp.load_library("kvisotplib.dll");
CreateParams create_params = {
0, // channel
CanMode::Can,
true, // support_virtual
500000, // bit_rate
0, // data_phase_bit_rate
false, // block_standard_ids
false // block_extended_ids
};
int handle = isotp.create(&create_params);
if (!isotp.set_full_duplex(handle, true)) {
std::cerr << "Failed to set full duplex!" << std::endl;
}
bool set_full_duplex(int isotp_handle, bool value)
Sets the full_duplex settings.
Definition kvisotplib_wrapper.h:231

◆ set_j1939_priority_masking()

bool IsoTpWrapper::set_j1939_priority_masking ( int  isotp_handle,
bool  value 
)
inline

Sets the j1939_priority_masking settings.

When this flag is set, the J1939 priority bits (28-26 of the CAN ID) shall be masked on all received messages. The priority bits shall be masked on all received ISO 15765 flow control messages and will be ignored if they are included in the LocalAddressInfo. However, transmitted ISO 15765 flow control messages shall include any priority bits set in the RemoteAddressInfo structure.

Parameters
isotp_handleThe handle to the ISO-TP channel.
valueThe new value.
Returns
True if succeeded; otherwise false.
Code Snippet:
// Use the Kvaser ISO-TP Wrapper to load the library and create a channel.
isotp.load_library("kvisotplib.dll");
CreateParams create_params = {
0, // channel
CanMode::Can,
true, // support_virtual
500000, // bit_rate
0, // data_phase_bit_rate
false, // block_standard_ids
false // block_extended_ids
};
int handle = isotp.create(&create_params);
if (!isotp.set_j1939_priority_masking(handle, true)) {
std::cerr << "Failed to set J1939 priority masking!" << std::endl;
}
bool set_j1939_priority_masking(int isotp_handle, bool value)
Sets the j1939_priority_masking settings.
Definition kvisotplib_wrapper.h:272

◆ set_min_separation_time()

bool IsoTpWrapper::set_min_separation_time ( int  isotp_handle,
uint8_t  value 
)
inline

Sets the min_separation_time settings.

This value is coded according to ISO 15765-2, 0x00 to 0x7F is 0 to 127 milliseconds, 0xF1 to 0xF9 is 100 to 900 microseconds, all other values will be interpreted as 127 milliseconds.

Parameters
isotp_handleThe handle to the ISO-TP channel.
valueThe new value.
Returns
True if succeeded; otherwise false.
Code Snippet:
// Use the Kvaser ISO-TP Wrapper to load the library and create a channel.
isotp.load_library("kvisotplib.dll");
CreateParams create_params = {
0, // channel
CanMode::Can,
true, // support_virtual
500000, // bit_rate
0, // data_phase_bit_rate
false, // block_standard_ids
false // block_extended_ids
};
int handle = isotp.create(&create_params);
if (!isotp.set_min_separation_time(handle, 100)) {
std::cerr << "Failed to set min separation time!" << std::endl;
}
bool set_min_separation_time(int isotp_handle, uint8_t value)
Sets the min_separation_time settings.
Definition kvisotplib_wrapper.h:384

◆ set_min_separation_time_override()

bool IsoTpWrapper::set_min_separation_time_override ( int  isotp_handle,
uint8_t  value 
)
inline

Sets the min_separation_time_override settings.

An optional minimum separation time override. If set, then this value will be used instead of the value specified in the flow control frame.

  • If this value is <= 0x7F then it is specified as milliseconds.
  • If this value is >= 0xF1 and <= 0xF9 then it is specified as a multiple of 100 microseconds.
  • All other values are invalid and will result in a separation time of 127 milliseconds.
Parameters
isotp_handleThe handle to the ISO-TP channel.
valueThe new value.
Returns
True if succeeded; otherwise false.
Code Snippet:
// Use the Kvaser ISO-TP Wrapper to load the library and create a channel.
isotp.load_library("kvisotplib.dll");
CreateParams create_params = {
0, // channel
CanMode::Can,
true, // support_virtual
500000, // bit_rate
0, // data_phase_bit_rate
false, // block_standard_ids
false // block_extended_ids
};
int handle = isotp.create(&create_params);
if (!isotp.set_min_separation_time_override(handle, 0x64)) {
std::cerr << "Failed to set min separation time override!" << std::endl;
}
bool set_min_separation_time_override(int isotp_handle, uint8_t value)
Sets the min_separation_time_override settings.
Definition kvisotplib_wrapper.h:467

◆ set_pad_value()

bool IsoTpWrapper::set_pad_value ( int  isotp_handle,
uint8_t  value 
)
inline

Sets the pad_value settings.

The value to be used when padding messages.

Parameters
isotp_handleThe handle to the ISO-TP channel.
valueThe new value.
Returns
True if succeeded; otherwise false.
Code Snippet:
// Use the Kvaser ISO-TP Wrapper to load the library and create a channel.
isotp.load_library("kvisotplib.dll");
CreateParams create_params = {
0, // channel
CanMode::Can,
true, // support_virtual
500000, // bit_rate
0, // data_phase_bit_rate
false, // block_standard_ids
false // block_extended_ids
};
int handle = isotp.create(&create_params);
if (!isotp.set_pad_value(handle, 0xFF)) {
std::cerr << "Failed to set pad value!" << std::endl;
}
bool set_pad_value(int isotp_handle, uint8_t value)
Sets the pad_value settings.
Definition kvisotplib_wrapper.h:309

◆ set_wft_max()

bool IsoTpWrapper::set_wft_max ( int  isotp_handle,
unsigned int  value 
)
inline

Sets the wft_max settings.

Max number of FC.WAIT frames that can be sent in a row. If set to 0, then there is no limit.

Parameters
isotp_handleThe handle to the ISO-TP channel.
valueThe new value.
Returns
True if succeeded; otherwise false.
Code Snippet:
// Use the Kvaser ISO-TP Wrapper to load the library and create a channel.
isotp.load_library("kvisotplib.dll");
CreateParams create_params = {
0, // channel
CanMode::Can,
true, // support_virtual
500000, // bit_rate
0, // data_phase_bit_rate
false, // block_standard_ids
false // block_extended_ids
};
int handle = isotp.create(&create_params);
if (!isotp.set_wft_max(handle, 10)) {
std::cerr << "Failed to set wft_max!" << std::endl;
}
bool set_wft_max(int isotp_handle, unsigned int value)
Sets the wft_max settings.
Definition kvisotplib_wrapper.h:614

◆ start_log()

bool IsoTpWrapper::start_log ( )
inline

Starts the logger for the library.

This function configures the logger to log messages to both the console and a file named kvisotplib.log.

Returns
True if succeeded; otherwise false.

◆ write()

bool IsoTpWrapper::write ( int  isotp_handle,
const struct WriteParams *  write_params 
)
inline

Sends a message.

The call returns immediately after queuing the message to the driver, so the message has not necessarily been transmitted.

Note
The message has been queued for transmission when this call returns. It has not necessarily been sent.
The Confirm callback will be called when the message has been sent.
Parameters
isotp_handleThe handle to the ISO-TP channel.
write_paramsThe parameters containing the message to send.
Returns
True if succeeded; otherwise false.
Code Snippet:
// Use the Kvaser ISO-TP Wrapper to load the library and create a channel.
isotp.load_library("kvisotplib.dll");
CreateParams create_params = {
0, // channel
CanMode::Can,
true, // support_virtual
500000, // bit_rate
0, // data_phase_bit_rate
false, // block_standard_ids
false // block_extended_ids
};
int handle = isotp.create(&create_params);
unsigned char data[] = {1, 2, 3, 4};
WriteParams write_params = {
MType::Diagnostics, // Message type
0x7E0, // CAN ID
TAType::PhysicalCanStandard, // TAType
0, // Address extension
data, // Data payload
sizeof(data), // Data length
use_padding, // Use padding
use_bit_rate_switch, // Use bit rate switch
1 // Request handle (for confirmation)
};
if (!isotp.write(handle, &write_params)) {
std::cerr << "Failed to write data!" << std::endl;
}
bool write(int isotp_handle, const struct WriteParams *write_params)
Sends a message.
Definition kvisotplib_wrapper.h:742
A struct that holds the parameters for an ISO-TP write request.
Definition kvisotplib.h:160
Examples
/examples/cpp_obd_reader/obd_reader.cpp.

The documentation for this class was generated from the following file: