ISOTP-C
A platform-agnostic ISOTP implementation in C.
|
#include <stdio.h>
#include <string.h>
#include "isotp_defines.h"
#include "isotp_config.h"
#include "isotp_user.h"
Go to the source code of this file.
Data Structures | |
struct | IsoTpLink |
Struct containing the data for linking an application to a CAN instance. The data stored in this struct is used internally and may be used by software programs using this library. More... | |
Typedefs | |
typedef struct IsoTpLink | IsoTpLink |
Struct containing the data for linking an application to a CAN instance. The data stored in this struct is used internally and may be used by software programs using this library. More... | |
Functions | |
void | isotp_init_link (IsoTpLink *link, uint32_t sendid, uint8_t *sendbuf, uint16_t sendbufsize, uint8_t *recvbuf, uint16_t recvbufsize) |
Initialises the ISO-TP library. More... | |
void | isotp_poll (IsoTpLink *link) |
Polling function; call this function periodically to handle timeouts, send consecutive frames, etc. More... | |
void | isotp_on_can_message (IsoTpLink *link, uint8_t *data, uint8_t len) |
Handles incoming CAN messages. Determines whether an incoming message is a valid ISO-TP frame or not and handles it accordingly. More... | |
int | isotp_send (IsoTpLink *link, const uint8_t payload[], uint16_t size) |
Sends ISO-TP frames via CAN, using the ID set in the initialising function. More... | |
int | isotp_send_with_id (IsoTpLink *link, uint32_t id, const uint8_t payload[], uint16_t size) |
See isotp_send, with the exception that this function is used only for functional addressing. More... | |
int | isotp_receive (IsoTpLink *link, uint8_t *payload, const uint16_t payload_size, uint16_t *out_size) |
Receives and parses the received data and copies the parsed data in to the internal buffer. More... | |
Struct containing the data for linking an application to a CAN instance. The data stored in this struct is used internally and may be used by software programs using this library.
void isotp_init_link | ( | IsoTpLink * | link, |
uint32_t | sendid, | ||
uint8_t * | sendbuf, | ||
uint16_t | sendbufsize, | ||
uint8_t * | recvbuf, | ||
uint16_t | recvbufsize | ||
) |
Initialises the ISO-TP library.
link | The Struct containing the data for linking an application to a CAN instance. The data stored in this stru... Definition: isotp.h:22 |
sendid | The ID used to send data to other CAN nodes. |
sendbuf | A pointer to an area in memory which can be used as a buffer for data to be sent. |
sendbufsize | The size of the buffer area. |
recvbuf | A pointer to an area in memory which can be used as a buffer for data to be received. |
recvbufsize | The size of the buffer area. |
Definition at line 450 of file isotp.c.
References ISOTP_RECEIVE_STATUS_IDLE, ISOTP_SEND_STATUS_IDLE, IsoTpLink::receive_buf_size, IsoTpLink::receive_buffer, IsoTpLink::receive_status, IsoTpLink::send_arbitration_id, IsoTpLink::send_buf_size, IsoTpLink::send_buffer, and IsoTpLink::send_status.
void isotp_on_can_message | ( | IsoTpLink * | link, |
uint8_t * | data, | ||
uint8_t | len | ||
) |
Handles incoming CAN messages. Determines whether an incoming message is a valid ISO-TP frame or not and handles it accordingly.
link | The instance used for transceiving data. |
data | The data received via CAN. |
len | The length of the data received. |
Definition at line 281 of file isotp.c.
References IsoTpCanMessage::common, IsoTpCanMessage::data_array, IsoTpCanMessage::flow_control, ISOTP_PCI_TYPE_FIRST_FRAME, ISOTP_PCI_TYPE_FLOW_CONTROL_FRAME, ISOTP_PCI_TYPE_SINGLE, isotp_receive_consecutive_frame(), isotp_receive_first_frame(), isotp_receive_flow_control_frame(), isotp_receive_single_frame(), ISOTP_RECEIVE_STATUS_FULL, ISOTP_RECEIVE_STATUS_IDLE, ISOTP_RECEIVE_STATUS_INPROGRESS, isotp_send_flow_control(), ISOTP_SEND_STATUS_ERROR, ISOTP_SEND_STATUS_INPROGRESS, isotp_st_min_to_us(), isotp_user_get_us(), PCI_FLOW_STATUS_CONTINUE, PCI_FLOW_STATUS_OVERFLOW, PCI_FLOW_STATUS_WAIT, IsoTpDataArray::ptr, IsoTpLink::receive_bs_count, IsoTpLink::receive_offset, IsoTpLink::receive_protocol_result, IsoTpLink::receive_size, IsoTpLink::receive_status, IsoTpLink::receive_timer_cr, IsoTpLink::send_bs_remain, IsoTpLink::send_protocol_result, IsoTpLink::send_st_min_us, IsoTpLink::send_status, IsoTpLink::send_timer_bs, IsoTpLink::send_wtf_count, and TSOTP_PCI_TYPE_CONSECUTIVE_FRAME.
void isotp_poll | ( | IsoTpLink * | link | ) |
Polling function; call this function periodically to handle timeouts, send consecutive frames, etc.
link | The instance used. |
Definition at line 463 of file isotp.c.
References ISOTP_RECEIVE_STATUS_IDLE, ISOTP_RECEIVE_STATUS_INPROGRESS, isotp_send_consecutive_frame(), ISOTP_SEND_STATUS_ERROR, ISOTP_SEND_STATUS_IDLE, ISOTP_SEND_STATUS_INPROGRESS, isotp_user_get_us(), IsoTpLink::receive_protocol_result, IsoTpLink::receive_status, IsoTpLink::receive_timer_cr, IsoTpLink::send_bs_remain, IsoTpLink::send_offset, IsoTpLink::send_protocol_result, IsoTpLink::send_size, IsoTpLink::send_st_min_us, IsoTpLink::send_status, IsoTpLink::send_timer_bs, and IsoTpLink::send_timer_st.
int isotp_receive | ( | IsoTpLink * | link, |
uint8_t * | payload, | ||
const uint16_t | payload_size, | ||
uint16_t * | out_size | ||
) |
Receives and parses the received data and copies the parsed data in to the internal buffer.
link | The IsoTpLink instance used to transceive data. |
payload | A pointer to an area in memory where the raw data is copied from. |
payload_size | The size of the received (raw) CAN data. |
out_size | A reference to a variable which will contain the size of the actual (parsed) data. |
Definition at line 430 of file isotp.c.
References ISOTP_RECEIVE_STATUS_FULL, ISOTP_RECEIVE_STATUS_IDLE, IsoTpLink::receive_buffer, IsoTpLink::receive_size, and IsoTpLink::receive_status.
int isotp_send | ( | IsoTpLink * | link, |
const uint8_t | payload[], | ||
uint16_t | size | ||
) |
Sends ISO-TP frames via CAN, using the ID set in the initialising function.
Single-frame messages will be sent immediately when calling this function. Multi-frame messages will be sent consecutively when calling isotp_poll.
link | The instance used for transceiving data. |
payload | The payload to be sent. (Up to 4095 bytes). |
size | The size of the payload to be sent. |
Sends ISO-TP frames via CAN, using the ID set in the initialising function.
Definition at line 229 of file isotp.c.
References isotp_send_with_id(), and IsoTpLink::send_arbitration_id.
int isotp_send_with_id | ( | IsoTpLink * | link, |
uint32_t | id, | ||
const uint8_t | payload[], | ||
uint16_t | size | ||
) |
See isotp_send, with the exception that this function is used only for functional addressing.
Definition at line 233 of file isotp.c.
References isotp_send_first_frame(), isotp_send_single_frame(), ISOTP_SEND_STATUS_INPROGRESS, isotp_user_debug(), isotp_user_get_us(), IsoTpLink::send_bs_remain, IsoTpLink::send_buf_size, IsoTpLink::send_buffer, IsoTpLink::send_offset, IsoTpLink::send_protocol_result, IsoTpLink::send_size, IsoTpLink::send_st_min_us, IsoTpLink::send_status, IsoTpLink::send_timer_bs, IsoTpLink::send_timer_st, and IsoTpLink::send_wtf_count.
Referenced by isotp_send().