isotp-c
Platform-independent ISO 15765-2 transport for embedded C
Loading...
Searching...
No Matches
isotp_example_polling.c

Advance segmented transmission and protocol timeouts.

Advance segmented transmission and protocol timeouts.Call this regularly even when completion callbacks are enabled. The required frequency depends on the configured separation time and response timeout. Single-frame transmission and incoming-frame parsing happen synchronously in their respective API calls.

Parameters
[in,out]linkInitialised link. Must not be NULL.
#include "example_platform.h"
#include "isotp.h"
#define EXAMPLE_TX_ID 0x7E0u
#define EXAMPLE_RX_ID 0x7E8u
#define EXAMPLE_BUFFER_SIZE 4095u
static ExampleCan* example_can;
static IsoTpLink link;
static uint8_t send_buffer[EXAMPLE_BUFFER_SIZE];
static uint8_t receive_buffer[EXAMPLE_BUFFER_SIZE];
int isotp_user_send_can(const uint32_t arbitration_id, const uint8_t* data, const uint8_t size) {
return example_can_send(example_can, arbitration_id, data, size, false, false);
}
uint32_t isotp_user_get_us(void) { return example_get_us(); }
void isotp_user_debug(const char* message, ...) { (void)message; }
void example_isotp_init(ExampleCan* can) {
example_can = can;
isotp_init_link(&link, EXAMPLE_TX_ID, send_buffer, sizeof(send_buffer), receive_buffer, sizeof(receive_buffer));
}
void example_isotp_process(void) {
uint32_t arbitration_id;
uint8_t frame[ISOTP_CAN_DL_CLASSIC];
uint8_t frame_size;
uint8_t payload[EXAMPLE_BUFFER_SIZE];
uint32_t payload_size;
if (example_can_receive(example_can, &arbitration_id, frame, &frame_size) && arbitration_id == EXAMPLE_RX_ID) {
isotp_on_can_message(&link, frame, frame_size);
}
isotp_poll(&link);
if (isotp_receive(&link, payload, sizeof(payload), &payload_size) == ISOTP_RET_OK) { example_process_message(payload, payload_size); }
}
int example_isotp_send(const uint8_t* payload, uint32_t size) { return isotp_send(&link, payload, size); }
int isotp_send(IsoTpLink *link, const uint8_t payload[], uint32_t size)
Start transmitting a payload with the link's configured CAN identifier.
void isotp_init_link(IsoTpLink *link, uint32_t sendid, uint8_t *sendbuf, uint32_t sendbufsize, uint8_t *recvbuf, uint32_t recvbufsize)
Initialise an ISO-TP link and its caller-owned buffers.
int isotp_receive(IsoTpLink *link, uint8_t *payload, const uint32_t payload_size, uint32_t *out_size)
Copy and consume one completed, non-streaming message.
void isotp_on_can_message(IsoTpLink *link, const uint8_t *data, uint8_t len)
Process one CAN frame already routed to this link.
#define ISOTP_CAN_DL_CLASSIC
void isotp_user_debug(const char *message,...)
Receive a diagnostic message from the library.
uint32_t isotp_user_get_us(void)
Return the current 32-bit monotonic time in microseconds.
int isotp_user_send_can(const uint32_t arbitration_id, const uint8_t *data, const uint8_t size, const uint8_t flags, void *arg)
Submit one CAN or CAN FD frame to the application's driver.
#define ISOTP_RET_OK
Public ISO-TP link and transport API.