slip.h (776B)
1#pragma once 2 3#include <stdint.h> 4#include <stdbool.h> 5#include <stdlib.h> 6 7struct slip { 8 int rx_state; 9 10 size_t rx_index; 11 size_t rx_buflen; 12 uint8_t *rx_buf; 13 14 void (*rx_restart)(struct slip *slip, uint8_t err_byte); 15 void (*rx_packet)(struct slip *slip, 16 uint8_t *data, size_t size, void *user); 17 void *rx_packet_userdata; 18 19 int (*realloc)(void **buffer, size_t size); 20 21 uint8_t esc, start, end; 22 bool esc_active[256]; 23 uint8_t esc_enc[256]; 24 uint8_t esc_dec[256]; 25}; 26 27int slip_init(struct slip *slip); 28void slip_deinit(struct slip *slip); 29 30int slip_decode(struct slip *slip, uint8_t *data, size_t size); 31int slip_decode_store(struct slip *slip, uint8_t byte); 32 33int slip_encode(struct slip *slip, uint8_t *out, size_t *outlen, 34 size_t outcap, uint8_t *in, size_t inlen);