Kvaser ISO-TP SDK
Loading...
Searching...
No Matches
kvisotplib_wrapper.h
Go to the documentation of this file.
1
2/*
3 * Copyright 2025 by KVASER AB, SWEDEN
4 *
5 * WWW: https://www.kvaser.com
6 *
7 * This software is furnished under a license and may be used and copied
8 * only in accordance with the terms of such license.
9 *
10 */
11
22#ifndef KVISOTPLIB_WRAPPER_H
23#define KVISOTPLIB_WRAPPER_H
24
25#include <stdexcept>
26#include "kvisotplib.h"
27
34{
35public:
39 IsoTpWrapper() : api{}
40 {
41 // Initialize the API structure
42 ::clear_api(&api);
43 }
44
49 {
50 unload_library(); // Ensure the library is unloaded on destruction
51 }
52
68 bool load_library(const char *lib_path)
69 {
70 api = ::load_library(lib_path);
71 return api.is_valid;
72 }
73
78 {
79 ::unload_library(&api);
80 }
81
89 bool start_log()
90 {
91 if (!api.is_valid || !api.isotp_start_log)
92 throw std::runtime_error("isotp_start_log: Library not loaded or function not found");
93 return api.isotp_start_log();
94 }
95
125 int create(const struct CreateParams *create_params)
126 {
127 if (!api.is_valid || !api.isotp_create)
128 throw std::runtime_error("isotp_create: Library not loaded or function not found");
129 return api.isotp_create(create_params);
130 }
131
156 void destroy(int isotp_handle)
157 {
158 if (!api.is_valid || !api.isotp_destroy)
159 throw std::runtime_error("isotp_destroy: Library not loaded or function not found");
160 return api.isotp_destroy(isotp_handle);
161 }
162
192 bool register_callbacks(int isotp_handle,
193 FFIndicationCallback ff_indication_callback,
194 IndicationCallback indication_callback,
195 ConfirmCallback confirm_callback)
196 {
197 if (!api.is_valid || !api.isotp_register_callbacks)
198 throw std::runtime_error("isotp_register_callbacks: Library not loaded or function not found");
199 return api.isotp_register_callbacks(isotp_handle, ff_indication_callback, indication_callback, confirm_callback);
200 }
201
231 bool set_full_duplex(int isotp_handle, bool value)
232 {
233 if (!api.is_valid || !api.isotp_set_full_duplex)
234 throw std::runtime_error("isotp_set_full_duplex: Library not loaded or function not found");
235 return api.isotp_set_full_duplex(isotp_handle, value);
236 }
237
272 bool set_j1939_priority_masking(int isotp_handle,
273 bool value)
274 {
276 throw std::runtime_error("isotp_set_j1939_priority_masking: Library not loaded or function not found");
277 return api.isotp_set_j1939_priority_masking(isotp_handle, value);
278 }
279
309 bool set_pad_value(int isotp_handle, uint8_t value)
310 {
311 if (!api.is_valid || !api.isotp_set_pad_value)
312 throw std::runtime_error("isotp_set_pad_value: Library not loaded or function not found");
313 return api.isotp_set_pad_value(isotp_handle, value);
314 }
315
345 bool set_block_size(int isotp_handle, uint8_t value)
346 {
347 if (!api.is_valid || !api.isotp_set_block_size)
348 throw std::runtime_error("isotp_set_block_size: Library not loaded or function not found");
349 return api.isotp_set_block_size(isotp_handle, value);
350 }
351
384 bool set_min_separation_time(int isotp_handle,
385 uint8_t value)
386 {
388 throw std::runtime_error("isotp_set_min_separation_time: Library not loaded or function not found");
389 return api.isotp_set_min_separation_time(isotp_handle, value);
390 }
391
424 bool set_block_size_override(int isotp_handle, uint8_t value)
425 {
427 throw std::runtime_error("isotp_set_block_size_override: Library not loaded or function not found");
428 return api.isotp_set_block_size_override(isotp_handle, value);
429 }
430
467 bool set_min_separation_time_override(int isotp_handle, uint8_t value)
468 {
470 throw std::runtime_error("isotp_set_min_separation_time_override: Library not loaded or function not found");
471 return api.isotp_set_min_separation_time_override(isotp_handle, value);
472 }
473
503 bool set_cr_max(int isotp_handle,
504 unsigned int value)
505 {
506 if (!api.is_valid || !api.isotp_set_cr_max)
507 throw std::runtime_error("isotp_set_cr_max: Library not loaded or function not found");
508 return api.isotp_set_cr_max(isotp_handle, value);
509 }
510
540 bool set_a_max(int isotp_handle,
541 unsigned int value)
542 {
543 if (!api.is_valid || !api.isotp_set_a_max)
544 throw std::runtime_error("isotp_set_a_max: Library not loaded or function not found");
545 return api.isotp_set_a_max(isotp_handle, value);
546 }
547
577 bool set_bs_max(int isotp_handle,
578 unsigned int value)
579 {
580 if (!api.is_valid || !api.isotp_set_bs_max)
581 throw std::runtime_error("isotp_set_bs_max: Library not loaded or function not found");
582 return api.isotp_set_bs_max(isotp_handle, value);
583 }
584
614 bool set_wft_max(int isotp_handle,
615 unsigned int value)
616 {
617 if (!api.is_valid || !api.isotp_set_wft_max)
618 throw std::runtime_error("isotp_set_wft_max: Library not loaded or function not found");
619 return api.isotp_set_wft_max(isotp_handle, value);
620 }
621
651 int open(int isotp_handle)
652 {
653 if (!api.is_valid || !api.isotp_open)
654 throw std::runtime_error("isotp_open: Library not loaded or function not found");
655 return api.isotp_open(isotp_handle);
656 }
657
688 int close(int isotp_handle)
689 {
690 if (!api.is_valid || !api.isotp_close)
691 throw std::runtime_error("isotp_close: Library not loaded or function not found");
692 return api.isotp_close(isotp_handle);
693 }
694
742 bool write(int isotp_handle,
743 const struct WriteParams *write_params)
744 {
745 if (!api.is_valid || !api.isotp_write)
746 throw std::runtime_error("isotp_write: Library not loaded or function not found");
747 return api.isotp_write(isotp_handle, write_params);
748 }
749
750private:
751 IsoTpApi api;
752};
753
754#endif // KVISOTPLIB_WRAPPER_H
Wrapper class for loading and using the Kvaser Iso-TP library.
Definition kvisotplib_wrapper.h:34
IsoTpWrapper()
Constructor for the IsoTpWrapper class.
Definition kvisotplib_wrapper.h:39
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
bool set_block_size_override(int isotp_handle, uint8_t value)
Sets the block_size_override settings.
Definition kvisotplib_wrapper.h:424
bool set_min_separation_time(int isotp_handle, uint8_t value)
Sets the min_separation_time settings.
Definition kvisotplib_wrapper.h:384
bool set_block_size(int isotp_handle, uint8_t value)
Sets the block_size settings.
Definition kvisotplib_wrapper.h:345
bool set_pad_value(int isotp_handle, uint8_t value)
Sets the pad_value settings.
Definition kvisotplib_wrapper.h:309
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
void unload_library()
Unload the Kvaser ISO-TP library.
Definition kvisotplib_wrapper.h:77
int create(const struct CreateParams *create_params)
Creates and opens a new ISO-TP channel.
Definition kvisotplib_wrapper.h:125
void destroy(int isotp_handle)
Closes and removes the ISO-TP channel with the specified handle.
Definition kvisotplib_wrapper.h:156
bool start_log()
Starts the logger for the library.
Definition kvisotplib_wrapper.h:89
bool set_a_max(int isotp_handle, unsigned int value)
Sets the a_max settings.
Definition kvisotplib_wrapper.h:540
bool set_wft_max(int isotp_handle, unsigned int value)
Sets the wft_max settings.
Definition kvisotplib_wrapper.h:614
bool set_j1939_priority_masking(int isotp_handle, bool value)
Sets the j1939_priority_masking settings.
Definition kvisotplib_wrapper.h:272
bool load_library(const char *lib_path)
Load the Kvaser ISO-TP library.
Definition kvisotplib_wrapper.h:68
bool set_full_duplex(int isotp_handle, bool value)
Sets the full_duplex settings.
Definition kvisotplib_wrapper.h:231
bool set_min_separation_time_override(int isotp_handle, uint8_t value)
Sets the min_separation_time_override settings.
Definition kvisotplib_wrapper.h:467
bool set_cr_max(int isotp_handle, unsigned int value)
Sets the cr_max settings.
Definition kvisotplib_wrapper.h:503
~IsoTpWrapper()
Destroy the IsoTpWrapper object.
Definition kvisotplib_wrapper.h:48
bool write(int isotp_handle, const struct WriteParams *write_params)
Sends a message.
Definition kvisotplib_wrapper.h:742
bool set_bs_max(int isotp_handle, unsigned int value)
Sets the bs_max settings.
Definition kvisotplib_wrapper.h:577
Kvaser ISO-TP API.
void(WINAPI * FFIndicationCallback)(enum MType m_type, unsigned int can_id, enum TAType ta_type, unsigned char address_extension, unsigned int length, unsigned long long timestamp)
This callback prototype is used for indicating to the upper layers that a FirstFrame (FF) of a segmen...
Definition kvisotplib.h:209
void(WINAPI * ConfirmCallback)(enum MType m_type, unsigned int can_id, enum TAType ta_type, unsigned char address_extension, unsigned long long timestamp, enum NResult result, unsigned int request_handle)
This callback prototype is used for confirming to the upper layers that a write request has been comp...
Definition kvisotplib.h:272
void(WINAPI * IndicationCallback)(enum MType m_type, unsigned int can_id, enum TAType ta_type, unsigned char address_extension, unsigned int length, unsigned long long timestamp, const unsigned char *payload, unsigned int payload_length, enum NResult result)
This callback prototype is used for indicating to the upper layers that a complete message has been r...
Definition kvisotplib.h:240
void clear_api(IsoTpApi *pApi)
Clears the contents of an ISO-TP API structure.
Definition kvisotplib.h:663
A struct that holds the parameters for creating an ISO-TP channel.
Definition kvisotplib.h:132
A struct with all function pointers for the ISO-TP API.
Definition kvisotplib.h:575
isotp_open_t isotp_open
Open the ISO-TP channel.
Definition kvisotplib.h:647
isotp_set_cr_max_t isotp_set_cr_max
Set N_Cr_Max timeout.
Definition kvisotplib.h:631
isotp_set_block_size_override_t isotp_set_block_size_override
Set block size override.
Definition kvisotplib.h:623
isotp_set_block_size_t isotp_set_block_size
Set block size.
Definition kvisotplib.h:615
isotp_destroy_t isotp_destroy
Destroy an existing ISO-TP channel.
Definition kvisotplib.h:595
isotp_start_log_t isotp_start_log
Start logging.
Definition kvisotplib.h:587
isotp_set_full_duplex_t isotp_set_full_duplex
Set full duplex mode.
Definition kvisotplib.h:603
isotp_write_t isotp_write
Write a message to the ISO-TP channel.
Definition kvisotplib.h:655
isotp_set_pad_value_t isotp_set_pad_value
Set padding value.
Definition kvisotplib.h:611
bool is_valid
A flag indicating if the library was successfully loaded and if the API is available.
Definition kvisotplib.h:583
isotp_create_t isotp_create
Create a new ISO-TP channel.
Definition kvisotplib.h:591
isotp_set_wft_max_t isotp_set_wft_max
Set wft_max setting.
Definition kvisotplib.h:643
isotp_set_min_separation_time_override_t isotp_set_min_separation_time_override
Set minimum separation time override.
Definition kvisotplib.h:627
isotp_set_min_separation_time_t isotp_set_min_separation_time
Set minimum separation time.
Definition kvisotplib.h:619
isotp_close_t isotp_close
Close the ISO-TP channel.
Definition kvisotplib.h:651
isotp_register_callbacks_t isotp_register_callbacks
Register callback functions.
Definition kvisotplib.h:599
isotp_set_bs_max_t isotp_set_bs_max
Set N_Bs_Max timeout.
Definition kvisotplib.h:639
isotp_set_j1939_priority_masking_t isotp_set_j1939_priority_masking
Set J1939 priority masking.
Definition kvisotplib.h:607
isotp_set_a_max_t isotp_set_a_max
Set N_As_Max and N_Ar_Max timeout.
Definition kvisotplib.h:635
A struct that holds the parameters for an ISO-TP write request.
Definition kvisotplib.h:160