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

Copy and consume the next available chunk of an incoming message.

Copy and consume the next available chunk of an incoming message.This function supports both oversized streaming messages and messages that fit in the normal receive buffer. Consuming an intermediate chunk emits a Continue Flow Control frame when more wire data is needed.

Parameters
[in,out]linkInitialised link, or NULL.
[out]payloadDestination for the complete available chunk, or NULL.
[in]payload_sizeCapacity of payload.
[out]out_sizeNumber of bytes copied, or NULL.
[out]is_completeSet to true when this chunk ends the message, or NULL.
Return values
ISOTP_RET_OKA chunk was copied.
ISOTP_RET_NO_DATANo chunk is currently available.
ISOTP_RET_NOSPACEThe destination cannot hold the available chunk; the chunk remains available.
ISOTP_RET_ERRORAny required pointer is NULL.
#include "example_platform.h"
#include "isotp.h"
#define EXAMPLE_TX_ID 0x7E0u
#define EXAMPLE_RX_ID 0x7E8u
static ExampleCan* example_can;
static IsoTpLink link;
static uint8_t send_buffer[512];
static uint8_t receive_chunk[64];
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_streaming_init(ExampleCan* can) {
example_can = can;
isotp_init_link(&link, EXAMPLE_TX_ID, send_buffer, sizeof(send_buffer), receive_chunk, sizeof(receive_chunk));
}
void example_streaming_process(void) {
uint32_t arbitration_id;
uint8_t frame[ISOTP_CAN_DL_CLASSIC];
uint8_t frame_size;
uint8_t chunk[sizeof(receive_chunk)];
uint32_t chunk_size;
bool complete;
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_streaming(&link, chunk, sizeof(chunk), &chunk_size, &complete) == ISOTP_RET_OK) { example_store_chunk(chunk, chunk_size, complete); }
}
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.
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.