Kvaser J1939 Library
kvj1939lib.h File Reference

Main API for the KVJ1939 Library. More...

#include "kvj1939lib_types.h"

Go to the source code of this file.

Functions

J1939Result j1939_start_log ()
 Start logging to stdout and file "kvj1939lib.log". More...
 
J1939Result j1939_configure_shared_address_table ()
 Configure shared address table size. More...
 
J1939ChannelResult j1939_create_channel (const J1939ChannelParams params)
 Create a J1939 channel. More...
 
J1939Result j1939_destroy_channel (J1939ChannelHandle hnd)
 Destroy a J1939 channel. More...
 
J1939Result j1939_open_channel (J1939ChannelHandle hnd)
 Open a J1939 channel and go on bus. More...
 
J1939Result j1939_close_channel (J1939ChannelHandle hnd)
 Close a J1939 channel and go off bus. More...
 
J1939Result j1939_register_callbacks (J1939ChannelHandle hnd, void *context, J1939RxCallback rx_callback, J1939TxCallback tx_callback, J1939AcCallback ac_callback)
 Set callbacks for a J1939 channel. More...
 
J1939Result j1939_write (J1939ChannelHandle hnd, const J1939WriteParams message)
 Send a J1939 message. More...
 
J1939ReadResult j1939_read (J1939ChannelHandle hnd, uint8_t *buffer, uint32_t buffer_len, int32_t timeout_ms)
 Read a J1939 message. More...
 
J1939Result j1939_claim_address (J1939ChannelHandle hnd, uint8_t address, uint64_t name)
 Claim a J1939 address on the bus. More...
 
J1939Result j1939_remove_address_claim (J1939ChannelHandle hnd, uint8_t address)
 Stop claiming a J1939 address on the bus. More...
 
J1939Result j1939_set_channel_option (J1939ChannelHandle hnd, J1939ChannelOption option, uint32_t value)
 Set a J1939 channel option. More...
 
J1939ChannelOptionResult j1939_get_channel_option (J1939ChannelHandle hnd, J1939ChannelOption option)
 Get the value of a J1939 channel option. More...
 

Detailed Description

Main API for the KVJ1939 Library.

Function Documentation

◆ j1939_claim_address()

J1939Result j1939_claim_address ( J1939ChannelHandle  hnd,
uint8_t  address,
uint64_t  name 
)

Claim a J1939 address on the bus.

This function returns immediately and the outcome of the address claim process is reported via the AC callback function.

Parameters
hndHandle to an open channel
addressThe source address to claim
nameThe unique 64-bit name of the node
Returns
J1939_STATUS_OK on success or an error code on failure
Examples
tp_sender.cpp.

◆ j1939_close_channel()

J1939Result j1939_close_channel ( J1939ChannelHandle  hnd)

Close a J1939 channel and go off bus.

Parameters
hndHandle to the channel to close
Returns
J1939_STATUS_OK on success or an error code on failure
Examples
j1939_logger.c, and tp_sender.cpp.

◆ j1939_configure_shared_address_table()

J1939Result j1939_configure_shared_address_table ( )

Configure shared address table size.

This function must be called before creating any channels. When using a shared address table, the address claims will be allocated per Kvaser CAN channel and multiple applications using the same channel will share the address claim. Up to 16 address claims can be used for the whole system.

Returns
J1939_STATUS_OK on success or an error code on failure

◆ j1939_create_channel()

J1939ChannelResult j1939_create_channel ( const J1939ChannelParams  params)

Create a J1939 channel.

Parameters
paramsParameters for the channel to create
Returns
J1939_STATUS_OK and the channel handle on success or an error code on failure
Examples
j1939_logger.c, and tp_sender.cpp.

◆ j1939_destroy_channel()

J1939Result j1939_destroy_channel ( J1939ChannelHandle  hnd)

Destroy a J1939 channel.

Parameters
hndHandle to the channel to destroy
Returns
J1939_STATUS_OK on success or an error code on failure
Examples
j1939_logger.c, and tp_sender.cpp.

◆ j1939_get_channel_option()

J1939ChannelOptionResult j1939_get_channel_option ( J1939ChannelHandle  hnd,
J1939ChannelOption  option 
)

Get the value of a J1939 channel option.

Parameters
hndHandle to the channel
optionThe option to get
Returns
J1939_STATUS_OK and the value on success or an error code on failure

◆ j1939_open_channel()

J1939Result j1939_open_channel ( J1939ChannelHandle  hnd)

Open a J1939 channel and go on bus.

Parameters
hndHandle to the channel to open
Returns
J1939_STATUS_OK on success or an error code on failure
Examples
j1939_logger.c, and tp_sender.cpp.

◆ j1939_read()

J1939ReadResult j1939_read ( J1939ChannelHandle  hnd,
uint8_t *  buffer,
uint32_t  buffer_len,
int32_t  timeout_ms 
)

Read a J1939 message.

Blocks for up to timeout_ms milliseconds. This method can only be used if callbacks are not configured.

Parameters
hndHandle to the channel
bufferPointer to the message buffer
buffer_lenLength of the message buffer
timeout_msTimeout in milliseconds, -1 for infinite wait
Returns
J1939_STATUS_OK on success or an error code on failure

◆ j1939_register_callbacks()

J1939Result j1939_register_callbacks ( J1939ChannelHandle  hnd,
void *  context,
J1939RxCallback  rx_callback,
J1939TxCallback  tx_callback,
J1939AcCallback  ac_callback 
)

Set callbacks for a J1939 channel.

This function must be called before opening the channel and replaces any previously registered callbacks.

Parameters
hndHandle to the channel
contextUser-defined context pointer passed to callbacks
rx_callbackPointer to the receive callback function
tx_callbackPointer to the transmit ack callback function
ac_callbackPointer to the address claim callback function
Returns
J1939_STATUS_OK on success or an error code on failure
Examples
j1939_logger.c, and tp_sender.cpp.

◆ j1939_remove_address_claim()

J1939Result j1939_remove_address_claim ( J1939ChannelHandle  hnd,
uint8_t  address 
)

Stop claiming a J1939 address on the bus.

Parameters
hndHandle to an open channel
addressThe source address to stop claiming
Returns
J1939_STATUS_OK on success or an error code on failure

◆ j1939_set_channel_option()

J1939Result j1939_set_channel_option ( J1939ChannelHandle  hnd,
J1939ChannelOption  option,
uint32_t  value 
)

Set a J1939 channel option.

Parameters
hndHandle to the channel
optionThe option to set
valueThe value to set for the option
Returns
J1939_STATUS_OK on success or an error code on failure

◆ j1939_start_log()

J1939Result j1939_start_log ( )

Start logging to stdout and file "kvj1939lib.log".

Returns
J1939_STATUS_OK on success or an error code on failure

◆ j1939_write()

J1939Result j1939_write ( J1939ChannelHandle  hnd,
const J1939WriteParams  message 
)

Send a J1939 message.

Parameters
hndHandle to an open channel
messageThe message to send
Returns
J1939_STATUS_OK on success or an error code on failure
Examples
tp_sender.cpp.