13 }
else if (us >= 100 && us <= 900) {
14 return 0xF0 + (us / 100);
23 }
else if (st_min >= 0xF1 && st_min <= 0xF9) {
24 return (st_min - 0xF0) * 100;
31 IsoTpCanMessage message;
41#ifdef ISO_TP_FRAME_PADDING
42 (
void) memset(message.as.flow_control.reserve, ISO_TP_FRAME_PADDING_VALUE,
sizeof(message.as.flow_control.reserve));
43 ret = isotp_user_send_can(link->send_arbitration_id, message.as.data_array.ptr,
sizeof(message));
55 IsoTpCanMessage message;
67#ifdef ISO_TP_FRAME_PADDING
68 (
void) memset(message.as.single_frame.data + link->send_size, ISO_TP_FRAME_PADDING_VALUE,
sizeof(message.as.single_frame.data) - link->send_size);
69 ret = isotp_user_send_can(id, message.as.data_array.ptr,
sizeof(message));
81 IsoTpCanMessage message;
105 IsoTpCanMessage message;
106 uint16_t data_length;
122#ifdef ISO_TP_FRAME_PADDING
123 (
void) memset(message.as.consecutive_frame.data + data_length, ISO_TP_FRAME_PADDING_VALUE,
sizeof(message.as.consecutive_frame.data) - data_length);
124 ret = isotp_user_send_can(link->send_arbitration_id, message.as.data_array.ptr,
sizeof(message));
155 uint16_t payload_length;
164 payload_length = (payload_length << 8) + message->as
.first_frame.FF_DL_low;
167 if (payload_length <= 7) {
187 uint16_t remaining_bytes;
199 if (remaining_bytes > len - 1) {
229int isotp_send(IsoTpLink *link,
const uint8_t payload[], uint16_t size) {
242 isotp_user_debug("Message size too large. Increase ISO_TP_MAX_MESSAGE_SIZE to set a larger buffer\n");
244 sprintf(&message[0],
"Attempted to send %d bytes; max size is %d!\n", size, link
->send_buf_size);
282 IsoTpCanMessage message;
285 if (len < 2 || len > 8) {
292 switch (message.as
.common.type) {
430int isotp_receive(IsoTpLink *link, uint8_t *payload,
const uint16_t payload_size, uint16_t *out_size) {
438 if (copylen > payload_size) {
439 copylen = payload_size;
450void isotp_init_link(IsoTpLink *link, uint32_t sendid, uint8_t *sendbuf, uint16_t sendbufsize, uint8_t *recvbuf, uint16_t recvbufsize) {
451 memset(link, 0,
sizeof(*link));
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 ...
static int isotp_send_single_frame(IsoTpLink *link, uint32_t id)
static int isotp_send_consecutive_frame(IsoTpLink *link)
static int isotp_receive_first_frame(IsoTpLink *link, IsoTpCanMessage *message, uint8_t len)
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.
static int isotp_receive_consecutive_frame(IsoTpLink *link, IsoTpCanMessage *message, uint8_t len)
static int isotp_receive_flow_control_frame(IsoTpLink *link, IsoTpCanMessage *message, uint8_t len)
static int isotp_send_flow_control(IsoTpLink *link, uint8_t flow_status, uint8_t block_size, uint32_t st_min_us)
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.
void isotp_poll(IsoTpLink *link)
Polling function; call this function periodically to handle timeouts, send consecutive frames,...
static uint8_t isotp_us_to_st_min(uint32_t us)
STATIC FUNCTIONS ///.
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.
static uint32_t isotp_st_min_to_us(uint8_t st_min)
static int isotp_send_first_frame(IsoTpLink *link, uint32_t id)
int isotp_send(IsoTpLink *link, const uint8_t payload[], uint16_t size)
PUBLIC FUNCTIONS ///.
static int isotp_receive_single_frame(IsoTpLink *link, IsoTpCanMessage *message, uint8_t len)
#define ISO_TP_MAX_WFT_NUMBER
#define ISO_TP_DEFAULT_ST_MIN_US
#define ISO_TP_DEFAULT_RESPONSE_TIMEOUT_US
#define ISO_TP_DEFAULT_BLOCK_SIZE
@ ISOTP_RECEIVE_STATUS_FULL
@ ISOTP_RECEIVE_STATUS_IDLE
@ ISOTP_RECEIVE_STATUS_INPROGRESS
#define ISOTP_RET_NOSPACE
#define ISOTP_PROTOCOL_RESULT_BUFFER_OVFLW
#define ISOTP_PROTOCOL_RESULT_UNEXP_PDU
#define ISOTP_RET_NO_DATA
#define ISOTP_PROTOCOL_RESULT_OK
#define ISOTP_RET_OVERFLOW
#define ISOTP_PROTOCOL_RESULT_TIMEOUT_CR
@ ISOTP_SEND_STATUS_ERROR
@ ISOTP_SEND_STATUS_INPROGRESS
#define ISOTP_PROTOCOL_RESULT_TIMEOUT_BS
#define ISOTP_RET_WRONG_SN
#define ISOTP_PROTOCOL_RESULT_WFT_OVRN
#define ISOTP_RET_INPROGRESS
@ PCI_FLOW_STATUS_OVERFLOW
@ PCI_FLOW_STATUS_CONTINUE
@ TSOTP_PCI_TYPE_CONSECUTIVE_FRAME
@ ISOTP_PCI_TYPE_FIRST_FRAME
@ ISOTP_PCI_TYPE_FLOW_CONTROL_FRAME
#define IsoTpTimeAfter(a, b)
#define ISOTP_PROTOCOL_RESULT_WRONG_SN
void isotp_user_debug(const char *message,...)
user implemented, print debug message
int isotp_user_send_can(const uint32_t arbitration_id, const uint8_t *data, const uint8_t size)
user implemented, send can message. should return ISOTP_RET_OK when success.
uint32_t isotp_user_get_us(void)
user implemented, gets the amount of time passed since the last call in microseconds
IsoTpDataArray data_array
IsoTpFirstFrame first_frame
IsoTpConsecutiveFrame consecutive_frame
IsoTpSingleFrame single_frame
IsoTpFlowControl flow_control
uint32_t receive_timer_cr
uint16_t receive_buf_size
int receive_protocol_result
uint32_t send_arbitration_id