Project

packet_io

0.0
No commit activity in last 3 years
No release in over 3 years
define packet based protocols in a declarative fashion
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 5.10
~> 0.7, ~> 0.8

Runtime

>= 0
 Project Readme

packet_io

by Levin Alexander
http://levinalex.net/

Build Status

DESCRIPTION:

packet_io is a small library that makes it easy to define packet based protocols over a serial link (RS232) in a declarative fashion.

SYNOPSIS:

require 'packet_io'

# define your protocol handler, inheriting from PacketIO::Base
#
# override `read` and `write` to implement your functionality
#
# this is a simple protocol handler that does nothing.
#
# see {PacketIO::LineBasedProtocol} for another trivial example
#
class MyNOPProtocol < PacketIO::Base
  def receive(packet)
    forward(packet)
  end

  def write(data)
    super(packet)
  end
end

# use your protocol. It is possible to stack multiple protocol
# layers on top of each other
#
stream = PacketIO.IOListener(File.open("/dev/ttyUSB0"))
line_based = PacketIO::LineBasedProtocol.new(stream)
my_protocol = MyNOPProtocol.new(line_based)


stream.run!

INSTALL:

gem install packet_io