Giter VIP home page Giter VIP logo

slip's Introduction

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;
}

slip's People

Contributors

marcinbor85 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.