Skip to content

Commit

Permalink
Update documentation, add missing license file
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-wieser committed Jan 6, 2017
1 parent 7b5329a commit 1617df1
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 4 deletions.
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Eric Wieser

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PacketIO
PacketIO [![documentation](https://readthedocs.org/projects/packetio/?version=latest)](http://packetio.readthedocs.org)
========

A PlatformIO library for framing packets sent or received over an arduino `Stream`, such as `Serial`.
Expand Down
17 changes: 14 additions & 3 deletions doc/index.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
PacketIO
========

A C++ library distributed with PlatformIO_, for framing packets sent or received over an Arduino `Stream`, such as `Serial`.
PacketIO is a C++ library for framing packets sent or received over an Arduino Stream_, such as Serial_. It is distributed as a PlatformIO library.

The key feature of this library over other framing implementations it that it operates on streams. This means that if your application layer is able to produce or consume streams, you can push these streams right the way through your program. Put simply, this means you can send arbitrarily large packets, without having to worry about allocating buffers.
The key feature of this library over other framing implementations, such as PacketSerial_, it that it operates on streams. This means that if your application layer is able to produce or consume streams, you can push these streams right the way through your program. Put simply, this means you can send arbitrarily large packets, without having to worry about allocating buffers.

The example below shows a contrived case when streams are needed - it duplicates whatever packets come in, but it works no matter how large the incoming packet is:

.. include:: ../examples/packetio_streaming/packetio_streaming.ino
:code: cpp

Contents
--------

.. toctree::
:maxdepth: 2
Expand All @@ -15,4 +23,7 @@ The key feature of this library over other framing implementations it that it op

.. default-domain:: cpp

.. _PlatformIO: https://platformio.org/
.. _PlatformIO: https://platformio.org/
.. _Serial: https://www.arduino.cc/en/Reference/Serial
.. _Stream: https://www.arduino.cc/en/Reference/Stream
.. _PacketSerial: https://github.com/bakercp/PacketSerial
32 changes: 32 additions & 0 deletions examples/packetio_streaming/packetio_streaming.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <Arduino.h>
#include <cobs/Stream.h>
#include <cobs/Print.h>
using namespace packetio;

COBSPrint cobs_out(Serial);
COBSStream cobs_in(Serial);

void setup() {
Serial.begin();
}

void loop() {
// send a packet
cobs_out.print("Starting packet duplicator");
cobs_out.end();

// duplicate bytes of every packet read
while(true) {
int c = cobs_in.read();
if(c == COBSStream::EOP) {
// incoming packet ended - end ours too
cobs_out.end();
cobs_in.next();
}
else if(c != COBSStream::EOF) {
// got a byte - duplicate it
cobs_out.write(c);
cobs_out.write(c);
}
}
}

0 comments on commit 1617df1

Please sign in to comment.