Skip to content

Latest commit

 

History

History
65 lines (51 loc) · 1.36 KB

README.md

File metadata and controls

65 lines (51 loc) · 1.36 KB

slip

Serial Line Internet Protocol

Features

  • enhanced framing based on crc-ccitt
  • callbacks driving
  • ready for embedded systems
  • no dependencies

Example

#include <stdio.h>
#include <stdint.h>
#include <string.h>

#include "slip.h"

void recv_message(uint8_t *data, uint32_t size);
uint8_t write_byte(uint8_t byte);

static uint8_t buf[100];

static const slip_descriptor_s slip_descriptor = {
        .buf = buf,
        .buf_size = sizeof(buf),
        .crc_seed = 0xFFFF,
        .recv_message = recv_message,
        .write_byte = write_byte,
};

static slip_handler_s slip;

int main(void)
{
        slip_init(&slip, &slip_descriptor);

        char *to_send = "test";
        printf("SEND: %s\n", to_send);
        slip_send_message(&slip, to_send, strlen(to_send));

        uint8_t emulated_recv[] = {0xC0, 0x74, 0x65, 0x73, 0x74, 0x1F, 0xC6, 0xC0};
        for (uint8_t i = 0; i < sizeof(emulated_recv); i++) {
                uint8_t rx = emulated_recv[i];
                printf("RX: %02X\n", rx);
                slip_read_byte(&slip, rx);
        }
        return 0;
}

void recv_message(uint8_t *data, uint32_t size)
{
        char recv_buf[size + 1];

        memcpy(recv_buf, data, size);
        recv_buf[size] = 0;

        printf("RECV: %s\n", recv_buf);
}

uint8_t write_byte(uint8_t byte) 
{
        printf("TX: %02X\n", byte);
        return 1;
}