Giter Club home page Giter Club logo

msgpkz's Introduction

MsgPkz - Lightweight Message Packetizer

This is a lightweight header-only messaging library with a core implementation that does not rely on any dynamic memory. It is suitable for systems with very limited ressources such as microcontrollers. MsgPkz originated from a project where an embedded board had to communicate wirelessly with an external server via TCP and with a tiny microcontroller via UART. For this reason, there are TCP and serial endpoints available as well as a serial client implementation for Arduino-like boards. Thanks to this guy for the amazing Arduino port of STL-like containers and type traits.

Messages are identified and depacketized with an unique 1-byte id, packets can consist of any number and kind of messages (adapt the maximum buffer sizes, if necessary). You can subscribe to specific packets by explicitely describing their message signature via lambda functions. The code to handle the packets with types of messages that you are interested in is actually generated at compile time. There is some happy little meta template programming magic going on in the background. Feel free to customize the message types to your needs. Just make sure that the size property sums up to the number of bytes of your payload.

Features

  • super fast message packetizer and de-packetizer
  • easily customizable and extendable
  • Arduino compatible
  • core without dynamic memory allocation
  • packet framing with either COBS or SLIP
  • CRC16-CCITT secured packets
  • pre-implemented TCP and serial endpoints (Boost.Asio and Arduino Serial)
  • subscribe, receive (async/blocking) and send (async/blocking)

Usage

client.subscribe(
  [](const FrameMessage& fm, const IMUMessage& im)
  {
    std::cout << "IMU message:"
      << " ts: " << im.timestamp
      << " acc: " << im.acc.vec.x << "," << im.acc.vec.y << "," << im.acc.vec.z
      << " gyr: " << im.gyr.vec.x << "," << im.gyr.vec.y << "," << im.gyr.vec.z
      << " mag: " << im.mag.vec.x << "," << im.mag.vec.y << "," << im.mag.vec.z
      << std::endl;
  },
  [](const FrameMessage& fm, const IMUMessage& im0, const IMUMessage& im1, const IMUMessage& im2)
  {
    std::cout << "I received a packet with exactly 3 IMU messages!" << std::endl;
  },
  [&](const StatusMessage& sm)
  {
    std::cout << "Status update: " << sm.id << std::endl;
    client.sendAsync(StatusMessage(0x01)); // Send something back
  },
  [](const ErrorMessage& em)
  {
    std::cerr << "Oops... something went wrong!" << std::endl;
  }
);

Requires

  • Boost::system โ‰ฅ 1.70

msgpkz's People

Contributors

felixlaufer avatar

Watchers

 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.