packet_io 0.4.0.rc3 → 0.4.0.rc4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,26 +1,55 @@
1
- serial_interface
1
+ # packet_io
2
+
2
3
  by Levin Alexander
3
4
  http://levinalex.net/
4
5
 
5
- == DESCRIPTION:
6
+ ## DESCRIPTION:
6
7
 
7
- serial_interface intends to be a small library that makes it easy
8
+ packet_io is a small library that makes it easy
8
9
  to define packet based protocols over a serial link (RS232) in a
9
10
  declarative fashion.
10
11
 
11
- == SYNOPSIS:
12
+ ## SYNOPSIS:
13
+
14
+ require 'packet_io'
15
+
16
+ # define your protocol handler, inheriting from PacketIO::Base
17
+ #
18
+ # override `read` and `write` to implement your functionality
19
+ #
20
+ # this is a simple protocol handler that does nothing.
21
+ #
22
+ # see {PacketIO::LineBasedProtocol} for another trivial example
23
+ #
24
+ class MyNOPProtocol < PacketIO::Base
25
+ def receive(packet)
26
+ forward(packet)
27
+ end
28
+
29
+ def write(data)
30
+ super(packet)
31
+ end
32
+ end
33
+
34
+ # use your protocol. It is possible to stack multiple protocol
35
+ # layers on top of each other
36
+ #
37
+ stream = PacketIO.IOListener(File.open("/dev/ttyUSB0"))
38
+ line_based = PacketIO::LineBasedProtocol.new(stream)
39
+ my_protocol = MyNOPProtocol.new(line_based)
40
+
12
41
 
13
- nothing written yet
42
+ stream.run!
14
43
 
15
- == INSTALL:
44
+ ## INSTALL:
16
45
 
17
- * not yet written
46
+ gem install packet_io
18
47
 
19
- == LICENSE:
48
+ ## LICENSE:
20
49
 
21
50
  (The MIT License)
22
51
 
23
- Copyright (c) 2006-2008 Levin Alexander
52
+ Copyright (c) 2006-2011 Levin Alexander
24
53
 
25
54
  Permission is hereby granted, free of charge, to any person obtaining
26
55
  a copy of this software and associated documentation files (the
@@ -1,4 +1,7 @@
1
1
  module PacketIO::Test
2
+
3
+ # a threaded reader that simulates a remote server to help testing io_listener
4
+ #
2
5
  class MockServer
3
6
 
4
7
  # create a new server and wire it up with a bidirectional pipe
@@ -13,14 +16,15 @@ module PacketIO::Test
13
16
 
14
17
  def initialize(read, write)
15
18
  @read, @write = read, write
16
- @queue = Queue.new
17
- @thread = Thread.new do
19
+ @write_queue = Queue.new
20
+
21
+ @writer = Thread.new do
18
22
  parse_commands
19
23
  end
20
24
  end
21
25
 
22
26
  def write(string)
23
- @queue.push [:write, string]
27
+ @write_queue.push [:write, string]
24
28
  self
25
29
  end
26
30
 
@@ -29,12 +33,12 @@ module PacketIO::Test
29
33
  end
30
34
 
31
35
  def wait(seconds = 0.02)
32
- @queue.push [:wait, seconds]
36
+ @write_queue.push [:wait, seconds]
33
37
  self
34
38
  end
35
39
 
36
40
  def eof
37
- @queue.push [:close]
41
+ @write_queue.push [:close]
38
42
  end
39
43
 
40
44
 
@@ -42,7 +46,7 @@ module PacketIO::Test
42
46
 
43
47
  def parse_commands
44
48
  loop do
45
- action, data = @queue.pop
49
+ action, data = @write_queue.pop
46
50
 
47
51
  case action
48
52
  when :close
data/lib/packet_io.rb CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  module PacketIO
3
- VERSION = '0.4.0.rc3'
3
+ VERSION = '0.4.0.rc4'
4
4
  end
5
5
 
6
6
  require 'strscan'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: packet_io
3
3
  version: !ruby/object:Gem::Version
4
- hash: 977940588
4
+ hash: 977940589
5
5
  prerelease: true
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
9
  - 0
10
- - rc3
11
- version: 0.4.0.rc3
10
+ - rc4
11
+ version: 0.4.0.rc4
12
12
  platform: ruby
13
13
  authors:
14
14
  - Levin Alexander
@@ -96,7 +96,7 @@ files:
96
96
  - .gitignore
97
97
  - History.txt
98
98
  - LICENSE
99
- - README.rdoc
99
+ - README.markdown
100
100
  - Rakefile
101
101
  - lib/packet_io.rb
102
102
  - lib/packet_io/io_listener.rb