fluent-plugin-serialport 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +12 -0
- data/Gemfile +5 -0
- data/README.rdoc +29 -0
- data/Rakefile +10 -0
- data/fluent-plugin-serialport.gemspec +27 -0
- data/lib/fluent/plugin/in_serialport.rb +48 -0
- data/test/plugin/test_in_serialport.rb +27 -0
- data/test/test_helper.rb +28 -0
- metadata +120 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
= fluent plugin serialport
|
2
|
+
|
3
|
+
fluent-plugin-serialport provides input plugin for {Fluentd}[http://fluentd.org].
|
4
|
+
|
5
|
+
= Install
|
6
|
+
|
7
|
+
git clone git@github.com:katsyoshi/fluent-plugin-serialport.git
|
8
|
+
|
9
|
+
cp fluent-plugin-serialport/lib/fluent/plugin/flent-plugin-serial.rb ${FLUENT_DIR}/plugin/.
|
10
|
+
|
11
|
+
== Configuration
|
12
|
+
|
13
|
+
=== Input Configuration
|
14
|
+
|
15
|
+
<source>
|
16
|
+
type serial_input
|
17
|
+
com_port /path/to/comport
|
18
|
+
baud_rate 9600
|
19
|
+
</source>
|
20
|
+
|
21
|
+
= TODO
|
22
|
+
|
23
|
+
- gems
|
24
|
+
- test
|
25
|
+
|
26
|
+
= Copyright
|
27
|
+
|
28
|
+
Copyright:: Copyright (c) 2012- Katsuyoshi MATSUMOTO
|
29
|
+
License:: Apache License, Version 2.0
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("./lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "fluent-plugin-serialport"
|
6
|
+
s.version = "0.0.1"
|
7
|
+
s.authors = ["MATSUMOTO Katsuyoshi"]
|
8
|
+
s.email = ["matsumoto.katsuyoshi+github@gmail.com"]
|
9
|
+
s.homepage = ""
|
10
|
+
s.summary = %q{fluentd plugin for serial port}
|
11
|
+
s.description = %q{fluentd plugin for serial port}
|
12
|
+
|
13
|
+
s.rubyforge_project = "fluent-plugin-serialport"
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
s.add_development_dependency "fluentd", ["~>0.10.7"]
|
21
|
+
s.add_development_dependency "serialport"
|
22
|
+
s.add_runtime_dependency "fluentd", ["~>0.10.7"]
|
23
|
+
s.add_runtime_dependency "serialport"
|
24
|
+
# specify any dependencies here; for example:
|
25
|
+
# s.add_development_dependency "rspec"
|
26
|
+
# s.add_runtime_dependency "rest-client"
|
27
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Fluent
|
2
|
+
class SerialPortInput < Input
|
3
|
+
Plugin.register_input('serial_input', self)
|
4
|
+
config_param :com_port, :string
|
5
|
+
config_param :baud_rate, :integer
|
6
|
+
config_param :tag, :string, :default => "serial"
|
7
|
+
config_param :eol, :string, :default => $/
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
require 'serialport'
|
11
|
+
super
|
12
|
+
end
|
13
|
+
|
14
|
+
def configure(conf)
|
15
|
+
super
|
16
|
+
@device = device
|
17
|
+
end
|
18
|
+
|
19
|
+
def start
|
20
|
+
@serial = SerialPort.new(@com_port, @baud_rate, 8, 1, SerialPort::NONE)
|
21
|
+
@thread = Thread.new(&method(:run))
|
22
|
+
end
|
23
|
+
|
24
|
+
def shutdown
|
25
|
+
@serial.close
|
26
|
+
@thread.join
|
27
|
+
end
|
28
|
+
|
29
|
+
def run
|
30
|
+
loop do
|
31
|
+
unless @serial.closed?
|
32
|
+
begin
|
33
|
+
data = {@device => @serial.readline(@eol)}
|
34
|
+
Engine.emit(@tag, Engine.now, data)
|
35
|
+
rescue
|
36
|
+
STDERR.puts caller()
|
37
|
+
break
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
def device
|
45
|
+
File.basename(@com_port).gsub(/\./,"_")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'fluent/test'
|
2
|
+
|
3
|
+
class SerialPortInputTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
Fluent::Test.setup
|
6
|
+
require 'fluent/plugin/in_serialport'
|
7
|
+
end
|
8
|
+
|
9
|
+
CONFIG = %[
|
10
|
+
type serial_input
|
11
|
+
com_port serialport
|
12
|
+
baud_rate 9600
|
13
|
+
tag serialport
|
14
|
+
format /\d+,\d+,\d+(.\d+)/
|
15
|
+
]
|
16
|
+
|
17
|
+
def create_driver(conf=CONFIG)
|
18
|
+
Fluent::Test::InputTestDriver.new(Fluent::SerialPortInput).configure(conf)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_configure
|
22
|
+
d = create_driver
|
23
|
+
assert_equal 'serialport', d.instance.com_port
|
24
|
+
assert_equal 9600, d.instance.baud_rate
|
25
|
+
assert_equal 'serialport', d.instance.tag
|
26
|
+
end
|
27
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
|
12
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
13
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
14
|
+
require 'fluent/test'
|
15
|
+
unless ENV.has_key?('VERBOSE')
|
16
|
+
nulllogger = Object.new
|
17
|
+
nulllogger.instance_eval {|obj|
|
18
|
+
def method_missing(method, *args)
|
19
|
+
# pass
|
20
|
+
end
|
21
|
+
}
|
22
|
+
$log = nulllogger
|
23
|
+
end
|
24
|
+
|
25
|
+
require 'fluent/plugin/in_serialport'
|
26
|
+
|
27
|
+
class Test::Unit::TestCase
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-serialport
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- MATSUMOTO Katsuyoshi
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-11 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: fluentd
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.10.7
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.10.7
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: serialport
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: fluentd
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.10.7
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.10.7
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: serialport
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: fluentd plugin for serial port
|
79
|
+
email:
|
80
|
+
- matsumoto.katsuyoshi+github@gmail.com
|
81
|
+
executables: []
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- .gitignore
|
86
|
+
- Gemfile
|
87
|
+
- README.rdoc
|
88
|
+
- Rakefile
|
89
|
+
- fluent-plugin-serialport.gemspec
|
90
|
+
- lib/fluent/plugin/in_serialport.rb
|
91
|
+
- test/plugin/test_in_serialport.rb
|
92
|
+
- test/test_helper.rb
|
93
|
+
homepage: ''
|
94
|
+
licenses: []
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ! '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project: fluent-plugin-serialport
|
113
|
+
rubygems_version: 1.8.23
|
114
|
+
signing_key:
|
115
|
+
specification_version: 3
|
116
|
+
summary: fluentd plugin for serial port
|
117
|
+
test_files:
|
118
|
+
- test/plugin/test_in_serialport.rb
|
119
|
+
- test/test_helper.rb
|
120
|
+
has_rdoc:
|